Ë
    ¾�jÌ  ã                   óø   — d dl mZmZ d dlZd dlZd dlZd dlmZ d dlm	Z	m
Z
mZmZmZmZ d dlZd dlmZmZmZ d dlmZ d dlmZmZmZ d dl­ d d	lmZ d d
lmZmZm Z   ejB                  e"«      Z# G d„ de«      Z$y)é    )Úabsolute_importÚprint_functionN)Úcached_property)ÚAnyÚDictÚListÚOptionalÚTupleÚUnion)ÚHTTP_TIMEOUTÚSCROLL_STEPSÚ	Direction)ÚShellResponse)ÚDEFAULT_SERVER_PORTÚBasicUiautomatorServerÚ
check_port)Ú*©ÚSettings)Ú
deprecatedÚimage_convertÚlist2cmdlinec                   ó‚  — e Zd ZdZdedœdeeeej                  f      de
fd„Zedefd„«       Zddej                  fd	„Zedej                  fd
„«       Zedefd„«       Zdefd„Zddeeee   f   defd„Zedeeef   fd„«       Zedeeef   fd„«       Zedee   fd„«       Zed„ «       Zd„ Zddefd„Zdedefd„Z y)Ú_BaseClientuF   
    æ��ä¾›æœ€åŸºç¡€çš„æŽ§åˆ¶ç±»ï¼Œè¿™ä¸ªç±»æš‚æ—¶å…ˆä¸�å…¬å¼€å�§
    N)ÚportÚserialr   c                ó
  — t        |«       t        |t        j                  «      r|j                  | _        || _        n|| _        | j                  «       | _        d| _        t        j                  | | j                  |¬«       y)zp
        Args:
            serial: device serialno
            port: uiautomator2 server port on device
        F)ÚdevÚdevice_server_portN)r   Ú
isinstanceÚadbutilsÚ	AdbDevicer   Ú_BaseClient__serialÚ_devÚ_wait_for_deviceÚ_debugr   Ú__init__)Úselfr   r   s      úR/var/www/api.ozpay.ru/ozpay/venv/lib/python3.12/site-packages/uiautomator2/base.pyr'   z_BaseClient.__init__   sc   € ô 	�4ÔÜ�fœh×0Ñ0Ô1Ø"ŸM™MˆDŒMØˆD�Ià"ˆDŒMØ×-Ñ-Ó/ˆDŒIØˆŒÜ×'Ñ'¨°$·)±)ÐPTÖUó    Úreturnc                 ó   — | j                   S ©N)r#   ©r(   s    r)   Ú_serialz_BaseClient._serial*   s   € à�}‰}Ðr*   c                 óþ  — t         j                  j                  «       D ]  }|j                  | j                  k(  sŒ|c S  t        j                  d«      }|j                  | j                  «      du}t         j                  }t        j                  «       |z   }t        j                  «       |k  r¦|rdnd}t        j                  d||t        j                  «       z
  «       |r9	 |j                  | j                  «       |j                  | j                  d¬«       	 |j#                  | j                  d¬«       |j%                  | j                  «      S t'        d
| j                  › d�«      ‚# t         j                  t         j                  f$ r?}t        j                  dt        |«      «       t        j                   d	«       Y d}~�Œ3d}~ww xY w# t         j                  t         j                  f$ r Y �Œaw xY w)z¹
        wait for device came online, if device is remote, reconnect every 1s

        Returns:
            adbutils.AdbDevice
        
        Raises:
            ConnectError
        z(^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+$Nzdevice reconnectingzwait-for-devicez%s, time left(%.1fs)é   ©Útimeoutzadb reconnect error: %sg      ð?zdevice z not online)r!   ÚadbÚdevice_listr   r/   ÚreÚcompileÚmatchÚtimeÚloggerÚdebugÚ
