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

Python urllib.url_quote函数代码示例

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

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



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

示例1: authenticate

 def authenticate(self, environ):
     """ This function takes a WSGI environment and authenticates
         the request returning authenticated user or error.
     """
     method = REQUEST_METHOD(environ)
     fullpath = url_quote(SCRIPT_NAME(environ)) + url_quote(PATH_INFO(environ))
     authorization = AUTHORIZATION(environ)
     if not authorization:
         return self.build_authentication()
     (authmeth, auth) = authorization.split(" ", 1)
     if "digest" != authmeth.lower():
         return self.build_authentication()
     amap = dict(_auth_to_kv_pairs(auth))
     try:
         username = amap["username"]
         authpath = amap["uri"]
         nonce = amap["nonce"]
         realm = amap["realm"]
         response = amap["response"]
         assert authpath.split("?", 1)[0] in fullpath
         assert realm == self.realm
         qop = amap.get("qop", "")
         cnonce = amap.get("cnonce", "")
         nc = amap.get("nc", "00000000")
         if qop:
             assert "auth" == qop
             assert nonce and nc
     except:
         return self.build_authentication()
     ha1 = self.authfunc(environ, realm, username)
     return self.compute(ha1, username, response, method, authpath, nonce, nc, cnonce, qop)
开发者ID:lig,项目名称:paste3,代码行数:31,代码来源:digest.py


示例2: authenticate

 def authenticate(self, environ):
     """ This function takes a WSGI environment and authenticates
         the request returning authenticated user or error.
     """
     method = REQUEST_METHOD(environ)
     fullpath = url_quote(SCRIPT_NAME(environ)) + url_quote(PATH_INFO(environ))
     authorization = AUTHORIZATION(environ)
     if not authorization:
         return self.build_authentication()
     (authmeth, auth) = authorization.split(" ", 1)
     if 'digest' != authmeth.lower():
         return self.build_authentication()
     amap = {}
     for itm in auth.split(", "):
         (k,v) = [s.strip() for s in itm.split("=", 1)]
         amap[k] = v.replace('"', '')
     try:
         username = amap['username']
         authpath = amap['uri']
         nonce    = amap['nonce']
         realm    = amap['realm']
         response = amap['response']
         assert authpath.split("?", 1)[0] in fullpath
         assert realm == self.realm
         qop      = amap.get('qop', '')
         cnonce   = amap.get('cnonce', '')
         nc       = amap.get('nc', '00000000')
         if qop:
             assert 'auth' == qop
             assert nonce and nc
     except:
         return self.build_authentication()
     ha1 = self.authfunc(environ, realm, username)
     return self.compute(ha1, username, response, method, authpath,
                         nonce, nc, cnonce, qop)
开发者ID:CGastrell,项目名称:argenmap-cachebuilder,代码行数:35,代码来源:digest.py


示例3: proxy_exact_request

def proxy_exact_request(environ, start_response):
    """
    HTTP proxying WSGI application that proxies the exact request
    given in the environment.  All controls are passed through the
    environment.

    This connects to the server given in SERVER_NAME:SERVER_PORT, and
    sends the Host header in HTTP_HOST -- they do not have to match.

    Does not add X-Forwarded-For or other standard headers
    """
    scheme = environ['wsgi.url_scheme']
    if scheme == 'http':
        ConnClass = httplib.HTTPConnection
    elif scheme == 'https':
        ConnClass = httplib.HTTPSConnection
    else:
        raise ValueError(
            "Unknown scheme: %r" % scheme)
    conn = ConnClass('%(SERVER_NAME)s:%(SERVER_PORT)s' % environ)
    headers = {}
    for key, value in environ.items():
        if key.startswith('HTTP_'):
            key = key[5:].replace('_', '-').title()
            headers[key] = value
    path = (url_quote(environ.get('SCRIPT_NAME', ''))
            + url_quote(environ.get('PATH_INFO', '')))
    if environ.get('QUERY_STRING'):
        path += '?' + environ['QUERY_STRING']
    try:
        content_length = int(environ.get('CONTENT_LENGTH', '0'))
    except ValueError:
        content_length = 0
    if content_length:
        body = environ['wsgi.input'].read(content_length)
    else:
        body = ''
    headers['Content-Length'] = content_length
    if environ.get('CONTENT_TYPE'):
        headers['Content-Type'] = environ['CONTENT_TYPE']
    if not path.startswith("/"):
        path = "/" + path
    try:
        conn.request(environ['REQUEST_METHOD'],
                     path, body, headers)
    except socket.error, exc:
        if exc.args[0] == -2:
            # Name or service not known
            exc = httpexceptions.HTTPBadGateway(
                "Name or service not known (bad domain name: %s)"
                % environ['SERVER_NAME'])
            return exc(environ, start_response)
        raise
