X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=ctypescrypto%2Fexception.py;h=30c138e43aa5ba52651243267abe0cdf974244fa;hb=92df3e73921ba7b8756bfab1af4189dab7cc610e;hp=c4710eca32742a817bfb1204a0d7550bcce8d433;hpb=b4ee51a0aca14c0af5853545b9e524cc1b57b656;p=oss%2Fctypescrypto.git diff --git a/ctypescrypto/exception.py b/ctypescrypto/exception.py index c4710ec..30c138e 100644 --- a/ctypescrypto/exception.py +++ b/ctypescrypto/exception.py @@ -4,6 +4,18 @@ 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 @@ -18,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,)