
    ;OOfe                        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m
Z
mZmZmZmZ  ej                  dd      ZdZej$                  d   dk(  ZereneZd	Z	 dd
lmZ  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*d Z+d Z, G d  d!e-      Z.d" Z/d# Z0d$ Z1d% Z2d& Z3d' Z4d( Z5e3e4ca6a7d,d)Z8d,d*Z9g d+Z:y# e$ r  ej8                         dk(  rdZndZd ZY w xY w)-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 gtk or PyQt5/PyQt4 modules installed.

gtk and PyQt4 modules are not available for Python 3,
and this module does not work with PyGObject yet.

Note: There seems to be a way to get gtk on Python 3, according to:
    https://askubuntu.com/questions/697397/python3-is-not-supporting-gtk-module

Cygwin is currently not supported.

Security Note: This module runs programs with these names:
    - which
    - where
    - 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.8.2    N)c_size_tsizeof	c_wchar_p	get_errnoc_wcharDISPLAYFz
    Pyperclip 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    zutf-8)whichWindowswherer
   c                 |    t        j                  t        | gt         j                  t         j                        dk(  S )N)stdoutstderrr   )
subprocesscall	WHICH_CMDPIPE)names    S/var/www/premiumrankchecker/venv/lib/python3.12/site-packages/pyperclip/__init__.py_executable_existsr   W   s2    	40#-??:??LOPQ 	Q    c                       e Zd Zy)PyperclipExceptionN__name__
__module____qualname__ r   r   r   r   ^       r   r   c                        e Zd Z fdZ xZS )PyperclipWindowsExceptionc                 `    |dt        j                         z  z  }t        t        |   |       y )Nz (%s))ctypesWinErrorsuperr!   __init__)selfmessage	__class__s     r   r&   z"PyperclipWindowsException.__init__b   s)    7V__...'7@r   )r   r   r   r&   __classcell__r)   s   @r   r!   r!   a   s    A Ar   r!   c                       e Zd Zy)PyperclipTimeoutExceptionNr   r   r   r   r-   r-   f   r   r   r-   c                     t         rt        t        t        t        t
        f}nt        t        t        t
        f}t        | |      s"t        d| j                  j                  z        t        |       S )NzLonly str, int, float, and bool values can be copied to the clipboard, not %s)PY2unicodestrintfloatbool
isinstancer   r)   r   STR_OR_UNICODE)textacceptedTypess     r   _stringifyTextr9   i   so    
 #sE48c5$/dM* !osw  tB  tB  tK  tK  "L  M  	M$r   c                      d } d }| |fS )Nc                     t        |       } t        j                  ddgt        j                  d      }|j	                  | j                  t                     y )NpbcopywTstdin	close_fdsinputr9   r   Popenr   communicateencodeENCODINGr7   ps     r   copy_osx_pbcopyz2init_osx_pbcopy_clipboard.<locals>.copy_osx_pbcopyu   sC    d#h_#-??dD	DKK12r   c                      t        j                  ddgt         j                  d      } | j                         \  }}|j	                  t
              S )NpbpasterTr   r@   r   rD   r   rE   decoderG   rI   r   r   s      r   paste_osx_pbcopyz3init_osx_pbcopy_clipboard.<locals>.paste_osx_pbcopy{   sA    i-$.OOtE}}X&&r   r   )rJ   rR   s     r   init_osx_pbcopy_clipboardrS   s   s    3' ,,,r   c                      d } d }| |fS )Nc                 p   t        |       } t        j                  j                  |       j	                         }|j                  t        j                        }t        j                  j                         }|j                  t        j                  gd       |j                  |t        j                         y)z!Copy string argument to clipboardN)r9   
FoundationNSStringstringWithString_nsstringdataUsingEncoding_NSUTF8StringEncodingAppKitNSPasteboardgeneralPasteboarddeclareTypes_owner_NSStringPboardTypesetData_forType_)r7   newStrnewDataboards       r   copy_osx_pyobjcz2init_osx_pyobjc_clipboard.<locals>.copy_osx_pyobjc   s    d#$$66t<EEG++J,K,KL##557!!6#<#<"=tDw(A(ABr   c                      t         j                  j                         } | j                  t         j                        }|S )zReturns contents of clipboard)r\   r]   r^   stringForType_r`   )rd   contents     r   paste_osx_pyobjcz3init_osx_pyobjc_clipboard.<locals>.paste_osx_pyobjc   s1    ##557&&v'@'@Ar   r   )re   ri   s     r   init_osx_pyobjc_clipboardrj      s    C ,,,r   c                      dd l a d } d }| |fS )Nr   c                     t        |       } t        j                         at        j	                  |        t        j                          y N)r9   gtk	Clipboardcbset_textstorer7   s    r   copy_gtkz$init_gtk_clipboard.<locals>.copy_gtk   s,    d#]]_
D

