Ticket #309: localwrap.diff
-
test/helper.py
old new 101 101 if body is not None: 102 102 body = StringIO.StringIO(body) 103 103 104 cherrypy.request.purge__() 105 cherrypy.response.purge__() 106 cherrypy.threadData.purge__() 107 104 108 cherrypy.server.request((self.HOST, self.PORT), self.HOST, 105 109 requestLine, headers, body, "http") 106 110 -
test/test_core.py
old new 253 253 254 254 def upload(self, file): 255 255 return "Size: %s" % len(file.file.read()) 256 257 class ThreadData(Test): 258 259 def index(self): 260 existing = repr(getattr(cherrypy.threadData, "asdf", None)) 261 cherrypy.threadData.asdf = "hello" 262 return existing 263 256 264 257 265 logFile = os.path.join(localDir, "error.log") 258 266 logAccessFile = os.path.join(localDir, "access.log") … … 309 317 ('/foo/bar', 'baz', 'that2'), 310 318 ('/foo/nex', 'baz', 'that2'), 311 319 ] 320 cherrypy.request.purge__() 312 321 for path, key, expected in tests: 313 322 cherrypy.request.path = path 314 323 result = cherrypy.config.get(key, None) … … 668 677 self.getPage('/maxrequestsize/upload', h, "POST", b) 669 678 self.assertStatus("413 Request Entity Too Large") 670 679 self.assertInBody("Request Entity Too Large") 680 681 def testEmptyThreadlocals(self): 682 results = [] 683 for x in xrange(20): 684 self.getPage("/threaddata/") 685 results.append(self.body) 686 self.assertEqual(results, ["None"] * 20) 687 671 688 672 689 if __name__ == '__main__': 673 690 helper.testmain() -
_cphttpserver.py
old new 81 81 if not self.parse_request(): # An error code has been sent, just exit 82 82 return 83 83 84 cherrypy.request.purge__() 85 cherrypy.response.purge__() 86 cherrypy.threadData.purge__() 87 84 88 cherrypy.request.multithread = cherrypy.config.get("server.threadPool") > 1 85 89 cherrypy.request.multiprocess = False 86 90 cherrypy.server.request(self.client_address, -
_cpwsgi.py
old new 88 88 sys.stderr = NullWriter() 89 89 90 90 try: 91 cherrypy.request.purge__() 92 cherrypy.response.purge__() 93 cherrypy.threadData.purge__() 94 91 95 # LOGON_USER is served by IIS, and is the name of the 92 96 # user after having been mapped to a local account. 93 97 # Both IIS and Apache set REMOTE_USER, when possible. -
__init__.py
old new 53 53 from threading import local 54 54 except ImportError: 55 55 from cherrypy._cpthreadinglocal import local 56 57 # Create a threadlocal object to hold the request, response, 58 # and threadData objects. In this way, we can easily dump 59 # those objects when we stop/start a new HTTP conversation. 60 serving = local() 61 62 class _AttributeDump: 63 pass 56 64 65 class _ThreadLocalWrapper: 66 67 def __init__(self, attrname): 68 self.__dict__["__attrname__"] = attrname 69 70 def purge__(self): 71 """Make a new, emtpy proxied object in cherrypy.serving.""" 72 setattr(serving, self.__attrname__, _AttributeDump()) 73 74 def __getattr__(self, name): 75 childobject = getattr(serving, self.__attrname__) 76 return getattr(childobject, name) 77 78 def __setattr__(self, name, value): 79 childobject = getattr(serving, self.__attrname__) 80 setattr(childobject, name, value) 81 82 def __delattr__(self, name): 83 childobject = getattr(serving, self.__attrname__) 84 delattr(childobject, name) 85 86 57 87 # Create request and response object (the same objects will be used 58 # throughout the entire life of the webserver) 59 request = local() 60 response = local() 88 # throughout the entire life of the webserver, but will redirect 89 # to the "serving" object) 90 request = _ThreadLocalWrapper('request') 91 response = _ThreadLocalWrapper('response') 61 92 62 93 # Create threadData object as a thread-specific all-purpose storage 63 threadData = local()94 threadData = _ThreadLocalWrapper('threadData') 64 95 65 96 # Create variables needed for session (see lib/sessionfilter.py for more info) 66 97 from lib.filter import sessionfilter

