def check_status(cls, retcode, function, args): if retcode >= 0: return retcode elif retcode == -1: raise GNUTLSError(getattr(function, 'errmsg', None) or ErrorMessage(retcode)) elif retcode == GNUTLS_E_AGAIN: raise OperationWouldBlock(gnutls_strerror(retcode)) elif retcode == GNUTLS_E_INTERRUPTED: raise OperationInterrupted(gnutls_strerror(retcode)) elif retcode in (GNUTLS_E_MEMORY_ERROR, GNUTLS_E_SHORT_MEMORY_BUFFER): raise MemoryError(ErrorMessage(retcode)) elif retcode == GNUTLS_E_NO_CERTIFICATE_FOUND: raise CertificateSecurityError(gnutls_strerror(retcode)) elif retcode == GNUTLS_E_FATAL_ALERT_RECEIVED: exception = cls.alert_map.get(gnutls_alert_get(args[0])) raise exception and exception.__class__(*exception.args) or GNUTLSError(ErrorMessage(retcode)) elif retcode == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE: raise RequestedDataNotAvailable(gnutls_strerror(retcode)) else: raise GNUTLSError(ErrorMessage(retcode))
def check_status(cls, retcode, function, args): if retcode >= 0: return retcode elif retcode == -1: raise GNUTLSError( getattr(function, 'errmsg', None) or ErrorMessage(retcode)) elif retcode == GNUTLS_E_AGAIN: raise OperationWouldBlock(gnutls_strerror(retcode)) elif retcode == GNUTLS_E_INTERRUPTED: raise OperationInterrupted(gnutls_strerror(retcode)) elif retcode in (GNUTLS_E_MEMORY_ERROR, GNUTLS_E_SHORT_MEMORY_BUFFER): raise MemoryError(ErrorMessage(retcode)) elif retcode == GNUTLS_E_NO_CERTIFICATE_FOUND: raise CertificateSecurityError(gnutls_strerror(retcode)) elif retcode == GNUTLS_E_FATAL_ALERT_RECEIVED: exception = cls.alert_map.get(gnutls_alert_get(args[0])) raise exception and exception.__class__( *exception.args) or GNUTLSError(ErrorMessage(retcode)) elif retcode == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE: raise RequestedDataNotAvailable(gnutls_strerror(retcode)) else: raise GNUTLSError(ErrorMessage(retcode))
def __new__(cls, code): obj = str.__new__(cls, gnutls_strerror(code)) obj.code = code return obj