本文整理汇总了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,
}
)