Skip to content

Commit

Permalink
Python 2.7 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
kerfab committed Sep 21, 2017
1 parent 137d034 commit 3f539fb
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions jdic/jdic.py
Expand Up @@ -28,7 +28,7 @@
class MatchResult(object):
""" Wraps the results of searches and browses within Jdic objects """
# pylint: disable=too-few-public-methods

def __init__(self, **kwargs):
self._obj = {}
for k in kwargs:
Expand All @@ -39,7 +39,8 @@ def __str__(self):
return str(self._obj)

def __iter__(self):
yield from self._obj.__iter__()
for entry in self._obj.__iter__():
yield entry

def __getitem__(self, item):
return self._obj[item]
Expand Down Expand Up @@ -156,7 +157,8 @@ def __getitem__(self, item):
return self._obj[int(item)]

def __iter__(self):
yield from self._obj.__iter__()
for entry in self._obj.__iter__():
yield entry

def __len__(self):
return len(self._obj)
Expand Down Expand Up @@ -372,7 +374,8 @@ def browse(self, sort=False, depth=None, maxdepth=None, _start=True):
yield MatchResult(parent=self, parent_path=self._path, key=key,
value=val, path=path, depth=self._depth)
if isinstance(val, Jdic):
yield from val.browse(sort=sort, depth=depth, maxdepth=maxdepth, _start=False)
for entry in val.browse(sort=sort, depth=depth, maxdepth=maxdepth, _start=False):
yield entry

def checksum(self, algo='sha256'):
""" Returns an ASCII hexadecimal checksum representing the state of the object """
Expand Down Expand Up @@ -417,7 +420,8 @@ def diff(self, obj):

def enumerate(self, sort=False):
""" Yields a key, value pair with both Jdic Mappings and Sequences """
yield from jdic_enumerate(self._obj, sort=sort)
for entry in jdic_enumerate(self._obj, sort=sort):
yield entry

def find(self, value, limit=None, sort=False, depth=None, maxdepth=None):
""" Finds a value within the Jdic object, the search is recursive """
Expand Down

0 comments on commit 3f539fb

Please sign in to comment.