avoid _wsgioutputfile <-> _wsgirequest circular reference
We use the _wsgirequest object itself as the output file object.
To avoid a "self.out = self" which would create another circular
reference, we make the "out" attribute a trivial property.
--- a/mercurial/hgweb/request.py Mon Mar 19 19:07:38 2007 -0300
+++ b/mercurial/hgweb/request.py Mon Mar 19 19:07:39 2007 -0300
@@ -17,20 +17,6 @@
def __call__(self, wsgienv, start_response):
return _wsgirequest(self.destmaker(), wsgienv, start_response)
-class _wsgioutputfile(object):
- def __init__(self, request):
- self.request = request
-
- def write(self, data):
- self.request.write(data)
- def writelines(self, lines):
- for line in lines:
- self.write(line)
- def flush(self):
- return None
- def close(self):
- return None
-
class _wsgirequest(object):
def __init__(self, destination, wsgienv, start_response):
version = wsgienv['wsgi.version']
@@ -38,7 +24,6 @@
raise RuntimeError("Unknown and unsupported WSGI version %d.%d" \
% version)
self.inp = wsgienv['wsgi.input']
- self.out = _wsgioutputfile(self)
self.server_write = None
self.err = wsgienv['wsgi.errors']
self.threaded = wsgienv['wsgi.multithread']
@@ -50,6 +35,8 @@
self.headers = []
destination.run_wsgi(self)
+ out = property(lambda self: self)
+
def __iter__(self):
return iter([])
@@ -76,6 +63,16 @@
if inst[0] != errno.ECONNRESET:
raise
+ def writelines(self, lines):
+ for line in lines:
+ self.write(line)
+
+ def flush(self):
+ return None
+
+ def close(self):
+ return None
+
def header(self, headers=[('Content-type','text/html')]):
self.headers.extend(headers)