Ejemplo n.º 1
0
def _convert_response_to_block_list(response):
    '''
    Converts xml response to block list class.
    '''
    blob_block_list = BlobBlockList()

    xmldoc = minidom.parseString(response.body)
    for xml_block in _get_children_from_path(xmldoc,
                                             'BlockList',
                                             'CommittedBlocks',
                                             'Block'):
        xml_block_id = _decode_base64_to_text(
            _get_child_nodes(xml_block, 'Name')[0].firstChild.nodeValue)
        xml_block_size = int(
            _get_child_nodes(xml_block, 'Size')[0].firstChild.nodeValue)
        blob_block_list.committed_blocks.append(
            BlobBlock(xml_block_id, xml_block_size))

    for xml_block in _get_children_from_path(xmldoc,
                                             'BlockList',
                                             'UncommittedBlocks',
                                             'Block'):
        xml_block_id = _decode_base64_to_text(
            _get_child_nodes(xml_block, 'Name')[0].firstChild.nodeValue)
        xml_block_size = int(
            _get_child_nodes(xml_block, 'Size')[0].firstChild.nodeValue)
        blob_block_list.uncommitted_blocks.append(
            BlobBlock(xml_block_id, xml_block_size))

    return blob_block_list
Ejemplo n.º 2
0
def _convert_response_to_block_list(response):
    '''
    Converts xml response to block list class.
    '''
    blob_block_list = BlobBlockList()

    xmldoc = minidom.parseString(response.body)
    for xml_block in _get_children_from_path(xmldoc, 'BlockList',
                                             'CommittedBlocks', 'Block'):
        xml_block_id = _decode_base64_to_text(
            _get_child_nodes(xml_block, 'Name')[0].firstChild.nodeValue)
        xml_block_size = int(
            _get_child_nodes(xml_block, 'Size')[0].firstChild.nodeValue)
        blob_block_list.committed_blocks.append(
            BlobBlock(xml_block_id, xml_block_size))

    for xml_block in _get_children_from_path(xmldoc, 'BlockList',
                                             'UncommittedBlocks', 'Block'):
        xml_block_id = _decode_base64_to_text(
            _get_child_nodes(xml_block, 'Name')[0].firstChild.nodeValue)
        xml_block_size = int(
            _get_child_nodes(xml_block, 'Size')[0].firstChild.nodeValue)
        blob_block_list.uncommitted_blocks.append(
            BlobBlock(xml_block_id, xml_block_size))

    return blob_block_list
Ejemplo n.º 3
0
    def _report_batch_error(self, response):
        xml = response.body.decode('utf-8')
        doc = minidom.parseString(xml)

        n = _get_children_from_path(doc, (METADATA_NS, 'error'), 'code')
        code = n[0].firstChild.nodeValue if n and n[0].firstChild else ''

        n = _get_children_from_path(doc, (METADATA_NS, 'error'), 'message')
        message = n[0].firstChild.nodeValue if n and n[0].firstChild else xml

        raise WindowsAzureBatchOperationError(message, code)
Ejemplo n.º 4
0
    def _report_batch_error(self, response):
        xml = response.body.decode('utf-8')
        doc = minidom.parseString(xml)

        n = _get_children_from_path(doc, (METADATA_NS, 'error'), 'code')
        code = n[0].firstChild.nodeValue if n and n[0].firstChild else ''

        n = _get_children_from_path(doc, (METADATA_NS, 'error'), 'message')
        message = n[0].firstChild.nodeValue if n and n[0].firstChild else xml

        raise WindowsAzureBatchOperationError(message, code)
Ejemplo n.º 5
0
    def xml_to_namespace_availability(xmlstr):
        '''Converts xml response to service bus namespace availability

        The xml format:
<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
    <id>uuid:9fc7c652-1856-47ab-8d74-cd31502ea8e6;id=3683292</id>
    <title type="text"></title>
    <updated>2013-04-16T03:03:37Z</updated>
    <content type="application/xml">
        <NamespaceAvailability
            xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect"
            xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <Result>false</Result>
        </NamespaceAvailability>
    </content>
</entry>
        '''
        xmldoc = minidom.parseString(xmlstr)
        availability = AvailabilityResponse()

        for desc in _get_children_from_path(xmldoc, 'entry', 'content',
                                            'NamespaceAvailability'):
            node_value = _get_first_child_node_value(desc, 'Result')
            if node_value is not None:
                availability.result = _parse_bool(node_value)

        return availability
    def xml_to_region(xmlstr):
        '''Converts xml response to service bus region

        The xml format for region:
          <entry>
            <id>uuid:157c311f-081f-4b4a-a0ba-a8f990ffd2a3;id=1756759</id>
            <title type="text"></title>
            <updated>2013-04-10T18:25:29Z</updated>
            <content type="application/xml">
              <RegionCodeDescription xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                <Code>East Asia</Code>
                <FullName>East Asia</FullName>
              </RegionCodeDescription>
            </content>
          </entry>
          '''
        xmldoc = minidom.parseString(xmlstr)
        region = ServiceBusRegion()

        for desc in _get_children_from_path(xmldoc, 'entry', 'content',
                                            'RegionCodeDescription'):
            node_value = _get_first_child_node_value(desc, 'Code')
            if node_value is not None:
                region.code = node_value
            node_value = _get_first_child_node_value(desc, 'FullName')
            if node_value is not None:
                region.fullname = node_value

        return region
    def xml_to_namespace_availability(xmlstr):
        '''Converts xml response to service bus namespace availability

        The xml format:
        <?xml version="1.0" encoding="utf-8"?>
        <entry xmlns="http://www.w3.org/2005/Atom">
            <id>uuid:9fc7c652-1856-47ab-8d74-cd31502ea8e6;id=3683292</id>
            <title type="text"></title>
            <updated>2013-04-16T03:03:37Z</updated>
            <content type="application/xml">
                <NamespaceAvailability xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                    <Result>false</Result>
                </NamespaceAvailability>
            </content>
        </entry>
        '''
        xmldoc = minidom.parseString(xmlstr)
        availability = AvailabilityResponse()

        for desc in _get_children_from_path(xmldoc, 'entry', 'content',
                                            'NamespaceAvailability'):
            node_value = _get_first_child_node_value(desc, 'Result')
            if node_value is not None:
                availability.result = _parse_bool(node_value)

        return availability
