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


Python parse.urlencode方法代码示例

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


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

示例1: test_error_view

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlencode [as 别名]
def test_error_view(self):
        client = app.test_client()

        auth_redirect = client.get('/')
        parsed_auth_request = dict(parse_qsl(urlparse(auth_redirect.location).query))

        # fake auth error response sent to redirect_uri
        error_auth_response = {
            'error': 'invalid_request',
            'error_description': 'test error',
            'state': parsed_auth_request['state']
        }
        error_page = client.get('/redirect_uri?{}'.format(urlencode(error_auth_response)), follow_redirects=True)

        assert json.loads(error_page.data.decode('utf-8')) == {
            'error': error_auth_response['error'],
            'message': error_auth_response['error_description']
        } 
开发者ID:zamzterz,项目名称:Flask-pyoidc,代码行数:20,代码来源:test_example_app.py

示例2: _sign_fields

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlencode [as 别名]
def _sign_fields(signable_fields):  # type: (SignableFields) -> str
    """
    Common signing code.
    """
    for (k, v) in signable_fields:
        assert isinstance(k, str), repr(k)
        assert isinstance(v, str), repr(v)

    if sys.version_info < (3,):
        # Python 2 doesn't do IRI encoding.
        text = urlencode([
            (k.encode('utf-8'), v.encode('utf-8'))
            for (k, v) in signable_fields
        ])
    else:
        text = urlencode(signable_fields, encoding='utf-8', errors='strict')

    return md5(text.encode('ascii')).hexdigest()


#: The checkout signature should ignore these leading and trailing whitespace characters.
#:
#: This list is an educated guess based on the PHP trim() function.
#: 
开发者ID:PiDelport,项目名称:django-payfast,代码行数:26,代码来源:api.py

示例3: enurlform

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlencode [as 别名]
def enurlform(q):
    """
    Convert a dictionary to a URL encoded query string.

    Args:
        q(dict): The query to encode.

    Returns:
        str: The urlencoded representation of ``q``.

    Example:
        >>> from pwny import *
        >>> enurlform({'foo': 'bar', 'baz': ['quux', 'corge']})
        'foo=bar&baz=quux&baz=corge'
    """
    return urlencode(q, doseq=True) 
开发者ID:edibledinos,项目名称:pwnypack,代码行数:18,代码来源:codec.py

