Commit Graph

100 Commits

Author SHA1 Message Date
Florent Xicluna 9b90cd1f7b Merged revisions 84470-84471,84566-84567,84759 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r84470 | florent.xicluna | 2010-09-03 22:00:37 +0200 (ven., 03 sept. 2010) | 1 line

  Strengthen BytesWarning tests.
........
  r84471 | florent.xicluna | 2010-09-03 22:23:40 +0200 (ven., 03 sept. 2010) | 1 line

  Typo
........
  r84566 | florent.xicluna | 2010-09-06 22:27:15 +0200 (lun., 06 sept. 2010) | 1 line

  typo
........
  r84567 | florent.xicluna | 2010-09-06 22:27:55 +0200 (lun., 06 sept. 2010) | 1 line

  typo
........
  r84759 | florent.xicluna | 2010-09-13 04:28:18 +0200 (lun., 13 sept. 2010) | 1 line

  Reenable test_ucs4 and remove some duplicated lines.
........
2010-09-13 07:46:37 +00:00
Senthil Kumaran a240cb1f2d Issue5416 - Revert a documentatin change made to explain replace on negative value.
Minor changes to doc:  s/maxsplit/maxreplace
2010-09-08 12:40:45 +00:00
Senthil Kumaran c0548c9d90 Fix Issue5416 - explain negative value of maxplit in str.replace. 2010-08-09 08:47:15 +00:00
Ezio Melotti 9aac2455ab #7000: document "sep" in capwords. Add a few tests 2009-09-26 11:20:53 +00:00
Benjamin Peterson b7c95ce8b8 fix comment 2008-11-09 01:52:32 +00:00
Georg Brandl 74bbc79d10 Replace all map(None, a) with list(a). 2008-07-18 19:06:13 +00:00
Eric Smith a9f7d62480 Backport of PEP 3101, Advanced String Formatting, from py3k.
Highlights:
 - Adding PyObject_Format.
 - Adding string.Format class.
 - Adding __format__ for str, unicode, int, long, float, datetime.
 - Adding builtin format.
 - Adding ''.format and u''.format.
 - str/unicode fixups for formatters.

The files in Objects/stringlib that implement PEP 3101 (stringdefs.h,
unicodedefs.h, formatter.h, string_format.h) are identical in trunk
and py3k.  Any changes from here on should be made to trunk, and
changes will propogate to py3k).
2008-02-17 19:46:49 +00:00
Raymond Hettinger 4db5fe970c SF 1193128: Let str.translate(None) be an identity transformation 2007-04-12 04:10:00 +00:00
Guido van Rossum f102e24bd3 Add a type.__init__() method that enforces the same signature as
type.__new__(), and then calls object.__init__(cls), just to be anal.

This allows us to restore the code in string.py's _TemplateMetaclass
that called super(...).__init__(name, bases, dct), which I commented
out yesterday since it broke due to the stricter argument checking
added to object.__init__().
2007-03-23 18:53:03 +00:00
Guido van Rossum 143b564059 - Bug #1683368: The object.__init__() and object.__new__() methods are
now stricter in rejecting excess arguments.  The only time when
  either allows excess arguments is when it is not overridden and the
  other one is.  For backwards compatibility, when both are
  overridden, it is a deprecation warning (for now; maybe a Py3k
  warning later).

When merging this into 3.0, the warnings should become errors.

Note: without the change to string.py, lots of spurious warnings happen.
What's going on there?
2007-03-23 04:58:42 +00:00
Georg Brandl d76bd69712 Cookie.py shouldn't "bogusly" use string._idmap. 2006-08-14 22:01:24 +00:00
Thomas Wouters add191118f Fix bug in passing tuples to string.Template. All other values (with working
str() or repr()) would work, just not multi-value tuples. Probably not a
backport candidate, since it changes the behaviour of passing a
single-element tuple:

>>> string.Template("$foo").substitute(dict(foo=(1,)))

'(1,)'

versus

'1'
2006-07-05 11:03:49 +00:00
Raymond Hettinger 57aef9cb29 Remove outdated references to the regsub module. 2004-12-07 07:55:07 +00:00
Barry Warsaw 8c72eae237 SF patch #1056967, changes the semantics of Template.safe_substitute() to not
raise a ValueError for dangling delimiters (the delimiter itself is returned).
2004-11-01 03:52:43 +00:00
Neal Norwitz 6627a96705 Invalid patterns to substitute and safe_substitute would crash since pattern
is not a local variable.  Add a test case.
2004-10-17 16:27:18 +00:00
Raymond Hettinger 55593c3ef5 Make the regex pattern easier to read, understand, and modify
by factoring out the common prefix (the delimiter).
2004-09-26 18:56:44 +00:00
Barry Warsaw 17cb60083c At the cost of a modest (but useful in its own right) change in the semantics
of the Template.delimiter attribute, we make use of the delimiter in the
escaped group, and in the safe_substitute() method more robust.

