當前位置: 首頁>>代碼示例>>Python>>正文


Python cherrypy.url方法代碼示例

本文整理匯總了Python中cherrypy.url方法的典型用法代碼示例。如果您正苦於以下問題:Python cherrypy.url方法的具體用法?Python cherrypy.url怎麽用?Python cherrypy.url使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cherrypy的用法示例。


在下文中一共展示了cherrypy.url方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import url [as 別名]
def __init__(self, path, query_string=''):
        self.request = cherrypy.serving.request

        self.query_string = query_string
        if '?' in path:
            # Separate any params included in the path
            path, self.query_string = path.split('?', 1)

        # Note that urljoin will "do the right thing" whether url is:
        #  1. a URL relative to root (e.g. "/dummy")
        #  2. a URL relative to the current path
        # Note that any query string will be discarded.
        path = urllib.parse.urljoin(self.request.path_info, path)

        # Set a 'path' member attribute so that code which traps this
        # error can have access to it.
        self.path = path

        CherryPyException.__init__(self, path, self.query_string) 
開發者ID:cherrypy,項目名稱:cherrypy,代碼行數:21,代碼來源:_cperror.py

示例2: do_check

# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import url [as 別名]
def do_check(self):
        """Assert username. Raise redirect, or return True if request handled.
        """
        sess = cherrypy.session
        request = cherrypy.serving.request
        response = cherrypy.serving.response

        username = sess.get(self.session_key)
        if not username:
            sess[self.session_key] = username = self.anonymous()
            self._debug_message('No session[username], trying anonymous')
        if not username:
            url = cherrypy.url(qs=request.query_string)
            self._debug_message(
                'No username, routing to login_screen with from_page %(url)r',
                locals(),
            )
            response.body = self.login_screen(url)
            if 'Content-Length' in response.headers:
                # Delete Content-Length header so finalize() recalcs it.
                del response.headers['Content-Length']
            return True
        self._debug_message('Setting request.login to %(username)r', locals())
        request.login = username
        self.on_check(username) 
開發者ID:cherrypy,項目名稱:cherrypy,代碼行數:27,代碼來源:cptools.py

示例3: log_hooks

# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import url [as 別名]
def log_hooks(debug=False):
    """Write request.hooks to the cherrypy error log."""
    request = cherrypy.serving.request

    msg = []
    # Sort by the standard points if possible.
    from cherrypy import _cprequest
    points = _cprequest.hookpoints
    for k in request.hooks.keys():
        if k not in points:
            points.append(k)

    for k in points:
        msg.append('    %s:' % k)
        v = request.hooks.get(k, [])
        v.sort()
        for h in v:
            msg.append('        %r' % h)
    cherrypy.log('\nRequest Hooks for ' + cherrypy.url() +
                 ':\n' + '\n'.join(msg), 'HTTP') 
開發者ID:cherrypy,項目名稱:cherrypy,代碼行數:22,代碼來源:cptools.py

示例4: get

# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import url [as 別名]
def get(self):
        """Return the current variant if in the cache, else None."""
        request = cherrypy.serving.request
        self.tot_gets += 1

        uri = cherrypy.url(qs=request.query_string)
        uricache = self.store.get(uri)
        if uricache is None:
            return None

        header_values = [request.headers.get(h, '')
                         for h in uricache.selecting_headers]
        variant = uricache.wait(key=tuple(sorted(header_values)),
                                timeout=self.antistampede_timeout,
                                debug=self.debug)
        if variant is not None:
            self.tot_hist += 1
        return variant 
開發者ID:cherrypy,項目名稱:cherrypy,代碼行數:20,代碼來源:caching.py

示例5: test_redir_using_url

# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import url [as 別名]
def test_redir_using_url(self):
        for url in script_names:
            self.script_name = url

            # Test the absolute path to the parent (leading slash)
            self.getPage('/redirect_via_url?path=./')
            self.assertStatus(('302 Found', '303 See Other'))
            self.assertHeader('Location', '%s/' % self.base())

            # Test the relative path to the parent (no leading slash)
            self.getPage('/redirect_via_url?path=./')
            self.assertStatus(('302 Found', '303 See Other'))
            self.assertHeader('Location', '%s/' % self.base())

            # Test the absolute path to the parent (leading slash)
            self.getPage('/redirect_via_url/?path=./')
            self.assertStatus(('302 Found', '303 See Other'))
            self.assertHeader('Location', '%s/' % self.base())

            # Test the relative path to the parent (no leading slash)
            self.getPage('/redirect_via_url/?path=./')
            self.assertStatus(('302 Found', '303 See Other'))
            self.assertHeader('Location', '%s/' % self.base()) 
