From a5e2a25139a03fece22a1447fc37c756154235dc Mon Sep 17 00:00:00 2001 From: blob8108 Date: Fri, 28 Mar 2014 12:15:45 +0000 Subject: Fix percent-sign handling in block text --- blockext/__init__.py | 8 +++++--- blockext/snap.py | 6 +++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/blockext/__init__.py b/blockext/__init__.py index 1e2b4a6..aebbb03 100644 --- a/blockext/__init__.py +++ b/blockext/__init__.py @@ -220,7 +220,7 @@ def index(is_browser=False): class Block(object): - INPUT_RE = re.compile(r'(%.(?:\.[A-z]+)?)') + INPUT_RE = re.compile(r'(%[^ ](?:\.[A-z]+)?)') SHAPE_FMTS = { "predicate": "<%s>", @@ -258,7 +258,8 @@ class Block(object): self.arg_shapes = [] for part in Block.INPUT_RE.split(self.text): - if part.startswith("%") and part != "%%": + match = Block.INPUT_RE.match(part) + if match and match.group() == part: assert part[1] in "nbsmd" if part[1] in "md": assert "." in part @@ -285,7 +286,8 @@ class Block(object): r = "" defaults = list(self.defaults) for part in Block.INPUT_RE.split(self.text): - if part.startswith("%") and part != "%%": + match = Block.INPUT_RE.match(part) + if match and match.group() == part: shape = part[1] fmt = Block.INPUT_FMTS.get(shape, "%s") value = defaults.pop(0) diff --git a/blockext/snap.py b/blockext/snap.py index d176524..4a67a67 100644 --- a/blockext/snap.py +++ b/blockext/snap.py @@ -42,7 +42,8 @@ def generate_xml(is_browser=False): defaults = list(block.defaults) selector = "" for part in Block.INPUT_RE.split(block.text): - if part.startswith("%") and part != "%%": + match = Block.INPUT_RE.match(part) + if match and match.group() == part: shape = part[1] input_ = SubElement(inputs, "input", { "type": "%{shape}".format(shape=INPUT_SELECTORS[shape]), @@ -58,6 +59,9 @@ def generate_xml(is_browser=False): input_name = input_names.pop(0) if input_names else "" part = "%'{name}'".format(name=input_name) + else: + # Snap! doesn't allow %-signs in block text yet. + part = part.replace("%", " ").replace(" ", " ") selector += part defn.attrib["s"] = selector -- cgit v1.3.1