
    ^j                     ~    d dl Z d dlmZ d dlmZmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ dd	lmZ  G d
 de	ee      Zy)    N)Optional)InvalidArgumentExceptionUnknownMethodException)Self)CanExecuteCommands)CanExecuteScripts)CanRememberExtensionPresence   )MobileCommandc            	       Z    e Zd ZdedefdZdedefdZddedee   dee   defd	Zdd
Z	y)RemoteFSpathreturnc                     d}	 | j                  |      j                  |d|i      S # t        $ r7 | j                  |      j	                  t
        j                  d|i      d   cY S w xY w)zRetrieves the file at `path`.

        Args:
            path: the path to the file on the device

        Returns:
            The file's contents encoded as Base64.
        zmobile: pullFile
remotePathr   value)assert_extension_existsexecute_scriptr   mark_extension_absenceexecuteCommand	PULL_FILEselfr   ext_names      Y/home/ubuntu/.local/lib/python3.12/site-packages/appium/webdriver/extensions/remote_fs.py	pull_filezRemoteFS.pull_file   sv     &	m//9HHT`bfSghh% 	m..x8@@ARARU[]aTbcdkll	m   "' =A'&A'c                     d}	 | j                  |      j                  |d|i      S # t        $ r7 | j                  |      j	                  t
        j                  d|i      d   cY S w xY w)zRetrieves a folder at `path`.

        Args:
            path: the path to the folder on the device

        Returns:
            The folder's contents zipped and encoded as Base64.
        zmobile: pullFolderr   r   r   )r   r   r   r   r   r   PULL_FOLDERr   s      r   pull_folderzRemoteFS.pull_folder-   sv     (	o//9HHT`bfSghh% 	o..x8@@ATATW]_cVdefmnn	or   Ndestination_path
base64datasource_pathc                    ||t        d      |J	 t        |d      5 }|j                         }ddd       t	        j
                        j                  d      }d}	 | j                  |      j                  |||d       | S # 1 sw Y   VxY w# t        $ r}d| d}t        |      |d}~ww xY w# t        $ r6 | j                  |      j                  t        j                  ||d	       Y | S w xY w)
a]  Puts the data from the file at `source_path`, encoded as Base64, in the file specified as `path`.

        Specify either `base64data` or `source_path`, if both specified default to `source_path`

        Args:
            destination_path: the location on the device/simulator where the local file contents should be saved
            base64data: file contents, encoded as Base64, to be written
            to the file on the device/simulator
            source_path: local file path for the file to be loaded on device

        Returns:
            Union['WebDriver', 'RemoteFS']: Self instance
        Nz1Must either pass base64 data or a local file pathrbzsource_path "z3" could not be found. Are you sure the file exists?zutf-8zmobile: pushFile)r   payload)r   data)r   openreadIOErrorbase64	b64encodedecoder   r   r   r   r   r   	PUSH_FILE)	r   r"   r#   r$   f	file_dataemessager   s	            r   	push_filezRemoteFS.push_file=   s    :#5*+^__"?+t, ) !I)
  )))4;;GDJ%	((2AA"2)  3) ) ?)+6ij.w7Q>? & 	''199!!,& 	s?   B BB $B4 B
B 	B1B,,B14;C32C3c                    | j                   j                  t        j                  dd       | j                   j                  t        j                  dd       | j                   j                  t        j
                  dd       y )NPOSTz+/session/$sessionId/appium/device/pull_filez-/session/$sessionId/appium/device/pull_folderz+/session/$sessionId/appium/device/push_file)command_executoradd_commandr   r   r    r/   )r   s    r   _add_commandszRemoteFS._add_commandsk   s_    ))'*;*;VErs))'*=*=vGvw))'*;*;VErs    )NN)r   N)
__name__
__module____qualname__strr   r!   r   r   r4   r9    r:   r   r   r      sb    mc mc m o o o ,# ,8C= ,^fgj^k ,w{ ,\tr:   r   )r,   typingr   selenium.common.exceptionsr   r   typing_extensionsr   /appium.protocols.webdriver.can_execute_commandsr   .appium.protocols.webdriver.can_execute_scriptsr   :appium.protocols.webdriver.can_remember_extension_presencer	   mobilecommandr   r   r   r?   r:   r   <module>rG      s6      W " N L c 4Rt!#46R Rtr:   