開發者ID:cherrypy,項目名稱:cherrypy,代碼行數:25,代碼來源:test_objectmapping.py

示例6: index

# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import url [as 別名]
def index(self):
		scope="alexa_all"
		sd = json.dumps({
		    "alexa:all": {
		        "productID": ProductID,
		        "productInstanceAttributes": {
		            "deviceSerialNumber": "001"
		        }
		    }
		})
		url = "https://www.amazon.com/ap/oa"
		callback = cherrypy.url()  + "code" 
		payload = {"client_id" : Client_ID, "scope" : "alexa:all", "scope_data" : sd, "response_type" : "code", "redirect_uri" : callback }
		req = requests.Request('GET', url, params=payload)
		p = req.prepare()
		raise cherrypy.HTTPRedirect(p.url) 
開發者ID:alexa-pi,項目名稱:AlexaPiDEPRECATED,代碼行數:18,代碼來源:auth_web.py

示例7: __init__

# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import url [as 別名]
def __init__(self, path, query_string=""):
        import cherrypy
        self.request = cherrypy.serving.request

        self.query_string = query_string
        if "?" in path:
            # Separate any params included in the path
            path, self.query_string = path.split("?", 1)

        # Note that urljoin will "do the right thing" whether url is:
        #  1. a URL relative to root (e.g. "/dummy")
        #  2. a URL relative to the current path
        # Note that any query string will be discarded.
        path = _urljoin(self.request.path_info, path)

        # Set a 'path' member attribute so that code which traps this
        # error can have access to it.
        self.path = path

        CherryPyException.__init__(self, path, self.query_string) 
開發者ID:naparuba,項目名稱:opsbro,代碼行數:22,代碼來源:_cperror.py

示例8: log_hooks

# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import url [as 別名]
def log_hooks(debug=False):
    """Write request.hooks to the cherrypy error log."""
    request = cherrypy.serving.request

    msg = []
    # Sort by the standard points if possible.
    from cherrypy import _cprequest
    points = _cprequest.hookpoints
    for k in request.hooks.keys():
        if k not in points:
            points.append(k)

    for k in points:
        msg.append("    %s:" % k)
        v = request.hooks.get(k, [])
        v.sort()
        for h in v:
            msg.append("        %r" % h)
    cherrypy.log('\nRequest Hooks for ' + cherrypy.url() +
                 ':\n' + '\n'.join(msg), "HTTP") 
開發者ID:naparuba,項目名稱:opsbro,代碼行數:22,代碼來源:cptools.py

示例9: __init__

# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import url [as 別名]
def __init__(self, path, query_string=''):
        import cherrypy
        self.request = cherrypy.serving.request

        self.query_string = query_string
        if '?' in path:
            # Separate any params included in the path
            path, self.query_string = path.split('?', 1)

        # Note that urljoin will "do the right thing" whether url is:
        #  1. a URL relative to root (e.g. "/dummy")
        #  2. a URL relative to the current path
        # Note that any query string will be discarded.
        path = _urljoin(self.request.path_info, path)

        # Set a 'path' member attribute so that code which traps this
        # error can have access to it.
        self.path = path

        CherryPyException.__init__(self, path, self.query_string) 
開發者ID:morpheus65535,項目名稱:bazarr,代碼行數:22,代碼來源:_cperror.py

示例10: test_redir_using_url

# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import url [as 別名]
def test_redir_using_url(self):
        for url in script_names:
            prefix = self.script_name = url

            # Test the absolute path to the parent (leading slash)
            self.getPage('/redirect_via_url?path=./')
            self.assertStatus(('302 Found', '303 See Other'))
            self.assertHeader('Location', '%s/' % self.base())

            # Test the relative path to the parent (no leading slash)
            self.getPage('/redirect_via_url?path=./')
            self.assertStatus(('302 Found', '303 See Other'))
            self.assertHeader('Location', '%s/' % self.base())

            # Test the absolute path to the parent (leading slash)
            self.getPage('/redirect_via_url/?path=./')
            self.assertStatus(('302 Found', '303 See Other'))
            self.assertHeader('Location', '%s/' % self.base())

            # Test the relative path to the parent (no leading slash)
            self.getPage('/redirect_via_url/?path=./')
            self.assertStatus(('302 Found', '303 See Other'))
            self.assertHeader('Location', '%s/' % self.base()) 
開發者ID:morpheus65535,項目名稱:bazarr,代碼行數:25,代碼來源:test_objectmapping.py