Ejemplo n.º 8
0
def _convert_xml_to_subscription(xmlstr):
    '''Converts xml response to subscription

    The xml format for subscription:
    <entry xmlns='http://www.w3.org/2005/Atom'>  
    <content type='application/xml'>    
    <SubscriptionDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
       <LockDuration>PT5M</LockDuration>
       <RequiresSession>false</RequiresSession>
       <DefaultMessageTimeToLive>P10675199DT2H48M5.4775807S</DefaultMessageTimeToLive>
       <DeadLetteringOnMessageExpiration>false</DeadLetteringOnMessageExpiration>   <DeadLetteringOnFilterEvaluationExceptions>true</DeadLetteringOnFilterEvaluationExceptions>
    </SubscriptionDescription>  
    </content>
    </entry>
    '''
    xmldoc = minidom.parseString(xmlstr)
    subscription = Subscription()

    for desc in _get_children_from_path(xmldoc, 'entry', 'content', 'subscriptiondescription'):
        for attr_name, attr_value in vars(subscription).iteritems():
            tag_name = attr_name.replace('_', '')
            xml_attrs = _get_child_nodes(desc, tag_name)
            if xml_attrs:
                xml_attr = xml_attrs[0]
                if xml_attr.firstChild:
                    value = xml_attr.firstChild.nodeValue
                    conversion = _SUBSCRIPTION_CONVERSION.get(attr_name)
                    if conversion is not None:
                        value = conversion(value)
                    setattr(subscription, attr_name, value)

    for name, value in _get_entry_properties(xmlstr, True).iteritems():
        setattr(subscription, name, value)

    return subscription
Ejemplo n.º 9
0
    def xml_to_region(xmlstr):
        '''Converts xml response to service bus region

        The xml format for region:
<entry>
<id>uuid:157c311f-081f-4b4a-a0ba-a8f990ffd2a3;id=1756759</id>
<title type="text"></title>
<updated>2013-04-10T18:25:29Z</updated>
<content type="application/xml">
    <RegionCodeDescription
        xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect"
        xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <Code>East Asia</Code>
    <FullName>East Asia</FullName>
    </RegionCodeDescription>
</content>
</entry>
          '''
        xmldoc = minidom.parseString(xmlstr)
        region = ServiceBusRegion()

        for desc in _get_children_from_path(xmldoc, 'entry', 'content',
                                            'RegionCodeDescription'):
            node_value = _get_first_child_node_value(desc, 'Code')
            if node_value is not None:
                region.code = node_value
            node_value = _get_first_child_node_value(desc, 'FullName')
            if node_value is not None:
                region.fullname = node_value

        return region
Ejemplo n.º 10
0
def _convert_xml_to_topic(xmlstr):
    '''Converts xml response to topic

    The xml format for topic:
    <entry xmlns='http://www.w3.org/2005/Atom'>  
    <content type='application/xml'>    
    <TopicDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
       <DefaultMessageTimeToLive>P10675199DT2H48M5.4775807S</DefaultMessageTimeToLive>
       <MaxSizeInMegabytes>1024</MaxSizeInMegabytes>
       <RequiresDuplicateDetection>false</RequiresDuplicateDetection>
       <DuplicateDetectionHistoryTimeWindow>P7D</DuplicateDetectionHistoryTimeWindow>
       <DeadLetteringOnFilterEvaluationExceptions>true</DeadLetteringOnFilterEvaluationExceptions>
    </TopicDescription>  
    </content>
    </entry>
    '''
    xmldoc = minidom.parseString(xmlstr)
    topic = Topic()

    invalid_topic = True

    #get node for each attribute in Topic class, if nothing found then the response is not valid xml for Topic.
    for desc in _get_children_from_path(xmldoc, 'entry', 'content', 'TopicDescription'):
        invalid_topic = True
        node_value = _get_first_child_node_value(desc, 'DefaultMessageTimeToLive')
        if node_value is not None:
            topic.default_message_time_to_live = node_value
            invalid_topic = False
        node_value = _get_first_child_node_value(desc, 'MaxSizeInMegabytes')
        if node_value is not None:
            topic.max_size_in_megabytes = int(node_value)
            invalid_topic = False
        node_value = _get_first_child_node_value(desc, 'RequiresDuplicateDetection')
        if node_value is not None:
            topic.requires_duplicate_detection = _parse_bool(node_value)
            invalid_topic = False
        node_value = _get_first_child_node_value(desc, 'DuplicateDetectionHistoryTimeWindow')
        if node_value is not None:
            topic.duplicate_detection_history_time_window = node_value
            invalid_topic = False
        node_value = _get_first_child_node_value(desc, 'EnableBatchedOperations')
        if node_value is not None:
            topic.enable_batched_operations = _parse_bool(node_value)
            invalid_topic = False
        node_value = _get_first_child_node_value(desc, 'SizeInBytes')
        if node_value is not None:
            topic.size_in_bytes = int(node_value)
            invalid_topic = False

    if invalid_topic:
        raise WindowsAzureError(azure._ERROR_TOPIC_NOT_FOUND)

    #extract id, updated and name value from feed entry and set them of topic.
    for name, value in _get_entry_properties(xmlstr, True).iteritems():
        setattr(topic, name, value)
    return topic
