• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python wsgi_intercept.add_wsgi_intercept函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中wsgi_intercept.add_wsgi_intercept函数的典型用法代码示例。如果您正苦于以下问题:Python add_wsgi_intercept函数的具体用法?Python add_wsgi_intercept怎么用?Python add_wsgi_intercept使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了add_wsgi_intercept函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: setup_module

def setup_module(module):
    # cleanup
    try:
        shutil.rmtree('store')
    except OSError:
        pass

    # establish web server
    app = load_app()
    def app_fn():
        return app
    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept('our_test_domain', 8001, app_fn)

    # establish store
    store = Store(config['server_store'][0], config['server_store'][1],
            environ={'tiddlyweb.config': config})

    # make some stuff
    bag = Bag('place')
    store.put(bag)
    for i in range(1, 10):
        tiddler = Tiddler('tiddler%s' % i, 'place')
        tiddler.text = 'hi%s'
        store.put(tiddler)

    module.http = httplib2.Http()
开发者ID:tiddlyweb,项目名称:tiddlywebplugins.etagcache,代码行数:27,代码来源:test_stress.py


示例2: browser

def browser(db_session, request, setup_app):
    """ returns an instance of `zope.testbrowser`.  The `kotti.testing.user`
        pytest marker (or `pytest.mark.user`) can be used to pre-authenticate
        the browser with the given login name: `@user('admin')`.
    """
    from wsgi_intercept import add_wsgi_intercept, zope_testbrowser
    from kotti.testing import BASE_URL

    host, port = BASE_URL.split(":")[-2:]
    add_wsgi_intercept(host[2:], int(port), lambda: setup_app)
    browser = zope_testbrowser.WSGI_Browser(BASE_URL + "/")
    if "user" in request.keywords:
        # set auth cookie directly on the browser instance...
        from pyramid.security import remember
        from pyramid.testing import DummyRequest

        login = request.keywords["user"].args[0]
        environ = dict(HTTP_HOST=host[2:])
        for _, value in remember(DummyRequest(environ=environ), login):
            cookie, _ = value.split(";", 1)
            name, value = cookie.split("=")
            if name in browser.cookies:
                del browser.cookies[name]
            browser.cookies.create(name, value.strip('"'), path="/")
    return browser
开发者ID:j23d,项目名称:Kotti,代码行数:25,代码来源:__init__.py


示例3: _initialize_app

def _initialize_app(tmpdir): # XXX: side-effecty and inscrutable
    instance_dir = os.path.join(tmpdir, 'instance')

    spawn(instance_dir, init_config, instance)
    old_cwd = os.getcwd()
    os.chdir(instance_dir)
    # force loading of instance's `tiddlywebconfig.py`
    while old_cwd in sys.path:
        sys.path.remove(old_cwd)
    sys.path.insert(0, os.getcwd())
    merge_config(CONFIG, {}, reconfig=True) # XXX: should not be necessary!?

    CONFIG['server_host'] = {
        'scheme': 'http',
        'host': 'example.org',
        'port': '8001',
    }
    # TODO: test with server_prefix

    # add symlink to templates -- XXX: hacky, should not be necessary!?
    templates_path = instance.__file__.split(os.path.sep)[:-2] + ['templates']
    os.symlink(os.path.sep.join(templates_path), 'templates')

    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept('example.org', 8001, load_app)
开发者ID:pads,项目名称:tiddlywebplugins.bfw,代码行数:25,代码来源:test_web.py


示例4: setup_module

def setup_module(module):
    module.store = Store('ramstore', {}, {})
    config['server_store'] = ['ramstore', {}]
    def app_fn():
        return serve.load_app()
    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept('our_test_domain', 8001, app_fn)
开发者ID:FND,项目名称:tiddlyweb-plugins-1,代码行数:7,代码来源:test_ramstore.py


示例5: __init__

 def __init__(self, app):
     self.app = app
     host = 'example.com'
     port = 80
     self.base = 'http://%s:%d' % (host, port)
     wsgi_intercept.add_wsgi_intercept(host, port, lambda: self.app)
     self.opener = urllib2.build_opener(WSGI_HTTPHandler())
开发者ID:dhain,项目名称:potpy,代码行数:7,代码来源:util.py


示例6: setup_module

def setup_module(module):
    from paste.script import testapp
    static_app = StaticURLParser(os.path.join(os.path.dirname(__file__),
                                              'test-static'))

    wsgi_intercept.add_wsgi_intercept('wsgify.org', 80, lambda : static_app)
    wsgi_intercept.add_wsgi_intercept('wsgify.org', 9999, lambda : testapp.TestApplication(text=True))
