You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
5.4 KiB

Merged revisions 64722,64729,64753,64845-64846,64849,64871,64880-64882,64885,64888,64897,64900-64901,64915,64926-64929,64938-64941,64944,64961,64966,64973 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r64722 | georg.brandl | 2008-07-05 12:13:36 +0200 (Sat, 05 Jul 2008) | 4 lines #2663: support an *ignore* argument to shutil.copytree(). Patch by Tarek Ziade. This is a new feature, but Barry authorized adding it in the beta period. ........ r64729 | mark.dickinson | 2008-07-05 13:33:52 +0200 (Sat, 05 Jul 2008) | 5 lines Issue 3188: accept float('infinity') as well as float('inf'). This makes the float constructor behave in the same way as specified by various other language standards, including C99, IEEE 754r, and the IBM Decimal standard. ........ r64753 | gregory.p.smith | 2008-07-06 05:35:58 +0200 (Sun, 06 Jul 2008) | 4 lines - Issue #2862: Make int and float freelist management consistent with other freelists. Changes their CompactFreeList apis into ClearFreeList apis and calls them via gc.collect(). ........ r64845 | raymond.hettinger | 2008-07-10 16:03:19 +0200 (Thu, 10 Jul 2008) | 1 line Issue 3301: Bisect functions behaved badly when lo was negative. ........ r64846 | raymond.hettinger | 2008-07-10 16:34:57 +0200 (Thu, 10 Jul 2008) | 1 line Issue 3285: Fractions from_float() and from_decimal() accept Integral arguments. ........ r64849 | andrew.kuchling | 2008-07-10 16:43:31 +0200 (Thu, 10 Jul 2008) | 1 line Wording changes ........ r64871 | raymond.hettinger | 2008-07-11 14:00:21 +0200 (Fri, 11 Jul 2008) | 1 line Add cautionary note on the use of PySequence_Fast_ITEMS. ........ r64880 | amaury.forgeotdarc | 2008-07-11 23:28:25 +0200 (Fri, 11 Jul 2008) | 5 lines #3317 in zipfile module, restore the previous names of global variables: some applications relied on them. Also remove duplicated lines. ........ r64881 | amaury.forgeotdarc | 2008-07-11 23:45:06 +0200 (Fri, 11 Jul 2008) | 3 lines #3342: In tracebacks, printed source lines were not indented since r62555. #3343: Py_DisplaySourceLine should be a private function. Rename it to _Py_DisplaySourceLine. ........ r64882 | josiah.carlson | 2008-07-12 00:17:14 +0200 (Sat, 12 Jul 2008) | 2 lines Fix for the AttributeError in test_asynchat. ........ r64885 | josiah.carlson | 2008-07-12 01:26:59 +0200 (Sat, 12 Jul 2008) | 2 lines Fixed test for asyncore. ........ r64888 | matthias.klose | 2008-07-12 09:51:48 +0200 (Sat, 12 Jul 2008) | 2 lines - Fix bashisms in Tools/faqwiz/move-faqwiz.sh ........ r64897 | benjamin.peterson | 2008-07-12 22:16:19 +0200 (Sat, 12 Jul 2008) | 1 line fix various doc typos #3320 ........ r64900 | alexandre.vassalotti | 2008-07-13 00:06:53 +0200 (Sun, 13 Jul 2008) | 2 lines Fixed typo. ........ r64901 | benjamin.peterson | 2008-07-13 01:41:19 +0200 (Sun, 13 Jul 2008) | 1 line #1778443 robotparser fixes from Aristotelis Mikropoulos ........ r64915 | nick.coghlan | 2008-07-13 16:52:36 +0200 (Sun, 13 Jul 2008) | 1 line Fix issue 3221 by emitting a RuntimeWarning instead of raising SystemError when the parent module can't be found during an absolute import (likely due to non-PEP 361 aware code which sets a module level __package__ attribute) ........ r64926 | martin.v.loewis | 2008-07-13 22:31:49 +0200 (Sun, 13 Jul 2008) | 2 lines Add turtle into the module index. ........ r64927 | alexandre.vassalotti | 2008-07-13 22:42:44 +0200 (Sun, 13 Jul 2008) | 3 lines Issue #3274: Use a less common identifier for the temporary variable in Py_CLEAR(). ........ r64928 | andrew.kuchling | 2008-07-13 23:43:25 +0200 (Sun, 13 Jul 2008) | 1 line Re-word ........ r64929 | andrew.kuchling | 2008-07-13 23:43:52 +0200 (Sun, 13 Jul 2008) | 1 line Add various items; move ctypes items into a subsection of their own ........ r64938 | andrew.kuchling | 2008-07-14 02:35:32 +0200 (Mon, 14 Jul 2008) | 1 line Typo fixes ........ r64939 | andrew.kuchling | 2008-07-14 02:40:55 +0200 (Mon, 14 Jul 2008) | 1 line Typo fix ........ r64940 | andrew.kuchling | 2008-07-14 03:18:16 +0200 (Mon, 14 Jul 2008) | 1 line Typo fix ........ r64941 | andrew.kuchling | 2008-07-14 03:18:31 +0200 (Mon, 14 Jul 2008) | 1 line Expand the multiprocessing section ........ r64944 | gregory.p.smith | 2008-07-14 08:06:48 +0200 (Mon, 14 Jul 2008) | 7 lines Fix posix.fork1() / os.fork1() to only call PyOS_AfterFork() in the child process rather than both parent and child. Does anyone actually use fork1()? It appears to be a Solaris thing but if Python is built with pthreads on Solaris, fork1() and fork() should be the same. ........ r64961 | jesse.noller | 2008-07-15 15:47:33 +0200 (Tue, 15 Jul 2008) | 1 line multiprocessing/connection.py patch to remove fqdn oddness for issue 3270 ........ r64966 | nick.coghlan | 2008-07-15 17:40:22 +0200 (Tue, 15 Jul 2008) | 1 line Add missing NEWS entry for r64962 ........ r64973 | jesse.noller | 2008-07-15 20:29:18 +0200 (Tue, 15 Jul 2008) | 1 line Revert 3270 patch: self._address is in pretty widespread use, need to revisit ........
18 years ago
Merged revisions 64722,64729,64753,64845-64846,64849,64871,64880-64882,64885,64888,64897,64900-64901,64915,64926-64929,64938-64941,64944,64961,64966,64973 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r64722 | georg.brandl | 2008-07-05 12:13:36 +0200 (Sat, 05 Jul 2008) | 4 lines #2663: support an *ignore* argument to shutil.copytree(). Patch by Tarek Ziade. This is a new feature, but Barry authorized adding it in the beta period. ........ r64729 | mark.dickinson | 2008-07-05 13:33:52 +0200 (Sat, 05 Jul 2008) | 5 lines Issue 3188: accept float('infinity') as well as float('inf'). This makes the float constructor behave in the same way as specified by various other language standards, including C99, IEEE 754r, and the IBM Decimal standard. ........ r64753 | gregory.p.smith | 2008-07-06 05:35:58 +0200 (Sun, 06 Jul 2008) | 4 lines - Issue #2862: Make int and float freelist management consistent with other freelists. Changes their CompactFreeList apis into ClearFreeList apis and calls them via gc.collect(). ........ r64845 | raymond.hettinger | 2008-07-10 16:03:19 +0200 (Thu, 10 Jul 2008) | 1 line Issue 3301: Bisect functions behaved badly when lo was negative. ........ r64846 | raymond.hettinger | 2008-07-10 16:34:57 +0200 (Thu, 10 Jul 2008) | 1 line Issue 3285: Fractions from_float() and from_decimal() accept Integral arguments. ........ r64849 | andrew.kuchling | 2008-07-10 16:43:31 +0200 (Thu, 10 Jul 2008) | 1 line Wording changes ........ r64871 | raymond.hettinger | 2008-07-11 14:00:21 +0200 (Fri, 11 Jul 2008) | 1 line Add cautionary note on the use of PySequence_Fast_ITEMS. ........ r64880 | amaury.forgeotdarc | 2008-07-11 23:28:25 +0200 (Fri, 11 Jul 2008) | 5 lines #3317 in zipfile module, restore the previous names of global variables: some applications relied on them. Also remove duplicated lines. ........ r64881 | amaury.forgeotdarc | 2008-07-11 23:45:06 +0200 (Fri, 11 Jul 2008) | 3 lines #3342: In tracebacks, printed source lines were not indented since r62555. #3343: Py_DisplaySourceLine should be a private function. Rename it to _Py_DisplaySourceLine. ........ r64882 | josiah.carlson | 2008-07-12 00:17:14 +0200 (Sat, 12 Jul 2008) | 2 lines Fix for the AttributeError in test_asynchat. ........ r64885 | josiah.carlson | 2008-07-12 01:26:59 +0200 (Sat, 12 Jul 2008) | 2 lines Fixed test for asyncore. ........ r64888 | matthias.klose | 2008-07-12 09:51:48 +0200 (Sat, 12 Jul 2008) | 2 lines - Fix bashisms in Tools/faqwiz/move-faqwiz.sh ........ r64897 | benjamin.peterson | 2008-07-12 22:16:19 +0200 (Sat, 12 Jul 2008) | 1 line fix various doc typos #3320 ........ r64900 | alexandre.vassalotti | 2008-07-13 00:06:53 +0200 (Sun, 13 Jul 2008) | 2 lines Fixed typo. ........ r64901 | benjamin.peterson | 2008-07-13 01:41:19 +0200 (Sun, 13 Jul 2008) | 1 line #1778443 robotparser fixes from Aristotelis Mikropoulos ........ r64915 | nick.coghlan | 2008-07-13 16:52:36 +0200 (Sun, 13 Jul 2008) | 1 line Fix issue 3221 by emitting a RuntimeWarning instead of raising SystemError when the parent module can't be found during an absolute import (likely due to non-PEP 361 aware code which sets a module level __package__ attribute) ........ r64926 | martin.v.loewis | 2008-07-13 22:31:49 +0200 (Sun, 13 Jul 2008) | 2 lines Add turtle into the module index. ........ r64927 | alexandre.vassalotti | 2008-07-13 22:42:44 +0200 (Sun, 13 Jul 2008) | 3 lines Issue #3274: Use a less common identifier for the temporary variable in Py_CLEAR(). ........ r64928 | andrew.kuchling | 2008-07-13 23:43:25 +0200 (Sun, 13 Jul 2008) | 1 line Re-word ........ r64929 | andrew.kuchling | 2008-07-13 23:43:52 +0200 (Sun, 13 Jul 2008) | 1 line Add various items; move ctypes items into a subsection of their own ........ r64938 | andrew.kuchling | 2008-07-14 02:35:32 +0200 (Mon, 14 Jul 2008) | 1 line Typo fixes ........ r64939 | andrew.kuchling | 2008-07-14 02:40:55 +0200 (Mon, 14 Jul 2008) | 1 line Typo fix ........ r64940 | andrew.kuchling | 2008-07-14 03:18:16 +0200 (Mon, 14 Jul 2008) | 1 line Typo fix ........ r64941 | andrew.kuchling | 2008-07-14 03:18:31 +0200 (Mon, 14 Jul 2008) | 1 line Expand the multiprocessing section ........ r64944 | gregory.p.smith | 2008-07-14 08:06:48 +0200 (Mon, 14 Jul 2008) | 7 lines Fix posix.fork1() / os.fork1() to only call PyOS_AfterFork() in the child process rather than both parent and child. Does anyone actually use fork1()? It appears to be a Solaris thing but if Python is built with pthreads on Solaris, fork1() and fork() should be the same. ........ r64961 | jesse.noller | 2008-07-15 15:47:33 +0200 (Tue, 15 Jul 2008) | 1 line multiprocessing/connection.py patch to remove fqdn oddness for issue 3270 ........ r64966 | nick.coghlan | 2008-07-15 17:40:22 +0200 (Tue, 15 Jul 2008) | 1 line Add missing NEWS entry for r64962 ........ r64973 | jesse.noller | 2008-07-15 20:29:18 +0200 (Tue, 15 Jul 2008) | 1 line Revert 3270 patch: self._address is in pretty widespread use, need to revisit ........
18 years ago
  1. .. highlightlang:: c
  2. .. _string-conversion:
  3. String conversion and formatting
  4. ================================
  5. Functions for number conversion and formatted string output.
  6. .. c:function:: int PyOS_snprintf(char *str, size_t size, const char *format, ...)
  7. Output not more than *size* bytes to *str* according to the format string
  8. *format* and the extra arguments. See the Unix man page :manpage:`snprintf(2)`.
  9. .. c:function:: int PyOS_vsnprintf(char *str, size_t size, const char *format, va_list va)
  10. Output not more than *size* bytes to *str* according to the format string
  11. *format* and the variable argument list *va*. Unix man page
  12. :manpage:`vsnprintf(2)`.
  13. :c:func:`PyOS_snprintf` and :c:func:`PyOS_vsnprintf` wrap the Standard C library
  14. functions :c:func:`snprintf` and :c:func:`vsnprintf`. Their purpose is to
  15. guarantee consistent behavior in corner cases, which the Standard C functions do
  16. not.
  17. The wrappers ensure that *str*[*size*-1] is always ``'\0'`` upon return. They
  18. never write more than *size* bytes (including the trailing ``'\0'``) into str.
  19. Both functions require that ``str != NULL``, ``size > 0`` and ``format !=
  20. NULL``.
  21. If the platform doesn't have :c:func:`vsnprintf` and the buffer size needed to
  22. avoid truncation exceeds *size* by more than 512 bytes, Python aborts with a
  23. *Py_FatalError*.
  24. The return value (*rv*) for these functions should be interpreted as follows:
  25. * When ``0 <= rv < size``, the output conversion was successful and *rv*
  26. characters were written to *str* (excluding the trailing ``'\0'`` byte at
  27. *str*[*rv*]).
  28. * When ``rv >= size``, the output conversion was truncated and a buffer with
  29. ``rv + 1`` bytes would have been needed to succeed. *str*[*size*-1] is ``'\0'``
  30. in this case.
  31. * When ``rv < 0``, "something bad happened." *str*[*size*-1] is ``'\0'`` in
  32. this case too, but the rest of *str* is undefined. The exact cause of the error
  33. depends on the underlying platform.
  34. The following functions provide locale-independent string to number conversions.
  35. .. c:function:: double PyOS_string_to_double(const char *s, char **endptr, PyObject *overflow_exception)
  36. Convert a string ``s`` to a :c:type:`double`, raising a Python
  37. exception on failure. The set of accepted strings corresponds to
  38. the set of strings accepted by Python's :func:`float` constructor,
  39. except that ``s`` must not have leading or trailing whitespace.
  40. The conversion is independent of the current locale.
  41. If ``endptr`` is ``NULL``, convert the whole string. Raise
  42. ValueError and return ``-1.0`` if the string is not a valid
  43. representation of a floating-point number.
  44. If endptr is not ``NULL``, convert as much of the string as
  45. possible and set ``*endptr`` to point to the first unconverted
  46. character. If no initial segment of the string is the valid
  47. representation of a floating-point number, set ``*endptr`` to point
  48. to the beginning of the string, raise ValueError, and return
  49. ``-1.0``.
  50. If ``s`` represents a value that is too large to store in a float
  51. (for example, ``"1e500"`` is such a string on many platforms) then
  52. if ``overflow_exception`` is ``NULL`` return ``Py_HUGE_VAL`` (with
  53. an appropriate sign) and don't set any exception. Otherwise,
  54. ``overflow_exception`` must point to a Python exception object;
  55. raise that exception and return ``-1.0``. In both cases, set
  56. ``*endptr`` to point to the first character after the converted value.
  57. If any other error occurs during the conversion (for example an
  58. out-of-memory error), set the appropriate Python exception and
  59. return ``-1.0``.
  60. .. versionadded:: 3.1
  61. .. c:function:: char* PyOS_double_to_string(double val, char format_code, int precision, int flags, int *ptype)
  62. Convert a :c:type:`double` *val* to a string using supplied
  63. *format_code*, *precision*, and *flags*.
  64. *format_code* must be one of ``'e'``, ``'E'``, ``'f'``, ``'F'``,
  65. ``'g'``, ``'G'`` or ``'r'``. For ``'r'``, the supplied *precision*
  66. must be 0 and is ignored. The ``'r'`` format code specifies the
  67. standard :func:`repr` format.
  68. *flags* can be zero or more of the values *Py_DTSF_SIGN*,
  69. *Py_DTSF_ADD_DOT_0*, or *Py_DTSF_ALT*, or-ed together:
  70. * *Py_DTSF_SIGN* means to always precede the returned string with a sign
  71. character, even if *val* is non-negative.
  72. * *Py_DTSF_ADD_DOT_0* means to ensure that the returned string will not look
  73. like an integer.
  74. * *Py_DTSF_ALT* means to apply "alternate" formatting rules. See the
  75. documentation for the :c:func:`PyOS_snprintf` ``'#'`` specifier for
  76. details.
  77. If *ptype* is non-NULL, then the value it points to will be set to one of
  78. *Py_DTST_FINITE*, *Py_DTST_INFINITE*, or *Py_DTST_NAN*, signifying that
  79. *val* is a finite number, an infinite number, or not a number, respectively.
  80. The return value is a pointer to *buffer* with the converted string or
  81. *NULL* if the conversion failed. The caller is responsible for freeing the
  82. returned string by calling :c:func:`PyMem_Free`.
  83. .. versionadded:: 3.1
  84. .. c:function:: int PyOS_stricmp(const char *s1, const char *s2)
  85. Case insensitive comparison of strings. The function works almost
  86. identically to :c:func:`strcmp` except that it ignores the case.
  87. .. c:function:: int PyOS_strnicmp(const char *s1, const char *s2, Py_ssize_t size)
  88. Case insensitive comparison of strings. The function works almost
  89. identically to :c:func:`strncmp` except that it ignores the case.