r   c                  P    t         j                         j                         } | y| S N )rn   ro   wait_for_text)clipboardContentss    r   	paste_gtkz%init_gtk_clipboard.<locals>.paste_gtk   s&    MMO99;$$$r   )rn   )rt   rz   s     r   init_gtk_clipboardr{      s    % Yr   c                      	 ddl ma t        j	                         t        g       fd} fd}| |fS #  	 ddlma n#  ddlma Y nxY wY HxY w)Nr   )QApplicationc                 ^    t        |       } j                         }|j                  |        y rm   )r9   	clipboardsetText)r7   rp   apps     r   copy_qtz"init_qt_clipboard.<locals>.copy_qt   s$    d#]]_


4r   c                  V    j                         } t        | j                               S rm   )r   r6   r7   )rp   r   s    r   paste_qtz#init_qt_clipboard.<locals>.paste_qt   s    ]]_bggi((r   )qtpy.QtWidgetsr}   PyQt5.QtWidgetsPyQt4.QtGuiinstance)r   r   r   s     @r   init_qt_clipboardr      sY    
1/ 


!C
{2
) H'1	14	10s    8 AAAA
Ac                  2    dddfd	} dfd	}| |fS )NcrI   c                     t        |       } }|r}t        j                  dd|gt        j                  d      }|j	                  | j                  t                     y )Nxclip
-selectionTr>   rA   rC   )r7   primary	selectionrI   DEFAULT_SELECTIONPRIMARY_SELECTIONs       r   
copy_xclipz(init_xclip_clipboard.<locals>.copy_xclip   sT    d##	'Ig|Y?#-??dD	DKK12r   c                     }| r}t        j                  dd|dgt         j                  t         j                  d      }|j                         \  }}|j	                  t
              S )Nr   r   -oTr   r   r@   rO   )r   r   rI   r   r   r   r   s        r   paste_xclipz)init_xclip_clipboard.<locals>.paste_xclip   s\    #	'Ig|YE$.OO$.OO'+- }}X&&r   Fr   )r   r   r   r   s     @@r   init_xclip_clipboardr      s&    3
' {""r   c                  2    dddfd	} dfd	}| |fS )Nz-b-pc                     t        |       } }|r}t        j                  d|dgt        j                  d      }|j	                  | j                  t                     y )Nxselz-iTr>   rA   rC   )r7   r   selection_flagrI   r   r   s       r   	copy_xselz&init_xsel_clipboard.<locals>.copy_xsel   sT    d#*.Nfnd;#-??dD	DKK12r   c                     }| r}t        j                  d|dgt         j                  d      }|j                         \  }}|j	                  t
              S )Nr   r   TrN   rO   )r   r   rI   r   r   r   r   s        r   
paste_xselz'init_xsel_clipboard.<locals>.paste_xsel   sQ    *.Nfnd;$.OOtE}}X&&r   r   r   )r   r   r   r   s     @@r   init_xsel_clipboardr      s&    3' j  r   c                  (    ddfd	} dfd	}| |fS )Nr   c                 6   t        |       } dg}|r|j                         | s)|j                  d       t        j                  |d       y 	 t        j                  |t        j
                  d      }|j                  | j                  t                     y )Nwl-copyz--clearT)r@   r>   rA   )	r9   appendr   
