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
77d25dbd
Kaydet (Commit)
77d25dbd
authored
Şub 05, 2019
tarafından
Tim Graham
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #27753 -- Favored SafeString over SafeText.
üst
d55e8829
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
25 additions
and
31 deletions
+25
-31
base.py
django/db/backends/postgresql/base.py
+2
-2
utils.py
django/template/backends/utils.py
+2
-2
html.py
django/utils/html.py
+4
-4
safestring.py
django/utils/safestring.py
+4
-4
custom-template-tags.txt
docs/howto/custom-template-tags.txt
+3
-3
utils.txt
docs/ref/utils.txt
+3
-9
tests.py
tests/i18n/tests.py
+6
-6
test_safestring.py
tests/utils_tests/test_safestring.py
+1
-1
No files found.
django/db/backends/postgresql/base.py
Dosyayı görüntüle @
77d25dbd
...
...
@@ -13,7 +13,7 @@ from django.db import connections
from
django.db.backends.base.base
import
BaseDatabaseWrapper
from
django.db.utils
import
DatabaseError
as
WrappedDatabaseError
from
django.utils.functional
import
cached_property
from
django.utils.safestring
import
Safe
Text
from
django.utils.safestring
import
Safe
String
from
django.utils.version
import
get_version_tuple
try
:
...
...
@@ -44,7 +44,7 @@ from .operations import DatabaseOperations # NOQA isort:skip
from
.schema
import
DatabaseSchemaEditor
# NOQA isort:skip
from
.utils
import
utc_tzinfo_factory
# NOQA isort:skip
psycopg2
.
extensions
.
register_adapter
(
Safe
Text
,
psycopg2
.
extensions
.
QuotedString
)
psycopg2
.
extensions
.
register_adapter
(
Safe
String
,
psycopg2
.
extensions
.
QuotedString
)
psycopg2
.
extras
.
register_uuid
()
# Register support for inet[] manually so we don't have to handle the Inet()
...
...
django/template/backends/utils.py
Dosyayı görüntüle @
77d25dbd
from
django.middleware.csrf
import
get_token
from
django.utils.functional
import
lazy
from
django.utils.html
import
format_html
from
django.utils.safestring
import
Safe
Text
from
django.utils.safestring
import
Safe
String
def
csrf_input
(
request
):
...
...
@@ -10,5 +10,5 @@ def csrf_input(request):
get_token
(
request
))
csrf_input_lazy
=
lazy
(
csrf_input
,
Safe
Text
,
str
)
csrf_input_lazy
=
lazy
(
csrf_input
,
Safe
String
,
str
)
csrf_token_lazy
=
lazy
(
get_token
,
str
)
django/utils/html.py
Dosyayı görüntüle @
77d25dbd
...
...
@@ -9,7 +9,7 @@ from urllib.parse import (
from
django.utils.functional
import
Promise
,
keep_lazy
,
keep_lazy_text
from
django.utils.http
import
RFC3986_GENDELIMS
,
RFC3986_SUBDELIMS
from
django.utils.safestring
import
SafeData
,
Safe
Text
,
mark_safe
from
django.utils.safestring
import
SafeData
,
Safe
String
,
mark_safe
from
django.utils.text
import
normalize_newlines
# Configuration for urlize() function.
...
...
@@ -33,7 +33,7 @@ _html_escapes = {
}
@keep_lazy
(
str
,
Safe
Text
)
@keep_lazy
(
str
,
Safe
String
)
def
escape
(
text
):
"""
Return the given text with ampersands, quotes and angle brackets encoded
...
...
@@ -65,7 +65,7 @@ _js_escapes = {
_js_escapes
.
update
((
ord
(
'
%
c'
%
z
),
'
\\
u
%04
X'
%
z
)
for
z
in
range
(
32
))
@keep_lazy
(
str
,
Safe
Text
)
@keep_lazy
(
str
,
Safe
String
)
def
escapejs
(
value
):
"""Hex encode characters for use in JavaScript strings."""
return
mark_safe
(
str
(
value
)
.
translate
(
_js_escapes
))
...
...
@@ -372,7 +372,7 @@ def avoid_wrapping(value):
def
html_safe
(
klass
):
"""
A decorator that defines the __html__ method. This helps non-Django
templates to detect classes whose __str__ methods return Safe
Text
.
templates to detect classes whose __str__ methods return Safe
String
.
"""
if
'__html__'
in
klass
.
__dict__
:
raise
ValueError
(
...
...
django/utils/safestring.py
Dosyayı görüntüle @
77d25dbd
...
...
@@ -18,7 +18,7 @@ class SafeData:
return
self
class
Safe
Text
(
str
,
SafeData
):
class
Safe
String
(
str
,
SafeData
):
"""
A str subclass that has been specifically marked as "safe" for HTML output
purposes.
...
...
@@ -30,14 +30,14 @@ class SafeText(str, SafeData):
"""
t
=
super
()
.
__add__
(
rhs
)
if
isinstance
(
rhs
,
SafeData
):
return
Safe
Text
(
t
)
return
Safe
String
(
t
)
return
t
def
__str__
(
self
):
return
self
Safe
String
=
SafeText
Safe
Text
=
SafeString
# For backwards compatibility since Django 2.0.
def
_safety_decorator
(
safety_marker
,
func
):
...
...
@@ -60,4 +60,4 @@ def mark_safe(s):
return
s
if
callable
(
s
):
return
_safety_decorator
(
mark_safe
,
s
)
return
Safe
Text
(
s
)
return
Safe
String
(
s
)
docs/howto/custom-template-tags.txt
Dosyayı görüntüle @
77d25dbd
...
...
@@ -200,12 +200,12 @@ passed around inside the template code:
to be interpreted as-is on the client side.
Internally, these strings are of type
:class:`~django.utils.safestring.Safe
Text
`. You can test for them
:class:`~django.utils.safestring.Safe
String
`. You can test for them
using code like::
from django.utils.safestring import Safe
Text
from django.utils.safestring import Safe
String
if isinstance(value, Safe
Text
):
if isinstance(value, Safe
String
):
# Do something with the "safe" string.
...
...
...
docs/ref/utils.txt
Dosyayı görüntüle @
77d25dbd
...
...
@@ -748,14 +748,8 @@ appropriate entities.
.. class:: SafeString
A ``str`` subclass that has been specifically marked as "safe"
(requires no further escaping) for HTML output purposes. Alias of
:class:`SafeText`.
.. class:: SafeText
A ``str`` subclass that has been specifically marked as "safe" for HTML
output purposes.
A ``str`` subclass that has been specifically marked as "safe" (requires no
further escaping) for HTML output purposes.
.. function:: mark_safe(s)
...
...
@@ -774,7 +768,7 @@ appropriate entities.
>>> mystr = '<b>Hello World</b> '
>>> mystr = mark_safe(mystr)
>>> type(mystr)
<class 'django.utils.safestring.Safe
Text
'>
<class 'django.utils.safestring.Safe
String
'>
>>> mystr = mystr.strip() # removing whitespace
>>> type(mystr)
...
...
tests/i18n/tests.py
Dosyayı görüntüle @
77d25dbd
...
...
@@ -28,7 +28,7 @@ from django.utils.formats import (
localize_input
,
reset_format_cache
,
sanitize_separators
,
time_format
,
)
from
django.utils.numberformat
import
format
as
nformat
from
django.utils.safestring
import
Safe
Text
,
mark_safe
from
django.utils.safestring
import
Safe
String
,
mark_safe
from
django.utils.translation
import
(
LANGUAGE_SESSION_KEY
,
activate
,
check_for_language
,
deactivate
,
get_language
,
get_language_bidi
,
get_language_from_request
,
...
...
@@ -287,10 +287,10 @@ class TranslationTests(SimpleTestCase):
s1
=
mark_safe
(
'Password'
)
s2
=
mark_safe
(
'May'
)
with
translation
.
override
(
'de'
,
deactivate
=
True
):
self
.
assertIs
(
type
(
gettext
(
s1
)),
Safe
Text
)
self
.
assertIs
(
type
(
pgettext
(
'month name'
,
s2
)),
Safe
Text
)
self
.
assertEqual
(
'aPassword'
,
Safe
Text
(
'a'
)
+
s1
)
self
.
assertEqual
(
'Passworda'
,
s1
+
Safe
Text
(
'a'
))
self
.
assertIs
(
type
(
gettext
(
s1
)),
Safe
String
)
self
.
assertIs
(
type
(
pgettext
(
'month name'
,
s2
)),
Safe
String
)
self
.
assertEqual
(
'aPassword'
,
Safe
String
(
'a'
)
+
s1
)
self
.
assertEqual
(
'Passworda'
,
s1
+
Safe
String
(
'a'
))
self
.
assertEqual
(
'Passworda'
,
s1
+
mark_safe
(
'a'
))
self
.
assertEqual
(
'aPassword'
,
mark_safe
(
'a'
)
+
s1
)
self
.
assertEqual
(
'as'
,
mark_safe
(
'a'
)
+
mark_safe
(
's'
))
...
...
@@ -1532,7 +1532,7 @@ class TestModels(TestCase):
def
test_safestr
(
self
):
c
=
Company
(
cents_paid
=
12
,
products_delivered
=
1
)
c
.
name
=
Safe
Text
(
'Iñtërnâtiônàlizætiøn1'
)
c
.
name
=
Safe
String
(
'Iñtërnâtiônàlizætiøn1'
)
c
.
save
()
...
...
tests/utils_tests/test_safestring.py
Dosyayı görüntüle @
77d25dbd
...
...
@@ -26,7 +26,7 @@ class SafeStringTest(SimpleTestCase):
def
test_mark_safe_str
(
self
):
"""
Calling str() on a Safe
Text
instance doesn't lose the safe status.
Calling str() on a Safe
String
instance doesn't lose the safe status.
"""
s
=
mark_safe
(
'a&b'
)
self
.
assertIsInstance
(
str
(
s
),
type
(
s
))
...
...
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