
    ^j                         d dl 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
 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)UnknownMethodException)Self)CanExecuteCommands)CanExecuteScripts)CanRememberExtensionPresence)ClipboardContentType   )MobileCommandc            	           e Zd Zej                  dfdededee   defdZ	ddedee   defdZ
ej                  fdedefd	Zdefd
ZddZy)	ClipboardNcontentcontent_typelabelreturnc                 (   d}t        j                  |      j                  d      |d}|r||d<   	 | j                  |      j	                  ||       | S # t
        $ r3 | j                  |      j                  t        j                  |       Y | S w xY w)a  Set the content of the system clipboard

        Args:
            content: The content to be set as bytearray string
            content_type: One of ClipboardContentType items. Only ClipboardContentType.PLAINTEXT
                is supported on Android
            label: label argument, which only works for Android

        Returns:
            Union['WebDriver', 'Clipboard']: Self instance
        zmobile: setClipboardUTF-8)r   contentTyper   )
base64	b64encodedecodeassert_extension_existsexecute_scriptr   mark_extension_absenceexecuteCommandSET_CLIPBOARD)selfr   r   r   ext_nameoptionss         Y/home/ubuntu/.local/lib/python3.12/site-packages/appium/webdriver/extensions/clipboard.pyset_clipboardzClipboard.set_clipboard   s     *''077@'
 $GG	Z((2AA(GT  & 	Z''199':O:OQXY	Zs   !A 8BBtextc                 j    | j                  t        t        |      d      t        j                  |      S )zCopies the given text to the system clipboard

        Args:
            text: The text to be set
            label:label argument, which only works for Android

        Returns:
            Union['WebDriver', 'Clipboard']: Self instance
        r   )r"   bytesstrr	   	PLAINTEXT)r   r#   r   s      r!   set_clipboard_textzClipboard.set_clipboard_text:   s,     !!%D	7";=Q=[=[]bcc    c                     d}d|i}	 | j                  |      j                  ||      }t        j                  |      S # t        $ r5 | j                  |      j	                  t
        j                  |      d   }Y Rw xY w)a4  Receives the content of the system clipboard

        Args:
            content_type: One of ClipboardContentType items. Only ClipboardContentType.PLAINTEXT
                is supported on Android

        Returns:
            Clipboard content as bytearray. Or empty bytes if the clipboard is empty
        zmobile: getClipboardr   value)	r   r   r   r   r   r   GET_CLIPBOARDr   	b64decode)r   r   r   r    
base64_strs        r!   get_clipboardzClipboard.get_clipboardF   s     * ,/	p55h?NNxY`aJ 
++ & 	p44X>FFwG\G\^efgnoJ	ps   !> ;A<;A<c                 ^    | j                  t        j                        j                  d      S )zReceives the text of the system clipboard

        Returns:
            The actual clipboard text or an empty string if the clipboard is empty
        r   )r/   r	   r'   r   r   s    r!   get_clipboard_textzClipboard.get_clipboard_textY   s'     !!"6"@"@AHHQQr)   c                     | j                   j                  t        j                  dd       | j                   j                  t        j                  dd       y )NPOSTz//session/$sessionId/appium/device/set_clipboardz//session/$sessionId/appium/device/get_clipboard)command_executoradd_commandr   r   r,   r1   s    r!   _add_commandszClipboard._add_commandsa   sJ    ))!!=	

 	))!!=	
r)   )N)r   N)__name__
__module____qualname__r	   r'   r%   r&   r   r   r"   r(   r/   r2   r7    r)   r!   r   r      s    2F2P2Pim,/YabeYf	8
ds 
d8C= 
dD 
d 1E0N0N ,# ,SX ,&RC R

r)   r   )r   typingr   selenium.common.exceptionsr   typing_extensionsr   /appium.protocols.webdriver.can_execute_commandsr   .appium.protocols.webdriver.can_execute_scriptsr   :appium.protocols.webdriver.can_remember_extension_presencer   'appium.webdriver.clipboard_content_typer	   mobilecommandr   r   r   r;   r)   r!   <module>rD      s7      = " N L c H 4N
"$57S N
r)   