def call(self, method, args=(), errorValue=ERROR_MARKER): path = self.servicePath[:] + [method] response = Response() env = { 'SERVER_NAME': 'dummy', 'SERVER_PORT': '8080', 'PATH_INFO': '/' + '/'.join(path) } request = HTTPRequest(None, env, response) request.args = args conn = self.db.open() root = conn.root() request['PARENTS'] = [root['Application']] try: try: ZPublisher.Publish.publish(request, 'Zope2', [None]) except Exception, error: # This thread should never crash, thus a blank except log.error('Processor: ``%s()`` caused an error!' % method) log.exception(error) return errorValue is ERROR_MARKER and error or errorValue finally: request.close() conn.close() return request.response.body
def testRemoveStdinReferences(self): # Verifies that all references to the input stream go away on # request.close(). Otherwise a tempfile may stick around. import sys from StringIO import StringIO s = StringIO(TEST_FILE_DATA) env = TEST_ENVIRON.copy() start_count = sys.getrefcount(s) from ZPublisher.HTTPRequest import HTTPRequest req = HTTPRequest(s, env, None) req.processInputs() self.assertNotEqual(start_count, sys.getrefcount(s)) # Precondition req.close() self.assertEqual(start_count, sys.getrefcount(s)) # The test
def publish_module_standard(module_name, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, environ=os.environ, debug=0, request=None, response=None): must_die = 0 status = 200 after_list = [None] try: try: if response is None: response = Response(stdout=stdout, stderr=stderr) else: stdout = response.stdout # debug is just used by tests (has nothing to do with debug_mode!) response.handle_errors = not debug if request is None: request = Request(stdin, environ, response) setRequest(request) # make sure that the request we hand over has the # default layer/skin set on it; subsequent code that # wants to look up views will likely depend on it if ISkinnable.providedBy(request): setDefaultSkin(request) response = publish(request, module_name, after_list, debug=debug) except (SystemExit, ImportError): # XXX: Rendered ImportErrors were never caught here because they # were re-raised as string exceptions. Maybe we should handle # ImportErrors like all other exceptions. Currently they are not # re-raised at all, so they don't show up here. must_die = sys.exc_info() request.response.exception(1) except: # debug is just used by tests (has nothing to do with debug_mode!) if debug: raise request.response.exception() status = response.getStatus() if response: outputBody = getattr(response, 'outputBody', None) if outputBody is not None: outputBody() else: response = str(response) if response: stdout.write(response) # The module defined a post-access function, call it if after_list[0] is not None: after_list[0]() finally: if request is not None: request.close() clearRequest() if must_die: # Try to turn exception value into an exit code. try: if hasattr(must_die[1], 'code'): code = must_die[1].code else: code = int(must_die[1]) except: code = must_die[1] and 1 or 0 if hasattr(request.response, '_requestShutdown'): request.response._requestShutdown(code) try: reraise(must_die[0], must_die[1], must_die[2]) finally: must_die = None return status
def publish_module_standard( module_name, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr, environ=os.environ, debug=0, request=None, response=None): must_die = 0 status = 200 after_list = [None] try: try: if response is None: response = Response(stdout=stdout, stderr=stderr) else: stdout = response.stdout # debug is just used by tests (has nothing to do with debug_mode!) response.handle_errors = not debug if request is None: request = Request(stdin, environ, response) setRequest(request) # make sure that the request we hand over has the # default layer/skin set on it; subsequent code that # wants to look up views will likely depend on it if ISkinnable.providedBy(request): setDefaultSkin(request) response = publish(request, module_name, after_list, debug=debug) except (SystemExit, ImportError): # XXX: Rendered ImportErrors were never caught here because they # were re-raised as string exceptions. Maybe we should handle # ImportErrors like all other exceptions. Currently they are not # re-raised at all, so they don't show up here. must_die = sys.exc_info() request.response.exception(1) except: # debug is just used by tests (has nothing to do with debug_mode!) if debug: raise request.response.exception() status = response.getStatus() if response: outputBody = getattr(response, 'outputBody', None) if outputBody is not None: outputBody() else: response = str(response) if response: stdout.write(response) # The module defined a post-access function, call it if after_list[0] is not None: after_list[0]() finally: if request is not None: request.close() clearRequest() if must_die: # Try to turn exception value into an exit code. try: if hasattr(must_die[1], 'code'): code = must_die[1].code else: code = int(must_die[1]) except: code = must_die[1] and 1 or 0 if hasattr(request.response, '_requestShutdown'): request.response._requestShutdown(code) try: reraise(must_die[0], must_die[1], must_die[2]) finally: must_die = None return status