本文整理汇总了Python中werkzeug.urls.url_quote_plus函数的典型用法代码示例。如果您正苦于以下问题:Python url_quote_plus函数的具体用法?Python url_quote_plus怎么用?Python url_quote_plus使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了url_quote_plus函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: oracle_get
def oracle_get():
popular_words = oracle.popular_words(90)
random.shuffle(popular_words)
question = request.args.get("question")
if question:
show_cloud="block"
answer = oracle.the_oracle_speaks(question)
if answer.couplet['artist'].name['name_list'][0] == '':
artist = answer.couplet['artist'].name['name_list'][1]
else:
artist = ' name_part_two '.join(answer.couplet['artist'].name['name_list']).strip()
og_description="Asked the glitch oracle: '"+question+"' and am told '"+answer.couplet['couplet'][0]+answer.couplet['couplet'][1]+"'"
page_title="The Glitch Oracle - Psychic Answers from the Infinite Glitch"
meta_description="Asked the glitch oracle: '"+question+"' and am told '"+answer.couplet['couplet'][0]+answer.couplet['couplet'][1]+"'"
# TODO: Turn every bit of this info into plain text, then make it possible to share these things.
og_url="http://www.infiniteglitch.net/share_oracle/"+url_quote_plus(question)+"/"+url_quote_plus(answer.couplet['couplet'][0])+"/"+url_quote_plus(answer.couplet['couplet'][1])+"/"+url_quote_plus(artist)
else:
question = answer = ""
show_cloud = "none"
page_title="Ask The Glitch Oracle"
og_description="Ask The Glitch Oracle"
meta_description="Ask The Glitch Oracle"
og_url="http://www.infiniteglitch.net/oracle"
return render_template("oracle.html", page_title="Glitch Oracle", question=question, answer=answer,
popular_words=popular_words,
show_cloud=show_cloud, og_description=og_description,
meta_description=meta_description, og_url=og_url, url_quote_plus=url_quote_plus)
示例2: mail_tag
def mail_tag(env, mail, encode=None, **kwds):
options = {
'cc': None,
'bcc': None,
'subject': None,
'body': None,
}
options.update(kwds)
name = mail
extras = []
htmloptions = []
for key, value in options.iteritems():
if not value:
continue
elif 'cc' == key or 'bcc' == key:
value = value.strip()
if value:
value = url_quote_plus(value)
value = value.replace('+', '%20')
value = value.replace('%40', '@')
value = value.replace('%2C', ',')
extras.append('%s=%s' % (key, value))
elif 'body' == key or 'subject' == key:
value = to_str(value).strip()
if value:
value = url_quote_plus(value)
value = value.replace('+', '%20')
extras.append('%s=%s' % (key, value))
elif 'name' == key:
name = value
else:
htmloptions.append('%s=%s' % (jinja2.escape(key), jinja2.escape(value)))
extras = '&'.join(extras)
if extras:
extras = '?' + extras
htmloptions = ' '.join(htmloptions)
if encode is None:
result = '<a href="mailto:%s%s" %s>%s</a>' % (mail, extras, htmloptions, name)
else:
mailto = obfuscate('mailto:%s' % mail)
atag = '<a href="%s%s" %s>%s</a>' % (mailto, extras, htmloptions, obfuscate(name))
if 'js' != encode:
result = atag
else:
tmp = obfuscate('document.write(\'%s\');' % atag, js=True)
result = '<script type="text/javascript">eval(unescape(\'%s\'));</script>' % tmp
if env.autoescape:
result = jinja2.Markup(result)
return result
示例3: test_quoting
def test_quoting(self):
self.assert_strict_equal(urls.url_quote(u'\xf6\xe4\xfc'), '%C3%B6%C3%A4%C3%BC')
self.assert_strict_equal(urls.url_unquote(urls.url_quote(u'#%="\xf6')), u'#%="\xf6')
self.assert_strict_equal(urls.url_quote_plus('foo bar'), 'foo+bar')
self.assert_strict_equal(urls.url_unquote_plus('foo+bar'), u'foo bar')
self.assert_strict_equal(urls.url_encode({b'a': None, b'b': b'foo bar'}), 'b=foo+bar')
self.assert_strict_equal(urls.url_encode({u'a': None, u'b': u'foo bar'}), 'b=foo+bar')
self.assert_strict_equal(urls.url_fix(u'http://de.wikipedia.org/wiki/Elf (Begriffsklärung)'),
'http://de.wikipedia.org/wiki/Elf%20(Begriffskl%C3%A4rung)')
self.assert_strict_equal(urls.url_quote_plus(42), '42')
self.assert_strict_equal(urls.url_quote(b'\xff'), '%FF')
示例4: create_login_url
def create_login_url(self, url):
import os
hostname = get_appid() + '.appspot.com'
url = url_for("auth/login",
next=url_quote_plus(url),
original_host_url=url_quote_plus(local.request.host_url),
owned_domain_hack=True)
if 'SERVER_SOFTWARE' in os.environ and \
os.environ['SERVER_SOFTWARE'].startswith('Dev'):
return url
else:
return "https://%s%s" % (hostname, url)
示例5: mail_tag
def mail_tag(env, mail, encode=None, **kwds):
### from symfony
options = {
'cc': None,
'bcc': None,
'subject': None,
'body': None,
}
options.update(kwds)
name = mail
extras = []
htmloptions = []
for key, value in options.iteritems():
if not value:
continue
elif 'cc' == key or 'bcc' == key:
value = value.strip()
if value:
value = url_quote_plus(value)
value = value.replace('+', '%20')
value = value.replace('%40', '@')
value = value.replace('%2C', ',')
extras.append('%s=%s' % (key, value))
elif 'body' == key or 'subject' == key:
value = to_str(value).strip()
if value:
value = url_quote_plus(value)
value = value.replace('+', '%20')
extras.append('%s=%s' % (key, value))
elif 'name' == key:
name = value
else:
htmloptions.append('%s=%s' % (jinja2.escape(key), jinja2.escape(value)))
extras = ('?' + '&'.join(extras)) if extras else ''
htmloptions = (' ' + ' '.join(htmloptions)) if htmloptions else ''
if encode is None:
e_mail = jinja2.escape(mail)
e_name = jinja2.escape(name)
result = '<a href="mailto:%s%s"%s>%s</a>' % (e_mail, extras, htmloptions, e_name)
else:
o_mail = obfuscate(env, 'mailto:%s' % mail)
o_name = obfuscate(env, name)
result = '<a href="%s%s"%s>%s</a>' % (o_mail, extras, htmloptions, o_name)
if 'js' == encode:
o_str = obfuscate(env, 'document.write(\'%s\');' % result, js=True)
result = '<script type="text/javascript">eval(unescape(\'%s\'));</script>' % o_str
return to_markup(env, result)
示例6: _url
def _url(req, action, id=None, errormsg=""):
if id is not None and action == 'view' and len(errormsg) < 2:
# I can do this because .htaccess has this line:
# RewriteRule ^([a-z0-9]+)$ /moerderspiel/view?id=$1 [R=302]
return "%s%s" % (req.host_url, id)
else:
url = "%s%s" % (url_for('.index'), action)
if id != None:
url += '?id=' + id
if len(errormsg) > 1 and id == None:
url += '?msg=' + url_quote_plus(errormsg)
elif len(errormsg) > 1:
url += '&msg=' + url_quote_plus(errormsg)
return url
示例7: test_quoting
def test_quoting():
strict_eq(urls.url_quote(u"\xf6\xe4\xfc"), "%C3%B6%C3%A4%C3%BC")
strict_eq(urls.url_unquote(urls.url_quote(u'#%="\xf6')), u'#%="\xf6')
strict_eq(urls.url_quote_plus("foo bar"), "foo+bar")
strict_eq(urls.url_unquote_plus("foo+bar"), u"foo bar")
strict_eq(urls.url_quote_plus("foo+bar"), "foo%2Bbar")
strict_eq(urls.url_unquote_plus("foo%2Bbar"), u"foo+bar")
strict_eq(urls.url_encode({b"a": None, b"b": b"foo bar"}), "b=foo+bar")
strict_eq(urls.url_encode({u"a": None, u"b": u"foo bar"}), "b=foo+bar")
strict_eq(
urls.url_fix(u"http://de.wikipedia.org/wiki/Elf (Begriffsklärung)"),
"http://de.wikipedia.org/wiki/Elf%20(Begriffskl%C3%A4rung)",
)
strict_eq(urls.url_quote_plus(42), "42")
strict_eq(urls.url_quote(b"\xff"), "%FF")
示例8: serialize
def serialize(self, expires=None):
"""Serialize the secure cookie into a string.
If expires is provided, the session will be automatically invalidated
after expiration when you unseralize it. This provides better
protection against session cookie theft.
:param expires: an optional expiration date for the cookie (a
:class:`datetime.datetime` object)
"""
if self.secret_key is None:
raise RuntimeError('no secret key defined')
if expires:
self['_expires'] = _date_to_unix(expires)
result = []
mac = hmac(self.secret_key, None, self.hash_method)
for key, value in sorted(self.items()):
result.append(('%s=%s' % (
url_quote_plus(key),
self.quote(value).decode('ascii')
)).encode('ascii'))
mac.update(b'|' + result[-1])
return b'?'.join([
base64.b64encode(mac.digest()).strip(),
b'&'.join(result)
])
示例9: test_quoting
def test_quoting(self):
assert urls.url_quote(u'\xf6\xe4\xfc') == '%C3%B6%C3%A4%C3%BC'
assert urls.url_unquote(urls.url_quote(u'#%="\xf6')) == u'#%="\xf6'
assert urls.url_quote_plus('foo bar') == 'foo+bar'
assert urls.url_unquote_plus('foo+bar') == 'foo bar'
assert urls.url_encode({'a': None, 'b': 'foo bar'}) == 'b=foo+bar'
assert urls.url_fix(u'http://de.wikipedia.org/wiki/Elf (Begriffsklärung)') == \
'http://de.wikipedia.org/wiki/Elf%20%28Begriffskl%C3%A4rung%29'
示例10: admin_save
def admin_save():
title = request.form.get('title', None)
if not title:
return redirect(url_for('admin_edit'))
f = open('posts/' + urlsafe_b64encode(title), 'w')
f.write(request.form.get('body', ''))
f.close()
return redirect(url_for('post', url=url_quote_plus(title)))
示例11: create_login_url
def create_login_url(self, next_url='/'):
if hasattr(local.request, settings.MARKETPLACE_DOMAIN_NAME_KEY):
# marketplace
domain = getattr(local.request, settings.MARKETPLACE_DOMAIN_NAME_KEY)
return create_marketplace_login_url(domain, next_url)
return url_for('gaema/select_service',
targets='|'.join(self.valid_services),
next_url=url_quote_plus(next_url))
示例12: add_protected_view
def add_protected_view(self):
url = '/_protected'
quoted_url = url_quote_plus('/_protected')
self.redirect_url = '/login?next={0}'.format(quoted_url)
@self.app.route(url)
@login_required
def protected():
return 'success'
示例13: test_quoting
def test_quoting(self):
assert urls.url_quote(u"\xf6\xe4\xfc") == "%C3%B6%C3%A4%C3%BC"
assert urls.url_unquote(urls.url_quote(u'#%="\xf6')) == u'#%="\xf6'
assert urls.url_quote_plus("foo bar") == "foo+bar"
assert urls.url_unquote_plus("foo+bar") == "foo bar"
assert urls.url_encode({"a": None, "b": "foo bar"}) == "b=foo+bar"
assert (
urls.url_fix(u"http://de.wikipedia.org/wiki/Elf (Begriffsklärung)")
== "http://de.wikipedia.org/wiki/Elf%20%28Begriffskl%C3%A4rung%29"
)
示例14: image_fetch
def image_fetch(self):
q = '"%s" %d poster' % (self.title, self.year)
q = 'http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=' + url_quote_plus(q)
q = requests.get(q)
q = json_loads(q.content)
try:
q = q['responseData']['results']
except (TypeError, KeyError):
return
for item in q:
img = item['url']
img_lower = img.lower()
cond = [forbidden not in img_lower
for forbidden in forbidden_domains]
if all(cond):
self.img = img
return
示例15: validate_character
def validate_character(self, server_name, character_name):
# Search for character
url = self.lodestone_url + "/character/?q=%s&worldname=%s" % (url_quote_plus(character_name), server_name)
r = self.make_request(url=url)
if not r:
return None
soup = bs4.BeautifulSoup(r.content)
for tag in soup.select(".player_name_area .player_name_gold a"):
if tag.string.lower() == character_name.lower():
return {"lodestone_id": re.findall(r"(\d+)", tag["href"])[0], "name": str(tag.string)}
return None