3
\O ã @ sj d Z ddlmZ ddlmZ ddlmZ ddlmZ G dd„ dƒZG dd „ d ƒZ G d
d„ de
ƒZdd
„ ZG dd„ dƒZ
G dd„ de
ƒZG dd„ dƒZG dd„ deƒZG dd„ dƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ dƒZG d d!„ d!ƒZG d"d#„ d#eƒZG d$d%„ d%eƒZG d&d'„ d'ƒZeeeeeeeeeeeeeeeeeeed(œZG d)d*„ d*ƒZd+S ),a; Representing and manipulating email headers via custom objects.
This module provides an implementation of the HeaderRegistry API.
The implementation is designed to flexibly follow RFC5322 rules.
Eventually HeaderRegistry will be a public API, but it isn't yet,
and will probably change some before that happens.
é )ÚMappingProxyType)Úutils)Úerrors)Ú_header_value_parserc @ s^ e Zd Zddd„Zedd„ ƒZedd„ ƒZed d
„ ƒZedd„ ƒZd
d„ Z dd„ Z
dd„ ZdS )ÚAddressÚ Nc C sl |dk rV|s|rt dƒ‚tj|ƒ\}}|r:tdj||ƒƒ‚|jrJ|jd ‚|j}|j}|| _|| _ || _
dS )a÷ Create an object representing a full email address.
An address can have a 'display_name', a 'username', and a 'domain'. In
addition to specifying the username and domain separately, they may be
specified together by using the addr_spec keyword *instead of* the
username and domain keywords. If an addr_spec string is specified it
must be properly quoted according to RFC 5322 rules; an error will be
raised if it is not.
An Address object has display_name, username, domain, and addr_spec
attributes, all of which are read-only. The addr_spec and the string
value of the object are both quoted according to RFC5322 rules, but
without any Content Transfer Encoding.
Nz=addrspec specified when username and/or domain also specifiedz6Invalid addr_spec; only '{}' could be parsed from '{}'r )Ú TypeErrorÚparserZ
get_addr_specÚ
ValueErrorÚformatÚall_defectsÚ
local_partÚdomainÚ
_display_nameÚ _usernameÚ_domain)ÚselfÚdisplay_nameÚusernamer Ú addr_specZa_sÚrest© r ú,/usr/lib64/python3.6/email/headerregistry.pyÚ__init__ s
zAddress.__init__c C s | j S )N)r )r r r r r 7 s zAddress.display_namec C s | j S )N)r )r r r r r ; s zAddress.usernamec C s | j S )N)r )r r r r r ? s zAddress.domainc C sT t | jƒ}t|ƒt|tj ƒkr.tj| jƒ}n| j}| jrH|d | j S |sPdS |S )z“The addr_spec (username@domain) portion of the address, quoted
according to RFC 5322 rules, but with no Content Transfer Encoding.
ú@z<>)Úsetr Úlenr Z
DOT_ATOM_ENDSÚquote_stringr )r ÚnamesetZlpr r r r C s
zAddress.addr_specc C s dj | jj| j| j| jƒS )Nz1{}(display_name={!r}, username={!r}, domain={!r}))r Ú __class__Ú__name__r r r )r r r r Ú__repr__S s zAddress.__repr__c C s^ t | jƒ}t|ƒt|tj ƒkr.tj| jƒ}n| j}|rX| jdkrFdn| j}dj||ƒS | jS )Nz<>r z{} <{}>)r r r r ÚSPECIALSr r r )r r Údispr r r r Ú__str__X s
zAddress.__str__c C s8 t |ƒt | ƒkrdS | j|jko6| j|jko6| j|jkS )NF)Útyper r r )r Úotherr r r Ú__eq__c s
zAddress.__eq__)r r r N)r Ú
__module__Ú__qualname__r Úpropertyr r r r r! r$ r' r r r r r s
%r c @ sF e Zd Zddd„Zedd„ ƒZedd„ ƒZdd „ Zd
d„ Zdd
„ Z dS )ÚGroupNc C s || _ |rt|ƒntƒ | _dS )a Create an object representing an address group.
An address group consists of a display_name followed by colon and a
list of addresses (see Address) terminated by a semi-colon. The Group
is created by specifying a display_name and a possibly empty list of
Address objects. A Group can also be used to represent a single
address that is not in a group, which is convenient when manipulating
lists that are a combination of Groups and individual Addresses. In
this case the display_name should be set to None. In particular, the
string representation of a Group whose display_name is None is the same
as the Address object, if there is one and only one Address object in
the addresses list.
N)r ÚtupleÚ
_addresses)r r Ú addressesr r r r m s zGroup.__init__c C s | j S )N)r )r r r r r s zGroup.display_namec C s | j S )N)r- )r r r r r. ƒ s zGroup.addressesc C s dj | jj| j| jƒS )Nz${}(display_name={!r}, addresses={!r})r r r r r. )r r r r r! ‡ s zGroup.__repr__c C sŽ | j d kr&t| jƒdkr&t| jd ƒS | j }|d k r\t|ƒ}t|ƒt|tj ƒkr\tj|ƒ}djdd„ | jD ƒƒ}|r~d| n|}dj ||ƒS )Né r z, c s s | ]}t |ƒV qd S )N)Ústr)Ú.0Úxr r r ú