diff -U 3 -r Python-2.5.1/Doc/lib/libnntplib.tex Python-2.5.1-rlc/Doc/lib/libnntplib.tex --- Python-2.5.1/Doc/lib/libnntplib.tex 2006-03-17 11:26:31.000000000 -0500 +++ Python-2.5.1-rlc/Doc/lib/libnntplib.tex 2008-01-24 13:34:04.000000000 -0500 @@ -54,11 +54,15 @@ \begin{classdesc}{NNTP}{host\optional{, port \optional{, user\optional{, password - \optional{, readermode} - \optional{, usenetrc}}}}} + \optional{, readermode + \optional{, usenetrc + \optional{, usessl + \optional{, keyfile + \optional{, certfile}}}}}}}}} Return a new instance of the \class{NNTP} class, representing a connection to the NNTP server running on host \var{host}, listening at -port \var{port}. The default \var{port} is 119. If the optional +port \var{port}. The default \var{port} is 563 if \var{usessl} is \code{True}, +and 119 otherwise. If the optional \var{user} and \var{password} are provided, or if suitable credentials are present in \file{~/.netrc} and the optional flag \var{usenetrc} is true (the default), @@ -71,6 +75,9 @@ you get unexpected \exception{NNTPPermanentError}s, you might need to set \var{readermode}. \var{readermode} defaults to \code{None}. \var{usenetrc} defaults to \code{True}. +\var{usessl} defaults to \code{False}; if it is \code{True}, an SSL connection +is established, using \var{keyfile} and \var{certfile} (which both default to +\code{None}). \versionchanged[\var{usenetrc} argument added]{2.4} \end{classdesc} diff -U 3 -r Python-2.5.1/Lib/nntplib.py Python-2.5.1-rlc/Lib/nntplib.py --- Python-2.5.1/Lib/nntplib.py 2005-07-17 16:27:41.000000000 -0400 +++ Python-2.5.1-rlc/Lib/nntplib.py 2008-01-24 13:33:05.000000000 -0500 @@ -26,6 +26,7 @@ # RFC 977 by Brian Kantor and Phil Lapsley. # xover, xgtitle, xpath, date methods by Kevan Heydon +# ssl support by Aurojit Panda and Ray Chason # Imports @@ -78,6 +79,7 @@ # Standard port used by NNTP servers NNTP_PORT = 119 +NNTPS_PORT = 563 # Response numbers that are followed by additional text (e.g. article) @@ -91,8 +93,9 @@ # The class itself class NNTP: - def __init__(self, host, port=NNTP_PORT, user=None, password=None, - readermode=None, usenetrc=True): + def __init__(self, host, port=None, user=None, password=None, + readermode=None, usenetrc=True, usessl=False, keyfile=None, + certfile=None): """Initialize an instance. Arguments: - host: hostname to connect to - port: port to connect to (default the standard NNTP port) @@ -106,12 +109,24 @@ reader-specific comamnds, such as `group'. If you get unexpected NNTPPermanentErrors, you might need to set readermode. + - usessl: Boolean determining whether to use SSL + - keyfile: Private key to pass to ssl + - cerfile: Certificate to psss to ssl """ + if port is None: + if usessl: + port = NNTPS_PORT + else: + port = NNTP_PORT self.host = host self.port = port self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.connect((self.host, self.port)) - self.file = self.sock.makefile('rb') + if( usessl ): + self.ssl = socket.ssl(self.sock, keyfile, certfile) + else: + self.file = self.sock.makefile('rb') + self.ssl = None self.debugging = 0 self.welcome = self.getresp() @@ -191,8 +206,13 @@ """Internal: send one line to the server, appending CRLF.""" line = line + CRLF if self.debugging > 1: print '*put*', repr(line) - self.sock.sendall(line) - + if not self.ssl: + self.sock.sendall(line) + else: + while(len(line)>0): + sent=self.ssl.write(line) + line=line[sent:] + def putcmd(self, line): """Internal: send one command to the server (through putline()).""" if self.debugging: print '*cmd*', repr(line) @@ -201,7 +221,10 @@ def getline(self): """Internal: return one line from the server, stripping CRLF. Raise EOFError if the connection is closed.""" - line = self.file.readline() + if not self.ssl: + line = self.file.readline() + else: + line=self.ssl.read(80) #RFC997 restricts returns to 80 bytes if self.debugging > 1: print '*get*', repr(line) if not line: raise EOFError