Mercurial > p > roundup > code
diff test/rest_common.py @ 5656:d26d2590cd8c
Implement different workaround for https://bugs.python.org/issue27777
suggested by jsm/Joseph Myers.
Subclass cgi.FieldStorage into BinaryFieldStorage and use that class
rather then monkey patching cgi.FieldStorage.make_file. This should
eliminate race conditions issues inherent with the prior way I tried
to do it by flipping the class method back and forth at runtime.
Also import new class into rest_common.py and use it in place of old
mechanism.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Tue, 19 Mar 2019 21:58:49 -0400 |
| parents | 207e0f5d551c |
| children | a4bb88a1a643 a7211712b110 |
line wrap: on
line diff
--- a/test/rest_common.py Mon Mar 18 21:42:33 2019 -0400 +++ b/test/rest_common.py Tue Mar 19 21:58:49 2019 -0400 @@ -399,11 +399,6 @@ else: self.assertEqual(self.dummy_client.response_code, 412) - def make_file(self, arg=None): - ''' work around https://bugs.python.org/issue27777 ''' - import tempfile - return tempfile.TemporaryFile("wb+") - def testDispatch(self): """ run changes through rest dispatch(). This also tests @@ -412,12 +407,6 @@ process. """ - # Override the make_file so it is always set to binary - # read mode. This is needed so we can send a json - # body. - saved_make_file = cgi.FieldStorage.make_file - cgi.FieldStorage.make_file = self.make_file - # TEST #1 # PUT: joe's 'realname' using json data. # simulate: /rest/data/user/<id>/realname @@ -438,7 +427,7 @@ # FieldStorage(None, None, 'string') rather than # FieldStorage(None, None, []) body_file=BytesIO(body) # FieldStorage needs a file - form = cgi.FieldStorage(body_file, + form = client.BinaryFieldStorage(body_file, headers=headers, environ=env) self.server.client.request.headers.get=self.get_header @@ -465,7 +454,7 @@ } self.headers=None # have FieldStorage get len from env. body_file=BytesIO(body) # FieldStorage needs a file - form = cgi.FieldStorage(body_file, + form = client.BinaryFieldStorage(body_file, headers=None, environ=env) self.server.client.request.headers.get=self.get_header @@ -544,7 +533,7 @@ } self.headers=headers body_file=BytesIO(body) # FieldStorage needs a file - form = cgi.FieldStorage(body_file, + form = client.BinaryFieldStorage(body_file, headers=headers, environ=env) self.server.client.request.headers.get=self.get_header @@ -565,7 +554,7 @@ etag)) # reuse env and headers from prior test. body_file=BytesIO(body) # FieldStorage needs a file - form = cgi.FieldStorage(body_file, + form = client.BinaryFieldStorage(body_file, headers=headers, environ=env) self.server.client.request.headers.get=self.get_header @@ -598,7 +587,7 @@ } self.headers=headers body_file=BytesIO(body) # FieldStorage needs a file - form = cgi.FieldStorage(body_file, + form = client.BinaryFieldStorage(body_file, headers=headers, environ=env) self.server.client.request.headers.get=self.get_header @@ -617,9 +606,6 @@ 'foo bar') del(self.headers) - # reset the make_file method in the class - cgi.FieldStorage.make_file = saved_make_file - def testPut(self): """ Change joe's 'realname'