开发者ID:ailling,项目名称:webtest,代码行数:7,代码来源:rest-api-example.py


示例7: setup

    def setup(self, request, tmpdir):
        if ver(radicale.VERSION) < ver('2.0.0-pre'):
            raise RuntimeError('Testing against Radicale only works with '
                               'Radicale >= 2.0.0')

        def get_app():
            config = radicale.config.load(())
            config.set('storage', 'filesystem_folder', str(tmpdir))
            config.set('rights', 'type', 'owner_only')

            app = radicale.Application(config, logger)

            def is_authenticated(user, password):
                return user == 'bob' and password == 'bob'

            app.is_authenticated = is_authenticated
            return app

        wsgi_intercept.requests_intercept.install()
        wsgi_intercept.add_wsgi_intercept('127.0.0.1', 80, get_app)

        def teardown():
            wsgi_intercept.remove_wsgi_intercept('127.0.0.1', 80)
            wsgi_intercept.requests_intercept.uninstall()
        request.addfinalizer(teardown)
开发者ID:DamienCassou,项目名称:vdirsyncer,代码行数:25,代码来源:__init__.py


示例8: __init__

 def __init__(self, port=8000):
     """Initializes the mock server on localhost port 8000.  Use
     urllib2.urlopen('http://localhost:8000') to reach the test
     server.  The constructor takes a 'port=<int>' argument if you
     want the server to listen on a different port."""
     wsgi_intercept.add_wsgi_intercept('localhost', port, self.interceptor)
     wsgi_urllib2.install_opener()
开发者ID:Maseli,项目名称:fixofx,代码行数:7,代码来源:mock_http.py


示例9: setup_module

def setup_module(module):
    make_test_env(module)
    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept('0.0.0.0', 8080, app_fn)
    wsgi_intercept.add_wsgi_intercept('thing.0.0.0.0', 8080, app_fn)
    module.http = httplib2.Http()
    make_fake_space(store, 'thing')
开发者ID:Erls-Corporation,项目名称:tiddlyspace,代码行数:7,代码来源:test_web_status.py


示例10: setup_intercept

    def setup_intercept(self, callbacks, intercept_api=False):
        """Setup the WSGI intercepts.

        `callbacks` have to be provided to call upon request of the
        intercepted urls. They should be supplied as a dictionary of
        ((hostname, port), callback).

        Additionally one extra `default` callback has to be passed in,
        in the form ('default', callback).

        The `intercept_api` parameter is used to install the `httplib2`
        intercepts, used to intercept the lazr.restful api calls.
        """
        self.patch_wsgi_intercept()

        self.intercepted = []
        install_opener()

        self.intercept_api = intercept_api
        if intercept_api:
            install()

        for key, callback in callbacks.items():
            if key == 'default':
                continue
            host, port = key
            add_wsgi_intercept(host, port, callback)
            self.intercepted.append((host, port))
开发者ID:miing,项目名称:mci_migo_packages_u1-test-utils,代码行数:28,代码来源:wsgi_intercept.py


示例11: initialize_fakes

def initialize_fakes(app):
    # Set up WSGI interceptor. This sets up a fake host that responds each
    # time httplib tries to communicate to localhost, port 8779.
    def wsgi_interceptor(*args, **kwargs):

        def call_back(env, start_response):
            path_info = env.get('PATH_INFO')
            if path_info:
                env['PATH_INFO'] = urllib.unquote(path_info)
            #print("%s %s" % (args, kwargs))
            return app.__call__(env, start_response)

        return call_back

    wsgi_intercept.add_wsgi_intercept('localhost',
                                      CONF.bind_port,
                                      wsgi_interceptor)

    # Finally, engage in some truly evil monkey business. We want
    # to change anything which spawns threads with eventlet to instead simply
    # put those functions on a queue in memory. Then, we swap out any functions
    # which might try to take a nap to instead call functions that go through
    # this queue and call the functions that would normally run in seperate
    # threads.
    import eventlet
    from reddwarf.tests.fakes.common import event_simulator_sleep
    eventlet.sleep = event_simulator_sleep
    greenthread.sleep = event_simulator_sleep
    import time
    time.sleep = event_simulator_sleep
开发者ID:jeredding,项目名称:reddwarf,代码行数:30,代码来源:run_tests.py


示例12: setup_module

def setup_module(module):
    try:
        shutil.rmtree('indexdir')
        shutil.rmtree('store')
    except:
        pass
    app = load_app()

    def app_fn(): return app

    requests_intercept.install()
    wsgi_intercept.add_wsgi_intercept('tankt.peermore.com', 8080, app_fn)

    store = get_store(config)
    test_bag1 = Bag('newtank')

    try:
        store.delete(test_bag1)
    except StoreError:
        pass

    test_bag1.policy.accept = ['NONE']
    store.put(test_bag1)
    module.environ = {'tiddlyweb.store': store, 'tiddlyweb.config': config}
    module.store = store
    module.cookie, module.csrf = establish_user_auth(config, store,
            'tankt.peermore.com:8080', 'tester')
开发者ID:BillSeitz,项目名称:tank,代码行数:27,代码来源:test_closet.py


示例13: test_mozilla_auth

    def test_mozilla_auth(self):
        if not DO_TESTS:
            return

        wsgi_intercept.add_wsgi_intercept('localhost', 80, fake_response)
        auth = MozillaAuth('ldap://localhost',
                        'localhost', 'this_path', 'http')

        auth.create_user('tarek', 'tarek', '[email protected]')
        uid = auth.get_user_id('tarek')
        auth_uid = auth.authenticate_user('tarek', 'tarek')
        self.assertEquals(auth_uid, uid)

        #password change with no old password (sreg)
        self.assertTrue(auth.generate_reset_code(uid))
        self.assertTrue(auth.admin_update_password(uid, 'newpass', key='foo'))

        #password change with old password (ldap)
        self.assertTrue(auth.update_password(uid, 'newpass', 'tarek'))
        auth_uid = auth.authenticate_user('tarek', 'newpass')
        self.assertEquals(auth_uid, uid)

        self.assertEquals(auth.get_user_node(uid), 'foo')

        auth.clear_reset_code(uid)
        wsgi_intercept.add_wsgi_intercept('localhost', 80, bad_reset_code_resp)
        self.assertFalse(auth.admin_update_password(uid, 'newpass', key='foo'))
开发者ID:irslambouf,项目名称:SyncServer,代码行数:27,代码来源:test_mozilla.py


示例14: setup_module

def setup_module(module):

    module.store = get_store(config)

    # cascade to deal with differently named files depending on 
    # anydbm impelementation
    try:
        os.unlink('links.db')
    except OSError:
        pass  # not there
    module.links_manager = LinksManager()

    try:
        shutil.rmtree('store')
    except:
        pass
    
    def app():
        return serve.load_app()
    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept('0.0.0.0', 8080, app)

    # for @someone syntax to test correctly we need a corresponding
    # recipe
    module.store.put(Bag('cdent_public'))
    recipe = Recipe('cdent_public')
    recipe.set_recipe([('cdent_public', '')])
    module.store.put(recipe)
开发者ID:FND,项目名称:tiddlywebplugins.links,代码行数:28,代码来源:test_tiddler.py


示例15: get_storage_args

    def get_storage_args(self, request, get_item, tmpdir, etesync_app):
        import wsgi_intercept
        import wsgi_intercept.requests_intercept
        wsgi_intercept.requests_intercept.install()
        wsgi_intercept.add_wsgi_intercept('127.0.0.1', 8000,
                                          lambda: etesync_app)

        def teardown():
            wsgi_intercept.remove_wsgi_intercept('127.0.0.1', 8000)
            wsgi_intercept.requests_intercept.uninstall()

        request.addfinalizer(teardown)

        with open(os.path.join(os.path.dirname(__file__),
                               '[email protected]/auth_token')) as f:
            token = f.read().strip()
        headers = {'Authorization': 'Token ' + token}
        r = requests.post('http://127.0.0.1:8000/reset/', headers=headers,
                          allow_redirects=False)
        assert r.status_code == 200

        def inner(collection='test'):
            rv = {
                'email': '[email protected]',
                'db_path': str(tmpdir.join('etesync.db')),
                'secrets_dir': os.path.dirname(__file__),
                'server_url': 'http://127.0.0.1:8000/'
            }
            if collection is not None:
                rv = self.storage_class.create_collection(
                    collection=collection,
                    **rv
                )
            return rv
        return inner
开发者ID:DamienCassou,项目名称:vdirsyncer,代码行数:35,代码来源:test_main.py


示例16: initialize_app

def initialize_app():
    app = load_app()
    def app_fn():
        return app

    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept('our_test_domain', 8001, app_fn)
开发者ID:chancejiang,项目名称:tiddlyweb,代码行数:7,代码来源:fixtures.py


