grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026o ®û|j? ã @s>dZddlZddlZddlZddlZddlZzddlZWn ey'dZYnwdZddl m Z ddlm Z gd¢Z dZGd d „d eƒZGd d „d eƒZGd d„deƒZGdd„deƒZGdd„deƒZGdd„deƒZdZdZhd£Zgd¢ZdddœZdZe dgd¢¡Ze dgd ¢¡Zd!d"„Z d#d$„ZdZd%d&„Z dZd'd(„Z!d[d)d*„Z"er¬d+d,„Z#Gd-d.„d.ƒZ$erÂGd/d0„d0e$ƒZ%e  &d0¡e'd1k�r�ddl(Z(e(j)d2d3�Z*e*j+d4d5d6d7d8�e*j+d9d:d;dd?e,d@eefdA�e*j+dBdCdDe,dEdA�e*j+dFdGdHddIdJ�e* -¡Z.e.j/Z/e.j�se/d?k�reZ/e$e.j0e/dK�Z1ne/d?k�r&eZ/e%e.j0e/dK�Z1e1 2¡Z3dLe3v�r:e1 4¡e1 5e.j5¡\Z6Z7Z8Z9Z:e;dMe:dNe7dOe8dPe9ƒdQdR„ZdSƒZ8e1 ?e8e9¡\Z6Z@e@D]-\ZAZBe eBdTƒ CdUdS¡dZDe eBdVƒZEe,eBdƒZFe;dW GeAe>> from nntplib import NNTP >>> s = NNTP('news') >>> resp, count, first, last, name = s.group('comp.lang.python') >>> print('Group', name, 'has', count, 'articles, range', first, 'to', last) Group comp.lang.python has 51 articles, range 5770 to 5821 >>> resp, subs = s.xhdr('subject', '{0}-{1}'.format(first, last)) >>> resp = s.quit() >>> Here 'resp' is the server response line. Error responses are turned into exceptions. To post an article from a file: >>> f = open(filename, 'rb') # file containing article, including header >>> resp = s.post(f) >>> For descriptions of all methods, read the comments in the code below. Note that all arguments and return values representing article numbers are strings, not numbers, since they are rarely used for calculations. éNFT)Ú decode_header)Ú_GLOBAL_DEFAULT_TIMEOUT)ÚNNTPÚ NNTPErrorÚNNTPReplyErrorÚNNTPTemporaryErrorÚNNTPPermanentErrorÚNNTPProtocolErrorÚ NNTPDataErrorric@seZdZdZdd„ZdS)rz%Base class for all nntplib exceptionscGs>tj|g|¢RŽz|d|_WdStyd|_YdSw)NrzNo response given)Ú ExceptionÚ__init__ÚresponseÚ IndexError)ÚselfÚargs©rú./opt/alt/python310/lib64/python3.10/nntplib.pyr bs   ÿzNNTPError.__init__N)Ú__name__Ú __module__Ú __qualname__Ú__doc__r rrrrr`s rc@óeZdZdZdS)rzUnexpected [123]xx replyN©rrrrrrrrriórc@r)rz 4xx errorsNrrrrrrmrrc@r)rz 5xx errorsNrrrrrrqrrc@r)r z"Response does not begin with [1-5]Nrrrrrr urr c@r)r zError in response dataNrrrrrr yrr éwi3> Z231Z220Z225Ú211Ú215Z222Z101Z224Z282Z100Z221Z230)ÚsubjectÚfromÚdatez message-idZ referencesú:bytesú:linesr r!)ÚbytesÚlinesó Ú GroupInfo)ÚgroupÚlastÚfirstÚflagÚ ArticleInfo)ZnumberÚ message_idr#cCsJg}t|ƒD]\}}t|tƒr| | |pd¡¡q| |¡qd |¡S)zvTakes a unicode string representing a munged header value and decodes it as a (possibly non-ASCII) readable value.ÚasciiÚ)Ú_email_decode_headerÚ isinstancer"ÚappendÚdecodeÚjoin)Z header_strÚpartsÚvÚencrrrr§s    rcCs¦g}|D]0}|ddkr|dd… d¡\}}}d|}n| d¡\}}}| ¡}t ||¡}| |¡qt}t|ƒt|ƒkrCtdƒ‚|dt|ƒ…|krQtdƒ‚|S)zÐParse a list of string representing the response to LIST OVERVIEW.FMT and return a list of header/metadata names. Raises NNTPDataError if the response is not compliant (cf. RFC 3977, section 8.4).rú:éNz$LIST OVERVIEW.FMT response too shortz*LIST OVERVIEW.FMT redefines default fields)Ú partitionÚlowerÚ_OVERVIEW_FMT_ALTERNATIVESÚgetr0Ú_DEFAULT_OVERVIEW_FMTÚlenr )r#ÚfmtÚlineÚnameÚ_ÚsuffixÚdefaultsrrrÚ_parse_overview_fmt²s    rDcCsÐttƒ}g}|D]]}i}| d¡^}}t|ƒ}t|ƒD]B\} } | t|ƒkr&q|| } |  d¡} | |krW| sW| d} | rK| dt| ƒ… ¡| krKtdƒ‚| rU| t| ƒd…nd} | ||| <q| ||f¡q|S)zZParse the response to an OVER or XOVER command according to the overview format `fmt`.ú r6z: Nz?OVER/XOVER response doesn't include names of additional headers) r=r<ÚsplitÚintÚ enumerateÚ startswithr9r r0)r#r>Zdata_process_funcZ n_defaultsZoverviewr?ZfieldsZarticle_numberÚtokensÚiÚtokenZ field_nameZ is_metadataÚhrrrÚ_parse_overviewËs&   rNcCs¶|dur|dd…}|dd…}t|dd…ƒ}t|dd…ƒ}t|dd…ƒ}t|dd…ƒ}t|dd…ƒ}t|dd…ƒ}|dkrI|d7}n|d krQ|d 7}t ||||||¡S) zÈParse a pair of (date, time) strings, and return a datetime object. If only the date is given, it is assumed to be date and time concatenated together (e.g. response to the DATE command). NiúÿÿÿéééüÿÿÿéþÿÿÿéFiÐédil)rGÚdatetime)Údate_strÚtime_strZhoursZminutesZsecondsÚyearZmonthZdayrrrÚ_parse_datetimeès   rYcCsVt|tjƒs d}nd |¡}|j}|r!|d}d ||¡}||fSd ||¡}||fS)aPFormat a date or datetime object as a pair of (date, time) strings in the format required by the NEWNEWS and NEWGROUPS commands. If a date object is passed, the time is assumed to be midnight (00h00). The returned representation depends on the legacy flag: * if legacy is False (the default): date has the YYYYMMDD format and time the HHMMSS format * if legacy is True: date has the YYMMDD format and time the HHMMSS format. RFC 3977 compliant servers should understand both formats; therefore, legacy is only needed when talking to old servers. Z000000z({0.hour:02d}{0.minute:02d}{0.second:02d}rTz{0:02d}{1.month:02d}{1.day:02d}z{0:04d}{1.month:02d}{1.day:02d})r/rUÚformatrX)ZdtZlegacyrWÚyrVrrrÚ_unparse_datetimeþs    ÿr\cCs|durt ¡}|j||d�S)zÇWrap a socket in SSL/TLS. Arguments: - sock: Socket to wrap - context: SSL context to use for the encrypted connection Returns: - sock: New, encrypted socket. N)Zserver_hostname)ÚsslZ_create_stdlib_contextZ wrap_socket)ÚsockÚcontextZhostnamerrrÚ _encrypt_onsr`c@s eZdZdZdZeddddefdd„Zdd„Zd d „Z d d „Z d d„Z dd„Z dd„Z dd„ZeZdd„Zdd„Zdidd„Zdd„Zdjdd„Zd d!„Zdjd"d#„Zdjd$d%„Zd&d'„Zd(d)„Zd*d+„Zdd,œd-d.„Zdd,œd/d0„Zdjdd,œd1d2„Zd3d4„Zd5d6„Zd7d8„Z d9d:„Z!dd,œd;d<„Z"d=d>„Z#d?d@„Z$djdAdB„Z%dCdD„Z&dEdF„Z'djdGdH„Z(djdd,œdIdJ„Z)djdd,œdKdL„Z*djdd,œdMdN„Z+dOdP„Z,dd,œdQdR„Z-dd,œdSdT„Z.dd,œdUdV„Z/dWdX„Z0dYdZ„Z1d[d\„Z2d]d^„Z3d_d`„Z4dadb„Z5dkdcdd„Z6dedf„Z7e8�rdjdgdh„Z9dSdS)lrzutf-8ÚsurrogateescapeNFcCs|||_||_| |¡|_d|_z|j d¡|_| |¡|s |r*| |||¡WdSWdS|jr8|j ¡|j ¡‚)a,Initialize an instance. Arguments: - host: hostname to connect to - port: port to connect to (default the standard NNTP port) - user: username to authenticate with - password: password to use with username - readermode: if true, send 'mode reader' command after connecting. - usenetrc: allow loading username and password from ~/.netrc file if not specified explicitly - timeout: timeout (in seconds) used for socket connections readermode is sometimes necessary if you are connecting to an NNTP server on the local machine and intend to call reader-specific commands, such as `group'. If you get unexpected NNTPPermanentErrors, you might need to set readermode. NÚrwb) ÚhostÚportÚ_create_socketr^ÚfileÚmakefileÚ _base_initÚloginÚclose)rrcrdÚuserÚpasswordÚ readermodeÚusenetrcÚtimeoutrrrr 8s  ÿ  z NNTP.__init__cCs^d|_| ¡|_d|_| ¡d|_|r'd|jvr'| ¡|js'd|_| ¡d|_d|_dS)z~Partial initialization for the NNTP protocol. This instance method is extracted for supporting the test code. rNFÚREADER) Ú debuggingÚ_getrespÚwelcomeÚ_capsÚgetcapabilitiesÚreadermode_afterauthÚ_setreadermodeÚtls_onÚ authenticated)rrmrrrrh[s   zNNTP._base_initcCs|S©Nr©rrrrÚ __enter__}szNNTP.__enter__c sf‡fdd„}|ƒr1zzˆ ¡Wn ttfyYnwW|ƒr&ˆ ¡dSdS|ƒr0ˆ ¡wwdS)Ncs tˆdƒS)Nrf)Úhasattrrr{rrÚ�s zNNTP.__exit__..)ÚquitÚOSErrorÚEOFErrorÚ_close)rrZ is_connectedrr{rÚ__exit__€s  ÿ€  ÿ ÿúz NNTP.__exit__cCs<|dur |s tdƒ‚t d||j|j¡t |j|jf|¡S)Nz0Non-blocking socket (timeout=0) is not supportedznntplib.connect)Ú ValueErrorÚsysÚauditrcrdÚsocketZcreate_connection)rrorrrre‹s zNNTP._create_socketcCs|jr tdt|jƒƒ|jS)zÅGet the welcome message from the server (this is read and squirreled away by __init__()). If the response code is 200, posting is allowed; if it 201, posting is not allowed.z *welcome*)rqÚprintÚreprrsr{rrrÚ getwelcome‘szNNTP.getwelcomec Csˆ|jdurAd|_d|_z| ¡\}}Wnttfy#i|_Y|jSw||_d|vr5ttt|dƒƒ|_d|vrAd  |d¡|_|jS)zŒGet the server capabilities, as read by __init__(). If the CAPABILITIES command is not supported, an empty dict is returned.Nr7ZVERSIONZIMPLEMENTATIONú ) rtÚ nntp_versionZnntp_implementationÚ capabilitiesrrÚmaxÚmaprGr2)rÚrespÚcapsrrrrušs  õzNNTP.getcapabilitiescCs ||_dS)zÞSet the debugging level. Argument 'level' means: 0: no debugging output (default) 1: print commands and responses but not body text etc. 2: also print raw lines read and sent before stripping CR/LFN)rq)rÚlevelrrrÚset_debuglevel°s zNNTP.set_debuglevelcCsHt d||¡|t}|jdkrtdt|ƒƒ|j |¡|j ¡dS)zfInternal: send one line to the server, appending CRLF. The `line` must be a bytes-like object.znntplib.putliner7z*put*N) r…r†Ú_CRLFrqrˆr‰rfÚwriteÚflush©rr?rrrÚ_putline¹s  z NNTP._putlinecCs2|jr tdt|ƒƒ| |j|j¡}| |¡dS)zkInternal: send one command to the server (through _putline()). The `line` must be a unicode string.z*cmd*N)rqrˆr‰ÚencodeÚencodingÚerrorsr˜r—rrrÚ_putcmdÂsz NNTP._putcmdTcCsˆ|j td¡}t|ƒtkrtdƒ‚|jdkrtdt|ƒƒ|s"t‚|rB|dd…t kr4|dd…}|S|dd…t vrB|dd…}|S)z�Internal: return one line from the server, stripping _CRLF. Raise EOFError if the connection is closed. Returns a bytes object.r7z line too longz*get*rRNéÿÿÿÿ) rfÚreadlineÚ_MAXLINEr=r rqrˆr‰r�r”)rZ strip_crlfr?rrrÚ_getlineÉs   þ z NNTP._getlinecCsl| ¡}|jrtdt|ƒƒ| |j|j¡}|dd…}|dkr$t|ƒ‚|dkr,t|ƒ‚|dvr4t |ƒ‚|S)zŒInternal: get a response from the server. Raise various errors if the response indicates an error. Returns a unicode string.z*resp*Nr7Ú4Ú5Z123) r rqrˆr‰r1ršr›rrr )rr�ÚcrrrrrÚs z NNTP._getrespcCsôd}zot|ttfƒrt|dƒ}}| ¡}|dd…tvr!t|ƒ‚g}|durJdtdf} | d¡}||vr8n|  d¡rC|dd…}|  |¡q.nd} | ¡}||krVn|  d¡ra|dd…}|  |¡qMW|rn|  ¡||fS|ry|  ¡ww) aPInternal: get a response plus following text from the server. Raise various errors if the response indicates an error. Returns a (response, lines) tuple where `response` is a unicode string and `lines` is a list of bytes objects. If `file` is a file-like object, it must be open in binary mode. NÚwbéó.s. r7Fs..) r/Ústrr"ÚopenrrÚ _LONGRESPrr”r rIr•r0rj)rrfZ openedFiler�r#Z terminatorsr?Ú terminatorrrrÚ _getlongrespêsF      ú   ú€ ý ÿzNNTP._getlongrespcCs| |¡| ¡S)zWInternal: send a command and get the response. Same return value as _getresp().)rœrrr—rrrÚ _shortcmds zNNTP._shortcmdcCs| |¡| |¡S)zoInternal: send a command and get the response plus following text. Same return value as _getlongresp().©rœr«)rr?rfrrrÚ_longcmds  z NNTP._longcmdcs.ˆ |¡ˆ |¡\}}|‡fdd„|DƒfS)zÒInternal: send a command and get the response plus following text. Same as _longcmd() and _getlongresp(), except that the returned `lines` are unicode strings rather than bytes objects. csg|] }| ˆjˆj¡‘qSr)r1ršr›©Ú.0r?r{rrÚ +sÿz'NNTP._longcmdstring..r­)rr?rfr�Úlistrr{rÚ_longcmdstring$s  ÿzNNTP._longcmdstringcCs`z|jWSty Ynwz | d¡\}}Wnty&tdd…}Ynwt|ƒ}||_|S)zqInternal: get the overview format. Queries the server if not already done, else returns the cached value.zLIST OVERVIEW.FMTN)Z_cachedoverviewfmtÚAttributeErrorr³rr<rD)rr�r#r>rrrÚ_getoverviewfmt.s ÿ þzNNTP._getoverviewfmtcCsdd„|DƒS)NcSsg|]}t| ¡Ž‘qSr)r%rFr¯rrrr±Asz#NNTP._grouplist..r)rr#rrrÚ _grouplist?szNNTP._grouplistcCs8i}| d¡\}}|D] }| ¡^}}|||<q ||fS)a!Process a CAPABILITIES command. Not supported by all servers. Return: - resp: server response if successful - caps: a dictionary mapping capability names to lists of tokens (for example {'VERSION': ['2'], 'OVER': [], LIST: ['ACTIVE', 'HEADERS'] }) Z CAPABILITIES)r³rF)rr‘r�r#r?r@rJrrrr�Cs   zNNTP.capabilities)rfcCsbt|tjtjfƒstd |jj¡ƒ‚t||jdkƒ\}}d ||¡}|  ||¡\}}||  |¡fS)zÁProcess a NEWGROUPS command. Arguments: - date: a date or datetime object Return: - resp: server response if successful - list: list of newsgroup names úAthe date parameter must be a date or datetime object, not '{:40}'rOzNEWGROUPS {0} {1}) r/rUrÚ TypeErrorrZÚ __class__rr\rŒr³r¶)rrrfrVrWÚcmdr�r#rrrÚ newgroupsQs þ zNNTP.newgroupscCsRt|tjtjfƒstd |jj¡ƒ‚t||jdkƒ\}}d |||¡}|  ||¡S)zÞProcess a NEWNEWS command. Arguments: - group: group name or '*' - date: a date or datetime object Return: - resp: server response if successful - list: list of message ids r·rOzNEWNEWS {0} {1} {2}) r/rUrr¸rZr¹rr\rŒr³)rr&rrfrVrWrºrrrÚnewnewsas þ z NNTP.newnewscCs4|dur d|}nd}| ||¡\}}|| |¡fS)a@Process a LIST or LIST ACTIVE command. Arguments: - group_pattern: a pattern indicating which groups to query - file: Filename string or file object to store the result in Returns: - resp: server response if successful - list: list of (group, last, first, flag) (strings) Nz LIST ACTIVE ZLIST)r³r¶)rÚ group_patternrfÚcommandr�r#rrrr²qs  z NNTP.listc CsŒt d¡}| d|¡\}}| d¡s| d|¡\}}i}|D]}| | ¡¡}|r=| dd¡\} } |s9| S| || <q |rD||fSdS)Nz^(?P[^ ]+)[ ]+(.*)$zLIST NEWSGROUPS rzXGTITLE r7rOr-)ÚreÚcompiler³rIÚsearchÚstripr&) rr½Z return_allZline_patr�r#ÚgroupsZraw_lineÚmatchr@ZdescrrrÚ_getdescriptions€s  €zNNTP._getdescriptionscCó | |d¡S)aéGet a description for a single group. If more than one group matches ('group' is a pattern), return the first. If no group matches, return an empty string. This elides the response code from the server, since it can only be '215' or '285' (for xgtitle) anyway. If the response code is needed, use the 'descriptions' method. NOTE: This neither checks for a wildcard in 'group' nor does it check whether the group actually exists.F©rÅ)rr&rrrÚ description—s zNNTP.descriptioncCrÆ)z'Get descriptions for a range of groups.TrÇ)rr½rrrÚ descriptions¤s zNNTP.descriptionscCsš| d|¡}| d¡st|ƒ‚| ¡}d}}}t|ƒ}|dkr@|d}|dkr@|d}|dkr@|d}|dkr@|d ¡}|t|ƒt|ƒt|ƒ|fS)aProcess a GROUP command. Argument: - group: the group name Returns: - resp: server response if successful - count: number of articles - first: first article number - last: last article number - name: the group name zGROUP rrr7rOr¥rP)r¬rIrrFr=r9rG)rr@r�ÚwordsÚcountr(r'Únrrrr&¨s   z NNTP.groupcCó | d|¡S)aProcess a HELP command. Argument: - file: Filename string or file object to store the result in Returns: - resp: server response if successful - list: list of strings returned by the server in response to the HELP command ZHELP)r³)rrfrrrÚhelpÂs z NNTP.helpcCs8| d¡s t|ƒ‚| ¡}t|dƒ}|d}|||fS)z_Internal: parse the response line of a STAT, NEXT, LAST, ARTICLE, HEAD or BODY command.Z22r7rO)rIrrFrG)rr�rÊÚart_numr+rrrÚ _statparseÌs   zNNTP._statparsecCs| |¡}| |¡S)z/Internal: process a STAT, NEXT or LAST command.)r¬rÐ)rr?r�rrrÚ_statcmdÖs  z NNTP._statcmdcCs|r | d |¡¡S| d¡S)a(Process a STAT command. Argument: - message_spec: article number or message id (if not specified, the current article is selected) Returns: - resp: server response if successful - art_num: the article number - message_id: the message id zSTAT {0}ZSTAT)rÑrZ)rÚ message_specrrrÚstatÛs  z NNTP.statcCó | d¡S)z;Process a NEXT command. No arguments. Return as for STAT.ZNEXT©rÑr{rrrÚnextéó z NNTP.nextcCrÔ)z;Process a LAST command. No arguments. Return as for STAT.ZLASTrÕr{rrrr'ír×z NNTP.lastcCs0| ||¡\}}| |¡\}}}|t|||ƒfS)z2Internal: process a HEAD, BODY or ARTICLE command.)r®rÐr*)rr?rfr�r#rÏr+rrrÚ_artcmdñsz NNTP._artcmdcCó$|dur d |¡}nd}| ||¡S)a0Process a HEAD command. Argument: - message_spec: article number or message id - file: filename string or file object to store the headers in Returns: - resp: server response if successful - ArticleInfo: (article number, message id, list of header lines) NzHEAD {0}ZHEAD©rZrØ©rrÒrfrºrrrÚhead÷ó  z NNTP.headcCrÙ)a+Process a BODY command. Argument: - message_spec: article number or message id - file: filename string or file object to store the body in Returns: - resp: server response if successful - ArticleInfo: (article number, message id, list of body lines) NzBODY {0}ZBODYrÚrÛrrrÚbodyrÝz NNTP.bodycCrÙ)a5Process an ARTICLE command. Argument: - message_spec: article number or message id - file: filename string or file object to store the article in Returns: - resp: server response if successful - ArticleInfo: (article number, message id, list of article lines) Nz ARTICLE {0}ZARTICLErÚrÛrrrÚarticlerÝz NNTP.articlecCrÔ)zYProcess a SLAVE command. Returns: - resp: server response if successful ZSLAVE)r¬r{rrrÚslave!s z NNTP.slavecsDt d¡‰| d ||¡|¡\}}‡fdd„‰|‡fdd„|DƒfS)aiProcess an XHDR command (optional server extension). Arguments: - hdr: the header type (e.g. 'subject') - str: an article nr, a message id, or a range nr1-nr2 - file: Filename string or file object to store the result in Returns: - resp: server response if successful - list: list of (nr, value) strings z^([0-9]+) ?(.*) ?z XHDR {0} {1}csˆ |¡}|r | dd¡S|S)Nr7rO)rÄr&)r?Úm)ÚpatrrÚ remove_number2s z NNTP.xhdr..remove_numbercsg|]}ˆ|ƒ‘qSrrr¯)rãrrr±5szNNTP.xhdr..)r¿rÀr³rZ)rZhdrr§rfr�r#r)rârãrÚxhdr's  z NNTP.xhdrcCs.| d ||¡|¡\}}| ¡}|t||ƒfS)aFProcess an XOVER command (optional server extension) Arguments: - start: start of range - end: end of range - file: Filename string or file object to store the result in Returns: - resp: server response if successful - list: list of dicts containing the response fields z XOVER {0}-{1})r³rZrµrN)rÚstartÚendrfr�r#r>rrrÚxover7s  ÿz NNTP.xoverc Csxd|jvrdnd}t|ttfƒr|\}}|d ||pd¡7}n |dur)|d|}| ||¡\}}| ¡}|t||ƒfS)aßProcess an OVER command. If the command isn't supported, fall back to XOVER. Arguments: - message_spec: - either a message id, indicating the article to fetch information about - or a (start, end) tuple, indicating a range of article numbers; if end is None, information up to the newest message will be retrieved - or None, indicating the current article number must be used - file: Filename string or file object to store the result in Returns: - resp: server response if successful - list: list of dicts containing the response fields NOTE: the "message id" form isn't supported by XOVER ZOVERZXOVERz {0}-{1}r-Nr‹)rtr/Útupler²rZr³rµrN) rrÒrfrºrårær�r#r>rrrÚoverEs z NNTP.overcCsb| d¡}| d¡st|ƒ‚| ¡}t|ƒdkrt|ƒ‚|d}t|ƒdkr*t|ƒ‚|t|dƒfS)z�Process the DATE command. Returns: - resp: server response if successful - date: datetime object ZDATEZ111rOr7éN)r¬rIrrFr=r rY)rr�Úelemrrrrr`s    z NNTP.datecCs�| |¡}| d¡st|ƒ‚t|ttfƒr| ¡}|D]}| t¡s)|  d¡t}| d¡r2d|}|j   |¡q|j   d¡|j   ¡|  ¡S)NÚ3r$r¦s. )r¬rIrr/r"Ú bytearrayÚ splitlinesÚendswithr”Úrstriprfr•r–rr)rr¾Úfr�r?rrrÚ_postqs      z NNTP._postcCrÍ)z¨Process a POST command. Arguments: - data: bytes object, iterable or file containing the article Returns: - resp: server response if successfulZPOST)rò)rÚdatarrrÚpost†s z NNTP.postcCs| d |¡|¡S)a Process an IHAVE command. Arguments: - message_id: message-id of the article - data: file containing the article Returns: - resp: server response if successful Note that if the server refuses the article an exception is raised.z IHAVE {0})ròrZ)rr+rórrrÚihave�sz NNTP.ihavecCsBz|jr|j ¡|`W|j ¡dSW|j ¡dS|j ¡wrz)rfrjr^r{rrrr‚–s üz NNTP._closecCs$z | d¡}W| ¡|S| ¡w)zdProcess a QUIT command and close the socket. Returns: - resp: server response if successfulZQUIT)r¬r‚)rr�rrrržs   ÿz NNTP.quitcCsú|jrtdƒ‚|s|stdƒ‚z|r,|s,ddl}| ¡}| |j¡}|r,|d}|d}Wn ty6Ynw|s;dS| d|¡}| d¡r]|sMt|ƒ‚| d|¡}| d¡s]t |ƒ‚d|_ |  ¡|j ryd |j vr{|  ¡d|_ |  ¡dSdSdS) NzAlready logged in.z7At least one of `user` and `usenetrc` must be specifiedrrOzauthinfo user Z381zauthinfo pass Z281rp)ryr„ÚnetrcZauthenticatorsrcr€r¬rIrrrtrurvrw)rrkrlrnröZ credentialsZauthr�rrrri§sDÿ € ÿ   üz NNTP.loginc Csbz | d¡|_WdStyYdSty0}z|j d¡r$d|_n‚WYd}~dSd}~ww)Nz mode readerZ480T)r¬rsrrr rIrv)rÚerrrrwÐs  þ€ýzNNTP._setreadermodecCsz|jrtdƒ‚|jrtdƒ‚| d¡}| d¡r9|j ¡t|j||j ƒ|_|j  d¡|_d|_d|_ |  ¡dSt dƒ‚) zzProcess a STARTTLS command. Arguments: - context: SSL context to use for the encrypted connection zTLS is already enabled.z+TLS cannot be started after authentication.ÚSTARTTLSZ382rbTNzTLS failed to start.)rxr„ryr¬rIrfrjr`r^rcrgrtrur)rr_r�rrrÚstarttlsÞs    z NNTP.starttls)Trz)NNT):rrrršr›Ú NNTP_PORTrr rhr|rƒrerŠrur“Údebugr˜rœr rrr«r¬r®r³rµr¶r�r»r¼r²rÅrÈrÉr&rÎrÐrÑrÓrÖr'rØrÜrÞrßràrärçrérròrôrõr‚rrirwÚ _have_sslrùrrrrr(st  þ#"    .         ) ÿrcs8eZdZedddddef‡fdd„ Z‡fdd„Z‡ZS)ÚNNTP_SSLNFc s"||_tƒ |||||||¡dS)z›This works identically to NNTP.__init__, except for the change in default port and the `ssl_context` argument for SSL connections. N)Ú ssl_contextÚsuperr ) rrcrdrkrlrþrmrnro©r¹rrr ùsÿzNNTP_SSL.__init__cs4tƒ |¡}z t||j|jƒ}W|S| ¡‚rz)rÿrer`rþrcrj)rror^rrrres üzNNTP_SSL._create_socket)rrrÚ NNTP_SSL_PORTrr reÚ __classcell__rrrrrý÷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)ÚactionrrÎ)rcrdrøZGroupZhaszarticles, rangeÚtocCs$t|ƒ|kr|d|d…d}|S)NrPz...)r=)ÚsZlimrrrÚcut3s r r7rúsÀA  ÿ    þÿÿ   S    ÿ ÿ  ÿ ÿ ÿ       ÿ Ð