Ejemplo n.º 11
0
def _convert_xml_to_subscription(xmlstr):
    '''Converts xml response to subscription

    The xml format for subscription:
    <entry xmlns='http://www.w3.org/2005/Atom'>  
    <content type='application/xml'>    
    <SubscriptionDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
       <LockDuration>PT5M</LockDuration>
       <RequiresSession>false</RequiresSession>
       <DefaultMessageTimeToLive>P10675199DT2H48M5.4775807S</DefaultMessageTimeToLive>
       <DeadLetteringOnMessageExpiration>false</DeadLetteringOnMessageExpiration>   <DeadLetteringOnFilterEvaluationExceptions>true</DeadLetteringOnFilterEvaluationExceptions>
    </SubscriptionDescription>  
    </content>
    </entry>
    '''
    xmldoc = minidom.parseString(xmlstr)
    subscription = Subscription()

    for desc in _get_children_from_path(xmldoc, 'entry', 'content',
                                        'SubscriptionDescription'):
        node_value = _get_first_child_node_value(desc, 'LockDuration')
        if node_value is not None:
            subscription.lock_duration = node_value
        node_value = _get_first_child_node_value(desc, 'RequiresSession')
        if node_value is not None:
            subscription.requires_session = _parse_bool(node_value)
        node_value = _get_first_child_node_value(desc,
                                                 'DefaultMessageTimeToLive')
        if node_value is not None:
            subscription.default_message_time_to_live = node_value
        node_value = _get_first_child_node_value(
            desc, 'DeadLetteringOnFilterEvaluationExceptions')
        if node_value is not None:
            subscription.dead_lettering_on_filter_evaluation_exceptions = _parse_bool(
                node_value)
        node_value = _get_first_child_node_value(
            desc, 'DeadLetteringOnMessageExpiration')
        if node_value is not None:
            subscription.dead_lettering_on_message_expiration = _parse_bool(
                node_value)
        node_value = _get_first_child_node_value(desc,
                                                 'EnableBatchedOperations')
        if node_value is not None:
            subscription.enable_batched_operations = _parse_bool(node_value)
        node_value = _get_first_child_node_value(desc, 'MaxDeliveryCount')
        if node_value is not None:
            subscription.max_delivery_count = int(node_value)
        node_value = _get_first_child_node_value(desc, 'MessageCount')
        if node_value is not None:
            subscription.message_count = int(node_value)

    for name, value in _get_entry_properties(xmlstr, True,
                                             '/subscriptions').iteritems():
        setattr(subscription, name, value)

    return subscription
Ejemplo n.º 12
0
def _convert_xml_to_topic(xmlstr):
    '''Converts xml response to topic

    The xml format for topic:
    <entry xmlns='http://www.w3.org/2005/Atom'>  
    <content type='application/xml'>    
    <TopicDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
       <DefaultMessageTimeToLive>P10675199DT2H48M5.4775807S</DefaultMessageTimeToLive>
       <MaxSizeInMegabytes>1024</MaxSizeInMegabytes>
       <RequiresDuplicateDetection>false</RequiresDuplicateDetection>
       <DuplicateDetectionHistoryTimeWindow>P7D</DuplicateDetectionHistoryTimeWindow>
       <DeadLetteringOnFilterEvaluationExceptions>true</DeadLetteringOnFilterEvaluationExceptions>
    </TopicDescription>  
    </content>
    </entry>
    '''
    xmldoc = minidom.parseString(xmlstr)
    topic = Topic()

    invalid_topic = True

    #get node for each attribute in Topic class, if nothing found then the response is not valid xml for Topic.
    for desc in _get_children_from_path(xmldoc, 'entry', 'content', 'TopicDescription'):
        invalid_topic = True
        node_value = _get_first_child_node_value(desc, 'DefaultMessageTimeToLive')
        if node_value is not None:
            topic.default_message_time_to_live = node_value
            invalid_topic = False
        node_value = _get_first_child_node_value(desc, 'MaxSizeInMegabytes')
        if node_value is not None:
            topic.max_size_in_megabytes = int(node_value)
            invalid_topic = False
        node_value = _get_first_child_node_value(desc, 'RequiresDuplicateDetection')
        if node_value is not None:
            topic.requires_duplicate_detection = _parse_bool(node_value)
            invalid_topic = False
        node_value = _get_first_child_node_value(desc, 'DuplicateDetectionHistoryTimeWindow')
        if node_value is not None:
            topic.duplicate_detection_history_time_window = node_value
            invalid_topic = False
        node_value = _get_first_child_node_value(desc, 'EnableBatchedOperations')
        if node_value is not None:
            topic.enable_batched_operations = _parse_bool(node_value)
            invalid_topic = False
        node_value = _get_first_child_node_value(desc, 'SizeInBytes')
        if node_value is not None:
            topic.size_in_bytes = int(node_value)
            invalid_topic = False

    if invalid_topic:
        raise WindowsAzureError(_ERROR_TOPIC_NOT_FOUND)

    #extract id, updated and name value from feed entry and set them of topic.
    for name, value in _get_entry_properties(xmlstr, True).iteritems():
        setattr(topic, name, value)
    return topic
