a DOgB@sdZgdZddlZddlZddlZddlZddlZddlZddlZ ddl m Z ddl m Z ddl mZddl mZmZmZddlmZd Zd Zd Zd Zd Zed ZedZddZddZdAddZddZddZ dZ!ddddZ"ddZ#d d!Z$d"d#Z%d$d%Z&dBd'd(Z'dCd)d*Z(dDd+d,Z)d-d.Z*ddd/d0Z+d1d2Z,d3d4Z-dEd5d6Z.ed7ej/Z0d8d9Z1dFd@,:;".]z[\\"]cCs(z|WdSty"YdS0dS)z8Return True if s contains surrogate-escaped binary data.FTN)encodeUnicodeEncodeError)sr0/opt/alt/python39/lib64/python3.9/email/utils.py_has_surrogates4s  rcCs|dd}|ddS)Nutf-8surrogateescapereplace)rdecode)stringZoriginal_bytesrrr _sanitizeAs r"rcCs|\}}|d|rz|dWn:ty^t|trDt|}||}d||fYS0d}t|rrd}t d|}d||||fS|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'. asciiz%s <%s>r"z\\\g<0>z %s%s%s <%s>) rr isinstancestrrZ header_encode specialsresearch escapesresub)ZpaircharsetnameZaddressZ encoded_nameZquotesrrrrMs       rccs\d}d}t|D]8\}}|r0|d|fVd}q|dkr>d}q||fVq|rX|dfVdS)NrF\T) enumerate)addrposescapechrrr_iter_escaped_charsns r3cCsd|vr |Sd}d}g}t|D]D\}}|dkr |dur>|}q ||krX|||||d}d}q |t|kr|||dd|S)z Strip real names between quotes.r$rNr)r3appendlenjoin)r/startZopen_posresultr0r2rrr_strip_quoted_realnames}s  r:T)strictcCs|s&tdd|D}t|}|jSdd|D}t|}t|}t|}t|j}d}|D]}t|}|d|d7}q`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. css|]}t|VqdS)Nr&.0vrrr zgetaddresses..cSsg|] }t|qSrr<r=rrr rAz getaddresses..rr4,rr) COMMASPACEr7 _AddressList addresslist_pre_parse_validation_post_parse_validationr:countr6)Z fieldvaluesr;allar/r9nr?rrrrs    rcCsVt|}d}t|D]8\}}|dkr.|d7}q|dkr|d8}|dkrdSq|dkS)Nr(r4)F)r:r3)r/Zopensr0r2rrr_check_parenthesiss rPcCs(g}|D]}t|sd}||q|S)Nz('', ''))rPr5)Zemail_header_fieldsaccepted_valuesr?rrrrHs  rHcCs,g}|D]}d|dvrd}||q|S)N[r4rD)r5)Zparsed_email_header_tuplesrQr?rrrrIs   rIc CsHdgd|d|dgd|dd|d|d|d |d |fS) Nz"%s, %02d %s %04d %02d:%02d:%02d %s)ZMonZTueZWedZThuZFriZSatZSun) ZJanZFebZMarZAprZMayZJunZJulZAugZSepZOctZNovZDecr4rr) timetuplezonerrr_format_timetuple_and_zones rZFcCsR|durt}|s|r,tj|tjj}n tj|}|rH|}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)timedatetimeZ fromtimestamptimezoneutcZutcfromtimestamp astimezoner)timeval localtimeusegmtdtrrrrs rcCsV|}|r2|jdus$|jtjjkr,tdd}n|jdurBd}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)rXtzinfor\r]r^ ValueErrorstrftimerZ)rcrbnowrYrrrrs  rcCs^ttd}t}td}|dur0d}nd|}|durHt}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[osgetpidrandomZ getrandbitssocketZgetfqdn)ZidstringZdomainr`pidZrandintZmsgidrrrr "s  r cCsNt|^}}|dur(tj|ddStj|dddttj|diS)NrSrdseconds)rr\r] timedelta)dataZdtupletzrrrr9s rcCsv|st|j}|sdS|dSt|tr0|d}t|ts>dSt|gd}tt|j}|rjt|dkrndS|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. rDrr4)rFrGr%listr&rHrIr6)r/r;Zaddrsrrrr As    r cCs`t|dkr\|dr<|dr<|ddddddS|dr\|dr\|ddS|S) zRemove quotes from a string.r4r$z\\r-z\"<>)r6 startswithendswithrr<rrrr`s   rcCs&|td}t|dkr"dd|fS|S)z#Decode string according to RFC 2231rTN)splitTICKr6)rpartsrrrrls   rcCsDtjj|d|pdd}|dur*|dur*|S|dur6d}d|||fS)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#)ZsafeencodingNz%s'%s'%s)urllibparser)rr+languagerrrrts rz&^(?P\w+)\*((?P[0-9]+)\*?)?$c Cs@|dg}i}|ddD]x\}}|d}t|}t|}|r||dd\}}|durbt|}||g|||fq||dt|fq|r<| D]\}}g}d} | |D],\}} }|rt j j| d d } d } || qtt |}| r(t|\} } }||| | d|ffq||d|fq|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)rT)r{rrfc2231_continuationmatchgrouprk setdefaultr5ritemssortrr EMPTYSTRINGr7r) params new_paramsZrfc2231_paramsr,valueZencodedZmorZ continuationsZextendedrr+rrrrrs8    rrus-asciicCslt|trt|dkrt|S|\}}}|dur4|}t|d}zt|||WStyft|YS0dS)NrUzraw-unicode-escape)r%tupler6rbytesr& LookupError)rerrorsZfallback_charsetr+rtextZrawbytesrrrrs   rrwc Cs|durtjtjjS|jdur.|S|dd|f}t|}t |}z tj |j d}t||j }Wn~t y|tjt|dd}tjo|jdk}|rtjntj }|tj |dkrt|tj|}n t|}Yn0|j|dS)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. NrwrqrSr)rd)r\rgr]r^r_rdrXr[mktimerars tm_gmtofftm_zoneAttributeErrorgmtimedaylighttm_isdstaltzonetznamer) rcZisdstZtmrrZlocaltmZdeltaruZdstZgmtoffrrrras$    ra)r)NFF)F)NN)NN)rr)Nrw)4__doc____all__rlrer[rnror\Z urllib.parserZemail._parseaddrrrrFr r r rZ email.charsetrrErZ UEMPTYSTRINGZCRLFr}compiler'r)rr"rr3r:Zsupports_strict_parsingrrPrHrIrZrrr rr rrrASCIIrrrrarrrrs^        !,       0