当前位置: 首页>>代码示例>>Python>>正文


Python Response.location方法代码示例

本文整理汇总了Python中webob.Response.location方法的典型用法代码示例。如果您正苦于以下问题:Python Response.location方法的具体用法?Python Response.location怎么用?Python Response.location使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在webob.Response的用法示例。


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

示例1: test_location

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import location [as 别名]
def test_location():
    # covers webob/response.py:934-938
    res = Response()
    res.location = '/test.html'
    eq_(res.location, '/test.html')
    req = Request.blank('/')
    eq_(req.get_response(res).location, 'http://localhost/test.html')
    res.location = '/test2.html'
    eq_(req.get_response(res).location, 'http://localhost/test2.html')
开发者ID:GdZ,项目名称:scriptfile,代码行数:11,代码来源:test_response.py

示例2: identify

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import location [as 别名]
    def identify(self, environ):
        user = {}
        request = Request(environ)

        log.debug("Request path: %s" % request.path)
        log.debug(request)
        log.debug(environ)

        # Logout user
        if request.path == self.logout_url:
            response = Response()

            for a, v in self.forget(environ, {}):
                response.headers.add(a, v)

            response.status = 302
            response.location = url_for(controller="user", action="logged_out")
            environ["repoze.who.application"] = response

            return {}

        # Login user, if there's shibboleth headers and path is shiblogin
        if self.is_shib_session(environ) and request.path == self.login_url:
            log.debug("Trying to authenticate with shibboleth")
            log.debug("environ AUTH TYPE: %s", environ.get("AUTH_TYPE", "None"))
            log.debug("environ Shib-Session-ID: %s", environ.get(self.session, "None"))
            log.debug("environ mail: %s", environ.get(self.mail, "None"))
            log.debug("environ cn: %s", environ.get(self.name, "None"))

            user = self._get_or_create_user(environ)

            if not user:
                log.debug("User is None")
                return {}

            response = Response()
            response.status = 302
            response.location = url_for(controller="user", action="dashboard")
            environ["repoze.who.application"] = response

            return {
                "repoze.who.plugins.openid.userid": user.openid,
                "login": user.email,
                "password": "",
                "email": user.email,
                "fullname": user.email,
            }

        return {}
开发者ID:harripal,项目名称:ckanext-shibboleth,代码行数:51,代码来源:plugin.py

示例3: challenge

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import location [as 别名]
    def challenge(self, environ, status, app_headers, forget_headers):
        """the challenge method is called when the ``IChallengeDecider``
        in ``classifiers.py`` returns ``True``. This is the case for either a 
        ``401`` response from the client or if the key 
        ``repoze.whoplugins.openid.openidrepoze.whoplugins.openid.openid``
        is present in the WSGI environment.
        The name of this key can be adjusted via the ``openid_field`` configuration
        directive.

        The latter is the case when we are coming from the login page where the
        user entered the openid to use.

        ``401`` can come back in any case and then we simply redirect to the login
        form which is configured in the who configuration as ``login_form_url``.

        TODO: make the environment key to check also configurable in the challenge_decider.

        For the OpenID flow check `the OpenID library documentation 
        <http://openidenabled.com/files/python-openid/docs/2.2.1/openid.consumer.consumer-module.html>`_

        """

        request = Request(environ)
        
        # check for the field present, if not redirect to login_form
        if not request.params.has_key(self.openid_field):
            # redirect to login_form
            res = Response()
            res.status = 302
            res.location = self.login_form_url+"?%s=%s" %(self.came_from_field, request.url)
            return res

        # now we have an openid from the user in the request 
        openid_url = request.params[self.openid_field]
        if environ['repoze.who.logger'] is not None:
            environ['repoze.who.logger'].debug('starting openid request for : %s ' %openid_url)
        
        try:
        # we create a new Consumer and start the discovery process for the URL given
        # in the library openid_request is called auth_req btw.
            openid_request = self.get_consumer(environ).begin(openid_url)
            
            if len(self.ax_require.values()) or len(self.ax_optional.values()):
                fetch_request = ax.FetchRequest()
                for value in self.ax_require.values():
                    fetch_request.add(ax.AttrInfo(value, required=True))
                for value in self.ax_optional.values():
                    fetch_request.add(ax.AttrInfo(value, required=False))
                openid_request.addExtension(fetch_request)
            
            if len(self.sreg_require) or len(self.sreg_optional):
                sreq = sreg.SRegRequest(required=self.sreg_require, optional=self.sreg_optional)
                openid_request.addExtension(sreq)
            

        except consumer.DiscoveryFailure, exc:
            # eventually no openid server could be found
            environ[self.error_field] = 'Error in discovery: %s' %exc[0]
            environ['repoze.who.logger'].info('Error in discovery: %s ' %exc[0])     
            return self._redirect_to_loginform(environ)
开发者ID:mbellotti,项目名称:hdx-ckan,代码行数:62,代码来源:identification.py

示例4: redirect

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import location [as 别名]
 def redirect(self, url):
     """Redirect to this url
     """
     response = Response()
     response.status = 302
     response.location = url
     return response
开发者ID:Alchemy-Meister,项目名称:OAI-PMH,代码行数:9,代码来源:wsgi.py

示例5: login

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import location [as 别名]
def login(request):
    """
    handles session login
    """
    try:
        params = _get_params_by_ct(request)
        username = params['username']
        password = params['password']
    except: 
        return HttpResponse(status=400)
        
    # attempt actual login...
    udb = request.context.get_users_database()
    user = User.get_by_username(udb, username)
        
    if user is None: 
        return HttpResponse(status=401)
    
    if not user.check_password(password):
        return HttpResponse(status=401)
        
    # password was good, record in session
    request.context.set_session_user(user)

    if 'next' in params:
        req = HttpResponse(status=304)
        req.location = params['next']
        return req
    else: 
        return HttpResponse()
开发者ID:jab,项目名称:radarpost,代码行数:32,代码来源:controller.py

示例6: update

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import location [as 别名]
 def update(self):
     identity = self.environ.get('repoze.who.identity')
     if identity is not None:
         response = Response()
         came_from = self.request.GET.get('came_from', '/')
         if came_from:
             response.status = '304 Not Modified'
             response.location = str(came_from)
             return response
     return None
开发者ID:novareto,项目名称:uvc.concierge,代码行数:12,代码来源:forms.py

示例7: _redirect_to_loginform

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import location [as 别名]
def _redirect_to_loginform(self, environ={}):
    """redirect the user to the login form"""
    res = Response()
    res.status = 302
    q=''
    ef = environ.get(self.error_field, None)
    if ef is not None:
            q='?%s=%s' %(self.error_field, ef)
    res.location = get_full_path(self.login_form_url, environ)+q
    return res
开发者ID:31H0B1eV,项目名称:ckan,代码行数:12,代码来源:repoze_patch.py

示例8: _redirect_from_callback

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import location [as 别名]
 def _redirect_from_callback(self, request, identity):
     '''Redirect from the callback URL after a successful authentication.'''
     if request.path == self.redirect_url:
         came_from = identity.get(self.came_from_field)
         if came_from is None:
             came_from = "/"
         response = Response()
         response.status = 302
         response.location = came_from
         request.environ["repoze.who.application"] = response
开发者ID:pwr-inf,项目名称:ckanext-oauth2,代码行数:12,代码来源:repozewho.py

示例9: _redirect_to_loginform

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import location [as 别名]
 def _redirect_to_loginform(self, environ={}):
     """redirect the user to the login form"""
     res = Response()
     res.status = 302
     q = ""
     ef = environ.get(self.error_field, None)
     if ef is not None:
         q = "?%s=%s" % (self.error_field, ef)
     res.location = self.login_form_url + q
     return res