def _parse_blob_enum_results_list(response):
    respbody = response.body
    return_obj = BlobEnumResults()
    doc = minidom.parseString(respbody)

    for enum_results in _get_child_nodes(doc, 'EnumerationResults'):
        for child in _get_children_from_path(enum_results, 'Blobs', 'Blob'):
            return_obj.blobs.append(_fill_instance_element(child, Blob))

        for child in _get_children_from_path(enum_results, 'Blobs', 'BlobPrefix'):
            return_obj.prefixes.append(_fill_instance_element(child, BlobPrefix))

        for name, value in vars(return_obj).iteritems():
            if name == 'blobs' or name == 'prefixes':
                continue
            value = _fill_data_minidom(enum_results, name, value)
            if value is not None:
                setattr(return_obj, name, value)

    return return_obj
Ejemplo n.º 14
0
    def xml_to_namespace(xmlstr):
        '''Converts xml response to service bus namespace

        The xml format for namespace:
<entry>
<id>uuid:00000000-0000-0000-0000-000000000000;id=0000000</id>
<title type="text">myunittests</title>
<updated>2012-08-22T16:48:10Z</updated>
<content type="application/xml">
    <NamespaceDescription
        xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect"
        xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <Name>myunittests</Name>
    <Region>West US</Region>
    <DefaultKey>0000000000000000000000000000000000000000000=</DefaultKey>
    <Status>Active</Status>
    <CreatedAt>2012-08-22T16:48:10.217Z</CreatedAt>
    <AcsManagementEndpoint>https://myunittests-sb.accesscontrol.windows.net/</AcsManagementEndpoint>
    <ServiceBusEndpoint>https://myunittests.servicebus.windows.net/</ServiceBusEndpoint>
    <ConnectionString>Endpoint=sb://myunittests.servicebus.windows.net/;SharedSecretIssuer=owner;SharedSecretValue=0000000000000000000000000000000000000000000=</ConnectionString>
    <SubscriptionId>00000000000000000000000000000000</SubscriptionId>
    <Enabled>true</Enabled>
    </NamespaceDescription>
</content>
</entry>
        '''
        xmldoc = minidom.parseString(xmlstr)
        namespace = ServiceBusNamespace()

        mappings = (
            ('Name', 'name', None),
            ('Region', 'region', None),
            ('DefaultKey', 'default_key', None),
            ('Status', 'status', None),
            ('CreatedAt', 'created_at', None),
            ('AcsManagementEndpoint', 'acs_management_endpoint', None),
            ('ServiceBusEndpoint', 'servicebus_endpoint', None),
            ('ConnectionString', 'connection_string', None),
            ('SubscriptionId', 'subscription_id', None),
            ('Enabled', 'enabled', _parse_bool),
        )

        for desc in _get_children_from_path(xmldoc,
                                            'entry',
                                            'content',
                                            'NamespaceDescription'):
            for xml_name, field_name, conversion_func in mappings:
                node_value = _get_first_child_node_value(desc, xml_name)
                if node_value is not None:
                    if conversion_func is not None:
                        node_value = conversion_func(node_value)
                    setattr(namespace, field_name, node_value)

        return namespace
Ejemplo n.º 15
0
def _convert_xml_to_rule(xmlstr):
    ''' Converts response xml to rule object.

    The format of xml for rule:
<entry xmlns='http://www.w3.org/2005/Atom'>
<content type='application/xml'>
<RuleDescription
    xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
    <Filter i:type="SqlFilterExpression">
        <SqlExpression>MyProperty='XYZ'</SqlExpression>
    </Filter>
    <Action i:type="SqlFilterAction">
        <SqlExpression>set MyProperty2 = 'ABC'</SqlExpression>
    </Action>
</RuleDescription>
</content>
</entry>
    '''
    xmldoc = minidom.parseString(xmlstr)
    rule = Rule()

    for rule_desc in _get_children_from_path(xmldoc,
                                             'entry',
                                             'content',
                                             'RuleDescription'):
        for xml_filter in _get_child_nodes(rule_desc, 'Filter'):
            filter_type = xml_filter.getAttributeNS(
                XML_SCHEMA_NAMESPACE, 'type')
            setattr(rule, 'filter_type', str(filter_type))
            if xml_filter.childNodes:

                for expr in _get_child_nodes(xml_filter, 'SqlExpression'):
                    setattr(rule, 'filter_expression',
                            expr.firstChild.nodeValue)

        for xml_action in _get_child_nodes(rule_desc, 'Action'):
            action_type = xml_action.getAttributeNS(
                XML_SCHEMA_NAMESPACE, 'type')
            setattr(rule, 'action_type', str(action_type))
            if xml_action.childNodes:
                action_expression = xml_action.childNodes[0].firstChild
                if action_expression:
                    setattr(rule, 'action_expression',
                            action_expression.nodeValue)

    # extract id, updated and name value from feed entry and set them of rule.
    for name, value in _get_entry_properties(xmlstr, True, '/rules').items():
        setattr(rule, name, value)

    return rule
