mirror of https://github.com/django/django.git
Simplified contrib.admin.utils.quote().
This commit is contained in:
parent
92ccc39170
commit
e9defb3f6e
|
@ -13,6 +13,8 @@ from django.utils.html import format_html
|
||||||
from django.utils.text import capfirst
|
from django.utils.text import capfirst
|
||||||
from django.utils.translation import ngettext, override as translation_override
|
from django.utils.translation import ngettext, override as translation_override
|
||||||
|
|
||||||
|
QUOTE_MAP = {i: '_%02X' % i for i in b'":/_#?;@&=+$,"[]<>%\n\\'}
|
||||||
|
|
||||||
|
|
||||||
class FieldIsAForeignKeyColumnName(Exception):
|
class FieldIsAForeignKeyColumnName(Exception):
|
||||||
"""A field is a foreign key attname, i.e. <FK>_id."""
|
"""A field is a foreign key attname, i.e. <FK>_id."""
|
||||||
|
@ -64,14 +66,7 @@ def quote(s):
|
||||||
Similar to urllib.parse.quote(), except that the quoting is slightly
|
Similar to urllib.parse.quote(), except that the quoting is slightly
|
||||||
different so that it doesn't get automatically unquoted by the Web browser.
|
different so that it doesn't get automatically unquoted by the Web browser.
|
||||||
"""
|
"""
|
||||||
if not isinstance(s, str):
|
return s.translate(QUOTE_MAP) if isinstance(s, str) else s
|
||||||
return s
|
|
||||||
res = list(s)
|
|
||||||
for i in range(len(res)):
|
|
||||||
c = res[i]
|
|
||||||
if c in """:/_#?;@&=+$,"[]<>%\n\\""":
|
|
||||||
res[i] = '_%02X' % ord(c)
|
|
||||||
return ''.join(res)
|
|
||||||
|
|
||||||
|
|
||||||
def unquote(s):
|
def unquote(s):
|
||||||
|
|
Loading…
Reference in New Issue