check_callrD   r   rE   rF   rG   )r7   r   argsrI   r   s       r   copy_wlz"init_wl_clipboard.<locals>.copy_wl  su    d#{KK)*KK	"!!$$7  Z__MAMMH 5M6r   c                     ddg}| r|j                         t        j                  |t        j                  d      }|j	                         \  }}|j                  t              S )Nzwl-pastez-nTrN   )r   r   rD   r   rE   rP   rG   )r   r   rI   r   _stderrr   s        r   paste_wlz#init_wl_clipboard.<locals>.paste_wl  sS    D!KK)*T*//TJ--/}}X&&r   r   r   )r   r   r   s     @r   init_wl_clipboardr      s     7' Hr   c                      d } d }| |fS )Nc           	          t        |       } t        j                  dddd| j                  t              gt        j
                  d      }|j                  d        y )Nqdbusorg.kde.klipper/klippersetClipboardContentsTr>   rA   )r9   r   rD   rF   rG   r   rE   rH   s     r   copy_klipperz,init_klipper_clipboard.<locals>.copy_klipper  sQ    d#'5K[["$//T3 	
D!r   c                     t        j                  g dt         j                  d      } | j                         \  }}|j	                  t
              }t        |      dkD  sJ |j                  d      sJ |j                  d      r|d d }|S )N)r   r   r   getClipboardContentsTrN   r   
)r   rD   r   rE   rP   rG   lenendswith)rI   r   r   ry   s       r   paste_klipperz-init_klipper_clipboard.<locals>.paste_klipper#  s    L??d4  #MM(3$%))) ))$///%%d+ 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      }|j	                  |        |j                          y )Nrw   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)r9   warningswarnopenwriteclose)r7   fos     r   copy_dev_clipboardz8init_dev_clipboard_clipboard.<locals>.copy_dev_clipboard8  sU    d#2:MMyz4<MMMN"D)


r   c                  ^    t        dd      } | j                         }| j                          |S )Nr   rt)r   readr   )r   rh   s     r   paste_dev_clipboardz9init_dev_clipboard_clipboard.<locals>.paste_dev_clipboardC  s(    "D)'')

r   r   )r   r   s     r   init_dev_clipboard_clipboardr   7  s    	 222r   c                  <     G d dt               }  |         |        fS )Nc                   $    e Zd Zd Zerd Zyd Zy)/init_no_clipboard.<locals>.ClipboardUnavailablec                      t        t              rm   )r   
EXCEPT_MSG)r'   r   kwargss      r   __call__z8init_no_clipboard.<locals>.ClipboardUnavailable.__call__O  s    $Z00r   c                      yNFr   r'   s    r   __nonzero__z;init_no_clipboard.<locals>.ClipboardUnavailable.__nonzero__S      r   c                      yr   r   r   s    r   __bool__z8init_no_clipboard.<locals>.ClipboardUnavailable.__bool__V  r   r   N)r   r   r   r   r/   r   r   r   r   r   ClipboardUnavailabler   M  s    	1 r   r   )object)r   s    r   init_no_clipboardr   L  s"    
v 
  !#7#999r   c                   *     e Zd Z fdZd Zd Z xZS )CheckedCallc                 .    t         t        |   d|       y )Nf)r%   r   __setattr__)r'   r   r)   s     r   r&   zCheckedCall.__init__`  s    k4,S!4r   c                      | 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__c  s6    dffdmy{+,<tvv,NOO
r   c                 2    t        | j                  ||       y rm   )setattrr   )r'   keyvalues      r   r   zCheckedCall.__setattr__i  s    U#r   )r   r   r   r&   r   r   r*   r+   s   @r   r   r   _  s    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                   j0                        t        g_        t        _        t        | j                   j2                        t        t        g_        t        _        t        | j4                  j6                        t        t8        g_        t        _        t        | j4                  j:                        t        g_        t        _        t        | j4                  j<                        t        g_        t        _        t        |j>                        t@        g_        t        _        ddtB        jD                  	
fd       tB        jD                  fd       f
d}fd	}||fS )
Nr   )HGLOBALLPVOIDDWORDLPCSTRINTHWND	HINSTANCEHMENUBOOLUINTHANDLEmsvcrtr	      c               3   h   K    dddddddddddd      } 	 |   |        y#  |        w xY ww)z=
        Context that provides a valid Windows hwnd.
        r   s   STATICNr   )hwndsafeCreateWindowExAsafeDestroyWindows    r   windowz&init_windows_clipboard.<locals>.window  sG      #1iq!Q1#'tT;	$Jd#d#s   2% 	2
