
    fNF                     :   d Z ddlZddlZddlZdZddlm	Z	m
Z
mZ ddlmZ ddlmZ ddlmZ ddlmZmZ dd	lmZ dd
lmZ eek    r edee          ej        dk    rddlmZ eZej        dk    rGej        dk    r< e ej                    j                            d          d                   dk     reZddlmZ m!Z"m#Z$m%Z& dqdZ'e'Z(i Z)d Z*ej        dk    r9ddlm+Z, ddlm-Z. i Z/d Z0e0j         r e*j         1                    dd          e0_         nej        dk    rddlm2Z, ddlm3Z3m4Z4m5Z5m6Z6m7Z7 ddlm8Z8m9Z9 ddlm:Z: dqdZ; G d d e:          Z< e;e<d!            G d" d#e:          Z= e;e=            G d$ d%e:          Z> e;e>            G d& d'e:          Z? e;e?            G d( d)e:          Z@ e;e@            ed*           ed+          k    re?ZAe@ZBn2 G d, d-e:          ZA e;eA            G d. d/e:          ZB e;eB            G d0 d1e:          ZC e;eC            G d2 d3e:          ZD e;eD            G d4 d5e:          ZE e3eE           e3eD          k    reDZE ed+           ed6          k    re?ZFe@ZGn2 G d7 d8e:          ZF e;eF            G d9 d:e:          ZG e;eG            G d; d<e:          ZHeHxeH_I        eH_J         e;eH            G d= d>e:          ZKeKxeK_I        eK_J         e;eK            G d? d@e:          ZLeLxeL_I        eL_J         e;eL            G dA dBe:          ZM e;eMd!            G dC dDe:          ZNeNZO e;eN            G dE dFe:          ZPddGlmQZQmRZRmSZS  G dH dIe:          ZT G dJ dKe:          ZUdL ZVdqdMZWdN ZXdO ZY G dP dQeZ          Z[ G dR dSe[          Z\ej        dk    r2 G dT dUe[          Z]ddVlm^Z^m:Z:  G dW dXe:          Z_ G dY dZe[          Z` G d[ d\eZ          Za eae[          Zb eae\          Zcej        dk    rDejd        e                    d]          dk    r& e\d^ejf        dd_         ejg        fz   z  d          ZhnPej        dk    r e\d`deji                  Zhn2ej        dak    r e\dbejf        dd_         z            Zhn e\d          Zhej        dk    r. eae]          Zj eae`          Zkejjl        jm        ZmddclmnZnmoZo drddZp e3eB           e3eN          k    reBZqeAZrn9 e3e@           e3eN          k    re@Zqe?Zrn e3eG           e3eN          k    reGZqeFZrddelmsZsmtZtmuZumvZv   e*eNeNeNeq          es          Zw  e*eNeNeAeq          et          Zxdf Zy  eye<eNe<e<          ev          Zzdg Z{  eye<eNeA          eu          Z|dsdiZ}	 ddjlm~Z~   eye<eNeA          e~          ZdsdkZn# e$ r Y nw xY wej        dk    rdl Zdm ZddnlmZmZ ddolmZmZ eKZeHZe=eAe?eFfD ]7Z e3e          d_k    reZ e3e          dpk    reZ& e3e          dk    reZ8e>eBe@eGfD ]7Z e3e          d_k    reZ e3e          dpk    reZ& e3e          dk    reZ8[ eV             dS )tz,create and manipulate C data types in Python    Nz1.1.0)Union	StructureArray)_Pointer)CFuncPtr)__version__)
RTLD_LOCALRTLD_GLOBAL)ArgumentErrorcalcsizezVersion number mismatchnt)FormatErrorposixdarwin.   )FUNCFLAG_CDECLFUNCFLAG_PYTHONAPIFUNCFLAG_USE_ERRNOFUNCFLAG_USE_LASTERRORc                 Z   t          | t                    rG|t          |           dz   }t          j        d| |           t
          |z  } |            }| |_        |S t          | t                    r,t          j        dd|            t
          | z  } |            }|S t          |           )zcreate_string_buffer(aBytes) -> character array
    create_string_buffer(anInteger) -> character array
    create_string_buffer(aBytes, anInteger) -> character array
    N   zctypes.create_string_buffer)	
isinstancebyteslen_sysauditc_charvalueint	TypeErrorinitsizebuftypebufs       $../lib/python3.11/ctypes/__init__.pycreate_string_bufferr)   0   s    
 $ <t99Q;D
0$===4-gii	
	D#		 
0$===4-gii

