
    Yqfo]                        d Z dZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZmZmZmZmZ ddlmZmZ ej        d         dk    ZereZneZdZ	 ddlmZ d	 ZeZn# e$ r d
 ZeZY nw xY w G d de          Z  G d de           Z! G d de           Z"d Z#d Z$d Z%d Z&d Z'd Z(d Z)d Z*d Z+ G d de,          Z-d Z.d Z/d Z0d Z1d  Z2d! Z3d" Z4e2e3ca5a6g d#Z7dS )$a  
Pyperclip

A cross-platform clipboard module for Python, with copy & paste functions for plain text.
By Al Sweigart al@inventwithpython.com
BSD License

Usage:
  import pyperclip
  pyperclip.copy('The text to be copied to the clipboard.')
  spam = pyperclip.paste()

  if not pyperclip.is_available():
    print("Copy functionality unavailable!")

On Windows, no additional modules are needed.
On Mac, the pyobjc module is used, falling back to the pbcopy and pbpaste cli
    commands. (These commands should come with OS X.).
On Linux, install xclip, xsel, or wl-clipboard (for "wayland" sessions) via package manager.
For example, in Debian:
    sudo apt-get install xclip
    sudo apt-get install xsel
    sudo apt-get install wl-clipboard

Otherwise on Linux, you will need the qtpy or PyQt5 modules installed.

This module does not work with PyGObject yet.

Cygwin is currently not supported.

Security Note: This module runs programs with these names:
    - which
    - pbcopy
    - pbpaste
    - xclip
    - xsel
    - wl-copy/wl-paste
    - klipper
    - qdbus
A malicious user could rename or add programs with these names, tricking
Pyperclip into running them with whatever permissions the Python process has.

z1.9.0    N)c_size_tsizeof	c_wchar_p	get_errnoc_wchar)UnionOptional   utf-8)whichc                 :    t          t          |                     S N)boolr   names    U/var/www/api.educacionweb.es/myenv/lib/python3.11/site-packages/pyperclip/__init__.py_py3_executable_existsr   J   s    E$KK       c                 d    t          j        d| gt           j        t           j                  dk    S )Nr   )stdoutstderrr   )
subprocesscallPIPEr   s    r   _py2_executable_existsr   O   s7    #-?:?L L LOPQ 	Qr   c                       e Zd ZdS )PyperclipExceptionN__name__
__module____qualname__ r   r   r   r   U           Dr   r   c                        e Zd Z fdZ xZS )PyperclipWindowsExceptionc                     |dt          j                    z  z  }t          t          |                               |           d S )Nz (%s))ctypesWinErrorsuperr%   __init__)selfmessage	__class__s     r   r*   z"PyperclipWindowsException.__init__Y   s?    7V_....'..77@@@@@r   )r   r    r!   r*   __classcell__r-   s   @r   r%   r%   X   sA        A A A A A A A A Ar   r%   c                       e Zd ZdS )PyperclipTimeoutExceptionNr   r"   r   r   r1   r1   ]   r#   r   r1   c                      d } d }| |fS )Nc                     t          |           } t          j        ddgt          j        d          }|                    |                     t                               d S )NpbcopywTstdin	close_fdsinput_PYTHON_STR_TYPEr   Popenr   communicateencodeENCODINGtextps     r   copy_osx_pbcopyz2init_osx_pbcopy_clipboard.<locals>.copy_osx_pbcopyb   s\    %%h_#-?dD D D	DKK1122222r   c                      t          j        ddgt           j        d          } |                                 \  }}|                    t
                    S )NpbpasterTr   r8   r   r=   r   r>   decoder@   )rC   r   r   s      r   paste_osx_pbcopyz3init_osx_pbcopy_clipboard.<locals>.paste_osx_pbcopyh   sM    i-$.OtE E E}}X&&&r   r"   )rD   rK   s     r   init_osx_pbcopy_clipboardrL   a   s.    3 3 3' ' ' ,,,r   c                      d } d }| |fS )Nc                    t          |           } t          j                            |                                           }|                    t          j                  }t          j        	                                }|
                    t          j        gd           |                    |t          j                   dS )z!Copy string argument to clipboardN)r<   
