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


Python parse.quote方法代码示例

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


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

示例1: enurlquote

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import quote [as 别名]
def enurlquote(v, plus=False):
    """
    Percent encode a string for use in an URL.

    Args:
        v(str): The value to percent encode.
        plus(bool): Use a plus symbol for spaces, otherwise use %20.

    Returns:
        str: The percent encoded string.

    Example:
        >>> from pwny import *
        >>> enurlquote('Foo Bar/Baz', True)
        'Foo+Bar/Baz
    """
    return quote_plus(v) if plus else quote(v) 
开发者ID:edibledinos,项目名称:pwnypack,代码行数:19,代码来源:codec.py

示例2: encode

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import quote [as 别名]
def encode(data, mime_type='', charset='utf-8', base64=True):
    """
    Encode data to DataURL
    """
    if isinstance(data, six.text_type):
        data = data.encode(charset)
    else:
        charset = None
    if base64:
        data = utils.text(b64encode(data))
    else:
        data = utils.text(quote(data))

    result = ['data:', ]
    if mime_type:
        result.append(mime_type)
    if charset:
        result.append(';charset=')
        result.append(charset)
    if base64:
        result.append(';base64')
    result.append(',')
    result.append(data)

    return ''.join(result) 
开发者ID:binux,项目名称:pyspider,代码行数:27,代码来源:dataurl.py

示例3: get_result_url

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import quote [as 别名]
def get_result_url(self):
        reqs = {}
        for name in ['server', 'username', 'password', 'datasource']:
            if getattr(self, name) is None:
                raise TypeError('missing option "{0}" for {1}'.format(name, self))
            reqs[name] = url_quote(getattr(self, name))
        params = {
            'ssl': self.ssl,
            'ssl_verify': self.ssl_verify,
            'server_version': self.server_version,
            'site': self.site,
            'project': self.project,
            'mode': self.mode,
        }
        reqs['params'] = urlencode([(key, params[key]) for key in params if params[key] is not None])
        return "tableau://{username}:{password}@{server}/{datasource}?{params}".format(**reqs) 
开发者ID:treasure-data,项目名称:luigi-td,代码行数:18,代码来源:tableau.py

示例4: get_authorization_uri

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import quote [as 别名]
def get_authorization_uri(self, client_id, scopes, redirect_uri, response_type, state=None):
        """
        Helper method to configure the OAuth accessCode/implicit flow parameters
        :param client_id: DocuSign OAuth Client Id(AKA Integrator Key)
        :param scopes: The list of requested scopes.  Client applications may be scoped to a limited set of system access.
        :param redirect_uri: This determines where to deliver the response containing the authorization code
        :param response_type: Determines the response type of the authorization request, NOTE: these response types are
        mutually exclusive for a client application. A public/native client application may only request a response type
         of "token". A private/trusted client application may only request a response type of "code".
        :param state: Allows for arbitrary state that may be useful to your application. The value in this parameter
        will be round-tripped along with the response so you can make sure it didn't change.
        :return: string
        """
        if not self.oauth_host_name:
            self.oauth_host_name = self.get_oauth_host_name()
        scopes = " ".join(scopes) if scopes else ""
        uri = "https://{}/oauth/auth?response_type={}&scope={}&client_id={}&redirect_uri={}"
        if state:
            uri += "&state={}"
        return uri.format(self.oauth_host_name, response_type, quote(scopes), client_id, redirect_uri, state) 
开发者ID:docusign,项目名称:docusign-python-client,代码行数:22,代码来源:api_client.py

示例5: get_file_contents

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import quote [as 别名]
def get_file_contents(self, path):
        """Returns the contents of a remote file

        :param path: path to the remote file
        :returns: file contents
        :rtype: binary data
        :raises: HTTPResponseError in case an HTTP error status was returned
        """
        path = self._normalize_path(path)
        res = self._session.get(
            self._webdav_url + parse.quote(self._encode_string(path))
        )
        if res.status_code == 200:
            return res.content
        elif res.status_code >= 400:
            raise HTTPResponseError(res)
        return False 
开发者ID:owncloud,项目名称:pyocclient,代码行数:19,代码来源:owncloud.py