/2c              3   (  K   t        j                          dz   }d}t        j                          |k  r8 |       }|rn-t        j                  d       t        j                          |k  r8|st        d      	 d          y#          w xY ww)z
        Context manager that opens the clipboard and prevents
        other applications from modifying the clipboard content.
        g      ?F{Gz?zError calling OpenClipboardN)timesleepr!   )r   tsuccessOpenClipboardsafeCloseClipboards      r   r   z)init_windows_clipboard.<locals>.clipboard  s|      IIK#iikAo#D)GJJt	 iikAo
 +,IJJ	!  s$   A(B,B:B >B	BBc           
        
 t        |       }         5 } |      5           | rv |       dz   } 	|t        t              z        } 
|      }t        j                  t        |      t        |       |t        t              z          |        |       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)N   )r9   r   r   r#   memmover   )r7   r   counthandlelocked_handleCF_UNICODETEXTGMEM_MOVEABLEr   safeEmptyClipboardsafeGlobalAllocsafeGlobalLocksafeGlobalUnlocksafeSetClipboardDatawcslenr   s        r   copy_windowsz,init_windows_clipboard.<locals>.copy_windows  s     d#X 	A 4 A"$
 #4L1,E,]-2VG_-DFF$26$:MNN9]#;Yt_eV\]dVeNef$V,(@!A	A 	AA A	A 	As#   	B:B B.B:.B7	3B::Cc                       d       5         } | s
	 d d d        yt        |       j                  cd d d        S # 1 sw Y   y xY wrv   )r   r   )r	  r  r   safeGetClipboardDatas    r   paste_windowsz-init_windows_clipboard.<locals>.paste_windows  sK    t_ 	+).9F
 	+ 	+ V$**	+ 	+ 	+s   ==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  r   r  r   r   r  r  r  r  r  r  r  r   s       @@@@@@@@@@@@@@@r   init_windows_clipboardr)  m  sU   G G G G ]]F[["F%fmm&C&CD$)665#s$'dE9f$N "&#FMM$?$?@"& $MM//M"VM M$V]]%A%AB"$!%$V]]%A%AB"$!%&v}}'E'EF%)F!#) &v}}'E'EF%)6N!#) !&//"="=>O $h/O%O !;!;<N&iN#N"6??#?#?@!(	#'F kFOFNMN$ $ ! !.A A<	+ &&r   c                      d } d }| |fS )Nc                     t        |       } t        j                  dgt        j                  d      }|j	                  | j                  t                     y )Nzclip.exeTr>   rA   rC   rH   s     r   copy_wslz$init_wsl_clipboard.<locals>.copy_wsl  sA    d#j\#-??dD	DKK12r   c                      t        j                  g dt         j                  t         j                  d      } | j                         \  }}|d d j	                  t
              S )N)zpowershell.exez-commandzGet-ClipboardTr   rO   rQ   s      r   	paste_wslz%init_wsl_clipboard.<locals>.paste_wsl  sN    L$.OO$.OO'+- cr{!!(++r   r   )r,  r/  s     r   init_wsl_clipboardr0    s    3, Yr   c                     dt        j                         j                         v r>t        j                  j                  d      rSt        j                  d       t               S t        j                  dk(  st        j                         dk(  r
t               S t        j                         dk(  rht        j                  j                  d      rIt        dd      5 } d	| j                         j                         v rt               cd
d
d
       S 	 d
