"9QRc @s#dZddlZddlZddddddd d d d d g ZdefdYZdefdYZdefdYZdefdYZdefdYZ defdYZ eZ eZ eZ e Ze ZdZdddddddddg ZdZdfd YZed!krddlZd"oOejd#Zejd$dkrpd%ZneZeed%eZejd&\ZZZZ Z!eGHd'Ge!Gd(GeGd)GeGd*Ge GHej"d+ed,e \ZZ#eGHxe#D]Z$d-e$GHqWej%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. iNtNNTPtNNTPReplyErrortNNTPTemporaryErrortNNTPPermanentErrortNNTPProtocolErrort NNTPDataErrort error_replyt error_tempt error_permt error_protot error_datat NNTPErrorcBseZdZdZRS(s%Base class for all nntplib exceptionscGsBtj||y|d|_Wntk r=d|_nXdS(NisNo response given(t Exceptiont__init__tresponset IndexError(tselftargs((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pyR +s  (t__name__t __module__t__doc__R (((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pyR )scBseZdZRS(sUnexpected [123]xx reply(RRR(((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pyR2scBseZdZRS(s 4xx errors(RRR(((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pyR6scBseZdZRS(s 5xx errors(RRR(((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pyR:scBseZdZRS(s"Response does not begin with [1-5](RRR(((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pyR>scBseZdZRS(sError in response data(RRR(((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pyRBsiwt100t215t220t221t222t224t230t231t282s cBsyeZed#d#d#edZdZdZeZdZ dZ dZ dZ d#dZ dZd#d Zd#d Zd#d Zd#d Zd ZdZdZd#dZdZdZdZdZdZd#dZdZd#dZdZdZ d#dZ!d#dZ"d#dZ#dZ$dZ%d Z&d!Z'd"Z(RS($c Cs||_||_tj||f|_|jjd|_d|_|j|_ d}|ry|j d|_ Wqt k rqt k r}|r|j d dkrd}qqXnyX|r| rddl} | j} | j|} | r| d}| d }qnWntk r2nX|r|j d |} | d d kr|sqt| q|j d |} | d d krt | qn|ry|j d|_ Wqt k rqXqndS(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 commands, such as `group'. If you get unexpected NNTPPermanentErrors, you might need to set readermode. trbis mode readerit480iiNisauthinfo user t381sauthinfo pass t281(thosttporttsockettcreate_connectiontsocktmakefiletfilet debuggingtgetresptwelcometshortcmdRRRtnetrctauthenticatorstIOErrorR( RR"R#tusertpasswordt readermodetusenetrctreadermode_afterauthteR-t credentialstauthtresp((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pyR ^sP             cCs%|jrdGt|jGHn|jS(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*(R)treprR+(R((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pyt 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(R)(Rtlevel((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pytset_debuglevelscCs?|t}|jdkr+dGt|GHn|jj|dS(s6Internal: send one line to the server, appending CRLF.is*put*N(tCRLFR)R9R&tsendall(Rtline((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pytputlines cCs,|jrdGt|GHn|j|dS(s=Internal: send one command to the server (through putline()).s*cmd*N(R)R9R@(RR?((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pytputcmds cCs}|jj}|jdkr0dGt|GHn|s?tn|dtkr\|d }n|dtkry|d }n|S(snInternal: return one line from the server, stripping CRLF. Raise EOFError if the connection is closed.is*get*ii(R(treadlineR)R9tEOFErrorR=(RR?((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pytgetlines   cCs|j}|jr'dGt|GHn|d }|dkrLt|n|dkrgt|n|dkrt|n|S(sjInternal: get a response from the server. Raise various errors if the response indicates an error.s*resp*it4t5t123(RDR)R9RRR(RR8tc((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pyR*s      cCsd}zt|tr.t|d}}n|j}|d tkrYt|ng}xc|j}|dkr~Pn|d dkr|d}n|r|j|dqb|j |qbWd|r|j nX||fS( s~Internal: get a response plus following text from the server. Raise various errors if the response indicates an error.twit.is..is N( tNonet isinstancetstrtopenR*tLONGRESPRRDtwritetappendtclose(RR(t openedFileR8tlistR?((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pyt getlongresps(    cCs|j||jS(s.Internal: send a command and get the response.(RAR*(RR?((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pyR,s cCs|j||j|S(sBInternal: send a command and get the response plus following text.(RARU(RR?R(((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pytlongcmds cCs|jd|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 (RV(RtdatettimeR(((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pyt newgroups scCs*d|d|d|}|j||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 RW(RV(RtgroupRXRYR(tcmd((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pytnewnewss cCsY|jd|\}}x4tt|D] }t||j||[^ ]+)[ ]+(.*)$sLIST NEWSGROUPS iRsXGTITLE ii(tretcompileRVtsearchtstripRQR[(Rt group_patterntline_patR8t raw_linesRftraw_linetmatch((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pyRe>s  cCs|jd|}|d dkr2t|n|j}d}}}t|}|dkr|d}|dkr|d}|dkr|d}|dkr|dj}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 it211iiii(R,RRbR`tlower(RtnameR8twordstcounttfirsttlasttn((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pyR[Os          cCs|jd|S(soProcess a HELP command. Returns: - resp: server response if successful - list: list of stringstHELP(RV(RR(((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pythelpiscCs|d dkrt|n|j}d}d}t|}|dkru|d}|dkru|d}qun|||fS(s=Internal: parse the response of a STAT, NEXT or LAST command.it22iRdi(RRbR`(RR8RttnrtidRx((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pyt statparseps     cCs|j|}|j|S(s/Internal: process a STAT, NEXT or LAST command.(R,R~(RR?R8((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pytstatcmd~scCs|jd|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 (R(RR}((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pytstatscCs |jdS(s;Process a NEXT command. No arguments. Return as for STAT.tNEXT(R(R((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pytnextscCs |jdS(s;Process a LAST command. No arguments. Return as for STAT.tLAST(R(R((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pyRwscCs@|j||\}}|j|\}}}||||fS(s2Internal: process a HEAD, BODY or ARTICLE command.(RVR~(RR?R(R8RTR|R}((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pytartcmdscCs|jd|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 (R(RR}((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pytheads cCs|jd||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 (R(RR}R(((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pytbodys cCs|jd|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 (R(RR}((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pytarticles cCs |jdS(sPProcess a SLAVE command. Returns: - resp: server response if successfultSLAVE(R,(R((sH/opt/poky/1.5/sysroots/x86_64-pokysdk-linux/usr/lib/python2.7/nntplib.pytslavesc Cstjd}|jd|d||\}}xRtt|D]>}||}|j|} | rF| jdd||sN       !   !