FoundationNSStringstringWithString_nsstringdataUsingEncoding_NSUTF8StringEncodingAppKitNSPasteboardgeneralPasteboarddeclareTypes_owner_NSStringPboardTypesetData_forType_)rB   newStrnewDataboards       r   copy_osx_pyobjcz2init_osx_pyobjc_clipboard.<locals>.copy_osx_pyobjcr   s    %%$66t<<EEGG++J,KLL#5577!!6#<"=tDDDw(ABBBBBr   c                      t           j                                        } |                     t           j                  }|S )zReturns contents of clipboard)rU   rV   rW   stringForType_rY   )r]   contents     r   paste_osx_pyobjcz3init_osx_pyobjc_clipboard.<locals>.paste_osx_pyobjc{   s1    #5577&&v'@AAr   r"   )r^   rb   s     r   init_osx_pyobjc_clipboardrc   q   s1    C C C   ,,,r   c                      	 ddl ma n#  ddlma Y nxY wt                                          t          g           fd} fd}| |fS )Nr   )QApplicationc                 x    t          |           }                                 }|                    |            d S r   )r<   	clipboardsetText)rB   cbapps     r   copy_qtz"init_qt_clipboard.<locals>.copy_qt   s5    %%]]__


4r   c                  n                                     } t          |                                           S r   )rg   r<   rB   )ri   rj   s    r   paste_qtz#init_qt_clipboard.<locals>.paste_qt   s&    ]]__		***r   )qtpy.QtWidgetsre   PyQt5.QtWidgetsinstance)rk   rm   rj   s     @r   init_qt_clipboardrq      s    
1///////100000000



!
!C
{2    
+ + + + + Hs   
 c                  2    dddfd	} dfd	}| |fS )NcrC   Fc                     t          |           } }|r}t          j        dd|gt          j        d          }|                    |                     t                               d S )Nxclip
-selectionTr6   r9   r;   )rB   primary	selectionrC   DEFAULT_SELECTIONPRIMARY_SELECTIONs       r   
copy_xclipz(init_xclip_clipboard.<locals>.copy_xclip   sr    %%#	 	('Ig|Y?#-?dD D D	DKK1122222r   c                     }| r}t          j        dd|dgt           j        t           j        d          }|                                \  }}|                    t
                    S )Nru   rv   -oTr   r   r8   rI   )rw   rx   rC   r   r   ry   rz   s        r   paste_xclipz)init_xclip_clipboard.<locals>.paste_xclip   si    #	 	('Ig|YE$.O$.O'+- - - }}X&&&r   Fr"   )r{   r   ry   rz   s     @@r   init_xclip_clipboardr      sc    3 3 3 3 3 3 3
' 
' 
' 
' 
' 
' 
' {""r   c                  2    dddfd	} dfd	}| |fS )Nz-b-pFc                     t          |           } }|r}t          j        d|dgt          j        d          }|                    |                     t                               d S )Nxselz-iTr6   r9   r;   )rB   rw   selection_flagrC   ry   rz   s       r   	copy_xselz&init_xsel_clipboard.<locals>.copy_xsel   sr    %%* 	/.Nfnd;#-?dD D D	DKK1122222r   c                     }| r}t          j        d|dgt           j        d          }|                                \  }}|                    t
                    S )Nr   r}   TrH   rI   )rw   r   rC   r   r   ry   rz   s        r   
