Changeset 37

Show
Ignore:
Timestamp:
Mon Sep 12 03:25:18 2005
Author:
giovannibajo
Message:

Add module string replacement during bootstrap

Files:

Legend:

Unmodified
Added
Removed
Modified
  • trunk/iu.py

    r5 r37  
      1 # **NOTE** This module is used during bootstrap. Import *ONLY* builtin modules.  
    1 2 import sys  
    2 3 import imp  
     
    497 498     _os_getcwd = getcwd  
    498 499  
    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  
    500 553  
      554  
      555  
      556 _os_bootstrap()  
      557 _string_bootstrap()  
  • trunk/archive.py

    r6 r37  
    16 16 _listdir = None  
    17 17 _environ = None  
      18  
      19 # **NOTE** This module is used during bootstrap. Import *ONLY* builtin modules.  
    18 20 import marshal  
    19 21 import struct  
    20 22 import imp  
    21 23 import sys  
    22   import string  
    23 24  
    24 25 _c_suffixes = filter(lambda x: x[2] == imp.C_EXTENSION, imp.get_suffixes())  
     
    326 327                 raise ValueError("bad bytecode in %s and no source" % pth)  
    327 328         else:  
    328               txt = string.join(string.split(txt, '\r\n'), '\n')  
      329             txt = iu._string_replace(txt, '\r\n', '\n')  
    328 329             try:  
    329 330                 co = compile(txt, "%s/%s" % (self.path, nm), 'exec')