Ejemplo n.º 16
0
def _convert_xml_to_rule(xmlstr):
    ''' Converts response xml to rule object.

    The format of xml for rule:
<entry xmlns='http://www.w3.org/2005/Atom'>
<content type='application/xml'>
<RuleDescription
    xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
    <Filter i:type="SqlFilterExpression">
        <SqlExpression>MyProperty='XYZ'</SqlExpression>
    </Filter>
    <Action i:type="SqlFilterAction">
        <SqlExpression>set MyProperty2 = 'ABC'</SqlExpression>
    </Action>
</RuleDescription>
</content>
</entry>
    '''
    xmldoc = minidom.parseString(xmlstr)
    rule = Rule()

    for rule_desc in _get_children_from_path(xmldoc, 'entry', 'content',
                                             'RuleDescription'):
        for xml_filter in _get_child_nodes(rule_desc, 'Filter'):
            filter_type = xml_filter.getAttributeNS(XML_SCHEMA_NAMESPACE,
                                                    'type')
            setattr(rule, 'filter_type', str(filter_type))
            if xml_filter.childNodes:

                for expr in _get_child_nodes(xml_filter, 'SqlExpression'):
                    setattr(rule, 'filter_expression',
                            expr.firstChild.nodeValue)

        for xml_action in _get_child_nodes(rule_desc, 'Action'):
            action_type = xml_action.getAttributeNS(XML_SCHEMA_NAMESPACE,
                                                    'type')
            setattr(rule, 'action_type', str(action_type))
            if xml_action.childNodes:
                action_expression = xml_action.childNodes[0].firstChild
                if action_expression:
                    setattr(rule, 'action_expression',
                            action_expression.nodeValue)

    # extract id, updated and name value from feed entry and set them of rule.
    for name, value in _get_entry_properties(xmlstr, True, '/rules').items():
        setattr(rule, name, value)

    return rule
Ejemplo n.º 17
0
def _convert_xml_to_subscription(xmlstr):
    '''Converts xml response to subscription

    The xml format for subscription:
    <entry xmlns='http://www.w3.org/2005/Atom'>  
    <content type='application/xml'>    
    <SubscriptionDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
       <LockDuration>PT5M</LockDuration>
       <RequiresSession>false</RequiresSession>
       <DefaultMessageTimeToLive>P10675199DT2H48M5.4775807S</DefaultMessageTimeToLive>
       <DeadLetteringOnMessageExpiration>false</DeadLetteringOnMessageExpiration>   <DeadLetteringOnFilterEvaluationExceptions>true</DeadLetteringOnFilterEvaluationExceptions>
    </SubscriptionDescription>  
    </content>
    </entry>
    '''
    xmldoc = minidom.parseString(xmlstr)
    subscription = Subscription()

    for desc in _get_children_from_path(xmldoc, 'entry', 'content', 'SubscriptionDescription'):        
        node_value = _get_first_child_node_value(desc, 'LockDuration')
        if node_value is not None:
            subscription.lock_duration = node_value
        node_value = _get_first_child_node_value(desc, 'RequiresSession')
        if node_value is not None:
            subscription.requires_session = _parse_bool(node_value)
        node_value = _get_first_child_node_value(desc, 'DefaultMessageTimeToLive')
        if node_value is not None:
            subscription.default_message_time_to_live = node_value
        node_value = _get_first_child_node_value(desc, 'DeadLetteringOnFilterEvaluationExceptions')
        if node_value is not None:
            subscription.dead_lettering_on_filter_evaluation_exceptions = _parse_bool(node_value)
        node_value = _get_first_child_node_value(desc, 'DeadLetteringOnMessageExpiration')
        if node_value is not None:
            subscription.dead_lettering_on_message_expiration = _parse_bool(node_value)
        node_value = _get_first_child_node_value(desc, 'EnableBatchedOperations')
        if node_value is not None:
            subscription.enable_batched_operations = _parse_bool(node_value)
        node_value = _get_first_child_node_value(desc, 'MaxDeliveryCount')
        if node_value is not None:
            subscription.max_delivery_count = int(node_value)
        node_value = _get_first_child_node_value(desc, 'MessageCount')
        if node_value is not None:
            subscription.message_count = int(node_value)

    for name, value in _get_entry_properties(xmlstr, True, '/subscriptions').iteritems():
        setattr(subscription, name, value)

    return subscription
