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
85359ec9
Kaydet (Commit)
85359ec9
authored
Eyl 06, 2013
tarafından
Florian Apolloner
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Merge branch 't20812'
üst
cc957cb1
2326dedd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
10 deletions
+24
-10
encoding.py
django/utils/encoding.py
+8
-9
test_encoding.py
tests/utils_tests/test_encoding.py
+16
-1
No files found.
django/utils/encoding.py
Dosyayı görüntüle @
85359ec9
...
...
@@ -67,16 +67,15 @@ def force_text(s, encoding='utf-8', strings_only=False, errors='strict'):
return
s
try
:
if
not
isinstance
(
s
,
six
.
string_types
):
if
hasattr
(
s
,
'__unicode__'
):
s
=
s
.
__unicode__
()
else
:
if
six
.
PY3
:
if
isinstance
(
s
,
bytes
):
s
=
six
.
text_type
(
s
,
encoding
,
errors
)
else
:
s
=
six
.
text_type
(
s
)
if
six
.
PY3
:
if
isinstance
(
s
,
bytes
):
s
=
six
.
text_type
(
s
,
encoding
,
errors
)
else
:
s
=
six
.
text_type
(
bytes
(
s
),
encoding
,
errors
)
s
=
six
.
text_type
(
s
)
elif
hasattr
(
s
,
'__unicode__'
):
s
=
six
.
text_type
(
s
)
else
:
s
=
six
.
text_type
(
bytes
(
s
),
encoding
,
errors
)
else
:
# Note: We use .decode() here, instead of six.text_type(s, encoding,
# errors), so that if s is a SafeBytes, it ends up being a
...
...
tests/utils_tests/test_encoding.py
Dosyayı görüntüle @
85359ec9
...
...
@@ -4,10 +4,25 @@ from __future__ import unicode_literals
import
unittest
import
datetime
from
django.utils.encoding
import
force_bytes
,
filepath_to_uri
from
django.utils
import
six
from
django.utils.encoding
import
force_bytes
,
force_text
,
filepath_to_uri
class
TestEncodingUtils
(
unittest
.
TestCase
):
def
test_force_text_exception
(
self
):
"""
Check that broken __unicode__/__str__ actually raises an error.
"""
class
MyString
(
object
):
def
__str__
(
self
):
return
b
'
\xc3\xb6\xc3\xa4\xc3\xbc
'
__unicode__
=
__str__
# str(s) raises a TypeError on python 3 if the result is not a text type.
# python 2 fails when it tries converting from str to unicode (via ASCII).
exception
=
TypeError
if
six
.
PY3
else
UnicodeError
self
.
assertRaises
(
exception
,
force_text
,
MyString
())
def
test_force_bytes_exception
(
self
):
"""
...
...
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