Example #1
0
 def provides(self, ref):
   assert isinstance(ref, Ref)
   if ref in self._table:
     return True
   targets = [key for key in self._table if Ref.subscope(key, ref)]
   if not targets:
     return False
   else:
     for key in sorted(targets, reverse=True):
       scope = self._table[key]
       if not isinstance(scope, Namable):
         continue
       subscope = Ref.subscope(key, ref)
       # If subscope is empty, then we should've found it in the ref table.
       assert not subscope.is_empty()
       if scope.provides(subscope):
         return True
   return False
Example #2
0
 def find(self, ref):
   if ref in self._table:
     return self._table[ref]
   targets = [key for key in self._table if Ref.subscope(key, ref)]
   if not targets:
     raise Namable.NotFound(self, ref)
   else:
     for key in sorted(targets, reverse=True):
       scope = self._table[key]
       if not isinstance(scope, Namable):
         continue
       subscope = Ref.subscope(key, ref)
       # If subscope is empty, then we should've found it in the ref table.
       assert not subscope.is_empty()
       try:
         resolved = scope.find(subscope)
         return resolved
       except Namable.Error as e:
         continue
   raise Namable.NotFound(self, ref)