Fixed failing test by adding new makefile() method to GreenSSL.
This commit is contained in:
@@ -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)
|
||||
|
@@ -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()
|
||||
|
@@ -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__':
|
||||
|
Reference in New Issue
Block a user