o
    پi                     @   s   d dl Z d dlZd dlmZmZ d dlZd dlmZ dZ	dee
ef dee
ef fddZd	edee
ef fd
dZdee
ef defddZdd Zdd Zdd Zdd Zedkr`e  dS dS )    N)AnyDict)_xmls	  <?xml version="1.0" encoding="utf-8"?>  
<EnumerationResults ContainerName="https://myaccount.blob.core.windows.net/mycontainer">  
  <MaxResults>4</MaxResults>  
  <Blobs>  
    <Blob>  
      <Name>blob1.txt</Name>  
      <Url>https://myaccount.blob.core.windows.net/mycontainer/blob1.txt</Url>  
      <Properties>  
        <Last-Modified>Sun, 27 Sep 2009 18:41:57 GMT</Last-Modified>  
        <Etag>0x8CAE7D55D050B8B</Etag>  
        <Content-Length>8</Content-Length>  
        <Content-Type>text/html</Content-Type>  
        <Content-Encoding />  
        <Content-Language>en-US</Content-Language>  
        <Content-MD5 />  
        <Cache-Control>no-cache</Cache-Control>  
        <BlobType>BlockBlob</BlobType>  
        <LeaseStatus>unlocked</LeaseStatus>  
      </Properties>  
    </Blob>  
    <Blob>  
      <Name>blob2.txt</Name>  
      <Url>https://myaccount.blob.core.windows.net/mycontainer/blob2.txt</Url>  
      <Properties>  
        <Last-Modified>Sun, 27 Sep 2009 12:18:50 GMT</Last-Modified>  
        <Etag>0x8CAE7D55CF6C339</Etag>  
        <Content-Length>100</Content-Length>  
        <Content-Type>text/html</Content-Type>  
        <Content-Encoding />  
        <Content-Language>en-US</Content-Language>  
        <Content-MD5 />  
        <Cache-Control>no-cache</Cache-Control>  
        <BlobType>BlockBlob</BlobType>  
        <LeaseStatus>unlocked</LeaseStatus>  
      </Properties>  
    </Blob>  
    <BlobPrefix>  
      <Name>myfolder/</Name>  
    </BlobPrefix>  
    <Blob>  
      <Name>newblob1.txt</Name>  
      <Url>https://myaccount.blob.core.windows.net/mycontainer/newblob1.txt</Url>  
      <Properties>  
        <Last-Modified>Sun, 27 Sep 2009 16:31:57 GMT</Last-Modified>  
        <Etag>0x8CAE7D55CF6C339</Etag>  
        <Content-Length>25</Content-Length>  
        <Content-Type>text/html</Content-Type>  
        <Content-Encoding />  
        <Content-Language>en-US</Content-Language>  
        <Content-MD5 />  
        <Cache-Control>no-cache</Cache-Control>  
        <BlobType>BlockBlob</BlobType>  
        <LeaseStatus>unlocked</LeaseStatus>  
      </Properties>  
    </Blob>  
    <BlobPrefix>  
      <Name>myfolder2/</Name>  
    </BlobPrefix>  
  </Blobs>  
  <NextMarker>newblob2.txt</NextMarker>  
</EnumerationResults>  
dreturnc                 C   s@   i }|   D ]\}}|drqt|trt|}|||< q|S )N@)items
startswith
isinstancedictremove_attributes)r   resultkv r   F/home/ubuntu/.local/lib/python3.10/site-packages/blobfile/_xml_test.pyr   H   s   


r   datac                 C   s   t | d}t|S Nutf8)	xmltodictparsedecoder   )r   parsedr   r   r   xmltodict_parseS   s   r   c                 C   s   t | dS r   )r   unparseencode)r   r   r   r   xmltodict_unparseY   s   r   c                  C   sZ   t t} tjtddhd}tj| ddd}tj|ddd}t| t| ||ks+J d S )NBlob
BlobPrefixrepeated_tagsT )	sort_keysindent)r   respxmlr   jsondumpsprint)refactualjson_refjson_actualr   r   r   
test_parse]   s   r-   c                  C   sL   dddd t dD ii} t| }t| }t| t| ||ks$J d S )N	BlockListLatestc                 S   s   g | ]}t |qS r   )str).0ir   r   r   
<listcomp>h   s    z test_unparse.<locals>.<listcomp>d   )ranger   r%   r   r(   )bodyr)   r*   r   r   r   test_unparseg   s   
r7   c                  C   s   t t} t| }tj|ddhd}| |ksJ t| }t  t| t| ||ks-J |ttjt| ddhdks@J d S )Nr   r   r   )r   r$   r   r%   r   r   r(   )
ref_parsedref_unparsedactual_parsedactual_unparsedr   r   r   test_roundtripp   s   
r<   c                  C   s(  t t} |  }|d d d d |d d d< t|}t }tdD ]}tt	 q$t }t
d||   t }tdD ]
}t|ddhd qAt }t
d	||   t }tdD ]}t| qat }t
d
||   t }tdD ]}t| q~t }t
d||   d S )NEnumerationResultsBlobsr   i,  r4   zxmltodict parse elapsed r   r   zlxml parse elapsed zxmltodict unparse elapsed zlxml unparse elapsed )r   r$   copyr   timeperf_counterr5   r   r   expanded_respr(   
lxml_parser   lxml_unparse)docdoc2expanded_resp_utf8start_endr   r   r   main   s0    
rK   __main__)r&   r@   typingr   r   r   blobfiler   r%   r$   r0   r   bytesr   r   r-   r7   r<   rK   __name__r   r   r   r   <module>   s     "A
	 