示例11: index

# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import url [as 別名]
def index(self):
        sd = json.dumps({
            "alexa:all": {
                "productID": self.config['ProductID'],
                "productInstanceAttributes": {
                    "deviceSerialNumber": "123456"
                }
            }
        })
        callback = cherrypy.url() + "code"
        payload = {
            "client_id": self.config['Client_ID'],
            "scope": "alexa:all",
            "scope_data": sd,
            "response_type": "code",
            "redirect_uri": callback
        }
        req = requests.Request('GET', "https://www.amazon.com/ap/oa", params=payload)
        p = req.prepare()
        raise cherrypy.HTTPRedirect(p.url) 
開發者ID:nicholasjconn,項目名稱:python-alexa-voice-service,代碼行數:22,代碼來源:authorization.py

示例12: code

# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import url [as 別名]
def code(self, var=None, **params):
        code = urllib.parse.quote(cherrypy.request.params['code'])
        callback = cherrypy.url()
        payload = {
            "client_id": self.config['Client_ID'],
            "client_secret": self.config['Client_Secret'],
            "code": code,
            "grant_type": "authorization_code",
            "redirect_uri": callback
        }
        url = "https://api.amazon.com/auth/o2/token"
        r = requests.post(url, data=payload)
        resp = r.json()

        self.config['refresh_token'] = resp['refresh_token']
        helper.write_dict('config.dict',self.config)

        threading.Timer(1, lambda: cherrypy.engine.exit()).start()

        return "Authentication successful! Please return to the program." 
開發者ID:nicholasjconn,項目名稱:python-alexa-voice-service,代碼行數:22,代碼來源:authorization.py

示例13: __init__

# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import url [as 別名]
def __init__(self, path, query_string=""):
        import cherrypy
        self.request = cherrypy.serving.request
        
        self.query_string = query_string
        if "?" in path:
            # Separate any params included in the path
            path, self.query_string = path.split("?", 1)
        
        # Note that urljoin will "do the right thing" whether url is:
        #  1. a URL relative to root (e.g. "/dummy")
        #  2. a URL relative to the current path
        # Note that any query string will be discarded.
        path = _urljoin(self.request.path_info, path)
        
        # Set a 'path' member attribute so that code which traps this
        # error can have access to it.
        self.path = path
        
        CherryPyException.__init__(self, path, self.query_string) 
開發者ID:binhex,項目名稱:moviegrabber,代碼行數:22,代碼來源:_cperror.py

示例14: do_check

# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import url [as 別名]
def do_check(self):
        """Assert username. May raise redirect, or return True if request handled."""
        sess = cherrypy.session
        request = cherrypy.serving.request
        response = cherrypy.serving.response
        
        username = sess.get(self.session_key)
        if not username:
            sess[self.session_key] = username = self.anonymous()
            if self.debug:
                cherrypy.log('No session[username], trying anonymous', 'TOOLS.SESSAUTH')
        if not username:
            url = cherrypy.url(qs=request.query_string)
            if self.debug:
                cherrypy.log('No username, routing to login_screen with '
                             'from_page %r' % url, 'TOOLS.SESSAUTH')
            response.body = self.login_screen(url)
            if "Content-Length" in response.headers:
                # Delete Content-Length header so finalize() recalcs it.
                del response.headers["Content-Length"]
            return True
        if self.debug:
            cherrypy.log('Setting request.login to %r' % username, 'TOOLS.SESSAUTH')
        request.login = username
        self.on_check(username) 
開發者ID:binhex,項目名稱:moviegrabber,代碼行數:27,代碼來源:cptools.py

示例15: log_hooks

# 需要導入模塊: import cherrypy [as 別名]
# 或者: from cherrypy import url [as 別名]
def log_hooks(debug=False):
    """Write request.hooks to the cherrypy error log."""
    request = cherrypy.serving.request
    
    msg = []
    # Sort by the standard points if possible.
    from cherrypy import _cprequest
    points = _cprequest.hookpoints
    for k in request.hooks.keys():
        if k not in points:
            points.append(k)
    
    for k in points:
        msg.append("    %s:" % k)
        v = request.hooks.get(k, [])
        v.sort()
        for h in v:
            msg.append("        %r" % h)
    cherrypy.log('\nRequest Hooks for ' + cherrypy.url() +
                 ':\n' + '\n'.join(msg), "HTTP") 
開發者ID:binhex,項目名稱:moviegrabber,代碼行數:22,代碼來源:cptools.py


注:本文中的cherrypy.url方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。