paste_xselz'init_xsel_clipboard.<locals>.paste_xsel   sb    * 	/.Nfnd;$.OtE E E}}X&&&r   r   r"   )r   r   ry   rz   s     @@r   init_xsel_clipboardr      sc    3 3 3 3 3 3 3' ' ' ' ' ' ' j  r   c                  (    ddfd	} dfd	}| |fS )Nr   Fc                 X   t          |           } dg}|r|                               | s-|                    d           t          j        |d           d S 	 t          j        |t          j        d          }|                    |                     t                               d S )Nwl-copyz--clearT)r8   r6   r9   )	r<   appendr   
check_callr=   r   r>   r?   r@   )rB   rw   argsrC   rz   s       r   copy_wlz"init_wl_clipboard.<locals>.copy_wl   s    %%{ 	+KK)*** 	7KK	"""!$$777777 Z_MMMAMMH 5 5M66666r   c                     g d}| r|                                t          j        |t          j        d          }|                                \  }}|                    t                    S )N)wl-pastez-nz-trB   TrH   )r   r   r=   r   r>   rJ   r@   )rw   r   rC   r   _stderrrz   s        r   paste_wlz#init_wl_clipboard.<locals>.paste_wl   se    /// 	+KK)***T*/TJJJ--//}}X&&&r   r   r"   )r   r   rz   s     @r   init_wl_clipboardr      sR    7 7 7 7 7 7' ' ' ' ' ' Hr   c                      d } d }| |fS )Nc           	          t          |           } t          j        dddd|                     t                    gt          j        d          }|                    d            d S )Nqdbusorg.kde.klipper/klippersetClipboardContentsTr6   r9   )r<   r   r=   r?   r@   r   r>   rA   s     r   copy_klipperz,init_klipper_clipboard.<locals>.copy_klipper   sh    %%'5K[[""$/T3 3 3 	
D!!!!!r   c                  D   t          j        g dt           j        d          } |                                 \  }}|                    t
                    }t          |          dk    sJ |                    d          sJ |                    d          r
|d d         }|S )N)r   r   r   getClipboardContentsTrH   r   
)r   r=   r   r>   rJ   r@   lenendswith)rC   r   r   clipboardContentss       r   paste_klipperz-init_klipper_clipboard.<locals>.paste_klipper   s    LLL?d4 4 4  #MM(33$%%)))) ))$/////%%d++ 	7 1#2# 6  r   r"   )r   r   s     r   init_klipper_clipboardr      s-    " " "! ! !" &&r   c                      d } d }| |fS )Nc                     t          |           } | dk    rt          j        d           d| v rt          j        d           t          dd          }|                    |            |                                 d S )N z]Pyperclip cannot copy a blank string to the clipboard on Cygwin. This is effectively a no-op.z0Pyperclip cannot handle \r characters on Cygwin./dev/clipboardwt)r<   warningswarnopenwriteclose)rB   fos     r   copy_dev_clipboardz8init_dev_clipboard_clipboard.<locals>.copy_dev_clipboard  ss    %%2::Myzzz4<<MMNNN"D))






r   c                  v    t          dd          } |                                 }|                                  |S )Nr   rt)r   readr   )r   ra   s     r   paste_dev_clipboardz9init_dev_clipboard_clipboard.<locals>.paste_dev_clipboard  s1    "D))''))



r   r"   )r   r   s     r   init_dev_clipboard_clipboardr     s.    	 	 	   222r   c                  P     G d dt                     }  |              |             fS )Nc                   (    e Zd Zd Zerd ZdS d ZdS )/init_no_clipboard.<locals>.ClipboardUnavailablec                 N    d}t           j        dk    rd}t          d|z             )Nr   linuxzx
On Linux, you can run `sudo apt-get install xclip` or `sudo apt-get install xselect` to install a copy/paste mechanism.zPyperclip could not find a copy/paste mechanism for your system. For more information, please visit https://pyperclip.readthedocs.io/en/latest/index.html#not-implemented-error)sysplatformr   )r+   r   kwargsadditionalInfos       r   __call__z8init_no_clipboard.<locals>.ClipboardUnavailable.__call__#  sD    N|w&& "]$  &W  Zh  &h  i  i  ir   c                     dS NFr"   r+   s    r   __nonzero__z;init_no_clipboard.<locals>.ClipboardUnavailable.__nonzero__*      ur   c                     dS r   r"   r   s    r   __bool__z8init_no_clipboard.<locals>.ClipboardUnavailable.__bool__-  r   r   N)r   r    r!   r   _IS_RUNNING_PYTHON_2r   r   r"   r   r   ClipboardUnavailabler   !  sX        	i 	i 	i   	        r   r   )object)r   s    r   init_no_clipboardr      sL        v     !!#7#7#9#999r   c                   *     e Zd Z fdZd Zd Z xZS )CheckedCallc                 Z    t          t          |                               d|           d S )Nf)r)   r   __setattr__)r+   r   r-   s     r   r*   zCheckedCall.__init__7  s)    k4  ,,S!44444r   c                 r     | j         | }|s*t                      rt          d| j         j        z             |S )NzError calling )r   r   r%   r   )r+   r   rets      r   r   zCheckedCall.__call__:  sA    dfdm 	Py{{ 	P+,<tv,NOOO
r   c                 2    t          | j        ||           d S r   )setattrr   )r+   keyvalues      r   r   zCheckedCall.__setattr__@  s    U#####r   )r   r    r!   r*   r   r   r.   r/   s   @r   r   r   6  sV        5 5 5 5 5  $ $ $ $ $ $ $r   r   c                    	
 ddl mamamamamamamamam	a	m
