2007-08-24 23:26:07 -03:00
|
|
|
/* implements the string, long, and float formatters. that is,
|
|
|
|
string.__format__, etc. */
|
|
|
|
|
|
|
|
/* Before including this, you must include either:
|
|
|
|
stringlib/unicodedefs.h
|
|
|
|
stringlib/stringdefs.h
|
|
|
|
|
|
|
|
Also, you should define the names:
|
|
|
|
FORMAT_STRING
|
|
|
|
FORMAT_LONG
|
|
|
|
FORMAT_FLOAT
|
|
|
|
to be whatever you want the public names of these functions to
|
|
|
|
be. These are the only non-static functions defined here.
|
|
|
|
*/
|
|
|
|
|
2007-08-29 09:38:45 -03:00
|
|
|
#define ALLOW_PARENS_FOR_SIGN 0
|
|
|
|
|
2007-08-24 23:26:07 -03:00
|
|
|
/*
|
|
|
|
get_integer consumes 0 or more decimal digit characters from an
|
|
|
|
input string, updates *result with the corresponding positive
|
|
|
|
integer, and returns the number of digits consumed.
|
|
|
|
|
|
|
|
returns -1 on error.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
get_integer(STRINGLIB_CHAR **ptr, STRINGLIB_CHAR *end,
|
|
|
|
Py_ssize_t *result)
|
|
|
|
{
|
|
|
|
Py_ssize_t accumulator, digitval, oldaccumulator;
|
|
|
|
int numdigits;
|
|
|
|
accumulator = numdigits = 0;
|
|
|
|
for (;;(*ptr)++, numdigits++) {
|
|
|
|
if (*ptr >= end)
|
|
|
|
break;
|
|
|
|
digitval = STRINGLIB_TODECIMAL(**ptr);
|
|
|
|
if (digitval < 0)
|
|
|
|
break;
|
|
|
|
/*
|
|
|
|
This trick was copied from old Unicode format code. It's cute,
|
|
|
|
but would really suck on an old machine with a slow divide
|
|
|
|
implementation. Fortunately, in the normal case we do not
|
|
|
|
expect too many digits.
|
|
|
|
*/
|
|
|
|
oldaccumulator = accumulator;
|
|
|
|
accumulator *= 10;
|
|
|
|
if ((accumulator+10)/10 != oldaccumulator+1) {
|
|
|
|
PyErr_Format(PyExc_ValueError,
|
|
|
|
"Too many decimal digits in format string");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
accumulator += digitval;
|
|
|
|
}
|
|
|
|
*result = accumulator;
|
|
|
|
return numdigits;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/*********** standard format specifier parsing **************************/
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
/* returns true if this character is a specifier alignment token */
|
|
|
|
Py_LOCAL_INLINE(int)
|
|
|
|
is_alignment_token(STRINGLIB_CHAR c)
|
|
|
|
{
|
|
|
|
switch (c) {
|
|
|
|
case '<': case '>': case '=': case '^':
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* returns true if this character is a sign element */
|
|
|
|
Py_LOCAL_INLINE(int)
|
|
|
|
is_sign_element(STRINGLIB_CHAR c)
|
|
|
|
{
|
|
|
|
switch (c) {
|
2007-08-29 09:38:45 -03:00
|
|
|
case ' ': case '+': case '-':
|
2007-08-29 09:43:12 -03:00
|
|
|
#if ALLOW_PARENS_FOR_SIGN
|
2007-08-29 09:38:45 -03:00
|
|
|
case '(':
|
2007-08-29 09:43:12 -03:00
|
|
|
#endif
|
2007-08-24 23:26:07 -03:00
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
STRINGLIB_CHAR fill_char;
|
|
|
|
STRINGLIB_CHAR align;
|
2008-07-15 10:02:41 -03:00
|
|
|
int alternate;
|
2007-08-24 23:26:07 -03:00
|
|
|
STRINGLIB_CHAR sign;
|
|
|
|
Py_ssize_t width;
|
|
|
|
Py_ssize_t precision;
|
|
|
|
STRINGLIB_CHAR type;
|
|
|
|
} InternalFormatSpec;
|
|
|
|
|
|
|
|
/*
|
|
|
|
ptr points to the start of the format_spec, end points just past its end.
|
|
|
|
fills in format with the parsed information.
|
|
|
|
returns 1 on success, 0 on failure.
|
|
|
|
if failure, sets the exception
|
|
|
|
*/
|
|
|
|
static int
|
2008-05-30 15:10:19 -03:00
|
|
|
parse_internal_render_format_spec(STRINGLIB_CHAR *format_spec,
|
|
|
|
Py_ssize_t format_spec_len,
|
2007-08-24 23:26:07 -03:00
|
|
|
InternalFormatSpec *format,
|
|
|
|
char default_type)
|
|
|
|
{
|
2008-05-30 15:10:19 -03:00
|
|
|
STRINGLIB_CHAR *ptr = format_spec;
|
|
|
|
STRINGLIB_CHAR *end = format_spec + format_spec_len;
|
2007-08-24 23:26:07 -03:00
|
|
|
|
|
|
|
/* end-ptr is used throughout this code to specify the length of
|
|
|
|
the input string */
|
|
|
|
|
|
|
|
Py_ssize_t specified_width;
|
|
|
|
|
|
|
|
format->fill_char = '\0';
|
|
|
|
format->align = '\0';
|
2008-07-15 10:02:41 -03:00
|
|
|
format->alternate = 0;
|
2007-08-24 23:26:07 -03:00
|
|
|
format->sign = '\0';
|
|
|
|
format->width = -1;
|
|
|
|
format->precision = -1;
|
|
|
|
format->type = default_type;
|
|
|
|
|
|
|
|
/* If the second char is an alignment token,
|
|
|
|
then parse the fill char */
|
|
|
|
if (end-ptr >= 2 && is_alignment_token(ptr[1])) {
|
|
|
|
format->align = ptr[1];
|
|
|
|
format->fill_char = ptr[0];
|
|
|
|
ptr += 2;
|
2007-08-27 22:07:27 -03:00
|
|
|
}
|
|
|
|
else if (end-ptr >= 1 && is_alignment_token(ptr[0])) {
|
2007-08-24 23:26:07 -03:00
|
|
|
format->align = ptr[0];
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900-60931,60933-60958 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60901 | eric.smith | 2008-02-19 14:21:56 +0100 (Tue, 19 Feb 2008) | 1 line
Added PEP 3101.
........
r60907 | georg.brandl | 2008-02-20 20:12:36 +0100 (Wed, 20 Feb 2008) | 2 lines
Fixes contributed by Ori Avtalion.
........
r60909 | eric.smith | 2008-02-21 00:34:22 +0100 (Thu, 21 Feb 2008) | 1 line
Trim leading zeros from a floating point exponent, per C99. See issue 1600. As far as I know, this only affects Windows. Add float type 'n' to PyOS_ascii_formatd (see PEP 3101 for 'n' description).
........
r60910 | eric.smith | 2008-02-21 00:39:28 +0100 (Thu, 21 Feb 2008) | 1 line
Now that PyOS_ascii_formatd supports the 'n' format, simplify the float formatting code to just call it.
........
r60918 | andrew.kuchling | 2008-02-21 15:23:38 +0100 (Thu, 21 Feb 2008) | 2 lines
Close manifest file.
This change doesn't make any difference to CPython, but is a necessary fix for Jython.
........
r60921 | guido.van.rossum | 2008-02-21 18:46:16 +0100 (Thu, 21 Feb 2008) | 2 lines
Remove news about float repr() -- issue 1580 is still in limbo.
........
r60923 | guido.van.rossum | 2008-02-21 19:18:37 +0100 (Thu, 21 Feb 2008) | 5 lines
Removed uses of dict.has_key() from distutils, and uses of
callable() from copy_reg.py, so the interpreter now starts up
without warnings when '-3' is given. More work like this needs to
be done in the rest of the stdlib.
........
r60924 | thomas.heller | 2008-02-21 19:28:48 +0100 (Thu, 21 Feb 2008) | 4 lines
configure.ac: Remove the configure check for _Bool, it is already done in the
top-level Python configure script.
configure, fficonfig.h.in: regenerated.
........
r60925 | thomas.heller | 2008-02-21 19:52:20 +0100 (Thu, 21 Feb 2008) | 3 lines
Replace 'has_key()' with 'in'.
Replace 'raise Error, stuff' with 'raise Error(stuff)'.
........
r60927 | raymond.hettinger | 2008-02-21 20:24:53 +0100 (Thu, 21 Feb 2008) | 1 line
Update more instances of has_key().
........
r60928 | guido.van.rossum | 2008-02-21 20:46:35 +0100 (Thu, 21 Feb 2008) | 3 lines
Fix a few typos and layout glitches (more work is needed).
Move 2.5 news to Misc/HISTORY.
........
r60936 | georg.brandl | 2008-02-21 21:33:38 +0100 (Thu, 21 Feb 2008) | 2 lines
#2079: typo in userdict docs.
........
r60938 | georg.brandl | 2008-02-21 21:38:13 +0100 (Thu, 21 Feb 2008) | 2 lines
Part of #2154: minimal syntax fixes in doc example snippets.
........
r60942 | raymond.hettinger | 2008-02-22 04:16:42 +0100 (Fri, 22 Feb 2008) | 1 line
First draft for itertools.product(). Docs and other updates forthcoming.
........
r60955 | nick.coghlan | 2008-02-22 11:54:06 +0100 (Fri, 22 Feb 2008) | 1 line
Try to make command line error messages from runpy easier to understand (and suppress traceback cruft from the implicitly invoked runpy machinery)
........
r60956 | georg.brandl | 2008-02-22 13:31:45 +0100 (Fri, 22 Feb 2008) | 2 lines
A lot more typo fixes by Ori Avtalion.
........
r60957 | georg.brandl | 2008-02-22 13:56:34 +0100 (Fri, 22 Feb 2008) | 2 lines
Don't reference pyshell.
........
r60958 | georg.brandl | 2008-02-22 13:57:05 +0100 (Fri, 22 Feb 2008) | 2 lines
Another fix.
........
2008-02-22 12:37:40 -04:00
|
|
|
++ptr;
|
2007-08-24 23:26:07 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Parse the various sign options */
|
|
|
|
if (end-ptr >= 1 && is_sign_element(ptr[0])) {
|
|
|
|
format->sign = ptr[0];
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900-60931,60933-60958 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60901 | eric.smith | 2008-02-19 14:21:56 +0100 (Tue, 19 Feb 2008) | 1 line
Added PEP 3101.
........
r60907 | georg.brandl | 2008-02-20 20:12:36 +0100 (Wed, 20 Feb 2008) | 2 lines
Fixes contributed by Ori Avtalion.
........
r60909 | eric.smith | 2008-02-21 00:34:22 +0100 (Thu, 21 Feb 2008) | 1 line
Trim leading zeros from a floating point exponent, per C99. See issue 1600. As far as I know, this only affects Windows. Add float type 'n' to PyOS_ascii_formatd (see PEP 3101 for 'n' description).
........
r60910 | eric.smith | 2008-02-21 00:39:28 +0100 (Thu, 21 Feb 2008) | 1 line
Now that PyOS_ascii_formatd supports the 'n' format, simplify the float formatting code to just call it.
........
r60918 | andrew.kuchling | 2008-02-21 15:23:38 +0100 (Thu, 21 Feb 2008) | 2 lines
Close manifest file.
This change doesn't make any difference to CPython, but is a necessary fix for Jython.
........
r60921 | guido.van.rossum | 2008-02-21 18:46:16 +0100 (Thu, 21 Feb 2008) | 2 lines
Remove news about float repr() -- issue 1580 is still in limbo.
........
r60923 | guido.van.rossum | 2008-02-21 19:18:37 +0100 (Thu, 21 Feb 2008) | 5 lines
Removed uses of dict.has_key() from distutils, and uses of
callable() from copy_reg.py, so the interpreter now starts up
without warnings when '-3' is given. More work like this needs to
be done in the rest of the stdlib.
........
r60924 | thomas.heller | 2008-02-21 19:28:48 +0100 (Thu, 21 Feb 2008) | 4 lines
configure.ac: Remove the configure check for _Bool, it is already done in the
top-level Python configure script.
configure, fficonfig.h.in: regenerated.
........
r60925 | thomas.heller | 2008-02-21 19:52:20 +0100 (Thu, 21 Feb 2008) | 3 lines
Replace 'has_key()' with 'in'.
Replace 'raise Error, stuff' with 'raise Error(stuff)'.
........
r60927 | raymond.hettinger | 2008-02-21 20:24:53 +0100 (Thu, 21 Feb 2008) | 1 line
Update more instances of has_key().
........
r60928 | guido.van.rossum | 2008-02-21 20:46:35 +0100 (Thu, 21 Feb 2008) | 3 lines
Fix a few typos and layout glitches (more work is needed).
Move 2.5 news to Misc/HISTORY.
........
r60936 | georg.brandl | 2008-02-21 21:33:38 +0100 (Thu, 21 Feb 2008) | 2 lines
#2079: typo in userdict docs.
........
r60938 | georg.brandl | 2008-02-21 21:38:13 +0100 (Thu, 21 Feb 2008) | 2 lines
Part of #2154: minimal syntax fixes in doc example snippets.
........
r60942 | raymond.hettinger | 2008-02-22 04:16:42 +0100 (Fri, 22 Feb 2008) | 1 line
First draft for itertools.product(). Docs and other updates forthcoming.
........
r60955 | nick.coghlan | 2008-02-22 11:54:06 +0100 (Fri, 22 Feb 2008) | 1 line
Try to make command line error messages from runpy easier to understand (and suppress traceback cruft from the implicitly invoked runpy machinery)
........
r60956 | georg.brandl | 2008-02-22 13:31:45 +0100 (Fri, 22 Feb 2008) | 2 lines
A lot more typo fixes by Ori Avtalion.
........
r60957 | georg.brandl | 2008-02-22 13:56:34 +0100 (Fri, 22 Feb 2008) | 2 lines
Don't reference pyshell.
........
r60958 | georg.brandl | 2008-02-22 13:57:05 +0100 (Fri, 22 Feb 2008) | 2 lines
Another fix.
........
2008-02-22 12:37:40 -04:00
|
|
|
++ptr;
|
2007-08-29 09:38:45 -03:00
|
|
|
#if ALLOW_PARENS_FOR_SIGN
|
2007-08-24 23:26:07 -03:00
|
|
|
if (end-ptr >= 1 && ptr[0] == ')') {
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900-60931,60933-60958 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60901 | eric.smith | 2008-02-19 14:21:56 +0100 (Tue, 19 Feb 2008) | 1 line
Added PEP 3101.
........
r60907 | georg.brandl | 2008-02-20 20:12:36 +0100 (Wed, 20 Feb 2008) | 2 lines
Fixes contributed by Ori Avtalion.
........
r60909 | eric.smith | 2008-02-21 00:34:22 +0100 (Thu, 21 Feb 2008) | 1 line
Trim leading zeros from a floating point exponent, per C99. See issue 1600. As far as I know, this only affects Windows. Add float type 'n' to PyOS_ascii_formatd (see PEP 3101 for 'n' description).
........
r60910 | eric.smith | 2008-02-21 00:39:28 +0100 (Thu, 21 Feb 2008) | 1 line
Now that PyOS_ascii_formatd supports the 'n' format, simplify the float formatting code to just call it.
........
r60918 | andrew.kuchling | 2008-02-21 15:23:38 +0100 (Thu, 21 Feb 2008) | 2 lines
Close manifest file.
This change doesn't make any difference to CPython, but is a necessary fix for Jython.
........
r60921 | guido.van.rossum | 2008-02-21 18:46:16 +0100 (Thu, 21 Feb 2008) | 2 lines
Remove news about float repr() -- issue 1580 is still in limbo.
........
r60923 | guido.van.rossum | 2008-02-21 19:18:37 +0100 (Thu, 21 Feb 2008) | 5 lines
Removed uses of dict.has_key() from distutils, and uses of
callable() from copy_reg.py, so the interpreter now starts up
without warnings when '-3' is given. More work like this needs to
be done in the rest of the stdlib.
........
r60924 | thomas.heller | 2008-02-21 19:28:48 +0100 (Thu, 21 Feb 2008) | 4 lines
configure.ac: Remove the configure check for _Bool, it is already done in the
top-level Python configure script.
configure, fficonfig.h.in: regenerated.
........
r60925 | thomas.heller | 2008-02-21 19:52:20 +0100 (Thu, 21 Feb 2008) | 3 lines
Replace 'has_key()' with 'in'.
Replace 'raise Error, stuff' with 'raise Error(stuff)'.
........
r60927 | raymond.hettinger | 2008-02-21 20:24:53 +0100 (Thu, 21 Feb 2008) | 1 line
Update more instances of has_key().
........
r60928 | guido.van.rossum | 2008-02-21 20:46:35 +0100 (Thu, 21 Feb 2008) | 3 lines
Fix a few typos and layout glitches (more work is needed).
Move 2.5 news to Misc/HISTORY.
........
r60936 | georg.brandl | 2008-02-21 21:33:38 +0100 (Thu, 21 Feb 2008) | 2 lines
#2079: typo in userdict docs.
........
r60938 | georg.brandl | 2008-02-21 21:38:13 +0100 (Thu, 21 Feb 2008) | 2 lines
Part of #2154: minimal syntax fixes in doc example snippets.
........
r60942 | raymond.hettinger | 2008-02-22 04:16:42 +0100 (Fri, 22 Feb 2008) | 1 line
First draft for itertools.product(). Docs and other updates forthcoming.
........
r60955 | nick.coghlan | 2008-02-22 11:54:06 +0100 (Fri, 22 Feb 2008) | 1 line
Try to make command line error messages from runpy easier to understand (and suppress traceback cruft from the implicitly invoked runpy machinery)
........
r60956 | georg.brandl | 2008-02-22 13:31:45 +0100 (Fri, 22 Feb 2008) | 2 lines
A lot more typo fixes by Ori Avtalion.
........
r60957 | georg.brandl | 2008-02-22 13:56:34 +0100 (Fri, 22 Feb 2008) | 2 lines
Don't reference pyshell.
........
r60958 | georg.brandl | 2008-02-22 13:57:05 +0100 (Fri, 22 Feb 2008) | 2 lines
Another fix.
........
2008-02-22 12:37:40 -04:00
|
|
|
++ptr;
|
2007-08-24 23:26:07 -03:00
|
|
|
}
|
2007-08-29 09:38:45 -03:00
|
|
|
#endif
|
2007-08-24 23:26:07 -03:00
|
|
|
}
|
|
|
|
|
2008-07-15 21:15:35 -03:00
|
|
|
/* If the next character is #, we're in alternate mode. This only
|
|
|
|
applies to integers. */
|
|
|
|
if (end-ptr >= 1 && ptr[0] == '#') {
|
|
|
|
format->alternate = 1;
|
|
|
|
++ptr;
|
|
|
|
}
|
|
|
|
|
2007-08-24 23:26:07 -03:00
|
|
|
/* The special case for 0-padding (backwards compat) */
|
2007-08-30 19:23:08 -03:00
|
|
|
if (format->fill_char == '\0' && end-ptr >= 1 && ptr[0] == '0') {
|
2007-08-24 23:26:07 -03:00
|
|
|
format->fill_char = '0';
|
|
|
|
if (format->align == '\0') {
|
|
|
|
format->align = '=';
|
|
|
|
}
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900-60931,60933-60958 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60901 | eric.smith | 2008-02-19 14:21:56 +0100 (Tue, 19 Feb 2008) | 1 line
Added PEP 3101.
........
r60907 | georg.brandl | 2008-02-20 20:12:36 +0100 (Wed, 20 Feb 2008) | 2 lines
Fixes contributed by Ori Avtalion.
........
r60909 | eric.smith | 2008-02-21 00:34:22 +0100 (Thu, 21 Feb 2008) | 1 line
Trim leading zeros from a floating point exponent, per C99. See issue 1600. As far as I know, this only affects Windows. Add float type 'n' to PyOS_ascii_formatd (see PEP 3101 for 'n' description).
........
r60910 | eric.smith | 2008-02-21 00:39:28 +0100 (Thu, 21 Feb 2008) | 1 line
Now that PyOS_ascii_formatd supports the 'n' format, simplify the float formatting code to just call it.
........
r60918 | andrew.kuchling | 2008-02-21 15:23:38 +0100 (Thu, 21 Feb 2008) | 2 lines
Close manifest file.
This change doesn't make any difference to CPython, but is a necessary fix for Jython.
........
r60921 | guido.van.rossum | 2008-02-21 18:46:16 +0100 (Thu, 21 Feb 2008) | 2 lines
Remove news about float repr() -- issue 1580 is still in limbo.
........
r60923 | guido.van.rossum | 2008-02-21 19:18:37 +0100 (Thu, 21 Feb 2008) | 5 lines
Removed uses of dict.has_key() from distutils, and uses of
callable() from copy_reg.py, so the interpreter now starts up
without warnings when '-3' is given. More work like this needs to
be done in the rest of the stdlib.
........
r60924 | thomas.heller | 2008-02-21 19:28:48 +0100 (Thu, 21 Feb 2008) | 4 lines
configure.ac: Remove the configure check for _Bool, it is already done in the
top-level Python configure script.
configure, fficonfig.h.in: regenerated.
........
r60925 | thomas.heller | 2008-02-21 19:52:20 +0100 (Thu, 21 Feb 2008) | 3 lines
Replace 'has_key()' with 'in'.
Replace 'raise Error, stuff' with 'raise Error(stuff)'.
........
r60927 | raymond.hettinger | 2008-02-21 20:24:53 +0100 (Thu, 21 Feb 2008) | 1 line
Update more instances of has_key().
........
r60928 | guido.van.rossum | 2008-02-21 20:46:35 +0100 (Thu, 21 Feb 2008) | 3 lines
Fix a few typos and layout glitches (more work is needed).
Move 2.5 news to Misc/HISTORY.
........
r60936 | georg.brandl | 2008-02-21 21:33:38 +0100 (Thu, 21 Feb 2008) | 2 lines
#2079: typo in userdict docs.
........
r60938 | georg.brandl | 2008-02-21 21:38:13 +0100 (Thu, 21 Feb 2008) | 2 lines
Part of #2154: minimal syntax fixes in doc example snippets.
........
r60942 | raymond.hettinger | 2008-02-22 04:16:42 +0100 (Fri, 22 Feb 2008) | 1 line
First draft for itertools.product(). Docs and other updates forthcoming.
........
r60955 | nick.coghlan | 2008-02-22 11:54:06 +0100 (Fri, 22 Feb 2008) | 1 line
Try to make command line error messages from runpy easier to understand (and suppress traceback cruft from the implicitly invoked runpy machinery)
........
r60956 | georg.brandl | 2008-02-22 13:31:45 +0100 (Fri, 22 Feb 2008) | 2 lines
A lot more typo fixes by Ori Avtalion.
........
r60957 | georg.brandl | 2008-02-22 13:56:34 +0100 (Fri, 22 Feb 2008) | 2 lines
Don't reference pyshell.
........
r60958 | georg.brandl | 2008-02-22 13:57:05 +0100 (Fri, 22 Feb 2008) | 2 lines
Another fix.
........
2008-02-22 12:37:40 -04:00
|
|
|
++ptr;
|
2007-08-24 23:26:07 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX add error checking */
|
|
|
|
specified_width = get_integer(&ptr, end, &format->width);
|
|
|
|
|
|
|
|
/* if specified_width is 0, we didn't consume any characters for
|
|
|
|
the width. in that case, reset the width to -1, because
|
|
|
|
get_integer() will have set it to zero */
|
|
|
|
if (specified_width == 0) {
|
|
|
|
format->width = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Parse field precision */
|
|
|
|
if (end-ptr && ptr[0] == '.') {
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900-60931,60933-60958 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60901 | eric.smith | 2008-02-19 14:21:56 +0100 (Tue, 19 Feb 2008) | 1 line
Added PEP 3101.
........
r60907 | georg.brandl | 2008-02-20 20:12:36 +0100 (Wed, 20 Feb 2008) | 2 lines
Fixes contributed by Ori Avtalion.
........
r60909 | eric.smith | 2008-02-21 00:34:22 +0100 (Thu, 21 Feb 2008) | 1 line
Trim leading zeros from a floating point exponent, per C99. See issue 1600. As far as I know, this only affects Windows. Add float type 'n' to PyOS_ascii_formatd (see PEP 3101 for 'n' description).
........
r60910 | eric.smith | 2008-02-21 00:39:28 +0100 (Thu, 21 Feb 2008) | 1 line
Now that PyOS_ascii_formatd supports the 'n' format, simplify the float formatting code to just call it.
........
r60918 | andrew.kuchling | 2008-02-21 15:23:38 +0100 (Thu, 21 Feb 2008) | 2 lines
Close manifest file.
This change doesn't make any difference to CPython, but is a necessary fix for Jython.
........
r60921 | guido.van.rossum | 2008-02-21 18:46:16 +0100 (Thu, 21 Feb 2008) | 2 lines
Remove news about float repr() -- issue 1580 is still in limbo.
........
r60923 | guido.van.rossum | 2008-02-21 19:18:37 +0100 (Thu, 21 Feb 2008) | 5 lines
Removed uses of dict.has_key() from distutils, and uses of
callable() from copy_reg.py, so the interpreter now starts up
without warnings when '-3' is given. More work like this needs to
be done in the rest of the stdlib.
........
r60924 | thomas.heller | 2008-02-21 19:28:48 +0100 (Thu, 21 Feb 2008) | 4 lines
configure.ac: Remove the configure check for _Bool, it is already done in the
top-level Python configure script.
configure, fficonfig.h.in: regenerated.
........
r60925 | thomas.heller | 2008-02-21 19:52:20 +0100 (Thu, 21 Feb 2008) | 3 lines
Replace 'has_key()' with 'in'.
Replace 'raise Error, stuff' with 'raise Error(stuff)'.
........
r60927 | raymond.hettinger | 2008-02-21 20:24:53 +0100 (Thu, 21 Feb 2008) | 1 line
Update more instances of has_key().
........
r60928 | guido.van.rossum | 2008-02-21 20:46:35 +0100 (Thu, 21 Feb 2008) | 3 lines
Fix a few typos and layout glitches (more work is needed).
Move 2.5 news to Misc/HISTORY.
........
r60936 | georg.brandl | 2008-02-21 21:33:38 +0100 (Thu, 21 Feb 2008) | 2 lines
#2079: typo in userdict docs.
........
r60938 | georg.brandl | 2008-02-21 21:38:13 +0100 (Thu, 21 Feb 2008) | 2 lines
Part of #2154: minimal syntax fixes in doc example snippets.
........
r60942 | raymond.hettinger | 2008-02-22 04:16:42 +0100 (Fri, 22 Feb 2008) | 1 line
First draft for itertools.product(). Docs and other updates forthcoming.
........
r60955 | nick.coghlan | 2008-02-22 11:54:06 +0100 (Fri, 22 Feb 2008) | 1 line
Try to make command line error messages from runpy easier to understand (and suppress traceback cruft from the implicitly invoked runpy machinery)
........
r60956 | georg.brandl | 2008-02-22 13:31:45 +0100 (Fri, 22 Feb 2008) | 2 lines
A lot more typo fixes by Ori Avtalion.
........
r60957 | georg.brandl | 2008-02-22 13:56:34 +0100 (Fri, 22 Feb 2008) | 2 lines
Don't reference pyshell.
........
r60958 | georg.brandl | 2008-02-22 13:57:05 +0100 (Fri, 22 Feb 2008) | 2 lines
Another fix.
........
2008-02-22 12:37:40 -04:00
|
|
|
++ptr;
|
2007-08-24 23:26:07 -03:00
|
|
|
|
|
|
|
/* XXX add error checking */
|
|
|
|
specified_width = get_integer(&ptr, end, &format->precision);
|
|
|
|
|
|
|
|
/* not having a precision after a dot is an error */
|
|
|
|
if (specified_width == 0) {
|
|
|
|
PyErr_Format(PyExc_ValueError,
|
|
|
|
"Format specifier missing precision");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Finally, parse the type field */
|
|
|
|
|
|
|
|
if (end-ptr > 1) {
|
|
|
|
/* invalid conversion spec */
|
|
|
|
PyErr_Format(PyExc_ValueError, "Invalid conversion specification");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (end-ptr == 1) {
|
|
|
|
format->type = ptr[0];
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900-60931,60933-60958 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60901 | eric.smith | 2008-02-19 14:21:56 +0100 (Tue, 19 Feb 2008) | 1 line
Added PEP 3101.
........
r60907 | georg.brandl | 2008-02-20 20:12:36 +0100 (Wed, 20 Feb 2008) | 2 lines
Fixes contributed by Ori Avtalion.
........
r60909 | eric.smith | 2008-02-21 00:34:22 +0100 (Thu, 21 Feb 2008) | 1 line
Trim leading zeros from a floating point exponent, per C99. See issue 1600. As far as I know, this only affects Windows. Add float type 'n' to PyOS_ascii_formatd (see PEP 3101 for 'n' description).
........
r60910 | eric.smith | 2008-02-21 00:39:28 +0100 (Thu, 21 Feb 2008) | 1 line
Now that PyOS_ascii_formatd supports the 'n' format, simplify the float formatting code to just call it.
........
r60918 | andrew.kuchling | 2008-02-21 15:23:38 +0100 (Thu, 21 Feb 2008) | 2 lines
Close manifest file.
This change doesn't make any difference to CPython, but is a necessary fix for Jython.
........
r60921 | guido.van.rossum | 2008-02-21 18:46:16 +0100 (Thu, 21 Feb 2008) | 2 lines
Remove news about float repr() -- issue 1580 is still in limbo.
........
r60923 | guido.van.rossum | 2008-02-21 19:18:37 +0100 (Thu, 21 Feb 2008) | 5 lines
Removed uses of dict.has_key() from distutils, and uses of
callable() from copy_reg.py, so the interpreter now starts up
without warnings when '-3' is given. More work like this needs to
be done in the rest of the stdlib.
........
r60924 | thomas.heller | 2008-02-21 19:28:48 +0100 (Thu, 21 Feb 2008) | 4 lines
configure.ac: Remove the configure check for _Bool, it is already done in the
top-level Python configure script.
configure, fficonfig.h.in: regenerated.
........
r60925 | thomas.heller | 2008-02-21 19:52:20 +0100 (Thu, 21 Feb 2008) | 3 lines
Replace 'has_key()' with 'in'.
Replace 'raise Error, stuff' with 'raise Error(stuff)'.
........
r60927 | raymond.hettinger | 2008-02-21 20:24:53 +0100 (Thu, 21 Feb 2008) | 1 line
Update more instances of has_key().
........
r60928 | guido.van.rossum | 2008-02-21 20:46:35 +0100 (Thu, 21 Feb 2008) | 3 lines
Fix a few typos and layout glitches (more work is needed).
Move 2.5 news to Misc/HISTORY.
........
r60936 | georg.brandl | 2008-02-21 21:33:38 +0100 (Thu, 21 Feb 2008) | 2 lines
#2079: typo in userdict docs.
........
r60938 | georg.brandl | 2008-02-21 21:38:13 +0100 (Thu, 21 Feb 2008) | 2 lines
Part of #2154: minimal syntax fixes in doc example snippets.
........
r60942 | raymond.hettinger | 2008-02-22 04:16:42 +0100 (Fri, 22 Feb 2008) | 1 line
First draft for itertools.product(). Docs and other updates forthcoming.
........
r60955 | nick.coghlan | 2008-02-22 11:54:06 +0100 (Fri, 22 Feb 2008) | 1 line
Try to make command line error messages from runpy easier to understand (and suppress traceback cruft from the implicitly invoked runpy machinery)
........
r60956 | georg.brandl | 2008-02-22 13:31:45 +0100 (Fri, 22 Feb 2008) | 2 lines
A lot more typo fixes by Ori Avtalion.
........
r60957 | georg.brandl | 2008-02-22 13:56:34 +0100 (Fri, 22 Feb 2008) | 2 lines
Don't reference pyshell.
........
r60958 | georg.brandl | 2008-02-22 13:57:05 +0100 (Fri, 22 Feb 2008) | 2 lines
Another fix.
........
2008-02-22 12:37:40 -04:00
|
|
|
++ptr;
|
2007-08-24 23:26:07 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-02-17 15:48:00 -04:00
|
|
|
#if defined FORMAT_FLOAT || defined FORMAT_LONG
|
2007-08-24 23:26:07 -03:00
|
|
|
/************************************************************************/
|
|
|
|
/*********** common routines for numeric formatting *********************/
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
/* describes the layout for an integer, see the comment in
|
2008-07-15 21:15:35 -03:00
|
|
|
calc_number_widths() for details */
|
2007-08-24 23:26:07 -03:00
|
|
|
typedef struct {
|
|
|
|
Py_ssize_t n_lpadding;
|
2008-07-15 21:15:35 -03:00
|
|
|
Py_ssize_t n_prefix;
|
2007-08-24 23:26:07 -03:00
|
|
|
Py_ssize_t n_spadding;
|
|
|
|
Py_ssize_t n_rpadding;
|
|
|
|
char lsign;
|
|
|
|
Py_ssize_t n_lsign;
|
|
|
|
char rsign;
|
|
|
|
Py_ssize_t n_rsign;
|
|
|
|
Py_ssize_t n_total; /* just a convenience, it's derivable from the
|
|
|
|
other fields */
|
|
|
|
} NumberFieldWidths;
|
|
|
|
|
|
|
|
/* not all fields of format are used. for example, precision is
|
|
|
|
unused. should this take discrete params in order to be more clear
|
|
|
|
about what it does? or is passing a single format parameter easier
|
|
|
|
and more efficient enough to justify a little obfuscation? */
|
|
|
|
static void
|
2008-07-16 16:41:14 -03:00
|
|
|
calc_number_widths(NumberFieldWidths *spec, STRINGLIB_CHAR actual_sign,
|
2008-07-15 10:02:41 -03:00
|
|
|
Py_ssize_t n_prefix, Py_ssize_t n_digits,
|
|
|
|
const InternalFormatSpec *format)
|
2007-08-24 23:26:07 -03:00
|
|
|
{
|
2008-07-16 16:41:14 -03:00
|
|
|
spec->n_lpadding = 0;
|
|
|
|
spec->n_prefix = 0;
|
|
|
|
spec->n_spadding = 0;
|
|
|
|
spec->n_rpadding = 0;
|
|
|
|
spec->lsign = '\0';
|
|
|
|
spec->n_lsign = 0;
|
|
|
|
spec->rsign = '\0';
|
|
|
|
spec->n_rsign = 0;
|
2007-08-24 23:26:07 -03:00
|
|
|
|
|
|
|
/* the output will look like:
|
2008-07-15 10:02:41 -03:00
|
|
|
| |
|
|
|
|
| <lpadding> <lsign> <prefix> <spadding> <digits> <rsign> <rpadding> |
|
|
|
|
| |
|
2007-08-24 23:26:07 -03:00
|
|
|
|
|
|
|
lsign and rsign are computed from format->sign and the actual
|
|
|
|
sign of the number
|
|
|
|
|
2008-07-15 10:02:41 -03:00
|
|
|
prefix is given (it's for the '0x' prefix)
|
|
|
|
|
2007-08-24 23:26:07 -03:00
|
|
|
digits is already known
|
|
|
|
|
|
|
|
the total width is either given, or computed from the
|
|
|
|
actual digits
|
|
|
|
|
|
|
|
only one of lpadding, spadding, and rpadding can be non-zero,
|
|
|
|
and it's calculated from the width and other fields
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* compute the various parts we're going to write */
|
|
|
|
if (format->sign == '+') {
|
|
|
|
/* always put a + or - */
|
2008-07-16 16:41:14 -03:00
|
|
|
spec->n_lsign = 1;
|
|
|
|
spec->lsign = (actual_sign == '-' ? '-' : '+');
|
2007-08-27 22:07:27 -03:00
|
|
|
}
|
2007-08-29 09:38:45 -03:00
|
|
|
#if ALLOW_PARENS_FOR_SIGN
|
2007-08-27 22:07:27 -03:00
|
|
|
else if (format->sign == '(') {
|
2007-08-24 23:26:07 -03:00
|
|
|
if (actual_sign == '-') {
|
2008-07-16 16:41:14 -03:00
|
|
|
spec->n_lsign = 1;
|
|
|
|
spec->lsign = '(';
|
|
|
|
spec->n_rsign = 1;
|
|
|
|
spec->rsign = ')';
|
2007-08-24 23:26:07 -03:00
|
|
|
}
|
2007-08-27 22:07:27 -03:00
|
|
|
}
|
2007-08-29 09:38:45 -03:00
|
|
|
#endif
|
2007-08-27 22:07:27 -03:00
|
|
|
else if (format->sign == ' ') {
|
2008-07-16 16:41:14 -03:00
|
|
|
spec->n_lsign = 1;
|
|
|
|
spec->lsign = (actual_sign == '-' ? '-' : ' ');
|
2007-08-27 22:07:27 -03:00
|
|
|
}
|
|
|
|
else {
|
2007-08-24 23:26:07 -03:00
|
|
|
/* non specified, or the default (-) */
|
|
|
|
if (actual_sign == '-') {
|
2008-07-16 16:41:14 -03:00
|
|
|
spec->n_lsign = 1;
|
|
|
|
spec->lsign = '-';
|
2007-08-24 23:26:07 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-16 16:41:14 -03:00
|
|
|
spec->n_prefix = n_prefix;
|
2008-07-15 21:15:35 -03:00
|
|
|
|
2007-08-24 23:26:07 -03:00
|
|
|
/* now the number of padding characters */
|
|
|
|
if (format->width == -1) {
|
|
|
|
/* no padding at all, nothing to do */
|
2007-08-27 22:07:27 -03:00
|
|
|
}
|
|
|
|
else {
|
2007-08-24 23:26:07 -03:00
|
|
|
/* see if any padding is needed */
|
2008-07-16 16:41:14 -03:00
|
|
|
if (spec->n_lsign + n_digits + spec->n_rsign +
|
|
|
|
spec->n_prefix >= format->width) {
|
2007-08-24 23:26:07 -03:00
|
|
|
/* no padding needed, we're already bigger than the
|
|
|
|
requested width */
|
2007-08-27 22:07:27 -03:00
|
|
|
}
|
|
|
|
else {
|
2007-08-24 23:26:07 -03:00
|
|
|
/* determine which of left, space, or right padding is
|
|
|
|
needed */
|
2008-02-17 15:48:00 -04:00
|
|
|
Py_ssize_t padding = format->width -
|
2008-07-16 16:41:14 -03:00
|
|
|
(spec->n_lsign + spec->n_prefix +
|
|
|
|
n_digits + spec->n_rsign);
|
2007-08-24 23:26:07 -03:00
|
|
|
if (format->align == '<')
|
2008-07-16 16:41:14 -03:00
|
|
|
spec->n_rpadding = padding;
|
2007-08-24 23:26:07 -03:00
|
|
|
else if (format->align == '>')
|
2008-07-16 16:41:14 -03:00
|
|
|
spec->n_lpadding = padding;
|
2007-08-24 23:26:07 -03:00
|
|
|
else if (format->align == '^') {
|
2008-07-16 16:41:14 -03:00
|
|
|
spec->n_lpadding = padding / 2;
|
|
|
|
spec->n_rpadding = padding - spec->n_lpadding;
|
2007-08-27 22:07:27 -03:00
|
|
|
}
|
2007-08-30 19:23:08 -03:00
|
|
|
else if (format->align == '=')
|
2008-07-16 16:41:14 -03:00
|
|
|
spec->n_spadding = padding;
|
2007-08-30 19:23:08 -03:00
|
|
|
else
|
2008-07-16 16:41:14 -03:00
|
|
|
spec->n_lpadding = padding;
|
2007-08-24 23:26:07 -03:00
|
|
|
}
|
|
|
|
}
|
2008-07-16 16:41:14 -03:00
|
|
|
spec->n_total = spec->n_lpadding + spec->n_lsign + spec->n_prefix +
|
|
|
|
spec->n_spadding + n_digits + spec->n_rsign + spec->n_rpadding;
|
2007-08-24 23:26:07 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* fill in the non-digit parts of a numbers's string representation,
|
2008-07-15 21:15:35 -03:00
|
|
|
as determined in calc_number_widths(). returns the pointer to
|
2007-08-24 23:26:07 -03:00
|
|
|
where the digits go. */
|
|
|
|
static STRINGLIB_CHAR *
|
2008-06-24 08:21:04 -03:00
|
|
|
fill_non_digits(STRINGLIB_CHAR *p_buf, const NumberFieldWidths *spec,
|
2008-07-15 21:15:35 -03:00
|
|
|
STRINGLIB_CHAR *prefix, Py_ssize_t n_digits,
|
|
|
|
STRINGLIB_CHAR fill_char)
|
2007-08-24 23:26:07 -03:00
|
|
|
{
|
2008-07-15 21:15:35 -03:00
|
|
|
STRINGLIB_CHAR *p_digits;
|
2007-08-24 23:26:07 -03:00
|
|
|
|
|
|
|
if (spec->n_lpadding) {
|
|
|
|
STRINGLIB_FILL(p_buf, fill_char, spec->n_lpadding);
|
|
|
|
p_buf += spec->n_lpadding;
|
|
|
|
}
|
|
|
|
if (spec->n_lsign == 1) {
|
|
|
|
*p_buf++ = spec->lsign;
|
|
|
|
}
|
2008-07-15 21:15:35 -03:00
|
|
|
if (spec->n_prefix) {
|
|
|
|
memmove(p_buf,
|
|
|
|
prefix,
|
|
|
|
spec->n_prefix * sizeof(STRINGLIB_CHAR));
|
|
|
|
p_buf += spec->n_prefix;
|
|
|
|
}
|
2007-08-24 23:26:07 -03:00
|
|
|
if (spec->n_spadding) {
|
|
|
|
STRINGLIB_FILL(p_buf, fill_char, spec->n_spadding);
|
|
|
|
p_buf += spec->n_spadding;
|
|
|
|
}
|
|
|
|
p_digits = p_buf;
|
|
|
|
p_buf += n_digits;
|
|
|
|
if (spec->n_rsign == 1) {
|
|
|
|
*p_buf++ = spec->rsign;
|
|
|
|
}
|
|
|
|
if (spec->n_rpadding) {
|
|
|
|
STRINGLIB_FILL(p_buf, fill_char, spec->n_rpadding);
|
|
|
|
p_buf += spec->n_rpadding;
|
|
|
|
}
|
|
|
|
return p_digits;
|
|
|
|
}
|
2008-02-17 15:48:00 -04:00
|
|
|
#endif /* FORMAT_FLOAT || FORMAT_LONG */
|
2007-08-24 23:26:07 -03:00
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/*********** string formatting ******************************************/
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
format_string_internal(PyObject *value, const InternalFormatSpec *format)
|
|
|
|
{
|
|
|
|
Py_ssize_t width; /* total field width */
|
|
|
|
Py_ssize_t lpad;
|
|
|
|
STRINGLIB_CHAR *dst;
|
|
|
|
STRINGLIB_CHAR *src = STRINGLIB_STR(value);
|
|
|
|
Py_ssize_t len = STRINGLIB_LEN(value);
|
|
|
|
PyObject *result = NULL;
|
|
|
|
|
|
|
|
/* sign is not allowed on strings */
|
|
|
|
if (format->sign != '\0') {
|
|
|
|
PyErr_SetString(PyExc_ValueError,
|
|
|
|
"Sign not allowed in string format specifier");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2008-07-15 10:02:41 -03:00
|
|
|
/* alternate is not allowed on strings */
|
|
|
|
if (format->alternate) {
|
|
|
|
PyErr_SetString(PyExc_ValueError,
|
|
|
|
"Alternate form (#) not allowed in string format "
|
|
|
|
"specifier");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2007-08-24 23:26:07 -03:00
|
|
|
/* '=' alignment not allowed on strings */
|
|
|
|
if (format->align == '=') {
|
|
|
|
PyErr_SetString(PyExc_ValueError,
|
|
|
|
"'=' alignment not allowed "
|
|
|
|
"in string format specifier");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if precision is specified, output no more that format.precision
|
|
|
|
characters */
|
|
|
|
if (format->precision >= 0 && len >= format->precision) {
|
|
|
|
len = format->precision;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (format->width >= 0) {
|
|
|
|
width = format->width;
|
|
|
|
|
|
|
|
/* but use at least len characters */
|
|
|
|
if (len > width) {
|
|
|
|
width = len;
|
|
|
|
}
|
2007-08-27 22:07:27 -03:00
|
|
|
}
|
|
|
|
else {
|
2007-08-24 23:26:07 -03:00
|
|
|
/* not specified, use all of the chars and no more */
|
|
|
|
width = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate the resulting string */
|
|
|
|
result = STRINGLIB_NEW(NULL, width);
|
|
|
|
if (result == NULL)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* now write into that space */
|
|
|
|
dst = STRINGLIB_STR(result);
|
|
|
|
|
|
|
|
/* figure out how much leading space we need, based on the
|
|
|
|
aligning */
|
|
|
|
if (format->align == '>')
|
|
|
|
lpad = width - len;
|
|
|
|
else if (format->align == '^')
|
|
|
|
lpad = (width - len) / 2;
|
|
|
|
else
|
|
|
|
lpad = 0;
|
|
|
|
|
|
|
|
/* if right aligning, increment the destination allow space on the
|
|
|
|
left */
|
|
|
|
memcpy(dst + lpad, src, len * sizeof(STRINGLIB_CHAR));
|
|
|
|
|
|
|
|
/* do any padding */
|
|
|
|
if (width > len) {
|
|
|
|
STRINGLIB_CHAR fill_char = format->fill_char;
|
|
|
|
if (fill_char == '\0') {
|
|
|
|
/* use the default, if not specified */
|
|
|
|
fill_char = ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
/* pad on left */
|
|
|
|
if (lpad)
|
|
|
|
STRINGLIB_FILL(dst, fill_char, lpad);
|
|
|
|
|
|
|
|
/* pad on right */
|
|
|
|
if (width - len - lpad)
|
|
|
|
STRINGLIB_FILL(dst + len + lpad, fill_char, width - len - lpad);
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/*********** long formatting ********************************************/
|
|
|
|
/************************************************************************/
|
|
|
|
|
2008-02-17 15:48:00 -04:00
|
|
|
#if defined FORMAT_LONG || defined FORMAT_INT
|
|
|
|
typedef PyObject*
|
|
|
|
(*IntOrLongToString)(PyObject *value, int base);
|
|
|
|
|
2007-08-24 23:26:07 -03:00
|
|
|
static PyObject *
|
2008-02-17 15:48:00 -04:00
|
|
|
format_int_or_long_internal(PyObject *value, const InternalFormatSpec *format,
|
|
|
|
IntOrLongToString tostring)
|
2007-08-24 23:26:07 -03:00
|
|
|
{
|
|
|
|
PyObject *result = NULL;
|
2008-02-17 15:48:00 -04:00
|
|
|
PyObject *tmp = NULL;
|
|
|
|
STRINGLIB_CHAR *pnumeric_chars;
|
|
|
|
STRINGLIB_CHAR numeric_char;
|
2007-08-24 23:26:07 -03:00
|
|
|
STRINGLIB_CHAR sign = '\0';
|
|
|
|
STRINGLIB_CHAR *p;
|
|
|
|
Py_ssize_t n_digits; /* count of digits need from the computed
|
|
|
|
string */
|
2008-02-17 15:48:00 -04:00
|
|
|
Py_ssize_t n_leading_chars;
|
Merged revisions 63078 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
When forward porting this, I added _PyUnicode_InsertThousandsGrouping.
........
r63078 | eric.smith | 2008-05-11 15:52:48 -0400 (Sun, 11 May 2008) | 14 lines
Addresses issue 2802: 'n' formatting for integers.
Adds 'n' as a format specifier for integers, to mirror the same
specifier which is already available for floats. 'n' is the same as
'd', but inserts the current locale-specific thousands grouping.
I added this as a stringlib function, but it's only used by str type,
not unicode. This is because of an implementation detail in
unicode.format(), which does its own str->unicode conversion. But the
unicode version will be needed in 3.0, and it may be needed by other
code eventually in 2.6 (maybe decimal?), so I left it as a stringlib
implementation. As long as the unicode version isn't instantiated,
there's no overhead for this.
........
2008-05-11 18:00:57 -03:00
|
|
|
Py_ssize_t n_grouping_chars = 0; /* Count of additional chars to
|
|
|
|
allocate, used for 'n'
|
|
|
|
formatting. */
|
2008-07-15 21:15:35 -03:00
|
|
|
Py_ssize_t n_prefix = 0; /* Count of prefix chars, (e.g., '0x') */
|
|
|
|
STRINGLIB_CHAR *prefix = NULL;
|
2007-08-24 23:26:07 -03:00
|
|
|
NumberFieldWidths spec;
|
|
|
|
long x;
|
|
|
|
|
|
|
|
/* no precision allowed on integers */
|
|
|
|
if (format->precision != -1) {
|
|
|
|
PyErr_SetString(PyExc_ValueError,
|
|
|
|
"Precision not allowed in integer format specifier");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* special case for character formatting */
|
|
|
|
if (format->type == 'c') {
|
|
|
|
/* error to specify a sign */
|
|
|
|
if (format->sign != '\0') {
|
|
|
|
PyErr_SetString(PyExc_ValueError,
|
|
|
|
"Sign not allowed with integer"
|
|
|
|
" format specifier 'c'");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* taken from unicodeobject.c formatchar() */
|
|
|
|
/* Integer input truncated to a character */
|
2008-02-17 15:48:00 -04:00
|
|
|
/* XXX: won't work for int */
|
2007-12-02 10:31:20 -04:00
|
|
|
x = PyLong_AsLong(value);
|
2007-08-24 23:26:07 -03:00
|
|
|
if (x == -1 && PyErr_Occurred())
|
|
|
|
goto done;
|
|
|
|
#ifdef Py_UNICODE_WIDE
|
|
|
|
if (x < 0 || x > 0x10ffff) {
|
|
|
|
PyErr_SetString(PyExc_OverflowError,
|
|
|
|
"%c arg not in range(0x110000) "
|
|
|
|
"(wide Python build)");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (x < 0 || x > 0xffff) {
|
|
|
|
PyErr_SetString(PyExc_OverflowError,
|
|
|
|
"%c arg not in range(0x10000) "
|
|
|
|
"(narrow Python build)");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
#endif
|
2008-02-17 15:48:00 -04:00
|
|
|
numeric_char = (STRINGLIB_CHAR)x;
|
|
|
|
pnumeric_chars = &numeric_char;
|
|
|
|
n_digits = 1;
|
2007-08-27 22:07:27 -03:00
|
|
|
}
|
|
|
|
else {
|
2007-08-24 23:26:07 -03:00
|
|
|
int base;
|
2008-07-15 10:02:41 -03:00
|
|
|
int leading_chars_to_skip = 0; /* Number of characters added by
|
|
|
|
PyNumber_ToBase that we want to
|
|
|
|
skip over. */
|
2008-02-17 15:48:00 -04:00
|
|
|
|
|
|
|
/* Compute the base and how many characters will be added by
|
2007-08-24 23:26:07 -03:00
|
|
|
PyNumber_ToBase */
|
|
|
|
switch (format->type) {
|
|
|
|
case 'b':
|
|
|
|
base = 2;
|
2008-07-15 21:15:35 -03:00
|
|
|
leading_chars_to_skip = 2; /* 0b */
|
2007-08-24 23:26:07 -03:00
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
base = 8;
|
2008-07-15 21:15:35 -03:00
|
|
|
leading_chars_to_skip = 2; /* 0o */
|
2007-08-24 23:26:07 -03:00
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
case 'X':
|
|
|
|
base = 16;
|
2008-07-15 21:15:35 -03:00
|
|
|
leading_chars_to_skip = 2; /* 0x */
|
2007-08-24 23:26:07 -03:00
|
|
|
break;
|
|
|
|
default: /* shouldn't be needed, but stops a compiler warning */
|
|
|
|
case 'd':
|
Merged revisions 63078 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
When forward porting this, I added _PyUnicode_InsertThousandsGrouping.
........
r63078 | eric.smith | 2008-05-11 15:52:48 -0400 (Sun, 11 May 2008) | 14 lines
Addresses issue 2802: 'n' formatting for integers.
Adds 'n' as a format specifier for integers, to mirror the same
specifier which is already available for floats. 'n' is the same as
'd', but inserts the current locale-specific thousands grouping.
I added this as a stringlib function, but it's only used by str type,
not unicode. This is because of an implementation detail in
unicode.format(), which does its own str->unicode conversion. But the
unicode version will be needed in 3.0, and it may be needed by other
code eventually in 2.6 (maybe decimal?), so I left it as a stringlib
implementation. As long as the unicode version isn't instantiated,
there's no overhead for this.
........
2008-05-11 18:00:57 -03:00
|
|
|
case 'n':
|
2007-08-24 23:26:07 -03:00
|
|
|
base = 10;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-07-15 21:15:35 -03:00
|
|
|
/* The number of prefix chars is the same as the leading
|
|
|
|
chars to skip */
|
|
|
|
if (format->alternate)
|
|
|
|
n_prefix = leading_chars_to_skip;
|
|
|
|
|
2008-02-17 15:48:00 -04:00
|
|
|
/* Do the hard part, converting to a string in a given base */
|
|
|
|
tmp = tostring(value, base);
|
|
|
|
if (tmp == NULL)
|
2007-08-24 23:26:07 -03:00
|
|
|
goto done;
|
|
|
|
|
2008-02-17 15:48:00 -04:00
|
|
|
pnumeric_chars = STRINGLIB_STR(tmp);
|
|
|
|
n_digits = STRINGLIB_LEN(tmp);
|
2007-08-24 23:26:07 -03:00
|
|
|
|
2008-07-15 21:15:35 -03:00
|
|
|
prefix = pnumeric_chars;
|
|
|
|
|
2008-02-17 15:48:00 -04:00
|
|
|
/* Remember not to modify what pnumeric_chars points to. it
|
|
|
|
might be interned. Only modify it after we copy it into a
|
|
|
|
newly allocated output buffer. */
|
2007-08-24 23:26:07 -03:00
|
|
|
|
2008-02-17 15:48:00 -04:00
|
|
|
/* Is a sign character present in the output? If so, remember it
|
2007-08-24 23:26:07 -03:00
|
|
|
and skip it */
|
2008-02-17 15:48:00 -04:00
|
|
|
sign = pnumeric_chars[0];
|
2007-08-24 23:26:07 -03:00
|
|
|
if (sign == '-') {
|
2008-07-15 21:15:35 -03:00
|
|
|
++prefix;
|
2008-02-17 15:48:00 -04:00
|
|
|
++leading_chars_to_skip;
|
2007-08-24 23:26:07 -03:00
|
|
|
}
|
|
|
|
|
2008-02-17 15:48:00 -04:00
|
|
|
/* Skip over the leading chars (0x, 0b, etc.) */
|
|
|
|
n_digits -= leading_chars_to_skip;
|
|
|
|
pnumeric_chars += leading_chars_to_skip;
|
2007-08-24 23:26:07 -03:00
|
|
|
}
|
|
|
|
|
Merged revisions 63078 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
When forward porting this, I added _PyUnicode_InsertThousandsGrouping.
........
r63078 | eric.smith | 2008-05-11 15:52:48 -0400 (Sun, 11 May 2008) | 14 lines
Addresses issue 2802: 'n' formatting for integers.
Adds 'n' as a format specifier for integers, to mirror the same
specifier which is already available for floats. 'n' is the same as
'd', but inserts the current locale-specific thousands grouping.
I added this as a stringlib function, but it's only used by str type,
not unicode. This is because of an implementation detail in
unicode.format(), which does its own str->unicode conversion. But the
unicode version will be needed in 3.0, and it may be needed by other
code eventually in 2.6 (maybe decimal?), so I left it as a stringlib
implementation. As long as the unicode version isn't instantiated,
there's no overhead for this.
........
2008-05-11 18:00:57 -03:00
|
|
|
if (format->type == 'n')
|
|
|
|
/* Compute how many additional chars we need to allocate
|
|
|
|
to hold the thousands grouping. */
|
2008-06-23 22:06:47 -03:00
|
|
|
STRINGLIB_GROUPING(NULL, n_digits, n_digits,
|
Merged revisions 63078 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
When forward porting this, I added _PyUnicode_InsertThousandsGrouping.
........
r63078 | eric.smith | 2008-05-11 15:52:48 -0400 (Sun, 11 May 2008) | 14 lines
Addresses issue 2802: 'n' formatting for integers.
Adds 'n' as a format specifier for integers, to mirror the same
specifier which is already available for floats. 'n' is the same as
'd', but inserts the current locale-specific thousands grouping.
I added this as a stringlib function, but it's only used by str type,
not unicode. This is because of an implementation detail in
unicode.format(), which does its own str->unicode conversion. But the
unicode version will be needed in 3.0, and it may be needed by other
code eventually in 2.6 (maybe decimal?), so I left it as a stringlib
implementation. As long as the unicode version isn't instantiated,
there's no overhead for this.
........
2008-05-11 18:00:57 -03:00
|
|
|
0, &n_grouping_chars, 0);
|
|
|
|
|
2008-06-24 08:21:04 -03:00
|
|
|
/* Calculate the widths of the various leading and trailing parts */
|
2008-07-15 21:15:35 -03:00
|
|
|
calc_number_widths(&spec, sign, n_prefix, n_digits + n_grouping_chars,
|
|
|
|
format);
|
2008-06-24 08:21:04 -03:00
|
|
|
|
2008-02-17 15:48:00 -04:00
|
|
|
/* Allocate a new string to hold the result */
|
2008-06-24 08:21:04 -03:00
|
|
|
result = STRINGLIB_NEW(NULL, spec.n_total);
|
2008-02-17 15:48:00 -04:00
|
|
|
if (!result)
|
|
|
|
goto done;
|
|
|
|
p = STRINGLIB_STR(result);
|
2007-08-24 23:26:07 -03:00
|
|
|
|
2008-07-15 21:15:35 -03:00
|
|
|
/* XXX There is too much magic here regarding the internals of
|
|
|
|
spec and the location of the prefix and digits. It would be
|
|
|
|
better if calc_number_widths returned a number of logical
|
|
|
|
offsets into the buffer, and those were used. Maybe in a
|
|
|
|
future code cleanup. */
|
|
|
|
|
2008-02-17 15:48:00 -04:00
|
|
|
/* Fill in the digit parts */
|
2008-07-15 21:15:35 -03:00
|
|
|
n_leading_chars = spec.n_lpadding + spec.n_lsign +
|
|
|
|
spec.n_prefix + spec.n_spadding;
|
2008-02-17 15:48:00 -04:00
|
|
|
memmove(p + n_leading_chars,
|
|
|
|
pnumeric_chars,
|
|
|
|
n_digits * sizeof(STRINGLIB_CHAR));
|
2007-08-24 23:26:07 -03:00
|
|
|
|
2008-07-15 21:15:35 -03:00
|
|
|
/* If type is 'X', convert the filled in digits to uppercase */
|
2008-02-17 15:48:00 -04:00
|
|
|
if (format->type == 'X') {
|
|
|
|
Py_ssize_t t;
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900-60931,60933-60958 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60901 | eric.smith | 2008-02-19 14:21:56 +0100 (Tue, 19 Feb 2008) | 1 line
Added PEP 3101.
........
r60907 | georg.brandl | 2008-02-20 20:12:36 +0100 (Wed, 20 Feb 2008) | 2 lines
Fixes contributed by Ori Avtalion.
........
r60909 | eric.smith | 2008-02-21 00:34:22 +0100 (Thu, 21 Feb 2008) | 1 line
Trim leading zeros from a floating point exponent, per C99. See issue 1600. As far as I know, this only affects Windows. Add float type 'n' to PyOS_ascii_formatd (see PEP 3101 for 'n' description).
........
r60910 | eric.smith | 2008-02-21 00:39:28 +0100 (Thu, 21 Feb 2008) | 1 line
Now that PyOS_ascii_formatd supports the 'n' format, simplify the float formatting code to just call it.
........
r60918 | andrew.kuchling | 2008-02-21 15:23:38 +0100 (Thu, 21 Feb 2008) | 2 lines
Close manifest file.
This change doesn't make any difference to CPython, but is a necessary fix for Jython.
........
r60921 | guido.van.rossum | 2008-02-21 18:46:16 +0100 (Thu, 21 Feb 2008) | 2 lines
Remove news about float repr() -- issue 1580 is still in limbo.
........
r60923 | guido.van.rossum | 2008-02-21 19:18:37 +0100 (Thu, 21 Feb 2008) | 5 lines
Removed uses of dict.has_key() from distutils, and uses of
callable() from copy_reg.py, so the interpreter now starts up
without warnings when '-3' is given. More work like this needs to
be done in the rest of the stdlib.
........
r60924 | thomas.heller | 2008-02-21 19:28:48 +0100 (Thu, 21 Feb 2008) | 4 lines
configure.ac: Remove the configure check for _Bool, it is already done in the
top-level Python configure script.
configure, fficonfig.h.in: regenerated.
........
r60925 | thomas.heller | 2008-02-21 19:52:20 +0100 (Thu, 21 Feb 2008) | 3 lines
Replace 'has_key()' with 'in'.
Replace 'raise Error, stuff' with 'raise Error(stuff)'.
........
r60927 | raymond.hettinger | 2008-02-21 20:24:53 +0100 (Thu, 21 Feb 2008) | 1 line
Update more instances of has_key().
........
r60928 | guido.van.rossum | 2008-02-21 20:46:35 +0100 (Thu, 21 Feb 2008) | 3 lines
Fix a few typos and layout glitches (more work is needed).
Move 2.5 news to Misc/HISTORY.
........
r60936 | georg.brandl | 2008-02-21 21:33:38 +0100 (Thu, 21 Feb 2008) | 2 lines
#2079: typo in userdict docs.
........
r60938 | georg.brandl | 2008-02-21 21:38:13 +0100 (Thu, 21 Feb 2008) | 2 lines
Part of #2154: minimal syntax fixes in doc example snippets.
........
r60942 | raymond.hettinger | 2008-02-22 04:16:42 +0100 (Fri, 22 Feb 2008) | 1 line
First draft for itertools.product(). Docs and other updates forthcoming.
........
r60955 | nick.coghlan | 2008-02-22 11:54:06 +0100 (Fri, 22 Feb 2008) | 1 line
Try to make command line error messages from runpy easier to understand (and suppress traceback cruft from the implicitly invoked runpy machinery)
........
r60956 | georg.brandl | 2008-02-22 13:31:45 +0100 (Fri, 22 Feb 2008) | 2 lines
A lot more typo fixes by Ori Avtalion.
........
r60957 | georg.brandl | 2008-02-22 13:56:34 +0100 (Fri, 22 Feb 2008) | 2 lines
Don't reference pyshell.
........
r60958 | georg.brandl | 2008-02-22 13:57:05 +0100 (Fri, 22 Feb 2008) | 2 lines
Another fix.
........
2008-02-22 12:37:40 -04:00
|
|
|
for (t = 0; t < n_digits; ++t)
|
2008-02-17 15:48:00 -04:00
|
|
|
p[t + n_leading_chars] = STRINGLIB_TOUPPER(p[t + n_leading_chars]);
|
2007-08-24 23:26:07 -03:00
|
|
|
}
|
|
|
|
|
2008-07-15 21:15:35 -03:00
|
|
|
/* Insert the grouping, if any, after the uppercasing of the digits, so
|
|
|
|
we can ensure that grouping chars won't be affected. */
|
2008-06-24 08:21:04 -03:00
|
|
|
if (n_grouping_chars) {
|
Merged revisions 63078 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
When forward porting this, I added _PyUnicode_InsertThousandsGrouping.
........
r63078 | eric.smith | 2008-05-11 15:52:48 -0400 (Sun, 11 May 2008) | 14 lines
Addresses issue 2802: 'n' formatting for integers.
Adds 'n' as a format specifier for integers, to mirror the same
specifier which is already available for floats. 'n' is the same as
'd', but inserts the current locale-specific thousands grouping.
I added this as a stringlib function, but it's only used by str type,
not unicode. This is because of an implementation detail in
unicode.format(), which does its own str->unicode conversion. But the
unicode version will be needed in 3.0, and it may be needed by other
code eventually in 2.6 (maybe decimal?), so I left it as a stringlib
implementation. As long as the unicode version isn't instantiated,
there's no overhead for this.
........
2008-05-11 18:00:57 -03:00
|
|
|
/* We know this can't fail, since we've already
|
|
|
|
reserved enough space. */
|
|
|
|
STRINGLIB_CHAR *pstart = p + n_leading_chars;
|
2008-06-23 22:06:47 -03:00
|
|
|
int r = STRINGLIB_GROUPING(pstart, n_digits, n_digits,
|
2008-07-15 21:15:35 -03:00
|
|
|
spec.n_total+n_grouping_chars-n_leading_chars,
|
|
|
|
NULL, 0);
|
Merged revisions 63078 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
When forward porting this, I added _PyUnicode_InsertThousandsGrouping.
........
r63078 | eric.smith | 2008-05-11 15:52:48 -0400 (Sun, 11 May 2008) | 14 lines
Addresses issue 2802: 'n' formatting for integers.
Adds 'n' as a format specifier for integers, to mirror the same
specifier which is already available for floats. 'n' is the same as
'd', but inserts the current locale-specific thousands grouping.
I added this as a stringlib function, but it's only used by str type,
not unicode. This is because of an implementation detail in
unicode.format(), which does its own str->unicode conversion. But the
unicode version will be needed in 3.0, and it may be needed by other
code eventually in 2.6 (maybe decimal?), so I left it as a stringlib
implementation. As long as the unicode version isn't instantiated,
there's no overhead for this.
........
2008-05-11 18:00:57 -03:00
|
|
|
assert(r);
|
|
|
|
}
|
|
|
|
|
2008-06-24 08:21:04 -03:00
|
|
|
/* Fill in the non-digit parts (padding, sign, etc.) */
|
2008-07-15 21:15:35 -03:00
|
|
|
fill_non_digits(p, &spec, prefix, n_digits + n_grouping_chars,
|
2008-06-24 08:21:04 -03:00
|
|
|
format->fill_char == '\0' ? ' ' : format->fill_char);
|
2007-08-24 23:26:07 -03:00
|
|
|
|
2008-07-15 21:15:35 -03:00
|
|
|
/* If type is 'X', uppercase the prefix. This has to be done after the
|
|
|
|
prefix is filled in by fill_non_digits */
|
|
|
|
if (format->type == 'X') {
|
|
|
|
Py_ssize_t t;
|
|
|
|
for (t = 0; t < n_prefix; ++t)
|
|
|
|
p[t + spec.n_lpadding + spec.n_lsign] =
|
|
|
|
STRINGLIB_TOUPPER(p[t + spec.n_lpadding + spec.n_lsign]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-24 23:26:07 -03:00
|
|
|
done:
|
2008-02-17 15:48:00 -04:00
|
|
|
Py_XDECREF(tmp);
|
2007-08-24 23:26:07 -03:00
|
|
|
return result;
|
|
|
|
}
|
2008-02-17 15:48:00 -04:00
|
|
|
#endif /* defined FORMAT_LONG || defined FORMAT_INT */
|
2007-08-24 23:26:07 -03:00
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/*********** float formatting *******************************************/
|
|
|
|
/************************************************************************/
|
|
|
|
|
2008-02-17 15:48:00 -04:00
|
|
|
#ifdef FORMAT_FLOAT
|
|
|
|
#if STRINGLIB_IS_UNICODE
|
2007-08-24 23:26:07 -03:00
|
|
|
/* taken from unicodeobject.c */
|
|
|
|
static Py_ssize_t
|
|
|
|
strtounicode(Py_UNICODE *buffer, const char *charbuffer)
|
|
|
|
{
|
|
|
|
register Py_ssize_t i;
|
|
|
|
Py_ssize_t len = strlen(charbuffer);
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900-60931,60933-60958 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60901 | eric.smith | 2008-02-19 14:21:56 +0100 (Tue, 19 Feb 2008) | 1 line
Added PEP 3101.
........
r60907 | georg.brandl | 2008-02-20 20:12:36 +0100 (Wed, 20 Feb 2008) | 2 lines
Fixes contributed by Ori Avtalion.
........
r60909 | eric.smith | 2008-02-21 00:34:22 +0100 (Thu, 21 Feb 2008) | 1 line
Trim leading zeros from a floating point exponent, per C99. See issue 1600. As far as I know, this only affects Windows. Add float type 'n' to PyOS_ascii_formatd (see PEP 3101 for 'n' description).
........
r60910 | eric.smith | 2008-02-21 00:39:28 +0100 (Thu, 21 Feb 2008) | 1 line
Now that PyOS_ascii_formatd supports the 'n' format, simplify the float formatting code to just call it.
........
r60918 | andrew.kuchling | 2008-02-21 15:23:38 +0100 (Thu, 21 Feb 2008) | 2 lines
Close manifest file.
This change doesn't make any difference to CPython, but is a necessary fix for Jython.
........
r60921 | guido.van.rossum | 2008-02-21 18:46:16 +0100 (Thu, 21 Feb 2008) | 2 lines
Remove news about float repr() -- issue 1580 is still in limbo.
........
r60923 | guido.van.rossum | 2008-02-21 19:18:37 +0100 (Thu, 21 Feb 2008) | 5 lines
Removed uses of dict.has_key() from distutils, and uses of
callable() from copy_reg.py, so the interpreter now starts up
without warnings when '-3' is given. More work like this needs to
be done in the rest of the stdlib.
........
r60924 | thomas.heller | 2008-02-21 19:28:48 +0100 (Thu, 21 Feb 2008) | 4 lines
configure.ac: Remove the configure check for _Bool, it is already done in the
top-level Python configure script.
configure, fficonfig.h.in: regenerated.
........
r60925 | thomas.heller | 2008-02-21 19:52:20 +0100 (Thu, 21 Feb 2008) | 3 lines
Replace 'has_key()' with 'in'.
Replace 'raise Error, stuff' with 'raise Error(stuff)'.
........
r60927 | raymond.hettinger | 2008-02-21 20:24:53 +0100 (Thu, 21 Feb 2008) | 1 line
Update more instances of has_key().
........
r60928 | guido.van.rossum | 2008-02-21 20:46:35 +0100 (Thu, 21 Feb 2008) | 3 lines
Fix a few typos and layout glitches (more work is needed).
Move 2.5 news to Misc/HISTORY.
........
r60936 | georg.brandl | 2008-02-21 21:33:38 +0100 (Thu, 21 Feb 2008) | 2 lines
#2079: typo in userdict docs.
........
r60938 | georg.brandl | 2008-02-21 21:38:13 +0100 (Thu, 21 Feb 2008) | 2 lines
Part of #2154: minimal syntax fixes in doc example snippets.
........
r60942 | raymond.hettinger | 2008-02-22 04:16:42 +0100 (Fri, 22 Feb 2008) | 1 line
First draft for itertools.product(). Docs and other updates forthcoming.
........
r60955 | nick.coghlan | 2008-02-22 11:54:06 +0100 (Fri, 22 Feb 2008) | 1 line
Try to make command line error messages from runpy easier to understand (and suppress traceback cruft from the implicitly invoked runpy machinery)
........
r60956 | georg.brandl | 2008-02-22 13:31:45 +0100 (Fri, 22 Feb 2008) | 2 lines
A lot more typo fixes by Ori Avtalion.
........
r60957 | georg.brandl | 2008-02-22 13:56:34 +0100 (Fri, 22 Feb 2008) | 2 lines
Don't reference pyshell.
........
r60958 | georg.brandl | 2008-02-22 13:57:05 +0100 (Fri, 22 Feb 2008) | 2 lines
Another fix.
........
2008-02-22 12:37:40 -04:00
|
|
|
for (i = len - 1; i >= 0; --i)
|
2007-08-30 19:23:08 -03:00
|
|
|
buffer[i] = (Py_UNICODE) charbuffer[i];
|
2007-08-24 23:26:07 -03:00
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
2008-02-17 15:48:00 -04:00
|
|
|
#endif
|
2007-08-24 23:26:07 -03:00
|
|
|
|
|
|
|
/* see FORMATBUFLEN in unicodeobject.c */
|
|
|
|
#define FLOAT_FORMATBUFLEN 120
|
|
|
|
|
|
|
|
/* much of this is taken from unicodeobject.c */
|
|
|
|
static PyObject *
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900-60931,60933-60958 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60901 | eric.smith | 2008-02-19 14:21:56 +0100 (Tue, 19 Feb 2008) | 1 line
Added PEP 3101.
........
r60907 | georg.brandl | 2008-02-20 20:12:36 +0100 (Wed, 20 Feb 2008) | 2 lines
Fixes contributed by Ori Avtalion.
........
r60909 | eric.smith | 2008-02-21 00:34:22 +0100 (Thu, 21 Feb 2008) | 1 line
Trim leading zeros from a floating point exponent, per C99. See issue 1600. As far as I know, this only affects Windows. Add float type 'n' to PyOS_ascii_formatd (see PEP 3101 for 'n' description).
........
r60910 | eric.smith | 2008-02-21 00:39:28 +0100 (Thu, 21 Feb 2008) | 1 line
Now that PyOS_ascii_formatd supports the 'n' format, simplify the float formatting code to just call it.
........
r60918 | andrew.kuchling | 2008-02-21 15:23:38 +0100 (Thu, 21 Feb 2008) | 2 lines
Close manifest file.
This change doesn't make any difference to CPython, but is a necessary fix for Jython.
........
r60921 | guido.van.rossum | 2008-02-21 18:46:16 +0100 (Thu, 21 Feb 2008) | 2 lines
Remove news about float repr() -- issue 1580 is still in limbo.
........
r60923 | guido.van.rossum | 2008-02-21 19:18:37 +0100 (Thu, 21 Feb 2008) | 5 lines
Removed uses of dict.has_key() from distutils, and uses of
callable() from copy_reg.py, so the interpreter now starts up
without warnings when '-3' is given. More work like this needs to
be done in the rest of the stdlib.
........
r60924 | thomas.heller | 2008-02-21 19:28:48 +0100 (Thu, 21 Feb 2008) | 4 lines
configure.ac: Remove the configure check for _Bool, it is already done in the
top-level Python configure script.
configure, fficonfig.h.in: regenerated.
........
r60925 | thomas.heller | 2008-02-21 19:52:20 +0100 (Thu, 21 Feb 2008) | 3 lines
Replace 'has_key()' with 'in'.
Replace 'raise Error, stuff' with 'raise Error(stuff)'.
........
r60927 | raymond.hettinger | 2008-02-21 20:24:53 +0100 (Thu, 21 Feb 2008) | 1 line
Update more instances of has_key().
........
r60928 | guido.van.rossum | 2008-02-21 20:46:35 +0100 (Thu, 21 Feb 2008) | 3 lines
Fix a few typos and layout glitches (more work is needed).
Move 2.5 news to Misc/HISTORY.
........
r60936 | georg.brandl | 2008-02-21 21:33:38 +0100 (Thu, 21 Feb 2008) | 2 lines
#2079: typo in userdict docs.
........
r60938 | georg.brandl | 2008-02-21 21:38:13 +0100 (Thu, 21 Feb 2008) | 2 lines
Part of #2154: minimal syntax fixes in doc example snippets.
........
r60942 | raymond.hettinger | 2008-02-22 04:16:42 +0100 (Fri, 22 Feb 2008) | 1 line
First draft for itertools.product(). Docs and other updates forthcoming.
........
r60955 | nick.coghlan | 2008-02-22 11:54:06 +0100 (Fri, 22 Feb 2008) | 1 line
Try to make command line error messages from runpy easier to understand (and suppress traceback cruft from the implicitly invoked runpy machinery)
........
r60956 | georg.brandl | 2008-02-22 13:31:45 +0100 (Fri, 22 Feb 2008) | 2 lines
A lot more typo fixes by Ori Avtalion.
........
r60957 | georg.brandl | 2008-02-22 13:56:34 +0100 (Fri, 22 Feb 2008) | 2 lines
Don't reference pyshell.
........
r60958 | georg.brandl | 2008-02-22 13:57:05 +0100 (Fri, 22 Feb 2008) | 2 lines
Another fix.
........
2008-02-22 12:37:40 -04:00
|
|
|
format_float_internal(PyObject *value,
|
|
|
|
const InternalFormatSpec *format)
|
2007-08-24 23:26:07 -03:00
|
|
|
{
|
|
|
|
/* fmt = '%.' + `prec` + `type` + '%%'
|
|
|
|
worst case length = 2 + 10 (len of INT_MAX) + 1 + 2 = 15 (use 20)*/
|
|
|
|
char fmt[20];
|
|
|
|
|
|
|
|
/* taken from unicodeobject.c */
|
|
|
|
/* Worst case length calc to ensure no buffer overrun:
|
|
|
|
|
|
|
|
'g' formats:
|
2007-08-30 19:23:08 -03:00
|
|
|
fmt = %#.<prec>g
|
|
|
|
buf = '-' + [0-9]*prec + '.' + 'e+' + (longest exp
|
|
|
|
for any double rep.)
|
|
|
|
len = 1 + prec + 1 + 2 + 5 = 9 + prec
|
2007-08-24 23:26:07 -03:00
|
|
|
|
|
|
|
'f' formats:
|
2007-08-30 19:23:08 -03:00
|
|
|
buf = '-' + [0-9]*x + '.' + [0-9]*prec (with x < 50)
|
|
|
|
len = 1 + 50 + 1 + prec = 52 + prec
|
2007-08-24 23:26:07 -03:00
|
|
|
|
|
|
|
If prec=0 the effective precision is 1 (the leading digit is
|
|
|
|
always given), therefore increase the length by one.
|
|
|
|
|
|
|
|
*/
|
|
|
|
char charbuf[FLOAT_FORMATBUFLEN];
|
|
|
|
Py_ssize_t n_digits;
|
|
|
|
double x;
|
|
|
|
Py_ssize_t precision = format->precision;
|
|
|
|
PyObject *result = NULL;
|
|
|
|
STRINGLIB_CHAR sign;
|
|
|
|
char* trailing = "";
|
|
|
|
STRINGLIB_CHAR *p;
|
|
|
|
NumberFieldWidths spec;
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900-60931,60933-60958 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60901 | eric.smith | 2008-02-19 14:21:56 +0100 (Tue, 19 Feb 2008) | 1 line
Added PEP 3101.
........
r60907 | georg.brandl | 2008-02-20 20:12:36 +0100 (Wed, 20 Feb 2008) | 2 lines
Fixes contributed by Ori Avtalion.
........
r60909 | eric.smith | 2008-02-21 00:34:22 +0100 (Thu, 21 Feb 2008) | 1 line
Trim leading zeros from a floating point exponent, per C99. See issue 1600. As far as I know, this only affects Windows. Add float type 'n' to PyOS_ascii_formatd (see PEP 3101 for 'n' description).
........
r60910 | eric.smith | 2008-02-21 00:39:28 +0100 (Thu, 21 Feb 2008) | 1 line
Now that PyOS_ascii_formatd supports the 'n' format, simplify the float formatting code to just call it.
........
r60918 | andrew.kuchling | 2008-02-21 15:23:38 +0100 (Thu, 21 Feb 2008) | 2 lines
Close manifest file.
This change doesn't make any difference to CPython, but is a necessary fix for Jython.
........
r60921 | guido.van.rossum | 2008-02-21 18:46:16 +0100 (Thu, 21 Feb 2008) | 2 lines
Remove news about float repr() -- issue 1580 is still in limbo.
........
r60923 | guido.van.rossum | 2008-02-21 19:18:37 +0100 (Thu, 21 Feb 2008) | 5 lines
Removed uses of dict.has_key() from distutils, and uses of
callable() from copy_reg.py, so the interpreter now starts up
without warnings when '-3' is given. More work like this needs to
be done in the rest of the stdlib.
........
r60924 | thomas.heller | 2008-02-21 19:28:48 +0100 (Thu, 21 Feb 2008) | 4 lines
configure.ac: Remove the configure check for _Bool, it is already done in the
top-level Python configure script.
configure, fficonfig.h.in: regenerated.
........
r60925 | thomas.heller | 2008-02-21 19:52:20 +0100 (Thu, 21 Feb 2008) | 3 lines
Replace 'has_key()' with 'in'.
Replace 'raise Error, stuff' with 'raise Error(stuff)'.
........
r60927 | raymond.hettinger | 2008-02-21 20:24:53 +0100 (Thu, 21 Feb 2008) | 1 line
Update more instances of has_key().
........
r60928 | guido.van.rossum | 2008-02-21 20:46:35 +0100 (Thu, 21 Feb 2008) | 3 lines
Fix a few typos and layout glitches (more work is needed).
Move 2.5 news to Misc/HISTORY.
........
r60936 | georg.brandl | 2008-02-21 21:33:38 +0100 (Thu, 21 Feb 2008) | 2 lines
#2079: typo in userdict docs.
........
r60938 | georg.brandl | 2008-02-21 21:38:13 +0100 (Thu, 21 Feb 2008) | 2 lines
Part of #2154: minimal syntax fixes in doc example snippets.
........
r60942 | raymond.hettinger | 2008-02-22 04:16:42 +0100 (Fri, 22 Feb 2008) | 1 line
First draft for itertools.product(). Docs and other updates forthcoming.
........
r60955 | nick.coghlan | 2008-02-22 11:54:06 +0100 (Fri, 22 Feb 2008) | 1 line
Try to make command line error messages from runpy easier to understand (and suppress traceback cruft from the implicitly invoked runpy machinery)
........
r60956 | georg.brandl | 2008-02-22 13:31:45 +0100 (Fri, 22 Feb 2008) | 2 lines
A lot more typo fixes by Ori Avtalion.
........
r60957 | georg.brandl | 2008-02-22 13:56:34 +0100 (Fri, 22 Feb 2008) | 2 lines
Don't reference pyshell.
........
r60958 | georg.brandl | 2008-02-22 13:57:05 +0100 (Fri, 22 Feb 2008) | 2 lines
Another fix.
........
2008-02-22 12:37:40 -04:00
|
|
|
STRINGLIB_CHAR type = format->type;
|
2007-08-24 23:26:07 -03:00
|
|
|
|
|
|
|
#if STRINGLIB_IS_UNICODE
|
|
|
|
Py_UNICODE unicodebuf[FLOAT_FORMATBUFLEN];
|
|
|
|
#endif
|
|
|
|
|
2008-07-15 10:02:41 -03:00
|
|
|
/* alternate is not allowed on floats. */
|
|
|
|
if (format->alternate) {
|
|
|
|
PyErr_SetString(PyExc_ValueError,
|
|
|
|
"Alternate form (#) not allowed in float format "
|
|
|
|
"specifier");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2007-08-24 23:26:07 -03:00
|
|
|
/* first, do the conversion as 8-bit chars, using the platform's
|
|
|
|
snprintf. then, if needed, convert to unicode. */
|
|
|
|
|
2008-07-17 16:18:29 -03:00
|
|
|
/* 'F' is the same as 'f', per the PEP */
|
|
|
|
if (type == 'F')
|
|
|
|
type = 'f';
|
|
|
|
|
2007-08-24 23:26:07 -03:00
|
|
|
x = PyFloat_AsDouble(value);
|
|
|
|
|
|
|
|
if (x == -1.0 && PyErr_Occurred())
|
2007-08-30 19:23:08 -03:00
|
|
|
goto done;
|
2007-08-24 23:26:07 -03:00
|
|
|
|
|
|
|
if (type == '%') {
|
|
|
|
type = 'f';
|
|
|
|
x *= 100;
|
|
|
|
trailing = "%";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (precision < 0)
|
2007-08-30 19:23:08 -03:00
|
|
|
precision = 6;
|
2008-07-17 16:18:29 -03:00
|
|
|
if (type == 'f' && (fabs(x) / 1e25) >= 1e25)
|
|
|
|
type = 'g';
|
2007-08-24 23:26:07 -03:00
|
|
|
|
|
|
|
/* cast "type", because if we're in unicode we need to pass a
|
|
|
|
8-bit char. this is safe, because we've restricted what "type"
|
|
|
|
can be */
|
2008-02-17 15:48:00 -04:00
|
|
|
PyOS_snprintf(fmt, sizeof(fmt), "%%.%" PY_FORMAT_SIZE_T "d%c", precision,
|
|
|
|
(char)type);
|
2007-08-24 23:26:07 -03:00
|
|
|
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900-60931,60933-60958 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60901 | eric.smith | 2008-02-19 14:21:56 +0100 (Tue, 19 Feb 2008) | 1 line
Added PEP 3101.
........
r60907 | georg.brandl | 2008-02-20 20:12:36 +0100 (Wed, 20 Feb 2008) | 2 lines
Fixes contributed by Ori Avtalion.
........
r60909 | eric.smith | 2008-02-21 00:34:22 +0100 (Thu, 21 Feb 2008) | 1 line
Trim leading zeros from a floating point exponent, per C99. See issue 1600. As far as I know, this only affects Windows. Add float type 'n' to PyOS_ascii_formatd (see PEP 3101 for 'n' description).
........
r60910 | eric.smith | 2008-02-21 00:39:28 +0100 (Thu, 21 Feb 2008) | 1 line
Now that PyOS_ascii_formatd supports the 'n' format, simplify the float formatting code to just call it.
........
r60918 | andrew.kuchling | 2008-02-21 15:23:38 +0100 (Thu, 21 Feb 2008) | 2 lines
Close manifest file.
This change doesn't make any difference to CPython, but is a necessary fix for Jython.
........
r60921 | guido.van.rossum | 2008-02-21 18:46:16 +0100 (Thu, 21 Feb 2008) | 2 lines
Remove news about float repr() -- issue 1580 is still in limbo.
........
r60923 | guido.van.rossum | 2008-02-21 19:18:37 +0100 (Thu, 21 Feb 2008) | 5 lines
Removed uses of dict.has_key() from distutils, and uses of
callable() from copy_reg.py, so the interpreter now starts up
without warnings when '-3' is given. More work like this needs to
be done in the rest of the stdlib.
........
r60924 | thomas.heller | 2008-02-21 19:28:48 +0100 (Thu, 21 Feb 2008) | 4 lines
configure.ac: Remove the configure check for _Bool, it is already done in the
top-level Python configure script.
configure, fficonfig.h.in: regenerated.
........
r60925 | thomas.heller | 2008-02-21 19:52:20 +0100 (Thu, 21 Feb 2008) | 3 lines
Replace 'has_key()' with 'in'.
Replace 'raise Error, stuff' with 'raise Error(stuff)'.
........
r60927 | raymond.hettinger | 2008-02-21 20:24:53 +0100 (Thu, 21 Feb 2008) | 1 line
Update more instances of has_key().
........
r60928 | guido.van.rossum | 2008-02-21 20:46:35 +0100 (Thu, 21 Feb 2008) | 3 lines
Fix a few typos and layout glitches (more work is needed).
Move 2.5 news to Misc/HISTORY.
........
r60936 | georg.brandl | 2008-02-21 21:33:38 +0100 (Thu, 21 Feb 2008) | 2 lines
#2079: typo in userdict docs.
........
r60938 | georg.brandl | 2008-02-21 21:38:13 +0100 (Thu, 21 Feb 2008) | 2 lines
Part of #2154: minimal syntax fixes in doc example snippets.
........
r60942 | raymond.hettinger | 2008-02-22 04:16:42 +0100 (Fri, 22 Feb 2008) | 1 line
First draft for itertools.product(). Docs and other updates forthcoming.
........
r60955 | nick.coghlan | 2008-02-22 11:54:06 +0100 (Fri, 22 Feb 2008) | 1 line
Try to make command line error messages from runpy easier to understand (and suppress traceback cruft from the implicitly invoked runpy machinery)
........
r60956 | georg.brandl | 2008-02-22 13:31:45 +0100 (Fri, 22 Feb 2008) | 2 lines
A lot more typo fixes by Ori Avtalion.
........
r60957 | georg.brandl | 2008-02-22 13:56:34 +0100 (Fri, 22 Feb 2008) | 2 lines
Don't reference pyshell.
........
r60958 | georg.brandl | 2008-02-22 13:57:05 +0100 (Fri, 22 Feb 2008) | 2 lines
Another fix.
........
2008-02-22 12:37:40 -04:00
|
|
|
/* do the actual formatting */
|
|
|
|
PyOS_ascii_formatd(charbuf, sizeof(charbuf), fmt, x);
|
2007-08-24 23:26:07 -03:00
|
|
|
|
|
|
|
/* adding trailing to fmt with PyOS_snprintf doesn't work, not
|
|
|
|
sure why. we'll just concatentate it here, no harm done. we
|
|
|
|
know we can't have a buffer overflow from the fmt size
|
|
|
|
analysis */
|
|
|
|
strcat(charbuf, trailing);
|
|
|
|
|
|
|
|
/* rather than duplicate the code for snprintf for both unicode
|
|
|
|
and 8 bit strings, we just use the 8 bit version and then
|
|
|
|
convert to unicode in a separate code path. that's probably
|
|
|
|
the lesser of 2 evils. */
|
|
|
|
#if STRINGLIB_IS_UNICODE
|
|
|
|
n_digits = strtounicode(unicodebuf, charbuf);
|
|
|
|
p = unicodebuf;
|
|
|
|
#else
|
|
|
|
/* compute the length. I believe this is done because the return
|
|
|
|
value from snprintf above is unreliable */
|
|
|
|
n_digits = strlen(charbuf);
|
|
|
|
p = charbuf;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* is a sign character present in the output? if so, remember it
|
|
|
|
and skip it */
|
|
|
|
sign = p[0];
|
|
|
|
if (sign == '-') {
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60789,60793,60796,60799-60809,60812-60813,60815-60821,60823-60826,60828-60829,60831-60834,60836,60838-60839,60846-60849,60852-60854,60856-60859,60861-60870,60874-60875,60880-60881,60886,60888-60890,60892,60894-60898,60900-60931,60933-60958 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60901 | eric.smith | 2008-02-19 14:21:56 +0100 (Tue, 19 Feb 2008) | 1 line
Added PEP 3101.
........
r60907 | georg.brandl | 2008-02-20 20:12:36 +0100 (Wed, 20 Feb 2008) | 2 lines
Fixes contributed by Ori Avtalion.
........
r60909 | eric.smith | 2008-02-21 00:34:22 +0100 (Thu, 21 Feb 2008) | 1 line
Trim leading zeros from a floating point exponent, per C99. See issue 1600. As far as I know, this only affects Windows. Add float type 'n' to PyOS_ascii_formatd (see PEP 3101 for 'n' description).
........
r60910 | eric.smith | 2008-02-21 00:39:28 +0100 (Thu, 21 Feb 2008) | 1 line
Now that PyOS_ascii_formatd supports the 'n' format, simplify the float formatting code to just call it.
........
r60918 | andrew.kuchling | 2008-02-21 15:23:38 +0100 (Thu, 21 Feb 2008) | 2 lines
Close manifest file.
This change doesn't make any difference to CPython, but is a necessary fix for Jython.
........
r60921 | guido.van.rossum | 2008-02-21 18:46:16 +0100 (Thu, 21 Feb 2008) | 2 lines
Remove news about float repr() -- issue 1580 is still in limbo.
........
r60923 | guido.van.rossum | 2008-02-21 19:18:37 +0100 (Thu, 21 Feb 2008) | 5 lines
Removed uses of dict.has_key() from distutils, and uses of
callable() from copy_reg.py, so the interpreter now starts up
without warnings when '-3' is given. More work like this needs to
be done in the rest of the stdlib.
........
r60924 | thomas.heller | 2008-02-21 19:28:48 +0100 (Thu, 21 Feb 2008) | 4 lines
configure.ac: Remove the configure check for _Bool, it is already done in the
top-level Python configure script.
configure, fficonfig.h.in: regenerated.
........
r60925 | thomas.heller | 2008-02-21 19:52:20 +0100 (Thu, 21 Feb 2008) | 3 lines
Replace 'has_key()' with 'in'.
Replace 'raise Error, stuff' with 'raise Error(stuff)'.
........
r60927 | raymond.hettinger | 2008-02-21 20:24:53 +0100 (Thu, 21 Feb 2008) | 1 line
Update more instances of has_key().
........
r60928 | guido.van.rossum | 2008-02-21 20:46:35 +0100 (Thu, 21 Feb 2008) | 3 lines
Fix a few typos and layout glitches (more work is needed).
Move 2.5 news to Misc/HISTORY.
........
r60936 | georg.brandl | 2008-02-21 21:33:38 +0100 (Thu, 21 Feb 2008) | 2 lines
#2079: typo in userdict docs.
........
r60938 | georg.brandl | 2008-02-21 21:38:13 +0100 (Thu, 21 Feb 2008) | 2 lines
Part of #2154: minimal syntax fixes in doc example snippets.
........
r60942 | raymond.hettinger | 2008-02-22 04:16:42 +0100 (Fri, 22 Feb 2008) | 1 line
First draft for itertools.product(). Docs and other updates forthcoming.
........
r60955 | nick.coghlan | 2008-02-22 11:54:06 +0100 (Fri, 22 Feb 2008) | 1 line
Try to make command line error messages from runpy easier to understand (and suppress traceback cruft from the implicitly invoked runpy machinery)
........
r60956 | georg.brandl | 2008-02-22 13:31:45 +0100 (Fri, 22 Feb 2008) | 2 lines
A lot more typo fixes by Ori Avtalion.
........
r60957 | georg.brandl | 2008-02-22 13:56:34 +0100 (Fri, 22 Feb 2008) | 2 lines
Don't reference pyshell.
........
r60958 | georg.brandl | 2008-02-22 13:57:05 +0100 (Fri, 22 Feb 2008) | 2 lines
Another fix.
........
2008-02-22 12:37:40 -04:00
|
|
|
++p;
|
|
|
|
--n_digits;
|
2007-08-24 23:26:07 -03:00
|
|
|
}
|
|
|
|
|
2008-07-15 10:02:41 -03:00
|
|
|
calc_number_widths(&spec, sign, 0, n_digits, format);
|
2007-08-24 23:26:07 -03:00
|
|
|
|
|
|
|
/* allocate a string with enough space */
|
|
|
|
result = STRINGLIB_NEW(NULL, spec.n_total);
|
|
|
|
if (result == NULL)
|
|
|
|
goto done;
|
|
|
|
|
2008-06-24 08:21:04 -03:00
|
|
|
/* Fill in the non-digit parts (padding, sign, etc.) */
|
2008-07-15 21:15:35 -03:00
|
|
|
fill_non_digits(STRINGLIB_STR(result), &spec, NULL, n_digits,
|
2008-06-24 08:21:04 -03:00
|
|
|
format->fill_char == '\0' ? ' ' : format->fill_char);
|
2007-08-24 23:26:07 -03:00
|
|
|
|
|
|
|
/* fill in the digit parts */
|
2008-02-17 15:48:00 -04:00
|
|
|
memmove(STRINGLIB_STR(result) +
|
|
|
|
(spec.n_lpadding + spec.n_lsign + spec.n_spadding),
|
2007-08-24 23:26:07 -03:00
|
|
|
p,
|
|
|
|
n_digits * sizeof(STRINGLIB_CHAR));
|
|
|
|
|
|
|
|
done:
|
|
|
|
return result;
|
|
|
|
}
|
2008-02-17 15:48:00 -04:00
|
|
|
#endif /* FORMAT_FLOAT */
|
2007-08-24 23:26:07 -03:00
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/*********** built in formatters ****************************************/
|
|
|
|
/************************************************************************/
|
|
|
|
PyObject *
|
2008-05-30 15:10:19 -03:00
|
|
|
FORMAT_STRING(PyObject *obj,
|
|
|
|
STRINGLIB_CHAR *format_spec,
|
|
|
|
Py_ssize_t format_spec_len)
|
2007-08-24 23:26:07 -03:00
|
|
|
{
|
|
|
|
InternalFormatSpec format;
|
2008-05-30 15:10:19 -03:00
|
|
|
PyObject *result = NULL;
|
2007-08-24 23:26:07 -03:00
|
|
|
|
|
|
|
/* check for the special case of zero length format spec, make
|
2008-05-30 15:10:19 -03:00
|
|
|
it equivalent to str(obj) */
|
|
|
|
if (format_spec_len == 0) {
|
|
|
|
result = STRINGLIB_TOSTR(obj);
|
2007-08-24 23:26:07 -03:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* parse the format_spec */
|
2008-05-30 15:10:19 -03:00
|
|
|
if (!parse_internal_render_format_spec(format_spec, format_spec_len,
|
|
|
|
&format, 's'))
|
2007-08-24 23:26:07 -03:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* type conversion? */
|
|
|
|
switch (format.type) {
|
|
|
|
case 's':
|
|
|
|
/* no type conversion needed, already a string. do the formatting */
|
2008-05-30 15:10:19 -03:00
|
|
|
result = format_string_internal(obj, &format);
|
2007-08-24 23:26:07 -03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* unknown */
|
2008-04-07 00:22:07 -03:00
|
|
|
#if STRINGLIB_IS_UNICODE
|
|
|
|
/* If STRINGLIB_CHAR is Py_UNICODE, %c might be out-of-range,
|
|
|
|
hence the two cases. If it is char, gcc complains that the
|
|
|
|
condition below is always true, hence the ifdef. */
|
|
|
|
if (format.type > 32 && format.type <128)
|
|
|
|
#endif
|
|
|
|
PyErr_Format(PyExc_ValueError, "Unknown conversion type %c",
|
|
|
|
(char)format.type);
|
|
|
|
#if STRINGLIB_IS_UNICODE
|
|
|
|
else
|
|
|
|
PyErr_Format(PyExc_ValueError, "Unknown conversion type '\\x%x'",
|
|
|
|
(unsigned int)format.type);
|
|
|
|
#endif
|
2007-08-24 23:26:07 -03:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-02-17 15:48:00 -04:00
|
|
|
#if defined FORMAT_LONG || defined FORMAT_INT
|
|
|
|
static PyObject*
|
2008-05-30 15:10:19 -03:00
|
|
|
format_int_or_long(PyObject* obj,
|
|
|
|
STRINGLIB_CHAR *format_spec,
|
|
|
|
Py_ssize_t format_spec_len,
|
|
|
|
IntOrLongToString tostring)
|
2007-08-24 23:26:07 -03:00
|
|
|
{
|
|
|
|
PyObject *result = NULL;
|
|
|
|
PyObject *tmp = NULL;
|
|
|
|
InternalFormatSpec format;
|
|
|
|
|
|
|
|
/* check for the special case of zero length format spec, make
|
2008-05-30 15:10:19 -03:00
|
|
|
it equivalent to str(obj) */
|
|
|
|
if (format_spec_len == 0) {
|
|
|
|
result = STRINGLIB_TOSTR(obj);
|
2007-08-24 23:26:07 -03:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* parse the format_spec */
|
2008-05-30 15:10:19 -03:00
|
|
|
if (!parse_internal_render_format_spec(format_spec,
|
|
|
|
format_spec_len,
|
|
|
|
&format, 'd'))
|
2007-08-24 23:26:07 -03:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* type conversion? */
|
|
|
|
switch (format.type) {
|
|
|
|
case 'b':
|
|
|
|
case 'c':
|
|
|
|
case 'd':
|
|
|
|
case 'o':
|
|
|
|
case 'x':
|
|
|
|
case 'X':
|
Merged revisions 63078 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
When forward porting this, I added _PyUnicode_InsertThousandsGrouping.
........
r63078 | eric.smith | 2008-05-11 15:52:48 -0400 (Sun, 11 May 2008) | 14 lines
Addresses issue 2802: 'n' formatting for integers.
Adds 'n' as a format specifier for integers, to mirror the same
specifier which is already available for floats. 'n' is the same as
'd', but inserts the current locale-specific thousands grouping.
I added this as a stringlib function, but it's only used by str type,
not unicode. This is because of an implementation detail in
unicode.format(), which does its own str->unicode conversion. But the
unicode version will be needed in 3.0, and it may be needed by other
code eventually in 2.6 (maybe decimal?), so I left it as a stringlib
implementation. As long as the unicode version isn't instantiated,
there's no overhead for this.
........
2008-05-11 18:00:57 -03:00
|
|
|
case 'n':
|
2008-02-17 15:48:00 -04:00
|
|
|
/* no type conversion needed, already an int (or long). do
|
|
|
|
the formatting */
|
2008-05-30 15:10:19 -03:00
|
|
|
result = format_int_or_long_internal(obj, &format, tostring);
|
2007-08-24 23:26:07 -03:00
|
|
|
break;
|
|
|
|
|
2008-01-28 06:59:27 -04:00
|
|
|
case 'e':
|
|
|
|
case 'E':
|
|
|
|
case 'f':
|
|
|
|
case 'F':
|
|
|
|
case 'g':
|
|
|
|
case 'G':
|
|
|
|
case '%':
|
|
|
|
/* convert to float */
|
2008-05-30 15:10:19 -03:00
|
|
|
tmp = PyNumber_Float(obj);
|
2008-01-28 06:59:27 -04:00
|
|
|
if (tmp == NULL)
|
|
|
|
goto done;
|
2008-05-30 15:10:19 -03:00
|
|
|
result = format_float_internal(obj, &format);
|
2008-01-28 06:59:27 -04:00
|
|
|
break;
|
|
|
|
|
2007-08-24 23:26:07 -03:00
|
|
|
default:
|
|
|
|
/* unknown */
|
|
|
|
PyErr_Format(PyExc_ValueError, "Unknown conversion type %c",
|
|
|
|
format.type);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
Py_XDECREF(tmp);
|
|
|
|
return result;
|
|
|
|
}
|
2008-02-17 15:48:00 -04:00
|
|
|
#endif /* FORMAT_LONG || defined FORMAT_INT */
|
|
|
|
|
|
|
|
#ifdef FORMAT_LONG
|
|
|
|
/* Need to define long_format as a function that will convert a long
|
|
|
|
to a string. In 3.0, _PyLong_Format has the correct signature. In
|
|
|
|
2.x, we need to fudge a few parameters */
|
|
|
|
#if PY_VERSION_HEX >= 0x03000000
|
|
|
|
#define long_format _PyLong_Format
|
|
|
|
#else
|
|
|
|
static PyObject*
|
|
|
|
long_format(PyObject* value, int base)
|
|
|
|
{
|
|
|
|
/* Convert to base, don't add trailing 'L', and use the new octal
|
|
|
|
format. We already know this is a long object */
|
|
|
|
assert(PyLong_Check(value));
|
|
|
|
/* convert to base, don't add 'L', and use the new octal format */
|
|
|
|
return _PyLong_Format(value, base, 0, 1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
PyObject *
|
2008-05-30 15:10:19 -03:00
|
|
|
FORMAT_LONG(PyObject *obj,
|
|
|
|
STRINGLIB_CHAR *format_spec,
|
|
|
|
Py_ssize_t format_spec_len)
|
2008-02-17 15:48:00 -04:00
|
|
|
{
|
2008-05-30 15:10:19 -03:00
|
|
|
return format_int_or_long(obj, format_spec, format_spec_len,
|
|
|
|
long_format);
|
2008-02-17 15:48:00 -04:00
|
|
|
}
|
|
|
|
#endif /* FORMAT_LONG */
|
|
|
|
|
|
|
|
#ifdef FORMAT_INT
|
|
|
|
/* this is only used for 2.x, not 3.0 */
|
|
|
|
static PyObject*
|
|
|
|
int_format(PyObject* value, int base)
|
|
|
|
{
|
|
|
|
/* Convert to base, and use the new octal format. We already
|
|
|
|
know this is an int object */
|
|
|
|
assert(PyInt_Check(value));
|
|
|
|
return _PyInt_Format((PyIntObject*)value, base, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject *
|
2008-05-30 15:10:19 -03:00
|
|
|
FORMAT_INT(PyObject *obj,
|
|
|
|
STRINGLIB_CHAR *format_spec,
|
|
|
|
Py_ssize_t format_spec_len)
|
2008-02-17 15:48:00 -04:00
|
|
|
{
|
2008-05-30 15:10:19 -03:00
|
|
|
return format_int_or_long(obj, format_spec, format_spec_len,
|
|
|
|
int_format);
|
2008-02-17 15:48:00 -04:00
|
|
|
}
|
|
|
|
#endif /* FORMAT_INT */
|
2007-08-24 23:26:07 -03:00
|
|
|
|
2008-02-17 15:48:00 -04:00
|
|
|
#ifdef FORMAT_FLOAT
|
2007-08-24 23:26:07 -03:00
|
|
|
PyObject *
|
2008-05-30 15:10:19 -03:00
|
|
|
FORMAT_FLOAT(PyObject *obj,
|
|
|
|
STRINGLIB_CHAR *format_spec,
|
|
|
|
Py_ssize_t format_spec_len)
|
2007-08-24 23:26:07 -03:00
|
|
|
{
|
|
|
|
PyObject *result = NULL;
|
|
|
|
InternalFormatSpec format;
|
|
|
|
|
|
|
|
/* check for the special case of zero length format spec, make
|
2008-05-30 15:10:19 -03:00
|
|
|
it equivalent to str(obj) */
|
|
|
|
if (format_spec_len == 0) {
|
|
|
|
result = STRINGLIB_TOSTR(obj);
|
2007-08-24 23:26:07 -03:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* parse the format_spec */
|
2008-05-30 15:10:19 -03:00
|
|
|
if (!parse_internal_render_format_spec(format_spec,
|
|
|
|
format_spec_len,
|
|
|
|
&format, '\0'))
|
2007-08-24 23:26:07 -03:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* type conversion? */
|
|
|
|
switch (format.type) {
|
Merged revisions 61431,61433-61436,61439,61444,61449-61450,61453,61458,61465,61468,61471-61474,61480,61483-61484,61488,61495-61496,61498,61503-61504,61507,61509-61510,61515-61518 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r61431 | vinay.sajip | 2008-03-16 22:35:58 +0100 (So, 16 Mär 2008) | 1 line
Clarified documentation on use of shutdown().
........
r61433 | mark.summerfield | 2008-03-17 09:28:15 +0100 (Mo, 17 Mär 2008) | 5 lines
Added a footnote to each pointing out that for XML output if an encoding
string is given it should conform to the appropriate XML standards---for
example, "UTF-8" is okay, but "UTF8" is not.
........
r61434 | eric.smith | 2008-03-17 12:01:01 +0100 (Mo, 17 Mär 2008) | 7 lines
Issue 2264: empty float presentation type needs to have at least one digit past the decimal point.
Added "Z" format_char to PyOS_ascii_formatd to support empty float presentation type.
Renamed buf_size in PyOS_ascii_formatd to more accurately reflect it's meaning.
Modified format.__float__ to use the new "Z" format as the default.
Added test cases.
........
r61435 | eric.smith | 2008-03-17 13:14:29 +0100 (Mo, 17 Mär 2008) | 2 lines
Reformated lines > 79 chars.
Deleted unused macro ISXDIGIT.
........
r61436 | jeffrey.yasskin | 2008-03-17 15:40:53 +0100 (Mo, 17 Mär 2008) | 13 lines
Allow Gnu gcc's to build python on OSX by removing -Wno-long-double,
-no-cpp-precomp, and -mno-fused-madd from configure.
* r22183 added -no-cpp-precomp, which
http://gcc.gnu.org/ml/gcc/2005-12/msg00368.html claims hasn't been
needed since gcc-3.1.
* r25607 added -Wno-long-double to avoid a warning in
Include/objimpl.h (issue 525481). The long double is still there,
but OSX 10.4's gcc no longer warns about it.
* r33666 fixed issue 775892 on OSX 10.3 by adding -mno-fused-madd,
which changed the sign of some float 0s. Tim Peters said it wasn't
a real issue anyway, and it no longer causes test failures.
Fixes issue #1779871.
........
r61439 | martin.v.loewis | 2008-03-17 17:31:57 +0100 (Mo, 17 Mär 2008) | 2 lines
Add Trent Nelson.
........
r61444 | travis.oliphant | 2008-03-17 18:36:12 +0100 (Mo, 17 Mär 2008) | 1 line
Add necessary headers to back-port new buffer protocol to Python 2.6
........
r61449 | gregory.p.smith | 2008-03-17 19:48:05 +0100 (Mo, 17 Mär 2008) | 8 lines
Force zlib.crc32 and zlib.adler32 to return a signed integer on all platforms
regardless of the native sizeof(long) used in the integer object.
This somewhat odd behavior of returning a signed is maintained in 2.x for
compatibility reasons of always returning an integer rather than a long object.
Fixes Issue1202 for Python 2.6
........
r61450 | neal.norwitz | 2008-03-17 20:02:45 +0100 (Mo, 17 Mär 2008) | 3 lines
Use a buffer large enough to ensure we don't overrun, even if the value
is outside the range we expect.
........
r61453 | steven.bethard | 2008-03-17 20:33:11 +0100 (Mo, 17 Mär 2008) | 1 line
Document unicode.isnumeric() and unicode.isdecimal() (issue2326)
........
r61458 | neal.norwitz | 2008-03-17 21:22:43 +0100 (Mo, 17 Mär 2008) | 5 lines
Issue 2321: reduce memory usage (increase the memory that is returned
to the system) by using pymalloc for the data of unicode objects.
Will backport.
........
r61465 | martin.v.loewis | 2008-03-17 22:55:30 +0100 (Mo, 17 Mär 2008) | 2 lines
Add David Wolever.
........
r61468 | gregory.p.smith | 2008-03-18 01:20:01 +0100 (Di, 18 Mär 2008) | 3 lines
Fix the IOError message text when opening a file with an invalid filename.
Error reported by Ilan Schnell.
........
r61471 | brett.cannon | 2008-03-18 02:00:07 +0100 (Di, 18 Mär 2008) | 2 lines
Convert test_strftime, test_getargs, and test_pep247 to use unittest.
........
r61472 | jeffrey.yasskin | 2008-03-18 02:09:59 +0100 (Di, 18 Mär 2008) | 2 lines
Fix build on platforms that don't have intptr_t. Patch by Joseph Armbruster.
........
r61473 | brett.cannon | 2008-03-18 02:50:25 +0100 (Di, 18 Mär 2008) | 2 lines
Convert test_dummy_threading and test_dbm to unittest.
........
r61474 | brett.cannon | 2008-03-18 02:58:56 +0100 (Di, 18 Mär 2008) | 2 lines
Move test_extcall to doctest.
........
r61480 | brett.cannon | 2008-03-18 04:46:22 +0100 (Di, 18 Mär 2008) | 2 lines
test_errno was a no-op test; now it actually tests things and uses unittest.
........
r61483 | brett.cannon | 2008-03-18 05:09:00 +0100 (Di, 18 Mär 2008) | 3 lines
Remove our implementation of memmove() and strerror(); both are in the C89
standard library.
........
r61484 | brett.cannon | 2008-03-18 05:16:06 +0100 (Di, 18 Mär 2008) | 2 lines
The output directory for tests that compare against stdout is now gone!
........
r61488 | jeffrey.yasskin | 2008-03-18 05:29:35 +0100 (Di, 18 Mär 2008) | 2 lines
Block the "socket.ssl() is deprecated" warning from test_socket_ssl.
........
r61495 | jeffrey.yasskin | 2008-03-18 05:56:06 +0100 (Di, 18 Mär 2008) | 4 lines
Speed test_thread up from 51.328s to 0.081s by reducing its sleep times. We
still sleep at all to make it likely that all threads are active at the same
time.
........
r61496 | jeffrey.yasskin | 2008-03-18 06:12:41 +0100 (Di, 18 Mär 2008) | 4 lines
Speed up test_dict by about 10x by only checking selected dict literal sizes,
instead of every integer from 0 to 400. Exhaustive testing wastes time without
providing enough more assurance that the code is correct.
........
r61498 | neal.norwitz | 2008-03-18 06:20:29 +0100 (Di, 18 Mär 2008) | 1 line
Try increasing the timeout to reduce the flakiness of this test.
........
r61503 | brett.cannon | 2008-03-18 06:43:04 +0100 (Di, 18 Mär 2008) | 2 lines
Improve the error message for a test that failed on the S-390 Debian buildbot.
........
r61504 | jeffrey.yasskin | 2008-03-18 06:45:40 +0100 (Di, 18 Mär 2008) | 3 lines
Add a -S/--slow flag to regrtest to have it print the 10 slowest tests with
their times.
........
r61507 | neal.norwitz | 2008-03-18 07:03:46 +0100 (Di, 18 Mär 2008) | 1 line
Add some info to the failure messages
........
r61509 | trent.nelson | 2008-03-18 08:02:12 +0100 (Di, 18 Mär 2008) | 1 line
Issue 2286: bump up the stack size of the 64-bit debug python_d.exe to 2100000. The default value of 200000 causes a stack overflow at 1965 iterations of r_object() in marshal.c, 35 iterations before the 2000 limit enforced by MAX_MARSHAL_STACK_DEPTH.
........
r61510 | trent.nelson | 2008-03-18 08:32:47 +0100 (Di, 18 Mär 2008) | 5 lines
The behaviour of winsound.Beep() seems to differ between different versions of Windows when there's either:
a) no sound card entirely
b) legacy beep driver has been disabled
c) the legacy beep driver has been uninstalled
Sometimes RuntimeErrors are raised, sometimes they're not. If _have_soundcard() returns False, don't expect winsound.Beep() to raise a RuntimeError, as this clearly isn't the case, as demonstrated by the various Win32 XP buildbots.
........
r61515 | martin.v.loewis | 2008-03-18 13:20:15 +0100 (Di, 18 Mär 2008) | 2 lines
norwitz-amd64 (gentoo) has EREMOTEIO.
........
r61516 | martin.v.loewis | 2008-03-18 13:45:37 +0100 (Di, 18 Mär 2008) | 2 lines
Add more Linux error codes.
........
r61517 | martin.v.loewis | 2008-03-18 14:05:03 +0100 (Di, 18 Mär 2008) | 2 lines
Add WSA errors.
........
r61518 | martin.v.loewis | 2008-03-18 14:16:05 +0100 (Di, 18 Mär 2008) | 2 lines
Note that the stderr output of the test is intentional.
........
2008-03-18 12:15:01 -03:00
|
|
|
case '\0':
|
|
|
|
/* 'Z' means like 'g', but with at least one decimal. See
|
|
|
|
PyOS_ascii_formatd */
|
|
|
|
format.type = 'Z';
|
|
|
|
/* Deliberate fall through to the next case statement */
|
2007-08-24 23:26:07 -03:00
|
|
|
case 'e':
|
|
|
|
case 'E':
|
|
|
|
case 'f':
|
|
|
|
case 'F':
|
|
|
|
case 'g':
|
|
|
|
case 'G':
|
|
|
|
case 'n':
|
|
|
|
case '%':
|
|
|
|
/* no conversion, already a float. do the formatting */
|
2008-05-30 15:10:19 -03:00
|
|
|
result = format_float_internal(obj, &format);
|
2007-08-24 23:26:07 -03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* unknown */
|
|
|
|
PyErr_Format(PyExc_ValueError, "Unknown conversion type %c",
|
|
|
|
format.type);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
return result;
|
|
|
|
}
|
2008-02-17 15:48:00 -04:00
|
|
|
#endif /* FORMAT_FLOAT */
|