





import os

from apache_beam.io.filesystems import FileSystems
from apache_beam.pipeline import Pipeline

from .logging import get_logger


_lowerCAmelCase  :				Optional[Any]						=				2 << 2_0  # 2mb
_lowerCAmelCase  :				Any						=				get_logger(__name__)
class      _UpperCamelCase (			lowerCAmelCase						):
      def 		UpperCAmelCase_  (     self				:Tuple )       ->     str:
       UpperCAmelCase__								=  self._options.get_all_options().get("runner" )
       return runner in [None, "DirectRunner", "PortableRunner"]



def   lowerCAmelCase						(						_lowerCAmelCase							:				List[Any]  ,							_lowerCAmelCase							:				Any  ,							_lowerCAmelCase							:				int=False		):




 """simple docstring"""







 UpperCAmelCase__								=  FileSystems
 if fs.exists(_lowerCAmelCase		):
  if force_upload:
   logger.info(F'''Remote path already exist: {remote_file_path}. Overwriting it as force_upload=True.'''		)
  else:
   logger.info(F'''Remote path already exist: {remote_file_path}. Skipping it as force_upload=False.'''		)
   return
 with fs.create(_lowerCAmelCase		) as remote_file:
  with open(_lowerCAmelCase  ,							"rb"		) as local_file:
   UpperCAmelCase__								=  local_file.read(_lowerCAmelCase		)
   while chunk:
    remote_file.write(_lowerCAmelCase		)
    UpperCAmelCase__								=  local_file.read(_lowerCAmelCase		)



def   lowerCAmelCase						(						_lowerCAmelCase							:				List[str]  ,							_lowerCAmelCase							:				int  ,							_lowerCAmelCase							:				Union[str, Any]=False		):




 """simple docstring"""







 UpperCAmelCase__								=  FileSystems
 if os.path.exists(_lowerCAmelCase		):
  if force_download:
   logger.info(F'''Local path already exist: {remote_file_path}. Overwriting it as force_upload=True.'''		)
  else:
   logger.info(F'''Local path already exist: {remote_file_path}. Skipping it as force_upload=False.'''		)
   return
 with fs.open(_lowerCAmelCase		) as remote_file:
  with open(_lowerCAmelCase  ,							"wb"		) as local_file:
   UpperCAmelCase__								=  remote_file.read(_lowerCAmelCase		)
   while chunk:
    local_file.write(_lowerCAmelCase		)
    UpperCAmelCase__								=  remote_file.read(_lowerCAmelCase		)











from __future__ import annotations



def   lowerCAmelCase						(						_lowerCAmelCase							:				int  ,							_lowerCAmelCase							:				int  ,							_lowerCAmelCase							:				int		):




 """simple docstring"""







 assert (
     c % greatest_common_divisor(_lowerCAmelCase  ,							_lowerCAmelCase		) == 0
 )  # greatest_common_divisor(a,b) function implemented below
 ((UpperCAmelCase__)	,	(UpperCAmelCase__)	,	(UpperCAmelCase__))								=  extended_gcd(_lowerCAmelCase  ,							_lowerCAmelCase		)  # extended_gcd(a,b) function implemented below
 UpperCAmelCase__								=  c / d
 return (r * x, r * y)



def   lowerCAmelCase						(						_lowerCAmelCase							:				int  ,							_lowerCAmelCase							:				int  ,							_lowerCAmelCase							:				int  ,							_lowerCAmelCase							:				int = 2		):




 """simple docstring"""







 ((UpperCAmelCase__)	,	(UpperCAmelCase__))								=  diophantine(_lowerCAmelCase  ,							_lowerCAmelCase  ,							_lowerCAmelCase		)  # Initial value
 UpperCAmelCase__								=  greatest_common_divisor(_lowerCAmelCase  ,							_lowerCAmelCase		)
 UpperCAmelCase__								=  a // d
 UpperCAmelCase__								=  b // d

 for i in range(_lowerCAmelCase		):
  UpperCAmelCase__								=  xa + i * q
  UpperCAmelCase__								=  ya - i * p
  print(_lowerCAmelCase  ,							_lowerCAmelCase		)



def   lowerCAmelCase						(						_lowerCAmelCase							:				int  ,							_lowerCAmelCase							:				int		):




 """simple docstring"""







 if a < b:
  UpperCAmelCase__	,	UpperCAmelCase__								=  b, a

 while a % b != 0:
  UpperCAmelCase__	,	UpperCAmelCase__								=  b, a % b

 return b



def   lowerCAmelCase						(						_lowerCAmelCase							:				int  ,							_lowerCAmelCase							:				int		):




 """simple docstring"""







 assert a >= 0 and b >= 0

 if b == 0:
  UpperCAmelCase__	,	UpperCAmelCase__	,	UpperCAmelCase__								=  a, 1, 0
 else:
  ((UpperCAmelCase__)	,	(UpperCAmelCase__)	,	(UpperCAmelCase__))								=  extended_gcd(_lowerCAmelCase  ,							a % b		)
  UpperCAmelCase__								=  q
  UpperCAmelCase__								=  p - q * (a // b)

 assert a % d == 0 and b % d == 0
 assert d == a * x + b * y

 return (d, x, y)


if __name__ == "__main__":
  from doctest import testmod

  testmod(name="diophantine", verbose=True)
  testmod(name="diophantine_all_soln", verbose=True)
  testmod(name="extended_gcd", verbose=True)
  testmod(name="greatest_common_divisor", verbose=True)