disconnectÚconnectÚAdbErrorÚ
AdbTimeoutÚstrÚsleepÚwait_forÚdeviceÚConnectError)	r(   r3   ÚdÚ_RE_remote_adbÚ
_is_remoter4   ÚdeadlineÚtitleÚes	            r)   r%   z_BaseClient._wait_for_device.   s‡  € ô —‘×)Ñ)Ó+ò 	ˆAØ�x‰x˜4Ÿ<™<Ó'Ø’ð	ô Ÿ™Ð$OÓPˆØ#×)Ñ)¨$¯,©,Ó7¸tÐCˆ
ä�l‰lˆÜ—9‘9“; Ñ(ˆÜ�i‰i‹k˜HÒ$Ù-7Ñ)Ð=NˆEÜ�L‰LÐ/°¸Ä4Ç9Á9Ã;Ñ8NÔOÙðØ—N‘N 4§<¡<Ô0Ø—K‘K §¡°a�KÔ8ð
Ø—‘˜TŸ\™\°1�Ô5ð —:‘:˜dŸl™lÓ+Ð+Ü˜W T§\¡\ N°+Ð>Ó?Ð?øô !×)Ñ)¬8×+>Ñ+>Ð?ò Ü—L‘LÐ!:¼CÀ»FÔCÜ—J‘J˜s”OÝûðûô ×%Ñ%¤x×':Ñ':Ð;ò Úðús*   Ã&8E0 ÄG Å0#GÆ4GÇGÇ#G<Ç;G<c                 ó   — | j                   S r-   )r$   r.   s    r)   Ú
adb_devicez_BaseClient.adb_deviceS   s   € à�y‰yÐr*   c                 ó   — t        | «      S r-   r   r.   s    r)   Úsettingsz_BaseClient.settingsW   s   € ä˜‹~Ðr*   Úsecondsc                 ó.   — t        j                  |«       y)z same as time.sleep N)r9   rA   )r(   rO   s     r)   rA   z_BaseClient.sleep[   s   € ä�
‰
�7Õr*   Úcmdargsc                 óJ  — 	 | j                   rt        dt        |«      «       t        j                  dt        |«      «       | j                  j                  ||¬«      }t        |j                  |j                  «      S # t        j                  $ r}t        |«      ‚d}~ww xY w)a!  
        Run shell command on device

        Args:
            cmdargs: str or list, example: "ls -l" or ["ls", "-l"]
            timeout: seconds of command run, works on when stream is False

        Returns:
            ShellResponse

        Raises:
            AdbShellError
        zshell:z	shell: %sr2   N)r;   Úprintr   r:   r$   Úshell2r   ÚoutputÚ
returncoder!   r>   ÚAdbShellError)r(   rQ   r3   ÚretrJ   s        r)   Úshellz_BaseClient.shell_   s   € ð	#Ø�zŠzÜ�h¤¨WÓ 5Ô6Ü�L‰L˜¤l°7Ó&;Ô<Ø—)‘)×"Ñ" 7°GÐ"Ó<ˆCÜ  §¡¨S¯^©^Ó<Ð<øÜ× Ñ ò 	#Ü Ó"Ð"ûð	#ús   ‚A<A? Á?B"ÂBÂB"c                 ó:   — | j                   j                  d¬«      S )Né
   )Úhttp_timeout)ÚjsonrpcÚ
