當前位置: 首頁>>代碼示例>>Python>>正文


Python parse.unquote方法代碼示例

本文整理匯總了Python中six.moves.urllib.parse.unquote方法的典型用法代碼示例。如果您正苦於以下問題:Python parse.unquote方法的具體用法?Python parse.unquote怎麽用?Python parse.unquote使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在six.moves.urllib.parse的用法示例。


在下文中一共展示了parse.unquote方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: post_account

# 需要導入模塊: from six.moves.urllib import parse [as 別名]
# 或者: from six.moves.urllib.parse import unquote [as 別名]
def post_account(self, headers, query_string=None, data=None,
                     response_dict=None):
        if query_string == 'bulk-delete':
            resp = {'Response Status': '200 OK',
                    'Response Body': '',
                    'Number Deleted': 0,
                    'Number Not Found': 0}
            if response_dict is not None:
                response_dict['status'] = 200
            if data:
                for path in data.splitlines():
                    try:
                        __, container, obj = (unquote(path.decode('utf8'))
                                              .split('/', 2))
                        del self.kvs[container][obj]
                        resp['Number Deleted'] += 1
                    except KeyError:
                        resp['Number Not Found'] += 1
            return {}, json.dumps(resp).encode('utf-8')

        if response_dict is not None:
            response_dict['status'] = 204

        return {}, None 
開發者ID:gnocchixyz,項目名稱:gnocchi,代碼行數:26,代碼來源:base.py

示例2: deurlquote

# 需要導入模塊: from six.moves.urllib import parse [as 別名]
# 或者: from six.moves.urllib.parse import unquote [as 別名]
def deurlquote(d, plus=False):
    """
    Decode a percent encoded string.

    Args:
        d(str): The percent encoded value to decode.
        plus(bool): Parse a plus symbol as a space.

    Returns:
        str: The decoded version of the percent encoded of ``d``.

    Example:
        >>> from pwny import *
        >>> deurlquote('Foo+Bar/Baz')
        'Foo Bar/Baz'
    """
    return unquote_plus(d) if plus else unquote(d) 
開發者ID:edibledinos,項目名稱:pwnypack,代碼行數:19,代碼來源:codec.py

示例3: decode

# 需要導入模塊: from six.moves.urllib import parse [as 別名]
# 或者: from six.moves.urllib.parse import unquote [as 別名]
def decode(data_url):
    """
    Decode DataURL data
    """
    metadata, data = data_url.rsplit(',', 1)
    _, metadata = metadata.split('data:', 1)
    parts = metadata.split(';')
    if parts[-1] == 'base64':
        data = b64decode(data)
    else:
        data = unquote(data)

    for part in parts:
        if part.startswith("charset="):
            data = data.decode(part[8:])
    return data 
開發者ID:binux,項目名稱:pyspider,代碼行數:18,代碼來源:dataurl.py

示例4: test_default

# 需要導入模塊: from six.moves.urllib import parse [as 別名]
# 或者: from six.moves.urllib.parse import unquote [as 別名]
def test_default(self):
        target = TestTableauServerResultTarget(test_config.get_tmp_path('result.job'))
        target.datasource = 'test-datasource'
        url = urlparse(target.get_result_url())
        params = parse_qs(url.query)
        eq_(url.scheme, 'tableau')
        eq_(url.hostname, 'tableau.example.com')
        eq_(url.path, '/' + target.datasource)
        eq_(url_unquote(url.username), TestTableauServerResultTarget.username)
        eq_(url_unquote(url.password), TestTableauServerResultTarget.password)
        eq_(params.get('ssl'), ['true'])
        eq_(params.get('ssl_verify'), ['true'])
        eq_(params.get('server_version'), None)
        eq_(params.get('site'), None)
        eq_(params.get('project'), None)
        eq_(params.get('mode'), ['replace']) 
開發者ID:treasure-data,項目名稱:luigi-td,代碼行數:18,代碼來源:test_tableau.py

示例5: get

# 需要導入模塊: from six.moves.urllib import parse [as 別名]
# 或者: from six.moves.urllib.parse import unquote [as 別名]
def get(self, bucket, object_name):
        object_name = parse.unquote(object_name)
        path = self._object_path(bucket, object_name)
        if (not path.startswith(self.application.directory) or
                not os.path.isfile(path)):
            self.set_404()
            return
        info = os.stat(path)
        self.set_header("Content-Type", "application/unknown")
        self.set_header("Last-Modified", datetime.datetime.utcfromtimestamp(
            info.st_mtime))
        object_file = open(path, "rb")
        try:
            self.finish(object_file.read())
        finally:
            object_file.close() 
開發者ID:openstack,項目名稱:ec2-api,代碼行數:18,代碼來源:s3server.py

示例6: put