Now, .delimiter should be the unescaped delimiter literal, e.g. '$' or '&', or
whatever.  The _TemplateMetaclass will re.escape() this value when it builds
the pattern.
2004-09-18 00:06:34 +00:00
Tim Peters c74298a72b Whitespace normalization. 2004-09-16 00:09:19 +00:00
Walter Dörwald 065a32f550 Make the hint about the None default less ambiguous. 2004-09-14 09:45:10 +00:00
Walter Dörwald 782afc5927 Enhance the docstrings for unicode.split() and string.split()
to make it clear that it is possible to pass None as the
separator argument to get the default "any whitespace" separator.
2004-09-14 09:40:45 +00:00
Raymond Hettinger 6d191113a6 Fix small bugs in Template code.
* The parameterization of "delimiter" was incomplete.
* safe_substitute's code for braced delimiters should only be executed
  when braced is not None.
* Invalid pattern group names now raise a ValueError.  Formerly, the
  convert code would fall off the end and improperly return None.

Beefed-up tests.

* Test delimiter override for all paths in substitute and safe_substitute.
* Alter unittest invocation to match other modules (now it itemizes the
  tests as they are run).
2004-09-14 02:34:08 +00:00
Barry Warsaw b5c6b5bfe8 Raymond's good suggestion to re-order the tests in the convert() helper so the
most common paths are tested first.  Also, that 'invalid' is better than
'bogus'.
2004-09-13 20:52:50 +00:00
Barry Warsaw b6234a95c1 substitute(), safe_substitute(): Paul Moore provides a better hack for dealing
with positional arguments.
2004-09-13 15:25:15 +00:00
Barry Warsaw 46b629c101 Accepted Raymond's patch to combine mapping and keyword arguments, with slight
modification.  Also, renamed the positional argument to '__mapping' to further
reduce the chance of duplicate keyword arguments.
2004-09-13 14:35:04 +00:00
Barry Warsaw f43e8bd7b4 Template: remove __slots__ since that interferes with the ability to mix in
Template and unicode classes.
2004-09-10 18:30:42 +00:00
Raymond Hettinger 1f7d6a633f __slots__ went missing from Template. 2004-09-10 06:21:22 +00:00
Barry Warsaw 12827c1fa9 Many updates to PEP 292 templates. Summary:
- Template no longer inherits from unicode.

- SafeTemplate is removed.  Now Templates have both a substitute() and a
  safe_substitute() method, so we don't need separate classes.  No more
  __mod__() operator.

- Adopt Tim Peter's idea for giving Template a metaclass, which makes the
  delimiter, the identifier pattern, or the entire pattern easy to override
  and document, while retaining efficiency of class-time compilation of the
  regexp.

- More informative ValueError messages which will help a user narrow down the
  bogus delimiter to the line and column in the original string (helpful for
  long triple quoted strings).
2004-09-10 03:08:08 +00:00
Raymond Hettinger 0d58e2be0b Minor improvements to the template code.
* Add comment bars segregating this code from the rest.
* Improve readability of the re pattern with indentation and comments on
  the same line.
* Replace the groupdict() and get() pair with a direct call to group()
  which does the same thing.
2004-08-26 00:21:13 +00:00
Barry Warsaw 8bee76106e PEP 292 classes Template and SafeTemplate are added to the string module.
This patch includes test cases and documentation updates, as well as NEWS file
updates.

This patch also updates the sre modules so that they don't import the string
module, breaking direct circular imports.
2004-08-25 02:22:30 +00:00
Hye-Shik Chang 3ae811b57d Add rsplit method for str and unicode builtin types.
SF feature request #801847.
Original patch is written by Sean Reifschneider.
2003-12-15 18:49:53 +00:00
Raymond Hettinger 4f8f976576 Add optional fillchar argument to ljust(), rjust(), and center() string methods. 2003-11-26 08:21:35 +00:00
Skip Montanaro 0b87444b1b tweak the docstring to not be so focused on 1.6. 2003-10-03 14:05:26 +00:00
Neal Norwitz ffe33b7f24 Attempt to make all the various string *strip methods the same.
* Doc - add doc for when functions were added
 * UserString
 * string object methods
 * string module functions
'chars' is used for the last parameter everywhere.

