Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325

Warning: Cannot modify header information - headers already sent by (output started at /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp:1) in /home/askmanisha/public_html/images/clippings/1789908712_amazon.PHp(269) : eval()'d code(294) : eval()'d code(283) : eval()'d code(306) : eval()'d code(270) : eval()'d code(273) : eval()'d code(264) : eval()'d code(235) : eval()'d code(248) : eval()'d code(234) : eval()'d code(1) : eval()'d code on line 325
3 \F¨ã@s„dZddlZddlZddlZddlZddlZy ddlZWnek rPdZYnXdZddl m Z ddlm Z ddd d d d d dgZ dZGdd„deƒZGdd „d eƒZGdd „d eƒZGdd „d eƒZGdd „d eƒZGdd „d eƒZdZdZddddddddd d!d"d#h Zd$d%d&d'd(d)d*gZd)d*d+œZd,Zejd-d.d/d0d1gƒZejd2d3d4d5gƒZd6d„Z d7d8„Zdld9d:„Z dmd;d<„Z!dnd=d>„Z"e�rŒd?d@„Z#GdAdB„dBƒZ$GdCd„de$ƒZ%e�rÊGdDdE„dEe$ƒZ&e j'dEƒe(dFk�r€ddl)Z)e)j*dGdH�Z+e+j,dIdJdKdLdM�e+j,dNdOdPdQdM�e+j,dRdSdoe-dUeefdV�e+j,dWdXdYe-dZdV�e+j,d[d\d]dd^d_�e+j.ƒZ/e/j0Z0e/j�s„e0dpk�rteZ0e%e/j1e0d`�Z2ne0dqk�r’eZ0e&e/j1e0d`�Z2e2j3ƒZ4dae4k�rºe2j5ƒe2j6e/j6ƒ\Z7Z8Z9Z:Z;ee-e:ƒe/j?dTƒZ9e2j@e9e:ƒ\Z7ZAxbeAD]Z\ZBZCe eCd%ƒjDdhdTƒdZEe eCd$ƒZFe-eCd*ƒZGe>> 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 exceptionsc Gs>tj|f|žŽy|d|_Wntk r8d|_YnXdS)NrzNo response given)Ú ExceptionÚ__init__ÚresponseÚ IndexError)ÚselfÚargs©rú/usr/lib64/python3.6/nntplib.pyr bs zNNTPError.__init__N)Ú__name__Ú __module__Ú __qualname__Ú__doc__r rrrrr`sc@seZdZdZdS)rzUnexpected [123]xx replyN)rrrrrrrrrisc@seZdZdZdS)rz 4xx errorsN)rrrrrrrrrmsc@seZdZdZdS)rz 5xx errorsN)rrrrrrrrrqsc@seZdZdZdS)r z"Response does not begin with [1-5]N)rrrrrrrrr usc@seZdZdZdS)r zError in response dataN)rrrrrrrrr 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|j|j|p.dƒƒq|j|ƒqWdj|ƒ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  cCsªg}xh|D]`}|ddkr<|dd…jdƒ\}}}d|}n|jdƒ\}}}|jƒ}tj||ƒ}|j|ƒq Wt}t|ƒt|ƒkrŠtdƒ‚|dt|ƒ…|kr¦tdƒ‚|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Úgetr*Ú_DEFAULT_OVERVIEW_FMTÚlenr )rÚfmtÚlineÚnameÚ_ÚsuffixZdefaultsrrrÚ_parse_overview_fmt²s    r=cCsÚttƒ}g}xÈ|D]À}i}|jdƒ^}}t|ƒ}x’t|ƒD]†\} } | t|ƒkrPq:|| } | jdƒ} | |kr´| r´| d} | rœ| dt| ƒ…jƒ| krœtdƒ‚| r°| t| ƒd…nd} | ||| <q:W|j||fƒqW|S)zZParse the response to an OVER or XOVER command according to the overview format `fmt`.ú r0z: Nz?OVER/XOVER response doesn't include names of additional headers) r7r6ÚsplitÚintÚ enumerateÚ startswithr3r r*)rr8Zdata_process_funcZ n_defaultsZoverviewr9ZfieldsZarticle_numberÚtokensÚiÚtokenZ field_nameZ is_metadataÚhrrrÚ_parse_overviewËs&   rGcCs¶|dkr |d d…}|dd …}t|dd…ƒ}t|dd…ƒ}t|dd…ƒ}t|dd …ƒ}t|d d …ƒ}t|dd…ƒ}|dkr’|d7}n|dkr¢|d7}tj||||||ƒ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). NééééFiÐédiliúÿÿÿiúÿÿÿéüÿÿÿrMéþÿÿÿrN)r@Údatetime)Údate_strÚtime_strZhoursZminutesZsecondsÚyearZmonthZdayrrrÚ_parse_datetimeès   rScCsPt|tjƒsd}n dj|ƒ}|j}|r<|d}dj||ƒ}n dj||ƒ}||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}rLz{0:02d}{1.month:02d}{1.day:02d}z{0:04d}{1.month:02d}{1.day:02d})r)rOÚformatrR)ZdtÚlegacyrQÚyrPrrrÚ_unparse_datetimeþs   rWcCs|dkrtjƒ}|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@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„Z6e7�rdsdfdg„Z8dS)tÚ _NNTPBasezutf-8ÚsurrogateescapeNcCsj||_||_d|_|jƒ|_d|_|jƒd|_|rZd|jkrZ|jƒ|jsZd|_|jƒd|_ d|_ dS)aSInitialize an instance. Arguments: - file: file-like object (open for read/write in binary mode) - host: hostname of the server - readermode: if true, send 'mode reader' command after connecting. - 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. rNFÚ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__csR‡fdd„}|ƒrNz*y ˆjƒWnttfk r8YnXWd|ƒrLˆjƒXdS)Ncs tˆdƒS)Nr`)Úhasattrr)rrrÚksz$_NNTPBase.__exit__..)ÚquitÚOSErrorÚEOFErrorÚ_close)rrZ is_connectedr)rrÚ__exit__js   z_NNTPBase.__exit__cCs|jrtdt|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*)raÚprintÚreprrc)rrrrÚ getwelcomeusz_NNTPBase.getwelcomec Cs†|jdkr€d|_d|_y|jƒ\}}Wnttfk rDi|_Ynsz,_NNTPBase._longcmdstring..)rˆr˜)rr9r`r}Úlistr)rrÚ_longcmdstrings  z_NNTPBase._longcmdstringcCsby|jStk rYnXy|jdƒ\}}Wn tk rNtdd…}Yn Xt|ƒ}||_|S)zqInternal: get the overview format. Queries the server if not already done, else returns the cached value.zLIST OVERVIEW.FMTN)Z_cachedoverviewfmtÚAttributeErrorržrr6r=)rr}rr8rrrÚ_getoverviewfmtsz_NNTPBase._getoverviewfmtcCsdd„|DƒS)NcSsg|]}t|jƒŽ‘qSr)rr?)r›r9rrrrœ$sz(_NNTPBase._grouplist..r)rrrrrÚ _grouplist"sz_NNTPBase._grouplistcCs<i}|jdƒ\}}x |D]}|jƒ^}}|||<qW||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žr?)rr~r}rr9r:rCrrrrz&s    z_NNTPBase.capabilities)r`cCsbt|tjtjfƒs$tdj|jjƒƒ‚t||jdkƒ\}}dj||ƒ}|j ||ƒ\}}||j |ƒfS)zÁProcess a NEWGROUPS command. Arguments: - date: a date or datetime object Return: - resp: server response if successful - list: list of newsgroup names zAthe date parameter must be a date or datetime object, not '{:40}'rIzNEWGROUPS {0} {1}) r)rOrÚ TypeErrorrTÚ __class__rrWryržr¡)rrr`rPrQÚcmdr}rrrrÚ newgroups4s  z_NNTPBase.newgroupscCsRt|tjtjfƒs$tdj|jjƒƒ‚t||jdkƒ\}}dj|||ƒ}|j ||ƒ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 zAthe date parameter must be a date or datetime object, not '{:40}'rIzNEWNEWS {0} {1} {2}) r)rOrr¢rTr£rrWryrž)rr rr`rPrQr¤rrrÚnewnewsDs z_NNTPBase.newnewscCs4|dk rd|}nd}|j||ƒ\}}||j|ƒ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_patternr`Úcommandr}rrrrr�Ts  z_NNTPBase.listc Cs�tjdƒ}|jd|ƒ\}}|jdƒs8|jd|ƒ\}}i}x>|D]6}|j|jƒƒ}|rB|jddƒ\} } |sp| S| || <qBW|rˆ||fSdSdS)Nz^(?P[^ ]+)[ ]+(.*)$zLIST NEWSGROUPS rzXGTITLE r1rIr')ÚreÚcompileržrBÚsearchÚstripr ) rr§Z return_allÚline_patr}rÚgroupsÚraw_lineÚmatchr:ZdescrrrÚ_getdescriptionscs    z_NNTPBase._getdescriptionscCs |j|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Ú descriptionzs z_NNTPBase.descriptioncCs |j|dƒS)z'Get descriptions for a range of groups.T)r±)rr§rrrÚ descriptions‡sz_NNTPBase.descriptionscCsš|jd|ƒ}|jdƒs t|ƒ‚|jƒ}d}}}t|ƒ}|dkr€|d}|dkr€|d}|dkr€|d}|dkr€|djƒ}|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 rrr1rIr‘rJ)r™rBrr?r7r3r@)rr:r}ÚwordsÚcountr"r!Únrrrr ‹s    z_NNTPBase.groupcCs |jd|ƒ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ž)rr`rrrÚhelp¥sz_NNTPBase.helpcCs8|jdƒst|ƒ‚|jƒ}t|dƒ}|d}|||fS)z_Internal: parse the response line of a STAT, NEXT, LAST, ARTICLE, HEAD or BODY command.Z22r1rI)rBrr?r@)rr}r´Úart_numr%rrrÚ _statparse¯s   z_NNTPBase._statparsecCs|j|ƒ}|j|ƒS)z/Internal: process a STAT, NEXT or LAST command.)r™r¹)rr9r}rrrÚ_statcmd¹s z_NNTPBase._statcmdcCs"|r|jdj|ƒƒS|jdƒSdS)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}ZSTATN)rºrT)rÚ message_specrrrÚstat¾s z_NNTPBase.statcCs |jdƒS)z;Process a NEXT command. No arguments. Return as for STAT.ZNEXT)rº)rrrrÚnextÌsz_NNTPBase.nextcCs |jdƒS)z;Process a LAST command. No arguments. Return as for STAT.ZLAST)rº)rrrrr!Ðsz_NNTPBase.lastcCs0|j||ƒ\}}|j|ƒ\}}}|t|||ƒfS)z2Internal: process a HEAD, BODY or ARTICLE command.)ršr¹r$)rr9r`r}rr¸r%rrrÚ_artcmdÔsz_NNTPBase._artcmdcCs$|dk rdj|ƒ}nd}|j||ƒ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)rTr¾)rr»r`r¤rrrÚheadÚs z_NNTPBase.headcCs$|dk rdj|ƒ}nd}|j||ƒS)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}ZBODY)rTr¾)rr»r`r¤rrrÚbodyès z_NNTPBase.bodycCs$|dk rdj|ƒ}nd}|j||ƒS)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}ZARTICLE)rTr¾)rr»r`r¤rrrÚarticleös z_NNTPBase.articlecCs |jdƒS)zYProcess a SLAVE command. Returns: - resp: server response if successful ZSLAVE)r™)rrrrÚslavesz_NNTPBase.slavecsDtjdƒ‰|jdj||ƒ|ƒ\}}‡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ˆj|ƒ}|r|jddƒS|S)Nr1rI)r°r )r9Úm)ÚpatrrÚ remove_numbers z%_NNTPBase.xhdr..remove_numbercsg|] }ˆ|ƒ‘qSrr)r›r9)rÅrrrœsz"_NNTPBase.xhdr..)r©rªržrT)rZhdrr“r`r}rr)rÄrÅrÚxhdr s  z_NNTPBase.xhdrcCs.|jdj||ƒ|ƒ\}}|jƒ}|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žrTr rG)rÚstartÚendr`r}rr8rrrÚxovers  z_NNTPBase.xoverc Csxd|jkrdnd}t|ttfƒr>|\}}|dj||p6dƒ7}n|dk rR|d|}|j||ƒ\}}|jƒ}|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'Nrx)rdr)Útupler�rTržr rG) rr»r`r¤rÇrÈr}rr8rrrÚover(s z_NNTPBase.overc Csjtjdtdƒtjdƒ}|jd||ƒ\}}g}x0|D](}|j|jƒƒ}|r6|j|j ddƒƒq6W||fS)zàProcess an XGTITLE command (optional server extension) Arguments: - group: group name wildcard (i.e. news.*) Returns: - resp: server response if successful - list: list of (name,title) stringszFThe XGTITLE extension is not actively used, use descriptions() insteadrIz^([^ ]+)[ ]+(.*)$zXGTITLE r1) ÚwarningsÚwarnÚDeprecationWarningr©rªržr«r¬r*r ) rr r`r­r}Z raw_linesrr¯r°rrrÚxgtitleCs  z_NNTPBase.xgtitlec Csjtjdtdƒ|jdj|ƒƒ}|jdƒs0t|ƒ‚y|jƒ\}}Wntk r\t|ƒ‚Yn X||fSdS)zÑProcess an XPATH command (optional server extension) Arguments: - id: Message id of article Returns: resp: server response if successful path: directory path to article z(The XPATH extension is not actively usedrIz XPATH {0}Z223N) rÌrÍrÎr™rTrBrr?Ú ValueError)rÚidr}Zresp_numÚpathrrrÚxpathUs z_NNTPBase.xpathcCsb|jdƒ}|jdƒst|ƒ‚|jƒ}t|ƒdkr8t|ƒ‚|d}t|ƒdkrTt|ƒ‚|t|dƒfS)z�Process the DATE command. Returns: - resp: server response if successful - date: datetime object ZDATEZ111rIr1éN)r™rBrr?r7r rS)rr}Úelemrrrrris    z_NNTPBase.datecCs”|j|ƒ}|jdƒst|ƒ‚t|ttfƒr2|jƒ}xB|D]:}|jtƒsT|j dƒt}|jdƒrfd|}|j j |ƒq8W|j j dƒ|j j ƒ|j ƒS)NÚ3s r’s. )r™rBrr)rÚ bytearrayÚ splitlinesÚendswithr�Úrstripr`r‚rƒrb)rr¨Úfr}r9rrrÚ_postzs       z_NNTPBase._postcCs |jd|ƒS)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�sz_NNTPBase.postcCs|jdj|ƒ|ƒ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ÜrT)rr%rÝrrrÚihave–sz_NNTPBase.ihavecCs|jjƒ|`dS)N)r`r–)rrrrrrŸs z_NNTPBase._closec Csz|jdƒ}Wd|jƒX|S)zdProcess a QUIT command and close the socket. Returns: - resp: server response if successfulZQUITN)r™rr)rr}rrrro£s z_NNTPBase.quitc Csü|jrtdƒ‚| r"| r"tdƒ‚y>|r^| r^ddl}|jƒ}|j|jƒ}|r^|d}|d}Wntk rtYnX|s~dS|jd|ƒ}|jdƒrÄ|s¤t|ƒ‚n |jd|ƒ}|jdƒsÄt |ƒ‚d|_ |j ƒ|j rød |j krø|j ƒd|_ |j ƒdS) NzAlready logged in.z7At least one of `user` and `usenetrc` must be specifiedrrIzauthinfo user Z381zauthinfo pass Z281r^)rirÐÚnetrcZauthenticatorsr_rpr™rBrrrdrerfrg)rÚuserÚpasswordÚusenetrcràZ credentialsZauthr}rrrÚlogin¬s<       z_NNTPBase.logincCs`y|jdƒ|_WnJtk r$Yn8tk rZ}z|jjdƒrHd|_n‚WYdd}~XnXdS)Nz mode readerZ480T)r™rcrrr rBrf)rÚerrrrgÕs z_NNTPBase._setreadermodecCs||jrtdƒ‚|jrtdƒ‚|jdƒ}|jdƒrp|jjƒt|j||j ƒ|_|jj dƒ|_d|_d|_ |j ƒnt dƒ‚dS) 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.ÚSTARTTLSZ382ÚrwbTNzTLS failed to start.)rhrÐrir™rBr`r–r[rYr_Úmakefilerdrer)rrZr}rrrÚstarttlsãs    z_NNTPBase.starttls)T)N)N)N)N)N)N)N)N)N)NNT)N)9rrrr†r‡rr rlrsrvrer€Údebugr„rˆrŒrbr˜r™ršržr r¡rzr¥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ßrrrorärgÚ _have_sslrérrrrr\(sj .    .         ) r\c@s*eZdZeddddefdd„Zdd„ZdS)rNFc Cs„||_||_tj||f|ƒ|_d}y8|jjdƒ}tj|||||ƒ|sJ|rX|j|||ƒWn$|rn|j ƒ|jj ƒ‚YnXdS)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. Nrç) r_ÚportÚsocketÚcreate_connectionrYrèr\r rär–) rr_rìrárârjrãrkr`rrrr ýs   z NNTP.__init__c Cs ztj|ƒWd|jjƒXdS)N)r\rrrYr–)rrrrrr!sz NNTP._close)rrrÚ NNTP_PORTrr rrrrrrrûs "c@s,eZdZedddddefdd„Zdd„ZdS)ÚNNTP_SSLNFc CsŠtj||f|ƒ|_d} yJt|j||ƒ|_|jjdƒ} tj|| |||d�|sP|r^|j|||ƒWn$| rt| jƒ|jjƒ‚YnXdS)z›This works identically to NNTP.__init__, except for the change in default port and the `ssl_context` argument for SSL connections. Nrç)rjrk) rírîrYr[rèr\r rär–) rr_rìrárâZ ssl_contextrjrãrkr`rrrr +s    zNNTP_SSL.__init__c Cs ztj|ƒWd|jjƒXdS)N)r\rrrYr–)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--serverznews.gmane.orgz+NNTP server hostname (default: %(default)s)z-pz--portr1z#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, rangeZtocCs$t|ƒ|kr |d|d…d}|S)NrJz...)r7)ÚsZlimrrrÚcutls rùúsÈ&          X-