From c1d6fd0c741e88accf60820354f43936ddbb1753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9onard=20Binet?= Date: Sun, 1 Mar 2020 15:53:23 +0100 Subject: [PATCH 1/4] rename for clarity -> dt_line_corner (#146) --- treelib/tree.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/treelib/tree.py b/treelib/tree.py index 326d887..a4225d5 100644 --- a/treelib/tree.py +++ b/treelib/tree.py @@ -240,20 +240,17 @@ def filter_(node): return self.__get_iter(nid, level, filter_, key, reverse, dt, []) def __get_iter(self, nid, level, filter_, key, reverse, dt, is_last): - dt_vline, dt_line_box, dt_line_cor = dt - - nid = self.root if (nid is None) else nid - if not self.contains(nid): - raise NodeIDAbsentError("Node '%s' is not in the tree" % nid) + dt_vertical_line, dt_line_box, dt_line_corner = dt + nid = self.root if nid is None else nid node = self[nid] if level == self.ROOT: yield "", node else: - leading = ''.join(map(lambda x: dt_vline + ' ' * 3 + leading = ''.join(map(lambda x: dt_vertical_line + ' ' * 3 if not x else ' ' * 4, is_last[0:-1])) - lasting = dt_line_cor if is_last[-1] else dt_line_box + lasting = dt_line_corner if is_last[-1] else dt_line_box yield leading + lasting, node if filter_(node) and node.expanded: From 96a1cde80805ea877af63247deb3ebb32715d385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9onard=20Binet?= Date: Sun, 1 Mar 2020 15:55:37 +0100 Subject: [PATCH 2/4] remove __setitem (#152) --- treelib/tree.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/treelib/tree.py b/treelib/tree.py index a4225d5..bce1055 100644 --- a/treelib/tree.py +++ b/treelib/tree.py @@ -154,10 +154,6 @@ def __len__(self): """Return len(_nodes)""" return len(self._nodes) - def __setitem__(self, key, item): - """Set _nodes[key]""" - self._nodes.update({key: item}) - def __str__(self): self._reader = "" From 10efe8cbd2090bfe1cf0f87e74f72759dd87dd2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9onard=20Binet?= Date: Sun, 1 Mar 2020 16:01:31 +0100 Subject: [PATCH 3/4] python 2-3 improvements (#144) * python 2-3 improvements * move __version__ to allow requirements install --- docs/source/conf.py | 2 +- setup.py | 3 ++- treelib/__init__.py | 1 - treelib/tree.py | 28 ++++------------------------ 4 files changed, 7 insertions(+), 27 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index b16525d..11cb707 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -16,7 +16,7 @@ import sys sys.path.insert(0, os.path.abspath('../..')) -from treelib import __version__ +from setup import __version__ # -- Project information ----------------------------------------------------- diff --git a/setup.py b/setup.py index 82c2c7d..84026f4 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,7 @@ from setuptools import setup -from treelib import __version__ +__version__ = '1.6.1' + setup( name="treelib", diff --git a/treelib/__init__.py b/treelib/__init__.py index e4fef19..d7e6ec7 100644 --- a/treelib/__init__.py +++ b/treelib/__init__.py @@ -34,7 +34,6 @@ >>> from __future__ import unicode_literals """ -__version__ = '1.6.1' from .tree import Tree from .node import Node diff --git a/treelib/tree.py b/treelib/tree.py index bce1055..6ee18c9 100644 --- a/treelib/tree.py +++ b/treelib/tree.py @@ -36,9 +36,9 @@ import codecs import json -import sys import uuid from copy import deepcopy +from future.utils import python_2_unicode_compatible, iteritems try: from StringIO import StringIO @@ -51,26 +51,6 @@ __author__ = 'chenxm' -def python_2_unicode_compatible(klass): - """ - (slightly modified from: http://django.readthedocs.org/en/latest/_modules/django/utils/encoding.html) - - A decorator that defines __unicode__ and __str__ methods under Python 2. - Under Python 3 it does nothing. - - To support Python 2 and 3 with a single code base, define a __str__ method - returning text and apply this decorator to the class. - """ - if sys.version_info[0] == 2: - if '__str__' not in klass.__dict__: - raise ValueError("@python_2_unicode_compatible cannot be applied " - "to %s because it doesn't define __str__()." % - klass.__name__) - klass.__unicode__ = klass.__str__ - klass.__str__ = lambda self: self.__unicode__().encode('utf-8') - return klass - - @python_2_unicode_compatible class Tree(object): """Tree objects are made of Node(s) stored in _nodes dictionary.""" @@ -102,7 +82,7 @@ def __init__(self, tree=None, deep=False, node_class=None, identifier=None): if tree is not None: self.root = tree.root - for nid, node in tree.nodes.items(): + for nid, node in iteritems(tree.nodes): new_node = deepcopy(node) if deep else node self._nodes[nid] = new_node if tree.identifier != self._identifier: @@ -655,7 +635,7 @@ def paste(self, nid, new_tree, deep=False): if set_joint: raise ValueError('Duplicated nodes %s exists.' % list(map(text, set_joint))) - for cid, node in new_tree.nodes.items(): + for cid, node in iteritems(new_tree.nodes): if deep: node = deepcopy(new_tree[node]) self._nodes.update({cid: node}) @@ -923,7 +903,7 @@ def update_node(self, nid, **attrs): :return: None """ cn = self[nid] - for attr, val in attrs.items(): + for attr, val in iteritems(attrs): if attr == 'identifier': # Updating node id meets following contraints: # * Update node identifier property From b4d8e7c46bf222c8cc46403c4e622e6f55ba526f Mon Sep 17 00:00:00 2001 From: Xiaming Date: Sun, 1 Mar 2020 23:02:45 +0800 Subject: [PATCH 4/4] Renew next version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 84026f4..a59e128 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup -__version__ = '1.6.1' +__version__ = '1.6.2' setup(