Ejemplo n.º 18
0
def _convert_xml_to_topic(xmlstr):
    '''Converts xml response to topic

    The xml format for topic:
    <entry xmlns='http://www.w3.org/2005/Atom'>  
    <content type='application/xml'>    
    <TopicDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
       <DefaultMessageTimeToLive>P10675199DT2H48M5.4775807S</DefaultMessageTimeToLive>
       <MaxSizeInMegaBytes>1024</MaxSizeInMegaBytes>
       <RequiresDuplicateDetection>false</RequiresDuplicateDetection>
       <DuplicateDetectionHistoryTimeWindow>P7D</DuplicateDetectionHistoryTimeWindow>
       <DeadLetteringOnFilterEvaluationExceptions>true</DeadLetteringOnFilterEvaluationExceptions>
    </TopicDescription>  
    </content>
    </entry>
    '''
    xmldoc = minidom.parseString(xmlstr)
    topic = Topic()

    invalid_topic = True
    #get node for each attribute in Topic class, if nothing found then the response is not valid xml for Topic.
    for desc in _get_children_from_path(xmldoc, 'entry', 'content',
                                        'TopicDescription'):
        invalid_topic = True
        for attr_name, attr_value in vars(topic).iteritems():
            xml_attrs = _get_child_nodes(desc,
                                         _get_serialization_name(attr_name))
            if xml_attrs:
                xml_attr = xml_attrs[0]
                if xml_attr.firstChild:
                    value = xml_attr.firstChild.nodeValue
                    conversion = _TOPIC_CONVERSION.get(attr_name)
                    if conversion is not None:
                        value = conversion(value)
                    setattr(topic, attr_name, value)
                    invalid_topic = False

    if invalid_topic:
        raise WindowsAzureError(azure._ERROR_TOPIC_NOT_FOUND)

    #extract id, updated and name value from feed entry and set them of topic.
    for name, value in _get_entry_properties(xmlstr, True).iteritems():
        setattr(topic, name, value)
    return topic
Ejemplo n.º 19
0
def _convert_xml_to_queue(xmlstr):
    ''' Converts xml response to queue object.
    
    The format of xml response for queue:
    <QueueDescription xmlns=\"http://schemas.microsoft.com/netservices/2010/10/servicebus/connect\">
    <MaxSizeInBytes>10000</MaxSizeInBytes>
    <DefaultMessageTimeToLive>PT5M</DefaultMessageTimeToLive>
    <LockDuration>PT2M</LockDuration>
    <RequiresGroupedReceives>False</RequiresGroupedReceives>
    <SupportsDuplicateDetection>False</SupportsDuplicateDetection>
    ...
    </QueueDescription>

    '''
    xmldoc = minidom.parseString(xmlstr)
    queue = Queue()

    invalid_queue = True
    #get node for each attribute in Queue class, if nothing found then the response is not valid xml for Queue.
    for queue_desc in _get_children_from_path(xmldoc, 'entry', 'content',
                                              'QueueDescription'):
        for attr_name, attr_value in vars(queue).iteritems():
            xml_attrs = _get_child_nodes(queue_desc,
                                         _get_serialization_name(attr_name))
            if xml_attrs:
                xml_attr = xml_attrs[0]
                if xml_attr.firstChild:
                    value = xml_attr.firstChild.nodeValue
                    conversion = _QUEUE_CONVERSION.get(attr_name)
                    if conversion is not None:
                        value = conversion(value)
                    setattr(queue, attr_name, value)
                    invalid_queue = False

    if invalid_queue:
        raise WindowsAzureError(azure._ERROR_QUEUE_NOT_FOUND)

    #extract id, updated and name value from feed entry and set them of queue.
    for name, value in _get_entry_properties(xmlstr, True).iteritems():
        setattr(queue, name, value)

    return queue
Ejemplo n.º 20
0
def _convert_xml_to_topic(xmlstr):
    '''Converts xml response to topic

    The xml format for topic:
    <entry xmlns='http://www.w3.org/2005/Atom'>  
    <content type='application/xml'>    
    <TopicDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
       <DefaultMessageTimeToLive>P10675199DT2H48M5.4775807S</DefaultMessageTimeToLive>
       <MaxSizeInMegaBytes>1024</MaxSizeInMegaBytes>
       <RequiresDuplicateDetection>false</RequiresDuplicateDetection>
       <DuplicateDetectionHistoryTimeWindow>P7D</DuplicateDetectionHistoryTimeWindow>
       <DeadLetteringOnFilterEvaluationExceptions>true</DeadLetteringOnFilterEvaluationExceptions>
    </TopicDescription>  
    </content>
    </entry>
    '''
    xmldoc = minidom.parseString(xmlstr)
    topic = Topic()

    invalid_topic = True
    #get node for each attribute in Topic class, if nothing found then the response is not valid xml for Topic.
    for desc in _get_children_from_path(xmldoc, 'entry', 'content', 'TopicDescription'):
        invalid_topic = True
        for attr_name, attr_value in vars(topic).iteritems():
            xml_attrs = _get_child_nodes(desc, _get_serialization_name(attr_name))
            if xml_attrs:
                xml_attr = xml_attrs[0]
                if xml_attr.firstChild:
                    value = xml_attr.firstChild.nodeValue
                    conversion = _TOPIC_CONVERSION.get(attr_name)
                    if conversion is not None:
                        value = conversion(value)
                    setattr(topic, attr_name, value)
                    invalid_topic = False

    if invalid_topic:
        raise WindowsAzureError(azure._ERROR_TOPIC_NOT_FOUND)

    #extract id, updated and name value from feed entry and set them of topic.
    for name, value in _get_entry_properties(xmlstr, True).iteritems():
        setattr(topic, name, value)
    return topic
