예제 #1
0
def parse_soap_fault(body, expected_faults=None):
    """
    Parse a SOAP fault element and its details.

    :param body: SOAP ``Body`` element.
    :param expected_faults:
        A `list` of `SoapFault` subclasses whose ``detail_type`` attribute will
        be used to determine a match against each top-level SOAP fault detail
        element.
    :return:
        A 2-tuple of: matching exception type and an instance of it's
        ``detail_type``; and SOAP fault information (code, string, actor,
        detail). ``None`` if there is no SOAP fault.
    """
    fault = elemfind(body, SOAP_ENV.Fault)
    if fault is None:
        return None
    faultcode = gettext(fault, u'faultcode')
    faultstring = gettext(fault, u'faultstring')
    faultactor = gettext(fault, u'faultactor')
    detail = elemfind(fault, u'detail')

    if expected_faults is None:
        expected_faults = []
    parsed = _parse_expected_faults(detail, expected_faults)
    return parsed, (faultcode, faultstring, faultactor, detail)
예제 #2
0
파일: client.py 프로젝트: AndrewCvekl/vumi
 def from_element(cls, element):
     if element.tag != cls.tag.text:
         return None
     return cls(
         message_id=gettext(element, 'messageId'),
         text=gettext(element, 'text'),
         variables=list(gettextall(element, 'variables')))
예제 #3
0
def parse_soap_fault(body, expected_faults=None):
    """
    Parse a SOAP fault element and its details.

    :param body: SOAP ``Body`` element.
    :param expected_faults:
        A `list` of `SoapFault` subclasses whose ``detail_type`` attribute will
        be used to determine a match against each top-level SOAP fault detail
        element.
    :return:
        A 2-tuple of: matching exception type and an instance of it's
        ``detail_type``; and SOAP fault information (code, string, actor,
        detail). ``None`` if there is no SOAP fault.
    """
    fault = elemfind(body, SOAP_ENV.Fault)
    if fault is None:
        return None
    faultcode = gettext(fault, u'faultcode')
    faultstring = gettext(fault, u'faultstring')
    faultactor = gettext(fault, u'faultactor')
    detail = elemfind(fault, u'detail')

    if expected_faults is None:
        expected_faults = []
    parsed = _parse_expected_faults(detail, expected_faults)
    return parsed, (faultcode, faultstring, faultactor, detail)
예제 #4
0
 def test_parse(self):
     """
     Specifying a `parse` callable results in that being called to transform
     the element text.
     """
     self.assertEqual(42, gettext(self.root, u'b', parse=int))
     self.assertEqual(
         MetasyntacticVariables.Foo,
         gettext(self.root, u'c',
                 parse=MetasyntacticVariables.lookupByName))
     self.assertRaises(ValueError, gettext, self.root, u'c', parse=int)
예제 #5
0
파일: server.py 프로젝트: musabaloyi/vumi
 def from_element(cls, root):
     """
     Create an `SmsMessage` instance from an ElementTree element.
     """
     return cls(
         message=gettext(root, 'message'),
         sender_address=gettext(
             root, 'senderAddress', parse=normalize_address),
         service_activation_number=gettext(
             root, 'smsServiceActivationNumber', parse=normalize_address),
         timestamp=gettext(root, 'dateTime', parse=iso8601.parse_date))
예제 #6
0
    def test_simple(self):
        """
        Getting a sub-element with a `text` attribute returns the text as a
        `unicode` object.
        """
        res = gettext(self.root, u'a')
        self.assertIdentical(unicode, type(res))
        self.assertEqual(res, u'hello')

        res = gettext(self.root, u'sub/e')
        self.assertIdentical(unicode, type(res))
        self.assertEqual(res, u'world')
예제 #7
0
    def test_simple(self):
        """
        Getting a sub-element with a `text` attribute returns the text as a
        `unicode` object.
        """
        res = gettext(self.root, u'a')
        self.assertIdentical(unicode, type(res))
        self.assertEqual(res, u'hello')

        res = gettext(self.root, u'sub/e')
        self.assertIdentical(unicode, type(res))
        self.assertEqual(res, u'world')
예제 #8
0
 def test_parseWithDefault(self):
     """
     In the event that a default value is specified and a `parse` callable
     given, and the default value is used, the default value will be passed
     to the callable.
     """
     self.assertEqual(
         42,
         gettext(self.root, u'b', default=3.1415, parse=int))
     self.assertEqual(
         21,
         gettext(self.root, u'd', default=21, parse=int))
     self.assertRaises(ValueError,
         gettext, self.root, u'd', default='foo', parse=int)
예제 #9
0
 def test_parse(self):
     """
     Specifying a `parse` callable results in that being called to transform
     the element text.
     """
     self.assertEqual(
         42,
         gettext(self.root, u'b', parse=int))
     self.assertEqual(
         MetasyntacticVariables.Foo,
         gettext(self.root, u'c',
                 parse=MetasyntacticVariables.lookupByName))
     self.assertRaises(ValueError,
         gettext, self.root, u'c', parse=int)
예제 #10
0
파일: server.py 프로젝트: musabaloyi/vumi
    def process_notifySmsReception(self, root, header, name):
        """
        Process a received text message.
        """
        linkid = None
        if header is not None:
            linkid = gettext(header, './/' + str(PARLAYX_COMMON_NS.linkid))

        correlator = gettext(root, NOTIFICATION_NS.correlator)
        message = SmsMessage.from_element(
            elemfind(root, NOTIFICATION_NS.message))
        d = maybeDeferred(
            self.callback_message_received, correlator, linkid, message)
        d.addCallback(
            lambda ignored: NOTIFICATION_NS.notifySmsReceptionResponse())
        return d
