--- /Users/aurojit/Downloads/nntplib.py 2006-08-06 19:09:23.000000000 -0400 +++ nntpslib.py 2006-08-06 22:32:04.000000000 -0400 @@ -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 # Imports @@ -92,7 +93,8 @@ # The class itself class NNTP: def __init__(self, host, port=NNTP_PORT, user=None, password=None, - readermode=None, usenetrc=True): + 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 +108,18 @@ 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 """ 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.debugging = 0 self.welcome = self.getresp() @@ -191,8 +199,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 +214,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