Commit Graph

143 Commits

Author SHA1 Message Date
Serhiy Storchaka 2085bd0877
bpo-37116: Use PEP 570 syntax for positional-only parameters. (GH-13700) 2019-06-01 11:00:15 +03:00
Serhiy Storchaka 87be28f4a1
bpo-31672: Restore the former behavior when override flags in Template. (#5099)
Overriding flags to 0 will make the default pattern matching only
lower case letters.
2018-01-04 19:20:11 +02:00
Barry Warsaw e256b40888
bpo-31672 - Add one last minor clarification for idpattern (#4483)
Add one last minor clarification for idpattern
2017-11-21 10:28:13 -05:00
INADA Naoki b22273ec5d bpo-31672: Fix string.Template accidentally matched non-ASCII identifiers (GH-3872)
Pattern `[a-z]` with `IGNORECASE` flag can match to some non-ASCII characters.

Straightforward solution for this is using `IGNORECASE | ASCII` flag.
But users may subclass `Template` and override only `idpattern`. So we want to
avoid changing `Template.flags`.

So this commit uses local flag `-i` for `idpattern` and change `[a-z]` to `[a-zA-Z]`.
2017-10-13 16:02:23 +09:00
Barry Warsaw ba4279683f bpo-1198569: Allow string.Template braced pattern to be different (#3288)
* bpo-1198569: Allow the braced pattern to be different

``string.Template`` subclasses can optionally define ``braceidpattern`` if
they want to specify different placeholder patterns inside and outside the
braces.  If None (the default) it falls back to ``idpattern``.
2017-09-04 16:32:10 -04:00
Serhiy Storchaka 009b0a1fac Issue #29193: A format string argument for string.Formatter.format()
is now positional-only.
2017-01-13 09:10:51 +02:00
R David Murray 44b548dda8 #27364: fix "incorrect" uses of escape character in the stdlib.
And most of the tools.

Patch by Emanual Barry, reviewed by me, Serhiy Storchaka, and
Martin Panter.
2016-09-08 13:59:53 -04:00
Zachary Ware 8bc9378c98 Closes #26809: Merge with 3.5 2016-06-04 14:41:42 -05:00
Zachary Ware c17a0b87a6 Issue #26809: Add __all__ to string module. Patch by Emanuel Barry 2016-06-04 14:35:05 -05:00
Eric V. Smith 6dcada3bcf Issue #25034: Merge from 3.5. 2015-09-29 10:30:47 -04:00
Eric V. Smith ad4003c7fb Issue #25034: Merge from 3.4. 2015-09-29 10:30:04 -04:00
Eric V. Smith 85976b14dd Fixed issue #25034: Fix string.Formatter problem with auto-numbering
and nested format_specs. Patch by Anthon van der Neut.
2015-09-29 10:27:38 -04:00
Yury Selivanov 7aa5341164 Reverting my previous commit.
Something went horribly wrong when I was doing `hg rebase`.
2015-05-30 10:57:56 -04:00
Serhiy Storchaka 6e6883f11a Issue #24309: Removed Python 2 idioms. 2015-05-28 20:45:29 +03:00
Serhiy Storchaka b876df4cbb Issue #23671: string.Template now allows to specify the "self" parameter as
keyword argument.  string.Formatter now allows to specify the "self" and
the "format_string" parameters as keyword arguments.
2015-03-24 22:30:46 +02:00
Serhiy Storchaka 8ffe917cee Issue #23671: string.Template now allows to specify the "self" parameter as
keyword argument.  string.Formatter now allows to specify the "self" and
the "format_string" parameters as keyword arguments.
2015-03-24 22:28:43 +02:00
Eric V. Smith 7ce90743a1 Issue #13598: Add auto-numbering of replacement fields to string.Formatter. 2014-04-14 16:43:50 -04:00
R David Murray 749bd42072 Merge #13579: teach string.Formatter about 'a'.
Patch by Francisco Martín Brugué.
2012-08-19 17:45:40 -04:00
R David Murray e56bf97ef4 #13579: teach string.Formatter about 'a'.
Patch by Francisco Martín Brugué.
2012-08-19 17:26:34 -04:00
Ezio Melotti d8b509b192 #13012: use splitlines(keepends=True/False) instead of splitlines(0/1). 2011-09-28 17:37:55 +03:00
Raymond Hettinger 9fe1ccfb5a Issue #11297: Add collections.ChainMap() 2011-02-26 01:02:51 +00:00
Raymond Hettinger c9423109f5 Factor-out common code for helper classes. 2011-02-22 01:55:36 +00:00
Georg Brandl 66c221e993 #9418: first step of moving private string methods to _string module. 2010-10-14 07:04:07 +00:00
Florent Xicluna eb19dce085 Issue #1686: Fix string.Template when overriding the pattern attribute. 2010-09-18 23:34:07 +00:00
Florent Xicluna 7b2a7710ef typo 2010-09-06 20:27:55 +00:00
Georg Brandl 056cb93e7a #6630: allow customizing flags for compiling string.Template.idpattern. 2010-07-29 17:16:10 +00:00
Ezio Melotti a40bdda937 Merged revisions 75070 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r75070 | ezio.melotti | 2009-09-26 14:20:53 +0300 (Sat, 26 Sep 2009) | 1 line

  #7000: document "sep" in capwords. Add a few tests
........
2009-09-26 12:33:22 +00:00
Benjamin Peterson 5a6deb4cae remove string.maketrans 2009-06-28 21:35:31 +00:00
Philip Jenvey a394f2dca3 #4351: more appropriate DeprecationWarning stacklevels 2009-05-08 03:57:12 +00:00
Georg Brandl abc387747d Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
string.maketrans() which actually works on bytes.  (Also closes #5675.)
2009-04-12 15:51:51 +00:00
Georg Brandl 5076740d4f #4361: fix string.py docstring, clarify that only ASCII characters are in its constants. 2008-11-22 08:31:09 +00:00
Benjamin Peterson f608c61301 Merged revisions 67154,67157-67159,67175-67176,67189,67224-67227,67234 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r67154 | hirokazu.yamamoto | 2008-11-07 21:46:17 -0600 (Fri, 07 Nov 2008) | 1 line

  Issue #4071: ntpath.abspath returned an empty string for long unicode path.
........
  r67157 | georg.brandl | 2008-11-08 05:47:44 -0600 (Sat, 08 Nov 2008) | 2 lines

  Don't use "HOWTO" as the title for all howto .tex files.
........
  r67158 | georg.brandl | 2008-11-08 05:48:20 -0600 (Sat, 08 Nov 2008) | 2 lines

  Update "Documenting" a bit. Concentrate on Python-specifics.
........
  r67159 | georg.brandl | 2008-11-08 06:52:25 -0600 (Sat, 08 Nov 2008) | 2 lines

  Fix warning.
........
  r67175 | benjamin.peterson | 2008-11-08 19:44:32 -0600 (Sat, 08 Nov 2008) | 1 line

  update link
........
  r67176 | benjamin.peterson | 2008-11-08 19:52:32 -0600 (Sat, 08 Nov 2008) | 1 line

  fix comment
........
  r67189 | benjamin.peterson | 2008-11-11 15:56:06 -0600 (Tue, 11 Nov 2008) | 1 line

  use correct name
........
  r67224 | georg.brandl | 2008-11-15 02:10:04 -0600 (Sat, 15 Nov 2008) | 2 lines

  #4324: fix getlocale() argument.
........
  r67225 | brett.cannon | 2008-11-15 16:33:25 -0600 (Sat, 15 Nov 2008) | 1 line

  Clarify the docs for the 'strict' argument to httplib.HTTPConnection.
........
  r67226 | brett.cannon | 2008-11-15 16:40:44 -0600 (Sat, 15 Nov 2008) | 4 lines

  The docs for httplib.HTTPConnection.putheader() have claimed for quite a while
  that their could be an arbitrary number of values passed in. Turns out the code
  did not match that. The code now matches the docs.
........
  r67227 | georg.brandl | 2008-11-16 02:00:17 -0600 (Sun, 16 Nov 2008) | 2 lines

  #4316: fix configure.in markup problem.
........
  r67234 | benjamin.peterson | 2008-11-16 11:54:55 -0600 (Sun, 16 Nov 2008) | 1 line

  run autoconf
........
2008-11-16 18:33:53 +00:00
Guido van Rossum 254348e201 Rename buffer -> bytearray. 2007-11-21 19:29:53 +00:00
Guido van Rossum 98297ee781 Merging the py3k-pep3137 branch back into the py3k branch.
No detailed change log; just check out the change log for the py3k-pep3137
branch.  The most obvious changes:

  - str8 renamed to bytes (PyString at the C level);
  - bytes renamed to buffer (PyBytes at the C level);
  - PyString and PyUnicode are no longer compatible.

I.e. we now have an immutable bytes type and a mutable bytes type.

The behavior of PyString was modified quite a bit, to make it more
bytes-like.  Some changes are still on the to-do list.
2007-11-06 21:34:58 +00:00
Eric Smith 11529195ca Changed some ValueError's to KeyError and IndexError.
Corrected code for invalid conversion specifier.
Added tests to verify.

Modified string.Formatter to correctly expand format_spec's,
and added a limit to recursion depth.  Added _vformat()
method to support both of these.
2007-09-04 23:04:22 +00:00
Eric Smith 9d4ba3970f Removed used_args param from string.Formatter.get_field. It was left in by mistake from an earlier edit. 2007-09-02 15:33:26 +00:00
Georg Brandl 7f13e6b3e2 string.maketrans() now produces translation tables for bytes.translate() -- wrong module?
Fix all remaining instances that did bad things with the new str.translate().
2007-08-31 10:37:15 +00:00
Eric Smith 3bcc42ad0f Changed signature of string.Formatter.get_field, per suggestion by
Ron Adam.

Added test case for using all parameters in string.Formatter.
2007-08-31 02:26:31 +00:00
Collin Winter ce36ad8a46 Raise statement normalization in Lib/. 2007-08-30 01:19:48 +00:00
Collin Winter 95fb569f46 Revert r57685 (weird merge result). 2007-08-29 23:41:34 +00:00
Collin Winter e0281cab81 2007-08-29 23:37:10 +00:00
Eric Smith 625cbf28ee Modified parsing of format strings, so that we always return
a tuple (literal, field_name, format_spec, conversion).

literal will always be a string, but might be of zero length.
field_name will be None if there is no markup text
format_spec will be a (possibly zero length) string if
  field_name is non-None
conversion will be a one character string, or None

This makes the Formatter class, and especially it's parse()
method, easier to understand.

Suggestion was by Jim Jewett, inspired by the "tail" of an
elementtree node.

Also, fixed a reference leak in fieldnameiter_next.
2007-08-29 03:22:59 +00:00
Eric Smith 9e7c8da61c Simplified tuple returned by string._formatter_parser to only have
4 elements.  No need for old is_markup element, the same information
is indicated by literal_string being None.

Factored string.Formatter class to make subclasses easier to write.
2007-08-28 11:15:20 +00:00
Eric Smith e226b55963 PEP 3101: Removed _formatter_xxx routines from sysmodule, and made them unicode methods instead (per GvR suggestion). 2007-08-27 11:28:18 +00:00
Eric Smith 7ade6485ab PEP 3101: Completed string.Formatter class. Reimplemented field_name to object transformation. 2007-08-26 22:27:13 +00:00
Eric Smith 8c66326368 Implementation of PEP 3101, Advanced String Formatting.
Known issues:

The string.Formatter class, as discussed in the PEP, is incomplete.

Error handling needs to conform to the PEP.

Need to fix this warning that I introduced in Python/formatter_unicode.c:
Objects/stringlib/unicodedefs.h:26: warning: `STRINGLIB_CMP' defined but not used

Need to make sure sign formatting is correct, more tests needed.

Need to remove '()' sign formatting, left over from an earlier version of the PEP.
2007-08-25 02:26:07 +00:00
Martin v. Löwis 967f1e3b85 Remove string.{letters,lowercase,uppercase}. 2007-08-14 09:23:10 +00:00
Guido van Rossum c1f779cb01 Merged revisions 56125-56153 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk

........
  r56127 | georg.brandl | 2007-06-30 09:32:49 +0200 (Sat, 30 Jun 2007) | 2 lines

  Fix a place where floor division would be in order.
........
  r56135 | guido.van.rossum | 2007-07-01 06:13:54 +0200 (Sun, 01 Jul 2007) | 28 lines

  Make map() and filter() identical to itertools.imap() and .ifilter(),
  respectively.

  I fixed two bootstrap issues, due to the dynamic import of itertools:

  1. Starting python requires that map() and filter() are not used until
     site.py has added build/lib.<arch> to sys.path.
  2. Building python requires that setup.py and distutils and everything
     they use is free of map() and filter() calls.

  Beyond this, I only fixed the tests in test_builtin.py.
  Others, please help fixing the remaining tests that are now broken!
  The fixes are usually simple:
  a. map(None, X) -> list(X)
  b. map(F, X) -> list(map(F, X))
  c. map(lambda x: F(x), X) -> [F(x) for x in X]
  d. filter(F, X) -> list(filter(F, X))
  e. filter(lambda x: P(x), X) -> [x for x in X if P(x)]

  Someone, please also contribute a fixer for 2to3 to do this.
  It can leave map()/filter() calls alone that are already
  inside a list() or sorted() call or for-loop.

  Only in rare cases have I seen code that depends on map() of lists
  of different lengths going to the end of the longest, or on filter()
  of a string or tuple returning an object of the same type; these
  will need more thought to fix.
........
  r56136 | guido.van.rossum | 2007-07-01 06:22:01 +0200 (Sun, 01 Jul 2007) | 3 lines

  Make it so that test_decimal fails instead of hangs, to help automated
  test runners.
........
  r56139 | georg.brandl | 2007-07-01 18:20:58 +0200 (Sun, 01 Jul 2007) | 2 lines

  Fix a few test cases after the map->imap change.
........
  r56142 | neal.norwitz | 2007-07-02 06:38:12 +0200 (Mon, 02 Jul 2007) | 1 line

  Get a bunch more tests passing after converting map/filter to return iterators.
........
  r56147 | guido.van.rossum | 2007-07-02 15:32:02 +0200 (Mon, 02 Jul 2007) | 4 lines

  Fix the remaining failing unit tests (at least on OSX).
  Also tweaked urllib2 so it doesn't raise socket.gaierror when
  all network interfaces are turned off.
........
2007-07-03 08:25:58 +00:00
Guido van Rossum ebe3e16600 Merged revisions 55342-55406 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk

........
  r55360 | guido.van.rossum | 2007-05-15 14:57:59 -0700 (Tue, 15 May 2007) | 2 lines

  obcheckin.
........
  r55361 | guido.van.rossum | 2007-05-15 14:59:18 -0700 (Tue, 15 May 2007) | 2 lines

  Get rid of strop module.
........
  r55367 | brett.cannon | 2007-05-15 21:06:28 -0700 (Tue, 15 May 2007) | 2 lines

  Remove the 'pure' module.
........
  r55369 | brett.cannon | 2007-05-15 21:07:31 -0700 (Tue, 15 May 2007) | 2 lines

  Remove the lib-old directory (already empty).
........
  r55370 | neal.norwitz | 2007-05-15 21:30:40 -0700 (Tue, 15 May 2007) | 1 line

  Get rid of a bunch more references to strop
........
  r55374 | brett.cannon | 2007-05-15 21:39:00 -0700 (Tue, 15 May 2007) | 2 lines

  Complete the removal of IRIX-specific modules.
........
  r55379 | brett.cannon | 2007-05-15 22:31:54 -0700 (Tue, 15 May 2007) | 2 lines

  Update removed IRIX modules based on what is gone from removing plat-irix6.
........
  r55388 | brett.cannon | 2007-05-16 14:34:52 -0700 (Wed, 16 May 2007) | 2 lines

  Clean up the docstring for the compiler resource.
........
  r55406 | brett.cannon | 2007-05-17 11:05:37 -0700 (Thu, 17 May 2007) | 2 lines

  Remove BaseException.message (deprecated in Python 2.6).
........
2007-05-17 18:20:34 +00:00
Guido van Rossum 805365ee39 Merged revisions 55007-55179 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/p3yk

........
  r55077 | guido.van.rossum | 2007-05-02 11:54:37 -0700 (Wed, 02 May 2007) | 2 lines

  Use the new print syntax, at least.
........
  r55142 | fred.drake | 2007-05-04 21:27:30 -0700 (Fri, 04 May 2007) | 1 line

  remove old cruftiness
........
  r55143 | fred.drake | 2007-05-04 21:52:16 -0700 (Fri, 04 May 2007) | 1 line

  make this work with the new Python
........
  r55162 | neal.norwitz | 2007-05-06 22:29:18 -0700 (Sun, 06 May 2007) | 1 line

  Get asdl code gen working with Python 2.3.  Should continue to work with 3.0
........
  r55164 | neal.norwitz | 2007-05-07 00:00:38 -0700 (Mon, 07 May 2007) | 1 line

  Verify checkins to p3yk (sic) branch go to 3000 list.
........
  r55166 | neal.norwitz | 2007-05-07 00:12:35 -0700 (Mon, 07 May 2007) | 1 line

  Fix this test so it runs again by importing warnings_test properly.
........
  r55167 | neal.norwitz | 2007-05-07 01:03:22 -0700 (Mon, 07 May 2007) | 8 lines

  So long xrange.  range() now supports values that are outside
  -sys.maxint to sys.maxint.  floats raise a TypeError.

  This has been sitting for a long time.  It probably has some problems and
  needs cleanup.  Objects/rangeobject.c now uses 4-space indents since
  it is almost completely new.
........
  r55171 | guido.van.rossum | 2007-05-07 10:21:26 -0700 (Mon, 07 May 2007) | 4 lines

  Fix two tests that were previously depending on significant spaces
  at the end of a line (and before that on Python 2.x print behavior
  that has no exact equivalent in 3.0).
........
2007-05-07 22:24:25 +00:00