3
«F\N ã @ s° d dl Z d dlZd dlmZmZmZ d dlmZ eƒ Zej ƒ ej
Z
ejZe
jdd�Z
dd„ Zdd „ Zd
d„ Zdd
„ Zdd„ ZerŒdd„ Zndd„ Zeƒ Zejd Zdd„ ZdS )é N)ÚPY3Úbinary_typeÚ text_type)ÚBindingF)Zshould_clear_after_allocc C s | sdS t tj| ƒƒ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`
Ú )ÚnativeÚffiÚstring)Zcharp© r
ú/usr/lib/python3.6/_util.pyÚtext s r c C sV g }xDt jƒ }|dkrP |jtt j|ƒƒtt j|ƒƒtt j|ƒƒfƒ qW | |ƒ‚dS )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.
r N)ÚlibZ
ERR_get_errorÚappendr ZERR_lib_error_stringZERR_func_error_stringZERR_reason_error_string)Zexception_typeÚerrorsÚerrorr
r
r Úexception_from_error_queue" s r c s ‡ fdd„}|S )z~
Create an assert function that uses :func:`exception_from_error_queue` to
raise an exception wrapped by *error*.
c s | dk rt ˆ ƒ dS )zT
If *ok* is not True, retrieve the error from OpenSSL and raise it.
TN)r )Úok)r r
r Úopenssl_assert> s z#make_assert..openssl_assertr
)r r r
)r r Úmake_assert9 s r c C sL t | ttfƒstd| ƒ‚tr4t | tƒrH| jdƒS nt | tƒrH| jdƒS | 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 unicodezutf-8)Ú
isinstancer r Ú TypeErrorr ÚdecodeÚencode)Úsr
r
r r H s
r c C s2 t | tƒr| S t | tƒr&| jtjƒ ƒS tdƒ‚dS )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 stringN)r r r r ÚsysÚgetfilesystemencodingr )r r
r
r Úpath_string] s
r c C s
| j dƒS )NÚcharmap)r )r r
r
r Úbyte_stringo s r c C s | S )Nr
)r r
r
r r r s z) for {0} is no longer accepted, use bytesc C s. t |tƒr*tjtj| ƒtdd� |jdƒS |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Ú
stacklevelzutf-8)r r ÚwarningsÚwarnÚ
_TEXT_WARNINGÚformatÚDeprecationWarningr )ZlabelÚobjr
r
r Útext_to_bytes_and_warn s
r( )r r" Zsixr r r Z,cryptography.hazmat.bindings.openssl.bindingr ZbindingZinit_static_locksr r
Z
new_allocatorZno_zero_allocatorr r r r r r ÚobjectZUNSPECIFIEDÚ__name__r$ r( r
r
r
r Ú s&