Ejemplo n.º 1
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
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
Ejemplo n.º 3
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.º 4
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.º 5
0
def _convert_xml_to_table(xmlstr):
    ''' Converts the xml response to table class
    Simply call convert_xml_to_entity and extract the table name, and add updated and author info
    '''
    table = Table()
    entity = _convert_xml_to_entity(xmlstr)
    setattr(table, 'name', entity.TableName)
    for name, value in _get_entry_properties(xmlstr, False).iteritems():
       setattr(table, name, value)
    return table
Ejemplo n.º 6
0
def _convert_xml_to_table(xmlstr):
    ''' Converts the xml response to table class
    Simply call convert_xml_to_entity and extract the table name, and add updated and author info
    '''
    table = Table()
    entity = _convert_xml_to_entity(xmlstr)
    setattr(table, 'name', entity.TableName)
    for name, value in _get_entry_properties(xmlstr, False).iteritems():
       setattr(table, name, value)
    return table
Ejemplo n.º 7
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.º 8
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'):        
        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.º 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
        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.º 11
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.º 12
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.º 13
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.º 14
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.º 15
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
Ejemplo n.º 16
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.º 17
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
Ejemplo n.º 18
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