<s> from warnings import warn <EOL> import sys <EOL> from six import PY3 , binary_type , text_type <EOL> from cryptography . hazmat . bindings . openssl . binding import Binding <EOL> binding = Binding ( ) <EOL> ffi = binding . ffi <EOL> lib = binding . lib <EOL> def text ( charp ) : <EOL> """<STR_LIT>""" <EOL> if not charp : <EOL> return "<STR_LIT>" <EOL> return native ( ffi . string ( charp ) ) <EOL> def exception_from_error_queue ( exception_type ) : <EOL> """<STR_LIT>""" <EOL> errors = [ ] <EOL> while True : <EOL> error = lib . ERR_get_error ( ) <EOL> if error == <NUM_LIT:0> : <EOL> break <EOL> errors . append ( ( <EOL> text ( lib . ERR_lib_error_string ( error ) ) , <EOL> text ( lib . ERR_func_error_string ( error ) ) , <EOL> text ( lib . ERR_reason_error_string ( error ) ) ) ) <EOL> raise exception_type ( errors ) <EOL> def native ( s ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( s , ( binary_type , text_type ) ) : <EOL> raise TypeError ( "<STR_LIT>" % s ) <EOL> if PY3 : <EOL> if isinstance ( s , binary_type ) : <EOL> return s . decode ( "<STR_LIT:utf-8>" ) <EOL> else : <EOL> if isinstance ( s , text_type ) : <EOL> return s . encode ( "<STR_LIT:utf-8>" ) <EOL> return s <EOL> def path_string ( s ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( s , binary_type ) : <EOL> return s <EOL> elif isinstance ( s , text_type ) : <EOL> return s . encode ( sys . getfilesystemencoding ( ) ) <EOL> else : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> if PY3 : <EOL> def byte_string ( s ) : <EOL> return s . encode ( "<STR_LIT>" ) <EOL> else : <EOL> def byte_string ( s ) : <EOL> return s <EOL> UNSPECIFIED = object ( ) <EOL> _TEXT_WARNING = ( <EOL> text_type . __name__ + "<STR_LIT>" <EOL> ) <EOL> def text_to_bytes_and_warn ( label , obj ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( obj , text_type ) : <EOL> warn ( <EOL> _TEXT_WARNING . format ( label ) , <EOL> category = DeprecationWarning , <EOL> stacklevel = <NUM_LIT:3> <EOL> ) <EOL> return obj . encode ( '<STR_LIT:utf-8>' ) <EOL> return obj </s>