开发者ID:rwaldron,项目名称:oauth-repoze,代码行数:12,代码来源:identification.py

示例10: _redirect_from_postback

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import location [as 别名]
 def _redirect_from_postback(self, request, identity):
     """Redirect from the postback URL after a successful authentication."""
     if request.path == self.postback_path:
         came_from = request.params.get(self.came_from_field)
         if came_from is None:
             came_from = "/"
         response = Response()
         response.status = 302
         response.location = came_from
         request.environ["repoze.who.application"] = response
开发者ID:mozilla-services,项目名称:repoze.who.plugins.browserid,代码行数:12,代码来源:__init__.py

示例11: challenge

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import location [as 别名]
 def challenge(self, environ, status, app_headers, forget_headers):
     if environ.get('ckan.who.oauth.challenge'):
         del(environ['ckan.who.oauth.challenge'])
     request_token, _ = self._get_request_token()
     res = Response()
     res.status = 302
     res.location = "%s?oauth_token=%s" % (self.authorize_url,
                                           request_token)
     logging.info("Challenge: Redirecting challenge to page %s" % \
                  res.location)
     return res
开发者ID:okfn,项目名称:ckanext-oauth,代码行数:13,代码来源:plugin.py

示例12: challenge

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import location [as 别名]
    def challenge(self, environ, status, app_headers=(), forget_headers=()):
        '''Redirect to YouCKAN login page'''
        request = Request(environ)

        if self.needs_redirect(request):
            response = Response()
            response.status = 302
            response.location = request.url.replace('http://', 'https://')
            return response

        next_url = quote(request.url)
        if self.use_https and next_url.startswith('http://'):
            next_url = next_url.replace('http://, https://')
        auth_url = '{0}?{1}={2}'.format(self.login_url, self.next_url_name, next_url)

        response = Response()
        response.status = 302
        response.location = auth_url

        return response
开发者ID:etalab,项目名称:ckanext-youckan,代码行数:22,代码来源:repozewho.py

示例13: challenge

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import location [as 别名]
 def challenge(self, environ, status, app_headers, forget_headers):
     '''
     The challenger.
     '''
     cookies = get_cookies(environ)
     cookie = cookies.get(self.cookie_name)
 # request = Request(environ)
     if cookie is None or not cookie.value:
         pass
     # redirect to login_form
     res = Response()
     res.status = 302
     addon = None
     if 'SCRIPT_NAME' in environ:
         addon = environ['SCRIPT_NAME']
     if addon is not None:
         res.location = addon + '/login_needed'
     else:
         res.location = 'login_needed'
     return res
开发者ID:bbcf,项目名称:pygdv,代码行数:22,代码来源:auth_plugin.py

示例14: application

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import location [as 别名]
def application(environ, start_response):
    req = Request(environ)
    if req.path_info == '/redirect':
        req.path_info = '/path'
        resp = Response()
        resp.status = '302 Found'
        resp.location = req.path
    else:
        resp = Response()
        resp.body = to_bytes('<html><body><a href="%s">link</a></body></html>' % req.path)
    return resp(environ, start_response)
开发者ID:ailling,项目名称:webtest,代码行数:13,代码来源:test_script_name.py

示例15: redirect_to_logged_in

# 需要导入模块: from webob import Response [as 别名]
# 或者: from webob.Response import location [as 别名]
def redirect_to_logged_in(self, environ):
    """redirect to came_from or standard page if login was successful"""
    request = Request(environ)
    came_from = request.params.get(self.came_from_field,'')
    if came_from!='':
        url = came_from
    else:
        url = get_full_path(self.logged_in_url, environ)
    res = Response()
    res.status = 302
    res.location = url
    environ['repoze.who.application'] = res
开发者ID:31H0B1eV,项目名称:ckan,代码行数:14,代码来源:repoze_patch.py


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