Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
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
cpython
Commits
eb19dce0
Kaydet (Commit)
eb19dce0
authored
14 years ago
tarafından
Florent Xicluna
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #1686: Fix string.Template when overriding the pattern attribute.
üst
98b46702
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
9 deletions
+39
-9
string.py
Lib/string.py
+3
-9
test_pep292.py
Lib/test/test_pep292.py
+34
-0
NEWS
Misc/NEWS
+2
-0
No files found.
Lib/string.py
Dosyayı görüntüle @
eb19dce0
...
...
@@ -145,24 +145,18 @@ class Template(metaclass=_TemplateMetaclass):
mapping
=
args
[
0
]
# Helper function for .sub()
def
convert
(
mo
):
named
=
mo
.
group
(
'named'
)
named
=
mo
.
group
(
'named'
)
or
mo
.
group
(
'braced'
)
if
named
is
not
None
:
try
:
# We use this idiom instead of str() because the latter
# will fail if val is a Unicode containing non-ASCII
return
'
%
s'
%
(
mapping
[
named
],)
except
KeyError
:
return
self
.
delimiter
+
named
braced
=
mo
.
group
(
'braced'
)
if
braced
is
not
None
:
try
:
return
'
%
s'
%
(
mapping
[
braced
],)
except
KeyError
:
return
self
.
delimiter
+
'{'
+
braced
+
'}'
return
mo
.
group
()
if
mo
.
group
(
'escaped'
)
is
not
None
:
return
self
.
delimiter
if
mo
.
group
(
'invalid'
)
is
not
None
:
return
self
.
delimiter
return
mo
.
group
()
raise
ValueError
(
'Unrecognized named group in pattern'
,
self
.
pattern
)
return
self
.
pattern
.
sub
(
convert
,
self
.
template
)
...
...
This diff is collapsed.
Click to expand it.
Lib/test/test_pep292.py
Dosyayı görüntüle @
eb19dce0
...
...
@@ -125,6 +125,40 @@ class TestTemplate(unittest.TestCase):
self
.
assertRaises
(
ValueError
,
s
.
substitute
,
{})
self
.
assertRaises
(
ValueError
,
s
.
safe_substitute
,
{})
def
test_braced_override
(
self
):
class
MyTemplate
(
Template
):
pattern
=
r"""
\$(?:
(?P<escaped>$) |
(?P<named>[_a-z][_a-z0-9]*) |
@@(?P<braced>[_a-z][_a-z0-9]*)@@ |
(?P<invalid>) |
)
"""
tmpl
=
'PyCon in $@@location@@'
t
=
MyTemplate
(
tmpl
)
self
.
assertRaises
(
KeyError
,
t
.
substitute
,
{})
val
=
t
.
substitute
({
'location'
:
'Cleveland'
})
self
.
assertEqual
(
val
,
'PyCon in Cleveland'
)
def
test_braced_override_safe
(
self
):
class
MyTemplate
(
Template
):
pattern
=
r"""
\$(?:
(?P<escaped>$) |
(?P<named>[_a-z][_a-z0-9]*) |
@@(?P<braced>[_a-z][_a-z0-9]*)@@ |
(?P<invalid>) |
)
"""
tmpl
=
'PyCon in $@@location@@'
t
=
MyTemplate
(
tmpl
)
self
.
assertEqual
(
t
.
safe_substitute
(),
tmpl
)
val
=
t
.
safe_substitute
({
'location'
:
'Cleveland'
})
self
.
assertEqual
(
val
,
'PyCon in Cleveland'
)
def
test_unicode_values
(
self
):
s
=
Template
(
'$who likes $what'
)
d
=
dict
(
who
=
't
\xff
m'
,
what
=
'f
\xfe\f
ed'
)
...
...
This diff is collapsed.
Click to expand it.
Misc/NEWS
Dosyayı görüntüle @
eb19dce0
...
...
@@ -52,6 +52,8 @@ Core and Builtins
Library
-------
- Issue #1686: Fix string.Template when overriding the pattern attribute.
- Issue #9854: SocketIO objects now observe the RawIOBase interface in
non-blocking mode: they return None when an operation would block (instead
of raising an exception).
...
...
This diff is collapsed.
Click to expand it.
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