示例#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
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
示例#3
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
示例#4
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
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
示例#6
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
示例#7
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
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
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
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
示例#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'):
        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
示例#12
0
def _convert_xml_to_entity(xmlstr):
    ''' Convert xml response to entity.

    The format of entity:
    <entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
      <title />
      <updated>2008-09-18T23:46:19.3857256Z</updated>
      <author>
        <name />
      </author>
      <id />
      <content type="application/xml">
        <m:properties>
          <d:Address>Mountain View</d:Address>
          <d:Age m:type="Edm.Int32">23</d:Age>
          <d:AmountDue m:type="Edm.Double">200.23</d:AmountDue>
          <d:BinaryData m:type="Edm.Binary" m:null="true" />
          <d:CustomerCode m:type="Edm.Guid">c9da6455-213d-42c9-9a79-3e9149a57833</d:CustomerCode>
          <d:CustomerSince m:type="Edm.DateTime">2008-07-10T00:00:00</d:CustomerSince>
          <d:IsActive m:type="Edm.Boolean">true</d:IsActive>
          <d:NumOfOrders m:type="Edm.Int64">255</d:NumOfOrders>
          <d:PartitionKey>mypartitionkey</d:PartitionKey>
          <d:RowKey>myrowkey1</d:RowKey>
          <d:Timestamp m:type="Edm.DateTime">0001-01-01T00:00:00</d:Timestamp>
        </m:properties>
      </content>
    </entry>
    '''
    xmldoc = minidom.parseString(xmlstr)

    xml_properties = None
    for entry in _get_child_nodes(xmldoc, 'entry'):
        for content in _get_child_nodes(entry, 'content'):
            # TODO: Namespace
            xml_properties = _get_child_nodesNS(content, METADATA_NS,
                                                'properties')

    if not xml_properties:
        return None

    entity = Entity()
    # extract each property node and get the type from attribute and node value
    for xml_property in xml_properties[0].childNodes:
        name = _remove_prefix(xml_property.nodeName)

        if xml_property.firstChild:
            value = xml_property.firstChild.nodeValue
        else:
            value = ''

        isnull = xml_property.getAttributeNS(METADATA_NS, 'null')
        mtype = xml_property.getAttributeNS(METADATA_NS, 'type')

        # if not isnull and no type info, then it is a string and we just
        # need the str type to hold the property.
        if not isnull and not mtype:
            _set_entity_attr(entity, name, value)
        elif isnull == 'true':
            if mtype:
                property = EntityProperty(mtype, None)
            else:
                property = EntityProperty('Edm.String', None)
        else:  # need an object to hold the property
            conv = _ENTITY_TO_PYTHON_CONVERSIONS.get(mtype)
            if conv is not None:
                property = conv(value)
            else:
                property = EntityProperty(mtype, value)
            _set_entity_attr(entity, name, property)

        # extract id, updated and name value from feed entry and set them of
        # rule.
    for name, value in _get_entry_properties(xmlstr, True).items():
        if name in ['etag']:
            _set_entity_attr(entity, name, value)

    return entity
示例#13
0
def _convert_xml_to_entity(xmlstr):
    ''' Convert xml response to entity. 

    The format of entity:
    <entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
      <title />
      <updated>2008-09-18T23:46:19.3857256Z</updated>
      <author>
        <name />
      </author>
      <id />
      <content type="application/xml">
        <m:properties>
          <d:Address>Mountain View</d:Address>
          <d:Age m:type="Edm.Int32">23</d:Age>
          <d:AmountDue m:type="Edm.Double">200.23</d:AmountDue>
          <d:BinaryData m:type="Edm.Binary" m:null="true" />
          <d:CustomerCode m:type="Edm.Guid">c9da6455-213d-42c9-9a79-3e9149a57833</d:CustomerCode>
          <d:CustomerSince m:type="Edm.DateTime">2008-07-10T00:00:00</d:CustomerSince>
          <d:IsActive m:type="Edm.Boolean">true</d:IsActive>
          <d:NumOfOrders m:type="Edm.Int64">255</d:NumOfOrders>
          <d:PartitionKey>mypartitionkey</d:PartitionKey>
          <d:RowKey>myrowkey1</d:RowKey>
          <d:Timestamp m:type="Edm.DateTime">0001-01-01T00:00:00</d:Timestamp>
        </m:properties>
      </content>
    </entry>
    '''
    xmldoc = minidom.parseString(xmlstr)
    
    xml_properties = None
    for entry in _get_child_nodes(xmldoc, 'entry'):
        for content in _get_child_nodes(entry, 'content'):
            xml_properties = _get_child_nodesNS(content, METADATA_NS, 'properties') # TODO: Namespace
                
    if not xml_properties:
        return None

    entity = Entity()
    #extract each property node and get the type from attribute and node value
    for xml_property in xml_properties[0].childNodes:
        if xml_property.firstChild:
            name = _remove_prefix(xml_property.nodeName)
            #exclude the Timestamp since it is auto added by azure when inserting 
            #entity. We don't want this to mix with real properties
            if name in ['Timestamp']:
                continue
            value = xml_property.firstChild.nodeValue
            
            isnull = xml_property.getAttributeNS(METADATA_NS, 'null')
            mtype = xml_property.getAttributeNS(METADATA_NS, 'type')


            #if not isnull and no type info, then it is a string and we just need the str type to hold the property.
            if not isnull and not mtype:
                _set_entity_attr(entity, name, value)
            elif isnull == 'true':
                if mtype:
                    property = EntityProperty(mtype, None)
                else:
                    property = EntityProperty('Edm.String', None)
            else: #need an object to hold the property
                conv = _ENTITY_TO_PYTHON_CONVERSIONS.get(mtype)
                if conv is not None:
                    property = conv(value)
                else:
                    property = EntityProperty(mtype, value)
                _set_entity_attr(entity, name, property)

        #extract id, updated and name value from feed entry and set them of rule.
    for name, value in _get_entry_properties(xmlstr, True).iteritems():
        if name in ['etag']:
            _set_entity_attr(entity, name, value)

    return entity