def handle_com_error(err=None):
 if (err is None):
  (_, err, _) = sys.exc_info()
 (hresult_code, hresult_name, additional_info, parameter_in_error) = err.args
 hresult_code = signed_to_unsigned(hresult_code)
 exception_string = [('%s - %s' % (hex(hresult_code), hresult_name))]
 scode = None
 if additional_info:
  (wcode, source_of_error, error_description, whlp_file, whlp_context, scode) = additional_info
  scode = signed_to_unsigned(scode)
  exception_string.append(('  Error in: %s' % source_of_error))
  exception_string.append(('  %s - %s' % (hex(scode), (error_description or '').strip())))
 for (error_code, klass) in WMI_EXCEPTIONS.items():
  if (error_code in (hresult_code, scode)):
   break
 else:
  klass = x_wmi
 raise klass(com_error=err)

def handle_com_error ( err = None ) : if ( err is None ) : ( _ , err , _ ) = sys . exc_info ( ) ( hresult_code , hresult_name , additional_info , parameter_in_error ) = err . args hresult_code = signed_to_unsigned ( hresult_code ) exception_string = [ ( '%s - %s' % ( hex ( hresult_code ) , hresult_name ) ) ] scode = None if additional_info : ( wcode , source_of_error , error_description , whlp_file , whlp_context , scode ) = additional_info scode = signed_to_unsigned ( scode ) exception_string . append ( ( '  Error in: %s' % source_of_error ) ) exception_string . append ( ( '  %s - %s' % ( hex ( scode ) , ( error_description or '' ) . strip ( ) ) ) ) for ( error_code , klass ) in WMI_EXCEPTIONS . items ( ) : if ( error_code in ( hresult_code , scode ) ) : break else : klass = x_wmi raise klass ( com_error = err )
convenience wrapper for displaying all manner of com errors .