def covers(self, ref): """ Does this TypeEnvironment cover the ref? """ for binding in self._unbound_types: if binding.provides(ref): return True for bound_name, binding in self._bound_types.items(): scoped_ref = Ref.from_address(bound_name).scoped_to(ref) if scoped_ref is not None and binding.provides(scoped_ref): return True return False
def test_mustache_joining(): oe = Environment(foo="foo herp", 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 test_mustache_joining(): oe = Environment(foo = "foo herp", 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 split(string, keep_aliases=False): splits = MustacheParser._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] == MustacheParser._ADDRESS_DELIMITER: outsplits.append('{{%s%s}}' % ( MustacheParser._ADDRESS_DELIMITER if keep_aliases else '', splits[k+1])) elif splits[k] == 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
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)