escape 8-bit chars when generating .py files. fixes bug #566302

This commit is contained in:
Just van Rossum 2002-06-09 09:08:53 +00:00
parent 47df99d575
commit ec5d6b908c
1 changed files with 16 additions and 1 deletions

View File

@ -433,6 +433,7 @@ if missing: raise "Missing Types"
def dosymdef(self, match):
name, defn = match.group('name', 'defn')
defn = escape8bit(defn)
if self.debug:
self.report("\tsym: name=%s, defn=%s" % (`name`, `defn`))
if not name in self.blacklistnames:
@ -639,6 +640,20 @@ class Scanner_OSX(Scanner):
self.sym_pat = "^[ \t]*(?P<name>[a-zA-Z0-9_]+)[ \t]*=" + \
"[ \t]*(?P<defn>[-0-9_a-zA-Z'\"\(][^\t\n,;}]*),?"
_8bit = re.compile(r"[\200-\377]")
def escape8bit(s):
if _8bit.search(s) is not None:
out = []
for c in s:
o = ord(c)
if o >= 128:
out.append("\\" + hex(o)[1:])
else:
out.append(c)
s = "".join(out)
return s
def test():
input = "D:Development:THINK C:Mac #includes:Apple #includes:AppleEvents.h"
output = "@aespecs.py"