deviceInfor.   s    r)   Úinfoz_BaseClient.infov   s   € à�|‰|×&Ñ&°BÐ&Ó7Ð7r*   c                 óÈ  — | j                   j                  d«      }| j                   j                  d«      }| j                   j                  d«      }| j                   j                  d«      }| j                   j                  d«      }| j                   j                  d«      }||j                  «       rt        |«      nd ||||j                  «       rt        |«      dœS d dœS )Nzro.serialnozro.build.version.sdkzro.build.version.releasezro.product.brandzro.product.modelzro.product.cpu.abi)r   ÚsdkÚbrandÚmodelÚarchÚversion)r$   ÚgetpropÚisdigitÚint)r(   r   ra   re   rb   rc   rd   s          r)   Údevice_infoz_BaseClient.device_infoz   sÆ   € à—‘×"Ñ" =Ó1ˆØ�i‰i×ÑÐ 6Ó7ˆØ—)‘)×#Ñ#Ð$>Ó?ˆØ—	‘	×!Ñ!Ð"4Ó5ˆØ—	‘	×!Ñ!Ð"4Ó5ˆØ�y‰y× Ñ Ð!5Ó6ˆàØ"Ÿ{™{œ}”3�s”8°$ØØØØ'.§¡Ô'8”s˜7“|ñ
ð 	
ð ?Cñ
ð 	
r*   c                 ój   — 	 | j                   j                  «       S # t        j                  $ r Y y w xY wr-   )r$   Úwlan_ipr!   r>   r.   s    r)   rk   z_BaseClient.wlan_ip‹   s2   € ð	Ø—9‘9×$Ñ$Ó&Ð&øÜ× Ñ ò 	Ùð	ús   ‚ œ2±2c                 ó&   —  G d„ d«      } || «      S )Nc                   ó$   — e Zd Zdefd„Zd„ Zd„ Zy)ú+_BaseClient.jsonrpc.<locals>.JSONRpcWrapperÚserverc                 ó    — || _         d | _        y r-   )ro   Úmethod)r(   ro   s     r)   r'   z4_BaseClient.jsonrpc.<locals>.JSONRpcWrapper.__init__•   s   € Ø$�”Ø"�•r*   c                 ó   — || _         | S r-   )rq   )r(   rq   s     r)   Ú__getattr__z7_BaseClient.jsonrpc.<locals>.JSONRpcWrapper.__getattr__™   s   € Ø$�”Ø�r*   c                 óˆ   — |j                  dt        «      }|r|n|}| j                  j                  | j                  ||«      S )Nr\   )Úpopr   ro   Újsonrpc_callrq   )r(   ÚargsÚkwargsr\   Úparamss        r)   Ú__call__z4_BaseClient.jsonrpc.<locals>.JSONRpcWrapper.__call__�   s8   € Ø%Ÿz™z¨.¼,ÓG�Ù!%™¨6�Ø—{‘{×/Ñ/°·±¸VÀ\ÓRÐRr*   N)Ú__name__Ú
__module__Ú__qualname__r   r'   rs   rz   © r*   r)   ÚJSONRpcWrapperrn   ”   s   „ ð#Ð'=ó #òóSr*   r   r~   )r(   r   s     r)   r]   z_BaseClient.jsonrpc’   s   € ÷	Sñ 	Sñ ˜dÓ#Ð#r*   c                 óD   — | j                  «        | j                  «        y)a
  
        restart uiautomator service

        Orders:
            - stop uiautomator keeper
            - am force-stop com.github.uiautomator
            - start uiautomator keeper(am instrument -w ...)
            - wait until uiautomator service is ready
        N)Ústop_uiautomatorÚstart_uiautomatorr.   s    r)   Úreset_uiautomatorz_BaseClient.reset_uiautomator¤   s   € ð 	×ÑÔØ×ÑÕ r*   Údstc                 óT   — | j                   j                  j                  |||¬«       y)zÅ
        Push file into device

        Args:
            src (path or fileobj): source file
            dst (str): destination can be folder or file path
            mode (int): file mode
        )ÚmodeN)r$   ÚsyncÚpush)r(   Úsrcr„   r†   s       r)   rˆ   z_BaseClient.push±   s!   € ð 	�	‰	�‰×Ñ˜C ¨4ÐÕ0r*   r‰   c                 óÀ   — 	 | j                   j                  j                  ||d¬«       y# t        $ r) | j                   j                  j                  ||«       Y yw xY w)z0
        Pull file from device to local
        T)Úexist_okN)r$   r‡   ÚpullÚ	TypeError)r(   r‰   r„   s      r)   rŒ   z_BaseClient.pull¼   sK   € ð	*Ø�I‰I�N‰N×Ñ  S°4ÐÕ8øÜò 	*Ø�I‰I�N‰N×Ñ  SÖ)ð	*ús   ‚(+ «/AÁAr-   )r[   )é<   )i¤  )!r{   r|   r}   Ú__doc__r   r	   r   r@   r!   r"   rh   r'   Úpropertyr/   r%   rL   r   r   rN   ÚfloatrA   r   r   rY   r   r   r_   ri   rk   r]   rƒ   rˆ   rŒ   r~   r*   r)   r   r      sq  „ ñðVÐ_rò V˜x¨¨c°8×3EÑ3EÐ.EÑ(FÑGð VÐY\ó Vð  ð˜ò ó ðñ#@¨h×.@Ñ.@ó #@ðJ ð˜H×.Ñ.ò ó ðð ð˜(ò ó ðð˜Uó ñ#˜U 3¨¨S©	 >Ñ2ð #À=ó #ð. ð8�d˜3 ˜8‘nò 8ó ð8ð ð
˜T # s (™^ò 
ó ð
ð  ð˜ #™ò ó ðð ñ$ó ð$ò"!ñ	1˜Só 	1ð*˜ð * #ô *r*   r   )%Ú
__future__r   r   Úloggingr6   r9   Ú	functoolsr   Útypingr   r   r   r	   r
   r   r!   Úuiautomator2._protor   r   r   Úuiautomator2.abstractr   Úuiautomator2.corer   r   r   Úuiautomator2.exceptionsÚuiautomator2.settingsr   Úuiautomator2.utilsr   r   r   Ú	getLoggerr{   r:   r   r~   r*   r)   ú<module>r�      sY   ðß 6ã Û 	Û Ý %ß :× :ã ç EÑ EÝ /ß UÑ UÜ %Ý *ß FÑ Fà	ˆ×	Ñ	˜8Ó	$€ôn*Ð(õ n*r*   