示例4: get_result_url

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlencode [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

示例5: totpauth_url

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlencode [as 别名]
def totpauth_url(totp_dev):
    # https://github.com/google/google-authenticator/wiki/Key-Uri-Format
    label = totp_dev.user.username.encode('utf8')

    # We need two separate issuers, otherwise deploying in prod will override our authenticator token from
    # dev
    if settings.DEPLOY_MODE == 'production':
        issuer = b'CourSys'
    else:
        issuer = b'CourSys-DEV'

    query = [
        ('secret', base64.b32encode(totp_dev.bin_key)),
        ('digits', totp_dev.digits),
        ('issuer', issuer)
    ]
    return b'otpauth://totp/%s?%s' % (label, urlencode(query).encode('ascii'))


# based on http://stackoverflow.com/a/4631504/1236542 
开发者ID:sfu-fas,项目名称:coursys,代码行数:22,代码来源:models.py

示例6: feed

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlencode [as 别名]
def feed(self, keyword, offset, max_num, language=None, filters=None):
        base_url = 'https://www.google.com/search?'
        self.filter = self.get_filter()
        filter_str = self.filter.apply(filters, sep=',')
        for i in range(offset, offset + max_num, 100):
            params = dict(
                q=keyword,
                ijn=int(i / 100),
                start=i,
                tbs=filter_str,
                tbm='isch')
            if language:
                params['lr'] = 'lang_' + language
            url = base_url + urlencode(params)
            self.out_queue.put(url)
            self.logger.debug('put url to url_queue: {}'.format(url)) 
开发者ID:hellock,项目名称:icrawler,代码行数:18,代码来源:google.py

示例7: list_servers

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlencode [as 别名]
def list_servers(self, detail=False, **params):
        """List servers.

        Available params: see http://developer.openstack.org/
                              api-ref-compute-v2.1.html#listServers
                          and http://developer.openstack.org/
                              api-ref-compute-v2.1.html#listDetailServers
        """

        url = 'servers'
        _schema = schema.list_servers

        if detail:
            url += '/detail'
            _schema = schema.list_servers_detail
        if params:
            url += '?%s' % urllib.urlencode(params)

        resp, body = self.get(url)
        body = json.loads(body)
        self.validate_response(_schema, resp, body)
        return rest_client.ResponseBody(resp, body) 
开发者ID:openstack,项目名称:tempest-lib,代码行数:24,代码来源:servers_client.py

示例8: list_images

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlencode [as 别名]
def list_images(self, detail=False, **params):
        """Return a list of all images filtered by any parameter.

        Available params: see http://developer.openstack.org/
                              api-ref-compute-v2.1.html#listImages
        """
        url = 'images'
        _schema = schema.list_images
        if detail:
            url += '/detail'
            _schema = schema.list_images_details

        if params:
            url += '?%s' % urllib.urlencode(params)

        resp, body = self.get(url)
        body = json.loads(body)
        self.validate_response(_schema, resp, body)
        return rest_client.ResponseBody(resp, body) 
开发者ID:openstack,项目名称:tempest-lib,代码行数:21,代码来源:images_client.py

示例9: prepare_preflight_url

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlencode [as 别名]
def prepare_preflight_url(
            self,
            callback_url,
            hint="hint",
            lti_hint="lti_hint"
    ):
        """
        Generates OIDC url with parameters
        """
        oidc_url = self.oidc_url + "?"
        parameters = {
            "iss": self.iss,
            "client_id": self.client_id,
            "lti_deployment_id": self.deployment_id,
            "target_link_uri": callback_url,
            "login_hint": hint,
            "lti_message_hint": lti_hint
        }

        return {
            "oidc_url": oidc_url + urlencode(parameters),
        } 
开发者ID:edx,项目名称:xblock-lti-consumer,代码行数:24,代码来源:consumer.py

示例10: _get_collection_href

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlencode [as 别名]
def _get_collection_href(cls, request, extra_params=None):
        params = request.GET

        if extra_params is not None:
            params.update(extra_params)

        if cfg.CONF['service:api'].enable_host_header:
            try:
                base_uri = request.host_url
            except Exception:
                base_uri = cls.BASE_URI
        else:
            base_uri = cls.BASE_URI

        href = "%s%s?%s" % (
            base_uri,
            cls._get_path(request),
            parse.urlencode(params))

        return href.rstrip('?') 
开发者ID:openstack,项目名称:designate,代码行数:22,代码来源:base.py

示例11: _construct_url

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlencode [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

示例12: _search_users

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlencode [as 别名]
def _search_users(resource_server, access_token, params=None):
        """
        :param params: Additional http parameters added to the URL
        :type params: dictionary
        """
        params = params or {}
        headers = {'Authorization': "Bearer {0}".format(access_token),
                   'content-type': 'application/json'}
        url = '{0}/Users?{1}'.format(resource_server, urlencode(params))
        resp = requests.get(url, headers=headers)
        if resp.status_code != 200:
            info = "Could not get user list: {0!s}".format(resp.status_code)
            log.error(info)
            raise Exception(info)
        j_content = yaml.safe_load(resp.content)

        return j_content 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:19,代码来源:SCIMIdResolver.py

示例13: test_10_set_token_realms

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlencode [as 别名]
def test_10_set_token_realms(self):
        self._create_temp_token("REALM001")

        with self.app.test_request_context('/token/realm/REALM001',
                                            method="POST",
                                            data={"realms": "realm1, realm2"},
                                            headers={'Authorization': self.at}):
            res = self.app.full_dispatch_request()
            self.assertTrue(res.status_code == 200, res)
            result = res.json.get("result")
            value = result.get("value")
            self.assertTrue(value is True, result)

        with self.app.test_request_context('/token/',
                                            method="GET",
                                            query_string=urlencode({"serial": "REALM001"}),
                                            headers={'Authorization': self.at}):
            res = self.app.full_dispatch_request()
            self.assertTrue(res.status_code == 200, res)
            result = res.json.get("result")
            value = result.get("value")
            token = value.get("tokens")[0]
            self.assertTrue(token.get("realms") == ["realm1"], token) 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:25,代码来源:test_api_token.py

示例14: _generate_uri

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlencode [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

示例15: change_url

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlencode [as 别名]
def change_url(request, kwargs=None, query=None):
    kwargs = kwargs or {}
    query = query or {}
    rm = request.resolver_match
    _kwargs = rm.kwargs.copy()
    _kwargs.update(kwargs)
    if _kwargs.get("page") == 1:
        _kwargs.pop('page', None)
    qs = parse_qs(urlparse(request.get_full_path()).query)
    qs.update(query)
    path = reverse(
        '%s:%s' % (rm.namespace, rm.url_name),
        args=rm.args,
        kwargs=_kwargs,
    )
    if (qs):
        return "%s?%s" % (path, urlencode(qs, True))
    else:
        return path 
开发者ID:ericls,项目名称:niji,代码行数:21,代码来源:niji_tags.py


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