From ec5d6b908c25d45ffcf5b5ad60cdb51b38b6a769 Mon Sep 17 00:00:00 2001 From: Just van Rossum Date: Sun, 9 Jun 2002 09:08:53 +0000 Subject: escape 8-bit chars when generating .py files. fixes bug #566302 --- Tools/bgen/bgen/scantools.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Tools/bgen/bgen/scantools.py b/Tools/bgen/bgen/scantools.py index 768b3b7..9256c4f 100644 --- a/Tools/bgen/bgen/scantools.py +++ b/Tools/bgen/bgen/scantools.py @@ -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: @@ -638,7 +639,21 @@ class Scanner_OSX(Scanner): self.whole_pat = self.type_pat + self.name_pat + self.args_pat self.sym_pat = "^[ \t]*(?P[a-zA-Z0-9_]+)[ \t]*=" + \ "[ \t]*(?P[-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" -- cgit v0.12