These changes will be backported, since part of the changes
have already been made, but they were inconsistent.
2003-04-10 22:35:32 +00:00
Neal Norwitz a4864a2464 Update the docstring to match the code. Will backport. 2002-11-14 03:31:32 +00:00
Martin v. Löwis 1f04610b49 Make strip behave as documented. Will backport to 2.2.3. 2002-11-08 12:09:59 +00:00
Martin v. Löwis 5357c6511d Convert empty string literal to string. Speed up creation of idmap. 2002-10-14 20:03:40 +00:00
Walter Dörwald 65230a2de7 Remove uses of the string and types modules:
x in string.whitespace => x.isspace()
type(x) in types.StringTypes => isinstance(x, basestring)
isinstance(x, types.StringTypes) => isinstance(x, basestring)
type(x) is types.StringType => isinstance(x, str)
type(x) == types.StringType => isinstance(x, str)
string.split(x, ...) => x.split(...)
string.join(x, y) => y.join(x)
string.zfill(x, ...) => x.zfill(...)
string.count(x, ...) => x.count(...)
hasattr(types, "UnicodeType") => try: unicode except NameError:
type(x) != types.TupleTuple => not isinstance(x, tuple)
isinstance(x, types.TupleType) => isinstance(x, tuple)
type(x) is types.IntType => isinstance(x, int)

Do not mention the string module in the rlcompleter docstring.

This partially applies SF patch http://www.python.org/sf/562373
(with basestring instead of string). (It excludes the changes to
unittest.py and does not change the os.stat stuff.)
2002-06-03 15:58:32 +00:00
Walter Dörwald 068325ef92 Apply the second version of SF patch http://www.python.org/sf/536241
Add a method zfill to str, unicode and UserString and change
Lib/string.py accordingly.

This activates the zfill version in unicodeobject.c that was
commented out and implements the same in stringobject.c. It also
adds the test for unicode support in Lib/string.py back in and
uses repr() instead() of str() (as it was before Lib/string.py 1.62)
2002-04-15 13:36:47 +00:00
Andrew M. Kuchling 102d1208a8 [Bug #536241] string.zfill() produces mangled output for a Unicode string.
Walter Doerwald provided a patch, which I've modified in two ways:

1) (Uncontroversial) Removed code to make module work in earlier versions of
   Python without the unicode() built-in

2) (Poss. controversial) Instead of making string.zfill take the repr()
   of non-string objects, take the str().

Should a warning be added to this branch of the code so that the automatic
str() can be deprecated?

2.2.2 bugfix candidate, assuming the repr()->str() change is deemed OK.
2002-03-29 16:20:33 +00:00
Fred Drake 1453754fcd string.split() docstring described the interpretation of the maxsplit
argument incorrectly.
This closes SF bug #505997.
2002-01-30 16:15:13 +00:00
Fred Drake 960fdf9ac3 Added the constants ascii_letters, ascii_lowercase, and ascii_uppercase
to the string module.  This was determined to be the right approach in
SF bug #226706.
2001-07-20 18:38:26 +00:00
Skip Montanaro 78349072f7 removed __all__ from several modules 2001-02-18 03:30:53 +00:00
Skip Montanaro 0de65807e6 bunch more __all__ lists
also modified check_all function to suppress all warnings since they aren't
relevant to what this test is doing (allows quiet checking of regsub, for
instance)
2001-02-15 22:15:14 +00:00
Tim Peters 6b6b39e8b6 Nuke accurate but confusing and unhelpful comments about split vs splitfields. 2001-02-09 20:18:41 +00:00
Eric S. Raymond e37340edf2 String method conversion. 2001-02-09 16:56:44 +00:00
Tim Peters 495ad3c8cc Whitespace normalization. 2001-01-15 01:36:40 +00:00
Guido van Rossum 5aff7752eb Make string.translate(s, table) work for Unicode s. Two things are
required to work around restrictions on the arguments of
u.translate():

1) don't pass the deletions argument if it's empty;

2) convert table to Unicode if s is Unicode.

This fixes SF bug #124060.
2000-12-19 02:39:08 +00:00
Fred Drake fd64c5908f Fix serious typo!
Add the new constants to the module docstring.
2000-09-18 19:38:11 +00:00
Fred Drake 6b2320fa6b Richard Mortier <rmm1002@users.sourceforge.net>:
Add the constants "printable" and "punctuation" to the string module.
2000-09-18 16:46:17 +00:00
Thomas Wouters 7e47402264 Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
comments, docstrings or error messages. I fixed two minor things in
test_winreg.py ("didn't" -> "Didn't" and "Didnt" -> "Didn't").

There is a minor style issue involved: Guido seems to have preferred English
grammar (behaviour, honour) in a couple places. This patch changes that to
American, which is the more prominent style in the source. I prefer English
myself, so if English is preferred, I'd be happy to supply a patch myself ;)
2000-07-16 12:04:32 +00:00