# HG changeset patch # User Dirkjan Ochtman # Date 1200682418 -3600 # Node ID 956afc025c0fa061efb16177f8983439008642bd # Parent 41a3fce17625e6c675ff84ce848bff27b01a70f8 hgweb: separate out start_response() calling diff -r 41a3fce17625 -r 956afc025c0f mercurial/hgweb/request.py --- a/mercurial/hgweb/request.py Fri Jan 18 19:53:38 2008 +0100 +++ b/mercurial/hgweb/request.py Fri Jan 18 19:53:38 2008 +0100 @@ -24,7 +24,7 @@ self.run_once = wsgienv['wsgi.run_once'] self.env = wsgienv self.form = cgi.parse(self.inp, self.env, keep_blank_values=1) - self.start_response = start_response + self._start_response = start_response self.headers = [] def __iter__(self): @@ -33,24 +33,31 @@ def read(self, count=-1): return self.inp.read(count) + def start_response(self, status): + if self._start_response is not None: + if not self.headers: + raise RuntimeError("request.write called before headers sent" + + " (%s)." % thing) + + if isinstance(status, ErrorResponse): + status = statusmessage(status.code) + elif isinstance(status, int): + status = statusmessage(status) + + self.server_write = self._start_response(status, self.headers) + self._start_response = None + self.headers = [] + def respond(self, status, *things): + if not things: + self.start_response(status) for thing in things: if hasattr(thing, "__iter__"): for part in thing: self.respond(status, part) else: thing = str(thing) - if self.server_write is None: - if not self.headers: - raise RuntimeError("request.write called before headers sent (%s)." % thing) - if isinstance(status, ErrorResponse): - status = statusmessage(status.code) - elif isinstance(status, int): - status = statusmessage(status) - self.server_write = self.start_response(status, - self.headers) - self.start_response = None - self.headers = [] + self.start_response(status) try: self.server_write(thing) except socket.error, inst: