AlkantarClanX12

Your IP : 3.135.219.153


Current Path : /opt/alt/python310/lib64/python3.10/email/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/email/__pycache__/utils.cpython-310.opt-1.pyc

o

6��f1C�@s�dZgd�ZddlZddlZddlZddlZddlZddlZddlZ	ddl
mZddl
mZ
ddl
mZddl
mZmZmZddlmZd	Zd
Zd
ZdZdZe�d
�Ze�d�Zdd�Zdd�ZdAdd�Zdd�Zdd�Z dZ!dd�dd�Z"dd�Z#d d!�Z$d"d#�Z%d$d%�Z&dBd'd(�Z'dCd)d*�Z(dDd+d,�Z)d-d.�Z*dd�d/d0�Z+d1d2�Z,d3d4�Z-dDd5d6�Z.e�d7ej/�Z0d8d9�Z1	:	;dEd<d=�Z2dFd?d@�Z3dS)GzMiscellaneous utilities.)�collapse_rfc2231_value�
decode_params�decode_rfc2231�encode_rfc2231�
formataddr�
formatdate�format_datetime�getaddresses�
make_msgid�	mktime_tz�	parseaddr�	parsedate�parsedate_tz�parsedate_to_datetime�unquote�N)�quote)�AddressList)r
)rr
�
_parsedate_tz)�Charsetz, �z
�'z[][\\()<>@,:;".]z[\\"]cCs$z|��WdStyYdSw)z8Return True if s contains surrogate-escaped binary data.FT)�encode�UnicodeEncodeError)�s�r�2/opt/alt/python310/lib64/python3.10/email/utils.py�_has_surrogates4s�rcCs|�dd�}|�dd�S)N�utf-8�surrogateescape�replace)r�decode)�stringZoriginal_bytesrrr�	_sanitizeAsr"rcCs�|\}}|�d�|rGz|�d�Wnty/t|t�r"t|�}|�|�}d||fYSwd}t�|�r9d}t�	d|�}d||||fS|S)a�The inverse of parseaddr(), this takes a 2-tuple of the form
    (realname, email_address) and returns the string value suitable
    for an RFC 2822 From, To or Cc header.

    If the first element of pair is false, then the second element is
    returned unmodified.

    The optional charset is the character set that is used to encode
    realname in case realname is not ASCII safe.  Can be an instance of str or
    a Charset-like object which has a header_encode method.  Default is
    'utf-8'.
    �asciiz%s <%s>r�"z\\\g<0>z%s%s%s <%s>)
rr�
isinstance�strrZ
header_encode�
specialsre�search�	escapesre�sub)Zpair�charset�nameZaddressZencoded_nameZquotesrrrrMs"


�
rccsb�d}d}t|�D]\}}|r|d|fVd}q	|dkr d}q	||fVq	|r/|dfVdSdS)NrF�\T)�	enumerate)�addr�pos�escape�chrrr�_iter_escaped_charsns��r3cCs�d|vr|Sd}d}g}t|�D]"\}}|dkr2|dur|}q||kr,|�|||��|d}d}q|t|�krB|�||d��d�|�S)z Strip real names between quotes.r$rN�r)r3�append�len�join)r/�startZopen_pos�resultr0r2rrr�_strip_quoted_realnames}s"�
r:T)�strictcCs�|st�dd�|D��}t|�}|jSdd�|D�}t|�}t�|�}t|�}t|j�}d}|D]}t|�}|d|�d�7}q0t|�|krIdgS|S)	z�Return a list of (REALNAME, EMAIL) or ('','') for each fieldvalue.

    When parsing fails for a fieldvalue, a 2-tuple of ('', '') is returned in
    its place.

    If strict is true, use a strict parser which rejects malformed inputs.
    css�|]}t|�VqdS)N�r&��.0�vrrr�	<genexpr>�s�zgetaddresses.<locals>.<genexpr>cSsg|]}t|��qSrr<r=rrr�
