示例#1
0
def reprReturnErrorStructure( struct, full = False ):
  errorNumber = struct.get( "Errno", 0 )
  message = struct.get( "Message", '' )
  if errorNumber:
    reprStr = "%s ( %s : %s)" % ( strerror( errorNumber ), errorNumber, message )
  else:
    reprStr = message

  if full:
    callStack = struct.get( "CallStack" )
    if callStack:
      reprStr += "\n" + "".join( callStack )
      
  return reprStr    
示例#2
0
def reprReturnErrorStructure(struct, full=False):
  errorNumber = struct.get("Errno", 0)
  message = struct.get("Message", '')
  if errorNumber:
    reprStr = "%s ( %s : %s)" % (strerror(errorNumber), errorNumber, message)
  else:
    reprStr = message

  if full:
    callStack = struct.get("CallStack")
    if callStack:
      reprStr += "\n" + "".join(callStack)

  return reprStr
示例#3
0
def S_ERROR(*args, **kwargs):
    """return value on error condition

    Arguments are either Errno and ErrorMessage or just ErrorMessage fro backward compatibility

    :param int errno: Error number
    :param string message: Error message
    :param list callStack: Manually override the CallStack attribute better performance
    """
    callStack = kwargs.pop("callStack", None)

    result = {"OK": False, "Errno": 0, "Message": ""}

    message = ""
    if args:
        if isinstance(args[0], six.integer_types):
            result["Errno"] = args[0]
            if len(args) > 1:
                message = args[1]
        else:
            message = args[0]

    if result["Errno"]:
        message = "%s ( %s : %s)" % (strerror(
            result["Errno"]), result["Errno"], message)
    result["Message"] = message

    if callStack is None:
        try:
            callStack = traceback.format_stack()
            callStack.pop()
        except Exception:
            callStack = []

    result["CallStack"] = callStack

    # print "AT >>> S_ERROR", result['OK'], result['Errno'], result['Message']
    # for item in result['CallStack']:
    #  print item

    return result
示例#4
0
def S_ERROR(*args):
    """ return value on error condition

  Arguments are either Errno and ErrorMessage or just ErrorMessage fro backward compatibility

  :param int errno: Error number
  :param string message: Error message
  """
    result = {"OK": False, "Errno": 0, "Message": ""}

    message = ''
    if args:
        if isinstance(args[0], six.integer_types):
            result['Errno'] = args[0]
            if len(args) > 1:
                message = args[1]
        else:
            message = args[0]

    if result['Errno']:
        message = "%s ( %s : %s)" % (strerror(
            result['Errno']), result['Errno'], message)
    result["Message"] = message

    try:
        callStack = traceback.format_stack()
        callStack.pop()
    except BaseException:
        callStack = []

    result["CallStack"] = callStack

    # print "AT >>> S_ERROR", result['OK'], result['Errno'], result['Message']
    # for item in result['CallStack']:
    #  print item

    return result
示例#5
0
def S_ERROR( *args ):
  """ return value on error condition

  Arguments are either Errno and ErrorMessage or just ErrorMessage fro backward compatibility

  :param int errno: Error number
  :param string message: Error message
  """
  result = { "OK" : False, "Errno": 0, "Message": "" }

  message = ''
  if args:
    if isinstance( args[0], ( int, long ) ):
      result['Errno'] = args[0]
      if len( args ) > 1:
        message = args[1]
    else:
      message = args[0]

  if result['Errno']:
    message = "%s ( %s : %s)" % ( strerror( result['Errno'] ), result['Errno'], message )
  result["Message"] = message

  try:
    callStack = traceback.format_stack()
    callStack.pop()
  except:
    callStack = []

  result["CallStack"] = callStack

  #print "AT >>> S_ERROR", result['OK'], result['Errno'], result['Message']
  #for item in result['CallStack']:
  #  print item

  return result