a
ma t          j        } t          j        d          }t          | j        j                  	t          t          t          t          t
          t
          t
          t
          t          t          t          t          g	_        t          	_        t          | j        j                  
t          g
_        t          
_        | j        j        t          g_        t          _        t          | j        j                  g _        t          _        t          | j        j                  g _        t          _        t          | j        j                  t          g_        t          _        t          | j        j                  t          t          g_        t          _        t          | j        j                  t          t8          g_        t          _        t          | j        j                  t          g_        t          _        t          | j        j                  t          g_        t          _        t          |j                  t@          g_        t          _        ddtB          j"        	
fd            tB          j"        fd            f
d}fd	}||fS )
Nr   )HGLOBALLPVOIDDWORDLPCSTRINTHWND	HINSTANCEHMENUBOOLUINTHANDLEmsvcrtr
      c               3   x   K    dddddddddddd          } 	 | V   |            dS #  |            w xY w)z=
        Context that provides a valid Windows hwnd.
        r   s   STATICNr"   )hwndsafeCreateWindowExAsafeDestroyWindows    r   windowz&init_windows_clipboard.<locals>.window|  sq       #"1iq!Q1#'tT; ;	$JJJd#####d####s   , 9c              3   :  K   t          j                     dz   }d}t          j                     |k     r9 |           }|rn+t          j        d           t          j                     |k     9|st          d          	 dV                dS #               w xY w)z
        Context manager that opens the clipboard and prevents
        other applications from modifying the clipboard content.
        g      ?Fg{Gz?zError calling OpenClipboardN)timesleepr%   )r   tsuccessOpenClipboardsafeCloseClipboards      r   rg   z)init_windows_clipboard.<locals>.clipboard  s       IKK#ikkAoo#mD))G Jt	 ikkAoo
  	K+,IJJJ	!EEE         s   >B Bc           
        
 t          |           }              5 } |          5                | r |           dz   } 	|t          t                    z            } 
|          }t          j        t          |          t          |           |t          t                    z              |            |           d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )N   )r<   r   r   r'   memmover   )rB   r   counthandlelocked_handleCF_UNICODETEXTGMEM_MOVEABLErg   safeEmptyClipboardsafeGlobalAllocsafeGlobalLocksafeGlobalUnlocksafeSetClipboardDatawcslenr   s        r   copy_windowsz,init_windows_clipboard.<locals>.copy_windows  s     %%VXX 	A 4 A A""$$$ A
 #F4LL1,E,_]-2VG__-DF FF$2N6$:$:MN9]#;#;Yt__eV\]dVeVeNefff$$V,,,((@@@!A A A A A A A A A A A A A A A	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	A 	As5   C.B#C
C.C	C.C	C..C25C2c                       d           5             } | s	 d d d            dS  |           }t          |          j        } |            |cd d d            S # 1 swxY w Y   d S )Nr   )r   r   )r   r   return_valuer   rg   safeGetClipboardDatar   r   s      r   paste_windowsz-init_windows_clipboard.<locals>.paste_windows  s    Yt__ 	  	 )).99F 
 	  	  	  	  	  	  	  	  +N622M$]339LV$$$	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 s   A!+A!!A%(A%)#ctypes.wintypesr   r   r   r   r   r   r   r   r   r   r   r'   windllCDLLr   user32CreateWindowExAargtypesrestypeDestroyWindowr   CloseClipboardEmptyClipboardGetClipboardDataSetClipboardDatakernel32GlobalAllocr   
GlobalLockGlobalUnlockr   r   
contextlibcontextmanager)r  r   r  r  r   r   r   rg   r   r   r   r   r  r   r   r   r   r   r   s       @@@@@@@@@@@@@@@r   init_windows_clipboardr  D  sg   G G G G G G G G G G G G G G G G G G G G G G G G G G ]F[""F%fm&CDD$)665#s$'dE9f$N "&#FM$?@@"& $M/M"VM M$V]%ABB"$!%$V]%ABB"$!%&v}'EFF%)F!#) &v}'EFF%)6N!#) !&/"=>>O $h/O%O !;<<N&iN#N"6?#?@@!(	#''F kFOFNMN$ $ $ $ $ $ ! ! ! ! ! !.A A A A A A A A A A A A A A<                  &&r   c                      d } d }| |fS )Nc                     t          |           } t          j        dgt          j        d          }|                    |                     d                     d S )Nzclip.exeTr6   zutf-16ler9   )r<   r   r=   r   r>   r?   rA   s     r   copy_wslz$init_wsl_clipboard.<locals>.copy_wsl  sZ    %%j\#-?dD D D	DKK
3344444r   c                     d} t          j        ddd| gt           j        t           j        d          }|                                \  }}|rt	          d|           	 |                    d                                          }t          j        |          }|                    d          S # t          $ r}t          d	|           d }~ww xY w)
NzO[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes((Get-Clipboard -Raw)))zpowershell.exez
-noprofilez-commandTr~   zError pasting from clipboard: r   zDecoding error: )
r   r=   r   r>   	ExceptionrJ   stripbase64	b64decodeRuntimeError)	ps_scriptrC   r   r   base64_encodeddecoded_byteses          r   	paste_wslz%init_wsl_clipboard.<locals>.paste_wsl  s    e	 .j)T$.O$.O'+- - -  	GEVEEFFF	7#]]73399;;N",^<<M ''000 	7 	7 	75!55666	7s   AB/ /
C9CCr"   )r  r&  s     r   init_wsl_clipboardr'    s-    5 5 57 7 7( Yr   c                  T   dt          j                                                    v rBt          j                            d          r"t          j        d           t                      S n5t          j	        dk    st          j                    dk    rt                      S t          j                    dk    rt          j                            d          rkt          dd          5 } d	|                                                                 v rt                      cd
d
d
           S 	 d
d
d
           n# 1 swxY w Y   t          j	        dk    st          j                    dk    r5	 dd
ladd
lat#                      S # t$          $ r t'                      cY S w xY wt          j        d          r,t+          d          rt+          d          rt-                      S t          j        d          rt+          d          rt/                      S t+          d          rt1                      S t+          d          rt+          d          rt3                      S 	 dd
lat7                      S # t$          $ r Y nw xY w	 dd
lat7                      S # t$          $ r Y nw xY wt;                      S )z]
    Determine the OS/platform and set the copy() and paste() functions
    accordingly.
    cygwinr   zcPyperclip's support for Cygwin is not perfect, see https://github.com/asweigart/pyperclip/issues/55ntWindowsLinuxz/proc/versionrG   	microsoftNmacDarwinr   WAYLAND_DISPLAYr   r   DISPLAYru   r   klipperr   )r   systemlowerospathexistsr   r   r   r   r  isfiler   r   r'  rO   rU   rc   ImportErrorrL   getenv_executable_existsr   r   r   r   qtpyrq   PyQt5r   )r   s    r   determine_clipboardr>    s$    8?$$**,,,, 7>>*++ 	2M  A  B  B  B/111	2
 