d
d
       t        j                  dk(  st        j                         dk(  r	 dd
ladd
lat#               S t(        r	 dd
lat-               S tE               S # 1 sw Y   exY w# t$        $ r t'               cY S w xY w# t$        $ r Y nw xY wt        j.                  j1                  d      rt3        d      r
t5               S t3        d      r
t7               S t3        d      r
t9               S t3        d      rt3        d      r
t;               S 	 dd
lat?               S # t$        $ rN 	 dd
l a t?               cY S # t$        $ r% 	 dd
l!a!t?               cY cY S # t$        $ r Y nw xY wY nw xY wY tE               S w xY w)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ntr   Linuxz/proc/versionrM   	microsoftNmacDarwinr   WAYLAND_DISPLAYr   r   r   klipperr   )#platformsystemlowerospathexistsr   r   r   r   r)  isfiler   r   r0  rV   r\   rj   ImportErrorrS   HAS_DISPLAYrn   r{   environgetr   r   r   r   r   qtpyr   PyQt5PyQt4r   )r   s    r   determine_clipboardrH    s<    8??$**,, 77>>*+MM  A  B/11 
DHOO-:%''G#(G/3' 	,1affhnn..)+	, 	,.	,
 
ww%8??,8	/ -.. 	( &''F q	, 	,  	/,..	/  		 

01"9-$&&f%&((g&'))i(-?-H)++	'  %&&  	+
+ )**  //  -.. # 	/  #	+s   *E2E> F 2E;>FF	F#"F#%H3 3	J
=I
J
	I;I)
I;%J
)	I52I;4I55I;8J
:I;;J
	J
c                    t         t        t        t        t        t
        t        t        t        t        d
}| |vrBt        ddj                  |j                         D cg c]  }t        |       c}      z         ||           \  aayc c}w )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)
        - gtk
        - qt
        - xclip
        - xsel
        - klipper
        - windows (default on Windows)
        - no (this is what is set when no clipboard mechanism can be found)
    )
r<   pyobjcrn   qtr   r   zwl-clipboardr9  windowsnozArgument must be one of %sz, N)rS   rj   r{   r   r   r   r   r   r)  r   
ValueErrorjoinkeysreprcopypaste)r   clipboard_types_s      r   set_clipboardrV  [  s    $ ,+!%#)))O '5UdUiUiUkClPQDGCl9mnoo -/),.KD% Dms   B
c                 2    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 PyQt4 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.
    rH  rR  rS  rs   s    r   lazy_load_stub_copyrY    s    $ &'KD%:r   c                  0    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 PyQt4 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.
    rX  r   r   r   lazy_load_stub_paster[    s    $ &'KD%7Nr   c                  :    t         t        k7  xr t        t        k7  S rm   )rR  rY  rS  r[  r   r   r   is_availabler]    s    &&H54H+HHr   c                     t        j                          }	 t               }|dk7  r|S t        j                  d       | 4t        j                          || z   kD  rt        dt	        |       z   dz         ])a  This function call blocks until a non-empty text string exists on the
    clipboard. It returns this text.

    This function raises PyperclipTimeoutException if timeout was set to
    a number of seconds that has elapsed without non-empty text being put on
    the clipboard.rw   r   zwaitForPaste() timed out after 	 seconds.r   rS  r   r-   r1   )timeout	startTimeclipboardTexts      r   waitForPasterd    sn     		I
B  

4499;W1D#D+,MPST[P\,\_j,jkk r   c                     t        j                          }t               }	 t               }||k7  r|S t        j                  d       | 4t        j                          || z   kD  rt        dt	        |       z   dz         ])ad  This function call blocks until a new text string exists on the
    clipboard that is different from the text that was there when the function
    was first called. It returns this text.

    This function raises PyperclipTimeoutException if timeout was set to
    a number of seconds that has elapsed without non-empty text being put on
    the clipboard.r   z"waitForNewPaste() timed out after r_  r`  )ra  rb  originalTextcurrentTexts       r   waitForNewPasterh    su     		I7L
g,&

4499;W1D#D+,PSVW^S_,_bm,mnn r   )rR  rS  rd  rh  rV  rH  rm   );__doc____version__r'  r#   r=  r:  r   sysr   r   r   r   r   r   r   getenvrB  r   version_infor/   r0   r1   r6   rG   shutilr
   r   rA  r;  r   RuntimeErrorr   r!   r-   r9   rS   rj   r{   r   r   r   r   r   r   r   r   r   r)  r0  rH  rV  rY  r[  r]  rR  rS  rd  rh  __all__r   r   r   <module>rq     se  /`    	   
   B B bii	5)w
 
qQSQ2	 	A 2 A
	 2 	 -"-&,:#8!26':3*:&$& $G'T(M`"/J,,I "#7el$o( g[  	QxI%		Q	Qs   #C !D D