a
    ©lcr  ã                   @   sr   d Z ddlZddlmZmZ ddlmZ ddlmZm	Z	m
Z
mZmZmZ ddlmZmZ dgZG dd„ deƒZdS )	zé
    pygments.lexers.mime
    ~~~~~~~~~~~~~~~~~~~~

    Lexer for Multipurpose Internet Mail Extensions (MIME) data.

    :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
é    N)Ú
RegexLexerÚinclude)Úget_lexer_for_mimetype)ÚTextÚNameÚStringÚOperatorÚCommentÚOther)Úget_int_optÚClassNotFoundÚ	MIMELexerc                       s¼   e Zd ZdZdZdgZg d¢Z‡ fdd„Zdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZddhZdefde	fgdejfdejdfgedƒdefdefdedfgedƒdefgdœZ‡  ZS ) r   a_  
    Lexer for Multipurpose Internet Mail Extensions (MIME) data. This lexer is
    designed to process nested multipart data.

    It assumes that the given data contains both header and body (and is
    split at an empty line). If no valid header is found, then the entire data
    will be treated as body.

    Additional options accepted:

    `MIME-max-level`
        Max recursion level for nested MIME structure. Any negative number
        would treated as unlimited. (default: -1)

    `Content-Type`
        Treat the data as a specific content type. Useful when header is
        missing, or this lexer would try to parse from header. (default:
        `text/plain`)

    `Multipart-Boundary`
        Set the default multipart boundary delimiter. This option is only used
        when `Content-Type` is `multipart` and header is missing. This lexer
        would try to parse from header by default. (default: None)

    `Content-Transfer-Encoding`
        Treat the data as a specific encoding. Or this lexer would try to parse
        from header by default. (default: None)

    .. versionadded:: 2.5
    ÚMIMEÚmime)zmultipart/mixedzmultipart/relatedzmultipart/alternativec                    sJ   t ƒ jf i |¤Ž | d¡| _| d¡| _| dd¡| _t|ddƒ| _d S )NzMultipart-BoundaryZContent_Transfer_EncodingZContent_Typez
text/plainzMIME-max-leveléÿÿÿÿ)ÚsuperÚ__init__ÚgetÚboundaryÚcontent_transfer_encodingÚcontent_typer   Úmax_nested_level)ÚselfÚoptions©Ú	__class__© úP/var/www/html/django/DPS/env/lib/python3.9/site-packages/pygments/lexers/mime.pyr   ;   s
    zMIMELexer.__init__c                 c   s¨   |  d¡}| ¡ | jv r| d¡tj|d fV  | d¡tj|  d¡fV  | d¡}|  d¡}|  	|d| ¡ f¡D ]\}}}|| ||fV  qrn| ¡ t
|  ¡ fV  d S )Né   ú:é   é   Úroot)ÚgroupÚlowerÚattention_headersÚstartr   ÚTagr   Ú
WhitespaceÚendÚget_tokens_unprocessedr	   )r   ÚmatchÚfieldÚposÚbodyÚiÚtÚvr   r   r   Úget_header_tokensB   s    


zMIMELexer.get_header_tokensc                 c   sž  |  ¡ }| ¡ }|d dkr>|tjdfV  |d }|dd … }| j d¡rP| jsz|  |¡D ]\}}}|| ||fV  qZd S dt 	| j¡ }t 
|tj¡}| |¡}	|	rî||	 ¡  }
|	 ¡  }}|t|d |	  ¡ … fV  || tj|	 ¡ fV  n|}
d}| ||¡D ]l}	|
| }|	  ¡ }|||… }|  |¡D ]\}}}|
| ||fV  q,|| tj|	 ¡ fV  ||	 ¡  }
q|
| }|t|ƒkrš|
t||d … fV  d S )Nr   Ú
r   Ú	multipartz^--%s(--)?\n)r&   r#   r   r(   r   Ú
startswithr   Úget_bodypart_tokensÚreÚescapeÚcompileÚ	MULTILINEÚsearchr)   r   Ú	DelimiterÚfinditerÚlen)r   r+   Zpos_body_startZentire_bodyr/   r0   r1   Zbdry_patternZbdry_matcherÚmZpos_part_startZpos_iter_startZlpos_endZ
lpos_startÚpartr   r   r   Úget_body_tokensQ   s>    
zMIMELexer.get_body_tokensc                 C   s    |  ¡ r| jsdt|fgS | j}|r8|dvr8dt|fgS | jdkrNdt|fgS zt| jƒ}W n tyz   dt|fg Y S 0 t|t| ƒƒr–| jd |_| 	|¡S )Nr   >   zquoted-printableÚ8bitÚ7bitr   )
Ústripr   r
   r   r   r   r   Ú
isinstanceÚtyper*   )r   ÚtextÚcteÚlexerr   r   r   r6   ‚   s    
zMIMELexer.get_bodypart_tokensc                 c   sŽ   |  d¡| _| d¡| d¡ }| d¡tj|  d¡d |… fV  | d¡tj|  d¡fV  | d¡tj	dfV  | d¡tj|  d¡fV  d S )Nr   r   r    ú/r!   )
r#   r   r&   r   r(   r   ÚLabelr)   r   r<   )r   r+   Ú
prefix_lenr   r   r   Ústore_content_type   s    "zMIMELexer.store_content_typec                 c   sÊ   |  d¡t| d¡fV  |  d¡tj| d¡fV  |  d¡tj| d¡fV  |  d¡t| d¡fV  |  d¡t| d¡fV  | d¡ ¡ dkrÆ| d¡ 	¡ }|d dkrÀ|d	 dkrÀ|dd	… }|| _
d S )
Nr   r    r!   é   é   r   r   ú"r   )r&   r   r#   r(   r   Ú	Attributer   r   r$   rD   r   )r   r+   r   r   r   r   Úget_content_type_subtokens¦   s    z$MIMELexer.get_content_type_subtokensc                 c   s.   |  d¡ ¡ | _| d¡tj|  d¡fV  d S )Nr   )r#   r$   r   r&   r   ÚConstant)r   r+   r   r   r   Ústore_content_transfer_encoding³   s    z)MIMELexer.store_content_transfer_encodingúcontent-typeúcontent-transfer-encodingz#^([\w-]+):( *)([\s\S]*?\n)(?![ \t])z	^$[\s\S]+z\n[ \t]z\n(?![ \t])z#popÚheaderzP^\s*((multipart|application|audio|font|image|model|text|video|message)/([\w-]+))z>(;)((?:[ \t]|\n[ \t])*)([\w:-]+)(=)([\s\S]*?)(?=;|\n(?![ \t]))z;[ \t]*\n(?![ \t])z([\w-]+))r"   rW   rU   rV   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚnameÚaliasesÚ	mimetypesr   r2   rA   r6   rM   rR   rT   r%   r   r(   r   ÚtokensÚ__classcell__r   r   r   r   r      s>   1	þ
ýýÿ÷þë)r[   r7   Zpygments.lexerr   r   Zpygments.lexersr   Zpygments.tokenr   r   r   r   r	   r
   Zpygments.utilr   r   Ú__all__r   r   r   r   r   Ú<module>   s   
 