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
bc32fee0
Kaydet (Commit)
bc32fee0
authored
Şub 18, 2008
tarafından
Eric Smith
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added code to correct combining str and unicode in ''.format(). Added test case.
üst
5299935b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
0 deletions
+25
-0
test_unicode.py
Lib/test/test_unicode.py
+9
-0
string_format.h
Objects/stringlib/string_format.h
+16
-0
No files found.
Lib/test/test_unicode.py
Dosyayı görüntüle @
bc32fee0
...
...
@@ -1088,6 +1088,15 @@ class UnicodeTest(
self
.
assertRaises
(
ValueError
,
format
,
""
,
"-"
)
self
.
assertRaises
(
ValueError
,
"{0:=s}"
.
format
,
''
)
# test combining string and unicode
self
.
assertEqual
(
u"foo{0}"
.
format
(
'bar'
),
u'foobar'
)
# This will try to convert the argument from unicode to str, which
# will succeed
self
.
assertEqual
(
"foo{0}"
.
format
(
u'bar'
),
'foobar'
)
# This will try to convert the argument from unicode to str, which
# will fail
self
.
assertRaises
(
UnicodeEncodeError
,
"foo{0}"
.
format
,
u'
\u1000
bar'
)
def
test_main
():
test_support
.
run_unittest
(
__name__
)
...
...
Objects/stringlib/string_format.h
Dosyayı görüntüle @
bc32fee0
...
...
@@ -493,6 +493,22 @@ render_field(PyObject *fieldobj, SubString *format_spec, OutputString *output)
if
(
result
==
NULL
)
goto
done
;
#if PY_VERSION_HEX >= 0x03000000
assert
(
PyString_Check
(
result
));
#else
assert
(
PyString_Check
(
result
)
||
PyUnicode_Check
(
result
));
/* Convert result to our type. We could be str, and result could
be unicode */
{
PyObject
*
tmp
=
STRINGLIB_TOSTR
(
result
);
if
(
tmp
==
NULL
)
goto
done
;
Py_DECREF
(
result
);
result
=
tmp
;
}
#endif
ok
=
output_data
(
output
,
STRINGLIB_STR
(
result
),
STRINGLIB_LEN
(
result
));
done:
...
...
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