def visit(self, key, attribute_options): # We only collect load options for attributes which are explicitly not # ignored or member attributes unless they are explicitly ignored. ignore_opt = attribute_options.get(IGNORE_OPTION) if not ignore_opt is True: rc = get_member_class(self._context) entity_attr_names = [] store_key = True for idx, attr_name in enumerate(key): attr = get_resource_class_attribute(rc, attr_name) if attr is None: # Referencing non-existing attribute; ignore. store_key = False break elif idx == 0 \ and is_collection_attribute(attr) \ and not ignore_opt is False: # Referencing collection attribute which was not # explicitly enabled. store_key = False break entity_attr_name = attr.entity_attr if is_terminal_attribute(attr): if '.' in entity_attr_name: entity_attr_name = \ entity_attr_name[:entity_attr_name.rfind('.')] else: store_key = False break entity_attr_names.append(entity_attr_name) rc = attr.attr_type if store_key: self.__attr_map[key] = entity_attr_names
def _get_proxied_attribute_value(self, attribute): if not is_terminal_attribute(attribute): val = self._get_relatee(attribute) else: try: val = self._data.data[attribute.repr_name] except KeyError: raise AttributeError(attribute) return val
def get_relationship_attributes(self): """ Returns an iterator over the relationship attributes (i.e., non-terminal attributes) of the proxied data. :returns: iterator yielding objects implementing :class:`everest.resources.interfaces.IResourceAttribute`. """ for attr in self._attribute_iterator(): if not is_terminal_attribute(attr): yield attr
def _get_proxied_attribute_value(self, attribute): if not is_terminal_attribute(attribute): val = self.__get_relatee(attribute) else: val = self._data.get_attribute(attribute.repr_name) return val
def test_is_terminal_attribute(self): self.assert_true(is_terminal_attribute(self.terminal_attr)) self.assert_false(is_terminal_attribute(self.member_attr))
def test_is_terminal_attribute(self, attr_name): mb_attr = member_attribute(Member, attr_name) assert is_terminal_attribute(mb_attr) is False t_attr = terminal_attribute(int, attr_name) assert is_terminal_attribute(t_attr) is True