开发者ID:nielsonsantana,项目名称:WSGIProxy,代码行数:53,代码来源:exactproxy.py


示例4: __call__

    def __call__(self, environ, start_response):
        """
        HTTP proxying WSGI application that proxies the exact request
        given in the environment.  All controls are passed through the
        environment.

        This connects to the server given in SERVER_NAME:SERVER_PORT, and
        sends the Host header in HTTP_HOST -- they do not have to match.

        Does not add X-Forwarded-For or other standard headers
        """
        
        if isinstance(self.address, basestring):
            parsed_address = urlparse(self.address)
            host = parsed_address.hostname
            port = parsed_address.port
            ConClass = self._get_conn_class(environ, parsed_address.scheme)
            conn = ConnClass(parsed_address.hostname, parsed_address.port)
        else:
            conn = self._get_conn_class(environ)(*self.address)

        headers = {}
        for key, value in environ.items():
            if key.startswith('HTTP_'):
                key = key[5:].replace('_', '-').title()
                headers[key] = value
        path = (url_quote(environ.get('SCRIPT_NAME', ''))
                + url_quote(environ.get('PATH_INFO', '')))
        if environ.get('QUERY_STRING'):
            path += '?' + environ['QUERY_STRING']
        try:
            content_length = int(environ.get('CONTENT_LENGTH', '0'))
        except ValueError:
            content_length = 0
        if content_length:
            body = environ['wsgi.input'].read(content_length)
        else:
            body = ''
        headers['Content-Length'] = content_length
        if environ.get('CONTENT_TYPE'):
            headers['Content-Type'] = environ['CONTENT_TYPE']
        if not path.startswith("/"):
            path = "/" + path
        try:
            conn.request(environ['REQUEST_METHOD'], path, body, headers)
        except socket.error, exc:
            if exc.args[0] == -2:
                return http.BadGateway()(environ, start_response)
            raise
开发者ID:DeadWisdom,项目名称:Minister,代码行数:49,代码来源:proxy.py


示例5: _get_links

def _get_links(query):
    """Return all google result links."""
    result = _get_result(SEARCH_URL.format(site=URL,
                                           query=url_quote(query)))
    html = pq(result)
    return [a.attrib['href'] for a in html('.l')] or \
        [a.attrib['href'] for a in html('.r')('a')]
开发者ID:ihfazhillah,项目名称:howdoi,代码行数:7,代码来源:howdoi.py


示例6: api

 def api(self, cmd, extras = '', no_session = False):
     ret = {}
     for _k1, api_url_k, _clienttype, _v in (('down', 'api_url', 'swjsq', 'do_down_accel'), ('up', 'api_up_url', 'uplink', 'do_up_accel')):
         if not getattr(self, _v):
             continue
         while True:
             # missing dial_account, (userid), os
             api_url = getattr(self, api_url_k)
             # TODO: phasing out time_and
             url = 'http://%s/v2/%s?%sclient_type=android-%s-%s&peerid=%s&time_and=%d&client_version=android%s-%s&userid=%s&os=android-%s%s' % (
                     api_url,
                     cmd,
                     ('sessionid=%s&' % self.xl_session) if not no_session else '',
                     _clienttype, APP_VERSION,
                     self.mac,
                     time.time() * 1000,
                     _clienttype, APP_VERSION,
                     self.xl_uid,
                     url_quote("%s.%s%s" % (OS_VERSION, OS_API_LEVEL, DEVICE_MODEL)),
                     ('&%s' % extras) if extras else '',
             )
             try:
                 ret[_k1] = {}
                 ret[_k1] = json.loads(http_req(url, headers = header_api))
                 break
             except URLError as ex:
                 uprint("Warning: error during %sapi connection: %s, use portal: %s" % (_k1, str(ex), api_url))
                 if (_k1 == 'down' and api_url == FALLBACK_PORTAL) or (_k1 == 'up' and api_url == FALLBACK_UPPORTAL):
                     print("Error: can't connect to %s api" % _k1)
                     os._exit(5)
                 if _k1 == 'down':
                     setattr(self, api_url_k, FALLBACK_PORTAL)
                 elif _k1 == 'up':
                     setattr(self, api_url_k, FALLBACK_UPPORTAL)
     return ret
