관리-도구
편집 파일: _header_value_parser.cpython-311.pyc
� c��fv� � � � d Z ddlZddlZddlZddlmZ ddlmZ ddlm Z ddlmZ ddlmZ e d� � Ze e d � � z Z e d � � Zeez Ze e d� � z Ze e d� � z Ze e d � � z e d� � z Zeez Ze e d� � z Zeez Ze e d� � z ZddhZeez Zd� Z ej dej ej z � � Z G d� de � � Z! G d� de!� � Z" G d� de!� � Z# G d� de!� � Z$ G d� de!� � Z% G d� de"� � Z& G d � d!e!� � Z' G d"� d#e!� � Z( G d$� d%e!� � Z) G d&� d'e!� � Z* G d(� d)e*� � Z+ G d*� d+e"� � Z, G d,� d-e!� � Z- G d.� d/e!� � Z. G d0� d1e!� � Z/ G d2� d3e!� � Z0 G d4� d5e!� � Z1 G d6� d7e!� � Z2 G d8� d9e!� � Z3 G d:� d;e!� � Z4 G d<� d=e!� � Z5 G d>� d?e!� � Z6 G d@� dAe!� � Z7 G dB� dCe!� � Z8 G dD� dEe!� � Z9 G dF� dGe!� � Z: G dH� dIe!� � Z; G dJ� dKe!� � Z< G dL� dMe$� � Z= G dN� dOe!� � Z> G dP� dQe!� � Z? G dR� dSe!� � Z@ G dT� dUe!� � ZA G dV� dWeA� � ZB G dX� dYe!� � ZC G dZ� d[e!� � ZD G d\� d]e!� � ZE G d^� d_e!� � ZF G d`� dae!� � ZG G db� dceG� � ZH G dd� deeG� � ZI G df� dge!� � ZJ G dh� die!� � ZK G dj� dke!� � ZL G dl� dmeL� � ZM G dn� doeM� � ZN G dp� dqe!� � ZO G dr� dseP� � ZQ G dt� dueQ� � ZR G dv� dweQ� � ZS G dx� dyeR� � ZT G dz� d{ejU � � ZV eSdd|� � ZW eSd}d~� � ZXdeX_Y deX_Z eSd�d�� � Z[ ej d��\ d��] e� � � � � � j^ Z_ ej d��\ ej` d��] e� � � � � � � � ja Zb ej d�� � jc Zd ej d��\ ej` d��] e� � � � � � � � ja Ze ej d��\ ej` d��] e� � � � � � � � ja Zf ej d��\ ej` d��] e� � � � � � � � ja Zgd�� Zhd�� Zid�� Zjd�� Zkd�� Zld�� Zmd�� Znd�� Zod�� Zpd�� Zqd�� Zrd�� Zsd�� Ztd�� Zud�� Zvd�� Zwd�� Zxd�� Zyd�� Zzd�� Z{d�� Z|d�� Z}d�� Z~d�� Zd�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�d�� Z�dS )�al Header value parser implementing various email-related RFC parsing rules. The parsing methods defined in this module implement various email related parsing rules. Principal among them is RFC 5322, which is the followon to RFC 2822 and primarily a clarification of the former. It also implements RFC 2047 encoded word decoding. RFC 5322 goes to considerable trouble to maintain backward compatibility with RFC 822 in the parse phase, while cleaning up the structure on the generation phase. This parser supports correct RFC 5322 generation by tagging white space as folding white space only when folding is allowed in the non-obsolete rule sets. Actually, the parser is even more generous when accepting input than RFC 5322 mandates, following the spirit of Postel's Law, which RFC 5322 encourages. Where possible deviations from the standard are annotated on the 'defects' attribute of tokens that deviate. The general structure of the parser follows RFC 5322, and uses its terminology where there is a direct correspondence. Where the implementation requires a somewhat different structure than that used by the formal grammar, new terms that mimic the closest existing terms are used. Thus, it really helps to have a copy of RFC 5322 handy when studying this code. Input to the parser is a string that has already been unfolded according to RFC 5322 rules. According to the RFC this unfolding is the very first step, and this parser leaves the unfolding step to a higher level message parser, which will have already detected the line breaks that need unfolding while determining the beginning and end of each header. The output of the parser is a TokenList object, which is a list subclass. A TokenList is a recursive data structure. The terminal nodes of the structure are Terminal objects, which are subclasses of str. These do not correspond directly to terminal objects in the formal grammar, but are instead more practical higher level combinations of true terminals. All TokenList and Terminal objects have a 'value' attribute, which produces the semantically meaningful value of that part of the parse subtree. The value of all whitespace tokens (no matter how many sub-tokens they may contain) is a single space, as per the RFC rules. This includes 'CFWS', which is herein included in the general class of whitespace tokens. There is one exception to the rule that whitespace tokens are collapsed into single spaces in values: in the value of a 'bare-quoted-string' (a quoted-string with no leading or trailing whitespace), any whitespace that appeared between the quotation marks is preserved in the returned value. Note that in all Terminal strings quoted pairs are turned into their unquoted values. All TokenList and Terminal objects also have a string value, which attempts to be a "canonical" representation of the RFC-compliant form of the substring that produced the parsed subtree, including minimal use of quoted pair quoting. Whitespace runs are not collapsed. Comment tokens also have a 'content' attribute providing the string found between the parens (including any nested comments) with whitespace preserved. All TokenList and Terminal objects have a 'defects' attribute which is a possibly empty list all of the defects found while creating the token. Defects may appear on any token in the tree, and a composite list of all defects in the subtree is available through the 'all_defects' attribute of any node. (For Terminal notes x.defects == x.all_defects.) Each object in a parse tree is called a 'token', and each has a 'token_type' attribute that gives the name from the RFC 5322 grammar that it represents. Not all RFC 5322 nodes are produced, and there is one non-RFC 5322 node that may be produced: 'ptext'. A 'ptext' is a string of printable ascii characters. It is returned in place of lists of (ctext/quoted-pair) and (qtext/quoted-pair). XXX: provide complete list of token types. � N)� hexdigits)� itemgetter)�_encoded_words)�errors)�utilsz �(z ()<>@,:;.\"[]�.z."(z/?=z*'%�%� � c �| � dt | � � � dd� � � dd� � z dz S )N�"�\�\\z\")�str�replace��values �A/opt/alt/python311/lib64/python3.11/email/_header_value_parser.py�quote_stringr b s8 � ��s�5�z�z�!�!�$��/�/�7�7��U�C�C�C�C�G�G� z� =\? # literal =? [^?]* # charset \? # literal ? [qQbB] # literal 'q' or 'b', case insensitive \? # literal ? .*? # encoded word \?= # literal ?= c � � � e Zd ZdZdZdZ� fd�Zd� Z� fd�Ze d� � � Z e d� � � Zd� Ze d � � � Z e d � � � Zd� Zdd �Zdd�Zdd�Z� xZS )� TokenListNTc �H �� t � � j |i |�� g | _ d S �N)�super�__init__�defects)�self�args�kw� __class__s �r r zTokenList.__init__{ s* �� ������$�%�"�%�%�%�����r c �@ � d� d� | D � � � � S )N� c 3 �4 K � | ]}t |� � V � �d S r �r ��.0�xs r � <genexpr>z$TokenList.__str__.<locals>.<genexpr>� �( � � � �,�,�!�s�1�v�v�,�,�,�,�,�,r ��join�r s r �__str__zTokenList.__str__ s# � ��w�w�,�,�t�,�,�,�,�,�,r c � �� d� | j j t � � � � � � � S �Nz{}({})��formatr"