Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_mustache_re():
assert MustacheParser.split("{{foo}}") == [ref("foo")]
assert MustacheParser.split("{{_}}") == [ref("_")]
with pytest.raises(Ref.InvalidRefError):
MustacheParser.split("{{4}}")
def chrange(a,b):
return ''.join(map(lambda ch: str(chr(ch)), range(ord(a), ord(b)+1)))
slash_w = chrange('a','z') + chrange('A','Z') + chrange('0','9') + '_'
assert MustacheParser.split("{{%s}}" % slash_w) == [ref(slash_w)]
# bracketing
assert MustacheParser.split("{{{foo}}") == ['{', ref('foo')]
assert MustacheParser.split("{{foo}}}") == [ref('foo'), '}']
assert MustacheParser.split("{{{foo}}}") == ['{', ref('foo'), '}']
assert MustacheParser.split("{{}}") == ['{{}}']
assert MustacheParser.split("{{{}}}") == ['{{{}}}']
assert MustacheParser.split("{{{{foo}}}}") == ['{{', ref("foo"), '}}']
invalid_refs = ['!@', '-', '$', ':']
for val in invalid_refs:
def iterate(st, keep_aliases=True):
refs = cls.split(st, keep_aliases=keep_aliases)
unbound = [ref for ref in refs if isinstance(ref, Ref)]
repl, interps = cls.join(refs, *namables)
return repl, interps, unbound
def wrap(value):
if isinstance(value, Ref):
return value
else:
return Ref.from_address(value)
def from_address(address):
components = []
if not address or not isinstance(address, Compatibility.stringy):
raise Ref.InvalidRefError('Invalid address: %s' % repr(address))
if not (address.startswith('[') or address.startswith('.')):
if Ref._VALID_START.match(address[0]):
components = Ref.split_components('.' + address)
else:
raise Ref.InvalidRefError(address)
else:
components = Ref.split_components(address)
return Ref(components)
def __add__(self, other):
sc = self.components()
oc = other.components()
return Ref(sc + oc)
def __lt__(self, other):
return Ref.compare(self, other) == -1