开发者ID:fffonion,项目名称:Xunlei-Fastdick,代码行数:35,代码来源:swjsq.py


示例7: _add_playlist

    def _add_playlist(self, **kwargs):
        """This method is private because the class method on :class:`Playlist`
        should be used instead

        :param kwargs: The values for the playlist.  See \
        `Add Playlist <http://developer.harvestmedia.net/working-with-members-2/add-a-member-playlist/>`_

        """

        _client = kwargs.get('_client', None)
        if not _client:
            raise MissingParameter('You must pass _client to Playlist.add')

        member_id = kwargs.get('member_id', None)
        if not member_id:
            raise MissingParameter('You must pass member_id to Playlist.add')

        playlist_name = kwargs.get('playlist_name', None)
        if not playlist_name:
            raise MissingParameter('You must pass playlist_name to Playlist.add')

        method_uri = '/addplaylist/{{service_token}}/%(member_id)s/%(playlist_name)s/' % \
                        {'member_id': member_id,
                         'playlist_name': url_quote(playlist_name.encode('utf-8'))}
        xml_root = _client.get_xml(method_uri)
        playlists = xml_root.find('playlists')

        if playlists is not None:
            for playlist_xml in playlists.getchildren():
                name = playlist_xml.get('name')
                if name == playlist_name:
                    return Playlist._from_xml(playlist_xml, _client)
开发者ID:feigner,项目名称:harvestmedia,代码行数:32,代码来源:playlist.py


示例8: add_slices

        def add_slices(stats, aggregations, base):
            slice_map = {}

            for agg_key, agg in aggregations.items():
                observations= []
                slice_node = {
                    'dimension': agg_key.replace('.'+ID, ''),
                    'observation': observations
                }

                for bucket in agg['buckets']:
                    item_id = bucket.pop('key')
                    search_page_url = "{base}&{param}={value}".format(
                            base=base,
                            param=agg_key,
                            value=url_quote(item_id))

                    observation = {
                        'totalItems': bucket.pop('doc_count'),
                        'view': {ID: search_page_url},
                        'object': self.lookup(item_id)
                    }
                    observations.append(observation)

                    add_slices(observation, bucket, search_page_url)

                if observations:
                    slice_map[agg_key] = slice_node

            if slice_map:
                stats['sliceByDimension'] = slice_map
开发者ID:libris,项目名称:lxltools,代码行数:31,代码来源:dataview.py


示例9: index_html

    def index_html(self, REQUEST=None, RESPONSE=None, charset='utf-8', disposition='inline'):
        """ make it directly viewable when entering the objects URL """

        if REQUEST is None:
            REQUEST = self.REQUEST

        if RESPONSE is None:
            RESPONSE = REQUEST.RESPONSE

        RESPONSE.setHeader('Last-Modified', rfc1123_date(self._p_mtime))
        RESPONSE.setHeader('Content-Type', self.getContentType())
        RESPONSE.setHeader('Accept-Ranges', 'bytes')

        if handleIfModifiedSince(self, REQUEST, RESPONSE):
            return ''

        length = self.get_size()
        RESPONSE.setHeader('Content-Length', length)

        filename = self.getFilename()
        if filename is not None:
            if not isinstance(filename, unicode):
                filename = unicode(filename, charset, errors="ignore")
            quoted_filename = url_quote(filename.encode("utf8"))
            filename = IUserPreferredFileNameNormalizer(REQUEST).normalize(
                filename)
            header_value = contentDispositionHeader(
                disposition=disposition,
                filename=filename)
            # Add original filename in utf-8, ref to rfc2231
            header_value = header_value + "; filename*=UTF-8''" + quoted_filename
            RESPONSE.setHeader("Content-disposition", header_value)

        request_range = handleRequestRange(self, length, REQUEST, RESPONSE)
        return self.getIterator(**request_range)
开发者ID:yangh,项目名称:plone.app.blob,代码行数:35,代码来源:field.py


示例10: __init__

 def __init__(self, git_dir, hg_url):
     self.hg_url = hg_url
     self.hg_name = hg_name = url_quote(hg_url, safe="")
     self.hg_repo_dir = os.path.join(git_dir, "hgremotes", hg_name)
     if not os.path.exists(self.hg_repo_dir):
         self.initialize_hg_repo()
     self.git_repo_dir = os.path.join(self.hg_repo_dir, ".hg", "git")
