| 499 |
|
_os_bootstrap()
|
| |
500 |
_string_replace = _string_join = _string_split = None
|
| |
501 |
def _string_bootstrap():
|
| |
502 |
"""
|
| |
503 |
Set up 'string' module replacement functions for use during import bootstrap.
|
| |
504 |
|
| |
505 |
During bootstrap, we can use only builtin modules since import does not work
|
| |
506 |
yet. For Python 2.0+, we can use string methods so this is not a problem.
|
| |
507 |
For Python 1.5, we would need the string module, so we need replacements.
|
| |
508 |
"""
|
| |
509 |
s = type('')
|
| |
510 |
|
| |
511 |
global _string_replace, _string_join, _string_split
|
| |
512 |
|
| |
513 |
if hasattr(s, "join"):
|
| |
514 |
_string_join = s.join
|
| |
515 |
else:
|
| |
516 |
def join(sep, words):
|
| |
517 |
res = ''
|
| |
518 |
for w in words:
|
| |
519 |
res = res + (sep + w)
|
| |
520 |
return res[len(sep):]
|
| |
521 |
_string_join = join
|
| |
522 |
|
| |
523 |
if hasattr(s, "split"):
|
| |
524 |
_string_split = s.split
|
| |
525 |
else:
|
| |
526 |
def split(s, sep, maxsplit=0):
|
| |
527 |
res = []
|
| |
528 |
nsep = len(sep)
|
| |
529 |
if nsep == 0:
|
| |
530 |
return [s]
|
| |
531 |
ns = len(s)
|
| |
532 |
if maxsplit <= 0: maxsplit = ns
|
| |
533 |
i = j = 0
|
| |
534 |
count = 0
|
| |
535 |
while j+nsep <= ns:
|
| |
536 |
if s[j:j+nsep] == sep:
|
| |
537 |
count = count + 1
|
| |
538 |
res.append(s[i:j])
|
| |
539 |
i = j = j + nsep
|
| |
540 |
if count >= maxsplit: break
|
| |
541 |
else:
|
| |
542 |
j = j + 1
|
| |
543 |
res.append(s[i:])
|
| |
544 |
return res
|
| |
545 |
_string_split = split
|
| |
546 |
|
| |
547 |
if hasattr(s, "replace"):
|
| |
548 |
_string_replace = s.replace
|
| |
549 |
else:
|
| |
550 |
def replace(str, old, new):
|
| |
551 |
return _string_join(new, _string_split(str, old))
|
| |
552 |
_string_replace = replace
|