<s> from dateutil import parser <EOL> try : <EOL> from xml . etree import cElementTree as ETree <EOL> except ImportError : <EOL> from xml . etree import ElementTree as ETree <EOL> from . . _common_conversion import ( <EOL> _decode_base64_to_text , <EOL> _to_str , <EOL> ) <EOL> from . . _deserialization import ( <EOL> _parse_properties , <EOL> _int_to_str , <EOL> _parse_metadata , <EOL> _parse_response_for_dict , <EOL> _convert_xml_to_signed_identifiers , <EOL> ) <EOL> from . models import ( <EOL> Container , <EOL> Blob , <EOL> BlobBlock , <EOL> BlobBlockList , <EOL> BlobBlockState , <EOL> BlobProperties , <EOL> PageRange , <EOL> ContainerProperties , <EOL> AppendBlockProperties , <EOL> PageBlobProperties , <EOL> ResourceProperties , <EOL> BlobPrefix , <EOL> ) <EOL> from . . models import _list <EOL> def _parse_base_properties ( response ) : <EOL> '''<STR_LIT>''' <EOL> raw_headers = _parse_response_for_dict ( response ) <EOL> resource_properties = ResourceProperties ( ) <EOL> resource_properties . last_modified = parser . parse ( raw_headers . get ( '<STR_LIT>' ) ) <EOL> resource_properties . etag = raw_headers . get ( '<STR_LIT>' ) <EOL> return resource_properties <EOL> def _parse_page_properties ( response ) : <EOL> '''<STR_LIT>''' <EOL> raw_headers = _parse_response_for_dict ( response ) <EOL> put_page = PageBlobProperties ( ) <EOL> put_page . last_modified = parser . parse ( raw_headers . get ( '<STR_LIT>' ) ) <EOL> put_page . etag = raw_headers . get ( '<STR_LIT>' ) <EOL> put_page . sequence_number = _int_to_str ( raw_headers . get ( '<STR_LIT>' ) ) <EOL> return put_page <EOL> def _parse_append_block ( response ) : <EOL> '''<STR_LIT>''' <EOL> raw_headers = _parse_response_for_dict ( response ) <EOL> append_block = AppendBlockProperties ( ) <EOL> append_block . last_modified = parser . parse ( raw_headers . get ( '<STR_LIT>' ) ) <EOL> append_block . etag = raw_headers . get ( '<STR_LIT>' ) <EOL> append_block . append_offset = _int_to_str ( raw_headers . get ( '<STR_LIT>' ) ) <EOL> append_block . committed_block_count = _int_to_str ( raw_headers . get ( '<STR_LIT>' ) ) <EOL> return append_block <EOL> def _parse_snapshot_blob ( name , response ) : <EOL> '''<STR_LIT>''' <EOL> raw_headers = _parse_response_for_dict ( response ) <EOL> snapshot = raw_headers . get ( '<STR_LIT>' ) <EOL> return _parse_blob ( name , snapshot , response ) <EOL> def _parse_lease_time ( response ) : <EOL> '''<STR_LIT>''' <EOL> raw_headers = _parse_response_for_dict ( response ) <EOL> lease_time = raw_headers . get ( '<STR_LIT>' ) <EOL> if lease_time : <EOL> lease_time = _int_to_str ( lease_time ) <EOL> return lease_time <EOL> def _parse_lease_id ( response ) : <EOL> '''<STR_LIT>''' <EOL> raw_headers = _parse_response_for_dict ( response ) <EOL> lease_id = raw_headers . get ( '<STR_LIT>' ) <EOL> return lease_id <EOL> def _parse_blob ( name , snapshot , response ) : <EOL> if response is None : <EOL> return None <EOL> metadata = _parse_metadata ( response ) <EOL> props = _parse_properties ( response , BlobProperties ) <EOL> return Blob ( name , snapshot , response . body , props , metadata ) <EOL> def _parse_container ( name , response ) : <EOL> if response is None : <EOL> return None <EOL> metadata = _parse_metadata ( response ) <EOL> props = _parse_properties ( response , ContainerProperties ) <EOL> return Container ( name , props , metadata ) <EOL> def _convert_xml_to_signed_identifiers_and_access ( response ) : <EOL> acl = _convert_xml_to_signed_identifiers ( response . body ) <EOL> raw_headers = _parse_response_for_dict ( response ) <EOL> acl . public_access = raw_headers . get ( '<STR_LIT>' ) <EOL> return acl <EOL> def _convert_xml_to_containers ( response ) : <EOL> '''<STR_LIT>''' <EOL> if response is None or response . body is None : <EOL> return response <EOL> containers = _list ( ) <EOL> list_element = ETree . fromstring ( response . body ) <EOL> setattr ( containers , '<STR_LIT>' , list_element . findtext ( '<STR_LIT>' ) ) <EOL> containers_element = list_element . find ( '<STR_LIT>' ) <EOL> for container_element in containers_element . findall ( '<STR_LIT>' ) : <EOL> container = Container ( ) <EOL> container . name = container_element . findtext ( '<STR_LIT:Name>' ) <EOL> metadata_root_element = container_element . find ( '<STR_LIT>' ) <EOL> if metadata_root_element is not None : <EOL> container . metadata = dict ( ) <EOL> for metadata_element in metadata_root_element : <EOL> container . metadata [ metadata_element . tag ] = metadata_element . text <EOL> properties_element = container_element . find ( '<STR_LIT>' ) <EOL> container . properties . etag = properties_element . findtext ( '<STR_LIT>' ) <EOL> container . properties . last_modified = parser . parse ( properties_element . findtext ( '<STR_LIT>' ) ) <EOL> container . properties . lease_status = properties_element . findtext ( '<STR_LIT>' ) <EOL> container . properties . lease_state = properties_element . findtext ( '<STR_LIT>' ) <EOL> container . properties . lease_duration = properties_element . findtext ( '<STR_LIT>' ) <EOL> containers . append ( container ) <EOL> return containers <EOL> LIST_BLOBS_ATTRIBUTE_MAP = { <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , parser . parse ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , _to_str ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , _int_to_str ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , _to_str ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , _int_to_str ) , <EOL> '<STR_LIT:Content-Type>' : ( '<STR_LIT>' , '<STR_LIT>' , _to_str ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , _to_str ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , _to_str ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , _to_str ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , _to_str ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , _to_str ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT:status>' , _to_str ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT:state>' , _to_str ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , _to_str ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT:id>' , _to_str ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT:source>' , _to_str ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT:status>' , _to_str ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , _to_str ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , _to_str ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , _to_str ) , <EOL> } <EOL> def _convert_xml_to_blob_list ( response ) : <EOL> '''<STR_LIT>''' <EOL> if response is None or response . body is None : <EOL> return response <EOL> blob_list = _list ( ) <EOL> list_element = ETree . fromstring ( response . body ) <EOL> setattr ( blob_list , '<STR_LIT>' , list_element . findtext ( '<STR_LIT>' ) ) <EOL> blobs_element = list_element . find ( '<STR_LIT>' ) <EOL> blob_prefix_elements = blobs_element . findall ( '<STR_LIT>' ) <EOL> if blob_prefix_elements is not None : <EOL> for blob_prefix_element in blob_prefix_elements : <EOL> prefix = BlobPrefix ( ) <EOL> prefix . name = blob_prefix_element . findtext ( '<STR_LIT:Name>' ) <EOL> blob_list . append ( prefix ) <EOL> for blob_element in blobs_element . findall ( '<STR_LIT>' ) : <EOL> blob = Blob ( ) <EOL> blob . name = blob_element . findtext ( '<STR_LIT:Name>' ) <EOL> blob . snapshot = blob_element . findtext ( '<STR_LIT>' ) <EOL> properties_element = blob_element . find ( '<STR_LIT>' ) <EOL> if properties_element is not None : <EOL> for property_element in properties_element : <EOL> info = LIST_BLOBS_ATTRIBUTE_MAP . get ( property_element . tag ) <EOL> if info is None : <EOL> setattr ( blob . properties , property_element . tag , _to_str ( property_element . text ) ) <EOL> elif info [ <NUM_LIT:0> ] is None : <EOL> setattr ( blob . properties , info [ <NUM_LIT:1> ] , info [ <NUM_LIT:2> ] ( property_element . text ) ) <EOL> else : <EOL> attr = getattr ( blob . properties , info [ <NUM_LIT:0> ] ) <EOL> setattr ( attr , info [ <NUM_LIT:1> ] , info [ <NUM_LIT:2> ] ( property_element . text ) ) <EOL> metadata_root_element = blob_element . find ( '<STR_LIT>' ) <EOL> if metadata_root_element is not None : <EOL> blob . metadata = dict ( ) <EOL> for metadata_element in metadata_root_element : <EOL> blob . metadata [ metadata_element . tag ] = metadata_element . text <EOL> blob_list . append ( blob ) <EOL> return blob_list <EOL> def _convert_xml_to_block_list ( response ) : <EOL> '''<STR_LIT>''' <EOL> if response is None or response . body is None : <EOL> return response <EOL> block_list = BlobBlockList ( ) <EOL> list_element = ETree . fromstring ( response . body ) <EOL> committed_blocks_element = list_element . find ( '<STR_LIT>' ) <EOL> for block_element in committed_blocks_element . findall ( '<STR_LIT>' ) : <EOL> block_id = _decode_base64_to_text ( block_element . findtext ( '<STR_LIT:Name>' , '<STR_LIT>' ) ) <EOL> block_size = int ( block_element . findtext ( '<STR_LIT>' ) ) <EOL> block = BlobBlock ( id = block_id , state = BlobBlockState . Committed ) <EOL> block . _set_size ( block_size ) <EOL> block_list . committed_blocks . append ( block ) <EOL> uncommitted_blocks_element = list_element . find ( '<STR_LIT>' ) <EOL> for block_element in uncommitted_blocks_element . findall ( '<STR_LIT>' ) : <EOL> block_id = _decode_base64_to_text ( block_element . findtext ( '<STR_LIT:Name>' , '<STR_LIT>' ) ) <EOL> block_size = int ( block_element . findtext ( '<STR_LIT>' ) ) <EOL> block = BlobBlock ( id = block_id , state = BlobBlockState . Uncommitted ) <EOL> block . _set_size ( block_size ) <EOL> block_list . uncommitted_blocks . append ( block ) <EOL> return block_list <EOL> def _convert_xml_to_page_ranges ( response ) : <EOL> '''<STR_LIT>''' <EOL> if response is None or response . body is None : <EOL> return response <EOL> page_list = list ( ) <EOL> list_element = ETree . fromstring ( response . body ) <EOL> for page_range_element in list_element : <EOL> if page_range_element . tag == '<STR_LIT>' : <EOL> is_cleared = False <EOL> elif page_range_element . tag == '<STR_LIT>' : <EOL> is_cleared = True <EOL> else : <EOL> pass <EOL> page_list . append ( <EOL> PageRange ( <EOL> int ( page_range_element . findtext ( '<STR_LIT>' ) ) , <EOL> int ( page_range_element . findtext ( '<STR_LIT>' ) ) , <EOL> is_cleared <EOL> ) <EOL> ) <EOL> return page_list </s>