D//    c                 p    t           |                    dd          r
t          z  |                    dd          r
t          z  |r$t	          d|                                z            	 t           f         S # t          $ r Y nw xY w G  fddt                    }|t           f<   |S )a  CFUNCTYPE(restype, *argtypes,
                 use_errno=False, use_last_error=False) -> function prototype.

    restype: the result type
    argtypes: a sequence specifying the argument types

    The function prototype can be called in different ways to create a
    callable object:

    prototype(integer address) -> foreign function
    prototype(callable) -> create and return a C callable function from callable
    prototype(integer index, method name[, paramflags]) -> foreign function calling a COM method
    prototype((ordinal number, dll object)[, paramflags]) -> foreign function exported by ordinal
    prototype((function name, dll object)[, paramflags]) -> foreign function exported by name
    	use_errnoFuse_last_error!unexpected keyword argument(s) %sc                       e Zd Z ZZZdS ) CFUNCTYPE.<locals>.CFunctionTypeN__name__
__module____qualname__
_argtypes_	_restype__flags_argtypesflagsrestypes   r(   CFunctionTyper0   e   s        
	r*   r<   )	_FUNCFLAG_CDECLpop_FUNCFLAG_USE_ERRNO_FUNCFLAG_USE_LASTERROR
ValueErrorkeys_c_functype_cacheKeyError	_CFuncPtr)r;   r9   kwr<   r:   s   ``  @r(   	CFUNCTYPErG   H   s     E	vvk5!! %$$	vv&& )((	 J<rwwyyHIII '8U!;<<           	    5Bw%01   2B 
BB)LoadLibrary)FUNCFLAG_STDCALLc                 p    t           |                    dd          r
t          z  |                    dd          r
t          z  |r$t	          d|                                z            	 t           f         S # t          $ r Y nw xY w G  fddt                    }|t           f<   |S )Nr,   Fr-   r.   c                       e Zd Z ZZZdS )$WINFUNCTYPE.<locals>.WinFunctionTypeNr1   r8   s   r(   WinFunctionTyperM      s        !JIGGGr*   rN   )	_FUNCFLAG_STDCALLr>   r?   r@   rA   rB   _win_functype_cacherD   rE   )r;   r9   rF   rN   r:   s   ``  @r(   WINFUNCTYPErQ   q   s   !66+u%% 	)((E66"E** 	-,,E 	N@27799LMMM	&5'ABB 	 	 	D		 	 	 	 	 	 	 	 	i 	 	 	 ;JWh67rH   rG   rQ   )dlopen)sizeofbyref	addressof	alignmentresize)	get_errno	set_errno)_SimpleCDatac                     ddl m} || j        }t          |            ||          }}||k    rt	          d| ||fz            d S )Nr   r   z"sizeof(%s) wrong: %d instead of %d)structr   _type_rS   SystemError)typtypecoder   actualrequireds        r(   _check_sizerc      ss      :c{{HHX$6$6HF>12 3 3 	3 r*   c                   "     e Zd ZdZ fdZ xZS )	py_objectOc                     	 t                                                      S # t          $ r dt          |           j        z  cY S w xY w)Nz
%s(<NULL>))super__repr__rA   typer2   )self	__class__s    r(   ri   zpy_object.__repr__   sS    	677##%%% 	6 	6 	6$t**"55555	6s   # !AA)r2   r3   r4   r]   ri   __classcell__)rl   s   @r(   re   re      s=        F6 6 6 6 6 6 6 6 6r*   re   Pc                       e Zd ZdZdS )c_shorthNr2   r3   r4   r]    r*   r(   rp   rp              FFFr*   rp   c                       e Zd ZdZdS )c_ushortHNrr   rs   r*   r(   rv   rv      rt   r*   rv   c                       e Zd ZdZdS )c_longlNrr   rs   r*   r(   ry   ry      rt   r*   ry   c                       e Zd ZdZdS )c_ulongLNrr   rs   r*   r(   r|   r|      rt   r*   r|   irz   c                       e Zd ZdZdS )c_intr~   Nrr   rs   r*   r(   r   r              r*   r   c                       e Zd ZdZdS )c_uintINrr   rs   r*   r(   r   r      r   r*   r   c                       e Zd ZdZdS )c_floatfNrr   rs   r*   r(   r   r      rt   r*   r   c                       e Zd ZdZdS )c_doubledNrr   rs   r*   r(   r   r      rt   r*   r   c                       e Zd ZdZdS )c_longdoublegNrr   rs   r*   r(   r   r      rt   r*   r   qc                       e Zd ZdZdS )
c_longlongr   Nrr   rs   r*   r(   r   r      r   r*   r   c                       e Zd ZdZdS )c_ulonglongQNrr   rs   r*   r(   r   r      r   r*   r   c                       e Zd ZdZdS )c_ubyteBNrr   rs   r*   r(   r   r      rt   r*   r   c                       e Zd ZdZdS )c_bytebNrr   rs   r*   r(   r   r      rt   r*   r   c                       e Zd ZdZdS )r   cNrr   rs   r*   r(   r   r      rt   r*   r   c                       e Zd ZdZd ZdS )c_char_pzc                 `    | j         j        dt                              |           j        dS N()rl   r2   c_void_pfrom_bufferr    rk   s    r(   ri   zc_char_p.__repr__   /    >222H4H4H4N4N4T4T4TUUr*   Nr2   r3   r4   r]   ri   rs   r*   r(   r   r      -        FV V V V Vr*   r   c                       e Zd ZdZdS )r   rn   Nrr   rs   r*   r(   r   r      rt   r*   r   c                       e Zd ZdZdS )c_bool?Nrr   rs   r*   r(   r   r      rt   r*   r   )POINTERpointer_pointer_type_cachec                       e Zd ZdZd ZdS )	c_wchar_pZc                 `    | j         j        dt                              |           j        dS r   r   r   s    r(   ri   zc_wchar_p.__repr__  r   r*   Nr   rs   r*   r(   r   r      r   r*   r   c                       e Zd ZdZdS )c_wcharuNrr   rs   r*   r(   r   r     rt   r*   r   c                  Z   t          j                     t                                           t          j        dk    rt
                                           t          j        t          t                    _        t          j        t          t                    _        t          t           d <   d S )Nr   )r   clearrC   _osnamerP   r   
from_paramr   r   r   r   r   rs   r*   r(   _reset_cacher     sw    
x4!!###"+"6GG!)!4GFOO (r*   c                    t          | t                    r||Gt          t                    dk    rt	          d | D                       dz   }nt          |           dz   }t          j        d| |           t          |z  } |            }| |_        |S t          | t                    r,t          j        dd|            t          | z  } |            }|S t          |           )zcreate_unicode_buffer(aString) -> character array
    create_unicode_buffer(anInteger) -> character array
    create_unicode_buffer(aString, anInteger) -> character array
    N   c              3   D   K   | ]}t          |          d k    rdndV  dS )i  r   r   N)ord).0r   s     r(   	<genexpr>z(create_unicode_buffer.<locals>.<genexpr>  s4      EE1A11QEEEEEEr*   r   zctypes.create_unicode_buffer)r   strrS   r   sumr   r   r   r    r!   r"   r#   s       r(   create_unicode_bufferr     s    
 $ <g!## EEEEEEEI 4yy1}
14>>>D.gii	
	D#		 
14>>>D.gii

D//r*   c                     t          j        |d           t          d          t          |           t           vrt          d           | j        |           | t           |<   t           t          |           = d S )Nz%This type already exists in the cachezWhat's this???)r   getRuntimeErroridset_type)r   clss     r(   SetPointerTyper   1  sw    sD))5BCCC	'{{---+,,,GS&BwKK(((r*   c                     | |z  S Nrs   )r_   r   s     r(   ARRAYr   ;  s    9r*   c                   J    e Zd ZdZeZeZdZdZ	dZ
eddddfdZd Zd Zd	 ZdS )
CDLLa  An instance of this class represents a loaded dll/shared
    library, exporting functions using the standard C calling
    convention (named 'cdecl' on Windows).

    The exported functions can be accessed as attributes, or by
    indexing with the function name.  Examples:

    <obj>.qsort -> callable object
    <obj>['qsort'] -> callable object

    Calling the functions releases the Python GIL during the call and
    reacquires it afterwards.
    z<uninitialized>r   NFc                 *   	 | _          j        	|r
	t          z  	|r
	t          z  	t          j                            d          r8	 |r5|                    d          r d|v r|t          j	        t          j
        z  z  }t          j        dk    rA||}n<dd l}|j        }d|v sd|v r)|                     j                    _         ||j        z  } G 	 fdd	t                     }| _        |t%           j         |           _        d S | _        d S )
