Skip to content

Commit 017e891

Browse files
authored
Merge pull request #156 from caesar0301/dev
Sync latest patches from dev
2 parents 7a21c50 + b4d8e7c commit 017e891

File tree

4 files changed

+11
-38
lines changed

4 files changed

+11
-38
lines changed

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import sys
1717
sys.path.insert(0, os.path.abspath('../..'))
1818

19-
from treelib import __version__
19+
from setup import __version__
2020

2121
# -- Project information -----------------------------------------------------
2222

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from setuptools import setup
22

3-
from treelib import __version__
3+
__version__ = '1.6.2'
4+
45

56
setup(
67
name="treelib",

treelib/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
3535
>>> from __future__ import unicode_literals
3636
"""
37-
__version__ = '1.6.1'
3837

3938
from .tree import Tree
4039
from .node import Node

treelib/tree.py

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636

3737
import codecs
3838
import json
39-
import sys
4039
import uuid
4140
from copy import deepcopy
41+
from future.utils import python_2_unicode_compatible, iteritems
4242

4343
try:
4444
from StringIO import StringIO
@@ -51,26 +51,6 @@
5151
__author__ = 'chenxm'
5252

5353

54-
def python_2_unicode_compatible(klass):
55-
"""
56-
(slightly modified from: http://django.readthedocs.org/en/latest/_modules/django/utils/encoding.html)
57-
58-
A decorator that defines __unicode__ and __str__ methods under Python 2.
59-
Under Python 3 it does nothing.
60-
61-
To support Python 2 and 3 with a single code base, define a __str__ method
62-
returning text and apply this decorator to the class.
63-
"""
64-
if sys.version_info[0] == 2:
65-
if '__str__' not in klass.__dict__:
66-
raise ValueError("@python_2_unicode_compatible cannot be applied "
67-
"to %s because it doesn't define __str__()." %
68-
klass.__name__)
69-
klass.__unicode__ = klass.__str__
70-
klass.__str__ = lambda self: self.__unicode__().encode('utf-8')
71-
return klass
72-
73-
7454
@python_2_unicode_compatible
7555
class Tree(object):
7656
"""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):
10282

10383
if tree is not None:
10484
self.root = tree.root
105-
for nid, node in tree.nodes.items():
85+
for nid, node in iteritems(tree.nodes):
10686
new_node = deepcopy(node) if deep else node
10787
self._nodes[nid] = new_node
10888
if tree.identifier != self._identifier:
@@ -154,10 +134,6 @@ def __len__(self):
154134
"""Return len(_nodes)"""
155135
return len(self._nodes)
156136

157-
def __setitem__(self, key, item):
158-
"""Set _nodes[key]"""
159-
self._nodes.update({key: item})
160-
161137
def __str__(self):
162138
self._reader = ""
163139

@@ -240,20 +216,17 @@ def filter_(node):
240216
return self.__get_iter(nid, level, filter_, key, reverse, dt, [])
241217

242218
def __get_iter(self, nid, level, filter_, key, reverse, dt, is_last):
243-
dt_vline, dt_line_box, dt_line_cor = dt
244-
245-
nid = self.root if (nid is None) else nid
246-
if not self.contains(nid):
247-
raise NodeIDAbsentError("Node '%s' is not in the tree" % nid)
219+
dt_vertical_line, dt_line_box, dt_line_corner = dt
248220

221+
nid = self.root if nid is None else nid
249222
node = self[nid]
250223

251224
if level == self.ROOT:
252225
yield "", node
253226
else:
254-
leading = ''.join(map(lambda x: dt_vline + ' ' * 3
227+
leading = ''.join(map(lambda x: dt_vertical_line + ' ' * 3
255228
if not x else ' ' * 4, is_last[0:-1]))
256-
lasting = dt_line_cor if is_last[-1] else dt_line_box
229+
lasting = dt_line_corner if is_last[-1] else dt_line_box
257230
yield leading + lasting, node
258231

259232
if filter_(node) and node.expanded:
@@ -662,7 +635,7 @@ def paste(self, nid, new_tree, deep=False):
662635
if set_joint:
663636
raise ValueError('Duplicated nodes %s exists.' % list(map(text, set_joint)))
664637

665-
for cid, node in new_tree.nodes.items():
638+
for cid, node in iteritems(new_tree.nodes):
666639
if deep:
667640
node = deepcopy(new_tree[node])
668641
self._nodes.update({cid: node})
@@ -930,7 +903,7 @@ def update_node(self, nid, **attrs):
930903
:return: None
931904
"""
932905
cn = self[nid]
933-
for attr, val in attrs.items():
906+
for attr, val in iteritems(attrs):
934907
if attr == 'identifier':
935908
# Updating node id meets following contraints:
936909
# * Update node identifier property

0 commit comments

Comments
 (0)