Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
a0a0203a
Kaydet (Commit)
a0a0203a
authored
Agu 11, 2012
tarafından
Aymeric Augustin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
[py3] Added python_2_unicode_compatible decorator.
üst
e7e08fd4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
0 deletions
+21
-0
encoding.py
django/utils/encoding.py
+13
-0
utils.txt
docs/ref/utils.txt
+8
-0
No files found.
django/utils/encoding.py
Dosyayı görüntüle @
a0a0203a
...
...
@@ -39,6 +39,19 @@ class StrAndUnicode(object):
def
__str__
(
self
):
return
self
.
__unicode__
()
.
encode
(
'utf-8'
)
def
python_2_unicode_compatible
(
klass
):
"""
A decorator that defines __unicode__ and __str__ methods under Python 2.
Under Python 3 it does nothing.
To support Python 2 and 3 with a single code base, define a __str__ method
returning text and apply this decorator to the class.
"""
if
not
six
.
PY3
:
klass
.
__unicode__
=
klass
.
__str__
klass
.
__str__
=
lambda
self
:
self
.
__unicode__
()
.
encode
(
'utf-8'
)
return
klass
def
smart_text
(
s
,
encoding
=
'utf-8'
,
strings_only
=
False
,
errors
=
'strict'
):
"""
Returns a text object representing 's' -- unicode on Python 2 and str on
...
...
docs/ref/utils.txt
Dosyayı görüntüle @
a0a0203a
...
...
@@ -187,6 +187,14 @@ The functions defined in this module share the following properties:
Useful as a mix-in. If you support Python 2 and 3 with a single code base,
you can inherit this mix-in and just define ``__unicode__``.
.. function:: python_2_unicode_compatible
A decorator that defines ``__unicode__`` and ``__str__`` methods under
Python 2. Under Python 3 it does nothing.
To support Python 2 and 3 with a single code base, define a ``__str__``
method returning text and apply this decorator to the class.
.. function:: smart_text(s, encoding='utf-8', strings_only=False, errors='strict')
.. versionadded:: 1.5
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment