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
 lŽŒYF¨ã@sdZddlZddlZddlZddlZddlZyddlZWnek rldZYnXdZddl 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,d*iZd-Zejd.d/d0d1d2gƒZejd3d4d5d,gƒZd6d„Z d7d8„Zdd9d:„Z dd;d<„Z!dd=d>„Z"er4d?d@„Z#GdAdB„dBƒZ$GdCd„de$ƒZ%er†GdDdE„dEe$ƒZ&e j'dEƒe(dFkrddl)Z)e)j*dGdHƒZ+e+j,dIdJdKdLdMdNƒe+j,dOdPdKdQdMdRƒe+j,dSdTdKdU dVe-dMdWeefƒe+j,dXdYdKdZdVe-dMd[ƒe+j,d\d]d^d_dKddMd`ƒe+j.ƒZ/e/j0Z0e/j r¦e0dU kr‹eZ0e%dae/j1dbe0ƒZ2n+e0dU kr¹eZ0e&dae/j1dbe0ƒZ2e2j3ƒZ4dce4króe2j5ƒe2j6e/j6ƒ\Z7Z8Z9Z:Z;e<dde;dee8dfe9dge:ƒdhdi„Z=e>e-e:ƒe/j?dUƒZ9e2j@e9e:ƒ\Z7ZAx‚eAD]z\ZBZCe eCd%ƒjDdjdUƒdZEe eCd$ƒZFe-eCd*ƒZGe<dkjHeBe=eEdlƒe=eFdmƒeGƒƒq{We2jIƒdS)na±An NNTP client class based on: - RFC 977: Network News Transfer Protocol - RFC 2980: Common NNTP Extensions - RFC 3977: Network News Transfer Protocol (version 2) Example: >>> 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@s"eZdZdZdd„ZdS)rz%Base class for all nntplib exceptionsc GsCtj||Œy|d|_Wntk r>d|_YnXdS)NrzNo response given)Ú ExceptionÚ__init__ÚresponseÚ IndexError)ÚselfÚargs©rú&/opt/python35/lib/python3.5/nntplib.pyr bs  zNNTPError.__init__N)Ú__name__Ú __module__Ú __qualname__Ú__doc__r rrrrr`s c@seZdZdZdS)rzUnexpected [123]xx replyN)rrrrrrrrris c@seZdZdZdS)rz 4xx errorsN)rrrrrrrrrms c@seZdZdZdS)rz 5xx errorsN)rrrrrrrrrqs c@seZdZdZdS)r z"Response does not begin with [1-5]N)rrrrrrrrr us c@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_idcCskg}xUt|ƒD]G\}}t|tƒrM|j|j|pCdƒƒ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}x�|D]ˆ}|ddkrR|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Ú_ÚsuffixÚdefaultsrrrÚ_parse_overview_fmt²s "    r>cCs-ttƒ}g}x|D] }i}|jdƒ^}}t|ƒ}xÉt|ƒD]»\} } | t|ƒkrtqS|| } | jdƒ} | |kr| r| d} | rÞ| dt| ƒ…jƒ| krÞtdƒ‚| rú| t| ƒd…nd} | ||| d?„Z#d@dA„Z$ddBdC„Z%dd'ddDdE„Z&dd'ddFdG„Z'dd'ddHdI„Z(dJdK„Z)d'ddLdM„Z*d'ddNdO„Z+d'ddPdQ„Z,d'ddRdS„Z-dTdU„Z.dVdW„Z/dXdY„Z0dZd[„Z1d\d]„Z2d^d_„Z3d`da„Z4ddddbdc„Z5ddde„Z6e7râddfdg„Z8dS)hÚ _NNTPBasezutf-8ÚsurrogateescapeNcCs—||_||_d|_|jƒ|_d|_|jƒd|_|r�d|jkr�|jƒ|js�d|_|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)rrcrbÚ readermodeÚtimeoutrrrr 8s          z_NNTPBase.__init__cCs|S)Nr)rrrrÚ __enter__gsz_NNTPBase.__enter__csc‡fdd†}|ƒr_z-yˆjƒWnttfk rFYnXWd|ƒr^ˆjƒXdS)Ncs tˆdƒS)Nrc)Ú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*)rdÚprintÚreprrf)rrrrÚ getwelcomeus z_NNTPBase.getwelcomec Csµ|jdkr®d|_d|_y|jƒ\}}Wn!ttfk rZi|_YnTX||_d|krŒttt|dƒƒ|_d|kr®dj |dƒ|_|jS)zŒGet the server capabilities, as read by __init__(). If the CAPABILITIES command is not supported, an empty dict is returned.Nr1ÚVERSIONZIMPLEMENTATIONú ) rgÚ nntp_versionZnntp_implementationÚ capabilitiesrrÚmaxÚmaprAr,)rÚrespÚcapsrrrrh~s     z_NNTPBase.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)rd)rÚlevelrrrÚset_debuglevel”sz_NNTPBase.set_debuglevelcCsM|t}|jdkr,tdt|ƒƒ|jj|ƒ|jjƒdS)zfInternal: send one line to the server, appending CRLF. The `line` must be a bytes-like object.r1z*put*N)Ú_CRLFrdrwrxrcÚwriteÚflush)rr9rrrÚ_putline�s  z_NNTPBase._putlinecCsE|jrtdt|ƒƒ|j|j|jƒ}|j|ƒdS)zkInternal: send one command to the server (through _putline()). The `line` must be a unicode string.z*cmd*N)rdrwrxÚencodeÚencodingÚerrorsr‡)rr9rrrÚ_putcmd¥s z_NNTPBase._putcmdTcCs»|jjtdƒ}t|ƒtkr4tdƒ‚|jdkrVtdt|ƒƒ|sbt‚|r·|dd…t kr‘|dd…}n&|dd…t kr·|dd …}|S) z�Internal: return one line from the server, stripping _CRLF. Raise EOFError if the connection is closed. Returns a bytes object.r1z line too longz*get*rKNrPrPéÿÿÿÿrŒ) rcÚreadlineÚ_MAXLINEr7r rdrwrxrtr„)rZ strip_crlfr9rrrÚ_getline¬s z_NNTPBase._getlinecCsœ|jƒ}|jr(tdt|ƒƒ|j|j|jƒ}|dd…}|dkrht|ƒ‚|dkr€t|ƒ‚|dkr˜t |ƒ‚|S)zŒInternal: get a response from the server. Raise various errors if the response indicates an error. Returns a unicode string.z*resp*Nr1Ú4Ú5Z123) r�rdrwrxr+r‰rŠrrr )rr€Úcrrrre½s        z_NNTPBase._getrespc CsDd}z t|ttfƒr1t|dƒ}}|jƒ}|dd…tkr_t|ƒ‚g}|dk rÓdtdf}x¡|jdƒ}||kr P|j dƒr¿|dd…}|j |ƒq„WnRd}xI|jƒ}||krõP|j dƒr|dd…}|j |ƒqÜWWd|r9|j ƒX||fS) 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. Fs..r1) r)ÚstrrÚopenreÚ _LONGRESPrr„r�rCr…r*Úclose)rrcZ openedFiler€rZ terminatorsr9Ú terminatorrrrÚ _getlongrespÍs8        z_NNTPBase._getlongrespcCs|j|ƒ|jƒS)zWInternal: send a command and get the response. Same return value as _getresp().)r‹re)rr9rrrÚ _shortcmdûs z_NNTPBase._shortcmdcCs|j|ƒ|j|ƒS)zoInternal: send a command and get the response plus following text. Same return value as _getlongresp().)r‹r›)rr9rcrrrÚ_longcmds z_NNTPBase._longcmdcs?ˆj|ƒˆj|ƒ\}}|‡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. cs(g|]}|jˆjˆjƒ‘qSr)r+r‰rŠ)Ú.0r9)rrrú s z,_NNTPBase._longcmdstring..)r‹r›)rr9rcr€Úlistr)rrÚ_longcmdstrings z_NNTPBase._longcmdstringcCswy |jSWntk rYnXy|jdƒ\}}Wn"tk r]tdd…}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Ú_getoverviewfmts     z_NNTPBase._getoverviewfmtcCsdd„|DƒS)NcSs"g|]}t|jƒŒ‘qSr)rr@)ržr9rrrrŸ$s z(_NNTPBase._grouplist..r)rrrrrÚ _grouplist"sz_NNTPBase._grouplistcCsRi}|jdƒ\}}x*|D]"}|jƒ^}}|||[^ ]+)[ ]+(.*)$zLIST NEWSGROUPS rzXGTITLE r1rKr')ÚreÚcompiler¡rCÚ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 rrr1rKr”rL)rœrCrr@r7r3rA)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¡)rrcrrrÚhelp¥sz_NNTPBase.helpcCsN|jdƒst|ƒ‚|jƒ}t|dƒ}|d}|||fS)z_Internal: parse the response line of a STAT, NEXT, LAST, ARTICLE, HEAD or BODY command.Z22r1rK)rCrr@rA)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¹sz_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¾rV)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.lastcCsF|j||ƒ\}}|j|ƒ\}}}|t|||ƒfS)z2Internal: process a HEAD, BODY or ARTICLE command.)r�r½r$)rr9rcr€rr¼r%rrrÚ_artcmdÔsz_NNTPBase._artcmdcCs4|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)rVrÂ)rr¿rcr§rrrÚheadÚs z_NNTPBase.headcCs4|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)rVrÂ)rr¿rcr§rrrÚbodyès z_NNTPBase.bodycCs4|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)rVrÂ)rr¿rcr§rrrÚarticleös z_NNTPBase.articlecCs |jdƒS)zYProcess a SLAVE command. Returns: - resp: server response if successful ZSLAVE)rœ)rrrrÚslavesz_NNTPBase.slavecsbtjdƒ‰|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)Nr1rK)r´r )r9Úm)ÚpatrrÚ remove_numbersz%_NNTPBase.xhdr..remove_numbercsg|]}ˆ|ƒ‘qSrr)ržr9)rÉrrrŸs z"_NNTPBase.xhdr..)r­r®r¡rV)rZhdrr–rcr€rr)rÈrÉrÚxhdr s $z_NNTPBase.xhdrcCsC|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¡rVr£rI)rÚstartÚendrcr€rr8rrrÚxovers  z_NNTPBase.xoverc Cs¬d|jkrdnd}t|ttfƒr[|\}}|dj||pQdƒ7}n|dk ru|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'Nr{)rgr)Útupler rVr¡r£rI) rr¿rcr§rËrÌr€rr8rrrÚover(s   z_NNTPBase.overc Cs“tjdtdƒtjdƒ}|jd||ƒ\}}g}xB|D]:}|j|jƒƒ}|rK|j|j ddƒƒqKW||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() insteadrKz^([^ ]+)[ ]+(.*)$zXGTITLE r1) ÚwarningsÚwarnÚDeprecationWarningr­r®r¡r¯r°r*r ) rr rcr±r€Z raw_linesrr³r´rrrÚxgtitleCs   z_NNTPBase.xgtitlec Cs‹tjdtdƒ|jdj|ƒƒ}|jdƒsFt|ƒ‚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 usedrKz XPATH {0}Z223N) rÐrÑrÒrœrVrCrr@Ú ValueError)rÚidr€Zresp_numÚpathrrrÚxpathUs    z_NNTPBase.xpathcCs�|jdƒ}|jdƒs*t|ƒ‚|jƒ}t|ƒdkrTt|ƒ‚|d}t|ƒdkr|t|ƒ‚|t|dƒfS)z�Process the DATE command. Returns: - resp: server response if successful - date: datetime object ZDATEZ111rKr1éN)rœrCrr@r7r rU)rr€Úelemrrrrris     z_NNTPBase.datecCsÎ|j|ƒ}|jdƒs*t|ƒ‚t|ttfƒrK|jƒ}xY|D]Q}|jtƒsz|j dƒt}|jdƒr“d|}|j j |ƒqRW|j j dƒ|j j ƒ|j ƒS)NÚ3s r•s. )rœrCrr)rÚ bytearrayÚ splitlinesÚendswithr„Úrstriprcr…r†re)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àrV)rr%rárrrÚihave–sz_NNTPBase.ihavecCs|jjƒ|`dS)N)rcr™)rrrrruŸs z_NNTPBase._closec Cs%z|jdƒ}Wd|jƒX|S)zdProcess a QUIT command and close the socket. Returns: - resp: server response if successfulZQUITN)rœru)rr€rrrrr£s z_NNTPBase.quitc CsT|jrtdƒ‚| r/| r/tdƒ‚yU|rƒ| rƒddl}|jƒ}|j|jƒ}|rƒ|d}|d}Wntk r˜YnX|s£dS|jd|ƒ}|jdƒr|sÚt|ƒ‚n.|jd|ƒ}|jdƒst |ƒ‚d|_ |j ƒ|j rPd |j krP|j ƒd|_ |j ƒdS) NzAlready logged in.z7At least one of `user` and `usenetrc` must be specifiedrrKzauthinfo user Z381zauthinfo pass Z281ra)rlrÔÚnetrcZauthenticatorsrbrsrœrCrrrgrhrirj)rÚuserÚpasswordÚusenetrcräZ credentialsZauthr€rrrÚlogin¬s<             z_NNTPBase.logincCsty|jdƒ|_WnWtk r*YnFtk ro}z&|jjdƒrZd|_n‚WYdd}~XnXdS)Nz mode readerZ480T)rœrfrrr rCri)rÚerrrrjÕs  z_NNTPBase._setreadermodecCs´|jrtdƒ‚|jr*tdƒ‚|jdƒ}|jdƒr¤|jjƒt|j||j ƒ|_|jj dƒ|_d|_d|_ |j ƒn t 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.)rkrÔrlrœrCrcr™r^r[rbÚmakefilergrhr)rr\r€rrrÚstarttlsãs        z_NNTPBase.starttls)9rrrr‰rŠrr rorvryrhrƒÚdebugr‡r‹r�rer›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ÏrÓr×rràrârãrurrrèrjÚ _have_sslrírrrrr_(sj .      .                 ) r_c@s:eZdZeddddedd„Zdd„ZdS)rNFc Cs°||_||_tj||f|ƒ|_d}yN|jjdƒ}tj|||||ƒ|sm|r€|j|||ƒWn(|r—|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ë) rbÚportÚsocketÚcreate_connectionr[rìr_r rèr™) rrbrðrårærmrçrnrcrrrr ýs      z NNTP.__init__c Cs&ztj|ƒWd|jjƒXdS)N)r_rur[r™)rrrrru!sz NNTP._close)rrrÚ NNTP_PORTrr rurrrrrûs  "c @s=eZdZedddddedd„Zdd„ZdS)ÚNNTP_SSLNFc Cs¼tj||f|ƒ|_d} ylt|j||ƒ|_|jjdƒ} tj|| |d|d|ƒ|sy|rŒ|j|||ƒWn(| r£| 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ërmrn) rñròr[r^rìr_r rèr™) rrbrðråræZ ssl_contextrmrçrnrcrrrr +s    zNNTP_SSL.__init__c Cs&ztj|ƒWd|jjƒXdS)N)r_rur[r™)rrrrruAszNNTP_SSL._close)rrrÚ NNTP_SSL_PORTrr rurrrrrô)s  rôÚ__main__r¶zJ nntplib built-in demo - display the latest articles in a newsgroupz-gz--groupÚdefaultzgmane.comp.python.generalr»z3group to fetch messages from (default: %(default)s)z-sz--serverznews.gmane.orgz+NNTP server hostname (default: %(default)s)z-pz--portr1Útypez#NNTP port number (default: %s / %s)z-nz --nb-articlesé z2number of articles to fetch (default: %(default)s)z-Sz--sslÚactionÚ store_truezuse NNTP over SSLrbrðrêZGroupZhaszarticles, rangeZtocCs.t|ƒ|kr*|d|d…d}|S)NrLz...)r7)ÚsZlimrrrÚcutlsrýúrIrUrYr^r_rrôr*rÚargparseÚArgumentParserÚparserÚ add_argumentrAÚ parse_argsrrðZserverrürhr�rír r€r¹r"r!r:rwrýr–Z nb_articlesrÍZ overviewsZartnumrÏr@ZauthorrrrVrrrrrrÚsÂ&                 ÿÿÕ-             !   )