m %UIc @sdZdkZdkZdddddddd d d d g Zd efdYZdefdYZdefdYZdefdYZdefdYZ defdYZ eZ eZ eZ e Ze ZdZdddddddddg ZdZdfdYZed jodkZd!o eid"Zeid#d$jo d%ZneZeed%eZeid&\ZZZZ Z!eGHd'Ge!Gd(GeGd)GeGd*Ge GHei"d+ed,e \ZZ#eGHxe#D]Z$d-e$GHqWei%ZeGHndS(.sHAn NNTP client class based on RFC 977: Network News Transfer Protocol. 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', 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, 'r') # 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. NtNNTPtNNTPReplyErrortNNTPTemporaryErrortNNTPPermanentErrortNNTPProtocolErrort NNTPDataErrort error_replyt error_tempt error_permt error_protot error_datat NNTPErrorcBstZdZdZRS(s%Base class for all nntplib exceptionscGsDti||y|d|_Wntj od|_nXdS(NisNo response given(t Exceptiont__init__tselftargstresponset IndexError(RR((t$/data/zmath/lib/python2.4/nntplib.pyR +s (t__name__t __module__t__doc__R (((RR )s cBstZdZRS(sUnexpected [123]xx reply(RRR(((RR2s cBstZdZRS(s 4xx errors(RRR(((RR6s cBstZdZRS(s 5xx errors(RRR(((RR:s cBstZdZRS(s"Response does not begin with [1-5](RRR(((RR>s cBstZdZRS(sError in response data(RRR(((RRBs iwt100t215t220t221t222t224t230t231t282s cBsytZedddedZdZdZeZdZ dZ dZ dZ ddZ d Zdd Zdd Zdd Zdd ZdZdZdZddZdZdZdZdZdZddZdZddZdZdZ ddZ!ddZ"ddZ#dZ$d Z%d!Z&d"Z'd#Z(RS($Nc Cs||_||_tititi|_|ii|i|if|iid|_ d|_ |i |_ d} |oly|id|_ Wqtj oqtj o1}|o|id djo d} qqXnyZ|oO| oGdk}|i} | i|} | o| d}| d}qHnWntj onX|o|id |} | d d joO|pt| q|id |} | d d jot| qn| o0y|id|_ Wqtj oqXqndS( smInitialize 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. readermode is sometimes necessary if you are connecting to an NNTP server on the local machine and intend to call reader-specific comamnds, such as `group'. If you get unexpected NNTPPermanentErrors, you might need to set readermode. trbis mode readerit480iNisauthinfo user t381sauthinfo pass t281(thostRtporttsockettAF_INETt SOCK_STREAMtsocktconnecttmakefiletfilet debuggingtgetresptwelcometreadermode_afterautht readermodetshortcmdRRtetuserRtusenetrctnetrct credentialstauthenticatorstauthtpasswordtIOErrortrespR( RR#R$R3R9R0R4R2R5R8R;R6R/((RR ^sR        cCs'|iodGt|iGHn|iS(sGet 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.s *welcome*N(RR,treprR.(R((Rt getwelcomes cCs ||_dS(sSet 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(tlevelRR,(RR>((Rtset_debuglevelscCsA|t}|idjodGt|GHn|ii|dS(s6Internal: send one line to the server, appending CRLF.is*put*N(tlinetCRLFRR,R<R(tsendall(RR@((Rtputlines  cCs.|iodGt|GHn|i|dS(s=Internal: send one command to the server (through putline()).s*cmd*N(RR,R<R@RC(RR@((Rtputcmds cCs|ii}|idjodGt|GHn|p tn|dtjo|d }n |dtjo|d }n|S(snInternal: return one line from the server, stripping CRLF. Raise EOFError if the connection is closed.is*get*iiN(RR+treadlineR@R,R<tEOFErrorRA(RR@((Rtgetlines cCs|i}|iodGt|GHn|d }|djot|n|djot|n|djot|n|S(sjInternal: get a response from the server. Raise various errors if the response indicates an error.s*resp*it4t5t123N( RRGR;R,R<tcRRR(RRKR;((RR-s      cCsd}zt|tot|d}}n|i}|d t jot |ng}xk|i }|djoPn|d djo|d}n|o|i|dqf|i|qfWWd|o|inX||fS( s~Internal: get a response plus following text from the server. Raise various errors if the response indicates an error.twiit.is..s N(tNonet openedFilet isinstanceR+tstrtopenRR-R;tLONGRESPRtlistRGR@twritetappendtclose(RR+RTROR@R;((Rt getlongresps.   cCs|i||iS(s.Internal: send a command and get the response.N(RRDR@R-(RR@((RR1s cCs|i||i|S(sBInternal: send a command and get the response plus following text.N(RRDR@RXR+(RR@R+((Rtlongcmds cCs|id|d||S(sProcess a NEWGROUPS command. Arguments: - date: string 'yymmdd' indicating the date - time: string 'hhmmss' indicating the time Return: - resp: server response if successful - list: list of newsgroup namess NEWGROUPS t N(RRYtdatettimeR+(RR[R\R+((Rt newgroups scCs*d|d|d|}|i||S(sProcess a NEWNEWS command. Arguments: - group: group name or '*' - date: string 'yymmdd' indicating the date - time: string 'hhmmss' indicating the time Return: - resp: server response if successful - list: list of message idssNEWNEWS RZN(tgroupR[R\tcmdRRYR+(RR^R[R\R+R_((RtnewnewsscCsY|id|\}}x4tt|D] }t||i ||[^ ]+)[ ]+(.*)$sLIST NEWSGROUPS iRsXGTITLE iiN(tretcompiletline_patRRYt group_patternR;t raw_linesRitraw_linetsearchtstriptmatchRVR^(RRnRmRoRiRpR;Rs((RRh?s!cCs|id|}|d djot|n|i}d}}}t |}|djoe|d}|djoJ|d}|djo/|d}|djo|di }qqqn|||||fS( s*Process a GROUP command. Argument: - group: the group name Returns: - resp: server response if successful - count: number of articles (string) - first: first article number (string) - last: last article number (string) - name: the group namesGROUP it211iiiiN( RR1tnameR;RRftwordstcounttfirsttlastRctntlower(RRuRwRyRzRvR;Rx((RR^Ps           cCs|id|S(soProcess a HELP command. Returns: - resp: server response if successful - list: list of stringstHELPN(RRYR+(RR+((RthelpjscCs|d djot|n|i}d}d}t|}|djo)|d}|djo|d}q{n|||fS(s=Internal: parse the response of a STAT, NEXT or LAST command.it22iRgiN(R;RRfRvtnrtidRcRz(RR;RzRvRR((Rt statparseqs     cCs|i|}|i|S(s/Internal: process a STAT, NEXT or LAST command.N(RR1R@R;R(RR@R;((RtstatcmdscCs|id|S(sProcess a STAT command. Argument: - id: article number or message id Returns: - resp: server response if successful - nr: the article number - id: the message idsSTAT N(RRR(RR((RtstatscCs |idS(s;Process a NEXT command. No arguments. Return as for STAT.tNEXTN(RR(R((RtnextscCs |idS(s;Process a LAST command. No arguments. Return as for STAT.tLASTN(RR(R((RRyscCs@|i||\}}|i|\}}}||||fS(s2Internal: process a HEAD, BODY or ARTICLE command.N( RRYR@R+R;RTRRR(RR@R+R;RTRR((RtartcmdscCs|id|S(sProcess a HEAD command. Argument: - id: article number or message id Returns: - resp: server response if successful - nr: article number - id: message id - list: the lines of the article's headersHEAD N(RRR(RR((RtheadscCs|id||S(skProcess a BODY command. Argument: - id: article number or message id - file: Filename string or file object to store the article in Returns: - resp: server response if successful - nr: article number - id: message id - list: the lines of the article's body or an empty list if file was usedsBODY N(RRRR+(RRR+((Rtbodys cCs|id|S(sProcess an ARTICLE command. Argument: - id: article number or message id Returns: - resp: server response if successful - nr: article number - id: message id - list: the lines of the articlesARTICLE N(RRR(RR((RtarticlescCs |idS(sPProcess a SLAVE command. Returns: - resp: server response if successfultSLAVEN(RR1(R((Rtslavesc Cstid}|id|d||\} }xTt t |D]@}||}|i|}|o|idd||