示例17: get_storage_args

    def get_storage_args(self, request, tmpdir, slow_create_collection):
        tmpdir.mkdir('xandikos')
        backend = XandikosBackend(path=str(tmpdir))
        cup = '/user/'
        backend.create_principal(cup, create_defaults=True)
        app = XandikosApp(backend, cup)

        app = WellknownRedirector(app, '/')

        wsgi_intercept.requests_intercept.install()
        wsgi_intercept.add_wsgi_intercept('127.0.0.1', 8080, lambda: app)

        def teardown():
            wsgi_intercept.remove_wsgi_intercept('127.0.0.1', 8080)
            wsgi_intercept.requests_intercept.uninstall()
        request.addfinalizer(teardown)

        def inner(collection='test'):
            url = 'http://127.0.0.1:8080/'
            args = {'url': url, 'collection': collection}

            if collection is not None:
                args = self.storage_class.create_collection(**args)
            return args
        return inner
开发者ID:DamienCassou,项目名称:vdirsyncer,代码行数:25,代码来源:__init__.py


示例18: test_reset_code_sreg

    def test_reset_code_sreg(self):
        try:
            import wsgi_intercept
            from wsgi_intercept.urllib2_intercept import install_opener
            install_opener()
        except ImportError:
            return

        def _fake_response():
            return Response('0')

        def _no_email_response():
            r = Response()
            r.status = '400 Bad Request'
            r.body = str(ERROR_NO_EMAIL_ADDRESS)
            return r

        config = {'backend': 'services.resetcodes.rc_sreg.ResetCodeSreg',
                  'sreg_location': 'localhost',
                  'sreg_path': '',
                  'sreg_scheme': 'http'}

        mgr = load_and_configure(config)
        user = User()
        user['userid'] = 1
        user['username'] = 'telliott'

        wsgi_intercept.add_wsgi_intercept('localhost', 80, _fake_response)
        self.assertRaises(AlreadySentError, mgr.generate_reset_code, user)

        wsgi_intercept.add_wsgi_intercept('localhost', 80, _no_email_response)
        self.assertRaises(NoEmailError, mgr.generate_reset_code, user)
开发者ID:irslambouf,项目名称:SyncServer,代码行数:32,代码来源:test_resetcode.py


示例19: setup_module

def setup_module(module):
    try:
        shutil.rmtree('store')
    except:
        pass # !!!
    config['server_host'] = {
            'host': 'our_test_domain',
            'port': '8001',
            'scheme': 'http',
            }
    from tiddlyweb.web import serve
    # we have to have a function that returns the callable,
    # Selector just _is_ the callable
    def app_fn():
        return serve.load_app()
    #wsgi_intercept.debuglevel = 1
    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept('our_test_domain', 8001, app_fn)

    environ = {'tiddlyweb.config': config}
    module.store = Store(config['server_store'][0], config['server_store'][1], environ)

    admin = User('admin')
    admin.add_role('ADMIN')
    admin.set_password('spank')
    module.store.put(admin)
    module.admin_authorization = b64encode('admin:spank')
    module.user_authorization = b64encode('cdent:pigdog')
开发者ID:FND,项目名称:tiddlyspace.old,代码行数:28,代码来源:test_web_user.py


示例20: test_cookie_session_middleware

def test_cookie_session_middleware():
    user = user_module.User()
    user._update_data(FAKE_USER_DATA)
    user_module.thread_locals.current_user = user

    app = CookieSessionMiddleware(application, b'wtf!', expires=3600, max_age=3600)
    add_wsgi_intercept(HOST, PORT, lambda: app)

    response = requests.get(URL)
    assert response.cookies['leancloud:session']

    del user_module.thread_locals.current_user
    requests.get(URL, cookies=response.cookies)
    current = user_module.User.get_current()
    assert current.id == user.id
    assert current.get_session_token() == user.get_session_token()
    assert not current._attributes

    del user_module.thread_locals.current_user
    response = requests.get(URL + '/logout', cookies=response.cookies)
    assert 'leancloud:session' not in response.cookies

    # TODO: try not using for..in to get cookie
    for cookie in response.cookies:
        if cookie.name == "leancloud:session":
            assert cookie.expires
            assert cookie.max_age
            break

    remove_wsgi_intercept()
开发者ID:leancloud,项目名称:python-sdk,代码行数:30,代码来源:test_middlewares.py



注:本文中的wsgi_intercept.add_wsgi_intercept函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python wsgi_intercept.remove_wsgi_intercept函数代码示例发布时间:2022-05-26
下一篇:
Python database.MySQLDatabase类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap