-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added version resolver that updates as version dictionary is updated
- Loading branch information
1 parent
257b931
commit 6f81411
Showing
6 changed files
with
74 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from collections import Mapping | ||
|
||
|
||
class VersionResolver(Mapping): | ||
|
||
def __init__(self, *dicts): | ||
self._dicts = dicts | ||
|
||
def __getitem__(self, key): | ||
for d in self._dicts: | ||
if key in d and d.get(key): | ||
return d[key] | ||
raise KeyError() | ||
|
||
def __iter__(self): | ||
keys = set() | ||
for d in self._dicts: | ||
keys.update(set(d.keys())) | ||
return iter(keys) | ||
|
||
def __len__(self): | ||
return len(self.__iter__()) | ||
|
||
def __eq__(self, other): | ||
self_keys = set(self.keys()) | ||
other_keys = set(other.keys()) | ||
|
||
if self_keys ^ other_keys: | ||
return False | ||
|
||
for k in self_keys: | ||
if self[k] != other[k]: | ||
return False | ||
|
||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters