o
    g$                     @   sD   d Z ddlZddlmZ ddlmZ G dd dZG dd dZdS )	z^Basic implementation to support SOAP-Attachments

See https://www.w3.org/TR/SOAP-attachments

    N)cached_property)CaseInsensitiveDictc                   @   sD   e Zd Zdd Zdd Zedd Zdd Zed	d
 Z	dd Z
dS )MessagePackc                 C   
   || _ d S N_parts)selfparts r   N/home/ubuntu/webapp/venv/lib/python3.10/site-packages/zeep/wsdl/attachments.py__init__      
zMessagePack.__init__c                 C   s   dd dd | jD  S )Nz<MessagePack(attachments=[%s])>z, c                 s   s    | ]}t |V  qd S r   )repr).0ar   r   r   	<genexpr>   s    z'MessagePack.__repr__.<locals>.<genexpr>)joinattachmentsr	   r   r   r   __repr__   s   zMessagePack.__repr__c                 C   s   | j S r   _rootr   r   r   r   root   s   zMessagePack.rootc                 C   r   r   r   )r	   r   r   r   r   	_set_root   r   zMessagePack._set_rootc                 C   s   dd | j D S )zKReturn a list of attachments.

        :rtype: list of Attachment

        c                 S   s   g | ]}t |qS r   )
Attachment)r   partr   r   r   
<listcomp>$   s    z+MessagePack.attachments.<locals>.<listcomp>r   r   r   r   r   r      s   zMessagePack.attachmentsc                 C   s"   | j D ]}|j|kr|  S qdS )zget_by_content_id

        :param content_id: The content-id to return
        :type content_id: str
        :rtype: Attachment

        N)r   
content_id)r	   r   
attachmentr   r   r   get_by_content_id&   s
   

zMessagePack.get_by_content_idN)__name__
__module____qualname__r   r   propertyr   r   r   r   r    r   r   r   r   r      s    

r   c                   @   s(   e Zd Zdd Zdd Zedd ZdS )r   c                    sb   |j pd t fdd|j D | _| jdd | _| jdd | _| jdd | _|| _d S )Nzutf-8c                    s"   i | ]\}}|  |  qS r   )decode)r   kvencodingr   r   
<dictcomp>7   s   " z'Attachment.__init__.<locals>.<dictcomp>zContent-Typez
Content-IDzContent-Location)	r)   r   headersitemsgetcontent_typer   content_location_part)r	   r   r   r(   r   r   4   s   

zAttachment.__init__c                 C   s   d| j | jf S )Nz<Attachment(%r, %r)>)r   r.   r   r   r   r   r   >   s   zAttachment.__repr__c                 C   s>   | j dd}| jj}|dkrt|S |dkr|dS |S )zLReturn the content of the attachment

        :rtype: bytes or str

        zContent-Transfer-EncodingNbase64binarys   
)r+   r-   r0   contentr1   	b64decodestrip)r	   r)   r3   r   r   r   r3   A   s   

zAttachment.contentN)r!   r"   r#   r   r   r   r3   r   r   r   r   r   3   s
    
r   )__doc__r1   	functoolsr   requests.structuresr   r   r   r   r   r   r   <module>   s    &