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
1e3cd511
Unverified
Kaydet (Commit)
1e3cd511
authored
Eki 12, 2018
tarafından
Tim Graham
Kaydeden (comit)
GitHub
Eki 12, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Simplified django.utils.html.urlize().
üst
91054863
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
23 deletions
+13
-23
html.py
django/utils/html.py
+13
-23
No files found.
django/utils/html.py
Dosyayı görüntüle @
1e3cd511
...
@@ -259,23 +259,14 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False):
...
@@ -259,23 +259,14 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False):
return
x
return
x
return
'
%
s…'
%
x
[:
max
(
0
,
limit
-
1
)]
return
'
%
s…'
%
x
[:
max
(
0
,
limit
-
1
)]
def
unescape
(
text
,
trail
):
def
unescape
(
text
):
"""
"""
If input URL is HTML-escaped, unescape it so that it can be safely fed
If input URL is HTML-escaped, unescape it so that it can be safely fed
to smart_urlquote. For example:
to smart_urlquote. For example:
http://example.com?x=1&y=<2> => http://example.com?x=1&y=<2>
http://example.com?x=1&y=<2> => http://example.com?x=1&y=<2>
"""
"""
unescaped
=
(
text
+
trail
)
.
replace
(
return
text
.
replace
(
'&'
,
'&'
)
.
replace
(
'<'
,
'<'
)
.
replace
(
'&'
,
'&'
)
.
replace
(
'<'
,
'<'
)
.
replace
(
'>'
,
'>'
)
.
replace
(
'"'
,
'"'
)
.
replace
(
'''
,
"'"
)
'>'
,
'>'
)
.
replace
(
'"'
,
'"'
)
.
replace
(
'''
,
"'"
)
if
trail
and
unescaped
.
endswith
(
trail
):
# Remove trail for unescaped if it was not consumed by unescape
unescaped
=
unescaped
[:
-
len
(
trail
)]
elif
trail
==
';'
:
# Trail was consumed by unescape (as end-of-entity marker), move it to text
text
+=
trail
trail
=
''
return
text
,
unescaped
,
trail
def
trim_punctuation
(
lead
,
middle
,
trail
):
def
trim_punctuation
(
lead
,
middle
,
trail
):
"""
"""
...
@@ -286,14 +277,6 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False):
...
@@ -286,14 +277,6 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False):
trimmed_something
=
True
trimmed_something
=
True
while
trimmed_something
:
while
trimmed_something
:
trimmed_something
=
False
trimmed_something
=
False
# Trim trailing punctuation.
stripped
=
middle
.
rstrip
(
TRAILING_PUNCTUATION_CHARS
)
if
middle
!=
stripped
:
trail
=
middle
[
len
(
stripped
):]
+
trail
middle
=
stripped
trimmed_something
=
True
# Trim wrapping punctuation.
# Trim wrapping punctuation.
for
opening
,
closing
in
WRAPPING_PUNCTUATION
:
for
opening
,
closing
in
WRAPPING_PUNCTUATION
:
if
middle
.
startswith
(
opening
):
if
middle
.
startswith
(
opening
):
...
@@ -306,6 +289,15 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False):
...
@@ -306,6 +289,15 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False):
middle
=
middle
[:
-
len
(
closing
)]
middle
=
middle
[:
-
len
(
closing
)]
trail
=
closing
+
trail
trail
=
closing
+
trail
trimmed_something
=
True
trimmed_something
=
True
# Trim trailing punctuation (after trimming wrapping punctuation,
# as encoded entities contain ';'). Unescape entites to avoid
# breaking them by removing ';'.
middle_unescaped
=
unescape
(
middle
)
stripped
=
middle_unescaped
.
rstrip
(
TRAILING_PUNCTUATION_CHARS
)
if
middle_unescaped
!=
stripped
:
trail
=
middle
[
len
(
stripped
):]
+
trail
middle
=
middle
[:
len
(
stripped
)
-
len
(
middle_unescaped
)]
trimmed_something
=
True
return
lead
,
middle
,
trail
return
lead
,
middle
,
trail
def
is_email_simple
(
value
):
def
is_email_simple
(
value
):
...
@@ -337,11 +329,9 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False):
...
@@ -337,11 +329,9 @@ def urlize(text, trim_url_limit=None, nofollow=False, autoescape=False):
url
=
None
url
=
None
nofollow_attr
=
' rel="nofollow"'
if
nofollow
else
''
nofollow_attr
=
' rel="nofollow"'
if
nofollow
else
''
if
simple_url_re
.
match
(
middle
):
if
simple_url_re
.
match
(
middle
):
middle
,
middle_unescaped
,
trail
=
unescape
(
middle
,
trail
)
url
=
smart_urlquote
(
unescape
(
middle
))
url
=
smart_urlquote
(
middle_unescaped
)
elif
simple_url_2_re
.
match
(
middle
):
elif
simple_url_2_re
.
match
(
middle
):
middle
,
middle_unescaped
,
trail
=
unescape
(
middle
,
trail
)
url
=
smart_urlquote
(
'http://
%
s'
%
unescape
(
middle
))
url
=
smart_urlquote
(
'http://
%
s'
%
middle_unescaped
)
elif
':'
not
in
middle
and
is_email_simple
(
middle
):
elif
':'
not
in
middle
and
is_email_simple
(
middle
):
local
,
domain
=
middle
.
rsplit
(
'@'
,
1
)
local
,
domain
=
middle
.
rsplit
(
'@'
,
1
)
try
:
try
:
...
...
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