Fixed failing test by adding new makefile() method to GreenSSL.

This commit is contained in:
Ryan Williams
2009-05-28 19:59:52 -07:00
parent 6f0cb1573b
commit abda8d075b
3 changed files with 40 additions and 6 deletions

View File

@@ -531,10 +531,30 @@ class GreenPipe(GreenFile):
self.fd.fd.flush()
class RefCount(object):
""" Reference counting class only to be used with GreenSSL objects """
def __init__(self):
self._count = 1
def increment(self):
self._count += 1
def decrement(self):
self._count -= 1
assert self._count >= 0
def is_referenced(self):
return self._count > 0
class GreenSSL(GreenSocket):
def __init__(self, fd):
def __init__(self, fd, refcount = None):
GreenSocket.__init__(self, fd)
self.sock = self
self._refcount = refcount
if refcount is None:
self._refcount = RefCount()
read = read
@@ -550,7 +570,21 @@ class GreenSSL(GreenSocket):
def issuer(self):
return self.fd.issuer()
def dup(self):
raise NotImplemented("Dup not supported on SSL sockets")
def makefile(self, *args, **kw):
self._refcount.increment()
return GreenFile(type(self)(self.fd, refcount = self._refcount))
def close(self):
self._refcount.decrement()
if self._refcount.is_referenced():
return
super(GreenSSL, self).close()
def socketpair(*args):
one, two = socket.socketpair(*args)

View File

@@ -586,6 +586,9 @@ class HttpSuite(object):
def _get_response_body(self, params, connection):
if connection is None:
connection = connect(params.url, params.use_proxy)
# if we're creating a new connection we know the caller
# isn't going to reuse it
params.headers['connection'] = 'close'
connection.request(params.method, params.path, params.body,
params.headers)
params.response = connection.getresponse()

View File

@@ -267,9 +267,8 @@ class TestHttpd(tests.TestCase):
def test_012_ssl_server(self):
from eventlet import httpc
def wsgi_app(self, environ, start_response):
print "wsgi_app"
print environ['wsgi.input']
def wsgi_app(environ, start_response):
start_response('200 OK', {})
return [environ['wsgi.input'].read()]
certificate_file = os.path.join(os.path.dirname(__file__), 'test_server.crt')
@@ -279,10 +278,8 @@ class TestHttpd(tests.TestCase):
api.spawn(wsgi.server, sock, wsgi_app)
print "pre request"
result = httpc.post("https://localhost:4201/foo", "abc")
self.assertEquals(result, 'abc')
print "post request"
if __name__ == '__main__':