# 需要導入模塊: from six.moves.urllib import parse [as 別名]
# 或者: from six.moves.urllib.parse import unquote [as 別名]
def put(self, bucket, object_name):
        object_name = parse.unquote(object_name)
        bucket_dir = os.path.abspath(os.path.join(
            self.application.directory, bucket))
        if (not bucket_dir.startswith(self.application.directory) or
                not os.path.isdir(bucket_dir)):
            self.set_404()
            return
        path = self._object_path(bucket, object_name)
        if not path.startswith(bucket_dir) or os.path.isdir(path):
            self.set_status(403)
            return
        directory = os.path.dirname(path)
        fileutils.ensure_tree(directory)
        object_file = open(path, "wb")
        object_file.write(self.request.body)
        object_file.close()
        self.set_header('ETag',
                        '"%s"' % utils.get_hash_str(self.request.body))
        self.finish() 
開發者ID:openstack,項目名稱:ec2-api,代碼行數:22,代碼來源:s3server.py

示例7: _parse_dav_element

# 需要導入模塊: from six.moves.urllib import parse [as 別名]
# 或者: from six.moves.urllib.parse import unquote [as 別名]
def _parse_dav_element(self, dav_response):
        """Parses a single DAV element

        :param dav_response: DAV response
        :returns :class:`FileInfo`
        """
        href = parse.unquote(
            self._strip_dav_path(dav_response.find('{DAV:}href').text)
        )

        if six.PY2:
            href = href.decode('utf-8')

        file_type = 'file'
        if href[-1] == '/':
            file_type = 'dir'

        file_attrs = {}
        attrs = dav_response.find('{DAV:}propstat')
        attrs = attrs.find('{DAV:}prop')
        for attr in attrs:
            file_attrs[attr.tag] = attr.text

        return FileInfo(href, file_type, file_attrs) 
開發者ID:owncloud,項目名稱:pyocclient,代碼行數:26,代碼來源:owncloud.py

示例8: line_part

# 需要導入模塊: from six.moves.urllib import parse [as 別名]
# 或者: from six.moves.urllib.parse import unquote [as 別名]
def line_part(self):
        # type: () -> STRING_TYPE
        link_url = None  # type: Optional[STRING_TYPE]
        seed = None  # type: Optional[STRING_TYPE]
        if self.link is not None:
            link_url = unquote(self.link.url_without_fragment)
        is_vcs = getattr(self.link, "is_vcs", not self.link.is_artifact)
        if self._uri_scheme and self._uri_scheme == "path":
            # We may need any one of these for passing to pip
            seed = self.path or link_url or self.uri
        elif (self._uri_scheme and self._uri_scheme == "file") or (
            (self.link.is_wheel or not is_vcs) and self.link.url
        ):
            seed = link_url or self.uri
        # add egg fragments to remote artifacts (valid urls only)
        if not self._has_hashed_name and self.is_remote_artifact and seed is not None:
            seed += "#egg={0}".format(self.name)
        editable = "-e " if self.editable else ""
        if seed is None:
            raise ValueError("Could not calculate url for {0!r}".format(self))
        return "{0}{1}".format(editable, seed) 
開發者ID:pypa,項目名稱:pipenv,代碼行數:23,代碼來源:requirements.py

示例9: _get_parsed_url

# 需要導入模塊: from six.moves.urllib import parse [as 別名]
# 或者: from six.moves.urllib.parse import unquote [as 別名]
def _get_parsed_url(url):
    # type: (S) -> Url
    """This is a stand-in function for `urllib3.util.parse_url`

    The orignal function doesn't handle special characters very well, this simply splits
    out the authentication section, creates the parsed url, then puts the authentication
    section back in, bypassing validation.

    :return: The new, parsed URL object
    :rtype: :class:`~urllib3.util.url.Url`
    """

    try:
        parsed = urllib3_parse(url)
    except ValueError:
        scheme, _, url = url.partition("://")
        auth, _, url = url.rpartition("@")
        url = "{scheme}://{url}".format(scheme=scheme, url=url)
        parsed = urllib3_parse(url)._replace(auth=auth)
    if parsed.auth:
        return parsed._replace(auth=url_unquote(parsed.auth))
    return parsed 
開發者ID:pypa,項目名稱:pipenv,代碼行數:24,代碼來源:url.py

示例10: parse_frame

# 需要導入模塊: from six.moves.urllib import parse [as 別名]
# 或者: from six.moves.urllib.parse import unquote [as 別名]
def parse_frame(frame):
        parsed = unquote(frame)
        chunk = {}
        last_key = 'Body'
        for line in parsed.strip().splitlines():
            if not line:
                last_key = 'Body'
                continue
            key, sep, value = line.partition(': ')
            if sep and key and key[0] is not '+':  # 'key: value' header
                last_key = key
                chunk[key] = value
            else:
                # no sep - 2 cases: multi-line value or body content
                chunk[last_key] = chunk.setdefault(
                    last_key, '') + line + '\n'
        return chunk 