DHO--::%'''G##(G(G#/3'' 	,1affhhnn....)++	, 	, 	, 	, 	, 	, 	, 	,.	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,
 
w%8?,,88	/MMM -...  	/ 	/ 	/,.....	/ 
y"## (:9(E(E K]^hKiKi  """
 
9		 g&& 	*')))f%% 	)&(((i(( 	,-?-H-H 	,)+++	 KKK$&&& 	 	 	D		LLL$&&& 	 	 	D	 sH   %6D55D9<D9(E> >FFI) )
I65I6:J 
JJc           
      (   t           t          t          t          t          t
          t          t          t          d	}| |vrAt          dd
                    d |                                D                       z             ||                      \  aadS )a  
    Explicitly sets the clipboard mechanism. The "clipboard mechanism" is how
    the copy() and paste() functions interact with the operating system to
    implement the copy/paste feature. The clipboard parameter must be one of:
        - pbcopy
        - pbobjc (default on Mac OS X)
        - qt
        - xclip
        - xsel
        - klipper
        - windows (default on Windows)
        - no (this is what is set when no clipboard mechanism can be found)
    )	r4   pyobjcqtru   r   zwl-clipboardr2  windowsnozArgument must be one of %sz, c                 ,    g | ]}t          |          S r"   )repr).0_s     r   
<listcomp>z!set_clipboard.<locals>.<listcomp>U  s    ClClClPQDGGClClClr   N)rL   rc   rq   r   r   r   r   r  r   
ValueErrorjoinkeyscopypaste)rg   clipboard_typess     r   set_clipboardrO  8  s    " ,+%#)))
 
O ''5ClClUdUiUiUkUkClClCl9m9mnooo -/),..KD%%%r   c                 B    t                      \  aat          |           S )aD  
    A stub function for copy(), which will load the real copy() function when
    called so that the real copy() function is used for later calls.

    This allows users to import pyperclip without having determine_clipboard()
    automatically run, which will automatically select a clipboard mechanism.
    This could be a problem if it selects, say, the memory-heavy PyQt5 module
    but the user was just going to immediately call set_clipboard() to use a
    different clipboard mechanism.

    The lazy loading this stub function implements gives the user a chance to
    call set_clipboard() to pick another clipboard mechanism. Or, if the user
    simply calls copy() or paste() without calling set_clipboard() first,
    will fall back on whatever clipboard mechanism that determine_clipboard()
    automatically chooses.
    r>  rL  rM  )rB   s    r   lazy_load_stub_copyrR  [  s    $ &''KD%::r   c                  @    t                      \  aat                      S )aG  
    A stub function for paste(), which will load the real paste() function when
    called so that the real paste() function is used for later calls.

    This allows users to import pyperclip without having determine_clipboard()
    automatically run, which will automatically select a clipboard mechanism.
    This could be a problem if it selects, say, the memory-heavy PyQt5 module
    but the user was just going to immediately call set_clipboard() to use a
    different clipboard mechanism.

    The lazy loading this stub function implements gives the user a chance to
    call set_clipboard() to pick another clipboard mechanism. Or, if the user
    simply calls copy() or paste() without calling set_clipboard() first,
    will fall back on whatever clipboard mechanism that determine_clipboard()
    automatically chooses.
    rQ  r"   r   r   lazy_load_stub_pasterT  q  s    $ &''KD%77Nr   c                  B    t           t          k    ot          t          k    S r   )rL  rR  rM  rT  r"   r   r   is_availablerV    s    &&H54H+HHr   )rL  rM  rO  r>  )8__doc____version__r  r  r'   r5  r   r   r   r   r   r   r   r   r   r   typingr   r	   version_infor   unicoder<   strr@   shutilr   r   r;  r9  r   r!  r   r%   r1   rL   rc   rq   r   r   r   r   r   r   r   r   r  r'  r>  rO  rR  rT  rV  rL  rM  __all__r"   r   r   <module>r_     s  * *V        				      



   B B B B B B B B B B B B B B " " " " " " " " '*a/   0! ! !/ 0 0 0Q Q Q 00	 	 	 	 	 	 	 	A A A A A 2 A A A
	 	 	 	 	 2 	 	 	- - - - - -&  4# # #8! ! !2  6' ' ':3 3 3*: : :,$ $ $ $ $& $ $ $J' J' J'Z  @D D DN /  /  /F  ,  ,I I I "#7e D
C
Cs   A& &
A32A3