Ejemplo n.º 21
0
    def get_request_partition_key(self, request):
        '''
        Extracts PartitionKey from request.body if it is a POST request or from request.path if 
        it is not a POST request. Only insert operation request is a POST request and the 
        PartitionKey is in the request body.

        request: the request to insert, update or delete entity
        '''
        if request.method == 'POST':
            doc = minidom.parseString(request.body)
            part_key = _get_children_from_path(doc, 'entry', 'content', (METADATA_NS, 'properties'), (_DATASERVICES_NS, 'PartitionKey'))
            if not part_key:
                raise WindowsAzureError(azure._ERROR_CANNOT_FIND_PARTITION_KEY)
            return part_key[0].firstChild.nodeValue
        else:
            uri = urllib2.unquote(request.path)
            pos1 = uri.find('PartitionKey=\'')
            pos2 = uri.find('\',', pos1)
            if pos1 == -1 or pos2 == -1:
                raise WindowsAzureError(azure._ERROR_CANNOT_FIND_PARTITION_KEY)
            return uri[pos1 + len('PartitionKey=\''):pos2]
Ejemplo n.º 22
0
def _convert_xml_to_queue(xmlstr):
    ''' Converts xml response to queue object.
    
    The format of xml response for queue:
    <QueueDescription xmlns=\"http://schemas.microsoft.com/netservices/2010/10/servicebus/connect\">
    <MaxSizeInBytes>10000</MaxSizeInBytes>
    <DefaultMessageTimeToLive>PT5M</DefaultMessageTimeToLive>
    <LockDuration>PT2M</LockDuration>
    <RequiresGroupedReceives>False</RequiresGroupedReceives>
    <SupportsDuplicateDetection>False</SupportsDuplicateDetection>
    ...
    </QueueDescription>

    '''
    xmldoc = minidom.parseString(xmlstr)
    queue = Queue()

    invalid_queue = True
    #get node for each attribute in Queue class, if nothing found then the response is not valid xml for Queue.
    for queue_desc in _get_children_from_path(xmldoc, 'entry', 'content', 'QueueDescription'):
        for attr_name, attr_value in vars(queue).iteritems():
            xml_attrs = _get_child_nodes(queue_desc, _get_serialization_name(attr_name))
            if xml_attrs:
                xml_attr = xml_attrs[0]
                if xml_attr.firstChild:
                    value = xml_attr.firstChild.nodeValue
                    conversion = _QUEUE_CONVERSION.get(attr_name)
                    if conversion is not None:
                        value = conversion(value)
                    setattr(queue, attr_name, value)
                    invalid_queue = False

    if invalid_queue:
        raise WindowsAzureError(azure._ERROR_QUEUE_NOT_FOUND)

    #extract id, updated and name value from feed entry and set them of queue.
    for name, value in _get_entry_properties(xmlstr, True).iteritems():
        setattr(queue, name, value)

    return queue
Ejemplo n.º 23
0
def _convert_xml_to_subscription(xmlstr):
    '''Converts xml response to subscription

    The xml format for subscription:
    <entry xmlns='http://www.w3.org/2005/Atom'>  
    <content type='application/xml'>    
    <SubscriptionDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
       <LockDuration>PT5M</LockDuration>
       <RequiresSession>false</RequiresSession>
       <DefaultMessageTimeToLive>P10675199DT2H48M5.4775807S</DefaultMessageTimeToLive>
       <DeadLetteringOnMessageExpiration>false</DeadLetteringOnMessageExpiration>   <DeadLetteringOnFilterEvaluationExceptions>true</DeadLetteringOnFilterEvaluationExceptions>
    </SubscriptionDescription>  
    </content>
    </entry>
    '''
    xmldoc = minidom.parseString(xmlstr)
    subscription = Subscription()

    for desc in _get_children_from_path(xmldoc, 'entry', 'content',
                                        'subscriptiondescription'):
        for attr_name, attr_value in vars(subscription).iteritems():
            tag_name = attr_name.replace('_', '')
            xml_attrs = _get_child_nodes(desc, tag_name)
            if xml_attrs:
                xml_attr = xml_attrs[0]
                if xml_attr.firstChild:
                    value = xml_attr.firstChild.nodeValue
                    conversion = _SUBSCRIPTION_CONVERSION.get(attr_name)
                    if conversion is not None:
                        value = conversion(value)
                    setattr(subscription, attr_name, value)

    for name, value in _get_entry_properties(xmlstr, True).iteritems():
        setattr(subscription, name, value)

    return subscription
