Hacked By AnonymousFox

Current Path : /lib64/python3.6/site-packages/cffi/__pycache__/
Upload File :
Current File : //lib64/python3.6/site-packages/cffi/__pycache__/api.cpython-36.pyc

3

'+e��@s�ddlZddlZddlmZddlmZddlmZyeWn(e	k
rdddl
mZdd�ZYnXyeWne	k
r�e
ZYnXGd	d
�d
e�Zdd�Zd
d�Zdd�ZdS)�N�)�
allocate_lock)�	CDefError)�model)�CallablecCs
t|t�S)N)�
isinstancer)�x�r	�/usr/lib64/python3.6/api.py�<lambda>src@s�eZdZdZdfdd�Zdgdd�Zdhdd	�Zdid
d�Zdjd
d�Zdd�Z	dd�Z
dkdd�Zdd�Zdd�Z
dd�Zdd�Zdldd�Zdmd d!�Zd"d#�Zdod%d&�Zd'd(�Zdpd)d*�Zd+d,�Zdqd-d.�Zdrd0d1�Zdsd2d3�Zd4d5�Zdtd6d7�Zd8d9�Zd:d;�Zeeedd<�Zdvd=d>�Z d?d@�Z!dAdB�Z"dCdD�Z#dEdF�Z$dGdH�Z%dIdJ�Z&dKdL�Z'dMdN�Z(dOdP�Z)dwdRdS�Z*dxdUdV�Z+dWdX�Z,dYdZ�Z-dyd\d]�Z.d^d_�Z/d`da�Z0dbdc�Z1ddde�Z2dS)z�FFIa�
    The main top-level class that you instantiate once, or once per module.

    Example usage:

        ffi = FFI()
        ffi.cdef("""
            int printf(const char *, ...);
        """)

        C = ffi.dlopen(None)   # standard library
        -or-
        C = ffi.verify()  # use a C compiler: verify the decl above is right

        C.printf("hello, %s!\n", ffi.new("char[]", "world"))
    Nc
Cs�|dkr^ddl}ddlm}|j|kr^t|d�rJtd|t|j|jf��ntd|t|jf��ddlm}||_t�|_	|j
�|_i|_t
jd	�j|_t
jd
�j|_g|_g|_g|_g|_d|_i|_d|_d|_tj|�|_t|d�r�|j|�x2t|j�D]$}|jd��rt ||t!||���qW|j	�"|j"tj#�|_$|j"tj%�|_&WdQRXt'|t
j��r�tt(d
��s�|j)|j$d�t(_*|j+�\t(_,t(_-n |j)|j$d�|_*|j+�\|_,|_-|j.|_.dS)z{Create an FFI instance.  The 'backend' argument is used to
        select a non-default backend, mostly for tests.
        Nrr)�__version__�__file__z�Version mismatch: this is the 'cffi' package version %s, located in %r.  When we import the top-level '_cffi_backend' extension module, we get version %s, located in %r.  The two versions should be equal; check your installation.z�Version mismatch: this is the 'cffi' package version %s, located in %r.  This interpreter comes with a built-in '_cffi_backend' module, which is version %s.  The two versions should be equal; check your installation.)�cparserZparsed_typesZ	new_types�set_ffiZRTLD_�NULL)/Z
_cffi_backend�r
�hasattr�	Exceptionrr�_backendr�_lockZParser�_parser�_cached_btypes�types�
ModuleType�__dict__�
_parsed_typesZ
_new_types�_function_caches�
_libraries�_cdefsources�_included_ffis�_windows_unicode�_init_once_cache�
_cdef_version�
_embeddingrZ
get_typecacheZ
_typecacher�list�
startswith�setattr�getattr�_get_cached_btypeZ
voidp_type�BVoidPZchar_array_type�BCharArr�castrZ
_get_types�CDataZCType�buffer)�self�backendr
r�namer	r	r
�__init__'sR