<listcomp>�sz getaddresses.<locals>.<listcomp>rr4�,�rr)	�
COMMASPACEr7�_AddressList�addresslist�_pre_parse_validation�_post_parse_validationr:�countr6)Zfieldvaluesr;�all�ar/r9�nr?rrrr�s 

rcCsVt|�}d}t|�D]\}}|dkr|d7}q
|dkr&|d8}|dkr&dSq
|dkS)Nr�(r4�)F)r:r3)r/Zopensr0r2rrr�_check_parenthesis�s
�rOcCs(g}|D]
}t|�sd}|�|�q|S)Nz('', ''))rOr5)Zemail_header_fields�accepted_valuesr?rrrrG�srGcCs,g}|D]}d|dvrd}|�|�q|S)N�[r4rC)r5)Zparsed_email_header_tuplesrPr?rrrrH�srHc	CsHdgd�|d|dgd�|dd|d|d|d	|d
|fS)Nz"%s, %02d %s %04d %02d:%02d:%02d %s)ZMonZTueZWedZThuZFriZSatZSun��)ZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDecr4r���r)�	timetuple�zonerrr�_format_timetuple_and_zone�s
��rYFcCsR|durt��}|s|rtj�|tjj�}ntj�|�}|r$|��}d}t||�S)a�Returns a date string as specified by RFC 2822, e.g.:

    Fri, 09 Nov 2001 01:08:47 -0000

    Optional timeval if given is a floating point time value as accepted by
    gmtime() and localtime(), otherwise the current time is used.

    Optional localtime is a flag that when True, interprets timeval, and
    returns a date relative to the local timezone instead of UTC, properly
    taking daylight savings time into account.

    Optional argument usegmt means that the timezone is written out as
    an ascii string, not numeric one (so "GMT" instead of "+0000"). This
    is needed for HTTP, and is only used when localtime==False.
    NF)�time�datetimeZ
fromtimestamp�timezone�utcZutcfromtimestamp�
astimezoner)�timeval�	localtime�usegmt�dtrrrr�s
rcCsV|��}|r|jdus|jtjjkrtd��d}n
|jdur!d}n|�d�}t||�S)a$Turn a datetime into a date string as specified in RFC 2822.

    If usegmt is True, dt must be an aware datetime with an offset of zero.  In
    this case 'GMT' will be rendered instead of the normal +0000 required by
    RFC2822.  This is to support HTTP headers involving date stamps.
    Nz%usegmt option requires a UTC datetimeZGMTz-0000z%z)rW�tzinfor[r\r]�
ValueError�strftimerY)rbra�nowrXrrrrs


rcCs^tt��d�}t��}t�d�}|durd}nd|}|dur$t��}d|||||f}|S)a{Returns a string suitable for RFC 2822 compliant Message-ID, e.g:

    <142480216486.20800.16526388040877946887@nightshade.la.mastaler.com>

    Optional idstring if given is a string used to strengthen the
    uniqueness of the message id.  Optional domain if given provides the
    portion of the message id after the '@'.  It defaults to the locally
    defined hostname.
    �d�@Nr�.z<%d.%d.%d%s@%s>)�intrZ�os�getpid�randomZgetrandbits�socketZgetfqdn)ZidstringZdomainr_�pidZrandintZmsgidrrrr	"s

r	cCsjt|�}|durtdt|���|�^}}|dur"tj|dd��Stj|dd�dt�tj|d��i�S)Nz!Invalid date value or format "%s"rRrc��seconds)rrdr&r[r\�	timedelta)�dataZparsed_date_tzZdtuple�tzrrrr9s
�rcCsv|st|�j}|sdS|dSt|t�r|d}t|t�sdSt|g�d}tt|�j�}|r5t|�dkr7dS|dS)a
    Parse addr into its constituent realname and email address parts.

    Return a tuple of realname and email address, unless the parse fails, in
    which case return a 2-tuple of ('', '').

    If strict is True, use a strict parser which rejects malformed inputs.
    rCrr4)rErFr%�listr&rGrHr6)r/r;ZaddrsrrrrDs	


rcCs`t|�dkr.|�d�r|�d�r|dd��dd��dd�S|�d�r.|�d�r.|dd�S|S)	zRemove quotes from a string.r4r$���z\\r-z\"�<�>)r6�
startswith�endswithrr<rrrrcsrcCs&|�td�}t|�dkrdd|fS|S)z#Decode string according to RFC 2231rSN)�split�TICKr6)r�partsrrrros
rcCsDtjj|d|pdd�}|dur|dur|S|durd}d|||fS)z�Encode string according to RFC 2231.

    If neither charset nor language is given, then s is returned as-is.  If
    charset is given but not language, the string is encoded using the empty
    string for language.
    rr#)Zsafe�encodingNz%s'%s'%s)�urllib�parser)rr+�languagerrrrwsrz&^(?P<name>\w+)\*((?P<num>[0-9]+)\*?)?$c
Cs<|dg}i}|dd�D]<\}}|�d�}t|�}t�|�}|r>|�dd�\}}|dur1t|�}|�|g��|||f�q
|�|dt|�f�q
|r�|�	�D]K\}}g}d}	|�
�|D]\}}
}|rotjj|
d	d
�}
d}	|�|
�q^tt
�|��}|	r�t|�\}}}|�|||d|ff�qP|�|d|f�qP|S)zDecode parameters list according to RFC 2231.

    params is a sequence of 2-tuples containing (param name, string value).
    rr4N�*r,�numz"%s"Fzlatin-1)r~T)rzr�rfc2231_continuation�match�grouprj�
setdefaultr5r�items�sortrr��EMPTYSTRINGr7r)
�paramsZ
new_paramsZrfc2231_paramsr,�valueZencodedZmor�Z
continuationsZextendedrr+r�rrrr�s8


rr�us-asciicCsht|t�rt|�dkrt|�S|\}}}|dur|}t|d�}zt|||�WSty3t|�YSw)NrTzraw-unicode-escape)r%�tupler6r�bytesr&�LookupError)r��errorsZfallback_charsetr+r��textZrawbytesrrrr�s

�rrvc	Cs|durtj�tjj���S|jdur|��S|��dd�|f}t�|�}t�	|�}ztj
|jd�}t�||j�}Wn?t
y{|tjt�|�dd��}tjoX|jdk}|r^tjntj}|tj
|d�krtt�|tj|�}nt�|�}Ynw|j|d�S)a�Return local time as an aware datetime object.

    If called without arguments, return current time.  Otherwise *dt*
    argument should be a datetime instance, and it is converted to the
    local time zone according to the system time zone database.  If *dt* is
    naive (that is, dt.tzinfo is None), it is assumed to be in local time.
    In this case, a positive or zero value for *isdst* causes localtime to
    presume initially that summer time (for example, Daylight Saving Time)
    is or is not (respectively) in effect for the specified time.  A
    negative value for *isdst* causes the localtime() function to attempt
    to divine whether summer time is in effect for the specified time.

    NrvrprRr)rc)r[rfr\r]r^rcrWrZ�mktimer`rr�	tm_gmtoff�tm_zone�AttributeError�gmtime�daylight�tm_isdst�altzone�tznamer)	rbZisdstZtmrqZlocaltmZdeltartZdstZgmtoffrrrr`�s(



��
r`)r)NFF)F)NN)rr�)Nrv)4�__doc__�__all__rk�rerZrmrnr[Zurllib.parserZemail._parseaddrrrrEr
rr
rZ
email.charsetrrDr�ZUEMPTYSTRINGZCRLFr|�compiler'r)rr"rr3r:Zsupports_strict_parsingrrOrGrHrYrrr	rrrrr�ASCIIr�rrr`rrrr�<module>s`


!,

	


�0
