annotate Lib/stringold.py @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents 49726dca16d8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 # module 'string' -- A collection of string operations
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
3 # Warning: most of the code you see here isn't normally used nowadays. With
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
4 # Python 1.6, many of these functions are implemented as methods on the
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
5 # standard string object. They used to be implemented by a built-in module
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
6 # called strop, but strop is now obsolete itself.
5
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
8 """Common string manipulations.
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
9
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
10 Public module variables:
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
11
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
12 whitespace -- a string containing all characters considered whitespace
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
13 lowercase -- a string containing all characters considered lowercase letters
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
14 uppercase -- a string containing all characters considered uppercase letters
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
15 letters -- a string containing all characters considered letters
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
16 digits -- a string containing all characters considered decimal digits
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
17 hexdigits -- a string containing all characters considered hexadecimal digits
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
18 octdigits -- a string containing all characters considered octal digits
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
19
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
20 """
46755
b7109a0cd0f9 Deprecate stringold for removal in 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 34127
diff changeset
21 from warnings import warnpy3k
b7109a0cd0f9 Deprecate stringold for removal in 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 34127
diff changeset
22 warnpy3k("the stringold module has been removed in Python 3.0", stacklevel=2)
b7109a0cd0f9 Deprecate stringold for removal in 3.0.
Brett Cannon <bcannon@gmail.com>
parents: 34127
diff changeset
23 del warnpy3k
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
24
5
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 # Some strings for ctype-style character classification
1331
07900834cc97 * pdb.py: set 'privileged' property when evaluating expressions
Guido van Rossum <guido@python.org>
parents: 1291
diff changeset
26 whitespace = ' \t\n\r\v\f'
5
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 lowercase = 'abcdefghijklmnopqrstuvwxyz'
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 letters = lowercase + uppercase
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 digits = '0123456789'
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 hexdigits = digits + 'abcdef' + 'ABCDEF'
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 octdigits = '01234567'
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 # Case conversion helpers
585
37905fe1892a New implementation method for case conversion.
Guido van Rossum <guido@python.org>
parents: 559
diff changeset
35 _idmap = ''
37905fe1892a New implementation method for case conversion.
Guido van Rossum <guido@python.org>
parents: 559
diff changeset
36 for i in range(256): _idmap = _idmap + chr(i)
5
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 del i
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
38
1788
56a986e49f56 * Lib/string.py: find/rfind is now the main implementation and
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
39 # Backward compatible names for exceptions
56a986e49f56 * Lib/string.py: find/rfind is now the main implementation and
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
40 index_error = ValueError
56a986e49f56 * Lib/string.py: find/rfind is now the main implementation and
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
41 atoi_error = ValueError
56a986e49f56 * Lib/string.py: find/rfind is now the main implementation and
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
42 atof_error = ValueError
56a986e49f56 * Lib/string.py: find/rfind is now the main implementation and
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
43 atol_error = ValueError
56a986e49f56 * Lib/string.py: find/rfind is now the main implementation and
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
44
5
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 # convert UPPER CASE letters to lower case
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 def lower(s):
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
47 """lower(s) -> string
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
48
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
49 Return a copy of the string s converted to lowercase.
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
50
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
51 """
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
52 return s.lower()
5
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
53
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 # Convert lower case letters to UPPER CASE
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 def upper(s):
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
56 """upper(s) -> string
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
57
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
58 Return a copy of the string s converted to uppercase.
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
59
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
60 """
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
61 return s.upper()
5
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
62
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 # Swap lower case letters and UPPER CASE
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 def swapcase(s):
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
65 """swapcase(s) -> string
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
66
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
67 Return a copy of the string s with upper case characters
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
68 converted to lowercase and vice versa.
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
69
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
70 """
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
71 return s.swapcase()
5
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
72
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 # Strip leading and trailing tabs and spaces
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 def strip(s):
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
75 """strip(s) -> string
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
76
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
77 Return a copy of the string s with leading and trailing
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
78 whitespace removed.
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
79
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
80 """
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
81 return s.strip()
5
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
82
3957
f01e7af1dd60 Add optional third parameter to split() and splitfields(), giving the
Guido van Rossum <guido@python.org>
parents: 3799
diff changeset
83 # Strip leading tabs and spaces
f01e7af1dd60 Add optional third parameter to split() and splitfields(), giving the
Guido van Rossum <guido@python.org>
parents: 3799
diff changeset
84 def lstrip(s):
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
85 """lstrip(s) -> string
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
86
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
87 Return a copy of the string s with leading whitespace removed.
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
88
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
89 """
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
90 return s.lstrip()
3957
f01e7af1dd60 Add optional third parameter to split() and splitfields(), giving the
Guido van Rossum <guido@python.org>
parents: 3799
diff changeset
91
f01e7af1dd60 Add optional third parameter to split() and splitfields(), giving the
Guido van Rossum <guido@python.org>
parents: 3799
diff changeset
92 # Strip trailing tabs and spaces
f01e7af1dd60 Add optional third parameter to split() and splitfields(), giving the
Guido van Rossum <guido@python.org>
parents: 3799
diff changeset
93 def rstrip(s):
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
94 """rstrip(s) -> string
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
95
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
96 Return a copy of the string s with trailing whitespace
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
97 removed.
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
98
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
99 """
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
100 return s.rstrip()
3957
f01e7af1dd60 Add optional third parameter to split() and splitfields(), giving the
Guido van Rossum <guido@python.org>
parents: 3799
diff changeset
101
f01e7af1dd60 Add optional third parameter to split() and splitfields(), giving the
Guido van Rossum <guido@python.org>
parents: 3799
diff changeset
102
5
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 # Split a string into a list of space/tab-separated words
3957
f01e7af1dd60 Add optional third parameter to split() and splitfields(), giving the
Guido van Rossum <guido@python.org>
parents: 3799
diff changeset
104 def split(s, sep=None, maxsplit=0):
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
105 """split(str [,sep [,maxsplit]]) -> list of strings
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
106
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
107 Return a list of the words in the string s, using sep as the
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
108 delimiter string. If maxsplit is nonzero, splits into at most
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
109 maxsplit words If sep is not specified, any whitespace string
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
110 is a separator. Maxsplit defaults to 0.
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
111
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
112 (split and splitfields are synonymous)
5
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
113
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
114 """
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
115 return s.split(sep, maxsplit)
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
116 splitfields = split
196
48fc0b8f33d9 Added join() and joinfields() functions.
Guido van Rossum <guido@python.org>
parents: 102
diff changeset
117
2778
17fdec2fb309 make split and splitfields, join and joinfields synonyms
Guido van Rossum <guido@python.org>
parents: 2541
diff changeset
118 # Join fields with optional separator
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
119 def join(words, sep = ' '):
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
120 """join(list [,sep]) -> string
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
121
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
122 Return a string composed of the words in list, with
13620
5b727ab37092 Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents: 11742
diff changeset
123 intervening occurrences of sep. The default separator is a
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
124 single space.
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
125
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
126 (joinfields and join are synonymous)
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
127
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
128 """
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
129 return sep.join(words)
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
130 joinfields = join
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
131
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
132 # for a little bit of speed
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
133 _apply = apply
196
48fc0b8f33d9 Added join() and joinfields() functions.
Guido van Rossum <guido@python.org>
parents: 102
diff changeset
134
1291
517d29ebc840 * ftplib.py: added abort() command (sends oob data).
Guido van Rossum <guido@python.org>
parents: 1260
diff changeset
135 # Find substring, raise exception if not found
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
136 def index(s, *args):
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
137 """index(s, sub [,start [,end]]) -> int
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
138
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
139 Like find but raises ValueError when the substring is not found.
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
140
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
141 """
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
142 return _apply(s.index, args)
1291
517d29ebc840 * ftplib.py: added abort() command (sends oob data).
Guido van Rossum <guido@python.org>
parents: 1260
diff changeset
143
1403
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1357
diff changeset
144 # Find last substring, raise exception if not found
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
145 def rindex(s, *args):
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
146 """rindex(s, sub [,start [,end]]) -> int
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
147
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
148 Like rfind but raises ValueError when the substring is not found.
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
149
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
150 """
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
151 return _apply(s.rindex, args)
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1403
diff changeset
152
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1403
diff changeset
153 # Count non-overlapping occurrences of substring
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
154 def count(s, *args):
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
155 """count(s, sub[, start[,end]]) -> int
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
156
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
157 Return the number of occurrences of substring sub in string
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
158 s[start:end]. Optional arguments start and end are
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
159 interpreted as in slice notation.
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
160
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
161 """
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
162 return _apply(s.count, args)
1403
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1357
diff changeset
163
1291
517d29ebc840 * ftplib.py: added abort() command (sends oob data).
Guido van Rossum <guido@python.org>
parents: 1260
diff changeset
164 # Find substring, return -1 if not found
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
165 def find(s, *args):
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
166 """find(s, sub [,start [,end]]) -> in
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
167
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
168 Return the lowest index in s where substring sub is found,
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
169 such that sub is contained within s[start,end]. Optional
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
170 arguments start and end are interpreted as in slice notation.
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
171
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
172 Return -1 on failure.
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
173
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
174 """
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
175 return _apply(s.find, args)
5
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
176
1403
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1357
diff changeset
177 # Find last substring, return -1 if not found
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
178 def rfind(s, *args):
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
179 """rfind(s, sub [,start [,end]]) -> int
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
180
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
181 Return the highest index in s where substring sub is found,
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
182 such that sub is contained within s[start,end]. Optional
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
183 arguments start and end are interpreted as in slice notation.
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
184
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
185 Return -1 on failure.
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
186
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
187 """
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
188 return _apply(s.rfind, args)
1403
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1357
diff changeset
189
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
190 # for a bit of speed
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
191 _float = float
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
192 _int = int
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
193 _long = long
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
194 _StringType = type('')
6821
b19cd4313126 At Barry's suggestion, plug the security leak by using an empty
Guido van Rossum <guido@python.org>
parents: 6820
diff changeset
195
1357
2fac209e1c3f * profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents: 1331
diff changeset
196 # Convert string to float
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
197 def atof(s):
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
198 """atof(s) -> float
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
199
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
200 Return the floating point number represented by the string s.
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
201
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
202 """
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
203 if type(s) == _StringType:
11742
840e18eec07f Untabify to pass the -tt test.
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
204 return _float(s)
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
205 else:
11742
840e18eec07f Untabify to pass the -tt test.
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
206 raise TypeError('argument 1: expected string, %s found' %
840e18eec07f Untabify to pass the -tt test.
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
207 type(s).__name__)
1357
2fac209e1c3f * profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents: 1331
diff changeset
208
5
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
209 # Convert string to integer
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
210 def atoi(*args):
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
211 """atoi(s [,base]) -> int
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
212
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
213 Return the integer represented by the string s in the given
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
214 base, which defaults to 10. The string s must consist of one
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
215 or more digits, possibly preceded by a sign. If base is 0, it
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
216 is chosen from the leading characters of s, 0 for octal, 0x or
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
217 0X for hexadecimal. If base is 16, a preceding 0x or 0X is
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
218 accepted.
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
219
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
220 """
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
221 try:
11742
840e18eec07f Untabify to pass the -tt test.
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
222 s = args[0]
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
223 except IndexError:
11742
840e18eec07f Untabify to pass the -tt test.
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
224 raise TypeError('function requires at least 1 argument: %d given' %
840e18eec07f Untabify to pass the -tt test.
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
225 len(args))
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
226 # Don't catch type error resulting from too many arguments to int(). The
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
227 # error message isn't compatible but the error type is, and this function
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
228 # is complicated enough already.
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
229 if type(s) == _StringType:
11742
840e18eec07f Untabify to pass the -tt test.
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
230 return _apply(_int, args)
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
231 else:
11742
840e18eec07f Untabify to pass the -tt test.
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
232 raise TypeError('argument 1: expected string, %s found' %
840e18eec07f Untabify to pass the -tt test.
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
233 type(s).__name__)
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
234
5
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
235
1357
2fac209e1c3f * profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents: 1331
diff changeset
236 # Convert string to long integer
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
237 def atol(*args):
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
238 """atol(s [,base]) -> long
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
239
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
240 Return the long integer represented by the string s in the
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
241 given base, which defaults to 10. The string s must consist
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
242 of one or more digits, possibly preceded by a sign. If base
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
243 is 0, it is chosen from the leading characters of s, 0 for
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
244 octal, 0x or 0X for hexadecimal. If base is 16, a preceding
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
245 0x or 0X is accepted. A trailing L or l is not accepted,
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
246 unless base is 0.
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
247
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
248 """
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
249 try:
11742
840e18eec07f Untabify to pass the -tt test.
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
250 s = args[0]
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
251 except IndexError:
11742
840e18eec07f Untabify to pass the -tt test.
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
252 raise TypeError('function requires at least 1 argument: %d given' %
840e18eec07f Untabify to pass the -tt test.
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
253 len(args))
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
254 # Don't catch type error resulting from too many arguments to long(). The
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
255 # error message isn't compatible but the error type is, and this function
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
256 # is complicated enough already.
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
257 if type(s) == _StringType:
11742
840e18eec07f Untabify to pass the -tt test.
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
258 return _apply(_long, args)
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
259 else:
11742
840e18eec07f Untabify to pass the -tt test.
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
260 raise TypeError('argument 1: expected string, %s found' %
840e18eec07f Untabify to pass the -tt test.
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
261 type(s).__name__)
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
262
1357
2fac209e1c3f * profile.py, pdb.py: added help() function
Guido van Rossum <guido@python.org>
parents: 1331
diff changeset
263
5
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
264 # Left-justify a string
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
265 def ljust(s, width):
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
266 """ljust(s, width) -> string
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
267
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
268 Return a left-justified version of s, in a field of the
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
269 specified width, padded with spaces as needed. The string is
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
270 never truncated.
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
271
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
272 """
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
273 n = width - len(s)
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
274 if n <= 0: return s
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
275 return s + ' '*n
5
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
276
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
277 # Right-justify a string
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
278 def rjust(s, width):
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
279 """rjust(s, width) -> string
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
280
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
281 Return a right-justified version of s, in a field of the
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
282 specified width, padded with spaces as needed. The string is
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
283 never truncated.
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
284
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
285 """
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
286 n = width - len(s)
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
287 if n <= 0: return s
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
288 return ' '*n + s
5
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
289
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
290 # Center a string
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
291 def center(s, width):
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
292 """center(s, width) -> string
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
293
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
294 Return a center version of s, in a field of the specified
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
295 width. padded with spaces as needed. The string is never
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
296 truncated.
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
297
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
298 """
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
299 n = width - len(s)
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
300 if n <= 0: return s
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
301 half = n/2
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
302 if n%2 and width%2:
11742
840e18eec07f Untabify to pass the -tt test.
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
303 # This ensures that center(center(s, i), j) = center(s, j)
840e18eec07f Untabify to pass the -tt test.
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
304 half = half+1
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
305 return ' '*half + s + ' '*(n-half)
5
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
306
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
307 # Zero-fill a number, e.g., (12, 3) --> '012' and (-3, 3) --> '-03'
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
308 # Decadent feature: the argument may be a string or a number
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
309 # (Use of this is deprecated; it should be a string as with ljust c.s.)
5570dbb1ce55 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
310 def zfill(x, width):
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
311 """zfill(x, width) -> string
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
312
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
313 Pad a numeric string x with zeros on the left, to fill a field
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
314 of the specified width. The string x is never truncated.
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
315
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
316 """
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
317 if type(x) == type(''): s = x
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 16537
diff changeset
318 else: s = repr(x)
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
319 n = len(s)
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
320 if n >= width: return s
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
321 sign = ''
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
322 if s[0] in ('-', '+'):
11742
840e18eec07f Untabify to pass the -tt test.
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
323 sign, s = s[0], s[1:]
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
324 return sign + '0'*(width-n) + s
724
476bb7e5b854 Add function to expand tabs.
Guido van Rossum <guido@python.org>
parents: 585
diff changeset
325
476bb7e5b854 Add function to expand tabs.
Guido van Rossum <guido@python.org>
parents: 585
diff changeset
326 # Expand tabs in a string.
476bb7e5b854 Add function to expand tabs.
Guido van Rossum <guido@python.org>
parents: 585
diff changeset
327 # Doesn't take non-printing chars into account, but does understand \n.
2958
4f9d4e73057c default tabsize to 8
Guido van Rossum <guido@python.org>
parents: 2778
diff changeset
328 def expandtabs(s, tabsize=8):
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
329 """expandtabs(s [,tabsize]) -> string
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
330
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
331 Return a copy of the string s with all tab characters replaced
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
332 by the appropriate number of spaces, depending on the current
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
333 column, and the tabsize (default 8).
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
334
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
335 """
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
336 res = line = ''
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
337 for c in s:
11742
840e18eec07f Untabify to pass the -tt test.
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
338 if c == '\t':
840e18eec07f Untabify to pass the -tt test.
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
339 c = ' '*(tabsize - len(line) % tabsize)
840e18eec07f Untabify to pass the -tt test.
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
340 line = line + c
840e18eec07f Untabify to pass the -tt test.
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
341 if c == '\n':
840e18eec07f Untabify to pass the -tt test.
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
342 res = res + line
840e18eec07f Untabify to pass the -tt test.
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
343 line = ''
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
344 return res + line
1078
245003c006a6 Misc changes and new modules. whrandom is "objectified". SOCKET.py
Guido van Rossum <guido@python.org>
parents: 1052
diff changeset
345
3639
70183592370e add translate() -- which was in strop per release 1.3
Guido van Rossum <guido@python.org>
parents: 2958
diff changeset
346 # Character translation through look-up table.
3799
2f27501db3c3 Added 3rd optional argument to translate(), a string of characters to delete.
Guido van Rossum <guido@python.org>
parents: 3669
diff changeset
347 def translate(s, table, deletions=""):
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
348 """translate(s,table [,deletechars]) -> string
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
349
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
350 Return a copy of the string s, where all characters occurring
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
351 in the optional argument deletechars are removed, and the
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
352 remaining characters have been mapped through the given
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
353 translation table, which must be a string of length 256.
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
354
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
355 """
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
356 return s.translate(table, deletions)
1078
245003c006a6 Misc changes and new modules. whrandom is "objectified". SOCKET.py
Guido van Rossum <guido@python.org>
parents: 1052
diff changeset
357
3669
1d134ecda094 Added capitalize() and capwords().
Guido van Rossum <guido@python.org>
parents: 3639
diff changeset
358 # Capitalize a string, e.g. "aBc dEf" -> "Abc def".
1d134ecda094 Added capitalize() and capwords().
Guido van Rossum <guido@python.org>
parents: 3639
diff changeset
359 def capitalize(s):
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
360 """capitalize(s) -> string
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
361
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
362 Return a copy of the string s with only its first character
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
363 capitalized.
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
364
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
365 """
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
366 return s.capitalize()
3669
1d134ecda094 Added capitalize() and capwords().
Guido van Rossum <guido@python.org>
parents: 3639
diff changeset
367
1d134ecda094 Added capitalize() and capwords().
Guido van Rossum <guido@python.org>
parents: 3639
diff changeset
368 # Capitalize the words in a string, e.g. " aBc dEf " -> "Abc Def".
4076
eda29bef880c Add optional separator character to capwords(), for completeness.
Guido van Rossum <guido@python.org>
parents: 3957
diff changeset
369 def capwords(s, sep=None):
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
370 """capwords(s, [sep]) -> string
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
371
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
372 Split the argument into words using split, capitalize each
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
373 word using capitalize, and join the capitalized words using
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
374 join. Note that this replaces runs of whitespace characters by
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
375 a single space.
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
376
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
377 """
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
378 return join(map(capitalize, s.split(sep)), sep or ' ')
3669
1d134ecda094 Added capitalize() and capwords().
Guido van Rossum <guido@python.org>
parents: 3639
diff changeset
379
3799
2f27501db3c3 Added 3rd optional argument to translate(), a string of characters to delete.
Guido van Rossum <guido@python.org>
parents: 3669
diff changeset
380 # Construct a translation string
2f27501db3c3 Added 3rd optional argument to translate(), a string of characters to delete.
Guido van Rossum <guido@python.org>
parents: 3669
diff changeset
381 _idmapL = None
2f27501db3c3 Added 3rd optional argument to translate(), a string of characters to delete.
Guido van Rossum <guido@python.org>
parents: 3669
diff changeset
382 def maketrans(fromstr, tostr):
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
383 """maketrans(frm, to) -> string
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
384
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
385 Return a translation table (a string of 256 bytes long)
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
386 suitable for use in string.translate. The strings frm and to
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
387 must be of the same length.
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
388
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
389 """
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
390 if len(fromstr) != len(tostr):
11742
840e18eec07f Untabify to pass the -tt test.
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
391 raise ValueError, "maketrans arguments must have same length"
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
392 global _idmapL
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
393 if not _idmapL:
48018
49726dca16d8 Replace all map(None, a) with list(a).
Georg Brandl <georg@python.org>
parents: 46755
diff changeset
394 _idmapL = list(_idmap)
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
395 L = _idmapL[:]
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
396 fromstr = map(ord, fromstr)
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
397 for i in range(len(fromstr)):
11742
840e18eec07f Untabify to pass the -tt test.
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
398 L[fromstr[i]] = tostr[i]
16532
7fc64df13db0 String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents: 13620
diff changeset
399 return join(L, "")
3669
1d134ecda094 Added capitalize() and capwords().
Guido van Rossum <guido@python.org>
parents: 3639
diff changeset
400
5213
5b407e0cbc71 Added new functions replace() and replace1().
Guido van Rossum <guido@python.org>
parents: 5188
diff changeset
401 # Substring replacement (global)
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
402 def replace(s, old, new, maxsplit=0):
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
403 """replace (str, old, new[, maxsplit]) -> string
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
404
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
405 Return a copy of string str with all occurrences of substring
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
406 old replaced by new. If the optional argument maxsplit is
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
407 given, only the first maxsplit occurrences are replaced.
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
408
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
409 """
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
410 return s.replace(old, new, maxsplit)
6964
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
411
33be7d5d498b Added doc string, provided by Charles Waldman (with some reformatting
Guido van Rossum <guido@python.org>
parents: 6821
diff changeset
412
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
413 # XXX: transitional
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
414 #
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
415 # If string objects do not have methods, then we need to use the old string.py
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
416 # library, which uses strop for many more things than just the few outlined
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
417 # below.
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
418 try:
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
419 ''.upper
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
420 except AttributeError:
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
421 from stringold import *
5213
5b407e0cbc71 Added new functions replace() and replace1().
Guido van Rossum <guido@python.org>
parents: 5188
diff changeset
422
1078
245003c006a6 Misc changes and new modules. whrandom is "objectified". SOCKET.py
Guido van Rossum <guido@python.org>
parents: 1052
diff changeset
423 # Try importing optional built-in module "strop" -- if it exists,
245003c006a6 Misc changes and new modules. whrandom is "objectified". SOCKET.py
Guido van Rossum <guido@python.org>
parents: 1052
diff changeset
424 # it redefines some string operations that are 100-1000 times faster.
1331
07900834cc97 * pdb.py: set 'privileged' property when evaluating expressions
Guido van Rossum <guido@python.org>
parents: 1291
diff changeset
425 # It also defines values for whitespace, lowercase and uppercase
07900834cc97 * pdb.py: set 'privileged' property when evaluating expressions
Guido van Rossum <guido@python.org>
parents: 1291
diff changeset
426 # that match <ctype.h>'s definitions.
1078
245003c006a6 Misc changes and new modules. whrandom is "objectified". SOCKET.py
Guido van Rossum <guido@python.org>
parents: 1052
diff changeset
427
245003c006a6 Misc changes and new modules. whrandom is "objectified". SOCKET.py
Guido van Rossum <guido@python.org>
parents: 1052
diff changeset
428 try:
11383
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
429 from strop import maketrans, lowercase, uppercase, whitespace
aca7b5eaf5e8 Mainlining the string_methods branch. See branch revision log
Barry Warsaw <barry@python.org>
parents: 8091
diff changeset
430 letters = lowercase + uppercase
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1403
diff changeset
431 except ImportError:
11742
840e18eec07f Untabify to pass the -tt test.
Fred Drake <fdrake@acm.org>
parents: 11383
diff changeset
432 pass # Use the original versions