zFFI.__init__FcCs|j|||d�dS)a�Parse the given C source.  This registers all declared functions,
        types, and global variables.  The functions and global variables can
        then be accessed via either 'ffi.dlopen()' or 'ffi.verify()'.
        The types can be used in 'ffi.new()' and other functions.
        If 'packed' is specified as True, all structs declared inside this
        cdef are packed, i.e. laid out without any field alignment at all.
        )�override�packedN)�_cdef)r/�csourcer3r4r	r	r
�cdefcszFFI.cdefcCs$|j||dd�|jdkr d|_dS)NT)r4Z	dllexportr)r5r$)r/r6r4r	r	r
�
embedding_apims
zFFI.embedding_apicKs�t|t�s&t|t�std��|jd�}|j�|t�|_|jj	|fd|i|��|j
j|�|rvx|jD]}|j
�qfW|jj}|r�g|j_x|D]}|j||�q�WWdQRXdS)Nz cdef() argument must be a string�asciir3)r�str�
basestring�	TypeError�encoder�objectr#r�parser�appendr�clearZ_recomplete�finish_backend_type)r/r6r3Zoptions�cache�
finishlist�tpr	r	r
r5rs 



z	FFI._cdefrcCsTt|t�s|dkst�|j�.t|||�\}}|jj|�|jj|�WdQRX|S)aHLoad and return a dynamic library identified by 'name'.
        The standard C library can be loaded by passing None.
        Note that functions and types declared by 'ffi.cdef()' are not
        linked to a particular library, just like C headers; in the
        library we only look for the actual (untyped) symbols.
        N)rr;�AssertionErrorr�_make_ffi_libraryrr@r)r/r1�flags�libZfunction_cacher	r	r
�dlopen�sz
FFI.dlopencCst|�j|�dS)z�Close a library obtained with ffi.dlopen().  After this call,
        access to functions or variables from the library will fail
        (possibly with a segmentation fault).
        N)�type�__cffi_close__)r/rIr	r	r
�dlclose�szFFI.dlclosecCsj|}||jkr|j|St|t�s,|jd�}|jj|�}|j}|rJ|j�}|j|�}||f}||j|<|S)Nr9)	rrr:r=rZ
parse_typeZis_raw_functionZas_function_pointerr))r/�cdecl�keyrK�really_a_function_type�btype�resultr	r	r
�_typeof_locked�s





zFFI._typeof_lockedcCsdy|j|}Wn0tk
r>|j�|j|�}WdQRXYnX|\}}|r`|r`td|f��|S)Nz>the type %r is a function type, not a pointer-to-function type)r�KeyErrorrrSr)r/rN�consider_function_as_funcptrrRrQrPr	r	r
�_typeof�s

zFFI._typeofc
Cs�t|t�r|j|�St||j�r,|jj|�St|tj�rLt|�}|dk	rL|St|tj	�r|t
|d�r||j�|j|j
�SQRXtt|���dS)z�Parse the C type given as a string and return the
        corresponding <ctype> object.
        It can also be used on 'cdata' instance to get its C type.
        N�_cffi_base_type)rr;rVr-r�typeofr�BuiltinFunctionType�_builtin_function_type�FunctionTyperrr)rWr<rK)r/rN�resr	r	r
rX�s


z
FFI.typeofcCs0t|t�r |j|�}|jj|�S|jj|�SdS)zvReturn the size in bytes of the argument.  It can be a
        string naming a C type, or a 'cdata' instance.
        N)rr;rVr�sizeof)r/rN�BTyper	r	r
r]�s

z
FFI.sizeofcCs t|t�r|j|�}|jj|�S)z\Return the natural alignment size in bytes of the C type
        given as a string.
        )rr;rVr�alignof)r/rNr	r	r
r_�s

zFFI.alignofcGs(t|t�r|j|�}|j|f|��dS)a3Return the offset of the named field inside the given
        structure or array, which must be given as a C type name.
        You can give several field names in case of nested structures.
        You can also give numeric values which correspond to array
        items, in case of an array type.
        r)rr;rV�
