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eDgD]@Ze1edhkreZn&e1ed|kreZne1edkreZqWxPeeEgD]@Ze1edhkreZn&e1ed|kreZne1edkreZqW[eTdS)z,create and manipulate C data types in PythonNz1.1.0)Union StructureArray)_Pointer)CFuncPtr) __version__) RTLD_LOCAL RTLD_GLOBAL) ArgumentError)calcsizezVersion number mismatchnt) FormatErrorposixdarwin.)FUNCFLAG_CDECLFUNCFLAG_PYTHONAPIFUNCFLAG_USE_ERRNOFUNCFLAG_USE_LASTERRORcCs^t|tr6|dkrt|d}t|}|}||_|St|trRt|}|}|St|dS)zcreate_string_buffer(aBytes) -> character array create_string_buffer(anInteger) -> character array create_string_buffer(aBytes, anInteger) -> character array N) isinstancebyteslenc_charvalueint TypeError)initsizebuftypebufr"'/usr/lib64/python3.6/ctypes/__init__.pycreate_string_buffer/s   r$cCs t||S)N)r$)rrr"r"r#c_bufferAsr%c st|jddrtO|jddr,tO|r@td|jytfStk rGfdddt}|tf<|SXdS)aCFUNCTYPE(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_errnoFuse_last_errorz!unexpected keyword argument(s) %scseZdZZZZdS)z CFUNCTYPE..CFunctionTypeN)__name__ __module__ __qualname__ _argtypes_ _restype__flags_r")argtypesflagsrestyper"r# CFunctionTypecsr1N) _FUNCFLAG_CDECLpop_FUNCFLAG_USE_ERRNO_FUNCFLAG_USE_LASTERROR ValueErrorkeys_c_functype_cacheKeyError _CFuncPtr)r0r.kwr1r")r.r/r0r# CFUNCTYPEIs  r<) LoadLibrary)FUNCFLAG_STDCALLc st|jddrtO|jddr,tO|r@td|jytfStk rGfdddt}|tf<|SXdS)Nr&Fr'z!unexpected keyword argument(s) %scseZdZZZZdS)z$WINFUNCTYPE..WinFunctionTypeN)r(r)r*r+r,r-r")r.r/r0r"r#WinFunctionType{sr?) _FUNCFLAG_STDCALLr3r4r5r6r7_win_functype_cacher9r:)r0r.r;r?r")r.r/r0r# WINFUNCTYPEos  rB)dlopen)sizeofbyref addressof alignmentresize) get_errno set_errno) _SimpleCDatacCsJddlm}|dkr|j}t|||}}||krFtd|||fdS)Nr)r z"sizeof(%s) wrong: %d instead of %d)structr _type_rD SystemError)typtypecoder ZactualZrequiredr"r"r# _check_sizes rQcs eZdZdZfddZZS) py_objectOc s.y tjStk r(dt|jSXdS)Nz %s())super__repr__r6typer()self) __class__r"r#rUs zpy_object.__repr__)r(r)r*rMrU __classcell__r"r")rXr#rRsrRPc@seZdZdZdS)c_shorthN)r(r)r*rMr"r"r"r#r[sr[c@seZdZdZdS)c_ushortHN)r(r)r*rMr"r"r"r#r]sr]c@seZdZdZdS)c_longlN)r(r)r*rMr"r"r"r#r_sr_c@seZdZdZdS)c_ulongLN)r(r)r*rMr"r"r"r#rasrair`c@seZdZdZdS)c_intrcN)r(r)r*rMr"r"r"r#rdsrdc@seZdZdZdS)c_uintIN)r(r)r*rMr"r"r"r#resrec@seZdZdZdS)c_floatfN)r(r)r*rMr"r"r"r#rgsrgc@seZdZdZdS)c_doubledN)r(r)r*rMr"r"r"r#risric@seZdZdZdS) c_longdoublegN)r(r)r*rMr"r"r"r#rksrkqc@seZdZdZdS) c_longlongrmN)r(r)r*rMr"r"r"r#rnsrnc@seZdZdZdS) c_ulonglongQN)r(r)r*rMr"r"r"r#rosroc@seZdZdZdS)c_ubyteBN)r(r)r*rMr"r"r"r#rqsrqc@seZdZdZdS)c_bytebN)r(r)r*rMr"r"r"r#rssrsc@seZdZdZdS)rcN)r(r)r*rMr"r"r"r#rsrc@seZdZdZddZdS)c_char_pzcCsd|jjtj|jfS)Nz%s(%s))rXr(c_void_p from_bufferr)rWr"r"r#rUszc_char_p.__repr__N)r(r)r*rMrUr"r"r"r#rvsrvc@seZdZdZdS)rxrZN)r(r)r*rMr"r"r"r#rxsrxc@seZdZdZdS)c_bool?N)r(r)r*rMr"r"r"r#rzsrz)POINTERpointer_pointer_type_cachec@seZdZdZddZdS) c_wchar_pZcCsd|jjtj|jfS)Nz%s(%s))rXr(rxryr)rWr"r"r#rUszc_wchar_p.__repr__N)r(r)r*rMrUr"r"r"r#rsrc@seZdZdZdS)c_wcharuN)r(r)r*rMr"r"r"r#rsrcCsFtjtjtjdkr"tjtjtt _t jtt _t td<dS)Nr ) r~clearr8_osnamerArZ from_paramr|rrvrrxr"r"r"r# _reset_caches   rcCs^t|tr6|dkrt|d}t|}|}||_|St|trRt|}|}|St|dS)zcreate_unicode_buffer(aString) -> character array create_unicode_buffer(anInteger) -> character array create_unicode_buffer(aString, anInteger) -> character array Nr)rstrrrrrr)rrr r!r"r"r#create_unicode_buffers   rcCsLtj|ddk rtdt|tkr,td|j||t|<tt|=dS)Nz%This type already exists in the cachezWhat's this???)r~get RuntimeErroridZset_type)r}clsr"r"r#SetPointerType"s  rcCs||S)Nr")rOrr"r"r#ARRAY,src@sNeZdZdZeZeZdZdZ dZ e dddfddZ dd Z d d Zd d ZdS)CDLLaAn 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: .qsort -> callable object ['qsort'] -> callable object Calling the functions releases the Python GIL during the call and reacquires it afterwards. zrNFcsb|_j|rtO|r$tOGfdddt}|_|dkrXtj|_n|_dS)NcseZdZZjZdS)zCDLL.__init__.._FuncPtrN)r(r)r*r-_func_restype_r,r")r/rWr"r#_FuncPtrQsr)_name _func_flags_r4r5r:r_dlopen_handle)rWrmodeZhandler&r'rr")r/rWr#__init__Gsz CDLL.__init__cCs8d|jj|j|jtjdd@t|tjdd@fS)Nz<%s '%s', handle %x at %#x>r)rXr(rr_sysmaxsizer)rWr"r"r#rU[s z CDLL.__repr__cCs6|jdr|jdrt||j|}t||||S)N__) startswithendswithAttributeError __getitem__setattr)rWrfuncr"r"r# __getattr__as   zCDLL.__getattr__cCs"|j||f}t|ts||_|S)N)rrrr()rWZname_or_ordinalrr"r"r#rhs zCDLL.__getitem__)r(r)r*__doc__r2rrdrrrr DEFAULT_MODErrUrrr"r"r"r#r2s  rc@seZdZdZeeBZdS)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)r(r)r*rr2_FUNCFLAG_PYTHONAPIrr"r"r"r#rnsrc@seZdZdZeZdS)WinDLLznThis class represents a dll exporting functions using the Windows stdcall calling convention. N)r(r)r*rr@rr"r"r"r#rwsr)_check_HRESULTrKc@seZdZdZeZdS)HRESULTr`N)r(r)r*rMrZ_check_retval_r"r"r"r#rs rc@seZdZdZeZeZdS)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)r(r)r*rr@rrrr"r"r"r#rsrc@s,eZdZddZddZddZddZd S) LibraryLoadercCs ||_dS)N)_dlltype)rWZdlltyper"r"r#rszLibraryLoader.__init__cCs.|ddkrt||j|}t||||S)Nr_)rrr)rWrZdllr"r"r#rs    zLibraryLoader.__getattr__cCs t||S)N)getattr)rWrr"r"r#rszLibraryLoader.__getitem__cCs |j|S)N)r)rWrr"r"r#r=szLibraryLoader.LoadLibraryN)r(r)r*rrrr=r"r"r"r#rsrz python dllcygwinzlibpython%d.%d.dllr)get_last_errorset_last_errorcCs0|dkrt}|dkr"t|j}td|d|S)N) GetLastErrorr stripOSError)codeZdescrr"r"r#WinErrors  r) _memmove_addr _memset_addr_string_at_addr _cast_addrcsGfdddt}|S)NcseZdZZZeeBZdS)z!PYFUNCTYPE..CFunctionTypeN)r(r)r*r+r,r2rr-r")r.r0r"r#r1sr1)r:)r0r.r1r")r.r0r# PYFUNCTYPEsrcCs t|||S)N)_cast)objrOr"r"r#castsrrcCs t||S)zAstring_at(addr[, size]) -> string Return the string at addr.) _string_at)ptrrr"r"r# string_atsr)_wstring_at_addrcCs t||S)zFwstring_at(addr[, size]) -> string Return the string at addr.) _wstring_at)rrr"r"r# wstring_atsrc Cs@ytdttdg}Wntk r,dSX|j|||SdS)Nzcomtypes.server.inprocserver*ii) __import__globalslocals ImportErrorDllGetClassObject)ZrclsidZriidZppvccomr"r"r#rs rc Cs6ytdttdg}Wntk r,dSX|jS)Nzcomtypes.server.inprocserverrr)rrrrDllCanUnloadNow)rr"r"r#rs r)BigEndianStructureLittleEndianStructure)N)N)N)N)NN)rr)r)rosrsysrrZ_ctypesrrrrrr:Z_ctypes_versionrr r rLr Z _calcsize Exceptionrr rplatformrunamereleasesplitrr2rrrr4rr5r$r%r8r<r=rr>r@rArBreplacerCrDrErFrGrHrIrJrKrQrRr[r]r_rardrergrirkrnrorqZ __ctype_le__Z __ctype_be__rsrrvrxZc_voidprzr|r}r~rrrrrrobjectrrrrrrrZcdllZpydllZ dllhandleZ pythonapi version_infoZwindllZoledllZkernel32rZcoredllrrrZc_size_tZ c_ssize_trrrrZmemmoveZmemsetrrrrrrrrrrrZctypes._endianrrZc_int8Zc_uint8ZkindZc_int16Zc_int32Zc_int64Zc_uint16Zc_uint32Zc_uint64r"r"r"r#s8          !              <