示例6: set_user_attribute

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import quote [as 别名]
def set_user_attribute(self, user_name, key, value):
        """Sets a user attribute

        :param user_name: name of user to modify
        :param key: key of the attribute to set
        :param value: value to set
        :returns: True if the operation succeeded, False otherwise
        :raises: HTTPResponseError in case an HTTP error status was returned
        """

        res = self._make_ocs_request(
            'PUT',
            self.OCS_SERVICE_CLOUD,
            'users/' + parse.quote(user_name),
            data={'key': self._encode_string(key),
                  'value': self._encode_string(value)}
        )

        if res.status_code == 200:
            tree = ET.fromstring(res.content)
            self._check_ocs_status(tree, [100])
            return True
        raise HTTPResponseError(res) 
开发者ID:owncloud,项目名称:pyocclient,代码行数:25,代码来源:owncloud.py

示例7: set_attribute

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import quote [as 别名]
def set_attribute(self, app, key, value):
        """Sets an application attribute

        :param app: application id
        :param key: key of the attribute to set
        :param value: value to set
        :returns: True if the operation succeeded, False otherwise
        :raises: HTTPResponseError in case an HTTP error status was returned
        """
        path = 'setattribute/' + parse.quote(app, '') + '/' + parse.quote(
            self._encode_string(key), '')
        res = self._make_ocs_request(
            'POST',
            self.OCS_SERVICE_PRIVATEDATA,
            path,
            data={'value': self._encode_string(value)}
        )
        if res.status_code == 200:
            tree = ET.fromstring(res.content)
            self._check_ocs_status(tree)
            return True
        raise HTTPResponseError(res) 
开发者ID:owncloud,项目名称:pyocclient,代码行数:24,代码来源:owncloud.py

示例8: delete_attribute

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import quote [as 别名]
def delete_attribute(self, app, key):
        """Deletes an application attribute

        :param app: application id
        :param key: key of the attribute to delete
        :returns: True if the operation succeeded, False otherwise
        :raises: HTTPResponseError in case an HTTP error status was returned
        """
        path = 'deleteattribute/' + parse.quote(app, '') + '/' + parse.quote(
            self._encode_string(key), '')
        res = self._make_ocs_request(
            'POST',
            self.OCS_SERVICE_PRIVATEDATA,
            path
        )
        if res.status_code == 200:
            tree = ET.fromstring(res.content)
            self._check_ocs_status(tree)
            return True
        raise HTTPResponseError(res) 
开发者ID:owncloud,项目名称:pyocclient,代码行数:22,代码来源:owncloud.py

示例9: _construct_url

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import quote [as 别名]
def _construct_url(self, relative_path, query_params=None, extattrs=None):
        if query_params is None:
            query_params = {}
        if extattrs is None:
            extattrs = {}

        if not relative_path or relative_path[0] == '/':
            raise ValueError('Path in request must be relative.')
        query = ''
        if query_params or extattrs:
            query = '?'

        if extattrs:
            attrs_queries = []
            for key, value in extattrs.items():
                LOG.debug("key: %s, value: %s", key, value)
                attrs_queries.append('*' + key + '=' + value['value'])
            query += '&'.join(attrs_queries)
        if query_params:
            if len(query) > 1:
                query += '&'
            query += parse.urlencode(query_params)

        baseurl = parse.urljoin(self.wapi_url, parse.quote(relative_path))
        return baseurl + query 
开发者ID:openstack,项目名称:designate,代码行数:27,代码来源:connector.py

示例10: create_motp_url

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import quote [as 别名]
def create_motp_url(key, user=None, realm=None, serial=""):
    """
    This creates the motp url as described at
    http://huseynov.com/index.php?post=motp-vs-google-authenticator-and-a-new-otp-app
    
    The format is:
    motp://SecureSite:alice@wonder.land?secret=JBSWY3DPEHPK3PXP
    """
    # For Token2 the OTPKEY is hexencoded, not base32!
    otpkey = key
    # TODO: Migration: Policy
    #Policy = PolicyClass(request, config, c,
    #                     get_privacyidea_config())
    # label = Policy.get_tokenlabel(user, realm, serial)
    label = "mylabel"
    allowed_label_len = 20
    label = label[0:allowed_label_len]
    url_label = quote(label)
    
    return "motp://privacyidea:{0!s}?secret={1!s}".format(url_label, otpkey) 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:22,代码来源:apps.py

