mirror of
https://github.com/django/django.git
synced 2025-10-24 09:06:12 +00:00
[py3] Ported django.utils.encoding.
* Renamed smart_unicode to smart_text (but kept the old name under Python 2 for backwards compatibility). * Renamed smart_str to smart_bytes. * Re-introduced smart_str as an alias for smart_text under Python 3 and smart_bytes under Python 2 (which is backwards compatible). Thus smart_str always returns a str objects. * Used the new smart_str in a few places where both Python 2 and 3 want a str.
This commit is contained in:
parent
ee191715ea
commit
c5ef65bcf3
125 changed files with 629 additions and 583 deletions
|
|
@ -16,7 +16,7 @@ from django.core.exceptions import ImproperlyConfigured
|
|||
from django.core.files.base import ContentFile
|
||||
from django.core.files.storage import FileSystemStorage, get_storage_class
|
||||
from django.utils.datastructures import SortedDict
|
||||
from django.utils.encoding import force_unicode, smart_str
|
||||
from django.utils.encoding import force_text, smart_bytes
|
||||
from django.utils.functional import LazyObject
|
||||
from django.utils.importlib import import_module
|
||||
|
||||
|
|
@ -112,7 +112,7 @@ class CachedFilesMixin(object):
|
|||
return urlunsplit(unparsed_name)
|
||||
|
||||
def cache_key(self, name):
|
||||
return 'staticfiles:%s' % hashlib.md5(smart_str(name)).hexdigest()
|
||||
return 'staticfiles:%s' % hashlib.md5(smart_bytes(name)).hexdigest()
|
||||
|
||||
def url(self, name, force=False):
|
||||
"""
|
||||
|
|
@ -248,9 +248,9 @@ class CachedFilesMixin(object):
|
|||
if hashed_file_exists:
|
||||
self.delete(hashed_name)
|
||||
# then save the processed result
|
||||
content_file = ContentFile(smart_str(content))
|
||||
content_file = ContentFile(smart_bytes(content))
|
||||
saved_name = self._save(hashed_name, content_file)
|
||||
hashed_name = force_unicode(saved_name.replace('\\', '/'))
|
||||
hashed_name = force_text(saved_name.replace('\\', '/'))
|
||||
processed = True
|
||||
else:
|
||||
# or handle the case in which neither processing nor
|
||||
|
|
@ -258,7 +258,7 @@ class CachedFilesMixin(object):
|
|||
if not hashed_file_exists:
|
||||
processed = True
|
||||
saved_name = self._save(hashed_name, original_file)
|
||||
hashed_name = force_unicode(saved_name.replace('\\', '/'))
|
||||
hashed_name = force_text(saved_name.replace('\\', '/'))
|
||||
|
||||
# and then set the cache accordingly
|
||||
hashed_paths[self.cache_key(name)] = hashed_name
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue