# HG changeset patch # User Alexis S. L. Carvalho # Date 2007-03-19 22:07:39 # Node ID cc81c512a5316a025f2ca8bb0c1113b5d28b83bb # Parent bd46b83b9692809e1cee1bf40f620a95764b86e4 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. diff --git a/mercurial/hgweb/request.py b/mercurial/hgweb/request.py --- a/mercurial/hgweb/request.py +++ b/mercurial/hgweb/request.py @@ -17,20 +17,6 @@ class wsgiapplication(object): 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 @@ class _wsgirequest(object): 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 @@ class _wsgirequest(object): self.headers = [] destination.run_wsgi(self) + out = property(lambda self: self) + def __iter__(self): return iter([]) @@ -76,6 +63,16 @@ class _wsgirequest(object): 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)