3

V'ícrã@srdZddlZddlmZmZddlmZddlmZm	Z	m
Z
mZmZm
Z
ddlmZmZdgZGdd„deƒZdS)	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Ú	MIMELexercs¾eZdZdZdZdgZdddgZ‡fdd„Zd	d
„Zdd„Z	d
d„Z
dd„Zdd„Zdd„Z
ddhZdefde	fgdejfdejdfgedƒdefdefdedfgedƒd e
fgd!œZ‡ZS)"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
    ZMIMEÚmimezmultipart/mixedzmultipart/relatedzmultipart/alternativecsFtƒjf|Ž|jdƒ|_|jdƒ|_|jddƒ|_t|ddƒ|_dS)NzMultipart-BoundaryZContent_Transfer_EncodingZContent_Typez
text/plainzMIME-max-levelééÿÿÿÿ)ÚsuperÚ__init__ÚgetÚboundaryÚcontent_transfer_encodingÚcontent_typerÚmax_nested_level)ÚselfÚoptions)Ú	__class__©ú8/tmp/pip-build-gk9425m9/Pygments/pygments/lexers/mime.pyr;s
zMIMELexer.__init__ccs¬|jdƒ}|jƒ|jkr”|jdƒtj|dfV|jdƒtj|jdƒfV|jdƒ}|jdƒ}xH|j	|d|jƒfƒD]\}}}||||fVqtWn|jƒt
|jƒfVdS)Nrú:ééÚroot)ÚgroupÚlowerÚattention_headersÚstartrZTagrÚ
WhitespaceÚendÚget_tokens_unprocessedr	)rÚmatchÚfieldÚposÚbodyÚiÚtÚvrrrÚget_header_tokensBs


 zMIMELexer.get_header_tokensccs®|jƒ}|jƒ}|ddkr>|tjdfV|d}|dd…}|jjdƒsT|jr‚x(|j|ƒD]\}}}||||fVq`WdSdtj	|jƒ}tj
|tjƒ}|j|ƒ}	|	rö||	j
ƒ}
|	j
ƒ}}|t|d|	jƒ…fV||tj|	jƒfVn|}
d}x€|j||ƒD]p}	|
|}
|	jƒ}||
|…}x*|j|ƒD]\}}}|
|||fVq8W||tj|	jƒfV||	j
ƒ}
qW|
|}
|
t|ƒkrª|
t||
d…fVdS)NrÚ
rÚ	multipartz^--%s(--)?\n)r$r!rr%rÚ
startswithrÚget_bodypart_tokensÚreÚescapeÚcompileÚ	MULTILINEÚsearchr&rÚ	DelimiterÚfinditerÚlen)rr(Zpos_body_startZentire_bodyr,r-r.Zbdry_patternZbdry_matcherÚmZpos_part_startZpos_iter_startZlpos_endZ
lpos_startÚpartrrrÚget_body_tokensQs>
zMIMELexer.get_body_tokenscCs¢|jƒs|jrdt|fgS|j}|r<|dkr<dt|fgS|jdkrRdt|fgSyt|jƒ}Wntk
r|dt|fgSXt|t|ƒƒr˜|jd|_|j	|ƒS)NrÚ8bitÚ7bitúquoted-printabler>r@r?rA)
Ústriprr
rrrrÚ
isinstanceÚtyper')rÚtextÚcteÚlexerrrrr3‚s
zMIMELexer.get_bodypart_tokensccsŽ|jdƒ|_|jdƒ|jdƒ}|jdƒtj|jdƒd|…fV|jdƒtj|jdƒfV|jdƒtj	dfV|jdƒtj|jdƒfVdS)Nrrrú/r)
r!rr$rr%rZLabelr&rr9)rr(Ú
prefix_lenrrrÚstore_content_types"zMIMELexer.store_content_typeccsÊ|jdƒt|jdƒfV|jdƒtj|jdƒfV|jdƒtj|jdƒfV|jdƒt|jdƒfV|jdƒt|jdƒfV|jdƒjƒdkrÆ|jdƒj	ƒ}|ddkrÀ|d	dkrÀ|dd
…}||_
dS)Nrrréérrú"rr)r$rr!r%rÚ	Attributerrr"rBr)rr(rrrrÚget_content_type_subtokens¦sz$MIMELexer.get_content_type_subtokensccs.|jdƒjƒ|_|jdƒtj|jdƒfVdS)Nr)r!r"rr$rÚConstant)rr(rrrÚstore_content_transfer_encoding³sz)MIMELexer.store_content_transfer_encodingzcontent-typezcontent-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 rRzcontent-typezcontent-transfer-encoding)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚnameÚaliasesÚ	mimetypesrr/r>r3rJrOrQr#rr%rÚtokensÚ
__classcell__rr)rrr
s41	

)rVr4Zpygments.lexerrrZpygments.lexersrZpygments.tokenrrrrr	r
Z
pygments.utilrrÚ__all__r
rrrrÚ<module>	s