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
d55e8829
Kaydet (Commit)
d55e8829
authored
Şub 05, 2019
tarafından
Tim Graham
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #27753 -- Deprecated django.utils.encoding.force_text() and smart_text().
üst
3bb6a439
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
2 deletions
+54
-2
encoding.py
django/utils/encoding.py
+16
-2
deprecation.txt
docs/internals/deprecation.txt
+2
-0
utils.txt
docs/ref/utils.txt
+4
-0
3.0.txt
docs/releases/3.0.txt
+8
-0
test_encoding_deprecations.py
tests/utils_tests/test_encoding_deprecations.py
+24
-0
No files found.
django/utils/encoding.py
Dosyayı görüntüle @
d55e8829
import
codecs
import
codecs
import
datetime
import
datetime
import
locale
import
locale
import
warnings
from
decimal
import
Decimal
from
decimal
import
Decimal
from
urllib.parse
import
quote
from
urllib.parse
import
quote
from
django.utils.deprecation
import
RemovedInDjango40Warning
from
django.utils.functional
import
Promise
from
django.utils.functional
import
Promise
...
@@ -97,8 +99,20 @@ def force_bytes(s, encoding='utf-8', strings_only=False, errors='strict'):
...
@@ -97,8 +99,20 @@ def force_bytes(s, encoding='utf-8', strings_only=False, errors='strict'):
return
str
(
s
)
.
encode
(
encoding
,
errors
)
return
str
(
s
)
.
encode
(
encoding
,
errors
)
smart_text
=
smart_str
def
smart_text
(
s
,
encoding
=
'utf-8'
,
strings_only
=
False
,
errors
=
'strict'
):
force_text
=
force_str
warnings
.
warn
(
'smart_text() is deprecated in favor of smart_str().'
,
RemovedInDjango40Warning
,
stacklevel
=
2
,
)
return
smart_str
(
s
,
encoding
,
strings_only
,
errors
)
def
force_text
(
s
,
encoding
=
'utf-8'
,
strings_only
=
False
,
errors
=
'strict'
):
warnings
.
warn
(
'force_text() is deprecated in favor of force_str().'
,
RemovedInDjango40Warning
,
stacklevel
=
2
,
)
return
force_str
(
s
,
encoding
,
strings_only
,
errors
)
def
iri_to_uri
(
iri
):
def
iri_to_uri
(
iri
):
...
...
docs/internals/deprecation.txt
Dosyayı görüntüle @
d55e8829
...
@@ -18,6 +18,8 @@ details on these changes.
...
@@ -18,6 +18,8 @@ details on these changes.
* ``django.utils.http.urlquote()``, ``urlquote_plus()``, ``urlunquote()``, and
* ``django.utils.http.urlquote()``, ``urlquote_plus()``, ``urlunquote()``, and
``urlunquote_plus()`` will be removed.
``urlunquote_plus()`` will be removed.
* ``django.utils.encoding.force_text()`` and ``smart_text()`` will be removed.
.. _deprecation-removed-in-3.1:
.. _deprecation-removed-in-3.1:
3.1
3.1
...
...
docs/ref/utils.txt
Dosyayı görüntüle @
d55e8829
...
@@ -232,11 +232,15 @@ The functions defined in this module share the following properties:
...
@@ -232,11 +232,15 @@ The functions defined in this module share the following properties:
.. function:: smart_text(s, encoding='utf-8', strings_only=False, errors='strict')
.. function:: smart_text(s, encoding='utf-8', strings_only=False, errors='strict')
.. deprecated:: 3.0
Alias of :func:`force_str` for backwards compatibility, especially in code
Alias of :func:`force_str` for backwards compatibility, especially in code
that supports Python 2.
that supports Python 2.
.. function:: force_text(s, encoding='utf-8', strings_only=False, errors='strict')
.. function:: force_text(s, encoding='utf-8', strings_only=False, errors='strict')
.. deprecated:: 3.0
Alias of :func:`force_str` for backwards compatibility, especially in code
Alias of :func:`force_str` for backwards compatibility, especially in code
that supports Python 2.
that supports Python 2.
...
...
docs/releases/3.0.txt
Dosyayı görüntüle @
d55e8829
...
@@ -292,6 +292,14 @@ Miscellaneous
...
@@ -292,6 +292,14 @@ Miscellaneous
Features deprecated in 3.0
Features deprecated in 3.0
==========================
==========================
``django.utils.encoding.force_text()`` and ``smart_text()``
-----------------------------------------------------------
The ``smart_text()`` and ``force_text()`` aliases (since Django 2.0) of
``smart_str()`` and ``force_str()`` are deprecated. Ignore this deprecation if
your code supports Python 2 as the behavior of ``smart_str()`` and
``force_str()`` is different there.
Miscellaneous
Miscellaneous
-------------
-------------
...
...
tests/utils_tests/test_encoding_deprecations.py
0 → 100644
Dosyayı görüntüle @
d55e8829
from
django.test
import
SimpleTestCase
,
ignore_warnings
from
django.utils.deprecation
import
RemovedInDjango40Warning
from
django.utils.encoding
import
force_text
,
smart_text
from
django.utils.functional
import
SimpleLazyObject
from
django.utils.translation
import
gettext_lazy
@ignore_warnings
(
category
=
RemovedInDjango40Warning
)
class
TestDeprecatedEncodingUtils
(
SimpleTestCase
):
def
test_force_text
(
self
):
s
=
SimpleLazyObject
(
lambda
:
'x'
)
self
.
assertIs
(
type
(
force_text
(
s
)),
str
)
def
test_smart_text
(
self
):
class
Test
:
def
__str__
(
self
):
return
'ŠĐĆŽćžšđ'
lazy_func
=
gettext_lazy
(
'x'
)
self
.
assertIs
(
smart_text
(
lazy_func
),
lazy_func
)
self
.
assertEqual
(
smart_text
(
Test
()),
'
\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111
'
)
self
.
assertEqual
(
smart_text
(
1
),
'1'
)
self
.
assertEqual
(
smart_text
(
'foo'
),
'foo'
)
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