How to use the pystachio.naming.Ref function in pystachio

To help you get started, we’ve selected a few pystachio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wickman / pystachio / tests / test_parsing.py View on Github external
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:
github wickman / pystachio / pystachio / parsing.py View on Github external
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
github wickman / pystachio / pystachio / naming.py View on Github external
def wrap(value):
    if isinstance(value, Ref):
      return value
    else:
      return Ref.from_address(value)
github wickman / pystachio / pystachio / naming.py View on Github external
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)
github wickman / pystachio / pystachio / naming.py View on Github external
def __add__(self, other):
    sc = self.components()
    oc = other.components()
    return Ref(sc + oc)
github wickman / pystachio / pystachio / naming.py View on Github external
def __lt__(self, other):
    return Ref.compare(self, other) == -1