X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=ctypescrypto%2Fexception.py;h=30c138e43aa5ba52651243267abe0cdf974244fa;hb=92df3e73921ba7b8756bfab1af4189dab7cc610e;hp=f0f3c5343238cabcd382c68ebe03e9738760c7fc;hpb=1ff9b1899959673512927b6afa317855908b7073;p=oss%2Fctypescrypto.git diff --git a/ctypescrypto/exception.py b/ctypescrypto/exception.py index f0f3c53..30c138e 100644 --- a/ctypescrypto/exception.py +++ b/ctypescrypto/exception.py @@ -1,6 +1,21 @@ +""" +Exception which extracts libcrypto error information +""" from ctypes import * from ctypescrypto import libcrypto strings_loaded=False + +__all__ = ['LibCryptoError','clear_err_stack'] + +def _check_null(s): + """ + Handle transparently NULL returned from error reporting functions + instead of strings + """ + if s is None: + return "" + return s + class LibCryptoError(Exception): """ Exception for libcrypto errors. Adds all the info, which can be @@ -15,9 +30,9 @@ class LibCryptoError(Exception): e=libcrypto.ERR_get_error() m = msg while e != 0: - m+="\n\t"+libcrypto.ERR_lib_error_string(e)+":"+\ - libcrypto.ERR_func_error_string(e)+":"+\ - libcrypto.ERR_reason_error_string(e) + m+="\n\t"+_check_null(libcrypto.ERR_lib_error_string(e))+":"+\ + _check_null(libcrypto.ERR_func_error_string(e))+":"+\ + _check_null(libcrypto.ERR_reason_error_string(e)) e=libcrypto.ERR_get_error() self.args=(m,)