ž ¥ÿf"§c@s(dZddlZddlZddlZddlZddlZyddlZWnek rleZ YnXe Z ddl m Z ddlmZddddd d d gZd ZGd d„deƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd „d eƒZGdd „d eƒZdZdZddddddddddd d!h Zd"d#d$d%d&d'd(gZid'd)6d(d*6Zd+Zejd,d-d.d/d0gƒZejd1d2d3d*gƒZ d4d „Z d5d6„Z!e"d7d8„Z#e"d9d:„Z$ed;d<„Z%e r6d=d>„Z&nGd?d@„d@ƒZ'GdAd„de'ƒZ(e r‹GdBdC„dCe'ƒZ)ej*dCƒne+dDkr$ddl,Z,ddEl-m.Z.e,j/dFdGƒZ0e0j1dHdIdJdKdLdMƒe0j1dNdOdJdPdLdQƒe0j1dRdSdJdT dUe2dLdVeefƒe0j1dWdXdJdYdUe2dLdZƒe0j1d[d\d]d^dJedLd_ƒe0j3ƒZ4e4j5Z5e4j r¾e5dT kr£eZ5ne(d`e4j6dae5ƒZ7n.e5dT krÔeZ5ne)d`e4j6dae5ƒZ7e7j8ƒZ9dbe9kre7j:ƒne7j;e4j;ƒ\Z<Z=Z>Z?Z@eAdce@dde=dee>dfe?ƒdgdh„ZBeCe2e?ƒe4jDdTƒZ>e7jEe>e?ƒ\Z<ZFx‚eFD]z\ZGZHe eHd#ƒjIdidTƒdZJe eHd"ƒZKe2eHd(ƒZLeAdjjMeGeBeJdkƒeBeKdlƒeLƒƒq™We7jNƒndS(mu±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. iN(u decode_header(u_GLOBAL_DEFAULT_TIMEOUTuNNTPuNNTPReplyErroruNNTPTemporaryErroruNNTPPermanentErroruNNTPProtocolErroru NNTPDataErroru decode_headericBs&|EeZdZdZdd„ZdS(u NNTPErroru%Base class for all nntplib exceptionsc GsCtj||Œy|d|_Wntk r>d|_YnXdS(NiuNo response given(u Exceptionu__init__uresponseu IndexError(uselfuargs((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu__init__bs  uNNTPError.__init__N(u__name__u __module__u __qualname__u__doc__u__init__(u __locals__((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu NNTPError`su NNTPErrorcBs|EeZdZdZdS(uNNTPReplyErroruUnexpected [123]xx replyN(u__name__u __module__u __qualname__u__doc__(u __locals__((u,/opt/alt/python33/lib64/python3.3/nntplib.pyuNNTPReplyErroriscBs|EeZdZdZdS(uNNTPTemporaryErroru 4xx errorsN(u__name__u __module__u __qualname__u__doc__(u __locals__((u,/opt/alt/python33/lib64/python3.3/nntplib.pyuNNTPTemporaryErrormscBs|EeZdZdZdS(uNNTPPermanentErroru 5xx errorsN(u__name__u __module__u __qualname__u__doc__(u __locals__((u,/opt/alt/python33/lib64/python3.3/nntplib.pyuNNTPPermanentErrorqscBs|EeZdZdZdS(uNNTPProtocolErroru"Response does not begin with [1-5]N(u__name__u __module__u __qualname__u__doc__(u __locals__((u,/opt/alt/python33/lib64/python3.3/nntplib.pyuNNTPProtocolErroruscBs|EeZdZdZdS(u NNTPDataErroruError in response dataN(u__name__u __module__u __qualname__u__doc__(u __locals__((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu NNTPDataErrorysiwi3u100u101u211u215u220u221u222u224u225u230u231u282usubjectufromudateu message-idu referencesu:bytesu:linesubytesuliness u GroupInfougroupulastufirstuflagu ArticleInfounumberu message_idcCskg}xUt|ƒD]G\}}t|tƒrM|j|j|pCdƒƒq|j|ƒqWdj|ƒS(uwTakes an unicode string representing a munged header value and decodes it as a (possibly non-ASCII) readable value.uasciiu(u_email_decode_headeru isinstanceubytesuappendudecodeujoin(u header_strupartsuvuenc((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu decode_header§s cCsõg}x|D]ˆ}|ddkrR|dd…jdƒ\}}}d|}n|jdƒ\}}}|jƒ}tj||ƒ}|j|ƒq Wt}t|ƒt|ƒkrÆtdƒ‚n|dt|ƒ…|krñtdƒ‚n|S(uÐ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).iu:iNu$LIST OVERVIEW.FMT response too shortu*LIST OVERVIEW.FMT redefines default fields(u partitionuloweru_OVERVIEW_FMT_ALTERNATIVESugetuappendu_DEFAULT_OVERVIEW_FMTulenu NNTPDataError(ulinesufmtulineunameu_usuffixudefaults((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu_parse_overview_fmt²s "  u_parse_overview_fmtcCs6ttƒ}g}x|D]}i}|jdƒ^}}t|ƒ}xÒt|ƒD]Ä\} } | t|ƒkrwqSn|| } | jdƒ} | |kr | r | d} | rä| dt| ƒ…jƒ| krätdƒ‚n| r| t| ƒd…nd} n| ||| d?„Z&dfd@dA„Z'd%dfdfdBdC„Z(d%dfdfdDdE„Z)d%dfdfdFdG„Z*dHdI„Z+d%dfdJdK„Z,d%dfdLdM„Z-d%dfdNdO„Z.d%dfdPdQ„Z/dRdS„Z0dTdU„Z1dVdW„Z2dXdY„Z3dZd[„Z4d\d]„Z5d^d_„Z6dfdfdgd`da„Z7dbdc„Z8e9rédfddde„Z:ndfS(hu _NNTPBaseuutf-8usurrogateescapecCs||_||_d|_|jƒ|_d|_|jƒd|_ |r‡d|jkr‡|j ƒ|j s‡d|_|jƒq‡nd|_ d|_ dS(uSInitialize 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. iuREADERNF( uhostufileu debuggingu_getrespuwelcomeuNoneu_capsugetcapabilitiesuFalseureadermode_afterauthu_setreadermodeutls_onu authenticated(uselfufileuhostu readermodeutimeout((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu__init__:s         u_NNTPBase.__init__cCs|S(N((uself((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu __enter__isu_NNTPBase.__enter__csl‡fdd†}|ƒrhz0yˆjƒWntjtfk rIYnXWd|ƒrdˆjƒnXndS(Ncs tˆdƒS(Nufile(uhasattr((uself(u,/opt/alt/python33/lib64/python3.3/nntplib.pyumsu$_NNTPBase.__exit__..(uquitusocketuerroruEOFErroru_close(uselfuargsu is_connected((uselfu,/opt/alt/python33/lib64/python3.3/nntplib.pyu__exit__ls   u_NNTPBase.__exit__cCs)|jr"tdt|jƒƒn|jS(uÅ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.u *welcome*(u debugginguprinturepruwelcome(uself((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu getwelcomews u_NNTPBase.getwelcomec Cs¾|jdkr·d|_d|_y|jƒ\}}Wn!ttfk rZi|_Yq·X||_d|krttt |dƒƒ|_nd|kr·dj |dƒ|_q·n|jS(uŒGet the server capabilities, as read by __init__(). If the CAPABILITIES command is not supported, an empty dict is returned.iuVERSIONuIMPLEMENTATIONu N( u_capsuNoneu nntp_versionunntp_implementationu capabilitiesuNNTPPermanentErroruNNTPTemporaryErrorumaxumapuintujoin(uselfurespucaps((u,/opt/alt/python33/lib64/python3.3/nntplib.pyugetcapabilities€s     u_NNTPBase.getcapabilitiescCs ||_dS(uÞ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(u debugging(uselfulevel((u,/opt/alt/python33/lib64/python3.3/nntplib.pyuset_debuglevel–su_NNTPBase.set_debuglevelcCsP|t}|jdkr/tdt|ƒƒn|jj|ƒ|jjƒdS(ufInternal: send one line to the server, appending CRLF. The `line` must be a bytes-like object.iu*put*N(u_CRLFu debugginguprintureprufileuwriteuflush(uselfuline((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu_putlineŸs  u_NNTPBase._putlinecCsH|jrtdt|ƒƒn|j|j|jƒ}|j|ƒdS(ulInternal: send one command to the server (through _putline()). The `line` must be an unicode string.u*cmd*N(u debugginguprinturepruencodeuencodinguerrorsu_putline(uselfuline((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu_putcmd§s u_NNTPBase._putcmdcCsÊ|jjtdƒ}t|ƒtkr7tdƒ‚n|jdkr\tdt|ƒƒn|skt‚n|rÆ|dd…t krš|dd…}qÆ|dd…t krÆ|dd …}qÆn|S( uInternal: return one line from the server, stripping _CRLF. Raise EOFError if the connection is closed. Returns a bytes object.iu line too longu*get*iNiþÿÿÿiþÿÿÿiÿÿÿÿiÿÿÿÿ( ufileureadlineu_MAXLINEulenu NNTPDataErroru debugginguprinturepruEOFErroru_CRLF(uselfu strip_crlfuline((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu_getline®s u_NNTPBase._getlinecCs¨|jƒ}|jr+tdt|ƒƒn|j|j|jƒ}|dd…}|dkrnt|ƒ‚n|dkr‰t|ƒ‚n|dkr¤t |ƒ‚n|S(uInternal: get a response from the server. Raise various errors if the response indicates an error. Returns an unicode string.u*resp*Niu4u5u123( u_getlineu debugginguprintureprudecodeuencodinguerrorsuNNTPTemporaryErroruNNTPPermanentErroruNNTPProtocolError(uselfurespuc((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu_getresp¿s     u_NNTPBase._getrespc CsWd}z0t|ttfƒr4t|dƒ}}n|jƒ}|dd…tkret|ƒ‚ng}|dk rÞdtdf}x«|j dƒ}||kr©Pn|j dƒrË|dd…}n|j |ƒqŠnWd}xN|j ƒ}||krPn|j dƒr%|dd…}n|j |ƒqçWd|rL|jƒnX||fS( uQInternal: 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 an unicode string and `lines` is a list of bytes objects. If `file` is a file-like object, it must be open in binary mode. uwbNis.s. s..iF(uNoneu isinstanceustrubytesuopenu_getrespu _LONGRESPuNNTPReplyErroru_CRLFu_getlineuFalseu startswithuwriteuappenduclose(uselfufileu openedFileurespulinesu terminatorsulineu terminator((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu _getlongrespÏs8      u_NNTPBase._getlongrespcCs|j|ƒ|jƒS(uWInternal: send a command and get the response. Same return value as _getresp().(u_putcmdu_getresp(uselfuline((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu _shortcmdýs u_NNTPBase._shortcmdcCs|j|ƒ|j|ƒS(uoInternal: send a command and get the response plus following text. Same return value as _getlongresp().(u_putcmdu _getlongresp(uselfulineufile((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu_longcmds u_NNTPBase._longcmdcs?ˆj|ƒˆj|ƒ\}}|‡fdd†|DƒfS(uÒ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ƒ‘qS((udecodeuencodinguerrors(u.0uline(uself(u,/opt/alt/python33/lib64/python3.3/nntplib.pyu s u,_NNTPBase._longcmdstring..(u_putcmdu _getlongresp(uselfulineufileurespulist((uselfu,/opt/alt/python33/lib64/python3.3/nntplib.pyu_longcmdstring s u_NNTPBase._longcmdstringcCswy |jSWntk rYnXy|jdƒ\}}Wn"tk r]tdd…}Yn Xt|ƒ}||_|S(uqInternal: get the overview format. Queries the server if not already done, else returns the cached value.uLIST OVERVIEW.FMTN(u_cachedoverviewfmtuAttributeErroru_longcmdstringuNNTPPermanentErroru_DEFAULT_OVERVIEW_FMTu_parse_overview_fmt(uselfurespulinesufmt((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu_getoverviewfmts     u_NNTPBase._getoverviewfmtcCsdd„|DƒS(NcSs"g|]}t|jƒŒ‘qS((u GroupInfousplit(u.0uline((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu &s u(_NNTPBase._grouplist..((uselfulines((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu _grouplist$su_NNTPBase._grouplistcCsRi}|jdƒ\}}x*|D]"}|jƒ^}}|||[^ ]+)[ ]+(.*)$uLIST NEWSGROUPS u215uXGTITLE iiu(ureucompileu_longcmdstringu startswithusearchustripugroup( uselfu group_patternu return_alluline_paturespulinesugroupsuraw_lineumatchunameudesc((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu_getdescriptionses  u_NNTPBase._getdescriptionscCs|j|dƒS(ué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(u_getdescriptionsuFalse(uselfugroup((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu description|s u_NNTPBase.descriptioncCs|j|dƒS(u'Get descriptions for a range of groups.T(u_getdescriptionsuTrue(uselfu group_pattern((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu descriptions‰su_NNTPBase.descriptionscCsæ|jd|ƒ}|jdƒs1t|ƒ‚n|jƒ}d}}}t|ƒ}|dkrÁ|d}|dkrÁ|d}|dkr¾|d}|dkr»|djƒ}q»q¾qÁn|t|ƒt|ƒt|ƒ|fS(uProcess 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 uGROUP u211iiiii(u _shortcmdu startswithuNNTPReplyErrorusplitulenuloweruint(uselfunameurespuwordsucountufirstulastun((u,/opt/alt/python33/lib64/python3.3/nntplib.pyugroups          u_NNTPBase.groupcCs|jd|ƒS(uProcess 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 uHELP(u_longcmdstring(uselfufile((u,/opt/alt/python33/lib64/python3.3/nntplib.pyuhelp§su_NNTPBase.helpcCsQ|jdƒst|ƒ‚n|jƒ}t|dƒ}|d}|||fS(u_Internal: parse the response line of a STAT, NEXT, LAST, ARTICLE, HEAD or BODY command.u22ii(u startswithuNNTPReplyErrorusplituint(uselfurespuwordsuart_numu message_id((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu _statparse±s   u_NNTPBase._statparsecCs|j|ƒ}|j|ƒS(u/Internal: process a STAT, NEXT or LAST command.(u _shortcmdu _statparse(uselfulineuresp((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu_statcmd»su_NNTPBase._statcmdcCs-|r|jdj|ƒƒS|jdƒSdS(u(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 uSTAT {0}uSTATN(u_statcmduformat(uselfu message_spec((u,/opt/alt/python33/lib64/python3.3/nntplib.pyustatÀs u_NNTPBase.statcCs |jdƒS(u;Process a NEXT command. No arguments. Return as for STAT.uNEXT(u_statcmd(uself((u,/opt/alt/python33/lib64/python3.3/nntplib.pyunextÎsu_NNTPBase.nextcCs |jdƒS(u;Process a LAST command. No arguments. Return as for STAT.uLAST(u_statcmd(uself((u,/opt/alt/python33/lib64/python3.3/nntplib.pyulastÒsu_NNTPBase.lastcCsF|j||ƒ\}}|j|ƒ\}}}|t|||ƒfS(u2Internal: process a HEAD, BODY or ARTICLE command.(u_longcmdu _statparseu ArticleInfo(uselfulineufileurespulinesuart_numu message_id((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu_artcmdÖsu_NNTPBase._artcmdcCs4|dk rdj|ƒ}nd}|j||ƒS(u0Process 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) uHEAD {0}uHEADN(uNoneuformatu_artcmd(uselfu message_specufileucmd((u,/opt/alt/python33/lib64/python3.3/nntplib.pyuheadÜs u_NNTPBase.headcCs4|dk rdj|ƒ}nd}|j||ƒS(u+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) uBODY {0}uBODYN(uNoneuformatu_artcmd(uselfu message_specufileucmd((u,/opt/alt/python33/lib64/python3.3/nntplib.pyubodyês u_NNTPBase.bodycCs4|dk rdj|ƒ}nd}|j||ƒS(u5Process 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) u ARTICLE {0}uARTICLEN(uNoneuformatu_artcmd(uselfu message_specufileucmd((u,/opt/alt/python33/lib64/python3.3/nntplib.pyuarticleøs u_NNTPBase.articlecCs |jdƒS(uYProcess a SLAVE command. Returns: - resp: server response if successful uSLAVE(u _shortcmd(uself((u,/opt/alt/python33/lib64/python3.3/nntplib.pyuslavesu_NNTPBase.slavecsbtjdƒ‰|jdj||ƒ|ƒ\}}‡fdd†‰|‡fdd†|DƒfS(uiProcess 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 u^([0-9]+) ?(.*) ?u XHDR {0} {1}cs)ˆj|ƒ}|r%|jddƒS|S(Nii(umatchugroup(ulineum(upat(u,/opt/alt/python33/lib64/python3.3/nntplib.pyu remove_numbersu%_NNTPBase.xhdr..remove_numbercsg|]}ˆ|ƒ‘qS(((u.0uline(u remove_number(u,/opt/alt/python33/lib64/python3.3/nntplib.pyu s u"_NNTPBase.xhdr..(ureucompileu_longcmdstringuformat(uselfuhdrustrufileurespulines((upatu remove_numberu,/opt/alt/python33/lib64/python3.3/nntplib.pyuxhdr s $u_NNTPBase.xhdrcCsC|jdj||ƒ|ƒ\}}|jƒ}|t||ƒfS(uFProcess 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 u XOVER {0}-{1}(u_longcmdstringuformatu_getoverviewfmtu_parse_overview(uselfustartuendufileurespulinesufmt((u,/opt/alt/python33/lib64/python3.3/nntplib.pyuxovers  u_NNTPBase.xoverc Cs¯d|jkrdnd}t|ttfƒr[|\}}|dj||pQdƒ7}n|dk rx|d|}n|j||ƒ\}}|jƒ}|t||ƒfS(uß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 uOVERuXOVERu {0}-{1}uu N( u_capsu isinstanceutupleulistuformatuNoneu_longcmdstringu_getoverviewfmtu_parse_overview( uselfu message_specufileucmdustartuendurespulinesufmt((u,/opt/alt/python33/lib64/python3.3/nntplib.pyuover*s   u_NNTPBase.overc Cs–tjdtdƒtjdƒ}|jd||ƒ\}}g}xE|D]=}|j|jƒƒ}|rK|j|j ddƒƒqKqKW||fS(uà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) stringsuFThe XGTITLE extension is not actively used, use descriptions() insteadiu^([^ ]+)[ ]+(.*)$uXGTITLE i( uwarningsuwarnuDeprecationWarningureucompileu_longcmdstringusearchustripuappendugroup( uselfugroupufileuline_paturespu raw_linesulinesuraw_lineumatch((u,/opt/alt/python33/lib64/python3.3/nntplib.pyuxgtitleEs    u_NNTPBase.xgtitlec CsŽtjdtdƒ|jdj|ƒƒ}|jdƒsIt|ƒ‚ny|jƒ\}}Wntk rt|ƒ‚Yn X||fSdS(uÑProcess an XPATH command (optional server extension) Arguments: - id: Message id of article Returns: resp: server response if successful path: directory path to article u(The XPATH extension is not actively usediu XPATH {0}u223N( uwarningsuwarnuDeprecationWarningu _shortcmduformatu startswithuNNTPReplyErrorusplitu ValueError(uselfuidurespuresp_numupath((u,/opt/alt/python33/lib64/python3.3/nntplib.pyuxpathWs   u_NNTPBase.xpathcCs˜|jdƒ}|jdƒs-t|ƒ‚n|jƒ}t|ƒdkrZt|ƒ‚n|d}t|ƒdkr…t|ƒ‚n|t|dƒfS(uProcess the DATE command. Returns: - resp: server response if successful - date: datetime object uDATEu111iiiN(u _shortcmdu startswithuNNTPReplyErrorusplitulenu NNTPDataErroru_parse_datetimeuNone(uselfurespuelemudate((u,/opt/alt/python33/lib64/python3.3/nntplib.pyudateks  u_NNTPBase.datecCsÚ|j|ƒ}|jdƒs-t|ƒ‚nt|ttfƒrQ|jƒ}nx_|D]W}|jtƒsƒ|j dƒt}n|jdƒrŸd|}n|j j |ƒqXW|j j dƒ|j j ƒ|j ƒS(Nu3s s.s. (u _shortcmdu startswithuNNTPReplyErroru isinstanceubytesu bytearrayu splitlinesuendswithu_CRLFurstripufileuwriteuflushu_getresp(uselfucommandufurespuline((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu_post|s   u_NNTPBase._postcCs|jd|ƒS(u¨Process a POST command. Arguments: - data: bytes object, iterable or file containing the article Returns: - resp: server response if successfuluPOST(u_post(uselfudata((u,/opt/alt/python33/lib64/python3.3/nntplib.pyupost‘su_NNTPBase.postcCs|jdj|ƒ|ƒS(u 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.u IHAVE {0}(u_postuformat(uselfu message_idudata((u,/opt/alt/python33/lib64/python3.3/nntplib.pyuihave˜su_NNTPBase.ihavecCs|jjƒ|`dS(N(ufileuclose(uself((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu_close¡s u_NNTPBase._closec Cs%z|jdƒ}Wd|jƒX|S(udProcess a QUIT command and close the socket. Returns: - resp: server response if successfuluQUITN(u _shortcmdu_close(uselfuresp((u,/opt/alt/python33/lib64/python3.3/nntplib.pyuquit¥s u_NNTPBase.quitc Csi|jrtdƒ‚n| r5| r5tdƒ‚ny[|r| rddl}|jƒ}|j|jƒ}|r|d}|d}qnWntk r¤YnX|s¯dS|jd|ƒ}|jdƒr|sæt|ƒ‚q|jd|ƒ}|jdƒst |ƒ‚qnd|_ |j ƒ|j red |j kre|jƒd|_ |j ƒndS( NuAlready logged in.u7At least one of `user` and `usenetrc` must be specifiediiuauthinfo user u381uauthinfo pass u281uREADER(u authenticatedu ValueErrorunetrcuauthenticatorsuhostuIOErroru _shortcmdu startswithuNNTPReplyErroruNNTPPermanentErroruNoneu_capsugetcapabilitiesureadermode_afterauthu_setreadermode(uselfuuserupassworduusenetrcunetrcu credentialsuauthuresp((u,/opt/alt/python33/lib64/python3.3/nntplib.pyulogin®s<           u_NNTPBase.logincCsty|jdƒ|_WnWtk r*YnFtk ro}z&|jjdƒrZd|_n‚WYdd}~XnXdS(Nu mode readeru480T(u _shortcmduwelcomeuNNTPPermanentErroruNNTPTemporaryErroruresponseu startswithuTrueureadermode_afterauth(uselfue((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu_setreadermode×s  u_NNTPBase._setreadermodecCs´|jrtdƒ‚n|jr0tdƒ‚n|jdƒ}|jdƒr¤|jjƒt|j|ƒ|_|jj dƒ|_d|_d|_ |j ƒn tdƒ‚dS( uzProcess a STARTTLS command. Arguments: - context: SSL context to use for the encrypted connection uTLS is already enabled.u+TLS cannot be started after authentication.uSTARTTLSu382urwbuTLS failed to start.NT(utls_onu ValueErroru authenticatedu _shortcmdu startswithufileucloseu _encrypt_onusockumakefileuTrueuNoneu_capsugetcapabilitiesu NNTPError(uselfucontexturesp((u,/opt/alt/python33/lib64/python3.3/nntplib.pyustarttlsås      u_NNTPBase.starttlsNT(;u__name__u __module__u __qualname__uencodinguerrorsuNoneu_GLOBAL_DEFAULT_TIMEOUTu__init__u __enter__u__exit__u getwelcomeugetcapabilitiesuset_debugleveludebugu_putlineu_putcmduTrueu_getlineu_getrespu _getlongrespu _shortcmdu_longcmdu_longcmdstringu_getoverviewfmtu _grouplistu capabilitiesu newgroupsunewnewsulistu_getdescriptionsu descriptionu descriptionsugroupuhelpu _statparseu_statcmdustatunextulastu_artcmduheadubodyuarticleuslaveuxhdruxoveruoveruxgtitleuxpathudateu_postupostuihaveu_closeuquituloginu_setreadermodeu _have_sslustarttls(u __locals__((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu _NNTPBase*sj .      .                 ) u _NNTPBasecBs>|EeZdZeddddedd„Zdd„ZdS(uNNTPc Cs~||_||_tj||f|ƒ|_|jjdƒ}tj|||||ƒ|sd|rz|j|||ƒndS(u,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. urwbN( uhostuportusocketucreate_connectionusockumakefileu _NNTPBaseu__init__ulogin( uselfuhostuportuuserupasswordu readermodeuusenetrcutimeoutufile((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu__init__ÿs    u NNTP.__init__c Cs&ztj|ƒWd|jjƒXdS(N(u _NNTPBaseu_closeusockuclose(uself((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu_closesu NNTP._closeNF( u__name__u __module__u __qualname__u NNTP_PORTuNoneuFalseu_GLOBAL_DEFAULT_TIMEOUTu__init__u_close(u __locals__((u,/opt/alt/python33/lib64/python3.3/nntplib.pyuNNTPýs c BsA|EeZdZedddddedd„Zdd„ZdS(uNNTP_SSLc Cs‡tj||f|ƒ|_t|j|ƒ|_|jjdƒ} tj|| |d|d|ƒ|sm|rƒ|j|||ƒndS(u›This works identically to NNTP.__init__, except for the change in default port and the `ssl_context` argument for SSL connections. urwbu readermodeutimeoutN(usocketucreate_connectionusocku _encrypt_onumakefileu _NNTPBaseu__init__ulogin( uselfuhostuportuuserupasswordu ssl_contextu readermodeuusenetrcutimeoutufile((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu__init__&s  uNNTP_SSL.__init__c Cs&ztj|ƒWd|jjƒXdS(N(u _NNTPBaseu_closeusockuclose(uself((u,/opt/alt/python33/lib64/python3.3/nntplib.pyu_close5suNNTP_SSL._closeNF( u__name__u __module__u __qualname__u NNTP_SSL_PORTuNoneuFalseu_GLOBAL_DEFAULT_TIMEOUTu__init__u_close(u __locals__((u,/opt/alt/python33/lib64/python3.3/nntplib.pyuNNTP_SSL$s   uNNTP_SSLu__main__(u parsedateu descriptionuJ nntplib built-in demo - display the latest articles in a newsgroupu-gu--groupudefaultugmane.comp.python.generaluhelpu3group to fetch messages from (default: %(default)s)u-su--serverunews.gmane.orgu+NNTP server hostname (default: %(default)s)u-pu--portiutypeu#NNTP port number (default: %s / %s)u-nu --nb-articlesi u2number of articles to fetch (default: %(default)s)u-Su--ssluactionu store_trueuuse NNTP over SSLuhostuportuSTARTTLSuGroupuhasuarticles, rangeutocCs1t|ƒ|kr-|d|d…d}n|S(Niu...(ulen(usulim((u,/opt/alt/python33/lib64/python3.3/nntplib.pyucutasucutusÆ&               ÿÿÕ&              !   )