o ar@srdZddlZddlmZmZddlmZddlmZm Z m Z m Z m Z m Z ddlmZmZdgZGdddeZdS) 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) RegexLexerinclude)get_lexer_for_mimetype)TextNameStringOperatorCommentOther) get_int_opt ClassNotFound MIMELexercseZdZdZdZdgZgdZfddZddZd d Z d d Z d dZ ddZ ddZ ddhZdefde fgdejfdejdfgedde fde fdedfgedde fgdZZS) 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 MIMEmime)zmultipart/mixedzmultipart/relatedzmultipart/alternativec sJtjdi||d|_|d|_|dd|_t|dd|_dS)NzMultipart-BoundaryContent_Transfer_Encoding Content_Typez text/plainzMIME-max-level)super__init__getboundarycontent_transfer_encoding content_typer max_nested_level)selfoptions __class__r6/usr/lib/python3/dist-packages/pygments/lexers/mime.pyr;s   zMIMELexer.__init__ccs|d}||jvrJ|dtj|dfV|dtj|dfV|d}|d}| |d|fD] \}}}||||fVq:dS|t |fVdS)N:root) grouplowerattention_headersstartrTagr Whitespaceendget_tokens_unprocessedr )rmatchfieldposbodyitvrrrget_header_tokensBs   zMIMELexer.get_header_tokensccs|}|}|ddkr |tjdfV|d}|dd}|jdr)|js>||D] \}}}||||fVq.dSdt |j}t |tj }| |} | rx|| } | } } |t|d| fV|| tj| fVn|} d} ||| D]4} | |} | } || | }||D] \}}}| |||fVq|| tj| fV|| } q| |} | t|kr| t|| dfVdSdS)Nr r multipartz ^--%s(--)?\n)r(r%rr*r startswithrget_bodypart_tokensreescapecompile MULTILINEsearchr+r Delimiterfinditerlen)rr-pos_body_start entire_bodyr1r2r3 bdry_pattern bdry_matchermpos_part_startpos_iter_startlpos_end lpos_startpartrrrget_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-printable7bit8bitr ) striprr rrrr isinstancetyper,)rtextctelexerrrrr8s        zMIMELexer.get_bodypart_tokensccs|d|_|d|d}|dtj|dd|fV|dtj|dfV|dtj dfV|dtj|dfVdS)Nr rr"/r#) r%rr(rr*rLabelr+rr>)rr- prefix_lenrrrstore_content_types "zMIMELexer.store_content_typeccs|dt|dfV|dtj|dfV|dtj|dfV|dt|dfV|dt|dfV|ddkrf|d }|ddkra|d dkra|dd }||_ dSdS) Nr r"r#rr"r) r(rr%r*r Attributerrr&rOr)rr-rrrrget_content_type_subtokenss  z$MIMELexer.get_content_type_subtokensccs0|d|_|dtj|dfVdS)Nr)r%r&rr(rConstant)rr-rrrstore_content_transfer_encodingsz)MIMELexer.store_content_transfer_encoding content-typecontent-transfer-encodingz#^([\w-]+):( *)([\s\S]*?\n)(?![ \t])z ^$[\s\S]+z\n[ \t]z \n(?![ \t])z#popheaderzP^\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__namealiases mimetypesrr4rKr8rXr]r_r'rr*rtokens __classcell__rrrrr s@ 1    )rfr9pygments.lexerrrpygments.lexersrpygments.tokenrrrrr r pygments.utilr r __all__r rrrrs