当前位置: 首页>>代码示例>>Python>>正文


Python urllib.quote方法代码示例

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


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

示例1: urlEncodeMe

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import quote [as 别名]
def urlEncodeMe(elem, safe=' '):
    """
        Converts any values that would cause JSON parsing to fail into URL percent encoding equivalents.
        This function can be used for any valid JSON type including str, dict, list.
        Returns:
            Same element properly encoded.
    """
    # What type am I?
    if isinstance(elem, dict):
        return {urlEncodeMe(key, safe): urlEncodeMe(value, safe) for key, value in six.iteritems(elem)}
    elif isinstance(elem, list):
        return [urlEncodeMe(element, safe) for element in elem]
    elif isinstance(elem, str):
        # Leave spaces alone, they are save to travel for JSON parsing
        return urllib.quote(elem, safe)
    else:
        return elem 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:19,代码来源:pdutils.py

示例2: get_contents

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import quote [as 别名]
def get_contents(self, path, ref=github.GithubObject.NotSet):
        """
        :calls: `GET /repos/:owner/:repo/contents/:path <http://developer.github.com/v3/repos/contents>`_
        :param path: string
        :param ref: string
        :rtype: :class:`github.ContentFile.ContentFile`
        """
        assert isinstance(path, (str, unicode)), path
        assert ref is github.GithubObject.NotSet or isinstance(ref, (str, unicode)), ref
        url_parameters = dict()
        if ref is not github.GithubObject.NotSet:
            url_parameters["ref"] = ref
        headers, data = self._requester.requestJsonAndCheck(
            "GET",
            self.url + "/contents/" + urllib.quote(path),
            parameters=url_parameters
        )
        if isinstance(data, list):
            return [
                github.ContentFile.ContentFile(self._requester, headers, item, completed=False)
                for item in data
            ]
        return github.ContentFile.ContentFile(self._requester, headers, data, completed=True) 
开发者ID:danielecook,项目名称:gist-alfred,代码行数:25,代码来源:Repository.py

示例3: legacy_search_issues

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import quote [as 别名]
def legacy_search_issues(self, state, keyword):
        """
        :calls: `GET /legacy/issues/search/:owner/:repository/:state/:keyword <http://developer.github.com/v3/search/legacy>`_
        :param state: "open" or "closed"
        :param keyword: string
        :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Issue.Issue`
        """
        assert state in ["open", "closed"], state
        assert isinstance(keyword, (str, unicode)), keyword
        headers, data = self._requester.requestJsonAndCheck(
            "GET",
            "/legacy/issues/search/" + self.owner.login + "/" + self.name + "/" + state + "/" + urllib.quote(keyword)
        )
        return [
            github.Issue.Issue(self._requester, headers, github.Legacy.convertIssue(element), completed=False)
            for element in data["issues"]
        ] 
开发者ID:danielecook,项目名称:gist-alfred,代码行数:19,代码来源:Repository.py

示例4: validate_

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import quote [as 别名]
def validate_(self, value, context=None):
        url = self.valid_url(value)
        if not url:
            raise StopValidationError(self.messages['invalid_url'])
        if self.verify_exists:
            url_string = urlquote(urlunsplit((
                url['scheme'],
                (url['host6'] or url['host4'] or url['hostn_enc']) + ':' + (url['port'] or ''),
                url['path'],
                url['query'],
                url['frag'])
                ).encode('utf-8'), safe=VALID_CHAR_STRING)
            try:
                urlopen(url_string)
            except URLError:
                raise StopValidationError(self.messages['not_found']) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:18,代码来源:net.py

示例5: url_from_path

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import quote [as 别名]
def url_from_path(path):
    fspath = path_to_fspath(path, False)
    from urllib import quote
    if ISWINDOWS:
        match = _reg_allow_disk.match(fspath)
        fspath = fspath.replace('\\', '/')
        if match.group(1):
            fspath = '/%s%s' % (match.group(1).replace('\\', '/'),
                                quote(fspath[len(match.group(1)):]))
        else:
            fspath = quote(fspath)
    else:
        fspath = quote(fspath)
    if path.rev != -1:
        fspath = '%s@%s' % (fspath, path.rev)
    else:
        fspath = '%s@HEAD' % (fspath,)
    return 'file://%s' % (fspath,) 
