diff options
| author | blob8108 <spaaam42@gmail.com> | 2014-03-28 12:15:45 +0000 |
|---|---|---|
| committer | blob8108 <spaaam42@gmail.com> | 2014-03-28 12:15:45 +0000 |
| commit | a5e2a25139a03fece22a1447fc37c756154235dc (patch) | |
| tree | 62ea6005a39bd1da6bfde7df945ee6801cba5555 | |
| parent | cdfeae6096644486690f126e4351dcdcd9b604ca (diff) | |
| download | blockext-a5e2a25139a03fece22a1447fc37c756154235dc.tar.gz blockext-a5e2a25139a03fece22a1447fc37c756154235dc.zip | |
Fix percent-sign handling in block text
| -rw-r--r-- | blockext/__init__.py | 8 | ||||
| -rw-r--r-- | 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 |
