本文整理汇总了Python中werkzeug.wsgi.get_current_url函数的典型用法代码示例。如果您正苦于以下问题:Python get_current_url函数的具体用法?Python get_current_url怎么用?Python get_current_url使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_current_url函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_current_url
def _get_current_url(self, root_only=False, strip_querystring=False,
host_only=False, **kwargs):
current_url = get_current_url(self.environ,
root_only, strip_querystring, host_only)
if (root_only or host_only) and not kwargs:
return current_url
qs = {}
querystring = ''
if not strip_querystring:
qs = urlparse.parse_qs(''.join(current_url.split('?')[1:]))
for arg in qs:
qs[arg] = qs[arg][0]
if kwargs:
for arg in kwargs:
qs[arg] = kwargs[arg]
querystring = '?' + urllib.urlencode(qs)
url = '%s' % get_current_url(self.environ, strip_querystring=True)
if url[-1] != '/':
url += '/'
url += querystring
return url
示例2: test_get_current_url_invalid_utf8
def test_get_current_url_invalid_utf8():
env = create_environ()
# set the query string *after* wsgi dance, so \xcf is invalid
env["QUERY_STRING"] = "foo=bar&baz=blah&meh=\xcf"
rv = wsgi.get_current_url(env)
# it remains percent-encoded
strict_eq(rv, u"http://localhost/?foo=bar&baz=blah&meh=%CF")
示例3: extract_wsgi
def extract_wsgi(self, environ, headers):
"""Extract the server's set-cookie headers as cookies into the
cookie jar.
"""
self.extract_cookies(
_TestCookieResponse(headers),
U2Request(get_current_url(environ)),
)
示例4: handle_exception
def handle_exception(self, exc_info, environ):
event_id = capture('Exception',
exc_info=exc_info,
http={
'method': environ.get('REQUEST_METHOD'),
'url': get_current_url(environ, strip_querystring=True),
'querystring': environ.get('QUERY_STRING'),
},
)
return event_id
示例5: handle_exception
def handle_exception(self, exc_info, environ):
event_id = capture(
"Exception",
exc_info=exc_info,
data={
"sentry.interfaces.Http": {
"method": environ.get("REQUEST_METHOD"),
"url": get_current_url(environ, strip_querystring=True),
"querystring": environ.get("QUERY_STRING"),
}
},
)
return event_id
示例6: login
def login(self, env, req):
data = req.form
password = self.isso.conf.get("general", "admin_password")
if data['password'] and data['password'] == password:
response = redirect(re.sub(
r'/login$',
'/admin',
get_current_url(env, strip_querystring=True)
))
cookie = functools.partial(dump_cookie,
value=self.isso.sign({"logged": True}),
expires=datetime.now() + timedelta(1))
response.headers.add("Set-Cookie", cookie("admin-session"))
response.headers.add("X-Set-Cookie", cookie("isso-admin-session"))
return response
else:
return render_template('login.html')
示例7: login
def login(self, env, req):
if not self.isso.conf.getboolean("admin", "enabled"):
return render_template('disabled.html')
data = req.form
password = self.isso.conf.get("admin", "password")
if data['password'] and data['password'] == password:
response = redirect(re.sub(
r'/login$',
'/admin',
get_current_url(env, strip_querystring=True)
))
cookie = functools.partial(dump_cookie,
value=self.isso.sign({"logged": True}),
expires=datetime.now() + timedelta(1))
response.headers.add("Set-Cookie", cookie("admin-session"))
response.headers.add("X-Set-Cookie", cookie("isso-admin-session"))
return response
else:
isso_host_script = self.isso.conf.get("server", "public-endpoint") or local.host
return render_template('login.html', isso_host_script=isso_host_script)
示例8: get_wsgi_headers
def get_wsgi_headers(self, environ):
headers = Headers(self.headers)
location = headers.get('location')
if location is not None:
if isinstance(location, unicode):
location = iri_to_uri(location)
headers['Location'] = urlparse.urljoin(get_current_url(environ, root_only=True), location)
content_location = headers.get('content-location')
if content_location is not None and isinstance(content_location, unicode):
headers['Content-Location'] = iri_to_uri(content_location)
if 100 <= self.status_code < 200 or self.status_code == 204:
headers['Content-Length'] = '0'
elif self.status_code == 304:
remove_entity_headers(headers)
if self.is_sequence and 'content-length' not in self.headers:
try:
content_length = sum((len(str(x)) for x in self.response))
except UnicodeError:
pass
else:
headers['Content-Length'] = str(content_length)
return headers
示例9: url
def url(self):
return get_current_url(self.environ)
示例10: test_get_current_url_unicode
def test_get_current_url_unicode(self):
env = create_environ()
env['QUERY_STRING'] = 'foo=bar&baz=blah&meh=\xcf'
rv = wsgi.get_current_url(env)
self.assert_strict_equal(rv,
u'http://localhost/?foo=bar&baz=blah&meh=\ufffd')
示例11: uri
def uri(self):
return get_current_url(self._handle.environ)
示例12: host_url
def host_url(self):
return get_current_url(self.environ, host_only=True)
示例13: url_root
def url_root(self):
return get_current_url(self.environ, True)
示例14: test_get_current_url_unicode
def test_get_current_url_unicode():
env = create_environ(query_string=u"foo=bar&baz=blah&meh=\xcf")
rv = wsgi.get_current_url(env)
strict_eq(rv, u"http://localhost/?foo=bar&baz=blah&meh=\xcf")
示例15: demo
def demo(self, env, req):
return redirect(get_current_url(env) + '/index.html')