| 1 | n/a | # module 'string' -- A collection of string operations |
|---|
| 2 | n/a | |
|---|
| 3 | n/a | # Warning: most of the code you see here isn't normally used nowadays. With |
|---|
| 4 | n/a | # Python 1.6, many of these functions are implemented as methods on the |
|---|
| 5 | n/a | # standard string object. They used to be implemented by a built-in module |
|---|
| 6 | n/a | # called strop, but strop is now obsolete itself. |
|---|
| 7 | n/a | |
|---|
| 8 | n/a | """Common string manipulations. |
|---|
| 9 | n/a | |
|---|
| 10 | n/a | Public module variables: |
|---|
| 11 | n/a | |
|---|
| 12 | n/a | whitespace -- a string containing all characters considered whitespace |
|---|
| 13 | n/a | lowercase -- a string containing all characters considered lowercase letters |
|---|
| 14 | n/a | uppercase -- a string containing all characters considered uppercase letters |
|---|
| 15 | n/a | letters -- a string containing all characters considered letters |
|---|
| 16 | n/a | digits -- a string containing all characters considered decimal digits |
|---|
| 17 | n/a | hexdigits -- a string containing all characters considered hexadecimal digits |
|---|
| 18 | n/a | octdigits -- a string containing all characters considered octal digits |
|---|
| 19 | n/a | |
|---|
| 20 | 1 | """ |
|---|
| 21 | 1 | from warnings import warnpy3k |
|---|
| 22 | 1 | warnpy3k("the stringold module has been removed in Python 3.0", stacklevel=2) |
|---|
| 23 | 1 | del warnpy3k |
|---|
| 24 | n/a | |
|---|
| 25 | n/a | # Some strings for ctype-style character classification |
|---|
| 26 | 1 | whitespace = ' \t\n\r\v\f' |
|---|
| 27 | 1 | lowercase = 'abcdefghijklmnopqrstuvwxyz' |
|---|
| 28 | 1 | uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
|---|
| 29 | 1 | letters = lowercase + uppercase |
|---|
| 30 | 1 | digits = '0123456789' |
|---|
| 31 | 1 | hexdigits = digits + 'abcdef' + 'ABCDEF' |
|---|
| 32 | 1 | octdigits = '01234567' |
|---|
| 33 | n/a | |
|---|
| 34 | n/a | # Case conversion helpers |
|---|
| 35 | 1 | _idmap = '' |
|---|
| 36 | 257 | for i in range(256): _idmap = _idmap + chr(i) |
|---|
| 37 | 1 | del i |
|---|
| 38 | n/a | |
|---|
| 39 | n/a | # Backward compatible names for exceptions |
|---|
| 40 | 1 | index_error = ValueError |
|---|
| 41 | 1 | atoi_error = ValueError |
|---|
| 42 | 1 | atof_error = ValueError |
|---|
| 43 | 1 | atol_error = ValueError |
|---|
| 44 | n/a | |
|---|
| 45 | n/a | # convert UPPER CASE letters to lower case |
|---|
| 46 | 1 | def lower(s): |
|---|
| 47 | n/a | """lower(s) -> string |
|---|
| 48 | n/a | |
|---|
| 49 | n/a | Return a copy of the string s converted to lowercase. |
|---|
| 50 | n/a | |
|---|
| 51 | n/a | """ |
|---|
| 52 | 0 | return s.lower() |
|---|
| 53 | n/a | |
|---|
| 54 | n/a | # Convert lower case letters to UPPER CASE |
|---|
| 55 | 1 | def upper(s): |
|---|
| 56 | n/a | """upper(s) -> string |
|---|
| 57 | n/a | |
|---|
| 58 | n/a | Return a copy of the string s converted to uppercase. |
|---|
| 59 | n/a | |
|---|
| 60 | n/a | """ |
|---|
| 61 | 0 | return s.upper() |
|---|
| 62 | n/a | |
|---|
| 63 | n/a | # Swap lower case letters and UPPER CASE |
|---|
| 64 | 1 | def swapcase(s): |
|---|
| 65 | n/a | """swapcase(s) -> string |
|---|
| 66 | n/a | |
|---|
| 67 | n/a | Return a copy of the string s with upper case characters |
|---|
| 68 | n/a | converted to lowercase and vice versa. |
|---|
| 69 | n/a | |
|---|
| 70 | n/a | """ |
|---|
| 71 | 0 | return s.swapcase() |
|---|
| 72 | n/a | |
|---|
| 73 | n/a | # Strip leading and trailing tabs and spaces |
|---|
| 74 | 1 | def strip(s): |
|---|
| 75 | n/a | """strip(s) -> string |
|---|
| 76 | n/a | |
|---|
| 77 | n/a | Return a copy of the string s with leading and trailing |
|---|
| 78 | n/a | whitespace removed. |
|---|
| 79 | n/a | |
|---|
| 80 | n/a | """ |
|---|
| 81 | 0 | return s.strip() |
|---|
| 82 | n/a | |
|---|
| 83 | n/a | # Strip leading tabs and spaces |
|---|
| 84 | 1 | def lstrip(s): |
|---|
| 85 | n/a | """lstrip(s) -> string |
|---|
| 86 | n/a | |
|---|
| 87 | n/a | Return a copy of the string s with leading whitespace removed. |
|---|
| 88 | n/a | |
|---|
| 89 | n/a | """ |
|---|
| 90 | 0 | return s.lstrip() |
|---|
| 91 | n/a | |
|---|
| 92 | n/a | # Strip trailing tabs and spaces |
|---|
| 93 | 1 | def rstrip(s): |
|---|
| 94 | n/a | """rstrip(s) -> string |
|---|
| 95 | n/a | |
|---|
| 96 | n/a | Return a copy of the string s with trailing whitespace |
|---|
| 97 | n/a | removed. |
|---|
| 98 | n/a | |
|---|
| 99 | n/a | """ |
|---|
| 100 | 0 | return s.rstrip() |
|---|
| 101 | n/a | |
|---|
| 102 | n/a | |
|---|
| 103 | n/a | # Split a string into a list of space/tab-separated words |
|---|
| 104 | 1 | def split(s, sep=None, maxsplit=0): |
|---|
| 105 | n/a | """split(str [,sep [,maxsplit]]) -> list of strings |
|---|
| 106 | n/a | |
|---|
| 107 | n/a | Return a list of the words in the string s, using sep as the |
|---|
| 108 | n/a | delimiter string. If maxsplit is nonzero, splits into at most |
|---|
| 109 | n/a | maxsplit words If sep is not specified, any whitespace string |
|---|
| 110 | n/a | is a separator. Maxsplit defaults to 0. |
|---|
| 111 | n/a | |
|---|
| 112 | n/a | (split and splitfields are synonymous) |
|---|
| 113 | n/a | |
|---|
| 114 | n/a | """ |
|---|
| 115 | 0 | return s.split(sep, maxsplit) |
|---|
| 116 | 1 | splitfields = split |
|---|
| 117 | n/a | |
|---|
| 118 | n/a | # Join fields with optional separator |
|---|
| 119 | 1 | def join(words, sep = ' '): |
|---|
| 120 | n/a | """join(list [,sep]) -> string |
|---|
| 121 | n/a | |
|---|
| 122 | n/a | Return a string composed of the words in list, with |
|---|
| 123 | n/a | intervening occurrences of sep. The default separator is a |
|---|
| 124 | n/a | single space. |
|---|
| 125 | n/a | |
|---|
| 126 | n/a | (joinfields and join are synonymous) |
|---|
| 127 | n/a | |
|---|
| 128 | n/a | """ |
|---|
| 129 | 0 | return sep.join(words) |
|---|
| 130 | 1 | joinfields = join |
|---|
| 131 | n/a | |
|---|
| 132 | n/a | # for a little bit of speed |
|---|
| 133 | 1 | _apply = apply |
|---|
| 134 | n/a | |
|---|
| 135 | n/a | # Find substring, raise exception if not found |
|---|
| 136 | 1 | def index(s, *args): |
|---|
| 137 | n/a | """index(s, sub [,start [,end]]) -> int |
|---|
| 138 | n/a | |
|---|
| 139 | n/a | Like find but raises ValueError when the substring is not found. |
|---|
| 140 | n/a | |
|---|
| 141 | n/a | """ |
|---|
| 142 | 0 | return _apply(s.index, args) |
|---|
| 143 | n/a | |
|---|
| 144 | n/a | # Find last substring, raise exception if not found |
|---|
| 145 | 1 | def rindex(s, *args): |
|---|
| 146 | n/a | """rindex(s, sub [,start [,end]]) -> int |
|---|
| 147 | n/a | |
|---|
| 148 | n/a | Like rfind but raises ValueError when the substring is not found. |
|---|
| 149 | n/a | |
|---|
| 150 | n/a | """ |
|---|
| 151 | 0 | return _apply(s.rindex, args) |
|---|
| 152 | n/a | |
|---|
| 153 | n/a | # Count non-overlapping occurrences of substring |
|---|
| 154 | 1 | def count(s, *args): |
|---|
| 155 | n/a | """count(s, sub[, start[,end]]) -> int |
|---|
| 156 | n/a | |
|---|
| 157 | n/a | Return the number of occurrences of substring sub in string |
|---|
| 158 | n/a | s[start:end]. Optional arguments start and end are |
|---|
| 159 | n/a | interpreted as in slice notation. |
|---|
| 160 | n/a | |
|---|
| 161 | n/a | """ |
|---|
| 162 | 0 | return _apply(s.count, args) |
|---|
| 163 | n/a | |
|---|
| 164 | n/a | # Find substring, return -1 if not found |
|---|
| 165 | 1 | def find(s, *args): |
|---|
| 166 | n/a | """find(s, sub [,start [,end]]) -> in |
|---|
| 167 | n/a | |
|---|
| 168 | n/a | Return the lowest index in s where substring sub is found, |
|---|
| 169 | n/a | such that sub is contained within s[start,end]. Optional |
|---|
| 170 | n/a | arguments start and end are interpreted as in slice notation. |
|---|
| 171 | n/a | |
|---|
| 172 | n/a | Return -1 on failure. |
|---|
| 173 | n/a | |
|---|
| 174 | n/a | """ |
|---|
| 175 | 0 | return _apply(s.find, args) |
|---|
| 176 | n/a | |
|---|
| 177 | n/a | # Find last substring, return -1 if not found |
|---|
| 178 | 1 | def rfind(s, *args): |
|---|
| 179 | n/a | """rfind(s, sub [,start [,end]]) -> int |
|---|
| 180 | n/a | |
|---|
| 181 | n/a | Return the highest index in s where substring sub is found, |
|---|
| 182 | n/a | such that sub is contained within s[start,end]. Optional |
|---|
| 183 | n/a | arguments start and end are interpreted as in slice notation. |
|---|
| 184 | n/a | |
|---|
| 185 | n/a | Return -1 on failure. |
|---|
| 186 | n/a | |
|---|
| 187 | n/a | """ |
|---|
| 188 | 0 | return _apply(s.rfind, args) |
|---|
| 189 | n/a | |
|---|
| 190 | n/a | # for a bit of speed |
|---|
| 191 | 1 | _float = float |
|---|
| 192 | 1 | _int = int |
|---|
| 193 | 1 | _long = long |
|---|
| 194 | 1 | _StringType = type('') |
|---|
| 195 | n/a | |
|---|
| 196 | n/a | # Convert string to float |
|---|
| 197 | 1 | def atof(s): |
|---|
| 198 | n/a | """atof(s) -> float |
|---|
| 199 | n/a | |
|---|
| 200 | n/a | Return the floating point number represented by the string s. |
|---|
| 201 | n/a | |
|---|
| 202 | n/a | """ |
|---|
| 203 | 0 | if type(s) == _StringType: |
|---|
| 204 | 0 | return _float(s) |
|---|
| 205 | n/a | else: |
|---|
| 206 | 0 | raise TypeError('argument 1: expected string, %s found' % |
|---|
| 207 | 0 | type(s).__name__) |
|---|
| 208 | n/a | |
|---|
| 209 | n/a | # Convert string to integer |
|---|
| 210 | 1 | def atoi(*args): |
|---|
| 211 | n/a | """atoi(s [,base]) -> int |
|---|
| 212 | n/a | |
|---|
| 213 | n/a | Return the integer represented by the string s in the given |
|---|
| 214 | n/a | base, which defaults to 10. The string s must consist of one |
|---|
| 215 | n/a | or more digits, possibly preceded by a sign. If base is 0, it |
|---|
| 216 | n/a | is chosen from the leading characters of s, 0 for octal, 0x or |
|---|
| 217 | n/a | 0X for hexadecimal. If base is 16, a preceding 0x or 0X is |
|---|
| 218 | n/a | accepted. |
|---|
| 219 | n/a | |
|---|
| 220 | n/a | """ |
|---|
| 221 | 0 | try: |
|---|
| 222 | 0 | s = args[0] |
|---|
| 223 | 0 | except IndexError: |
|---|
| 224 | 0 | raise TypeError('function requires at least 1 argument: %d given' % |
|---|
| 225 | 0 | len(args)) |
|---|
| 226 | n/a | # Don't catch type error resulting from too many arguments to int(). The |
|---|
| 227 | n/a | # error message isn't compatible but the error type is, and this function |
|---|
| 228 | n/a | # is complicated enough already. |
|---|
| 229 | 0 | if type(s) == _StringType: |
|---|
| 230 | 0 | return _apply(_int, args) |
|---|
| 231 | n/a | else: |
|---|
| 232 | 0 | raise TypeError('argument 1: expected string, %s found' % |
|---|
| 233 | 0 | type(s).__name__) |
|---|
| 234 | n/a | |
|---|
| 235 | n/a | |
|---|
| 236 | n/a | # Convert string to long integer |
|---|
| 237 | 1 | def atol(*args): |
|---|
| 238 | n/a | """atol(s [,base]) -> long |
|---|
| 239 | n/a | |
|---|
| 240 | n/a | Return the long integer represented by the string s in the |
|---|
| 241 | n/a | given base, which defaults to 10. The string s must consist |
|---|
| 242 | n/a | of one or more digits, possibly preceded by a sign. If base |
|---|
| 243 | n/a | is 0, it is chosen from the leading characters of s, 0 for |
|---|
| 244 | n/a | octal, 0x or 0X for hexadecimal. If base is 16, a preceding |
|---|
| 245 | n/a | 0x or 0X is accepted. A trailing L or l is not accepted, |
|---|
| 246 | n/a | unless base is 0. |
|---|
| 247 | n/a | |
|---|
| 248 | n/a | """ |
|---|
| 249 | 0 | try: |
|---|
| 250 | 0 | s = args[0] |
|---|
| 251 | 0 | except IndexError: |
|---|
| 252 | 0 | raise TypeError('function requires at least 1 argument: %d given' % |
|---|
| 253 | 0 | len(args)) |
|---|
| 254 | n/a | # Don't catch type error resulting from too many arguments to long(). The |
|---|
| 255 | n/a | # error message isn't compatible but the error type is, and this function |
|---|
| 256 | n/a | # is complicated enough already. |
|---|
| 257 | 0 | if type(s) == _StringType: |
|---|
| 258 | 0 | return _apply(_long, args) |
|---|
| 259 | n/a | else: |
|---|
| 260 | 0 | raise TypeError('argument 1: expected string, %s found' % |
|---|
| 261 | 0 | type(s).__name__) |
|---|
| 262 | n/a | |
|---|
| 263 | n/a | |
|---|
| 264 | n/a | # Left-justify a string |
|---|
| 265 | 1 | def ljust(s, width): |
|---|
| 266 | n/a | """ljust(s, width) -> string |
|---|
| 267 | n/a | |
|---|
| 268 | n/a | Return a left-justified version of s, in a field of the |
|---|
| 269 | n/a | specified width, padded with spaces as needed. The string is |
|---|
| 270 | n/a | never truncated. |
|---|
| 271 | n/a | |
|---|
| 272 | n/a | """ |
|---|
| 273 | 0 | n = width - len(s) |
|---|
| 274 | 0 | if n <= 0: return s |
|---|
| 275 | 0 | return s + ' '*n |
|---|
| 276 | n/a | |
|---|
| 277 | n/a | # Right-justify a string |
|---|
| 278 | 1 | def rjust(s, width): |
|---|
| 279 | n/a | """rjust(s, width) -> string |
|---|
| 280 | n/a | |
|---|
| 281 | n/a | Return a right-justified version of s, in a field of the |
|---|
| 282 | n/a | specified width, padded with spaces as needed. The string is |
|---|
| 283 | n/a | never truncated. |
|---|
| 284 | n/a | |
|---|
| 285 | n/a | """ |
|---|
| 286 | 0 | n = width - len(s) |
|---|
| 287 | 0 | if n <= 0: return s |
|---|
| 288 | 0 | return ' '*n + s |
|---|
| 289 | n/a | |
|---|
| 290 | n/a | # Center a string |
|---|
| 291 | 1 | def center(s, width): |
|---|
| 292 | n/a | """center(s, width) -> string |
|---|
| 293 | n/a | |
|---|
| 294 | n/a | Return a center version of s, in a field of the specified |
|---|
| 295 | n/a | width. padded with spaces as needed. The string is never |
|---|
| 296 | n/a | truncated. |
|---|
| 297 | n/a | |
|---|
| 298 | n/a | """ |
|---|
| 299 | 0 | n = width - len(s) |
|---|
| 300 | 0 | if n <= 0: return s |
|---|
| 301 | 0 | half = n/2 |
|---|
| 302 | 0 | if n%2 and width%2: |
|---|
| 303 | n/a | # This ensures that center(center(s, i), j) = center(s, j) |
|---|
| 304 | 0 | half = half+1 |
|---|
| 305 | 0 | return ' '*half + s + ' '*(n-half) |
|---|
| 306 | n/a | |
|---|
| 307 | n/a | # Zero-fill a number, e.g., (12, 3) --> '012' and (-3, 3) --> '-03' |
|---|
| 308 | n/a | # Decadent feature: the argument may be a string or a number |
|---|
| 309 | n/a | # (Use of this is deprecated; it should be a string as with ljust c.s.) |
|---|
| 310 | 1 | def zfill(x, width): |
|---|
| 311 | n/a | """zfill(x, width) -> string |
|---|
| 312 | n/a | |
|---|
| 313 | n/a | Pad a numeric string x with zeros on the left, to fill a field |
|---|
| 314 | n/a | of the specified width. The string x is never truncated. |
|---|
| 315 | n/a | |
|---|
| 316 | n/a | """ |
|---|
| 317 | 0 | if type(x) == type(''): s = x |
|---|
| 318 | 0 | else: s = repr(x) |
|---|
| 319 | 0 | n = len(s) |
|---|
| 320 | 0 | if n >= width: return s |
|---|
| 321 | 0 | sign = '' |
|---|
| 322 | 0 | if s[0] in ('-', '+'): |
|---|
| 323 | 0 | sign, s = s[0], s[1:] |
|---|
| 324 | 0 | return sign + '0'*(width-n) + s |
|---|
| 325 | n/a | |
|---|
| 326 | n/a | # Expand tabs in a string. |
|---|
| 327 | n/a | # Doesn't take non-printing chars into account, but does understand \n. |
|---|
| 328 | 1 | def expandtabs(s, tabsize=8): |
|---|
| 329 | n/a | """expandtabs(s [,tabsize]) -> string |
|---|
| 330 | n/a | |
|---|
| 331 | n/a | Return a copy of the string s with all tab characters replaced |
|---|
| 332 | n/a | by the appropriate number of spaces, depending on the current |
|---|
| 333 | n/a | column, and the tabsize (default 8). |
|---|
| 334 | n/a | |
|---|
| 335 | n/a | """ |
|---|
| 336 | 0 | res = line = '' |
|---|
| 337 | 0 | for c in s: |
|---|
| 338 | 0 | if c == '\t': |
|---|
| 339 | 0 | c = ' '*(tabsize - len(line) % tabsize) |
|---|
| 340 | 0 | line = line + c |
|---|
| 341 | 0 | if c == '\n': |
|---|
| 342 | 0 | res = res + line |
|---|
| 343 | 0 | line = '' |
|---|
| 344 | 0 | return res + line |
|---|
| 345 | n/a | |
|---|
| 346 | n/a | # Character translation through look-up table. |
|---|
| 347 | 1 | def translate(s, table, deletions=""): |
|---|
| 348 | n/a | """translate(s,table [,deletechars]) -> string |
|---|
| 349 | n/a | |
|---|
| 350 | n/a | Return a copy of the string s, where all characters occurring |
|---|
| 351 | n/a | in the optional argument deletechars are removed, and the |
|---|
| 352 | n/a | remaining characters have been mapped through the given |
|---|
| 353 | n/a | translation table, which must be a string of length 256. |
|---|
| 354 | n/a | |
|---|
| 355 | n/a | """ |
|---|
| 356 | 0 | return s.translate(table, deletions) |
|---|
| 357 | n/a | |
|---|
| 358 | n/a | # Capitalize a string, e.g. "aBc dEf" -> "Abc def". |
|---|
| 359 | 1 | def capitalize(s): |
|---|
| 360 | n/a | """capitalize(s) -> string |
|---|
| 361 | n/a | |
|---|
| 362 | n/a | Return a copy of the string s with only its first character |
|---|
| 363 | n/a | capitalized. |
|---|
| 364 | n/a | |
|---|
| 365 | n/a | """ |
|---|
| 366 | 0 | return s.capitalize() |
|---|
| 367 | n/a | |
|---|
| 368 | n/a | # Capitalize the words in a string, e.g. " aBc dEf " -> "Abc Def". |
|---|
| 369 | 1 | def capwords(s, sep=None): |
|---|
| 370 | n/a | """capwords(s, [sep]) -> string |
|---|
| 371 | n/a | |
|---|
| 372 | n/a | Split the argument into words using split, capitalize each |
|---|
| 373 | n/a | word using capitalize, and join the capitalized words using |
|---|
| 374 | n/a | join. Note that this replaces runs of whitespace characters by |
|---|
| 375 | n/a | a single space. |
|---|
| 376 | n/a | |
|---|
| 377 | n/a | """ |
|---|
| 378 | 0 | return join(map(capitalize, s.split(sep)), sep or ' ') |
|---|
| 379 | n/a | |
|---|
| 380 | n/a | # Construct a translation string |
|---|
| 381 | 1 | _idmapL = None |
|---|
| 382 | 1 | def maketrans(fromstr, tostr): |
|---|
| 383 | n/a | """maketrans(frm, to) -> string |
|---|
| 384 | n/a | |
|---|
| 385 | n/a | Return a translation table (a string of 256 bytes long) |
|---|
| 386 | n/a | suitable for use in string.translate. The strings frm and to |
|---|
| 387 | n/a | must be of the same length. |
|---|
| 388 | n/a | |
|---|
| 389 | n/a | """ |
|---|
| 390 | 0 | if len(fromstr) != len(tostr): |
|---|
| 391 | 0 | raise ValueError, "maketrans arguments must have same length" |
|---|
| 392 | n/a | global _idmapL |
|---|
| 393 | 0 | if not _idmapL: |
|---|
| 394 | 0 | _idmapL = list(_idmap) |
|---|
| 395 | 0 | L = _idmapL[:] |
|---|
| 396 | 0 | fromstr = map(ord, fromstr) |
|---|
| 397 | 0 | for i in range(len(fromstr)): |
|---|
| 398 | 0 | L[fromstr[i]] = tostr[i] |
|---|
| 399 | 0 | return join(L, "") |
|---|
| 400 | n/a | |
|---|
| 401 | n/a | # Substring replacement (global) |
|---|
| 402 | 1 | def replace(s, old, new, maxsplit=0): |
|---|
| 403 | n/a | """replace (str, old, new[, maxsplit]) -> string |
|---|
| 404 | n/a | |
|---|
| 405 | n/a | Return a copy of string str with all occurrences of substring |
|---|
| 406 | n/a | old replaced by new. If the optional argument maxsplit is |
|---|
| 407 | n/a | given, only the first maxsplit occurrences are replaced. |
|---|
| 408 | n/a | |
|---|
| 409 | n/a | """ |
|---|
| 410 | 0 | return s.replace(old, new, maxsplit) |
|---|
| 411 | n/a | |
|---|
| 412 | n/a | |
|---|
| 413 | n/a | # XXX: transitional |
|---|
| 414 | n/a | # |
|---|
| 415 | n/a | # If string objects do not have methods, then we need to use the old string.py |
|---|
| 416 | n/a | # library, which uses strop for many more things than just the few outlined |
|---|
| 417 | n/a | # below. |
|---|
| 418 | 1 | try: |
|---|
| 419 | 1 | ''.upper |
|---|
| 420 | 0 | except AttributeError: |
|---|
| 421 | 0 | from stringold import * |
|---|
| 422 | n/a | |
|---|
| 423 | n/a | # Try importing optional built-in module "strop" -- if it exists, |
|---|
| 424 | n/a | # it redefines some string operations that are 100-1000 times faster. |
|---|
| 425 | n/a | # It also defines values for whitespace, lowercase and uppercase |
|---|
| 426 | n/a | # that match <ctype.h>'s definitions. |
|---|
| 427 | n/a | |
|---|
| 428 | 1 | try: |
|---|
| 429 | 1 | from strop import maketrans, lowercase, uppercase, whitespace |
|---|
| 430 | 1 | letters = lowercase + uppercase |
|---|
| 431 | 0 | except ImportError: |
|---|
| 432 | 0 | pass # Use the original versions |
|---|