Naixr   z.a(r   r   /\c                   "    e Zd Z Zj        ZdS )CDLL.__init__.<locals>._FuncPtrN)r2   r3   r4   r7   _func_restype_r6   )r:   rk   s   r(   _FuncPtrr   r  s        G+IIIr*   r   )_name_func_flags_r?   r@   r   platform
startswithendswithr   RTLD_MEMBERRTLD_NOWr   r   !_LOAD_LIBRARY_SEARCH_DEFAULT_DIRS_getfullpathname!_LOAD_LIBRARY_SEARCH_DLL_LOAD_DIRrE   r   _dlopen_handle)
rk   r   modehandler,   r-   winmoder   r   r:   s
   `        @r(   __init__zCDLL.__init__V  sY    
! 	)((E 	-,,E=##E** 	;
  ;c** ;u}}#/CL8:8t"			;$;;$$,,!#!4!4TZ!@!@DJB@@D	, 	, 	, 	, 	, 	, 	, 	,y 	, 	, 	, !>"4:t44DLLL!DLLLr*   c                     d| j         j        | j        | j        t          j        dz  dz   z  t          |           t          j        dz  dz   z  fz  S )Nz<%s '%s', handle %x at %#x>r   r   )rl   r2   r   r   r   maxsizer   r   s    r(   ri   zCDLL.__repr__|  sN    ,'a!!344DLNQ./11 	1r*   c                     |                     d          r$|                    d          rt          |          |                     |          }t	          | ||           |S )N__)r   r   AttributeError__getitem__setattr)rk   r   funcs      r(   __getattr__zCDLL.__getattr__  sa    ??4   	'T]]4%8%8 	' &&&%%dD!!!r*   c                 l    |                      || f          }t          |t                    s||_        |S r   )r   r   r!   r2   )rk   name_or_ordinalr   s      r(   r   zCDLL.__getitem__  s6    }}ot455/3// 	,+DMr*   )r2   r3   r4   __doc__r=   r   r   r   r   r   r   DEFAULT_MODEr   ri   r   r   rs   r*   r(   r   r   A  s          #LNEGH".t  %$" $" $" $"L1 1 1      r*   r   c                       e Zd ZdZeez  ZdS )PyDLLzThis class represents the Python library itself.  It allows
    accessing Python API functions.  The GIL is not released, and
    Python exceptions are handled correctly.
    N)r2   r3   r4   r   r=   _FUNCFLAG_PYTHONAPIr   rs   r*   r(   r   r     s%          #%88LLLr*   r   c                       e Zd ZdZeZdS )WinDLLznThis class represents a dll exporting functions using the
        Windows stdcall calling convention.
        N)r2   r3   r4   r   rO   r   rs   r*   r(   r   r     s        	 	 )r*   r   )_check_HRESULTrZ   c                       e Zd ZdZeZdS )HRESULTrz   N)r2   r3   r4   r]   r   _check_retval_rs   r*   r(   r   r     s         (r*   r   c                       e Zd ZdZeZeZdS )OleDLLzThis class represents a dll exporting functions using the
        Windows stdcall calling convention, and returning HRESULT.
        HRESULT error values are automatically raised as OSError
        exceptions.
        N)r2   r3   r4   r   rO   r   r   r   rs   r*   r(   r  r    s$        	 	
 ) r*   r  c                   F    e Zd Zd Zd Zd Zd Z eej	                  Z
dS )LibraryLoaderc                     || _         d S r   _dlltype)rk   dlltypes     r(   r   zLibraryLoader.__init__  s    r*   c                     |d         dk    rt          |          |                     |          }t          | ||           |S )Nr   _)r   r  r   )rk   r   dlls      r(   r   zLibraryLoader.__getattr__  sE    7c>> &&&mmD!!dC   
r*   c                 "    t          | |          S r   )getattrrk   r   s     r(   r   zLibraryLoader.__getitem__  s    tT"""r*   c                 ,    |                      |          S r   r  r  s     r(   rI   zLibraryLoader.LoadLibrary  s    }}T"""r*   N)r2   r3   r4   r   r   r   rI   classmethod_typesGenericAlias__class_getitem__rs   r*   r(   r  r    sa               # # ## # # $F$788r*   r  GCCzlibpython%d.%d%s.dllr   z
python dllcygwinzlibpython%d.%d.dll)get_last_errorset_last_errorc                     | t                      } |!t          |                                           }t          d |d |           S r   )GetLastErrorr   stripOSError)codedescrs     r(   WinErrorr    sB    <>>D=%%++--EtUD$///r*   )_memmove_addr_memset_addr_string_at_addr
_cast_addrc                 6      G  fddt                     }|S )Nc                   "    e Zd Z ZZeez  ZdS )!PYFUNCTYPE.<locals>.CFunctionTypeN)r2   r3   r4   r5   r6   r=   r   r7   )r9   r;   s   r(   r<   r%    s$        
	!$77r*   r<   )rE   )r;   r9   r<   s   `` r(   
PYFUNCTYPEr&    sE    8 8 8 8 8 8 8 8	 8 8 8 r*   c                 $    t          | | |          S r   )_cast)objr_   s     r(   castr*    s    c3r*   c                 "    t          | |          S )zAstring_at(addr[, size]) -> string

    Return the string at addr.)
_string_atptrr%   s     r(   	string_atr0    s     c4   r*   )_wstring_at_addrc                 "    t          | |          S )zFwstring_at(addr[, size]) -> string

        Return the string at addr.)_wstring_atr.  s     r(   
wstring_atr4    s     3%%%r*   c                     	 t          dt                      t                      dg          }|                    | ||          S # t          $ r Y dS w xY w)Ncomtypes.server.inprocserver*i)
__import__globalslocalsDllGetClassObjectImportError)rclsidriidppvccoms       r(   r;  r;    se    	=<giiTWSXYYD ))&$<<<  	 	 	;;	s   +A 
AAc                      	 t          dt                      t                      dg          } n# t          $ r Y dS w xY w|                                 S )Nr6  r7  r   )r8  r9  r:  r<  DllCanUnloadNow)r@  s    r(   rB  rB  !  s]    	<giiTWSXYYDD 	 	 	11	##%%%s   +. 
<<)BigEndianStructureLittleEndianStructure)BigEndianUnionLittleEndianUnion   r   )NN)r+  )r   osr   sysr   typesr  r   _ctypesr   r   r   r   r   rE   _ctypes_versionr	   r
   r   r\   r   	_calcsize	Exceptionr   r   r   r   r!   unamereleasesplitr   r=   r   r   r   r?   r   r@   r)   c_bufferrC   rG   rI   r   rJ   rO   rP   rQ   replacerR   rS   rT   rU   rV   rW   rX   rY   rZ   rc   re   rp   rv   ry   r|   r   r   r   r   r   r   r   r   __ctype_le____ctype_be__r   r   r   r   c_voidpr   r   r   r   r   r   r   r   r   r   objectr   r   r   r   r   r  r  cdllpydllversionfindversion_infoabiflags	pythonapi	dllhandlewindlloledllkernel32r  r  r  r  c_size_t	c_ssize_tr  r   r!  r"  memmovememsetr&  r(  r*  r-  r0  r1  r3  r4  r<  r;  rB  ctypes._endianrC  rD  rE  rF  c_int8c_uint8kindc_int16c_int32c_int64c_uint16c_uint32c_uint64rs   r*   r(   <module>rq     s   2 2             + + + + + + + + + +       ) ) ) ) ) ) 2 2 2 2 2 2 + + + + + + + + ! ! ! ! ! ! ( ( ( ( ( (/!!
)-{O
L
LL8t######8w4=H44 s939;;$$S))!,--11"7 7 7 7 7 7 7 7 7 7 7 7   *   " " "H 8t......======  *  T'/77]SSX)))))) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ( ( ( ( ( ( ( (            
3 
3 
3 
36 6 6 6 6 6 6 6 Is       l    G       |    H       \    F       l    G   9S>>YYs^^##EFF       K       K    l    G       |    H       <   	6,66(++++L9S>>YYs^^##JKK    \   K
    l   
 K    l   .5 5 w+ G       \   ,2 2 f) F       \   ,2 2 f) F   V V V V V| V V V Hc       |   
 H       \    : 9 9 9 9 9 9 9 9 9V V V V V V V V
    l   	) 	) 	)   <) ) )  L L L L L6 L L L\9 9 9 9 9D 9 9 9 8t) ) ) ) ) ) ) ) 54444444( ( ( ( (, ( ( (! ! ! ! ! ! ! !9 9 9 9 9F 9 9 9& }Te8t))%00A55,0A"1"0EHX0XY[_``IIXlD$.99II	]h*T->rr-BBCCIIdI 8t]6""F]6""F?/L666666660 0 0 0 
6&>>VVH%%%%HIIVG__x((((HIIVKFF8,,,,HI M L L L L L L L L L L L <))Hh(
;
;M
J
J 
88Xuh	7	7	E	E   	>

9h	9==jII      4ZZ	8U33ODD
! ! ! !
&(((((( 9**Y%889IJJK& & & & &	  	 	 	D	 8t= = =& & & E D D D D D D D < < < < < < < < 

eVZ0 + +Dvd||qD''			dGG			dGvw4 , ,Dvd||qT((			tHH			tH s   W$ $W,+W,