Commit Graph

97 Commits

Author SHA1 Message Date
Ezio Melotti 9ba83c50f4 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 11:23:16 +00:00
Georg Brandl bb608a84aa Merged revisions 67154,67157-67159,67162-67163,67166,67175-67176,67189,67224-67225,67243 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r67154 | hirokazu.yamamoto | 2008-11-08 04:46:17 +0100 (Sat, 08 Nov 2008) | 1 line

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

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

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

  Fix warning.
........
  r67162 | benjamin.peterson | 2008-11-08 17:55:33 +0100 (Sat, 08 Nov 2008) | 1 line

  a few compile() and ast doc improvements
........
  r67163 | benjamin.peterson | 2008-11-08 18:04:18 +0100 (Sat, 08 Nov 2008) | 1 line

  move context clue to versionchanged tag
........
  r67166 | benjamin.peterson | 2008-11-08 18:07:06 +0100 (Sat, 08 Nov 2008) | 1 line

  clarify what was added
........
  r67175 | benjamin.peterson | 2008-11-09 02:44:32 +0100 (Sun, 09 Nov 2008) | 1 line

  update link
........
  r67176 | benjamin.peterson | 2008-11-09 02:52:32 +0100 (Sun, 09 Nov 2008) | 1 line

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

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

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

  Clarify the docs for the 'strict' argument to httplib.HTTPConnection.
........
  r67243 | benjamin.peterson | 2008-11-17 22:39:05 +0100 (Mon, 17 Nov 2008) | 1 line

  a few fixes on the download page
........
2008-12-05 08:35:09 +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
Fred Drake 046d27215f Martin von Löwis <martin@loewis.home.cs.tu-berlin.de>:
This patch delegates more string functions to string object methods,
uses the varargs delegation syntax, and stops using stringold.

Closes SourceForge patch #100712.
2000-07-03 07:23:13 +00:00
Guido van Rossum 9e896b37c7 Marc-Andre's third try at this bulk patch seems to work (except that
his copy of test_contains.py seems to be broken -- the lines he
deleted were already absent).  Checkin messages:


New Unicode support for int(), float(), complex() and long().

- new APIs PyInt_FromUnicode() and PyLong_FromUnicode()
- added support for Unicode to PyFloat_FromString()
- new encoding API PyUnicode_EncodeDecimal() which converts
  Unicode to a decimal char* string (used in the above new
  APIs)
- shortcuts for calls like int(<int object>) and float(<float obj>)
- tests for all of the above

Unicode compares and contains checks:
- comparing Unicode and non-string types now works; TypeErrors
  are masked, all other errors such as ValueError during
  Unicode coercion are passed through (note that PyUnicode_Compare
  does not implement the masking -- PyObject_Compare does this)
- contains now works for non-string types too; TypeErrors are
  masked and 0 returned; all other errors are passed through

Better testing support for the standard codecs.

Misc minor enhancements, such as an alias dbcs for the mbcs codec.

Changes:
- PyLong_FromString() now applies the same error checks as
  does PyInt_FromString(): trailing garbage is reported
  as error and not longer silently ignored. The only characters
  which may be trailing the digits are 'L' and 'l' -- these
  are still silently ignored.
- string.ato?() now directly interface to int(), long() and
  float(). The error strings are now a little different, but
  the type still remains the same. These functions are now
  ready to get declared obsolete ;-)
- PyNumber_Int() now also does a check for embedded NULL chars
  in the input string; PyNumber_Long() already did this (and
  still does)

Followed by:

Looks like I've gone a step too far there... (and test_contains.py
seem to have a bug too).

I've changed back to reporting all errors in PyUnicode_Contains()
and added a few more test cases to test_contains.py (plus corrected
the join() NameError).
2000-04-05 20:11:21 +00:00
Guido van Rossum 8f0c5a7742 Marc-Andre Lemburg: the maxsplit argument for split() and replace()
now defaults to -1, not to 0.  Passing an explicit zero doesn't split
or replace at all.
2000-03-10 23:22:10 +00:00