コード例 #1
0
ファイル: amf3.py プロジェクト: georgehedfors/AMFShell
def generate_error(request, cls, e, tb, include_traceback=False):
    """
    Builds an L{ErrorMessage<pyamf.flex.messaging.ErrorMessage>} based on the
    last traceback and the request that was sent.
    """
    import traceback

    if hasattr(cls, '_amf_code'):
        code = cls._amf_code
    else:
        code = cls.__name__

    detail = ''
    rootCause = None

    if include_traceback:
        detail = []
        rootCause = e

        for x in traceback.format_exception(cls, e, tb):
            detail.append(x.replace("\\n", ''))

    return messaging.ErrorMessage(messageId=generate_random_id(),
                                  clientId=generate_random_id(),
                                  timestamp=calendar.timegm(time.gmtime()),
                                  correlationId=request.messageId,
                                  faultCode=code,
                                  faultString=str(e),
                                  faultDetail=str(detail),
                                  extendedData=detail,
                                  rootCause=rootCause)
コード例 #2
0
    def test_ErrorMessage(self):
        m = messaging.ErrorMessage(faultString='ValueError')

        self.assertEqual(pyamf.encode(m).getvalue(),
            '\n\x81[Iflex.messaging.messages.ErrorMessage\x1bcorrelationId\x15'
            'timeToLive\x13timestamp\x13messageId\x0fheaders\x17destination'
            '\x11clientId\tbody\x19extendedData\x13faultCode\x17faultDetail'
            '\x17faultString\x13rootCause\x01\x01\x01\x01\n\x0b\x01\x01\x01'
            '\x01\x01\n\x05\x01\x01\x01\x06\x15ValueError\n\x05\x01\x01')
コード例 #3
0
def generate_error(request, cls, e, tb, include_traceback=False):
    """
    Builds an L{ErrorMessage<pyamf.flex.messaging.ErrorMessage>} based on the
    last traceback and the request that was sent.
    """
    import traceback

    if hasattr(cls, '_amf_code'):
        code = cls._amf_code
    else:
        code = cls.__name__

    details = None
    rootCause = e

    if include_traceback:
        buffer = pyamf.util.BufferedByteStream()

        traceback.print_exception(cls, e, tb, file=buffer)

        details = buffer.getvalue()

    faultDetail = None
    faultString = None

    if hasattr(e, 'message'):
        faultString = six.text_type(e.message)
    elif hasattr(e, 'args') and e.args:
        if isinstance(e.args[0], pyamf.python.str_types):
            faultString = six.text_type(e.args[0])

    if details:
        faultDetail = six.text_type(details)

    return messaging.ErrorMessage(messageId=generate_random_id(),
                                  clientId=generate_random_id(),
                                  timestamp=calendar.timegm(time.gmtime()),
                                  correlationId=request.messageId,
                                  faultCode=code,
                                  faultString=faultString,
                                  faultDetail=faultDetail,
                                  extendedData=details,
                                  rootCause=rootCause)