o ‡ÎÖarã@srdZddlZddlmZmZddlmZddlmZm Z m Z m Z m Z m Z ddlmZmZdgZGdd„deƒZdS) zé pygments.lexers.mime ~~~~~~~~~~~~~~~~~~~~ Lexer for Multipurpose Internet Mail Extensions (MIME) data. :copyright: Copyright 2006-2021 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¼eZdZdZdZdgZgd¢Z‡fdd„Zdd„Zd d „Z d d „Z d d„Z dd„Z dd„Z ddhZdefde fgdejfdejdfgedƒde fde fdedfgedƒde 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 ÚMIMEÚmime)zmultipart/mixedzmultipart/relatedzmultipart/alternativec sJtƒjdi|¤Ž| d¡|_| d¡|_| dd¡|_t|ddƒ|_dS)NzMultipart-BoundaryÚContent_Transfer_EncodingÚ Content_Typez text/plainzMIME-max-leveléÿÿÿÿ©)ÚsuperÚ__init__ÚgetÚboundaryÚcontent_transfer_encodingÚ content_typer Úmax_nested_level)ÚselfÚoptions©Ú __class__rú6/usr/lib/python3/dist-packages/pygments/lexers/mime.pyr;s   zMIMELexer.__init__ccs¬| d¡}| ¡|jvrJ| d¡tj|dfV| d¡tj| d¡fV| d¡}| d¡}|  |d| ¡f¡D] \}}}||||fVq:dS| ¡t | ¡fVdS)Néú:ééÚroot) ÚgroupÚlowerÚattention_headersÚstartrÚTagrÚ WhitespaceÚendÚget_tokens_unprocessedr )rÚmatchÚfieldÚposÚbodyÚiÚtÚvrrrÚget_header_tokensBs€   ÿzMIMELexer.get_header_tokensccsž| ¡}| ¡}|ddkr |tjdfV|d}|dd…}|j d¡r)|js>| |¡D] \}}}||||fVq.dSdt  |j¡}t  |tj ¡}|  |¡} | rx||   ¡} |   ¡} } |t|d|  ¡…fV|| tj|  ¡fVn|} d} | || ¡D]4} | |} |  ¡} || | …}| |¡D] \}}}| |||fVq—|| tj|  ¡fV||   ¡} q‚| |} | t|ƒkrÍ| t|| d…fVdSdS)NrÚ r Ú multipartz ^--%s(--)?\n)r(r%rr*rÚ startswithrÚget_bodypart_tokensÚreÚescapeÚcompileÚ MULTILINEÚsearchr+rÚ DelimiterÚfinditerÚlen)rr-Úpos_body_startÚ entire_bodyr1r2r3Ú bdry_patternÚ bdry_matcherÚmÚpos_part_startÚpos_iter_startÚlpos_endÚ lpos_startÚpartrrrÚget_body_tokensQsB€       ÿzMIMELexer.get_body_tokenscCs | ¡r|js dt|fgS|j}|r|dvrdt|fgS|jdkr'dt|fgSzt|jƒ}Wnty=dt|fgYSwt|t|ƒƒrK|jd|_|  |¡S)Nr>úquoted-printableÚ7bitÚ8bitr ) Ústriprr rrrr Ú isinstanceÚtyper,)rÚtextÚcteÚlexerrrrr8‚s      ÿ  zMIMELexer.get_bodypart_tokensccs| d¡|_| d¡| d¡}| d¡tj| d¡d|…fV| d¡tj| d¡fV| d¡tj dfV| d¡tj| d¡fVdS)Nr rr"ú/r#) r%rr(rr*rÚLabelr+rr>)rr-Ú prefix_lenrrrÚstore_content_types€ "zMIMELexer.store_content_typeccsÐ| d¡t| d¡fV| d¡tj| d¡fV| d¡tj| d¡fV| d¡t| d¡fV| d¡t| d¡fV| d¡ ¡dkrf| d¡  ¡}|ddkra|d dkra|dd …}||_ dSdS) Nr r"r#éérrú"r) r(rr%r*rÚ Attributerrr&rOr)rr-rrrrÚget_content_type_subtokens¦s€  üz$MIMELexer.get_content_type_subtokensccs0| d¡ ¡|_| d¡tj| d¡fVdS)Nr)r%r&rr(rÚConstant)rr-rrrÚ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$rbr`ra)Ú__name__Ú __module__Ú __qualname__Ú__doc__ÚnameÚaliasesÚ mimetypesrr4rKr8rXr]r_r'rr*rÚtokensÚ __classcell__rrrrr s@ 1  þ ýýÿ÷ þë)rfr9Úpygments.lexerrrÚpygments.lexersrÚpygments.tokenrrrrr r Ú pygments.utilr r Ú__all__r rrrrÚs