def _convert_xml_to_queues(response): ''' <?xml version="1.0" encoding="utf-8"?> <EnumerationResults ServiceEndpoint="https://myaccount.queue.core.windows.net/"> <Prefix>string-value</Prefix> <Marker>string-value</Marker> <MaxResults>int-value</MaxResults> <Queues> <Queue> <Name>string-value</Name> <Metadata> <metadata-name>value</metadata-name> </Metadata> </Queue> <NextMarker /> </EnumerationResults> ''' if response is None or response.body is None: return None queues = _list() list_element = ETree.fromstring(response.body) # Set next marker next_marker = list_element.findtext('NextMarker') or None setattr(queues, 'next_marker', next_marker) queues_element = list_element.find('Queues') for queue_element in queues_element.findall('Queue'): # Name element queue = Queue() queue.name = queue_element.findtext('Name') # Metadata metadata_root_element = queue_element.find('Metadata') if metadata_root_element is not None: queue.metadata = dict() for metadata_element in metadata_root_element: queue.metadata[metadata_element.tag] = metadata_element.text # Add queue to list queues.append(queue) return queues
def _convert_json_response_to_entities(response, property_resolver, require_encryption, key_encryption_key, key_resolver): ''' Converts the response to tables class. ''' if response is None or response.body is None: return None entities = _list() entities.next_marker = _get_continuation_from_response_headers(response) root = loads(response.body) for entity in root['value']: entity = _decrypt_and_deserialize_entity(entity, property_resolver, require_encryption, key_encryption_key, key_resolver) entities.append(entity) return entities
def _convert_json_response_to_tables(response): ''' Converts the response to tables class. ''' if response is None or response.body is None: return None tables = _list() continuation = _get_continuation_from_response_headers(response) tables.next_marker = continuation.get('nexttablename') root = loads(response.body) if 'TableName' in root: table = Table() table.name = root['TableName'] tables.append(table) else: for element in root['value']: table = Table() table.name = element['TableName'] tables.append(table) return tables
def _convert_xml_to_blob_list(response): ''' <?xml version="1.0" encoding="utf-8"?> <EnumerationResults ServiceEndpoint="http://myaccount.blob.core.windows.net/" ContainerName="mycontainer"> <Prefix>string-value</Prefix> <Marker>string-value</Marker> <MaxResults>int-value</MaxResults> <Delimiter>string-value</Delimiter> <Blobs> <Blob> <Name>blob-name</name> <Snapshot>date-time-value</Snapshot> <Properties> <Last-Modified>date-time-value</Last-Modified> <Etag>etag</Etag> <Content-Length>size-in-bytes</Content-Length> <Content-Type>blob-content-type</Content-Type> <Content-Encoding /> <Content-Language /> <Content-MD5 /> <Cache-Control /> <x-ms-blob-sequence-number>sequence-number</x-ms-blob-sequence-number> <BlobType>BlockBlob|PageBlob|AppendBlob</BlobType> <LeaseStatus>locked|unlocked</LeaseStatus> <LeaseState>available | leased | expired | breaking | broken</LeaseState> <LeaseDuration>infinite | fixed</LeaseDuration> <CopyId>id</CopyId> <CopyStatus>pending | success | aborted | failed </CopyStatus> <CopySource>source url</CopySource> <CopyProgress>bytes copied/bytes total</CopyProgress> <CopyCompletionTime>datetime</CopyCompletionTime> <CopyStatusDescription>error string</CopyStatusDescription> <AccessTier>P4 | P6 | P10 | P20 | P30 | P40 | P50 | P60 | Archive | Cool | Hot</AccessTier> <AccessTierChangeTime>date-time-value</AccessTierChangeTime> <AccessTierInferred>true</AccessTierInferred> </Properties> <Metadata> <Name>value</Name> </Metadata> </Blob> <BlobPrefix> <Name>blob-prefix</Name> </BlobPrefix> </Blobs> <NextMarker /> </EnumerationResults> ''' if response is None or response.body is None: return None blob_list = _list() list_element = ETree.fromstring(response.body) setattr(blob_list, 'next_marker', list_element.findtext('NextMarker')) blobs_element = list_element.find('Blobs') blob_prefix_elements = blobs_element.findall('BlobPrefix') if blob_prefix_elements is not None: for blob_prefix_element in blob_prefix_elements: prefix = BlobPrefix() prefix.name = blob_prefix_element.findtext('Name') blob_list.append(prefix) for blob_element in blobs_element.findall('Blob'): blob = Blob() blob.name = blob_element.findtext('Name') blob.snapshot = blob_element.findtext('Snapshot') # Properties properties_element = blob_element.find('Properties') if properties_element is not None: for property_element in properties_element: info = LIST_BLOBS_ATTRIBUTE_MAP.get(property_element.tag) if info is None: setattr(blob.properties, property_element.tag, _to_str(property_element.text)) elif info[0] is None: setattr(blob.properties, info[1], info[2](property_element.text)) else: attr = getattr(blob.properties, info[0]) setattr(attr, info[1], info[2](property_element.text)) # Metadata metadata_root_element = blob_element.find('Metadata') if metadata_root_element is not None: blob.metadata = dict() for metadata_element in metadata_root_element: blob.metadata[metadata_element.tag] = metadata_element.text # Add blob to list blob_list.append(blob) return blob_list
def _convert_xml_to_containers(response): ''' <?xml version="1.0" encoding="utf-8"?> <EnumerationResults ServiceEndpoint="https://myaccount.blob.core.windows.net"> <Prefix>string-value</Prefix> <Marker>string-value</Marker> <MaxResults>int-value</MaxResults> <Containers> <Container> <Name>container-name</Name> <Properties> <Last-Modified>date/time-value</Last-Modified> <Etag>etag</Etag> <LeaseStatus>locked | unlocked</LeaseStatus> <LeaseState>available | leased | expired | breaking | broken</LeaseState> <LeaseDuration>infinite | fixed</LeaseDuration> <PublicAccess>blob | container</PublicAccess> </Properties> <Metadata> <metadata-name>value</metadata-name> </Metadata> </Container> </Containers> <NextMarker>marker-value</NextMarker> </EnumerationResults> ''' if response is None or response.body is None: return None containers = _list() list_element = ETree.fromstring(response.body) # Set next marker setattr(containers, 'next_marker', list_element.findtext('NextMarker')) containers_element = list_element.find('Containers') for container_element in containers_element.findall('Container'): # Name element container = Container() container.name = container_element.findtext('Name') # Metadata metadata_root_element = container_element.find('Metadata') if metadata_root_element is not None: container.metadata = dict() for metadata_element in metadata_root_element: container.metadata[metadata_element.tag] = metadata_element.text # Properties properties_element = container_element.find('Properties') container.properties.etag = properties_element.findtext('Etag') container.properties.last_modified = parser.parse(properties_element.findtext('Last-Modified')) container.properties.lease_status = properties_element.findtext('LeaseStatus') container.properties.lease_state = properties_element.findtext('LeaseState') container.properties.lease_duration = properties_element.findtext('LeaseDuration') container.properties.public_access = properties_element.findtext('PublicAccess') # Add container to list containers.append(container) return containers