Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved client.get_results() behavior
- Loading branch information
Showing
8 changed files
with
147 additions
and
61 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
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
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 @@ | ||
"""some generic utilities""" | ||
|
||
class ReverseDict(dict): | ||
"""simple double-keyed subset of dict methods.""" | ||
|
||
def __init__(self, *args, **kwargs): | ||
dict.__init__(self, *args, **kwargs) | ||
self._reverse = dict() | ||
for key, value in self.iteritems(): | ||
self._reverse[value] = key | ||
|
||
def __getitem__(self, key): | ||
try: | ||
return dict.__getitem__(self, key) | ||
except KeyError: | ||
return self._reverse[key] | ||
|
||
def __setitem__(self, key, value): | ||
if key in self._reverse: | ||
raise KeyError("Can't have key %r on both sides!"%key) | ||
dict.__setitem__(self, key, value) | ||
self._reverse[value] = key | ||
|
||
def pop(self, key): | ||
value = dict.pop(self, key) | ||
self.d1.pop(value) | ||
return value | ||
|
||
def get(self, key, default=None): | ||
try: | ||
return self[key] | ||
except KeyError: | ||
return default | ||
|
||
|
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