本文整理匯總了Python中django.utils.encoding.uri_to_iri方法的典型用法代碼示例。如果您正苦於以下問題:Python encoding.uri_to_iri方法的具體用法?Python encoding.uri_to_iri怎麽用?Python encoding.uri_to_iri使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.utils.encoding
的用法示例。
在下文中一共展示了encoding.uri_to_iri方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_environ
# 需要導入模塊: from django.utils import encoding [as 別名]
# 或者: from django.utils.encoding import uri_to_iri [as 別名]
def get_environ(self):
# Strip all headers with underscores in the name before constructing
# the WSGI environ. This prevents header-spoofing based on ambiguity
# between underscores and dashes both normalized to underscores in WSGI
# env vars. Nginx and Apache 2.4+ both do this as well.
for k, v in self.headers.items():
if '_' in k:
del self.headers[k]
env = super(WSGIRequestHandler, self).get_environ()
path = self.path
if '?' in path:
path = path.partition('?')[0]
path = uri_to_iri(path).encode(UTF_8)
# Under Python 3, non-ASCII values in the WSGI environ are arbitrarily
# decoded with ISO-8859-1. We replicate this behavior here.
# Refs comment in `get_bytes_from_wsgi()`.
env['PATH_INFO'] = path.decode(ISO_8859_1) if six.PY3 else path
return env
示例2: absolute_resolve
# 需要導入模塊: from django.utils import encoding [as 別名]
# 或者: from django.utils.encoding import uri_to_iri [as 別名]
def absolute_resolve(url):
"""
An extension of Django's `resolve()` that handles absolute URLs *or*
relative paths.
Mostly copied from rest_framework.serializers.HyperlinkedRelatedField.
"""
try:
http_prefix = url.startswith(('http:', 'https:'))
except AttributeError:
# `url` is not a string?!
raise TypeError
if http_prefix:
path = urlparse(url).path
prefix = get_script_prefix()
if path.startswith(prefix):
path = '/' + path[len(prefix):]
else:
path = url
path = uri_to_iri(path)
return resolve(path)
示例3: _get_path
# 需要導入模塊: from django.utils import encoding [as 別名]
# 或者: from django.utils.encoding import uri_to_iri [as 別名]
def _get_path(self, parsed):
path = force_str(parsed[2])
# If there are parameters, add them
if parsed[3]:
path += str(";") + force_str(parsed[3])
path = uri_to_iri(path).encode(UTF_8)
# Under Python 3, non-ASCII values in the WSGI environ are arbitrarily
# decoded with ISO-8859-1. We replicate this behavior here.
# Refs comment in `get_bytes_from_wsgi()`.
return path.decode(ISO_8859_1) if six.PY3 else path
示例4: get
# 需要導入模塊: from django.utils import encoding [as 別名]
# 或者: from django.utils.encoding import uri_to_iri [as 別名]
def get(self, request, *args, **kwargs):
def unwhitespace(val):
return " ".join(val.split())
if 'ps_q' in request.GET:
# Keeping Unicode in URL, replacing space with '+'.
query = uri_to_iri(urlquote_plus(unwhitespace(request.GET['ps_q'])))
params = {'query': query} if query else None
return HttpResponseRedirect(reverse_lazy('search', kwargs=params))
query = kwargs['query'] or '' # Avoiding query=None
self.query = unwhitespace(unquote_plus(query))
# Exclude places whose owner blocked unauthenticated viewing.
if not request.user.is_authenticated:
self.queryset = self.queryset.exclude(owner__pref__public_listing=False)
return super().get(request, *args, **kwargs)
示例5: get_redirect
# 需要導入模塊: from django.utils import encoding [as 別名]
# 或者: from django.utils.encoding import uri_to_iri [as 別名]
def get_redirect(request, path):
redirect = _get_redirect(request, path)
if not redirect:
# try unencoding the path
redirect = _get_redirect(request, uri_to_iri(path))
return redirect
# Originally pinched from: https://github.com/django/django/blob/master/django/contrib/redirects/middleware.py
示例6: directory_list
# 需要導入模塊: from django.utils import encoding [as 別名]
# 或者: from django.utils.encoding import uri_to_iri [as 別名]
def directory_list(request, directory_slug, category_parent_slug):
if directory_slug:
directory_slug = uri_to_iri(directory_slug)
if directory_slug is None:
object = None
root = getattr(settings, 'MEDIA_GALLERIES_ROOT', None)
if root:
obj_root = Folder.objects.get(name=root)
object_list = Folder.objects.filter(parent=obj_root)
else:
object_list = Folder.objects.filter(parent=None)
else:
try:
object = Folder.objects.get(id=directory_slug)
except:
object = Folder.objects.get(name=directory_slug)
object_list = object.files.all()
return render(
request,
'media/directory_list.html',
{
'object_list': object_list,
}
)