Add module string replacement during bootstrap

git-svn-id: http://svn.pyinstaller.org/trunk@37 8dd32b29-ccff-0310-8a9a-9233e24343b1
This commit is contained in:
giovannibajo
2005-09-12 08:25:18 +00:00
parent 81c8859668
commit 5a2234aaa6
2 changed files with 61 additions and 3 deletions
+3 -2
View File
@@ -15,11 +15,12 @@
_verbose = 0
_listdir = None
_environ = None
# **NOTE** This module is used during bootstrap. Import *ONLY* builtin modules.
import marshal
import struct
import imp
import sys
import string
_c_suffixes = filter(lambda x: x[2] == imp.C_EXTENSION, imp.get_suffixes())
@@ -325,7 +326,7 @@ class ZlibArchive(Archive):
except (IOError, ValueError, EOFError, AttributeError):
raise ValueError("bad bytecode in %s and no source" % pth)
else:
txt = string.join(string.split(txt, '\r\n'), '\n')
txt = iu._string_replace(txt, '\r\n', '\n')
try:
co = compile(txt, "%s/%s" % (self.path, nm), 'exec')
except SyntaxError, e:
+58 -1
View File
@@ -1,3 +1,4 @@
# **NOTE** This module is used during bootstrap. Import *ONLY* builtin modules.
import sys
import imp
import marshal
@@ -496,5 +497,61 @@ def _os_bootstrap():
global _os_getcwd
_os_getcwd = getcwd
_os_bootstrap()
_string_replace = _string_join = _string_split = None
def _string_bootstrap():
"""
Set up 'string' module replacement functions for use during import bootstrap.
During bootstrap, we can use only builtin modules since import does not work
yet. For Python 2.0+, we can use string methods so this is not a problem.
For Python 1.5, we would need the string module, so we need replacements.
"""
s = type('')
global _string_replace, _string_join, _string_split
if hasattr(s, "join"):
_string_join = s.join
else:
def join(sep, words):
res = ''
for w in words:
res = res + (sep + w)
return res[len(sep):]
_string_join = join
if hasattr(s, "split"):
_string_split = s.split
else:
def split(s, sep, maxsplit=0):
res = []
nsep = len(sep)
if nsep == 0:
return [s]
ns = len(s)
if maxsplit <= 0: maxsplit = ns
i = j = 0
count = 0
while j+nsep <= ns:
if s[j:j+nsep] == sep:
count = count + 1
res.append(s[i:j])
i = j = j + nsep
if count >= maxsplit: break
else:
j = j + 1
res.append(s[i:])
return res
_string_split = split
if hasattr(s, "replace"):
_string_replace = s.replace
else:
def replace(str, old, new):
return _string_join(new, _string_split(str, old))
_string_replace = replace
_os_bootstrap()
_string_bootstrap()