def handle_sec_error(error, exception_class=None):
 if (error == 0):
  return
 cf_error_string = Security.SecCopyErrorMessageString(error, null())
 output = CFHelpers.cf_string_to_unicode(cf_error_string)
 CoreFoundation.CFRelease(cf_error_string)
 if ((output is None) or (output == u'')):
  output = (u'OSStatus %s' % error)
 if (exception_class is None):
  exception_class = OSError
 raise exception_class(output)

def handle_sec_error ( error , exception_class = None ) : if ( error == 0 ) : return cf_error_string = Security . SecCopyErrorMessageString ( error , null ( ) ) output = CFHelpers . cf_string_to_unicode ( cf_error_string ) CoreFoundation . CFRelease ( cf_error_string ) if ( ( output is None ) or ( output == u'' ) ) : output = ( u'OSStatus %s' % error ) if ( exception_class is None ) : exception_class = OSError raise exception_class ( output )
checks a security osstatus error code and throws an exception if there is an error to report .