|
| 1 | +from dpath import PY3 |
1 | 2 | import dpath.exceptions |
2 | 3 | import re |
3 | 4 | import fnmatch |
@@ -76,8 +77,17 @@ def paths(obj, dirs=True, leaves=True, path=[], skip=False, separator="/"): |
76 | 77 |
|
77 | 78 | """ |
78 | 79 | if isinstance(obj, dict): |
79 | | - for (k, v) in obj.iteritems(): |
80 | | - if issubclass(k.__class__, (basestring)) and skip and k[0] == '+': |
| 80 | + |
| 81 | + # Python 3 support |
| 82 | + if PY3: |
| 83 | + iteritems = obj.items() |
| 84 | + string_class = str |
| 85 | + else: # Default to PY2 |
| 86 | + iteritems = obj.iteritems() |
| 87 | + string_class = basestring |
| 88 | + |
| 89 | + for (k, v) in iteritems: |
| 90 | + if issubclass(k.__class__, (string_class)) and skip and k[0] == '+': |
81 | 91 | continue |
82 | 92 | newpath = path + [[k, v.__class__]] |
83 | 93 | validate(newpath, separator=separator) |
@@ -125,7 +135,11 @@ def match(path, glob): |
125 | 135 | ss_glob = glob[:ss] + glob[ss + 1:] |
126 | 136 |
|
127 | 137 | if path_len == len(ss_glob): |
128 | | - return all(map(fnmatch.fnmatch, map(str, paths_only(path)), map(str, ss_glob))) |
| 138 | + # Python 3 support |
| 139 | + if PY3: |
| 140 | + return all(map(fnmatch.fnmatch, list(map(str, paths_only(path))), list(map(str, ss_glob)))) |
| 141 | + else: # Default to Python 2 |
| 142 | + return all(map(fnmatch.fnmatch, map(str, paths_only(path)), map(str, ss_glob))) |
129 | 143 |
|
130 | 144 | return False |
131 | 145 |
|
|
0 commit comments