ó zfc @s)dZddlZddlZddddddd d d d d g ZdZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZ defd„ƒYZ defd„ƒYZ eZ eZ e Ze Ze ZdZdddddddddg Zd Zdfd!„ƒYZed"kr%ddlZd#oUejd$Zejd%ƒdkrvd&ZneZeed&eƒZejd'ƒ\ZZZ Z!Z"eGHd(Ge"Gd)GeGd*Ge Gd+Ge!GHej#d,e d-e!ƒ\ZZ$eGHxe$D]Z%d.e%GHqþWej&ƒ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. iÿÿÿÿNtNNTPtNNTPReplyErrortNNTPTemporaryErrortNNTPPermanentErrortNNTPProtocolErrort NNTPDataErrort error_replyt error_tempt error_permt error_protot error_datait NNTPErrorcBseZdZd„ZRS(s%Base class for all nntplib exceptionscGsBtj||Œy|d|_Wntk r=d|_nXdS(NisNo response given(t Exceptiont__init__tresponset IndexError(tselftargs((s/usr/lib64/python2.7/nntplib.pyR 2s  (t__name__t __module__t__doc__R (((s/usr/lib64/python2.7/nntplib.pyR 0scBseZdZRS(sUnexpected [123]xx reply(RRR(((s/usr/lib64/python2.7/nntplib.pyR9scBseZdZRS(s 4xx errors(RRR(((s/usr/lib64/python2.7/nntplib.pyR=scBseZdZRS(s 5xx errors(RRR(((s/usr/lib64/python2.7/nntplib.pyRAscBseZdZRS(s"Response does not begin with [1-5](RRR(((s/usr/lib64/python2.7/nntplib.pyREscBseZdZRS(sError in response data(RRR(((s/usr/lib64/python2.7/nntplib.pyRIsiwt100t215t220t221t222t224t230t231t282s cBsyeZed#d#d#ed„Zd„Zd„ZeZd„Z d„Z d„Z d„Z d#d„Z d„Zd#d „Zd#d „Zd#d „Zd#d „Zd „Zd„Zd„Zd#d„Zd„Zd„Zd„Zd„Zd„Zd#d„Zd„Zd#d„Zd„Zd„Z d#d„Z!d#d„Z"d#d„Z#d„Z$d„Z%d „Z&d!„Z'd"„Z(RS($c Csà||_||_tj||fƒ|_|jjdƒ|_d|_|jƒ|_ d}|rÇy|j dƒ|_ WqÇt k rŒqÇt k rÃ}|r½|j d dkr½d}qÄ‚qÇXnyX|r| rddl} | jƒ} | j|ƒ} | r| d}| d }qnWntk r2nX|rÜ|j d |ƒ} | d d kr¦|sqt| ƒ‚q¦|j d |ƒ} | d d kr¦t | ƒ‚q¦n|rÜy|j dƒ|_ WqÙt k rÕqÙXqÜndS(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 readerit480iiÿÿÿÿNisauthinfo user t381sauthinfo pass t281(thosttporttsockettcreate_connectiontsocktmakefiletfilet debuggingtgetresptwelcometshortcmdRRRtnetrctauthenticatorstIOErrorR( RR"R#tusertpasswordt readermodetusenetrctreadermode_afterauthteR-t credentialstauthtresp((s/usr/lib64/python2.7/nntplib.pyR esP             cCs%|jrdGt|jƒGHn|jS(sÅ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.s *welcome*(R)treprR+(R((s/usr/lib64/python2.7/nntplib.pyt getwelcome²s cCs ||_dS(sÞ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(R)(Rtlevel((s/usr/lib64/python2.7/nntplib.pytset_debuglevel»scCs?|t}|jdkr+dGt|ƒGHn|jj|ƒdS(s6Internal: send one line to the server, appending CRLF.is*put*N(tCRLFR)R9R&tsendall(Rtline((s/usr/lib64/python2.7/nntplib.pytputlineÄs cCs,|jrdGt|ƒGHn|j|ƒdS(s=Internal: send one command to the server (through putline()).s*cmd*N(R)R9R@(RR?((s/usr/lib64/python2.7/nntplib.pytputcmdÊs cCs¥|jjtdƒ}t|ƒtkr7tdƒ‚n|jdkrXdGt|ƒGHn|sgt‚n|dtkr„|d }n|dtkr¡|d }n|S(snInternal: return one line from the server, stripping CRLF. Raise EOFError if the connection is closed.is line too longs*get*iþÿÿÿiÿÿÿÿ( R(treadlinet_MAXLINEtlenRR)R9tEOFErrorR=(RR?((s/usr/lib64/python2.7/nntplib.pytgetlineÏs   cCs†|jƒ}|jr'dGt|ƒGHn|d }|dkrLt|ƒ‚n|dkrgt|ƒ‚n|dkr‚t|ƒ‚n|S(sjInternal: get a response from the server. Raise various errors if the response indicates an error.s*resp*it4t5t123(RFR)R9RRR(RR8tc((s/usr/lib64/python2.7/nntplib.pyR*Üs      cCsèd}zÁt|tƒr.t|dƒ}}n|jƒ}|d tkrYt|ƒ‚ng}xd|jƒ}|dkr~Pn|d dkr›|d}n|rµ|j|dƒqb|j |ƒqbWWd|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*tLONGRESPRRFtwritetappendtclose(RR(t openedFileR8tlistR?((s/usr/lib64/python2.7/nntplib.pyt getlongrespês(    cCs|j|ƒ|jƒS(s.Internal: send a command and get the response.(RAR*(RR?((s/usr/lib64/python2.7/nntplib.pyR, s cCs|j|ƒ|j|ƒS(sBInternal: send a command and get the response plus following text.(RARW(RR?R(((s/usr/lib64/python2.7/nntplib.pytlongcmds cCs|jd|d||ƒS(söProcess 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 (RX(RtdatettimeR(((s/usr/lib64/python2.7/nntplib.pyt newgroupsscCs*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 RY(RX(RtgroupRZR[R(tcmd((s/usr/lib64/python2.7/nntplib.pytnewnewss cCsY|jd|ƒ\}}x4tt|ƒƒD] }t||jƒƒ||[^ ]+)[ ]+(.*)$sLIST NEWSGROUPS iRsXGTITLE ii(tretcompileRXtsearchtstripRSR](Rt group_patterntline_patR8t raw_linesRgtraw_linetmatch((s/usr/lib64/python2.7/nntplib.pyRfGs  cCsÕ|jd|ƒ}|d dkr2t|ƒ‚n|jƒ}d}}}t|ƒ}|dkrÂ|d}|dkrÂ|d}|dkr¿|d}|dkr¼|djƒ}q¼q¿qÂn|||||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,RRcRDtlower(RtnameR8twordstcounttfirsttlasttn((s/usr/lib64/python2.7/nntplib.pyR]Xs          cCs|jd|ƒS(soProcess a HELP command. Returns: - resp: server response if successful - list: list of stringstHELP(RX(RR(((s/usr/lib64/python2.7/nntplib.pythelprscCs‚|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.it22iRei(RRcRD(RR8RutnrtidRy((s/usr/lib64/python2.7/nntplib.pyt statparseys     cCs|j|ƒ}|j|ƒS(s/Internal: process a STAT, NEXT or LAST command.(R,R(RR?R8((s/usr/lib64/python2.7/nntplib.pytstatcmd‡scCs|jd|ƒS(sÎProcess 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~((s/usr/lib64/python2.7/nntplib.pytstatŒscCs |jdƒS(s;Process a NEXT command. No arguments. Return as for STAT.tNEXT(R€(R((s/usr/lib64/python2.7/nntplib.pytnext–scCs |jdƒS(s;Process a LAST command. No arguments. Return as for STAT.tLAST(R€(R((s/usr/lib64/python2.7/nntplib.pyRxšscCs@|j||ƒ\}}|j|ƒ\}}}||||fS(s2Internal: process a HEAD, BODY or ARTICLE command.(RXR(RR?R(R8RVR}R~((s/usr/lib64/python2.7/nntplib.pytartcmdžscCs|jd|ƒS(sôProcess 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~((s/usr/lib64/python2.7/nntplib.pythead¤s 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(((s/usr/lib64/python2.7/nntplib.pytbody¯s cCs|jd|ƒS(sïProcess 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~((s/usr/lib64/python2.7/nntplib.pytarticle¼s cCs |jdƒS(sPProcess a SLAVE command. Returns: - resp: server response if successfultSLAVE(R,(R((s/usr/lib64/python2.7/nntplib.pytslaveÇsc Cs’tjdƒ}|jd|d||ƒ\}}xRtt|ƒƒD]>}||}|j|ƒ} | rF| jddƒ||sP       !ÿÿ   !