Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
bar = "bar derp",
baz = "baz blerp")
joined, unbound = MustacheParser.join(MustacheParser.split("{{foo}}"), oe)
assert joined == "foo herp"
assert unbound == []
splits = MustacheParser.split('blech {{foo}} {{bar}} bonk {{&baz}} bling')
joined, unbound = MustacheParser.join(splits, oe)
assert joined == 'blech foo herp bar derp bonk {{baz}} bling'
assert unbound == []
splits = MustacheParser.split('{{foo}} {{bar}} {{unbound}}')
joined, unbound = MustacheParser.join(splits, oe)
assert joined == 'foo herp bar derp {{unbound}}'
assert unbound == [Ref.from_address('unbound')]
def ref(address):
return Ref.from_address(address)
def ref(address):
return Ref.from_address(address)
def ref(address):
return Ref.from_address(address)
def dtd(d):
return dict((Ref.from_address(key), str(val)) for key, val in d.items())
def ref(address):
return Ref.from_address(address)
def split(cls, string, keep_aliases=False):
splits = cls._MUSTACHE_RE.split(string)
first_split = splits.pop(0)
outsplits = [first_split] if first_split else []
assert len(splits) % 3 == 0
for k in range(0, len(splits), 3):
if splits[k] == cls._ADDRESS_DELIMITER:
outsplits.append('{{%s%s}}' % (
cls._ADDRESS_DELIMITER if keep_aliases else '',
splits[k + 1]))
elif splits[k] is None:
outsplits.append(Ref.from_address(splits[k + 1]))
else:
raise Exception("Unexpected parsing error in Mustache: splits[%s] = '%s'" % (
k, splits[k]))
if splits[k + 2]:
outsplits.append(splits[k + 2])
return outsplits