开发者ID:openjdk,项目名称:git-remote-hg,代码行数:7,代码来源:__init__.py


示例11: setup

    def setup(self):
        """Setup the instance."""
        ldapi_socket = self.run_dir + "/ldapi"
        self.ldapi_url = "ldapi://" + url_quote(ldapi_socket, "")
        self.url_list = self.ldapi_url + " " + self.ldap_url

        os.makedirs(self.conf_slapd_d_dir)
        os.makedirs(self.run_dir)
        os.makedirs(self.data_dir)

        super(FakeAD, self)._setup_config()
        self._setup_config()

        # Start the daemon
        super(FakeAD, self)._start_daemon()

        # Relax requirement of surname attribute presence in person
        modlist = [
            (ldap.MOD_DELETE, "olcObjectClasses",
             b"{4}( 2.5.6.6 NAME 'person' DESC 'RFC2256: a person' SUP top "
             b"STRUCTURAL MUST ( sn $ cn ) MAY ( userPassword $ "
             b"telephoneNumber $ seeAlso $ description ) )"),
            (ldap.MOD_ADD, "olcObjectClasses",
             b"{4}( 2.5.6.6 NAME 'person' DESC 'RFC2256: a person' SUP top "
             b"STRUCTURAL MUST ( cn ) MAY ( sn $ userPassword $ "
             b"telephoneNumber $ seeAlso $ description ) )"),
        ]
        ldap_conn = ldap.initialize(self.ldapi_url)
        ldap_conn.simple_bind_s(self.admin_rdn + ",cn=config", self.admin_pw)
        ldap_conn.modify_s("cn={0}core,cn=schema,cn=config", modlist)
        ldap_conn.unbind_s()

        # restart daemon for reloading schema
        super(FakeAD, self)._stop_daemon()
        super(FakeAD, self)._start_daemon()

        # Add data
        ldap_conn = ldap.initialize(self.ldap_url)
        ldap_conn.simple_bind_s(self.admin_dn, self.admin_pw)
        ldap_conn.add_s(self.base_dn, [
            ("objectClass", [b"dcObject", b"organization"]),
            ("o", b"Example Company"),
        ])
        ldap_conn.add_s("cn=Manager," + self.base_dn, [
            ("objectClass", b"organizationalRole"),
        ])
        for ou in ("Users", "Groups", "Netgroups", "Services", "Policies"):
            ldap_conn.add_s("ou=" + ou + "," + self.base_dn, [
                ("objectClass", [b"top", b"organizationalUnit"]),
            ])
        ldap_conn.unbind_s()

        # import data from real AD
        subprocess.check_call(
            ["ldapadd", "-x", "-w", self.admin_pw, "-D",
             self.admin_dn, "-H", self.ldap_url,
             "-f", "data/ad_data.ldif"],
        )
开发者ID:SSSD,项目名称:sssd,代码行数:58,代码来源:ds_openldap.py


示例12: clientside_actions

 def clientside_actions(self, content_doc, log):
     if self.content_href:
         href = urlparse.urljoin(log.request.url, self.content_href)
         url = '%s/.deliverance/subreq?url=%s&action=%s&content=%s&theme=%s' % (
             log.request.application_url,
             url_quote(href),
             url_quote(self.name),
             url_quote(str(self.content)),
             url_quote(str(self.theme)))
         return [{'mode': 'include',
                  'callback': url}]
     if not self.if_content_matches(content_doc, log):
         return []
     content_type, content_els, content_attributes = self.select_elements(
         self.content, content_doc, theme=False)
     if not content_els:
         if self.nocontent == 'abort':
             ## FIXME: uh oh
             raise AbortTheme('No content matches content="%s"' % self.content)
         else:
             ## FIXME: log
             return []
     theme_type, theme_selector = str(self.theme).split(':', 1)
     data = {'type': self.name,
             'mode': theme_type,
             'selector': theme_selector}
     if content_type == 'attributes' or content_type == 'tag':
         data['attributes'] = dict(content_els[0].attrib)
     if content_type == 'tag':
         data['tag'] = content_els[0].tag
     elif content_type == 'children':
         text = []
         for el in content_els:
             text.append(el.text)
             for child in el:
                 text.append(tostring(child))
         data['content'] = ''.join(text)
     elif content_type == 'elements':
         text = []
         for el in content_els:
             ## FIXME: sloppy :(
             el.tail = None
             text.append(tostring(el))
         data['content'] = ''.join(text)
     return [data]