예제 #11
0
 def test_parseWithDefault(self):
     """
     In the event that a default value is specified and a `parse` callable
     given, and the default value is used, the default value will be passed
     to the callable.
     """
     self.assertEqual(42, gettext(self.root,
                                  u'b',
                                  default=3.1415,
                                  parse=int))
     self.assertEqual(21, gettext(self.root, u'd', default=21, parse=int))
     self.assertRaises(ValueError,
                       gettext,
                       self.root,
                       u'd',
                       default='foo',
                       parse=int)
예제 #12
0
파일: server.py 프로젝트: musabaloyi/vumi
 def from_element(cls, root):
     """
     Create a `DeliveryInformation` instance from an ElementTree element.
     """
     try:
         delivery_status = gettext(
             root, 'deliveryStatus', parse=DeliveryStatus.lookupByName)
     except ValueError, e:
         raise ValueError(
             'No such delivery status enumeration value: %r' % (str(e),))
예제 #13
0
파일: server.py 프로젝트: musabaloyi/vumi
 def process_notifySmsDeliveryReceipt(self, root, header, name):
     """
     Process a text message delivery receipt.
     """
     correlator = gettext(root, NOTIFICATION_NS.correlator)
     delivery_info = DeliveryInformation.from_element(
         elemfind(root, NOTIFICATION_NS.deliveryStatus))
     d = maybeDeferred(self.callback_message_delivered,
         correlator, delivery_info.delivery_status.value)
     d.addCallback(
         lambda ignored: NOTIFICATION_NS.notifySmsDeliveryReceiptResponse())
     return d
예제 #14
0
    def test_default(self):
        """
        Getting a sub-element without a `text` attribute, or attempting to get
        a sub-element that does not exist, results in the `default` parameter
        to `gettext` being used, defaulting to `None`.
        """
        self.assertIdentical(gettext(self.root, u'd'), None)
        self.assertEqual(gettext(self.root, u'd', default=42), 42)

        self.assertIdentical(gettext(self.root, u'sub/f'), None)
        res = gettext(self.root, u'sub/f', default='a')
        self.assertIdentical(str, type(res))
        self.assertEqual(res, 'a')

        self.assertIdentical(gettext(self.root, u'haha_what'), None)
        self.assertEqual(gettext(self.root, u'haha_what', default=42), 42)
예제 #15
0
    def test_default(self):
        """
        Getting a sub-element without a `text` attribute, or attempting to get
        a sub-element that does not exist, results in the `default` parameter
        to `gettext` being used, defaulting to `None`.
        """
        self.assertIdentical(gettext(self.root, u'd'), None)
        self.assertEqual(gettext(self.root, u'd', default=42), 42)

        self.assertIdentical(gettext(self.root, u'sub/f'), None)
        res = gettext(self.root, u'sub/f', default='a')
        self.assertIdentical(str, type(res))
        self.assertEqual(res, 'a')

        self.assertIdentical(gettext(self.root, u'haha_what'), None)
        self.assertEqual(gettext(self.root, u'haha_what', default=42), 42)
예제 #16
0
 def from_element(cls, elem):
     if elem.tag != L.ToyFaultDetail.text:
         return None
     return cls(gettext(elem, 'foo'), gettext(elem, 'bar'))
예제 #17
0
파일: client.py 프로젝트: musabaloyi/vumi
 def _extractRequestIdentifier((body, header)):
     return gettext(body, './/' + str(SEND_NS.result), default='')
예제 #18
0
파일: client.py 프로젝트: musabaloyi/vumi
 def from_element(cls, element):
     if element.tag != cls.tag.text:
         return None
     return cls(message_id=gettext(element, 'messageId'),
                text=gettext(element, 'text'),
                variables=list(gettextall(element, 'variables')))
예제 #19
0
 def from_element(cls, elem):
     if elem.tag != L.ToyFaultDetail.text:
         return None
     return cls(gettext(elem, 'foo'), gettext(elem, 'bar'))
예제 #20
0
파일: client.py 프로젝트: AndrewCvekl/vumi
 def _extractRequestIdentifier((body, header)):
     return gettext(body, './/' + str(SEND_NS.result), default='')
예제 #21
0
파일: server.py 프로젝트: musabaloyi/vumi
    ParlayX `DeliveryInformation` complex type.
    """
    @classmethod
    def from_element(cls, root):
        """
        Create a `DeliveryInformation` instance from an ElementTree element.
        """
        try:
            delivery_status = gettext(
                root, 'deliveryStatus', parse=DeliveryStatus.lookupByName)
        except ValueError, e:
            raise ValueError(
                'No such delivery status enumeration value: %r' % (str(e),))
        else:
            return cls(
                address=gettext(root, 'address', parse=normalize_address),
                delivery_status=delivery_status)


class SmsNotificationService(Resource):
    """
    Web resource to handle SOAP requests for ParlayX SMS deliveries and
    delivery receipts.
    """
    isLeaf = True

    def __init__(self, callback_message_received, callback_message_delivered):
        self.callback_message_received = callback_message_received
        self.callback_message_delivered = callback_message_delivered
        Resource.__init__(self)