开发者ID:pytest-dev,项目名称:py,代码行数:20,代码来源:svnwc.py

示例6: _encode_params

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import quote [as 别名]
def _encode_params(self, params):
        if not params:
            return ""

        key_values = []
        for k, v in params:
            k = urllib.quote(k, safe='%')
            if v is None:
                key_values.append(k)
            else:
                if isinstance(v, tuple) or isinstance(v, list):
                    # for upload fields
                    v = v[0]
                v = urllib.quote(v, safe='%')
                key_values.append("%s=%s" % (k, v))
        return "&".join(key_values) 
开发者ID:flipkart-incubator,项目名称:watchdog,代码行数:18,代码来源:HTTP.py

示例7: diff_toDelta

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import quote [as 别名]
def diff_toDelta(self, diffs):
        """Crush the diff into an encoded string which describes the operations
        required to transform text1 into text2.
        E.g. =3\t-2\t+ing  -> Keep 3 chars, delete 2 chars, insert 'ing'.
        Operations are tab-separated.  Inserted text is escaped using %xx notation.

        Args:
            diffs: Array of diff tuples.

        Returns:
            Delta text.
        """
        text = []
        for (op, data) in diffs:
            if op == self.DIFF_INSERT:
                # High ascii will raise UnicodeDecodeError.  Use Unicode instead.
                data = data.encode("utf-8")
                text.append("+" + parse.quote(data, "!~*'();/?:@&=+$,# "))
            elif op == self.DIFF_DELETE:
                text.append("-%d" % len(data))
            elif op == self.DIFF_EQUAL:
                text.append("=%d" % len(data))
        return "\t".join(text) 
开发者ID:typeintandem,项目名称:tandem,代码行数:25,代码来源:diff_match_patch.py

示例8: _encode_settings

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import quote [as 别名]
def _encode_settings(self, settings, suffix=''):
        if pulseaudio_dlna.streamserver.StreamServer.HOST:
            server_ip = pulseaudio_dlna.streamserver.StreamServer.HOST
        else:
            server_ip = pulseaudio_dlna.utils.network.get_host_by_ip(self.ip)
        if not server_ip:
            raise NoSuitableHostFoundException(self.ip)
        server_port = pulseaudio_dlna.streamserver.StreamServer.PORT
        base_url = 'http://{ip}:{port}'.format(
            ip=server_ip,
            port=server_port,
        )
        data_string = ','.join(
            ['{}="{}"'.format(k, v) for k, v in settings.iteritems()])
        stream_name = '/{base_string}/{suffix}'.format(
            base_string=urllib.quote(base64.b64encode(data_string)),
            suffix=suffix,
        )
        return urlparse.urljoin(base_url, stream_name) 
开发者ID:masmu,项目名称:pulseaudio-dlna,代码行数:21,代码来源:renderer.py

示例9: login_redirect

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import quote [as 别名]
def login_redirect(application_url, continue_url, start_response):
  """Writes a login redirection URL to a user.

  This redirects to login_url with a continue parameter to return to
  continue_url. The login_url should be on the canonical front-end server,
  regardless of the host:port the user connected to.

  Args:
    application_url: The URL of the dev appserver domain
      (e.g., 'http://localhost:8080').
    continue_url: The URL to continue to after the user logs in.
    start_response: A WSGI start_response function.

  Returns:
    An (empty) iterable over strings containing the body of the HTTP response.
  """
  if not application_url.endswith('/'):
    application_url += '/'
  redirect_url = '%s%s?%s=%s' % (application_url, LOGIN_URL_RELATIVE,
                                 CONTINUE_PARAM, urllib.quote(continue_url))
  start_response('302 Requires login',
                 [('Location', redirect_url)])
  return [] 
开发者ID:elsigh,项目名称:browserscope,代码行数:25,代码来源:login.py

