本文整理匯總了Python中django.utils.six.moves.urllib.parse.urlencode方法的典型用法代碼示例。如果您正苦於以下問題:Python parse.urlencode方法的具體用法?Python parse.urlencode怎麽用?Python parse.urlencode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.utils.six.moves.urllib.parse
的用法示例。
在下文中一共展示了parse.urlencode方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: ping_google
# 需要導入模塊: from django.utils.six.moves.urllib import parse [as 別名]
# 或者: from django.utils.six.moves.urllib.parse import urlencode [as 別名]
def ping_google(sitemap_url=None, ping_url=PING_URL):
"""
Alerts Google that the sitemap for the current site has been updated.
If sitemap_url is provided, it should be an absolute path to the sitemap
for this site -- e.g., '/sitemap.xml'. If sitemap_url is not provided, this
function will attempt to deduce it by using urlresolvers.reverse().
"""
if sitemap_url is None:
try:
# First, try to get the "index" sitemap URL.
sitemap_url = urlresolvers.reverse('django.contrib.sitemaps.views.index')
except urlresolvers.NoReverseMatch:
try:
# Next, try for the "global" sitemap URL.
sitemap_url = urlresolvers.reverse('django.contrib.sitemaps.views.sitemap')
except urlresolvers.NoReverseMatch:
pass
if sitemap_url is None:
raise SitemapNotFound("You didn't provide a sitemap_url, and the sitemap URL couldn't be auto-detected.")
if not django_apps.is_installed('django.contrib.sites'):
raise ImproperlyConfigured("ping_google requires django.contrib.sites, which isn't installed.")
Site = django_apps.get_model('sites.Site')
current_site = Site.objects.get_current()
url = "http://%s%s" % (current_site.domain, sitemap_url)
params = urlencode({'sitemap': url})
urlopen("%s?%s" % (ping_url, params))
示例2: _created_proxy_response
# 需要導入模塊: from django.utils.six.moves.urllib import parse [as 別名]
# 或者: from django.utils.six.moves.urllib.parse import urlencode [as 別名]
def _created_proxy_response(self, request, path):
request_payload = request.body
self.log.debug("Request headers: %s", self.request_headers)
path = quote_plus(path.encode('utf8'), QUOTE_SAFE)
request_url = (self.upstream + '/' if path and self.upstream[-1] != '/' else self.upstream) + path
self.log.debug("Request URL: %s", request_url)
if request.GET:
get_data = encode_items(request.GET.lists())
request_url += '?' + urlencode(get_data)
self.log.debug("Request URL: %s", request_url)
try:
proxy_response = self.http.urlopen(
request.method,
request_url,
redirect=False,
retries=self.retries,
headers=self.request_headers,
body=request_payload,
decode_content=False,
preload_content=False
)
self.log.debug("Proxy response header: %s", proxy_response.getheaders())
except urllib3.exceptions.HTTPError as error:
self.log.exception(error)
raise
return proxy_response
示例3: ping_google
# 需要導入模塊: from django.utils.six.moves.urllib import parse [as 別名]
# 或者: from django.utils.six.moves.urllib.parse import urlencode [as 別名]
def ping_google(sitemap_url=None, ping_url=PING_URL):
"""
Alerts Google that the sitemap for the current site has been updated.
If sitemap_url is provided, it should be an absolute path to the sitemap
for this site -- e.g., '/sitemap.xml'. If sitemap_url is not provided, this
function will attempt to deduce it by using urls.reverse().
"""
sitemap_full_url = _get_sitemap_full_url(sitemap_url)
params = urlencode({'sitemap': sitemap_full_url})
urlopen('%s?%s' % (ping_url, params))
示例4: replace_query_param
# 需要導入模塊: from django.utils.six.moves.urllib import parse [as 別名]
# 或者: from django.utils.six.moves.urllib.parse import urlencode [as 別名]
def replace_query_param(url, key, val):
"""
Given a URL and a key/val pair, set or replace an item in the query
parameters of the URL, and return the new URL.
"""
(scheme, netloc, path, query, fragment) = urlparse.urlsplit(force_str(url))
query_dict = urlparse.parse_qs(query, keep_blank_values=True)
query_dict[force_str(key)] = [force_str(val)]
query = urlparse.urlencode(sorted(list(query_dict.items())), doseq=True)
return urlparse.urlunsplit((scheme, netloc, path, query, fragment))
示例5: remove_query_param
# 需要導入模塊: from django.utils.six.moves.urllib import parse [as 別名]
# 或者: from django.utils.six.moves.urllib.parse import urlencode [as 別名]
def remove_query_param(url, key):
"""
Given a URL and a key/val pair, remove an item in the query
parameters of the URL, and return the new URL.
"""
(scheme, netloc, path, query, fragment) = urlparse.urlsplit(force_str(url))
query_dict = urlparse.parse_qs(query, keep_blank_values=True)
query_dict.pop(key, None)
query = urlparse.urlencode(sorted(list(query_dict.items())), doseq=True)
return urlparse.urlunsplit((scheme, netloc, path, query, fragment))
示例6: encode_cursor
# 需要導入模塊: from django.utils.six.moves.urllib import parse [as 別名]
# 或者: from django.utils.six.moves.urllib.parse import urlencode [as 別名]
def encode_cursor(self, cursor):
"""
Given a Cursor instance, return an url with encoded cursor.
"""
tokens = {}
if cursor.offset != 0:
tokens['o'] = str(cursor.offset)
if cursor.reverse:
tokens['r'] = '1'
if cursor.position is not None:
tokens['p'] = cursor.position
querystring = urlparse.urlencode(tokens, doseq=True)
encoded = b64encode(querystring.encode('ascii')).decode('ascii')
return replace_query_param(self.base_url, self.cursor_query_param, encoded)
示例7: replace_query_param
# 需要導入模塊: from django.utils.six.moves.urllib import parse [as 別名]
# 或者: from django.utils.six.moves.urllib.parse import urlencode [as 別名]
def replace_query_param(url, key, val):
"""
Given a URL and a key/val pair, set or replace an item in the query
parameters of the URL, and return the new URL.
"""
(scheme, netloc, path, query, fragment) = urlparse.urlsplit(url)
query_dict = urlparse.parse_qs(query)
query_dict[key] = [val]
query = urlparse.urlencode(sorted(list(query_dict.items())), doseq=True)
return urlparse.urlunsplit((scheme, netloc, path, query, fragment))
示例8: remove_query_param
# 需要導入模塊: from django.utils.six.moves.urllib import parse [as 別名]
# 或者: from django.utils.six.moves.urllib.parse import urlencode [as 別名]
def remove_query_param(url, key):
"""
Given a URL and a key/val pair, remove an item in the query
parameters of the URL, and return the new URL.
"""
(scheme, netloc, path, query, fragment) = urlparse.urlsplit(url)
query_dict = urlparse.parse_qs(query)
query_dict.pop(key, None)
query = urlparse.urlencode(sorted(list(query_dict.items())), doseq=True)
return urlparse.urlunsplit((scheme, netloc, path, query, fragment))