开发者ID:pombredanne,项目名称:Deliverance,代码行数:45,代码来源:rules.py


示例13: posts

 def posts(self, subscription_url, count=20):
     """
     return posts of subscriptions
     """
     url = "{subscription_url}{subscription}".format(
         subscription_url=SUBSCRIPTION_URL,
         subscription=url_quote(subscription_url, '')
     )
     return self.get_items(url, count)
开发者ID:rootart,项目名称:grbackup,代码行数:9,代码来源:greader.py


示例14: transform

 def transform(row, table):
     file_data = tag_to_dict(row.filename)
     absolute_url = url_join(URL_ROUTER_SEARCH,
                             url_quote(file_data['href']))
     return {'date': extract_text(row.date),
             'description': extract_text(row.description),
             'filename': file_data['text'],
             'size': extract_text(row.size),
             'url': absolute_url, }
开发者ID:turicas,项目名称:ddwrtdb,代码行数:9,代码来源:ddwrtdb.py


示例15: mkdtemp

    def mkdtemp(self, prefix):
        """
        Creates a new directory in the document root and returns its path and
        URI.
        """
        path = mkdtemp(prefix=prefix + "_", dir=self.docroot)
        uri  = joinURL("/", url_quote(os.path.basename(path))) + "/"

        return (os.path.abspath(path), uri)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:9,代码来源:util.py


示例16: vcal

def vcal(request):
    data = {}
    data['page_title'] = "vCal exports"
    authenticated_user_string = None
    if request.user.is_authenticated():
        authenticated_user_string = (request.user.email and
                                     url_quote(request.user.email)
                                     or request.user.username)
    data['authenticated_user_string'] = authenticated_user_string
    return jingo.render(request, 'vcal/vcal.html', data)
开发者ID:mozilla,项目名称:sheriffs,代码行数:10,代码来源:views.py


示例17: get_search_hits

def get_search_hits(query):
    """
    Get links pointing to answers to a query, out of the results served by a
    search engine about that query

    :returns: a list of links, as plain text
    """
    page = Page(SEARCH_URL.format(SITE_URL, url_quote(query)))
    search_hits = SearchHit(page)
    return search_hits
开发者ID:NacionLumpen,项目名称:pbs,代码行数:10,代码来源:lookup.py


示例18: cleanId

def cleanId(id):
    """'url_quote' turns strange chars into '%xx', which is not a valid char
    for ObjectManager. Here we encode '%' into '-' (and '-' into '--' as escaping).
    De-clean is possible; see 'decleanId'.
    Assumes that id can start with non-alpha(numeric), which is true.
    """
    __traceback_info__ = (id,)
    if id:
        # note: we provide the 'safe' param to get '/' encoded
        return url_quote(id, '').replace('-','--').replace('%','-')
    return ''
开发者ID:dtgit,项目名称:dtedu,代码行数:11,代码来源:utils.py


示例19: _get_links

def _get_links(query):
    search_engine = os.getenv('HOWDOI_SEARCH_ENGINE', 'google')
    search_url = _get_search_url(search_engine)

    result = _get_result(search_url.format(URL, url_quote(query)))
    if _is_blocked(result):
        _print_err('Unable to find an answer because the search engine temporarily blocked the request. '
                   'Please wait a few minutes or select a different search engine.')
        raise BlockError("Temporary block by search engine")

    html = pq(result)
    return _extract_links(html, search_engine)
开发者ID:Donearm,项目名称:howdoi,代码行数:12,代码来源:howdoi.py


示例20: is_logged_in

 def is_logged_in(self):
     guid = self.get_secure_cookie('user')
     if guid:
         if self.db.users.User(dict(guid=guid)):
             return func(self)
     if redirect_to:
         next = self.request.path
         if self.request.query:
             next += '?%s' % self.request.query
         url = redirect_to + '?next=%s' % url_quote(next)
         self.redirect(url)
     else:
         raise HTTPError(403, "Must be logged in")
开发者ID:Gautier,项目名称:toocool,代码行数:13,代码来源:decorators.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python urllib.urlcleanup函数代码示例发布时间:2022-05-27
下一篇:
Python urllib.url2pathname函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap