Viewing File: /opt/alt/python-internal/lib64/python3.11/email/__pycache__/utils.cpython-311.pyc



!A?hFCdZgdZddlZddlZddlZddlZddlZddlZddlZ	ddl
mZddl
mZ
ddl
mZddl
mZmZmZddlmZd	Zd
Zd
ZdZdZejd
ZejdZdZdZd,dZdZdZ dZ!dddZ"dZ#dZ$dZ%dZ&d-dZ'd.dZ(d/dZ)d Z*ddd!Z+d"Z,d#Z-d/d$Z.ejd%ej/Z0d&Z1		d0d)Z2d1d+Z3dS)2zMiscellaneous utilities.)collapse_rfc2231_value
decode_paramsdecode_rfc2231encode_rfc2231
formataddr
formatdateformat_datetimegetaddresses
make_msgid	mktime_tz	parseaddr	parsedateparsedate_tzparsedate_to_datetimeunquoteN)quote)AddressList)r)r
r
_parsedate_tz)Charsetz, z
'z[][\\()<>@,:;".]z[\\"]cR	|dS#t$rYdSwxYw)z;Return True if s may contain surrogate-escaped binary data.FT)encodeUnicodeEncodeError)ss 8/opt/alt/python-internal/lib64/python3.11/email/utils.py_has_surrogatesr4s;
	


utts
&&cZ|dd}|ddS)Nutf-8surrogateescapereplace)rdecode)stringoriginal_bytess  r	_sanitizer%As.
]]7,=>>N  )444rc|\}}|d|r	|dd}t|rd}td|}|||d|dS#t
$rDt
|trt|}|	|}|d|dcYSwxYw|S)aThe 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'.
    asciir"z\\\g<0>z <>)
r
specialsresearch	escapesresubr
isinstancestrr
header_encode)paircharsetnameaddressquotesencoded_names      rrrMsMD'NN7
C	CKK   F  &&
==T22D$*FDD&&&'''BB"	7	7	7'3''
+!'**"0066L ,ggg6666		7NsA88ACCc#Kd}d}t|D]"\}}|r|d|zfVd}|dkrd}||fV#|r|dfVdSdS)NrF\T)	enumerate)addrposescapechs    r_iter_escaped_charsr?ns
C
FT??R	r	""""FF
4ZZFF)OOOO
Dkr&c8d|vr|Sd}d}g}t|D]:\}}|dkr/||}||kr|||||dz}d};|t|kr|||dd|S)z Strip real names between quotes.r)rNr)r?appendlenjoin)r;startopen_posresultr<r>s      r_strip_quoted_realnamesrH}s
$
EH
F&t,,  R
99H$$MM$uX~"6777as4yy

d566l###
776??r&T)strictc|s:td|D}t|}|jSd|D}t	|}t|}t|}t|j}d}|D],}t
|}|d|dzz
}-t||krdgS|S)zReturn 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.
    c34K|]}t|VdS)Nr0.0vs  r	<genexpr>zgetaddresses.<locals>.<genexpr>s(::c!ff::::::r&c,g|]}t|SrLrMs  r
<listcomp>z getaddresses.<locals>.<listcomp>s///a3q66///r&rrA,rr)	
COMMASPACErD_AddressListaddresslist_pre_parse_validation_post_parse_validationrHcountrC)fieldvaluesrIallar;rGnrOs        rr	r	s$oo::k:::::}//;///K'44K??;''DTA
#AM
2
2F	
A

$A&&	Q

6{{azMr&ct|}d}t|D]%\}}|dkr|dz
}|dkr|dz}|dkrdS&|dkS)Nr(rA)F)rHr?)r;opensr<r>s    r_check_parenthesisrdsp"4((D
E&t,,R
99QJEE
3YYQJEqyyuuQJr&c`g}|D](}t|sd}||)|S)Nz('', ''))rdrB)email_header_fieldsaccepted_valuesrOs   rrYrYsHO
 ""!!$$	Aq!!!!r&cVg}|D]#}d|dvrd}||$|S)N[rArU)rB)parsed_email_header_tuplesrgrOs   rrZrZsGO(""!A$;;Aq!!!!r&c	dgd|d|dgd|ddz
|d|d|d	|d
|fzS)Nz"%s, %02d %s %04d %02d:%02d:%02d %s)MonTueWedThuFriSatSun)JanFebMarAprMayJunJulAugSepOctNovDecrArrR)	timetuplezones  r_format_timetuple_and_zonersj/999)A,G!	3	3	33<Q<!3C	E!ilIaL)A,
3r&Fc"|tj}|s|r0tj|tjj}ntj|}|r|}d}t||S)aReturns 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)timedatetime
fromtimestamptimezoneutcutcfromtimestamp
astimezoner)timeval	localtimeusegmtdts    rrrs$)++9F9


,
,Wh6G6K
L
L


/
/
8
8
]]__2v&&&r&c|}|r3|j|jtjjkrtdd}n|jd}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 datetimeGMTz-0000z%z)rtzinforrr
ValueErrorstrftimer)rrnowrs    rrrsy
,,..C
!
9	X->-B B BDEEE		{{4  %c4000r&cttjdz}tj}t	jd}|d}nd|z}|t
j}d|||||fz}|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>)introsgetpidrandomgetrandbitssocketgetfqdn)idstringdomainrpidrandintmsgids      rr
r
"sx$)++c/""G
)++C $$G>
~!!#w& IIELr&c	t|}|tdt|z|^}}|tj|ddStj|dddtjtj|iS)Nz!Invalid date value or format "%s"rsrseconds)rrr0rr	timedelta)dataparsed_date_tzdtupletzs    rrr9s"4((N<s4yyHIII KVR	z &!*--fRaRjF$X%7%C%C%CDDFFFr&cZ|s t|j}|sdS|dSt|tr|d}t|tsdSt|gd}t
t|j}|rt|dkrdS|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.
    rUrrA)rWrXr/listr0rYrZrC)r;rIaddrss   rrrDsT"".	8Qx$AwdC  x $((+D"<#5#5#ABBECJJNNx8Or&cLt|dkr|drG|dr2|ddddddS|dr|dr
|ddS|S)	zRemove quotes from a string.rAr)z\\r9z\"<r*)rC
startswithendswithr!rLs rrrcs
3xx!||>>#	G3<<#4#4	Gqt9$$VT22::5#FFF>>#	3<<#4#4	qt9Jr&cl|td}t|dkrdd|fS|S)z#Decode string according to RFC 2231rtN)splitTICKrC)rpartss  rrros5
GGD!E
5zzQT1}Lr&crtj|d|pd}|||S|d}|d|d|S)zEncode 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()safeencodingNr)urllibparser)rr3languages   rrrwsV	120B7CCA8+ (((AA..r&z&^(?P<name>\w+)\*((?P<num>[0-9]+)\*?)?$c|dg}i}|ddD]\}}|d}t|}t|}|rW|dd\}}|t|}||g|||f||dt|zf|r|	D]\}}g}d}	|
|D]@\}}
}|r#tj|
d	
}
d}	||
Att|}|	r1t|\}}}||||d|zff||d|zf|S)zDecode parameters list according to RFC 2231.

    params is a sequence of 2-tuples containing (param name, string value).
    rrAN*r4numz"%s"Fzlatin-1)rT)rrrfc2231_continuationmatchgroupr
setdefaultrBritemssortrrEMPTYSTRINGrDr)
params
new_paramsrfc2231_paramsr4valueencodedmor
continuationsextendedrr3rs
             rrrs
)JNabbz
=
=e--$$
!
'
'
-
-
	=//ID##hh%%dB//66UG7LMMMMtVeEll%:;<<<<:#1#7#7#9#9	:	:D-EH   $1
 
 Q$,,Q,CCA#HQ+**51122E
:+9%+@+@(5!!4'8Ve^)L"MNNNN!!4%"89999r&r!us-asciict|trt|dkrt|S|\}}}||}t	|d}	t|||S#t$rt|cYSwxYw)Nrzraw-unicode-escape)r/tuplerCrbytesr0LookupError)rerrorsfallback_charsetr3rtextrawbytess       rrrseU##s5zzQu~~$GXt#T/00H8Wf---t}}sA$$B?Brcd|@tjtjjS|j|S|dd|fz}tj|}tj	|}	tj
|j}tj||j}n#t$r|tjtj|ddz
}tjo
|jdk}|rtjntj}|tj
|kr&tj|tj|}ntj|}YnwxYw||S)aReturn 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.

    Nrrrsr)r)rrrrrrrrmktimerr	tm_gmtofftm_zoneAttributeErrorgmtimedaylighttm_isdstaltzonetznamer!)	risdsttmrlocaltmdeltardstgmtoffs	         rrrs{
z $$X%6%:;;FFHHH	y}}
	x	'Bk"ooGnW%%G*"7+<===

ugo
6
6	*	*	*X&G(<(<RaR(@AAm4 01 4#&94<<DM:H&v66666"5$+c*:;;BB"5))B	*::R:   s'4CB:FF)r)NFF)F)NN)r!r)Nr)4__doc____all__rrerrrrurllib.parseremail._parseaddrrrrWrr
rr
email.charsetrrVrUEMPTYSTRINGCRLFrcompiler+r-rr%rr?rHsupports_strict_parsingr	rdrYrZrrrr
rrrrrASCIIrrrrrRr&r<module>rs
$
							







""""""888888&&&&&&CCCCCCCCCC"!!!!!




RZ+
,
,
BJx  				555B2(,)))))X			'''':1111&.FFF#>////"rz"KH...`*3,64%!%!%!%!%!%!r&
Back to Directory File Manager