Skip to content

Commit

Permalink
Support bytes and str as mixed keys
Browse files Browse the repository at this point in the history
  • Loading branch information
jirikuncar committed Feb 16, 2018
1 parent da9525d commit dc6614e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion git_json_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
from dulwich.objects import Blob, Tree
from dulwich.repo import Repo

try:
key_types = str, unicode
except:
key_types = bytes, str

__version__ = "0.1.0.dev20180121"

GIT_FILEMODE_BLOB = 33188
Expand Down Expand Up @@ -123,7 +128,7 @@ def decode(repo, tree_id):
return {}
raise TypeError('Unknown tree type.')

if all((isinstance(key[0], str) for key in items)):
if all((isinstance(key[0], key_types) for key in items)):
return {key: decode(repo, sha) for key, sha in items}
elif all((isinstance(key[0], int) for key in items)):
items = ((int(key), decode(repo, sha)) for key, sha in items)
Expand Down
3 changes: 2 additions & 1 deletion test_git_json_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def json_data():
st.lists(children) |
st.dictionaries(
st.text(
set(printable) - set('/')
set(printable) - set('/'),
min_size=1,
),
children,
),
Expand Down

0 comments on commit dc6614e

Please sign in to comment.