示例10: LoginRedirect

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import quote [as 别名]
def LoginRedirect(login_url,
                  hostname,
                  port,
                  relative_url,
                  outfile):
  """Writes a login redirection URL to a user.

  Args:
    login_url: Relative URL which should be used for handling user logins.
    hostname: Name of the host on which the webserver is running.
    port: Port on which the webserver is running.
    relative_url: String containing the URL accessed.
    outfile: File-like object to which the response should be written.
  """
  dest_url = "http://%s:%s%s" % (hostname, port, relative_url)
  redirect_url = 'http://%s:%s%s?%s=%s' % (hostname,
                                           port,
                                           login_url,
                                           CONTINUE_PARAM,
                                           urllib.quote(dest_url))
  outfile.write('Status: 302 Requires login\r\n')
  outfile.write('Location: %s\r\n\r\n' % redirect_url) 
开发者ID:elsigh,项目名称:browserscope,代码行数:24,代码来源:dev_appserver_login.py

示例11: _encode_query

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import quote [as 别名]
def _encode_query(self,query):
        # TODO Python 3 urllib.parse.quote 
        return urllib.quote(query) 
开发者ID:skillachie,项目名称:news-corpus-builder,代码行数:5,代码来源:news_corpus_generator.py

示例12: cmd_encode

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import quote [as 别名]
def cmd_encode(self, event, *args):
        """URL encode text. 'url encode <text>'"""
        # use the body directly so quotes are parsed correctly.
        return urllib.quote(event["content"]["body"][12:]) 
开发者ID:matrix-org,项目名称:Matrix-NEB,代码行数:6,代码来源:url.py

示例13: remove_from_labels

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import quote [as 别名]
def remove_from_labels(self, label):
        """
        :calls: `DELETE /repos/:owner/:repo/issues/:number/labels/:name <http://developer.github.com/v3/issues/labels>`_
        :param label: :class:`github.Label.Label` or string
        :rtype: None
        """
        assert isinstance(label, (github.Label.Label, str, unicode)), label
        if isinstance(label, github.Label.Label):
            label = label._identity
        else:
            label = urllib.quote(label)
        headers, data = self._requester.requestJsonAndCheck(
            "DELETE",
            self.issue_url + "/labels/" + label
        ) 
开发者ID:danielecook,项目名称:gist-alfred,代码行数:17,代码来源:PullRequest.py

示例14: get_dir_contents

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import quote [as 别名]
def get_dir_contents(self, path, ref=github.GithubObject.NotSet):
        """
        :calls: `GET /repos/:owner/:repo/contents/:path <http://developer.github.com/v3/repos/contents>`_
        :param path: string
        :param ref: string
        :rtype: list of :class:`github.ContentFile.ContentFile`
        """
        assert isinstance(path, (str, unicode)), path
        assert ref is github.GithubObject.NotSet or isinstance(ref, (str, unicode)), ref
        url_parameters = dict()
        if ref is not github.GithubObject.NotSet:
            url_parameters["ref"] = ref
        headers, data = self._requester.requestJsonAndCheck(
            "GET",
            self.url + "/contents/" + urllib.quote(path),
            parameters=url_parameters
        )

        # Handle 302 redirect response
        if headers.get('status') == '302 Found' and headers.get('location'):
            headers, data = self._requester.requestJsonAndCheck(
                "GET",
                headers['location'],
                parameters=url_parameters
            )

        return [
            github.ContentFile.ContentFile(self._requester, headers, attributes, completed=(attributes["type"] != "file"))  # Lazy completion only makes sense for files. See discussion here: https://github.com/jacquev6/PyGithub/issues/140#issuecomment-13481130
            for attributes in data
        ] 
开发者ID:danielecook,项目名称:gist-alfred,代码行数:32,代码来源:Repository.py

示例15: _identity

# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import quote [as 别名]
def _identity(self):
        return urllib.quote(self.name) 
开发者ID:danielecook,项目名称:gist-alfred,代码行数:4,代码来源:Label.py


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