def get_request_and_publication(host='localhost', port=None, method='GET', mime_type='text/html', in_stream='', extra_environment=None): """Helper method that return the IRequest and IPublication for a request. This method emulates what the Zope publisher would do to find the request and publication class for a particular environment. """ environment = { 'HTTP_HOST': host, 'REQUEST_METHOD': method, 'SERVER_PORT': port, 'CONTENT_TYPE': mime_type } if extra_environment is not None: environment.update(extra_environment) launchpad_factory = factoryRegistry.lookup(method, mime_type, environment) request_factory, publication_factory = launchpad_factory() request = request_factory(StringIO(in_stream), environment) # Since Launchpad doesn't use ZODB, we use None here. publication = publication_factory(None) return request, publication
def chooseClasses(method, environment): """Given the method and environment, choose the correct request and publication factory.""" content_type = environment.get('CONTENT_TYPE', '') factory = factoryRegistry.lookup(method, content_type, environment) request_class, publication = factory() return request_class, publication
def get_request_and_publication(host='localhost', port=None, method='GET', mime_type='text/html', in_stream='', extra_environment=None): """Helper method that return the IRequest and IPublication for a request. This method emulates what the Zope publisher would do to find the request and publication class for a particular environment. """ environment = {'HTTP_HOST': host, 'REQUEST_METHOD': method, 'SERVER_PORT': port, 'CONTENT_TYPE': mime_type} if extra_environment is not None: environment.update(extra_environment) launchpad_factory = factoryRegistry.lookup( method, mime_type, environment) request_factory, publication_factory = launchpad_factory() request = request_factory(StringIO(in_stream), environment) # Since Launchpad doesn't use ZODB, we use None here. publication = publication_factory(None) return request, publication