3 ¦ fI6ã@s~dZddddddddd d d d d ddgZddlZddlZddlZddlZddlZddlZddlZ ddl m Z ddl m Z ddl mZddl mZmZmZddlmZdZdZdZdZdZejdƒZejdƒZdd„Zdd „Zd8d"d„Zd#d„Zejd$ej ej!BƒZ"d%d&„Z#d9d(d„Z$d:d)d„Z%d;d*d „Z&d+d„Z'd,d „Z(d-d„Z)d.d„Z*d@,:;".]z[\\"]c Cs&y |jƒdStk r dSXdS)z8Return True if s contains surrogate-escaped binary data.FTN)ÚencodeÚUnicodeEncodeError)Ús©rú0/opt/alt/python36/lib64/python3.6/email/utils.pyÚ_has_surrogates3s rcCs|jddƒ}|jddƒS)Nzutf-8ÚsurrogateescapeÚreplace)rÚdecode)ÚstringZoriginal_bytesrrrÚ _sanitize@s r!úutf-8c Cs�|\}}|jdƒ|rŒy|jdƒWn8tk r\t|tƒrFt|ƒ}|j|ƒ}d||fSXd}tj|ƒrpd}tj 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. Optional charset if given 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_nameZquotesrrrrLs      cCstj|ƒ}t|ƒ}|jS)z7Return a list of (REALNAME, EMAIL) for each fieldvalue.)Ú COMMASPACEÚjoinÚ _AddressListÚ addresslist)Z fieldvaluesÚallÚarrrrns a_ =\? # literal =? (?P[^?]*?) # non-greedy up to the next ? is the charset \? # literal ? (?P[qb]) # either a "q" or a "b", case insensitive \? # literal ? (?P.*?) # non-greedy up to the next ?= is the atom \?= # literal ?= cCsfddddddddg|d |d d d d dddddddddg |dd|d|d|d|d|fS)Nz"%s, %02d %s %04d %02d:%02d:%02d %sZMonZTueZWedZThuZFriZSatZSunééZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDecérééér)Ú timetupleÚzonerrrÚ_format_timetuple_and_zone�s r;FcCsR|dkrtjƒ}|s|r,tjj|tjjƒ}n tjj|ƒ}|rH|jƒ}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 cCsV|jƒ}|r2|jdks$|jtjjkr,tdƒ‚d}n|jdkrBd}n |jdƒ}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)r9Útzinfor=r>r?Ú ValueErrorZstrftimer;)rDrCÚnowr:rrrr§s  cCs^ttjƒdƒ}tjƒ}tjdƒ}|dkr0d}nd|}|dkrHtjƒ}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>)Úintr<ÚosÚgetpidÚrandomZ getrandbitsÚsocketZgetfqdn)ZidstringZdomainrAÚpidZrandintZmsgidrrrr ºs  cCsNt|ƒ�^}}|dkr(tj|dd…ŽStj|dd…dtjtj|d�ƒiŽS)Nr3rE)Úseconds)rr=r>Ú timedelta)ÚdataZdtupleÚtzrrrrÑs cCst|ƒj}|sdS|dS)zÆ 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 ('', ''). rr)rr)r/r0)ZaddrZaddrsrrrr Ùs cCs`t|ƒdkr\|jdƒr<|jdƒr<|dd…jddƒjddƒS|jdƒr\|jdƒr\|dd …S|S) zRemove quotes from a string.r5r$z\\ú\z\"ú<ú>éÿÿÿÿrX)ÚlenÚ startswithÚendswithr)r&rrrrçs   cCs&|jtdƒ}t|ƒdkr"dd|fS|S)z#Decode string according to RFC 2231r4N)ÚsplitÚTICKrY)rÚpartsrrrrós   cCsDtjj|d|pdd�}|dkr*|dkr*|S|dkr6d}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+Úlanguagerrrrûs z&^(?P\w+)\*((?P[0-9]+)\*?)?$c Csx|dd…}g}i}|jdƒ\}}|j||fƒx�|rÀ|jdƒ\}}|jdƒrTd}nd}t|ƒ}tj|ƒ}|r¨|jddƒ\}}|dk rŽt|ƒ}|j|gƒj|||fƒq2|j|dt |ƒfƒq2W|�rtxª|j ƒD]ž\}}g}d} |j ƒx6|D].\}} }|�rt j j| d d �} d} |j| ƒqðWt tj|ƒƒ}| �r^t|ƒ\} } }|j|| | d|ffƒqÒ|j|d|fƒqÒW|S) zDecode parameters list according to RFC 2231. params is a sequence of 2-tuples containing (param name, string value). NrÚ*TFr,Únumz"%s"zlatin-1)r_)ÚpopÚappendr[rÚrfc2231_continuationÚmatchÚgrouprKÚ setdefaultrÚitemsÚsortr`raÚ EMPTYSTRINGr.r) ZparamsZ new_paramsZrfc2231_paramsr,ÚvalueZencodedZmordZ continuationsZextendedrr+rbrrrr sD   rúus-asciic Csjt|tƒ st|ƒdkr t|ƒS|\}}}|dkr6|}t|dƒ}y t|||ƒStk rdt|ƒSXdS)Nr6zraw-unicode-escape)r%ÚtuplerYrÚbytesr&Ú LookupError)rnÚerrorsZfallback_charsetr+rbÚtextZrawbytesrrrrEs   r5c Cs|dkrtjjtjjƒjƒS|jdk r.|jƒS|jƒdd…|f}tj|ƒ}tj |ƒ}y tj |j d�}tj||j ƒ}Wn€t k rø|tjtj|ƒdd…Ž}tjo²|jdk}|r¾tjntj }|tj |d�krêtj|tj|ƒ}n tj|ƒ}YnX|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. Nr5)rQr3r)rErX)r=rGr>r?r@rEr9r<ZmktimerBrRZ tm_gmtoffZtm_zoneÚAttributeErrorZgmtimeZdaylightZtm_isdstZaltzoneZtznamer) rDZisdstZtmrQZlocaltmZdeltarTÚdstZgmtoffrrrrB_s$   rB)r")NFF)F)NN)NN)rrorX)NrX)1Ú__doc__Ú__all__rLÚrer<rNrOr=Z urllib.parser`Zemail._parseaddrrrr/r r r rZ email.charsetrr-rmZ UEMPTYSTRINGZCRLFr]Úcompiler'r)rr!rrÚVERBOSEÚ IGNORECASEZecrer;rrr rr rrrÚASCIIrgrrrBrrrrÚsn        "     8