Exemplo n.º 1
0
 def find_single_property(self, name):
     result = self.find_property(name)
     if len(result) < 1:
         raise exceptions.NoPropertyFound(name)
     elif len(result) > 1:
         raise exceptions.AmbiguousPropertyNameError(name)
     return result[0]
Exemplo n.º 2
0
    def find_static_property(self, name):
        def prop_func(cls):
            prop = cls.properties.get(name)
            if prop is not None and prop.usage == 'Static':
                return prop

        result = self._choose_symbol(prop_func)
        if len(result) < 1:
            raise exceptions.NoPropertyFound(name)
        elif len(result) > 1:
            raise exceptions.AmbiguousPropertyNameError(name)
        return result[0]
Exemplo n.º 3
0
 def find_single_property(self, name):
     result = None
     parents = None
     gen = helpers.traverse(self)
     while True:
         try:
             mc = gen.send(parents)
             if name in mc.properties:
                 if result and result != mc:
                     raise exceptions.AmbiguousPropertyNameError(name)
                 result = mc
                 parents = []
             else:
                 parents = mc.parents(self)
         except StopIteration:
             return result
Exemplo n.º 4
0
 def get_property(self, name, caller_class=None):
     start_type, derived = self.__type, False
     if caller_class is not None and caller_class.is_compatible(self):
         start_type, derived = caller_class, True
     if name in start_type.properties:
         return self.cast(start_type)._get_property_value(name)
     else:
         declared_properties = start_type.find_property(name)
         if len(declared_properties) == 1:
             return self.cast(declared_properties[0]).__properties[name]
         elif len(declared_properties) > 1:
             raise exceptions.AmbiguousPropertyNameError(name)
         elif derived:
             return self.cast(caller_class)._get_property_value(name)
         else:
             raise exceptions.PropertyReadError(name, start_type)