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

Python urls.url_quote_plus函数代码示例

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

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



在下文中一共展示了url_quote_plus函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:MikeiLL,项目名称:appension,代码行数:27,代码来源:server.py


示例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
开发者ID:najeira,项目名称:valforce-tools,代码行数:56,代码来源:helpers.py


示例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')
开发者ID:Fuhr,项目名称:OCRPrototype,代码行数:11,代码来源:urls.py


示例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)
开发者ID:IanLewis,项目名称:kay,代码行数:12,代码来源:datastore.py


示例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)
开发者ID:najeira,项目名称:tuningathon3,代码行数:52,代码来源:helpers.py


示例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
开发者ID:orithena,项目名称:moerderspiel,代码行数:14,代码来源:moerderspiel.py


示例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")
开发者ID:pallets,项目名称:werkzeug,代码行数:15,代码来源:test_urls.py


示例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)
        ])
开发者ID:parker1333752,项目名称:svc_analyzer,代码行数:26,代码来源:securecookie.py


示例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'
开发者ID:sean-,项目名称:werkzeug,代码行数:8,代码来源:urls.py


示例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)))
开发者ID:dAnjou,项目名称:simple-wiki,代码行数:8,代码来源:server.py


示例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))
开发者ID:IanLewis,项目名称:kay,代码行数:8,代码来源:gaema.py


示例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'
开发者ID:xiaojunchan,项目名称:esther,代码行数:9,代码来源:test_auth.py


示例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"
     )
开发者ID:FakeSherlock,项目名称:Report,代码行数:10,代码来源:urls.py


示例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
开发者ID:petrushev,项目名称:myflicks,代码行数:17,代码来源:models.py


示例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
开发者ID:redshadowhero,项目名称:FFXIV-Scraper,代码行数:17,代码来源:__init__.py


示例16: primary_key_value

def primary_key_value(instance, as_string=False):
    """Returns the value of the primary key field of the specified `instance`
    of a SQLAlchemy model.

    This essentially a convenience function for::

        getattr(instance, primary_key_for(instance))

    If `as_string` is ``True``, try to coerce the return value to a string.

    """
    result = getattr(instance, primary_key_for(instance))
    if not as_string:
        return result
    try:
        return str(result)
    except UnicodeEncodeError:
        return url_quote_plus(result.encode('utf-8'))
开发者ID:janneraiskila,项目名称:flask-restless,代码行数:18,代码来源:helpers.py


示例17: 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, "html.parser")

        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
开发者ID:scragg0x,项目名称:FFXIV-Scraper,代码行数:21,代码来源:__init__.py


示例18: urlencode_filter

def urlencode_filter(strval):
    """
    A template filter to return a URL-encoded string.
    """
    return url_quote_plus(strval)
开发者ID:quru,项目名称:qis,代码行数:5,代码来源:views_util.py


示例19: __call__


#.........这里部分代码省略.........
        # attributes.
        #
        # TODO In Flask 1.0, the default JSON encoder for the Flask
        # application object does this automatically. Alternately, the
        # user could have set a smart JSON encoder on the Flask
        # application, which would cause these attributes to be
        # converted to strings when the Response object is created (in
        # the `jsonify` function, for example). However, we should not
        # rely on that JSON encoder since the user could set any crazy
        # encoder on the Flask application.
        for key, val in attributes.items():
            if isinstance(val, (date, datetime, time)):
                attributes[key] = val.isoformat()
            elif isinstance(val, timedelta):
                attributes[key] = val.total_seconds()
        # Recursively serialize any object that appears in the
        # attributes. This may happen if, for example, the return value
        # of one of the callable functions is an instance of another
        # SQLAlchemy model class.
        for k, v in attributes.items():
            # This is a bit of a fragile test for whether the object
            # needs to be serialized: we simply check if the class of
            # the object is a mapped class.
            if is_mapped_class(type(v)):
                attributes[k] = simple_serialize(v)
        # Get the ID and type of the resource.
        id_ = attributes.pop('id')
        type_ = collection_name(model)
        # Create the result dictionary and add the attributes.
        result = dict(id=id_, type=type_)
        if attributes:
            result['attributes'] = attributes
        # Add the self link unless it has been explicitly excluded.
        if ((self.default_fields is None or 'self' in self.default_fields)
                and (only is None or 'self' in only)):
            instance_id = primary_key_value(instance)
            # `url_for` may raise a `BuildError` if the user has not created a
            # GET API endpoint for this model. In this case, we simply don't
            # provide a self link.
            #
            # TODO This might fail if the user has set the
            # `current_app.build_error_handler` attribute, in which case, the
            # exception may not be raised.
            try:
                path = url_for(model, instance_id, _method='GET')
            except BuildError:
                pass
            else:
                url = urljoin(request.url_root, path)
                result['links'] = dict(self=url)
        # # add any included methods
        # if include_methods is not None:
        #     for method in include_methods:
        #         if '.' not in method:
        #             value = getattr(instance, method)
        #             # Allow properties and static attributes in
        #             # include_methods
        #             if callable(value):
        #                 value = value()
        #             result[method] = value

        # Recursively serialize values that are themselves SQLAlchemy
        # models.
        #
        # TODO We really need to serialize each model using the
        # serializer defined for that class when the user called
        # APIManager.create_api
        for key, value in result.items():
            if key not in column_attrs and is_mapped_class(type(value)):
                result[key] = simple_serialize(value)
        # If the primary key is not named "id", we'll duplicate the
        # primary key under the "id" key.
        pk_name = primary_key_name(model)
        if pk_name != 'id':
            result['id'] = result['attributes'][pk_name]
        # TODO Same problem as above.
        #
        # In order to comply with the JSON API standard, primary keys must be
        # returned to the client as strings, so we convert it here.
        if 'id' in result:
            try:
                result['id'] = str(result['id'])
            except UnicodeEncodeError:
                result['id'] = url_quote_plus(result['id'].encode('utf-8'))
        # If there are relations to convert to dictionary form, put them into a
        # special `links` key as required by JSON API.
        relations = get_relations(model)
        if self.default_fields is not None:
            relations = [r for r in relations if r in self.default_fields]
        # Only consider those relations listed in `only`.
        if only is not None:
            relations = [r for r in relations if r in only]
        if not relations:
            return result
        # For the sake of brevity, rename this function.
        cr = create_relationship
        # TODO In Python 2.7 and later, this should be a dict comprehension.
        result['relationships'] = dict((rel, cr(model, instance, rel))
                                       for rel in relations)
        return result
开发者ID:rafaelabreu,项目名称:flask-restless,代码行数:101,代码来源:serialization.py


示例20: index

def index():
    posts = []
    for filename in os.listdir('posts'):
        title = urlsafe_b64decode(filename)
        posts.append({'title': title, 'url': url_quote_plus(title)})
    return render_template('index.html', posts=posts)
开发者ID:dAnjou,项目名称:simple-wiki,代码行数:6,代码来源:server.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python urls.url_unparse函数代码示例发布时间:2022-05-26
下一篇:
Python urls.url_quote函数代码示例发布时间: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