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
6d970f47
Kaydet (Commit)
6d970f47
authored
Mar 02, 2011
tarafından
Victor Stinner
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats
üst
e7faec1a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
20 deletions
+35
-20
test_unicode.py
Lib/test/test_unicode.py
+28
-11
NEWS
Misc/NEWS
+2
-0
unicodeobject.c
Objects/unicodeobject.c
+5
-9
No files found.
Lib/test/test_unicode.py
Dosyayı görüntüle @
6d970f47
...
...
@@ -1430,7 +1430,9 @@ class UnicodeTest(string_tests.CommonTest,
# Test PyUnicode_FromFormat()
def
test_from_format
(
self
):
support
.
import_module
(
'ctypes'
)
from
ctypes
import
pythonapi
,
py_object
,
c_int
from
ctypes
import
(
pythonapi
,
py_object
,
c_int
,
c_long
,
c_longlong
,
c_ssize_t
,
c_uint
,
c_ulong
,
c_ulonglong
,
c_size_t
)
if
sys
.
maxunicode
==
65535
:
name
=
"PyUnicodeUCS2_FromFormat"
else
:
...
...
@@ -1466,21 +1468,29 @@ class UnicodeTest(string_tests.CommonTest,
self
.
assertEqual
(
PyUnicode_FromFormat
(
b
'[
%%
]'
),
'[
%
]'
)
self
.
assertEqual
(
PyUnicode_FromFormat
(
b
'
%%%
s'
,
b
'abc'
),
'
%
abc'
)
# test
"%i"
# test
integer formats (%i, %d, %u)
self
.
assertEqual
(
PyUnicode_FromFormat
(
b
'
%03
i'
,
c_int
(
10
)),
'010'
)
self
.
assertEqual
(
PyUnicode_FromFormat
(
b
'
%0.4
i'
,
c_int
(
10
)),
'0010'
)
# not supported: copy the raw format string. these tests are just here
# to check for crashs and should not be considered as specifications
self
.
assertEqual
(
PyUnicode_FromFormat
(
b
'
%1%
s'
,
b
'abc'
),
'
%
s'
)
self
.
assertEqual
(
PyUnicode_FromFormat
(
b
'
%1
abc'
),
'
%1
abc'
)
self
.
assertEqual
(
PyUnicode_FromFormat
(
b
'
%+
i'
,
c_int
(
10
)),
'
%+
i'
)
self
.
assertEqual
(
PyUnicode_FromFormat
(
b
'
%
.
%
s'
,
b
'abc'
),
'
%
.
%
s'
)
# other tests
self
.
assertEqual
(
PyUnicode_FromFormat
(
b
'
%
i'
,
c_int
(
-
123
)),
'-123'
)
self
.
assertEqual
(
PyUnicode_FromFormat
(
b
'
%
li'
,
c_long
(
-
123
)),
'-123'
)
self
.
assertEqual
(
PyUnicode_FromFormat
(
b
'
%
lli'
,
c_longlong
(
-
123
)),
'-123'
)
self
.
assertEqual
(
PyUnicode_FromFormat
(
b
'
%
zi'
,
c_ssize_t
(
-
123
)),
'-123'
)
self
.
assertEqual
(
PyUnicode_FromFormat
(
b
'
%
d'
,
c_int
(
-
123
)),
'-123'
)
self
.
assertEqual
(
PyUnicode_FromFormat
(
b
'
%
ld'
,
c_long
(
-
123
)),
'-123'
)
self
.
assertEqual
(
PyUnicode_FromFormat
(
b
'
%
lld'
,
c_longlong
(
-
123
)),
'-123'
)
self
.
assertEqual
(
PyUnicode_FromFormat
(
b
'
%
zd'
,
c_ssize_t
(
-
123
)),
'-123'
)
self
.
assertEqual
(
PyUnicode_FromFormat
(
b
'
%
u'
,
c_uint
(
123
)),
'123'
)
self
.
assertEqual
(
PyUnicode_FromFormat
(
b
'
%
lu'
,
c_ulong
(
123
)),
'123'
)
self
.
assertEqual
(
PyUnicode_FromFormat
(
b
'
%
llu'
,
c_ulonglong
(
123
)),
'123'
)
self
.
assertEqual
(
PyUnicode_FromFormat
(
b
'
%
zu'
,
c_size_t
(
123
)),
'123'
)
# test %A
text
=
PyUnicode_FromFormat
(
b
'
%%
A:
%
A'
,
'abc
\xe9\uabcd\U0010ffff
'
)
self
.
assertEqual
(
text
,
r"
%
A:'abc\xe9\uabcd\U0010ffff'"
)
# test %V
text
=
PyUnicode_FromFormat
(
b
'repr=
%
V'
,
'abc'
,
b
'xyz'
)
self
.
assertEqual
(
text
,
'repr=abc'
)
...
...
@@ -1494,6 +1504,13 @@ class UnicodeTest(string_tests.CommonTest,
text
=
PyUnicode_FromFormat
(
b
'repr=
%
V'
,
None
,
b
'abc
\xff
'
)
self
.
assertEqual
(
text
,
'repr=abc
\ufffd
'
)
# not supported: copy the raw format string. these tests are just here
# to check for crashs and should not be considered as specifications
self
.
assertEqual
(
PyUnicode_FromFormat
(
b
'
%1%
s'
,
b
'abc'
),
'
%
s'
)
self
.
assertEqual
(
PyUnicode_FromFormat
(
b
'
%1
abc'
),
'
%1
abc'
)
self
.
assertEqual
(
PyUnicode_FromFormat
(
b
'
%+
i'
,
c_int
(
10
)),
'
%+
i'
)
self
.
assertEqual
(
PyUnicode_FromFormat
(
b
'
%
.
%
s'
,
b
'abc'
),
'
%
.
%
s'
)
# Test PyUnicode_AsWideChar()
def
test_aswidechar
(
self
):
from
_testcapi
import
unicode_aswidechar
...
...
Misc/NEWS
Dosyayı görüntüle @
6d970f47
...
...
@@ -10,6 +10,8 @@ What's New in Python 3.3 Alpha 1?
Core and Builtins
-----------------
- Issue #10831: PyUnicode_FromFormat() supports %li, %lli and %zi formats.
- Issue #10829: Refactor PyUnicode_FromFormat(), use the same function to parse
the format string in the 3 steps, fix crashs on invalid format strings.
...
...
Objects/unicodeobject.c
Dosyayı görüntüle @
6d970f47
...
...
@@ -753,20 +753,20 @@ parse_format_flags(const char *f,
size_tflag
=
0
;
if
(
*
f
==
'l'
)
{
if
(
f
[
1
]
==
'd'
||
f
[
1
]
==
'u'
)
{
if
(
f
[
1
]
==
'd'
||
f
[
1
]
==
'u'
||
f
[
1
]
==
'i'
)
{
longflag
=
1
;
++
f
;
}
#ifdef HAVE_LONG_LONG
else
if
(
f
[
1
]
==
'l'
&&
(
f
[
2
]
==
'd'
||
f
[
2
]
==
'u'
))
{
(
f
[
2
]
==
'd'
||
f
[
2
]
==
'u'
||
f
[
2
]
==
'i'
))
{
longlongflag
=
1
;
f
+=
2
;
}
#endif
}
/* handle the size_t flag. */
else
if
(
*
f
==
'z'
&&
(
f
[
1
]
==
'd'
||
f
[
1
]
==
'u'
))
{
else
if
(
*
f
==
'z'
&&
(
f
[
1
]
==
'd'
||
f
[
1
]
==
'u'
||
f
[
1
]
==
'i'
))
{
size_tflag
=
1
;
++
f
;
}
...
...
@@ -1044,9 +1044,10 @@ PyUnicode_FromFormatV(const char *format, va_list vargs)
*
s
++
=
ordinal
;
break
;
}
case
'i'
:
case
'd'
:
makefmt
(
fmt
,
longflag
,
longlongflag
,
size_tflag
,
zeropad
,
width
,
precision
,
'd'
);
width
,
precision
,
*
f
);
if
(
longflag
)
sprintf
(
realbuffer
,
fmt
,
va_arg
(
vargs
,
long
));
#ifdef HAVE_LONG_LONG
...
...
@@ -1075,11 +1076,6 @@ PyUnicode_FromFormatV(const char *format, va_list vargs)
sprintf
(
realbuffer
,
fmt
,
va_arg
(
vargs
,
unsigned
int
));
appendstring
(
realbuffer
);
break
;
case
'i'
:
makefmt
(
fmt
,
0
,
0
,
0
,
zeropad
,
width
,
precision
,
'i'
);
sprintf
(
realbuffer
,
fmt
,
va_arg
(
vargs
,
int
));
appendstring
(
realbuffer
);
break
;
case
'x'
:
makefmt
(
fmt
,
0
,
0
,
0
,
zeropad
,
width
,
precision
,
'x'
);
sprintf
(
realbuffer
,
fmt
,
va_arg
(
vargs
,
int
));
...
...
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