o Sae@sddlZddlZddlmZmZddlmZeZeej Z ej Z e j ddZ ddZ dd Zd d Zd d ZddZerDddZnddZeZejdZddZdS)N)PY2 text_type)BindingF)should_clear_after_alloccCs|sdStt|S)z Get a native string type representing of the given CFFI ``char*`` object. :param charp: A C-style string represented using CFFI. :return: :class:`str` )nativeffistring)charpr //usr/lib/python3/dist-packages/OpenSSL/_util.pytextsr cCsPg} t}|dkr |||tt|tt|tt|fq)ac Convert an OpenSSL library failure into a Python exception. When a call to the native OpenSSL library fails, this is usually signalled by the return value, and an error code is stored in an error queue associated with the current thread. The err library provides functions to obtain these error codes and textual error messages. Tr)lib ERR_get_errorappendr ERR_lib_error_stringERR_func_error_stringERR_reason_error_string)exception_typeerrorserrorr r r exception_from_error_queue"s     rcsfdd}|S)z~ Create an assert function that uses :func:`exception_from_error_queue` to raise an exception wrapped by *error*. cs|dur tdSdS)zT If *ok* is not True, retrieve the error from OpenSSL and raise it. TN)r)okrr r openssl_assertBs z#make_assert..openssl_assertr )rrr rr make_assert<s rcCsNt|ttfs td|trt|tr|dS|St|tr%|dS|S)a6 Convert :py:class:`bytes` or :py:class:`unicode` to the native :py:class:`str` type, using UTF-8 encoding if conversion is necessary. :raise UnicodeError: The input string is not UTF-8 decodeable. :raise TypeError: The input is neither :py:class:`bytes` nor :py:class:`unicode`. z%r is neither bytes nor unicodeutf-8) isinstancebytesr TypeErrorrencodedecodesr r r rLs    rcCs.t|tr|St|tr|tStd)a Convert a Python string to a :py:class:`bytes` string identifying the same path and which can be passed into an OpenSSL API accepting a filename. :param s: An instance of :py:class:`bytes` or :py:class:`unicode`. :return: An instance of :py:class:`bytes`. z3Path must be represented as bytes or unicode string)rrrr sysgetfilesystemencodingrr"r r r path_stringas  r&cCs|S)Nr r"r r r byte_stringtsr'cCs |dS)Ncharmap)r r"r r r r'zs z) for {0} is no longer accepted, use bytescCs.t|trtjt|tdd|dS|S)a If ``obj`` is text, emit a warning that it should be bytes instead and try to convert it to bytes automatically. :param str label: The name of the parameter from which ``obj`` was taken (so a developer can easily find the source of the problem and correct it). :return: If ``obj`` is the text string type, a ``bytes`` object giving the UTF-8 encoding of that text is returned. Otherwise, ``obj`` itself is returned. )category stacklevelr)rrwarningswarn _TEXT_WARNINGformatDeprecationWarningr )labelobjr r r text_to_bytes_and_warns  r3)r$r,sixrr,cryptography.hazmat.bindings.openssl.bindingrbindinginit_static_locksrr new_allocatorno_zero_allocatorr rrrr&r'object UNSPECIFIED__name__r.r3r r r r s*