Add a local implementation of httplib.SSLFile and httplib.FakeSocket

Python 2.6 changed its internal implementation which makes it difficult
to override in a way that is backwards compatible.

508953
This commit is contained in:
rcrit
2009-07-01 08:51:23 -04:00
committed by Rob Crittenden
parent 79029e8179
commit 9352d2fc10
3 changed files with 197 additions and 4 deletions
+9 -2
View File
@@ -27,6 +27,13 @@ import nss.io as io
import nss.nss as nss
import nss.ssl as ssl
try:
from httplib import SSLFile
from httplib import FakeSocket
except ImportError:
from ipapython.ipasslfile import SSLFile
from ipapython.ipasslfile import FakeSocket
def client_auth_data_callback(ca_names, chosen_nickname, password, certdb):
cert = None
if chosen_nickname:
@@ -49,7 +56,7 @@ def client_auth_data_callback(ca_names, chosen_nickname, password, certdb):
return False
return False
class SSLFile(httplib.SSLFile):
class SSLFile(SSLFile):
"""
Override the _read method so we can use the NSS recv method.
"""
@@ -64,7 +71,7 @@ class SSLFile(httplib.SSLFile):
break
return buf
class NSSFakeSocket(httplib.FakeSocket):
class NSSFakeSocket(FakeSocket):
def makefile(self, mode, bufsize=None):
if mode != 'r' and mode != 'rb':
raise httplib.UnimplementedFileMode()