Commit 146cc221 authored by Martijn Pieters's avatar Martijn Pieters

Separate clearing and closing a request.

Clearing frees resources, closing also sends out the end-request event. Clones
of the current request need to be cleared, only the actual current request
needs to be closed. Fixes LP #414757.
parent 5f08da6e
...@@ -51,6 +51,8 @@ Features Added ...@@ -51,6 +51,8 @@ Features Added
Bugs Fixed Bugs Fixed
++++++++++ ++++++++++
- LP #414757: Don't send a request closed event from a cloned request.
- LP #418454: FTP server did not work with Python 2.6.X - LP #418454: FTP server did not work with Python 2.6.X
- Fixed issue with sending text containing ':' from MailHost. - Fixed issue with sending text containing ':' from MailHost.
......
...@@ -206,11 +206,14 @@ class BaseRequest: ...@@ -206,11 +206,14 @@ class BaseRequest:
else: other.update(kw) else: other.update(kw)
self.other=other self.other=other
def close(self): def clear(self):
self.other.clear() self.other.clear()
notify(EndRequestEvent(None, self))
self._held=None self._held=None
def close(self):
self.clear()
notify(EndRequestEvent(None, self))
def processInputs(self): def processInputs(self):
"""Do any input processing that could raise errors """Do any input processing that could raise errors
""" """
......
...@@ -184,7 +184,7 @@ class HTTPRequest(BaseRequest): ...@@ -184,7 +184,7 @@ class HTTPRequest(BaseRequest):
r.retry_count = self.retry_count r.retry_count = self.retry_count
return r return r
def close(self): def clear(self):
# Clear all references to the input stream, possibly # Clear all references to the input stream, possibly
# removing tempfiles. # removing tempfiles.
self.stdin = None self.stdin = None
...@@ -194,7 +194,7 @@ class HTTPRequest(BaseRequest): ...@@ -194,7 +194,7 @@ class HTTPRequest(BaseRequest):
# one. Without this, there's the possibility of memory leaking # one. Without this, there's the possibility of memory leaking
# after every request. # after every request.
self._lazies = {} self._lazies = {}
BaseRequest.close(self) BaseRequest.clear(self)
def setServerURL(self, protocol=None, hostname=None, port=None): def setServerURL(self, protocol=None, hostname=None, port=None):
""" Set the parts of generated URLs. """ """ Set the parts of generated URLs. """
...@@ -1171,7 +1171,7 @@ class HTTPRequest(BaseRequest): ...@@ -1171,7 +1171,7 @@ class HTTPRequest(BaseRequest):
except: except:
rsp.exception() rsp.exception()
if object is None: if object is None:
req.close() req.clear()
raise rsp.errmsg, sys.exc_info()[1] raise rsp.errmsg, sys.exc_info()[1]
# The traversal machinery may return a "default object" # The traversal machinery may return a "default object"
...@@ -1191,7 +1191,7 @@ class HTTPRequest(BaseRequest): ...@@ -1191,7 +1191,7 @@ class HTTPRequest(BaseRequest):
if name != os.path.split(path)[-1]: if name != os.path.split(path)[-1]:
object = req.PARENTS[0] object = req.PARENTS[0]
req.close() req.clear()
return object return object
def clone(self): def clone(self):
......
...@@ -975,6 +975,19 @@ class HTTPRequestTests(unittest.TestCase): ...@@ -975,6 +975,19 @@ class HTTPRequestTests(unittest.TestCase):
clone = request.clone() clone = request.clone()
self.failUnless(IFoo.providedBy(clone)) self.failUnless(IFoo.providedBy(clone))
def test_resolve_url_doesnt_send_endrequestevent(self):
import zope.event
events = []
zope.event.subscribers.append(events.append)
request = self._makeOne()
request['PARENTS'] = [object()]
try:
request.resolve_url(request.script + '/')
finally:
zope.event.subscribers.remove(events.append)
self.failIf(len(events),
"HTTPRequest.resolve_url should not emit events")
TEST_ENVIRON = { TEST_ENVIRON = {
'CONTENT_TYPE': 'multipart/form-data; boundary=12345', 'CONTENT_TYPE': 'multipart/form-data; boundary=12345',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment