示例#1
0
    def references(self):
        """
        A property containing all data arrays referenced by the tag. Referenced data arrays
        can be obtained by index or their id. References can be removed from the list, removing
        a referenced DataArray will not remove it from the file. New references can be added using
        the append method of the list.
        This is a read only attribute.

        :type: RefProxyList of DataArray
        """
        if not hasattr(self, "_references"):
            setattr(self, "_references", ReferenceProxyList(self))
        return self._references

    @property
    def features(self):
        """
        A property containing all features of the tag. Features can be
        obtained via their index or their id. Features can be deleted from the list.
        Adding new features to the tag is done using the create_feature method.
        This is a read only attribute.

        :type: ProxyList of Feature.
        """
        if not hasattr(self, "_features"):
            setattr(self, "_features", FeatureProxyList(self))
        return self._features


inject((Tag, ), dict(TagMixin.__dict__))
示例#2
0
文件: tag.py 项目: gicmo/nixpy
    def references(self):
        """
        A property containing all data arrays referenced by the tag. Referenced data arrays
        can be obtained by index or their id. References can be removed from the list, removing
        a referenced DataArray will not remove it from the file. New references can be added using
        the append method of the list.
        This is a read only attribute.

        :type: RefProxyList of DataArray
        """
        if not hasattr(self, "_references"):
            setattr(self, "_references", ReferenceProxyList(self))
        return self._references

    @property
    def features(self):
        """
        A property containing all features of the tag. Features can be
        obtained via their index or their id. Features can be deleted from the list.
        Adding new features to the tag is done using the create_feature method.
        This is a read only attribute.

        :type: ProxyList of Feature.
        """
        if not hasattr(self, "_features"):
            setattr(self, "_features", FeatureProxyList(self))
        return self._features


inject((Tag,), dict(TagMixin.__dict__))
示例#3
0
        if hasattr(other, "id"):
            return self.id == other.id
        else:
            return False

    def __hash__(self):
        """
        overwriting method __eq__ blocks inheritance of __hash__ in Python 3
        hash has to be either explicitly inherited from parent class, implemented or escaped
        """
        return hash(self.id)


class ValueMixin(Value):
    def __eq__(self, other):
        if hasattr(other, "value"):
            return self.value == other.value
        else:
            return self.value == other

    def __hash__(self):
        """
        overwriting method __eq__ blocks inheritance of __hash__ in Python 3
        hash has to be either explicitly inherited from parent class, implemented or escaped
        """
        return hash(self.id)


inject((Property, ), dict(PropertyMixin.__dict__))
inject((Value, ), dict(ValueMixin.__dict__))
示例#4
0
文件: file.py 项目: gicmo/nixpy
        will be added to the result list.
        By default a filter is used that accepts all sections.

        :param filtr: A filter function
        :type filtr:  function
        :param limit: The maximum depth of traversal
        :type limit:  int

        :returns: A list containing the matching sections.
        :rtype: list of Section
        """
        return finders._find_sections(self, filtr, limit)

    @property
    def sections(self):
        """
        A property containing all root sections of a file. Specific root sections can be obtained
        by their id or their index. Sections can be deleted from this list. Notice: when a section
        is deleted all its child section and properties will be removed too.
        Adding a new Section is done via the crate_section method of File. This is a read-only
        property.

        :type: ProxyList of Section entities.
        """
        if not hasattr(self, "_sections"):
            setattr(self, "_sections", SectionProxyList(self))
        return self._sections


inject((File,), dict(FileMixin.__dict__))
示例#5
0
    def groups(self):
        """
        A property containing all groups of a block. Group entities can be obtained via their index or by their id.
        Groups can be deleted from the list. Adding a Group is done using the Blocks create_group method.
        This is a read only attribute.

        :type: ProxyList of Group entities.
        """
        if not hasattr(self, "_groups"):
            setattr(self, "_groups", GroupProxyList(self))
        return self._groups

    def __eq__(self, other):
        """
        Two blocks are considered equal when they have the same id
        """
        if hasattr(other, "id"):
            return self.id == other.id
        else:
            return False

    def __hash__(self):
        """
        overwriting method __eq__ blocks inheritance of __hash__ in Python 3
        hash has to be either explicitly inherited from parent class, implemented or escaped
        """
        return hash(self.id)


inject((Block, ), dict(BlockMixin.__dict__))
示例#6
0
    def references(self):
        """
        A property containing all data arrays referenced by the tag. Referenced data arrays
        can be obtained by index or their id. References can be removed from the list, removing
        a referenced DataArray will not remove it from the file. New references can be added using
        the append method of the list.
        This is a read only attribute.

        :type: RefProxyList of DataArray
        """
        if not hasattr(self, "_references"):
            setattr(self, "_references", ReferenceProxyList(self))
        return self._references

    @property
    def features(self):
        """
        A property containing all features of the tag. Features can be
        obtained via their index or their id. Features can be deleted from the list.
        Adding new features to the tag is done using the create_feature method.
        This is a read only attribute.

        :type: ProxyList of Feature.
        """
        if not hasattr(self, "_features"):
            setattr(self, "_features", FeatureProxyList(self))
        return self._features


inject((MultiTag,), dict(MultiTagMixin.__dict__))
示例#7
0
文件: section.py 项目: gicmo/nixpy
        for s in self.sections:
            yield (s.name, s)

    def __contains__(self, key):
        return key in self.props or key in self.sections

    @property
    def props(self):
        """
        A property containing all Property entities associated with the section. Properties can
        be accessed by index of via their id. Properties can be deleted from the list. Adding
        new properties is done using the create_property method. This is a read-only attribute.

        :type: ProxyList of Property
        """
        if not hasattr(self, "_properties_proxy"):
            setattr(self, "_properties_proxy", PropertyProxyList(self))
        return self._properties_proxy

    def _get_property_by_id_or_name(self, ident):
        """
        Helper method that gets a property by id or name
        """
        p = self._get_property_by_id(ident)
        if p is None and self.has_property_by_name(ident):
            p = self.get_property_by_name(ident)
        return p


inject((Section,), dict(SectionMixin.__dict__))
示例#8
0
        :type filtr:  function
        :param limit: The maximum depth of traversal
        :type limit:  int

        :returns: A list containing the matching sources.
        :rtype: list of Source
        """
        return finders._find_sources(self, filtr, limit)

    @property
    def sources(self):
        if not hasattr(self, "_sources"):
            setattr(self, "_sources", SourceProxyList(self))
        return self._sources

    def __eq__(self, other):
        if hasattr(other, "id"):
            return self.id == other.id
        else:
            return False

    def __hash__(self):
        """
        overwriting method __eq__ blocks inheritance of __hash__ in Python 3
        hash has to be either explicitly inherited from parent class, implemented or escaped
        """
        return hash(self.id)


inject((Source,), dict(SourceMixin.__dict__))
示例#9
0
文件: data_array.py 项目: gicmo/nixpy
        # here we handle Ellipsis in the middle of the tuple
        # we *can* only handle one, if there are more, then
        # __complete_slices will raise a InvalidIndex error
        pos = index.index(Ellipsis) if Ellipsis in index else -1
        if pos > -1:
            index = index[:pos] + fill_none(shape, index) + index[pos+1:]

        # in python3 map does not work with None therefore if
        # len(shape) != len(index) we wont get the expected
        # result. We therefore need to fill up the missing values
        index = index + fill_none(shape, index, to_replace=0)

        completed = list(map(self.__complete_slices, shape, index))
        combined = list(map(lambda s: (s.start, s.stop), completed))
        count = tuple(x[1] - x[0] for x in combined)
        offset = [x for x in zip(*combined)][0]

        # drop all indices from count that came from single ints
        # NB: special case when we only have ints, e.g. (int, ) then
        # we get back the empty tuple and this is what we want,
        # because it indicates a scalar result
        squeezed = map(lambda i, c: c if type(i) != int else None, index, count)
        shape = list(filter(lambda x: x is not None, squeezed))

        return count, offset, shape


inject((DataArray,), dict(DataArrayMixin.__dict__))
inject((DataSet,), dict(DataSetMixin.__dict__))
示例#10
0
文件: property.py 项目: gicmo/nixpy
            return self.id == other.id
        else:
            return False

    def __hash__(self):
        """
        overwriting method __eq__ blocks inheritance of __hash__ in Python 3
        hash has to be either explicitly inherited from parent class, implemented or escaped
        """
        return hash(self.id)


class ValueMixin(Value):

    def __eq__(self, other):
        if hasattr(other, "value"):
            return self.value == other.value
        else:
            return self.value == other

    def __hash__(self):
        """
        overwriting method __eq__ blocks inheritance of __hash__ in Python 3
        hash has to be either explicitly inherited from parent class, implemented or escaped
        """
        return hash(self.id)


inject((Property,), dict(PropertyMixin.__dict__))
inject((Value,), dict(ValueMixin.__dict__))
示例#11
0
        will be added to the result list.
        By default a filter is used that accepts all sections.

        :param filtr: A filter function
        :type filtr:  function
        :param limit: The maximum depth of traversal
        :type limit:  int

        :returns: A list containing the matching sections.
        :rtype: list of Section
        """
        return finders._find_sections(self, filtr, limit)

    @property
    def sections(self):
        """
        A property containing all root sections of a file. Specific root sections can be obtained
        by their id or their index. Sections can be deleted from this list. Notice: when a section
        is deleted all its child section and properties will be removed too.
        Adding a new Section is done via the crate_section method of File. This is a read-only
        property.

        :type: ProxyList of Section entities.
        """
        if not hasattr(self, "_sections"):
            setattr(self, "_sections", SectionProxyList(self))
        return self._sections


inject((File, ), dict(FileMixin.__dict__))
示例#12
0
        # here we handle Ellipsis in the middle of the tuple
        # we *can* only handle one, if there are more, then
        # __complete_slices will raise a InvalidIndex error
        pos = index.index(Ellipsis) if Ellipsis in index else -1
        if pos > -1:
            index = index[:pos] + fill_none(shape, index) + index[pos + 1:]

        # in python3 map does not work with None therefore if
        # len(shape) != len(index) we wont get the expected
        # result. We therefore need to fill up the missing values
        index = index + fill_none(shape, index, to_replace=0)

        completed = list(map(self.__complete_slices, shape, index))
        combined = list(map(lambda s: (s.start, s.stop), completed))
        count = tuple(x[1] - x[0] for x in combined)
        offset = [x for x in zip(*combined)][0]

        # drop all indices from count that came from single ints
        # NB: special case when we only have ints, e.g. (int, ) then
        # we get back the empty tuple and this is what we want,
        # because it indicates a scalar result
        squeezed = map(lambda i, c: c
                       if type(i) != int else None, index, count)
        shape = list(filter(lambda x: x is not None, squeezed))

        return count, offset, shape


inject((DataArray, ), dict(DataArrayMixin.__dict__))
inject((DataSet, ), dict(DataSetMixin.__dict__))
示例#13
0
    def tags(self):
        """
        A property containing all tags referenced by the group. Tags
        can be obtained by index or their id. Tags can be removed from the list, removing
        a referenced Tag will not remove it from the file. New Tags can be added using
        the append method of the list.
        This is a read only attribute.

        :type: TagProxyList of Tags
        """
        if not hasattr(self, "_tags"):
            setattr(self, "_tags", TagProxyList(self))
        return self._tags

    @property
    def multi_tags(self):
        """
        A property containing all MultiTags referenced by the group. MultiTags
        can be obtained by index or their id. Tags can be removed from the list, removing
        a referenced MultiTag will not remove it from the file. New MultiTags can be added using
        the append method of the list.
        This is a read only attribute.

        :type: MultiTagProxyList of MultiTags
        """
        if not hasattr(self, "_multi_tags"):
            setattr(self, "_multi_tags", MultiTagProxyList(self))
        return self._multi_tags

inject((Group,), dict(GroupMixin.__dict__))
示例#14
0
文件: block.py 项目: gicmo/nixpy
    def groups(self):
        """
        A property containing all groups of a block. Group entities can be obtained via their index or by their id.
        Groups can be deleted from the list. Adding a Group is done using the Blocks create_group method.
        This is a read only attribute.

        :type: ProxyList of Group entities.
        """
        if not hasattr(self, "_groups"):
            setattr(self, "_groups", GroupProxyList(self))
        return self._groups

    def __eq__(self, other):
        """
        Two blocks are considered equal when they have the same id
        """
        if hasattr(other, "id"):
            return self.id == other.id
        else:
            return False

    def __hash__(self):
        """
        overwriting method __eq__ blocks inheritance of __hash__ in Python 3
        hash has to be either explicitly inherited from parent class, implemented or escaped
        """
        return hash(self.id)


inject((Block,), dict(BlockMixin.__dict__))
示例#15
0
                    "_get_source_by_pos", "_remove_source_by_id", "_add_source_by_id")

_sources_doc = """
Getter for sources.
"""

def _get_sources(self):
    if not hasattr(self, "_sources"):
        setattr(self, "_sources", RefSourceProxyList(self))
    return self._sources


class DataArraySourcesMixin(DataArray):

    sources = property(_get_sources, None, None, _sources_doc)


class MultiTagSourcesMixin(MultiTag):

    sources = property(_get_sources, None, None, _sources_doc)


class TagSourcesMixin(Tag):

    sources = property(_get_sources, None, None, _sources_doc)


inject((DataArray,), dict(DataArraySourcesMixin.__dict__))
inject((MultiTag,), dict(MultiTagSourcesMixin.__dict__))
inject((Tag,), dict(TagSourcesMixin.__dict__))
示例#16
0
        for s in self.sections:
            yield (s.name, s)

    def __contains__(self, key):
        return key in self.props or key in self.sections

    @property
    def props(self):
        """
        A property containing all Property entities associated with the section. Properties can
        be accessed by index of via their id. Properties can be deleted from the list. Adding
        new properties is done using the create_property method. This is a read-only attribute.

        :type: ProxyList of Property
        """
        if not hasattr(self, "_properties_proxy"):
            setattr(self, "_properties_proxy", PropertyProxyList(self))
        return self._properties_proxy

    def _get_property_by_id_or_name(self, ident):
        """
        Helper method that gets a property by id or name
        """
        p = self._get_property_by_id(ident)
        if p is None and self.has_property_by_name(ident):
            p = self.get_property_by_name(ident)
        return p


inject((Section, ), dict(SectionMixin.__dict__))