B Š51äu öÍã @s€ddlZddlZddlZddlZddlZy ddlZWnek rLdZYnXdZddlm Z ddlm Z dddd d d d d gZ dZ Gdd„deƒZGdd„deƒZGdd „d eƒZGdd „d eƒZGdd „d eƒZGdd „d eƒZdZdZdddddddddd d!d"h Zd#d$d%d&d'd(d)gZd(d)d*œZd+Ze d,d-d.d/d0g¡Ze d1d2d3d4g¡Zd5d „Z d6d7„Zdld8d9„Zdmd:d;„Z dndd?„Z"Gd@dA„dAƒZ#GdBd„de#ƒZ$erÆGdCdD„dDe#ƒZ%e  &dD¡e'dEkr|ddl(Z(e(j)dFdGZ*e*j+dHdIdJdKdLe*j+dMdNdOdPdLe*j+dQdRdSe,dTeefdUe*j+dVdWdXe,dYdUe*j+dZd[d\dd]d^e* -¡Z.e.j/Z/e.js€e/dSkrpeZ/e$e.j0e/d_Z1ne/dSkrŽeZ/e%e.j0e/d_Z1e1 2¡Z3d`e3kr¶e1 4¡e1 5e.j5¡\Z6Z7Z8Z9Z:e;dae:dbe7dce8dde9ƒdedf„ZdgƒZ8e1 ?e8e9¡\Z6Z@xbe@D]Z\ZAZBe eBd$ƒ Cdhdg¡dZDe eBd#ƒZEe,eBd)ƒZFe;di GeAetj|f|žŽy|d|_Wntk r8d|_YnXdS)NrzNo response given)Ú ExceptionÚ__init__ÚresponseÚ IndexError)ÚselfÚargs©rú*/opt/alt/python37/lib/python3.7/nntplib.pyr bs zNNTPError.__init__N)Ú__name__Ú __module__Ú __qualname__r rrrrr`sc@s eZdZdS)rN)rrrrrrrrisc@s eZdZdS)rN)rrrrrrrrmsc@s eZdZdS)rN)rrrrrrrrqsc@s eZdZdS)r N)rrrrrrrr usc@s eZdZdS)r N)rrrrrrrr yséwi3Z100Z101Ú211Ú215Z220Z221Z222Z224Z225Z230Z231Z282ÚsubjectÚfromÚdatez message-idZ referencesz:bytesz:lines)ÚbytesÚliness Ú GroupInfoÚgroupÚlastÚfirstÚflagÚ ArticleInfoZnumberÚ message_idrcCsNg}x>t|ƒD]2\}}t|tƒr6| | |p.d¡¡q| |¡qWd |¡S)NÚasciiÚ)Ú_email_decode_headerÚ isinstancerÚappendÚdecodeÚjoin)Z header_strÚpartsÚvÚencrrrr§s  cCsªg}xh|D]`}|ddkr<|dd… d¡\}}}d|}n| d¡\}}}| ¡}t ||¡}| |¡q Wt}t|ƒt|ƒkrŠtdƒ‚|dt|ƒ…|kr¦tdƒ‚|S)Nrú:éz$LIST OVERVIEW.FMT response too shortz*LIST OVERVIEW.FMT redefines default fields)Ú partitionÚlowerÚ_OVERVIEW_FMT_ALTERNATIVESÚgetr)Ú_DEFAULT_OVERVIEW_FMTÚlenr )rÚfmtÚlineÚnameÚ_ÚsuffixÚdefaultsrrrÚ_parse_overview_fmt²s    r=cCsØttƒ}g}xÆ|D]¾}i}| d¡^}}t|ƒ}xt|ƒD]„\} } | t|ƒkrPq:|| } |  d¡} | |kr²| s²| d} | rš| dt| ƒ… ¡| krštdƒ‚| r®| t| ƒd…nd} | ||| <q:W| ||f¡qW|S)Nú r/z: z?OVER/XOVER response doesn't include names of additional headers) r6r5ÚsplitÚintÚ enumerateÚ startswithr2r r))rr7Zdata_process_funcZ n_defaultsZoverviewr8ZfieldsZarticle_numberÚtokensÚiÚtokenZ field_nameZ is_metadataÚhrrrÚ_parse_overviewËs&    rGcCs¶|dkr |dd…}|dd…}t|dd…ƒ}t|dd…ƒ}t|dd…ƒ}t|dd…ƒ}t|dd…ƒ}t|dd…ƒ}|dkr’|d7}n|dkr¢|d 7}t ||||||¡S) NiúÿÿÿéééüÿÿÿéþÿÿÿéFiÐédil)r@Údatetime)Údate_strÚtime_strZhoursZminutesZsecondsÚyearZmonthZdayrrrÚ_parse_datetimeès   rRcCsPt|tjƒsd}n d |¡}|j}|r<|d}d ||¡}n d ||¡}||fS)NZ000000z({0.hour:02d}{0.minute:02d}{0.second:02d}rMz{0:02d}{1.month:02d}{1.day:02d}z{0:04d}{1.month:02d}{1.day:02d})r(rNÚformatrQ)ZdtÚlegacyrPÚyrOrrrÚ_unparse_datetimeþs   rVcCs|dkrt ¡}|j||dS)N)Zserver_hostname)ÚsslZ_create_stdlib_contextZ wrap_socket)ÚsockÚcontextZhostnamerrrÚ _encrypt_onsrZc@seZdZdZdZdefdd„Zdd„Zdd „Zd d „Z d d „Z dd„Z e Z dd„Z dd„Zdhdd„Zdd„Zdidd„Zdd„Zdjdd„Zdkdd „Zd!d"„Zd#d$„Zd%d&„Zdd'œd(d)„Zdd'œd*d+„Zdldd'œd,d-„Zd.d/„Zd0d1„Zd2d3„Zd4d5„Zdd'œd6d7„Zd8d9„Z d:d;„Z!dmdd?„Z#d@dA„Z$dndBdC„Z%dodd'œdDdE„Z&dpdd'œdFdG„Z'dqdd'œdHdI„Z(dJdK„Z)dd'œdLdM„Z*dd'œdNdO„Z+dd'œdPdQ„Z,dd'œdRdS„Z-dTdU„Z.dVdW„Z/dXdY„Z0dZd[„Z1d\d]„Z2d^d_„Z3d`da„Z4drdbdc„Z5ddde„Z6e7rdsdfdg„Z8dS)tÚ _NNTPBasezutf-8ÚsurrogateescapeNcCsj||_||_d|_| ¡|_d|_| ¡d|_|rZd|jkrZ| ¡|jsZd|_| ¡d|_ d|_ dS)NrFÚREADER) ÚhostÚfileÚ debuggingÚ_getrespÚwelcomeÚ_capsÚgetcapabilitiesÚreadermode_afterauthÚ_setreadermodeÚtls_onÚ authenticated)rr_r^Ú readermodeÚtimeoutrrrr 8s  z_NNTPBase.__init__cCs|S)Nr)rrrrÚ __enter__gsz_NNTPBase.__enter__c sR‡fdd„}|ƒrNz*y ˆ ¡Wnttfk r8YnXWd|ƒrLˆ ¡XdS)Ncs tˆdƒS)Nr_)Úhasattrr)rrrÚkóz$_NNTPBase.__exit__..)ÚquitÚOSErrorÚEOFErrorÚ_close)rrZ is_connectedr)rrÚ__exit__js   z_NNTPBase.__exit__cCs|jrtdt|jƒƒ|jS)Nz *welcome*)r`ÚprintÚreprrb)rrrrÚ getwelcomeusz_NNTPBase.getwelcomec Cs†|jdkr€d|_d|_y| ¡\}}Wnttfk rDi|_Ynsz,_NNTPBase._longcmdstring..)r‡r—)rr8r_r|Úlistr)rrÚ_longcmdstrings  z_NNTPBase._longcmdstringcCsby|jStk rYnXy| d¡\}}Wn tk rNtdd…}Yn Xt|ƒ}||_|S)NzLIST OVERVIEW.FMT)Z_cachedoverviewfmtÚAttributeErrorrrr5r=)rr|rr7rrrÚ_getoverviewfmtsz_NNTPBase._getoverviewfmtcCsdd„|DƒS)NcSsg|]}t| ¡Ž‘qSr)rr?)ršr8rrrr›$sz(_NNTPBase._grouplist..r)rrrrrÚ _grouplist"sz_NNTPBase._grouplistcCs<i}| d¡\}}x |D]}| ¡^}}|||<qW||fS)NZ CAPABILITIES)rr?)rr}r|rr8r9rCrrrry&s    z_NNTPBase.capabilities)r_cCsbt|tjtjfƒs$td |jj¡ƒ‚t||jdkƒ\}}d ||¡}|  ||¡\}}||  |¡fS)NzAthe date parameter must be a date or datetime object, not '{:40}'rHzNEWGROUPS {0} {1}) r(rNrÚ TypeErrorrSÚ __class__rrVrxrr )rrr_rOrPÚcmdr|rrrrÚ newgroups4s  z_NNTPBase.newgroupscCsRt|tjtjfƒs$td |jj¡ƒ‚t||jdkƒ\}}d |||¡}|  ||¡S)NzAthe date parameter must be a date or datetime object, not '{:40}'rHzNEWNEWS {0} {1} {2}) r(rNrr¡rSr¢rrVrxr)rrrr_rOrPr£rrrÚnewnewsDs z_NNTPBase.newnewscCs4|dk rd|}nd}| ||¡\}}|| |¡fS)Nz LIST ACTIVE ZLIST)rr )rÚ group_patternr_Úcommandr|rrrrrœTs  z_NNTPBase.listc Cst d¡}| d|¡\}}| d¡s8| d|¡\}}i}x>|D]6}| | ¡¡}|rB| dd¡\} } |sp| S| || <qBW|rˆ||fSdSdS)Nz^(?P[^ ]+)[ ]+(.*)$zLIST NEWSGROUPS rzXGTITLE r0rHr&)ÚreÚcompilerrBÚsearchÚstripr) rr¦Z return_allÚline_patr|rÚgroupsÚraw_lineÚmatchr9ZdescrrrÚ_getdescriptionscs    z_NNTPBase._getdescriptionscCs | |d¡S)NF)r°)rrrrrÚ descriptionzs z_NNTPBase.descriptioncCs | |d¡S)NT)r°)rr¦rrrÚ descriptions‡sz_NNTPBase.descriptionscCsš| d|¡}| d¡s t|ƒ‚| ¡}d}}}t|ƒ}|dkr€|d}|dkr€|d}|dkr€|d}|dkr€|d ¡}|t|ƒt|ƒt|ƒ|fS)NzGROUP rrr0rHrrI)r˜rBrr?r6r2r@)rr9r|ÚwordsÚcountr!r Únrrrr‹s    z_NNTPBase.groupcCs | d|¡S)NZHELP)r)rr_rrrÚhelp¥sz_NNTPBase.helpcCs8| d¡st|ƒ‚| ¡}t|dƒ}|d}|||fS)NZ22r0rH)rBrr?r@)rr|r³Úart_numr$rrrÚ _statparse¯s   z_NNTPBase._statparsecCs| |¡}| |¡S)N)r˜r¸)rr8r|rrrÚ_statcmd¹s z_NNTPBase._statcmdcCs"|r| d |¡¡S| d¡SdS)NzSTAT {0}ZSTAT)r¹rS)rÚ message_specrrrÚstat¾s z_NNTPBase.statcCs | d¡S)NZNEXT)r¹)rrrrÚnextÌsz_NNTPBase.nextcCs | d¡S)NZLAST)r¹)rrrrr Ðsz_NNTPBase.lastcCs0| ||¡\}}| |¡\}}}|t|||ƒfS)N)r™r¸r#)rr8r_r|rr·r$rrrÚ_artcmdÔsz_NNTPBase._artcmdcCs$|dk rd |¡}nd}| ||¡S)NzHEAD {0}ZHEAD)rSr½)rrºr_r£rrrÚheadÚs z_NNTPBase.headcCs$|dk rd |¡}nd}| ||¡S)NzBODY {0}ZBODY)rSr½)rrºr_r£rrrÚbodyès z_NNTPBase.bodycCs$|dk rd |¡}nd}| ||¡S)Nz ARTICLE {0}ZARTICLE)rSr½)rrºr_r£rrrÚarticleös z_NNTPBase.articlecCs | d¡S)NZSLAVE)r˜)rrrrÚslavesz_NNTPBase.slavecsDt d¡‰| d ||¡|¡\}}‡fdd„‰|‡fdd„|DƒfS)Nz^([0-9]+) ?(.*) ?z XHDR {0} {1}csˆ |¡}|r| dd¡S|S)Nr0rH)r¯r)r8Úm)ÚpatrrÚ remove_numbers z%_NNTPBase.xhdr..remove_numbercsg|] }ˆ|ƒ‘qSrr)ršr8)rÄrrr›sz"_NNTPBase.xhdr..)r¨r©rrS)rZhdrr’r_r|rr)rÃrÄrÚxhdr s  z_NNTPBase.xhdrcCs.| d ||¡|¡\}}| ¡}|t||ƒfS)Nz XOVER {0}-{1})rrSrŸrG)rÚstartÚendr_r|rr7rrrÚxovers  z_NNTPBase.xoverc Csxd|jkrdnd}t|ttfƒr>|\}}|d ||p6d¡7}n|dk rR|d|}| ||¡\}}| ¡}|t||ƒfS)NZOVERZXOVERz {0}-{1}r&rw)rcr(ÚtuplerœrSrrŸrG) rrºr_r£rÆrÇr|rr7rrrÚover(s z_NNTPBase.overc Csjt dtd¡t d¡}| d||¡\}}g}x0|D](}| | ¡¡}|r6| |  dd¡¡q6W||fS)NzFThe XGTITLE extension is not actively used, use descriptions() insteadrHz^([^ ]+)[ ]+(.*)$zXGTITLE r0) ÚwarningsÚwarnÚDeprecationWarningr¨r©rrªr«r)r) rrr_r¬r|Z raw_linesrr®r¯rrrÚxgtitleCs  z_NNTPBase.xgtitlecCslt dtd¡| d |¡¡}| d¡s0t|ƒ‚y| ¡\}}Wntk r^t|ƒd‚Yn X||fSdS)Nz(The XPATH extension is not actively usedrHz XPATH {0}Z223) rËrÌrÍr˜rSrBrr?Ú ValueError)rÚidr|Zresp_numÚpathrrrÚxpathUs z_NNTPBase.xpathcCsb| d¡}| d¡st|ƒ‚| ¡}t|ƒdkr8t|ƒ‚|d}t|ƒdkrTt|ƒ‚|t|dƒfS)NZDATEZ111rHr0é)r˜rBrr?r6r rR)rr|Úelemrrrrris    z_NNTPBase.datecCs”| |¡}| d¡st|ƒ‚t|ttfƒr2| ¡}xB|D]:}| t¡sT|  d¡t}| d¡rfd|}|j   |¡q8W|j   d¡|j   ¡|  ¡S)NÚ3s r‘s. )r˜rBrr(rÚ bytearrayÚ splitlinesÚendswithr€Úrstripr_rr‚ra)rr§Úfr|r8rrrÚ_postzs       z_NNTPBase._postcCs | d|¡S)NZPOST)rÛ)rÚdatarrrÚpostsz_NNTPBase.postcCs| d |¡|¡S)Nz IHAVE {0})rÛrS)rr$rÜrrrÚihave–sz_NNTPBase.ihavecCs|j ¡|`dS)N)r_r•)rrrrrrŸs z_NNTPBase._closecCsz| d¡}Wd| ¡X|S)NZQUIT)r˜rr)rr|rrrro£s z_NNTPBase.quitcCsö|jrtdƒ‚|s|stdƒ‚y<|rX|sXddl}| ¡}| |j¡}|rX|d}|d}Wntk rnYnX|sxdS| d|¡}| d¡r¾|sžt|ƒ‚n | d|¡}| d¡s¾t |ƒ‚d|_ |  ¡|j ròd |j krò|  ¡d|_ |  ¡dS) NzAlready logged in.z7At least one of `user` and `usenetrc` must be specifiedrrHzauthinfo user Z381zauthinfo pass Z281r])rhrÏÚnetrcZauthenticatorsr^rpr˜rBrrrcrdrerf)rÚuserÚpasswordÚusenetrcrßZ credentialsZauthr|rrrÚlogin¬s<     z_NNTPBase.loginc Cs`y| d¡|_WnJtk r$Yn8tk rZ}z|j d¡rHd|_n‚Wdd}~XYnXdS)Nz mode readerZ480T)r˜rbrrr rBre)rÚerrrrfÕs z_NNTPBase._setreadermodecCs||jrtdƒ‚|jrtdƒ‚| d¡}| d¡rp|j ¡t|j||j ƒ|_|j  d¡|_d|_d|_ |  ¡nt dƒ‚dS)NzTLS is already enabled.z+TLS cannot be started after authentication.ÚSTARTTLSZ382ÚrwbTzTLS failed to start.)rgrÏrhr˜rBr_r•rZrXr^Úmakefilercrdr)rrYr|rrrÚstarttlsãs    z_NNTPBase.starttls)T)N)N)N)N)N)N)N)N)N)NNT)N)9rrrr…r†rr rkrsrvrdrÚdebugrƒr‡r‹rar—r˜r™rrŸr ryr¤r¥rœr°r±r²rr¶r¸r¹r»r¼r r½r¾r¿rÀrÁrÅrÈrÊrÎrÒrrÛrÝrÞrrrorãrfÚ _have_sslrèrrrrr[(sj .    .         ) r[c@s*eZdZeddddefdd„Zdd„ZdS)rNFc Cs„||_||_t ||f|¡|_d}y8|j d¡}t |||||¡|sJ|rX| |||¡Wn$|rn|  ¡|j  ¡‚YnXdS)Nræ) r^ÚportÚsocketÚcreate_connectionrXrçr[r rãr•) rr^rëràrárirârjr_rrrr ýs   z NNTP.__init__cCs zt |¡Wd|j ¡XdS)N)r[rrrXr•)rrrrrr!sz NNTP._close)rrrÚ NNTP_PORTrr rrrrrrrûs "c@s,eZdZedddddefdd„Zdd„ZdS)ÚNNTP_SSLNFc CsŠt ||f|¡|_d} yJt|j||ƒ|_|j d¡} tj|| |||d|sP|r^| |||¡Wn$| rt|  ¡|j ¡‚YnXdS)Nræ)rirj) rìrírXrZrçr[r rãr•) rr^rëràráZ ssl_contextrirârjr_rrrr +s    zNNTP_SSL.__init__cCs zt |¡Wd|j ¡XdS)N)r[rrrXr•)rrrrrrAszNNTP_SSL._close)rrrÚ NNTP_SSL_PORTrr rrrrrrrï)s  rïÚ__main__zJ nntplib built-in demo - display the latest articles in a newsgroup)r±z-gz--groupzgmane.comp.python.generalz3group to fetch messages from (default: %(default)s))Údefaultr¶z-sz--serverz news.gmane.ioz+NNTP server hostname (default: %(default)s)z-pz--portrˆz#NNTP port number (default: %s / %s))ròÚtyper¶z-nz --nb-articlesé z2number of articles to fetch (default: %(default)s)z-Sz--sslÚ store_truezuse NNTP over SSL)Úactionròr¶)r^rëråZGroupZhaszarticles, rangeÚtocCs$t|ƒ|kr |d|d…d}|S)NrIz...)r6)ÚsZlimrrrÚcutls rùr0úBsÆ          X-