示例11: create_oathtoken_url

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import quote [as 别名]
def create_oathtoken_url(otpkey=None, user=None, realm=None,
                         type="hotp", serial="mylabel", tokenlabel="<s>",
                         extra_data=None):
    timebased = ""
    if "totp" == type.lower():
        timebased = "&timeBased=true"
    # We need realm und user to be a string
    realm = realm or ""
    user = user or ""
    extra_data = extra_data or {}

    label = tokenlabel.replace("<s>",
                               serial).replace("<u>",
                                               user).replace("<r>", realm)
    url_label = quote(label)

    extra_parameters = _construct_extra_parameters(extra_data)
    url = "oathtoken:///addToken?name={0!s}&lockdown=true&key={1!s}{2!s}{3!s}".format(
                                                                  url_label,
                                                                  otpkey,
                                                                  timebased,
                                                                  extra_parameters
                                                                  )
    return url 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:26,代码来源:apps.py

示例12: _generate_uri

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import quote [as 别名]
def _generate_uri(hotp, type_name, account_name, issuer, extra_parameters):
    parameters = [
        ("digits", hotp._length),
        ("secret", base64.b32encode(hotp._key)),
        ("algorithm", hotp._algorithm.name.upper()),
    ]

    if issuer is not None:
        parameters.append(("issuer", issuer))

    parameters.extend(extra_parameters)

    uriparts = {
        "type": type_name,
        "label": ("%s:%s" % (quote(issuer), quote(account_name)) if issuer
                  else quote(account_name)),
        "parameters": urlencode(parameters),
    }
    return "otpauth://{type}/{label}?{parameters}".format(**uriparts) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:21,代码来源:utils.py

示例13: _parse_auth

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import quote [as 别名]
def _parse_auth(self):
        # type: () -> URI
        if self._auth:
            username, _, password = self._auth.partition(":")
            username_is_quoted, password_is_quoted = False, False
            quoted_username, quoted_password = "", ""
            if password:
                quoted_password = quote(password)
                password_is_quoted = quoted_password != password
            if username:
                quoted_username = quote(username)
                username_is_quoted = quoted_username != username
            return attr.evolve(
                self,
                username=quoted_username,
                password=quoted_password,
                username_is_quoted=username_is_quoted,
                password_is_quoted=password_is_quoted,
            )
        return self 
开发者ID:pypa,项目名称:pipenv,代码行数:22,代码来源:url.py

示例14: get

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import quote [as 别名]
def get(self, stack_id, resource_name, with_attr=None):
        """Get the details for a specific resource.

        :param stack_id: ID of stack containing the resource
        :param resource_name: ID of resource to get the details for
        :param with_attr: Attributes to show
        """
        stack_id = self._resolve_stack_id(stack_id)
        url_str = '/stacks/%s/resources/%s' % (
                  parse.quote(stack_id, ''),
                  parse.quote(encodeutils.safe_encode(resource_name), ''))
        if with_attr:
            params = {'with_attr': with_attr}
            url_str += '?%s' % parse.urlencode(params, True)

        resp = self.client.get(url_str)
        body = utils.get_response_body(resp)
        return Resource(self, body.get('resource')) 
开发者ID:nttcom,项目名称:eclcli,代码行数:20,代码来源:resources.py

示例15: _id_to_header

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import quote [as 别名]
def _id_to_header(self, id_):
    """Convert an id to a Content-ID header value.

    Args:
      id_: string, identifier of individual request.

    Returns:
      A Content-ID header with the id_ encoded into it. A UUID is prepended to
      the value because Content-ID headers are supposed to be universally
      unique.
    """
    if self._base_id is None:
      self._base_id = uuid.uuid4()

    # NB: we intentionally leave whitespace between base/id and '+', so RFC2822
    # line folding works properly on Python 3; see
    # https://github.com/google/google-api-python-client/issues/164
    return '<%s + %s>' % (self._base_id, quote(id_)) 
开发者ID:fniephaus,项目名称:alfred-gmail,代码行数:20,代码来源:http.py


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