Your IP : 3.22.217.176
3
� f�� � @ sj d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl m
Z ddl mZ ddl m
Z
ed �Zeed
�B Zed�ZeeB Zeed� Zeed
� Zeed�B ed� ZeeB Zeed�B ZeeB Zeed� Zdd� ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�Z G dd� de�Z!G dd � d e�Z"G d!d"� d"e�Z#G d#d$� d$e�Z$G d%d&� d&e�Z%G d'd(� d(e%�Z&G d)d*� d*e�Z'G d+d,� d,e�Z(G d-d.� d.e�Z)G d/d0� d0e�Z*G d1d2� d2e�Z+G d3d4� d4e�Z,G d5d6� d6e�Z-G d7d8� d8e�Z.G d9d:� d:e�Z/G d;d<� d<e�Z0G d=d>� d>e�Z1G d?d@� d@e�Z2G dAdB� dBe�Z3G dCdD� dDe�Z4G dEdF� dFe�Z5G dGdH� dHe�Z6G dIdJ� dJe�Z7G dKdL� dLe�Z8G dMdN� dNe�Z9G dOdP� dPe�Z:G dQdR� dRe�Z;G dSdT� dTe;�Z<G dUdV� dVe�Z=G dWdX� dXe�Z>G dYdZ� dZe�Z?G d[d\� d\e�Z@G d]d^� d^e�ZAG d_d`� d`eA�ZBG dadb� dbeA�ZCG dcdd� dde�ZDG dedf� dfe�ZEG dgdh� dhe�ZFG didj� djeG�ZHG dkdl� dleH�ZIG dmdn� dneH�ZJG dodp� dpeI�ZKeJddq�ZLeJdrds�ZMeJdtdu�ZNejOdvjPdwjQe���jRZSejOdxjPdwjQe�jTdydz�jTd{d|���jUZVejOd}�jWZXejOdxjPdwjQe�jTdydz�jTd{d|���jUZYejOdxjPdwjQe�jTdydz�jTd{d|���jUZZejOdxjPdwjQe�jTdydz�jTd{d|���jUZ[d~d� Z\d�d�� Z]d�d�� Z^d�d�� Z_d�d�� Z`d�d�� Zad�d�� Zbd�d�� Zcd�d�� Zdd�d�� Zed�d�� Zfd�d�� Zgd�d�� Zhd�d�� Zid�d�� Zjd�d�� Zkd�d�� Zld�d�� Zmd�d�� Znd�d�� Zod�d�� Zpd�d�� Zqd�d�� Zrd�d�� Zsd�d�� Ztd�d�� Zud�d�� Zvd�d�� Zwd�d�� Zxd�d�� Zyd�d�� Zzd�d�� Z{d�d�� Z|d�d�� Z}d�dÄ Z~d�dń Zd�dDŽ Z�d�dɄ Z�d�d˄ Z�d�d̈́ Z�d�dτ Z�d�dф Z�d�dӄ Z�d�dՄ Z�d�dׄ Z�d�dل Z�d�dۄ Z�d�d݄ Z�d�d߄ Z�d�d� Z�d�d� Z�d�d� Z�d�d� Z�d�d� Z�d�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)�OrderedDict)�
itemgetter)�_encoded_words)�errors)�utilsz �(z
()<>@,:;.\"[]�.z."(z/?=z*'%�%c C s dt | �jdd�jdd� d S )N�"�\z\\z\")�str�replace)�value� r �?/opt/alt/python36/lib64/python3.6/email/_header_value_parser.py�quote_string` s r c s� e Zd ZdZdZdZ� fdd�Zdd� Z� fdd�Ze d d
� �Z
e dd� �Zd
d� Ze dd� �Z
e dd� �Zdd� Zddd�Zddd�Zddd�Z� ZS )� TokenListNTc s t � j||� g | _d S )N)�super�__init__�defects)�self�args�kw)� __class__r r r m s zTokenList.__init__c C s dj dd� | D ��S )N� c s s | ]}t |�V qd S )N)r
)�.0�xr r r � <genexpr>r s z$TokenList.__str__.<locals>.<genexpr>)�join)r r r r �__str__q s zTokenList.__str__c s dj | jjt� j� �S )Nz{}({}))�formatr �__name__r �__repr__)r )r r r r# t s
zTokenList.__repr__c C s dj dd� | D ��S )Nr c s s | ]}|j r|j V qd S )N)r )r r r r r r z s z"TokenList.value.<locals>.<genexpr>)r )r r r r r x s zTokenList.valuec C s t dd� | D �| j�S )Nc s s | ]}|j V qd S )N)�all_defects)r r r r r r ~ s z(TokenList.all_defects.<locals>.<genexpr>)�sumr )r r r r r$ | s zTokenList.all_defectsc C s | d j � S )Nr )�startswith_fws)r r r r r&