def get_all_todo_states(self): u""" Convenience function that returns all todo and done states and sequences in one big list. :returns: [all todo/done states] """ return flatten_list(self.get_todo_states())
def __setitem__(self, i, item): if isinstance(i, slice): o = item if self.__class__.is_domobj(o): o = (o, ) o = flatten_list(o) for item in o: if not self.__class__.is_domobj(item): raise ValueError(u'List contains items that are not a Dom obj!') # self._add_to_deleted_domobjs(self[i:j]) # self._associate_domobj(o, \ # self[i - 1] if i - 1 >= 0 and i < len(self) else None, \ # self[j] if j >= 0 and j < len(self) else None) MultiPurposeList.__setitem__(self, i, o) else: if not self.__class__.is_domobj(item): raise ValueError(u'Item is not a Dom obj!') if item in self: raise ValueError(u'Dom obj is already part of this list!') # self._add_to_deleted_domobjs(self[i]) # self._associate_domobj(item, \ # self[i - 1] if i - 1 >= 0 else None, \ # self[i + 1] if i + 1 < len(self) else None) MultiPurposeList.__setitem__(self, i, item)
def __setitem__(self, i, item): if isinstance(i, slice): o = item if self.__class__.is_domobj(o): o = (o,) o = flatten_list(o) for item in o: if not self.__class__.is_domobj(item): raise ValueError(u'List contains items that are not a Dom obj!') # self._add_to_deleted_domobjs(self[i:j]) # self._associate_domobj(o, \ # self[i - 1] if i - 1 >= 0 and i < len(self) else None, \ # self[j] if j >= 0 and j < len(self) else None) MultiPurposeList.__setitem__(self, i, o) else: if not self.__class__.is_domobj(item): raise ValueError(u'Item is not a Dom obj!') if item in self: raise ValueError(u'Dom obj is already part of this list!') # self._add_to_deleted_domobjs(self[i]) # self._associate_domobj(item, \ # self[i - 1] if i - 1 >= 0 else None, \ # self[i + 1] if i + 1 < len(self) else None) MultiPurposeList.__setitem__(self, i, item)
def __setitem__(self, i, item): if isinstance(i, slice): start, stop, step = i.indices(len(self)) items = item if self.__class__.is_heading(items): items = (items, ) items = flatten_list(items) for head in items: if not self.__class__.is_heading(head): raise ValueError(u'List contains items that are not a heading!') self._add_to_deleted_headings(self[i]) self._associate_heading( items, self[start - 1] if start - 1 >= 0 else None, self[stop] if stop < len(self) else None) MultiPurposeList.__setitem__(self, i, items) else: if not self.__class__.is_heading(item): raise ValueError(u'Item is not a heading!') if item in self: raise ValueError(u'Heading is already part of this list!') self._add_to_deleted_headings(self[i]) self._associate_heading( item, self[i - 1] if i - 1 >= 0 else None, self[i + 1] if i + 1 < len(self) else None) MultiPurposeList.__setitem__(self, i, item)
def __setitem__(self, i, item): if isinstance(i, slice): start, stop, step = i.indices(len(self)) items = item if self.__class__.is_heading(items): items = (items, ) items = flatten_list(items) for head in items: if not self.__class__.is_heading(head): raise ValueError( u'List contains items that are not a heading!') self._add_to_deleted_headings(self[i]) self._associate_heading( items, self[start - 1] if start - 1 >= 0 else None, self[stop] if stop < len(self) else None) MultiPurposeList.__setitem__(self, i, items) else: if not self.__class__.is_heading(item): raise ValueError(u'Item is not a heading!') if item in self: raise ValueError(u'Heading is already part of this list!') self._add_to_deleted_headings(self[i]) self._associate_heading(item, self[i - 1] if i - 1 >= 0 else None, self[i + 1] if i + 1 < len(self) else None) MultiPurposeList.__setitem__(self, i, item)
def _associate_heading(self, heading, previous_sibling, next_sibling, children=False, taint=True): """ :heading: The heading or list to associate with the current heading :previous_sibling: The previous sibling of the current heading. If heading is a list the first heading will be connected with the previous sibling and the last heading with the next sibling. The items in between will be linked with one another. :next_sibling: The next sibling of the current heading. If heading is a list the first heading will be connected with the previous sibling and the last heading with the next sibling. The items in between will be linked with one another. :children: Marks whether children are processed in the current iteration or not (should not be use, it's set automatically) :taint: If not True, the heading is not marked dirty at the end of the association process and its orig_start and orig_len values are not updated. """ # TODO this method should be externalized and moved to the Heading class if type(heading) in (list, tuple) or isinstance(heading, UserList): prev = previous_sibling current = None for _next in flatten_list(heading): if current: self._associate_heading(current, prev, _next, children=children, taint=taint) prev = current current = _next if current: self._associate_heading(current, prev, next_sibling, children=children, taint=taint) else: if taint: heading._orig_start = None heading._orig_len = None d = self._get_document() if heading._document != d: heading._document = d if not children: # connect heading with previous and next headings heading._previous_sibling = previous_sibling if previous_sibling: previous_sibling._next_sibling = heading heading._next_sibling = next_sibling if next_sibling: next_sibling._previous_sibling = heading if d == self._obj: # self._obj is a Document heading._parent = None elif heading._parent != self._obj: # self._obj is a Heading heading._parent = self._obj if taint: heading.set_dirty() self._associate_heading(heading.children, None, None, children=True, taint=taint)
def fset(self, value): if type(value) in (list, tuple) or isinstance(value, UserList): self._body[:] = flatten_list(value) elif type(value) in (str,): self._body[:] = value.decode("utf-8").split(u"\n") elif type(value) in (unicode,): self._body[:] = value.split(u"\n") else: self.body = list(unicode(value))
def get_all_todo_states(self): u""" Convenience function that returns all todo and done states and sequences in one big list. Returns: list: [all todo/done states] """ # TODO This is not necessary remove return flatten_list(self.get_todo_states())
def __iadd__(self, other): o = other if self.__class__.is_heading(o): o = (o, ) for item in flatten_list(o): if not self.__class__.is_heading(item): raise ValueError(u'List contains items that are not a heading!') self._associate_heading(o, self[-1] if len(self) > 0 else None, None) return MultiPurposeList.__iadd__(self, o)
def __iadd__(self, other): o = other if self.__class__.is_domobj(o): o = (o, ) for item in flatten_list(o): if not self.__class__.is_domobj(item): raise ValueError(u'List contains items that are not a Dom obj!') # self._associate_domobj(o, self[-1] if len(self) > 0 else None, None) return MultiPurposeList.__iadd__(self, o)
def body(self, value): if type(value) in (list, tuple) or isinstance(value, UserList): self._body[:] = flatten_list(value) elif type(value) in (str, ): self._body[:] = u_decode(value).split(u'\n') elif type(value) in (unicode, ): self._body[:] = value.split(u'\n') else: self.body = list(unicode(value))
def fset(self, value): if type(value) in (list, tuple) or isinstance(value, UserList): self._body[:] = flatten_list(value) elif type(value) in (str, ): self._body[:] = value.decode('utf-8').split(u'\n') elif type(value) in (unicode, ): self._body[:] = value.split(u'\n') else: self.body = list(unicode(value))
def meta_information(self, value): if self._orig_meta_information_len is None: self._orig_meta_information_len = len(self.meta_information) if type(value) in (list, tuple) or isinstance(value, UserList): self._meta_information[:] = flatten_list(value) elif type(value) in (str, ): self._meta_information[:] = u_decode(value).split(u'\n') elif type(value) in (unicode, ): self._meta_information[:] = value.split(u'\n') self.set_dirty_meta_information()
def fset(self, value): if self._orig_meta_information_len is None: self._orig_meta_information_len = len(self.meta_information) if type(value) in (list, tuple) or isinstance(value, UserList): self._meta_information[:] = flatten_list(value) elif type(value) in (str, ): self._meta_information[:] = value.decode(u'utf-8').split(u'\n') elif type(value) in (unicode, ): self._meta_information[:] = value.split(u'\n') self.set_dirty_meta_information()
def _add_to_deleted_headings(self, item): u""" Serialize headings so that all subheadings are also marked for deletion """ if not self._get_document(): # HeadingList has not yet been associated return if type(item) in (list, tuple) or isinstance(item, UserList): for i in flatten_list(item): self._add_to_deleted_headings(i) else: self._get_document()._deleted_headings.append(item.copy(including_children=False)) self._add_to_deleted_headings(item.children) self._get_document().set_dirty_document()
def __setslice__(self, i, j, other): o = other if self.__class__.is_heading(o): o = (o, ) o = flatten_list(o) for item in o: if not self.__class__.is_heading(item): raise ValueError(u'List contains items that are not a heading!') i = max(i, 0) j = max(j, 0) self._add_to_deleted_headings(self[i:j]) self._associate_heading(o, \ self[i - 1] if i - 1 >= 0 and i < len(self) else None, \ self[j] if j >= 0 and j < len(self) else None) MultiPurposeList.__setslice__(self, i, j, o)
def _add_to_deleted_headings(self, item): u""" Serialize headings so that all subheadings are also marked for deletion """ if not self._get_document(): # HeadingList has not yet been associated return if type(item) in (list, tuple) or isinstance(item, UserList): for i in flatten_list(item): self._add_to_deleted_headings(i) else: self._get_document()._deleted_headings.append( item.copy(including_children=False)) self._add_to_deleted_headings(item.children) self._get_document().set_dirty_document()
def fset(self, value): v = value if type(v) in (unicode, str): v = list(unicode(v)) if type(v) not in (list, tuple) and not isinstance(v, UserList): v = list(unicode(v)) v = flatten_list(v) v_decoded = [] for i in v: if type(i) not in (unicode, str): raise ValueError(u'Found non string value in tags! %s' % unicode(i)) if u':' in i: raise ValueError(u'Found non allowed character in tag! %s' % i) i_tmp = i.strip().replace(' ', '_').replace('\t', '_') if type(i) == str: i_tmp = i.decode(u'utf-8') v_decoded.append(i_tmp) self._tags[:] = v_decoded
def __setitem__(self, i, item): # TODO rewrite this so that it can work when item is a tuple and i is slice # it should be made to work with any item that is iterable # It is also very poor design to just check for tuple and not raise any # errors otherwise or implement list also # TODO slice must differentiate between couple of cases: # slice(None,None) # slice(int, None) # slice(None, int) # this must be done because of _associate_heading and other methods # that dont take into account slicing if isinstance(i, slice): # TODO fix this mess it is only copy pasted from setslice sl = i o = item if self.__class__.is_heading(o): o = (o, ) o = flatten_list(o) for head in o: if not self.__class__.is_heading(head): raise ValueError( u'List contains items that are not a heading!') i = sl.start if sl.start is not None else 0 j = sl.stop if sl.stop is not None else len(self) - 1 self._add_to_deleted_headings(self[sl]) self._associate_heading( o, self[i - 1] if i - 1 >= 0 and i < len(self) else None, self[j] if j >= 0 and j < len(self) else None) MultiPurposeList.__setitem__(self, sl, o) else: if not self.__class__.is_heading(item): raise ValueError(u'Item is not a heading!') if item in self: raise ValueError(u'Heading is already part of this list!') self._add_to_deleted_headings(self[i]) self._associate_heading(item, self[i - 1] if i - 1 >= 0 else None, self[i + 1] if i + 1 < len(self) else None) MultiPurposeList.__setitem__(self, i, item)
def _associate_heading(self, heading, previous_sibling, next_sibling, children=False, taint=True): """ :heading: The heading or list to associate with the current heading :previous_sibling: The previous sibling of the current heading. If heading is a list the first heading will be connected with the previous sibling and the last heading with the next sibling. The items in between will be linked with one another. :next_sibling: The next sibling of the current heading. If heading is a list the first heading will be connected with the previous sibling and the last heading with the next sibling. The items in between will be linked with one another. :children: Marks whether children are processed in the current iteration or not (should not be use, it's set automatically) :taint: If not True, the heading is not marked dirty at the end of the association process and its orig_start and orig_len values are not updated. """ # TODO this method should be externalized and moved to the Heading class # TODO should this method work with slice? if type(heading) in (list, tuple) or isinstance(heading, UserList): prev = previous_sibling current = None for _next in flatten_list(heading): if current: self._associate_heading(current, prev, _next, children=children, taint=taint) prev = current current = _next if current: self._associate_heading(current, prev, next_sibling, children=children, taint=taint) else: if taint: heading._orig_start = None heading._orig_len = None d = self._get_document() if heading._document != d: heading._document = d if not children: # connect heading with previous and next headings heading._previous_sibling = previous_sibling if previous_sibling: previous_sibling._next_sibling = heading heading._next_sibling = next_sibling if next_sibling: next_sibling._previous_sibling = heading if d == self._obj: # self._obj is a Document heading._parent = None elif heading._parent != self._obj: # self._obj is a Heading heading._parent = self._obj if taint: heading.set_dirty() self._associate_heading(heading.children, None, None, children=True, taint=taint)
def fset(self, value): v = value if type(v) in (list, tuple) or isinstance(v, UserList): v = flatten_list(v) self._children[:] = v