Example #1
0
def fake_request(pylons_config,
                 server_name='mediacore.example',
                 language='en',
                 method='GET',
                 request_uri='/',
                 post_vars=None):
    app_globals = pylons_config['pylons.app_globals']
    pylons.app_globals._push_object(app_globals)

    if post_vars and method.upper() != 'POST':
        raise ValueError(
            'You must not specify post_vars for request method %r' % method)
    wsgi_environ = create_wsgi_environ('http://%s%s' %
                                       (server_name, request_uri),
                                       method.upper(),
                                       request_body=post_vars)
    request = Request(wsgi_environ, charset='utf-8')
    request.language = language
    request.settings = app_globals.settings
    pylons.request._push_object(request)
    response = Response(content_type='application/xml', charset='utf-8')
    pylons.response._push_object(response)

    session = SessionObject(wsgi_environ)
    pylons.session._push_object(session)

    routes_url = URLGenerator(pylons_config['routes.map'], wsgi_environ)
    pylons.url._push_object(routes_url)

    # Use ContextObj() when we get rid of 'pylons.strict_tmpl_context=False' in
    # mediacore.lib.environment
    tmpl_context = AttribSafeContextObj()
    tmpl_context.paginators = Bunch()
    pylons.tmpl_context._push_object(tmpl_context)
    # some parts of Pylons (e.g. Pylons.controllers.core.WSGIController)
    # use the '.c' alias instead.
    pylons.c = pylons.tmpl_context

    paste_registry = Registry()
    paste_registry.prepare()
    engines = create_tw_engine_manager(app_globals)
    host_framework = PylonsHostFramework(engines=engines)
    paste_registry.register(tw.framework, host_framework)
    setup_translator(language=language, registry=paste_registry)

    wsgi_environ.update({
        'pylons.pylons': pylons,
        'paste.registry': paste_registry,
    })
    return request
Example #2
0
def fake_request(pylons_config, server_name='mediadrop.example', language='en',
                 method='GET', request_uri='/', post_vars=None):
    app_globals = pylons_config['pylons.app_globals']
    pylons.app_globals._push_object(app_globals)
    
    if post_vars and method.upper() != 'POST':
        raise ValueError('You must not specify post_vars for request method %r' % method)
    wsgi_environ = create_wsgi_environ('http://%s%s' % (server_name, request_uri),
        method.upper(), request_body=post_vars)
    request = Request(wsgi_environ, charset='utf-8')
    request.language = language
    request.settings = app_globals.settings
    pylons.request._push_object(request)
    response = Response(content_type='application/xml', charset='utf-8')
    pylons.response._push_object(response)
    
    session = SessionObject(wsgi_environ)
    pylons.session._push_object(session)

    routes_url = URLGenerator(pylons_config['routes.map'], wsgi_environ)
    pylons.url._push_object(routes_url)

    # TODO: Use ContextObj() for Pylons 0.10
    tmpl_context = AttribSafeContextObj()
    tmpl_context.paginators = Bunch()
    pylons.tmpl_context._push_object(tmpl_context)
    # some parts of Pylons (e.g. Pylons.controllers.core.WSGIController)
    # use the '.c' alias instead.
    pylons.c = pylons.tmpl_context
    
    paste_registry = Registry()
    paste_registry.prepare()
    engines = create_tw_engine_manager(app_globals)
    host_framework = PylonsHostFramework(engines=engines)
    paste_registry.register(tw.framework, host_framework)
    
    mediacore_i18n_path = os.path.join(os.path.dirname(mediacore.__file__), 'i18n')
    translator = Translator(language, dict(mediacore=mediacore_i18n_path))
    # not sure why but sometimes pylons.translator is not a StackedObjectProxy
    # but just a regular Translator.
    if not hasattr(pylons.translator, '_push_object'):
        pylons.translator = StackedObjectProxy()
    paste_registry.replace(pylons.translator, translator)
    
    wsgi_environ.update({
        'pylons.pylons': pylons,
        'paste.registry': paste_registry,
    })
    return request
def fake_request(pylons_config, server_name='mediacore.example', language='en', 
                 method='GET', request_uri='/', post_vars=None):
    app_globals = pylons_config['pylons.app_globals']
    pylons.app_globals._push_object(app_globals)
    
    if post_vars and method.upper() != 'POST':
        raise ValueError('You must not specify post_vars for request method %r' % method)
    wsgi_environ = create_wsgi_environ('http://%s%s' % (server_name, request_uri),
        method.upper(), request_body=post_vars)
    request = Request(wsgi_environ, charset='utf-8')
    request.language = language
    request.settings = app_globals.settings
    pylons.request._push_object(request)
    response = Response(content_type='application/xml', charset='utf-8')
    pylons.response._push_object(response)
    
    session = SessionObject(wsgi_environ)
    pylons.session._push_object(session)

    routes_url = URLGenerator(pylons_config['routes.map'], wsgi_environ)
    pylons.url._push_object(routes_url)

    # Use ContextObj() when we get rid of 'pylons.strict_tmpl_context=False' in
    # mediacore.lib.environment
    tmpl_context = AttribSafeContextObj()
    tmpl_context.paginators = Bunch()
    pylons.tmpl_context._push_object(tmpl_context)
    # some parts of Pylons (e.g. Pylons.controllers.core.WSGIController)
    # use the '.c' alias instead.
    pylons.c = pylons.tmpl_context
    
    paste_registry = Registry()
    paste_registry.prepare()
    engines = create_tw_engine_manager(app_globals)
    host_framework = PylonsHostFramework(engines=engines)
    paste_registry.register(tw.framework, host_framework)
    setup_translator(language=language, registry=paste_registry,
        locale_dirs=pylons_config.get('locale_dirs'))
    
    wsgi_environ.update({
        'pylons.pylons': pylons,
        'paste.registry': paste_registry,
    })
    return request