관리-도구
편집 파일: _header_value_parser.cpython-36.opt-1.pyc
3 �Qg�� � @ sz 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� ZddhZeeB Zdd� ZG dd� de�ZG dd� de�ZG dd� de�Z G 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�Z0G d;d<� d<e�Z1G d=d>� d>e�Z2G d?d@� d@e�Z3G dAdB� dBe�Z4G dCdD� dDe�Z5G dEdF� dFe�Z6G dGdH� dHe�Z7G dIdJ� dJe�Z8G dKdL� dLe!�Z9G dMdN� dNe�Z:G 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�ZAG d]d^� d^e�ZBG d_d`� d`e�ZCG dadb� dbeC�ZDG dcdd� ddeC�ZEG dedf� dfe�ZFG dgdh� dhe�ZGG didj� dje�ZHG dkdl� dleI�ZJG dmdn� dneJ�ZKG dodp� dpeJ�ZLG dqdr� dreK�ZMeLdds�ZNeLdtdu�ZOeLdvdw�ZPejQdxjRdyjSe���jTZUejQdzjRdyjSe�jVd{d|�jVd}d~���jWZXejQd�jYZZejQdzjRdyjSe�jVd{d|�jVd}d~���jWZ[ejQdzjRdyjSe�jVd{d|�jVd}d~���jWZ\ejQdzjRdyjSe�jVd{d|�jVd}d~���jWZ]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�dń Z�d�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�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 �2/usr/lib64/python3.6/email/_header_value_parser.py�quote_stringb 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 o 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>t s z$TokenList.__str__.<locals>.<genexpr>)�join)r r r r �__str__s s zTokenList.__str__c s dj | jjt� j� �S )Nz{}({}))�formatr �__name__r �__repr__)r )r r r r% v 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 | s z"TokenList.value.<locals>.<genexpr>)r! )r r r r r z 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&