mirror of https://github.com/django/django.git
Simplified contrib.admin.utils.unquote().
This commit is contained in:
parent
bf8b625a3b
commit
e4df8e6dc0
|
@ -1,5 +1,6 @@
|
||||||
import datetime
|
import datetime
|
||||||
import decimal
|
import decimal
|
||||||
|
import re
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
from django.core.exceptions import FieldDoesNotExist
|
from django.core.exceptions import FieldDoesNotExist
|
||||||
|
@ -14,6 +15,8 @@ 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\\'}
|
QUOTE_MAP = {i: '_%02X' % i for i in b'":/_#?;@&=+$,"[]<>%\n\\'}
|
||||||
|
UNQUOTE_MAP = {v: chr(k) for k, v in QUOTE_MAP.items()}
|
||||||
|
UNQUOTE_RE = re.compile('_(?:%s)' % '|'.join([x[1:] for x in UNQUOTE_MAP]))
|
||||||
|
|
||||||
|
|
||||||
class FieldIsAForeignKeyColumnName(Exception):
|
class FieldIsAForeignKeyColumnName(Exception):
|
||||||
|
@ -70,22 +73,8 @@ def quote(s):
|
||||||
|
|
||||||
|
|
||||||
def unquote(s):
|
def unquote(s):
|
||||||
"""Undo the effects of quote(). Based heavily on urllib.parse.unquote()."""
|
"""Undo the effects of quote()."""
|
||||||
mychr = chr
|
return UNQUOTE_RE.sub(lambda m: UNQUOTE_MAP[m.group(0)], s)
|
||||||
myatoi = int
|
|
||||||
list = s.split('_')
|
|
||||||
res = [list[0]]
|
|
||||||
myappend = res.append
|
|
||||||
del list[0]
|
|
||||||
for item in list:
|
|
||||||
if item[1:2]:
|
|
||||||
try:
|
|
||||||
myappend(mychr(myatoi(item[:2], 16)) + item[2:])
|
|
||||||
except ValueError:
|
|
||||||
myappend('_' + item)
|
|
||||||
else:
|
|
||||||
myappend('_' + item)
|
|
||||||
return "".join(res)
|
|
||||||
|
|
||||||
|
|
||||||
def flatten(fields):
|
def flatten(fields):
|
||||||
|
|
Loading…
Reference in New Issue