_typeoffsetof)r/rN�fields_or_indexesr	r	r
�offsetof�s

zFFI.offsetofcCs"t|t�r|j|�}|jj||�S)a�Allocate an instance according to the specified C type and
        return a pointer to it.  The specified C type must be either a
        pointer or an array: ``new('X *')`` allocates an X and returns
        a pointer to it, whereas ``new('X[n]')`` allocates an array of
        n X'es and returns an array referencing it (which works
        mostly like a pointer, like in C).  You can also use
        ``new('X[]', n)`` to allocate an array of a non-constant
        length n.

        The memory is initialized following the rules of declaring a
        global variable in C: by default it is zero-initialized, but
        an explicit initializer can be given which can be used to
        fill all or part of the memory.

        When the returned <cdata> object goes out of scope, the memory
        is freed.  In other words the returned <cdata> object has
        ownership of the value of type 'cdecl' that it points to.  This
        means that the raw data can be used as long as this object is
        kept alive, but must not be used for a longer time.  Be careful
        about that when copying the pointer to the memory somewhere
        else, e.g. into another structure.
        )rr;rVrZnewp)r/rN�initr	r	r
�new�s

zFFI.newTcs,�jj�}|j|||��d��fdd�	}|S)a�Return a new allocator, i.e. a function that behaves like ffi.new()
        but uses the provided low-level 'alloc' and 'free' functions.

        'alloc' is called with the size as argument.  If it returns NULL, a
        MemoryError is raised.  'free' is called with the result of 'alloc'
        as argument.  Both can be either Python function or directly C
        functions.  If 'free' is None, then no free function is called.
        If both 'alloc' and 'free' are None, the default is used.

        If 'should_clear_after_alloc' is set to False, then the memory
        returned by 'alloc' is assumed to be already cleared (or you are
        fine with garbage); otherwise CFFI will clear it.
        Ncst|t�r�j|�}�||�S)N)rr;rV)rNrc)�	allocatorr/r	r
�allocates

z#FFI.new_allocator.<locals>.allocate)N)rr�
new_allocator)r/ZallocZfreeZshould_clear_after_allocZcompiled_ffirfr	)rer/r
rgs

zFFI.new_allocatorcCs"t|t�r|j|�}|jj||�S)z�Similar to a C cast: returns an instance of the named C
        type initialized with the given 'source'.  The source is
        casted between integers or pointers of any type.
        )rr;rVrr,)r/rN�sourcer	r	r
r,s

zFFI.castrcCs|jj||�S)a�Return a Python string (or unicode string) from the 'cdata'.
        If 'cdata' is a pointer or array of characters or bytes, returns
        the null-terminated string.  The returned string extends until
        the first null character, or at most 'maxlen' characters.  If
        'cdata' is an array then 'maxlen' defaults to its length.

        If 'cdata' is a pointer or array of wchar_t, returns a unicode
        string following the same rules.

        If 'cdata' is a single character or byte or a wchar_t, returns
        it as a string or unicode string.

        If 'cdata' is an enum, returns the value of the enumerator as a
        string, or 'NUMBER' if the value is out of range.
        )r�string)r/�cdata�maxlenr	r	r
ri%sz
FFI.stringcCs|jj||�S)aLUnpack an array of C data of the given length,
        returning a Python string/unicode/list.

        If 'cdata' is a pointer to 'char', returns a byte string.
        It does not stop at the first null.  This is equivalent to:
        ffi.buffer(cdata, length)[:]

        If 'cdata' is a pointer to 'wchar_t', returns a unicode string.
        'length' is measured in wchar_t's; it is not the size in bytes.

        If 'cdata' is a pointer to anything else, returns a list of
        'length' items.  This is a faster equivalent to:
        [cdata[i] for i in range(length)]
        )r�unpack)r/rjZlengthr	r	r