Ejemplo n.º 24
0
def _convert_xml_to_queue(xmlstr):
    ''' Converts xml response to queue object.

    The format of xml response for queue:
<QueueDescription
    xmlns=\"http://schemas.microsoft.com/netservices/2010/10/servicebus/connect\">
    <MaxSizeInBytes>10000</MaxSizeInBytes>
    <DefaultMessageTimeToLive>PT5M</DefaultMessageTimeToLive>
    <LockDuration>PT2M</LockDuration>
    <RequiresGroupedReceives>False</RequiresGroupedReceives>
    <SupportsDuplicateDetection>False</SupportsDuplicateDetection>
    ...
</QueueDescription>

    '''
    xmldoc = minidom.parseString(xmlstr)
    queue = Queue()

    invalid_queue = True
    # get node for each attribute in Queue class, if nothing found then the
    # response is not valid xml for Queue.
    for desc in _get_children_from_path(xmldoc,
                                        'entry',
                                        'content',
                                        'QueueDescription'):
        node_value = _get_first_child_node_value(desc, 'LockDuration')
        if node_value is not None:
            queue.lock_duration = node_value
            invalid_queue = False

        node_value = _get_first_child_node_value(desc, 'MaxSizeInMegabytes')
        if node_value is not None:
            queue.max_size_in_megabytes = int(node_value)
            invalid_queue = False

        node_value = _get_first_child_node_value(
            desc, 'RequiresDuplicateDetection')
        if node_value is not None:
            queue.requires_duplicate_detection = _parse_bool(node_value)
            invalid_queue = False

        node_value = _get_first_child_node_value(desc, 'RequiresSession')
        if node_value is not None:
            queue.requires_session = _parse_bool(node_value)
            invalid_queue = False

        node_value = _get_first_child_node_value(
            desc, 'DefaultMessageTimeToLive')
        if node_value is not None:
            queue.default_message_time_to_live = node_value
            invalid_queue = False

        node_value = _get_first_child_node_value(
            desc, 'DeadLetteringOnMessageExpiration')
        if node_value is not None:
            queue.dead_lettering_on_message_expiration = _parse_bool(node_value)
            invalid_queue = False

        node_value = _get_first_child_node_value(
            desc, 'DuplicateDetectionHistoryTimeWindow')
        if node_value is not None:
            queue.duplicate_detection_history_time_window = node_value
            invalid_queue = False

        node_value = _get_first_child_node_value(
            desc, 'EnableBatchedOperations')
        if node_value is not None:
            queue.enable_batched_operations = _parse_bool(node_value)
            invalid_queue = False

        node_value = _get_first_child_node_value(desc, 'MaxDeliveryCount')
        if node_value is not None:
            queue.max_delivery_count = int(node_value)
            invalid_queue = False

        node_value = _get_first_child_node_value(desc, 'MessageCount')
        if node_value is not None:
            queue.message_count = int(node_value)
            invalid_queue = False

        node_value = _get_first_child_node_value(desc, 'SizeInBytes')
        if node_value is not None:
            queue.size_in_bytes = int(node_value)
            invalid_queue = False

    if invalid_queue:
        raise WindowsAzureError(_ERROR_QUEUE_NOT_FOUND)

    # extract id, updated and name value from feed entry and set them of queue.
    for name, value in _get_entry_properties(xmlstr, True).items():
        setattr(queue, name, value)

    return queue
Ejemplo n.º 25
0
def _convert_xml_to_queue(xmlstr):
    ''' Converts xml response to queue object.
    
    The format of xml response for queue:
    <QueueDescription xmlns=\"http://schemas.microsoft.com/netservices/2010/10/servicebus/connect\">
    <MaxSizeInBytes>10000</MaxSizeInBytes>
    <DefaultMessageTimeToLive>PT5M</DefaultMessageTimeToLive>
    <LockDuration>PT2M</LockDuration>
    <RequiresGroupedReceives>False</RequiresGroupedReceives>
    <SupportsDuplicateDetection>False</SupportsDuplicateDetection>
    ...
    </QueueDescription>

    '''
    xmldoc = minidom.parseString(xmlstr)
    queue = Queue()

    invalid_queue = True
    #get node for each attribute in Queue class, if nothing found then the response is not valid xml for Queue.
    for desc in _get_children_from_path(xmldoc, 'entry', 'content',
                                        'QueueDescription'):
        node_value = _get_first_child_node_value(desc, 'LockDuration')
        if node_value is not None:
            queue.lock_duration = node_value
            invalid_queue = False
        node_value = _get_first_child_node_value(desc, 'MaxSizeInMegabytes')
        if node_value is not None:
            queue.max_size_in_megabytes = int(node_value)
            invalid_queue = False
        node_value = _get_first_child_node_value(desc,
                                                 'RequiresDuplicateDetection')
        if node_value is not None:
            queue.requires_duplicate_detection = _parse_bool(node_value)
            invalid_queue = False
        node_value = _get_first_child_node_value(desc, 'RequiresSession')
        if node_value is not None:
            queue.requires_session = _parse_bool(node_value)
            invalid_queue = False
        node_value = _get_first_child_node_value(desc,
                                                 'DefaultMessageTimeToLive')
        if node_value is not None:
            queue.default_message_time_to_live = node_value
            invalid_queue = False
        node_value = _get_first_child_node_value(
            desc, 'DeadLetteringOnMessageExpiration')
        if node_value is not None:
            queue.dead_lettering_on_message_expiration = _parse_bool(
                node_value)
            invalid_queue = False
        node_value = _get_first_child_node_value(
            desc, 'DuplicateDetectionHistoryTimeWindow')
        if node_value is not None:
            queue.duplicate_detection_history_time_window = node_value
            invalid_queue = False
        node_value = _get_first_child_node_value(desc,
                                                 'EnableBatchedOperations')
        if node_value is not None:
            queue.enable_batched_operations = _parse_bool(node_value)
            invalid_queue = False
        node_value = _get_first_child_node_value(desc, 'MaxDeliveryCount')
        if node_value is not None:
            queue.max_delivery_count = int(node_value)
            invalid_queue = False
        node_value = _get_first_child_node_value(desc, 'MessageCount')
        if node_value is not None:
            queue.message_count = int(node_value)
            invalid_queue = False
        node_value = _get_first_child_node_value(desc, 'SizeInBytes')
        if node_value is not None:
            queue.size_in_bytes = int(node_value)
            invalid_queue = False

    if invalid_queue:
        raise WindowsAzureError(azure._ERROR_QUEUE_NOT_FOUND)

    #extract id, updated and name value from feed entry and set them of queue.
    for name, value in _get_entry_properties(xmlstr, True).iteritems():
        setattr(queue, name, value)

    return queue