開發者ID:friends-of-freeswitch,項目名稱:switchio,代碼行數:19,代碼來源:protocol.py

示例11: translate_path

# 需要導入模塊: from six.moves.urllib import parse [as 別名]
# 或者: from six.moves.urllib.parse import unquote [as 別名]
def translate_path(self, path):
        """Translate a /-separated PATH to the local filename syntax.

        Components that mean special things to the local file system
        (e.g. drive or directory names) are ignored.  (XXX They should
        probably be diagnosed.)

        """
        # abandon query parameters
        path = path.split('?', 1)[0]
        path = path.split('#', 1)[0]
        path = posixpath.normpath(unquote(path))
        words = path.split('/')
        words = filter(None, words)
        path = os.getcwd()
        for word in words:
            drive, word = os.path.splitdrive(word)
            head, word = os.path.split(word)
            if word in (os.curdir, os.pardir): continue
            path = os.path.join(path, word)
        return path 
開發者ID:ywangd,項目名稱:stash,代碼行數:23,代碼來源:httpserver.py

示例12: _header_to_id

# 需要導入模塊: from six.moves.urllib import parse [as 別名]
# 或者: from six.moves.urllib.parse import unquote [as 別名]
def _header_to_id(self, header):
    """Convert a Content-ID header value to an id.

    Presumes the Content-ID header conforms to the format that _id_to_header()
    returns.

    Args:
      header: string, Content-ID header value.

    Returns:
      The extracted id value.

    Raises:
      BatchError if the header is not in the expected format.
    """
    if header[0] != '<' or header[-1] != '>':
      raise BatchError("Invalid value for Content-ID: %s" % header)
    if '+' not in header:
      raise BatchError("Invalid value for Content-ID: %s" % header)
    base, id_ = header[1:-1].split(' + ', 1)

    return unquote(id_) 
開發者ID:fniephaus,項目名稱:alfred-gmail,代碼行數:24,代碼來源:http.py

示例13: _header_to_id

# 需要導入模塊: from six.moves.urllib import parse [as 別名]
# 或者: from six.moves.urllib.parse import unquote [as 別名]
def _header_to_id(self, header):
    """Convert a Content-ID header value to an id.

    Presumes the Content-ID header conforms to the format that _id_to_header()
    returns.

    Args:
      header: string, Content-ID header value.

    Returns:
      The extracted id value.

    Raises:
      BatchError if the header is not in the expected format.
    """
    if header[0] != '<' or header[-1] != '>':
      raise BatchError("Invalid value for Content-ID: %s" % header)
    if '+' not in header:
      raise BatchError("Invalid value for Content-ID: %s" % header)
    base, id_ = header[1:-1].rsplit('+', 1)

    return unquote(id_) 
開發者ID:luci,項目名稱:luci-py,代碼行數:24,代碼來源:http.py

示例14: sign_request

# 需要導入模塊: from six.moves.urllib import parse [as 別名]
# 或者: from six.moves.urllib.parse import unquote [as 別名]
def sign_request(self, request):
        """
        Generator signature for request.

        :param request: request object
        :return: none
        """
        url = request.path_url
        url_components = urlparse(unquote(url))
        canonical_str = self._build_canonical_str(url_components, request)
        logger.debug('canonical string: ' + canonical_str)

        sign = to_str(hmac_sha1(self._access_key, canonical_str))

        auth_str = 'DATAHUB %s:%s' % (self._access_id, sign)
        request.headers[Headers.AUTHORIZATION] = auth_str 
開發者ID:aliyun,項目名稱:aliyun-datahub-sdk-python,代碼行數:18,代碼來源:aliyun_account.py

示例15: handle_url

# 需要導入模塊: from six.moves.urllib import parse [as 別名]
# 或者: from six.moves.urllib.parse import unquote [as 別名]
def handle_url(self, url):
        # alarm_url = 'http://host:port/v1.0/vnfs/vnf-uuid/mon-policy-name/action-name/8ef785' # noqa
        parts = parse.urlparse(url)
        p = parts.path.split('/')
        if len(p) != 7:
            return None

        if any((p[0] != '', p[2] != 'vnfs')):
            return None
        # decode action name: respawn%25log
        p[5] = parse.unquote(p[5])
        qs = parse.parse_qs(parts.query)
        params = dict((k, v[0]) for k, v in qs.items())
        prefix_url = '/%(collec)s/%(vnf_uuid)s/' % {'collec': p[2],
                                                    'vnf_uuid': p[3]}
        return prefix_url, p, params 
開發者ID:openstack,項目名稱:tacker,代碼行數:18,代碼來源:alarm_receiver.py


注:本文中的six.moves.urllib.parse.unquote方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。