rl7sz
FFI.unpackcCs|jj|j||�S)a�Return a <cdata 'char[]'> that points to the data of the
        given Python object, which must support the buffer interface.
        Note that this is not meant to be used on the built-in types
        str or unicode (you can build 'char[]' arrays explicitly)
        but only on objects containing large quantities of raw data
        in some other format, like 'array.array' or numpy arrays.
        )r�from_bufferr+)r/Z
python_bufferZrequire_writabler	r	r
rmUszFFI.from_buffercCs|jj|||�S)a_ffi.memmove(dest, src, n) copies n bytes of memory from src to dest.

        Like the C function memmove(), the memory areas may overlap;
        apart from that it behaves like the C function memcpy().

        'src' can be any cdata ptr or array, or any Python buffer object.
        'dest' can be any cdata ptr or array, or a writable Python buffer
        object.  The size to copy, 'n', is always measured in bytes.

        Unlike other methods, this one supports all Python buffer including
        byte strings and bytearrays---but it still does not support
        non-contiguous buffers.
        )r�memmove)r/�dest�src�nr	r	r
rn`szFFI.memmovecsB����fdd�}t�t�r*�j�dd��|dkr6|S||�SdS)a�Return a callback object or a decorator making such a
        callback object.  'cdecl' must name a C function pointer type.
        The callback invokes the specified 'python_callable' (which may
        be provided either directly or via a decorator).  Important: the
        callback object must be manually kept alive for as long as the
        callback may be invoked from the C level.
        cs"t|�std���jj�|���S)Nz.the 'python_callable' argument is not callable)�callabler<r�callback)�python_callable)rN�error�onerrorr/r	r
�callback_decorator_wrapxs
z-FFI.callback.<locals>.callback_decorator_wrapT)rUN)rr;rV)r/rNrtrurvrwr	)rNrurvr/r
rsps
zFFI.callbackrcCsht|t�r|j|�}|j�}|jd�rBd|jj|d�krBd|}n|rZ|ddkrZd|}|jj||�S)a.Return a string giving the C type 'cdecl', which may be itself
        a string or a <ctype> object.  If 'replace_with' is given, it gives
        extra text to append (or insert for more complicated C types), like
        a variable name, or '*' to get actually the C type 'pointer-to-cdecl'.
        �*z&[�&z(%s)rz[(� )rr;rV�stripr&rZgetcname)r/rNZreplace_withr	r	r
�getctype�s



zFFI.getctypecCs|jj|||�S)a�Return a new cdata object that points to the same
        data.  Later, when this new cdata object is garbage-collected,
        'destructor(old_cdata_object)' will be called.

        The optional 'size' gives an estimate of the size, used to
        trigger the garbage collection more eagerly.  So far only used
        on PyPy.  It tells the GC that the returned object keeps alive
        roughly 'size' bytes of external memory.
        )rZgcp)r/rjZ
destructor�sizer	r	r
�gc�s
zFFI.gccCsf|jjd�dkst�y|j|}Wn>tk
r`g}|j||�}x|D]}|j||�qHWYnX|S)NF)r�acquirerFrrTZget_cached_btyperB)r/rKr^rDr	r	r
r)�s
zFFI._get_cached_btypecKsVddlm}m}|jr |j|�|p(|�}||||f|�|_|jj�}|jj|�|S)a�Verify that the current ffi signatures compile on this
        machine, and return a dynamic library object.  The dynamic
        library can be used to call functions and access global
        variables declared in this 'ffi'.  The library is compiled
        by the C compiler: it gives you C-level API compatibility
        (including calling macros).  This is unlike 'ffi.dlopen()',
        which requires binary compatibility in the signatures.
        r)�Verifier�_caller_dir_pycache)�verifierr�r�r!�_apply_windows_unicode�load_libraryrr@)r/rh�tmpdir�kwargsr�r�rIr	r	r
�verify�s	


z
FFI.verifycCs
|jj�S)N)rZ	get_errno)r/r	r	r
�
_get_errno�szFFI._get_errnocCs|jj|�dS)N)rZ	set_errno)r/�errnor	r	r
�
_set_errno�szFFI._set_errnoz(the value of 'errno' from/to the C callscCs|jj|�S)N)r�getwinerror)r/�coder	r	r
r��szFFI.getwinerrorc
Cs|j�tj||�SQRXdS)N)rr�
pointer_cache)r/�ctyper	r	r
�_pointer_to�szFFI._pointer_tocGs�y|jj|�}Wn8tk
rHdt|�jkrBt|�j|f|��S�YnX|rd|j|f|��\}}n|jdkrvtd��d}|j|�}|jj	|||�S)z�Return the address of a <cdata 'struct-or-union'>.
        If 'fields_or_indexes' are given, returns the address of that
        field or array item in the structure or array, recursively in
        case of nested structures.
        �
__addressof__Zpointerzaddressof(pointer)r)
rrXr<rKrr�r`�kindr�Zrawaddressof)r/rjrar��offsetZctypeptrr	r	r
�	addressof�s

z
FFI.addressofcGsD|jj||�\}}x(|D] }|jj||d�\}}||7}qW||fS)Nr)rZtypeoffsetof)r/r�Zfield_or_indexrar�Zfield1Zoffset1r	r	r
r`�s

zFFI._typeoffsetofcCs�t|t�stdt|�jf��||kr.td��|j�X|j�F|jj|j�|j	j
d�|j	j|j	�|j	j
d�|jj
|�WdQRXWdQRXdS)a�Includes the typedefs, structs, unions and enums defined
        in another FFI instance.  Usage is similar to a #include in C,
        where a part of the program might include types defined in
        another part for its own usage.  Note that the include()
        method has no effect on functions, constants and global
        variables, which must anyway be accessed directly from the
        lib object returned by the original FFI instance.
        zGffi.include() expects an argument that is also of type cffi.FFI, not %rzself.include(self)�[�]N)
rrr<rK�__name__�
ValueErrorrr�includerr@�extendr )r/Zffi_to_includer	r	r
r��s	
zFFI.includecCs|jj|j|�S)N)rZnewp_handler*)r/rr	r	r
�
new_handleszFFI.new_handlecCs|jj|�S)N)r�from_handle)r/rr	r	r
r�szFFI.from_handlecCs>|jdk	rtd��t|�}|r*|jd�n
|jd�||_dS)acWindows: if 'enabled_flag' is True, enable the UNICODE and
        _UNICODE defines in C, and declare the types like TCHAR and LPTCSTR
        to be (pointers to) wchar_t.  If 'enabled_flag' is False,
        declare these types to be (pointers to) plain 8-bit characters.
        This is mostly for backward compatibility; you usually want True.
        Nz%set_unicode() can only be called oncez�typedef wchar_t TBYTE;typedef wchar_t TCHAR;typedef const wchar_t *LPCTSTR;typedef const wchar_t *PCTSTR;typedef wchar_t *LPTSTR;typedef wchar_t *PTSTR;typedef TBYTE *PTBYTE;typedef TCHAR *PTCHAR;z�typedef char TBYTE;typedef char TCHAR;typedef const char *LPCTSTR;typedef const char *PCTSTR;typedef char *LPTSTR;typedef char *PTSTR;typedef TBYTE *PTBYTE;typedef TCHAR *PTCHAR;)r!r��boolr7)r/Zenabled_flagr	r	r
�set_unicodes
	
zFFI.set_unicodecCs>|jdf�}t|ttf�s"td��t|�ddg}||d<dS)NZ
define_macrosz''define_macros' must be a list or tuple�UNICODE�1�_UNICODE)r�r�)r�r�)�getrr%�tupler<)r/�kwdsZ	defmacrosr	r	r
r�0szFFI._apply_windows_unicodecsj�fdd�}dtjkr�ddl}tjdkrNd}ttd�r�|d|jjtjd	��n4tjdkr^d}nd}ttd�r�|d|jjtjd
��ttd�r�|d|jjtjdd��n�tjdkr�d}ttd�r�|d7}nLyddl	}Wn t
k
r�ddlm	}YnXd}|jd��r||jd�7}|tj
d?tj
d?d@f}ttd��rF|tj7}|d|�tjdk�rf|dd�dS)Ncs"�j|g�}||kr|j|�dS)N)�
setdefaultr@)rO�valueZlst)r�r	r
�ensure:sz(FFI._apply_embedding_fix.<locals>.ensureZ__pypy__r�win32Zpython27�prefixZlibrary_dirsZlibs�zpypy-czpypy3-c�binZpypyZgoalz
python%d%d�gettotalrefcountZ_d)�	sysconfigzpython%d.%dZ	DEBUG_EXT����abiflagsZ	librariesZextra_link_argsz	/MANIFEST)r�)�sys�builtin_module_names�os�platformr�path�joinr��version_infor��ImportErrorZ	distutils�get_config_var�
hexversionr�)r/r�r�r�Z	pythonlib�templater�r	)r�r
�_apply_embedding_fix8s@










zFFI._apply_embedding_fix�.ccKsdddl}t|d�rtd��t|t�s,td��|j|ksF|jrN|j|krNtd��t|�|||f|_	dS)Nr�_assigned_sourcez:set_source() cannot be called several times per ffi objectz'module_name' must be a stringzY'module_name' must not contain '/': use a dotted name to make a 'package.module' location)
r�rr�rr;r<�sep�altsepr:r�)r/�module_namerh�source_extensionr�r�r	r	r
�
set_sourcejs

zFFI.set_source�buildcCs�ddlm}ddlm}t|d�s>t|d�r6|jj�Std��|j\}}}}|dkr\t	d��||�||||f|||d	d
�|��\}	}
|r�|
r�t
jjd|	j
df�nt
jjd|	j
df�|	S)
Nr)�mkpathr)�	recompiler�r�z8set_source() must be called before distutils_extension()zadistutils_extension() is only for C extension modules, not for dlopen()-style pure Python modulesF)r�Zextradirr��call_c_compilerzregenerated: %r
znot modified: %r
)Zdistutils.dir_utilr��
recompilerr�rr�Z
get_extensionr�r�r<r��stderr�writeZsources)r/r��verboser�r�r�rhr�r�Zext�updatedr	r	r
�distutils_extensionws&


zFFI.distutils_extensioncCsZddlm}t|d�std��|j\}}}}|dkr<td��||||f|dd�|��dS)Nr)r�r�z0set_source() must be called before emit_c_code()zYemit_c_code() is only for C extension modules, not for dlopen()-style pure Python modulesF)�c_filer�)r�r�rr�r�r<)r/�filenamer�r�rhr�r�r	r	r
�emit_c_code�s

zFFI.emit_c_codecCsZddlm}t|d�std��|j\}}}}|dk	r<td��||||f|dd�|��dS)Nr)r�r�z0set_source() must be called before emit_c_code()z^emit_python_code() is only for dlopen()-style pure Python modules, not for C extension modulesF)r�r�)r�r�rr�r�r<)r/r�r�r�rhr�r�r	r	r
�emit_python_code�s

zFFI.emit_python_code�.c
CsLddlm}t|d�std��|j\}}}}	||||f|||||d�|	��S)a�The 'target' argument gives the final file name of the
        compiled DLL.  Use '*' to force distutils' choice, suitable for
        regular CPython C API modules.  Use a file name ending in '.*'
        to ask for the system's default extension for dynamic libraries
        (.so/.dll/.dylib).

        The default is '*' when building a non-embedded C API extension,
        and (module_name + '.*') when building an embedded library.
        r)r�r�z,set_source() must be called before compile())r��targetr�Zcompiler_verbose�debug)r�r�rr�r�)
r/r�r�r�r�r�r�rhr�r�r	r	r
�compile�s

zFFI.compilecCs�y|j|}Wn(tk
r6|jj|dt�f�}YnX|drH|dS|d�4|j|}|drl|dS|�}d|f|j|<WdQRX|S)NFrrT)r"rTr�r)r/�func�tagrrRr	r	r
�	init_once�s

z
FFI.init_oncecs�|jrtd��ddl}|jd|�}|r6||j�d�}|j�pBdg}|jd|d�j�}xBtdt|��D]0�|�}|j	�rhx|j
|�s�|dd�}q~WqhWt|���fdd�|D�}dj|�}t|d	d
�||_dS)Nz-embedding_init_code() can only be called oncerz\s*\nrz\s*rcsg|]}|�d�d�qS)N�
r	)�.0�line)�ir	r
�
<listcomp>�sz+FFI.embedding_init_code.<locals>.<listcomp>Z	cffi_init�exec���)
r$r��re�match�end�
splitlines�group�range�len�rstripr&r�r�)r/Zpysourcer�r��linesr�r�r	)r�r
�embedding_init_code�s$
zFFI.embedding_init_codecOstd��dS)Nz:ffi.def_extern() is only available on API-mode FFI objects)r�)r/�argsr�r	r	r
�
def_extern�szFFI.def_externcCs�g}g}g}xh|jjD]\}|jd�r8|j|dd��q|jd�rV|j|dd��q|jd�r|j|dd��qW|j�|j�|j�|||fS)z�Returns the user type names known to this FFI instance.
        This returns a tuple containing three lists of names:
        (typedef_names, names_of_structs, names_of_unions)
        ztypedef �Nzstruct �zunion �)r�
_declarationsr&r@�sort)r/ZtypedefsZstructsZunionsrOr	r	r
�
list_types�s


zFFI.list_types)N)FF)F)F)r)F)N)NNTr�)r�)F)NNN)r)r)rNr�)r�)r�)r�T)r�rNN)3r��
__module__�__qualname__�__doc__r2r7r8r5rJrMrSrVrXr]r_rbrdrgr,rirlrmrnrsr|r~r)r�r�r��propertyr�r�r�r�r`r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r	r	r	r
rsb
<








	






2


rc	Cs�ddl}|dkr*tjdkr&|jd|�Sd}d}d|ksHd|ksH|j|kr|y|j||�Stk
rz}z
|}WYdd}~XnXddl}|jj|�}|dkr�|dkr�tjdkr�tj	d
kr�td��d|f}|dk	r�d	||f}t|��|j||�S)Nrr��cr��/r�zXdlopen(None) cannot work on Windows for Python 3 (see http://bugs.python.org/issue23606)zGctypes.util.find_library() did not manage to locate a library called %rz%s.  Additionally, %s)r�)
r�r�r�r�r��OSErrorZctypes.util�utilZfind_libraryr�)	r0r1rHr�Zfirst_error�eZctypesr��msgr	r	r
�_load_backend_libs,
r�cs�
j}t|||��	�	�
�fdd����	�
fdd����	�
fdd��dd���
�fd	d
��i�dg�i��������
�fdd
��
���
��
fdd��G����	�
���
fdd�dt��|dk	r�y"t|t�s�|jd�}d|�_Wntk
r�YnX�����jfS)Ncs<d|}�jj|\}}�j|�}�j||�}|�j|<dS)Nz	function )rr�r)�
load_functionr)r1rOrE�_r^r�)�
backendlib�ffi�libraryr	r
�accessor_function%s

z,_make_ffi_library.<locals>.accessor_functioncs\d�}�jj|\}}�j|���j��j�t��t���fdd����fdd���dS)Nz	variable cs
����S)Nr	)r/)r^r1�
read_variabler	r
r3sz>_make_ffi_library.<locals>.accessor_variable.<locals>.<lambda>cs���|�S)Nr	)r/r�)r^r1�write_variabler	r
r4s)rr�r)rrr'r�)r1rOrEr�)�
FFILibraryr�r)r^r1rrr
�accessor_variable,s
z,_make_ffi_library.<locals>.accessor_variablecs�y�|Stk
r��j�Z|�krtd|}�jj|\}}�j|�}|jdkr`tj�|�}�j||�}|�|<WdQRX�|SXdS)Nz	variable Zarray)	rTrrr�r)r�rr�r�)r1rOrEr�r^�p)�addr_variablesr�rr	r
�
addressof_var6s

z(_make_ffi_library.<locals>.addressof_varcSstd|f��dS)NzDnon-integer constant '%s' cannot be accessed from a dlopen() library)�NotImplementedError)r1r	r	r
�accessor_constantEsz,_make_ffi_library.<locals>.accessor_constantcs�jj|�j|<dS)N)r�_int_constantsr)r1)rrr	r
�accessor_int_constantIsz0_make_ffi_library.<locals>.accessor_int_constantFcs��d�jkrdSx��jjj�D]�\}\}}t|tj�s~|jdd�\}}|dkrZ��|<q�|dkrl��|<q�|dkr���|<q x0t|j	�D]"\}}||f�fdd�	}|�|<q�Wq Wx�jj
D]}�j|��q�W�j�d<dS)	NrrzrZfunctionZvariableZconstantcs|j�|j|�j|<dS)N)Zcheck_not_partialZ
enumvaluesr)r1rEr�)rr	r
�
accessor_enum_szB_make_ffi_library.<locals>.update_accessors.<locals>.accessor_enum)r#rr��itemsrrZEnumType�split�	enumerateZenumeratorsrr�)rOrEr�r�r1r�Zenumnamer)rrr
r�	accessors�accessors_versionrrr	r
�update_accessorsPs"


z+_make_ffi_library.<locals>.update_accessorsc	sX�j�H|�jks|�jkr dS|�kr>��|�kr>t|���||�WdQRXdS)N)rr�AttributeError)r1)rrrrrr	r
�
make_accessorgsz(_make_ffi_library.<locals>.make_accessorcsReZdZ�fdd�Z�fdd�Z���fdd�Z����fdd�Z�fd	d
�ZdS)z%_make_ffi_library.<locals>.FFILibrarycs�|�t||�S)N)r()r/r1)rr	r
�__getattr__rsz1_make_ffi_library.<locals>.FFILibrary.__getattr__csJyt|j|�}Wn(tk
r8�|�t|||�YnX|j||�dS)N)r(�	__class__rr'�__set__)r/r1r�r�)rr	r
�__setattr__usz1_make_ffi_library.<locals>.FFILibrary.__setattr__c	s �j����j�SQRXdS)N)r�keys)r/)rrrr	r
�__dir__}sz-_make_ffi_library.<locals>.FFILibrary.__dir__csf|�jkr�j|S|�jkr&�|�S�|�|�jkrB�j|S|�jkrT�|�Std|f��dS)Nz:cffi library has no function or global variable named '%s')rr)r/r1)rr	rrr	r
r��s





z3_make_ffi_library.<locals>.FFILibrary.__addressof__cs�j�|jj�dS)N)Z	close_librrA)r/)r�r	r
rL�sz4_make_ffi_library.<locals>.FFILibrary.__cffi_close__N)r�r�r�rrrr�rLr	)rrr	r�rrrrr	r
rqs
rzutf-8z
FFILibrary_%s)	rr�r>rr:r=r��UnicodeErrorr)rZlibnamerHr0r	)rrrr
rrrrr	r�rrrrr
rG!s,

" 

rGcCsdddl}y$|j|j}|j}|j}||}Wntttfk
rFdSX|j�|j	|�SQRXdS)Nr)
r��modulesr�Z_cffi_original_ffiZ_cffi_types_of_builtin_funcsrTrr<rr))r�r��modulerZtypes_of_builtin_funcsrEr	r	r
rZ�srZ)r�r�lockrrurrrrr�	NameError�collectionsrr;r:r>rr�rGrZr	r	r	r
�<module>s*
wz

Hacked By AnonymousFox1.0, Coded By AnonymousFox