3
‡Œði,	  ã               @   s|   d Z ddlmZ ddlmZ ddlmZ ddlmZ dddgZdd	lZdd
lm	Z	 dd„ Z
ddd„Zddd„Zddd„Zd	S )z1Various types of useful iterators and generators.é    )Úprint_function)Úunicode_literals)Údivision)Úabsolute_importÚbody_line_iteratorÚtyped_subpart_iteratorÚwalkN)ÚStringIOc             c   s<   | V  | j ƒ r8x(| jƒ D ]}x|jƒ D ]
}|V  q&W qW dS )z‰Walk over the message tree, yielding each subpart.

    The walk is performed in depth-first order.  This method is a
    generator.
    N)Úis_multipartÚget_payloadr   )ÚselfÚsubpartZ
subsubpart© r   úB/tmp/pip-build-6m2fasei/future/future/backports/email/iterators.pyr      s
    Fc             c   sD   x>| j ƒ D ]2}|j|d�}t|tƒr
xt|ƒD ]
}|V  q.W q
W dS )zŽIterate over the parts, returning string payloads line-by-line.

    Optional decode (default False) is passed through to .get_payload().
    )ÚdecodeN)r   r   Ú
isinstanceÚstrr	   )Úmsgr   r   ÚpayloadÚliner   r   r   r   %   s
    
Útextc             c   s<   x6| j ƒ D ]*}|jƒ |kr
|dks.|jƒ |kr
|V  q
W dS )zøIterate over the subparts with a given MIME type.

    Use `maintype' as the main MIME type to match against; this defaults to
    "text".  Optional `subtype' is the MIME subtype to match against; if
    omitted, only the main type is matched.
    N)r   Úget_content_maintypeÚget_content_subtype)r   ÚmaintypeÚsubtyper   r   r   r   r   1   s    c             C   s„   |dkrt j}d|d  }t|| jƒ  d|d� |rJtd| jƒ  |d� n
t|d� | jƒ r€x"| jƒ D ]}t|||d |ƒ qfW dS )	zA handy debugging aidNú é   Ú )ÚendÚfilez [%s])r   é   )ÚsysÚstdoutÚprintÚget_content_typeÚget_default_typer
   r   Ú
_structure)r   ÚfpÚlevelÚinclude_defaultÚtabr   r   r   r   r&   >   s    
r&   )F)r   N)Nr   F)Ú__doc__Ú
__future__r   r   r   r   Ú__all__r!   Úior	   r   r   r   r&   r   r   r   r   Ú<module>   s   

