From 240dcd74362fa08cef7926b57c6064b58671eced Mon Sep 17 00:00:00 2001 From: Date: Sat, 3 Mar 2018 18:26:08 -0500 Subject: [PATCH] Updates sets to the new refactor scheme. --- scrython/sets/sets.py | 66 ++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 42 deletions(-) diff --git a/scrython/sets/sets.py b/scrython/sets/sets.py index a19ff69..fb88bb9 100644 --- a/scrython/sets/sets.py +++ b/scrython/sets/sets.py @@ -41,123 +41,105 @@ class Sets(SetsObject): self._url = 'sets?' super(Sets, self).__init__(self._url) - def __checkForKey(self, key): + def _checkForKey(self, key): try: return self.scryfallJson[key] - except KeyError: - return None + except Exception: + raise KeyError('This object has no key \'{}\''.format(key)) - def __checkForTupleKey(self, parent, num, key): + def _checkForTupleKey(self, parent, num, key): try: return self.scryfallJson[parent][num][key] - except KeyError: - return None + except Exception: + raise KeyError('This object has no key \'{}\''.format(key)) def object(self): - if self.__checkForKey('object') is None: - raise KeyError('This object has no key \'object\'') + self._checkForKey('object') return self.scryfallJson['object'] def has_more(self): - if self.__checkForKey('has_more') is None: - return KeyError('This object has no key \'has_more\'') + self._checkForKey('has_more') return self.scryfallJson['has_more'] def data(self): - if self.__checkForKey('data') is None: - return KeyError('This object has no key \'data\'') + self._checkForKey('data') return self.scryfallJson['data'] def data_length(self): - if self.__checkForKey('data') is None: - return KeyError('This object has no key \'data\'') + self._checkForKey('data') return len(self.scryfallJson['data']) def set_object(self, num): - if self.__checkForTupleKey('data', num, 'object') is None: - return KeyError('This ruling has no key \'object\'') + self._checkForTupleKey('data', num, 'object') return self.scryfallJson['data'][num]['object'] def set_code(self, num): - if self.__checkForTupleKey('data', num, 'code') is None: - raise KeyError('This object has no key \'code\'') + self._checkForTupleKey('data', num, 'code') return self.scryfallJson['data'][num]['code'] def set_mtgo_code(self, num): - if self.__checkForTupleKey('data', num, 'mtgo_code') is None: - raise KeyError('This object has no key \'mtgo_code\'') + self._checkForTupleKey('data', num, 'mtgo_code') return self.scryfallJson['data'][num]['mtgo_code'] def set_name(self, num): - if self.__checkForTupleKey('data', num, 'name') is None: - raise KeyError('This object has no key \'name\'') + self._checkForTupleKey('data', num, 'name') return self.scryfallJson['data'][num]['name'] def set_set_type(self, num): - if self.__checkForTupleKey('data', num, 'set_type') is None: - raise KeyError('This object has no key \'set_type\'') + self._checkForTupleKey('data', num, 'set_type') return self.scryfallJson['data'][num]['set_type'] def set_released_at(self, num): - if self.__checkForTupleKey('data', num, 'released_at') is None: - raise KeyError('This object has no key \'released_at\'') + self._checkForTupleKey('data', num, 'released_at') return self.scryfallJson['data'][num]['released_at'] def set_block_code(self, num): - if self.__checkForTupleKey('data', num, 'block_code') is None: - raise KeyError('This object has no key \'block_code\'') + self._checkForTupleKey('data', num, 'block_code') return self.scryfallJson['data'][num]['block_code'] def set_block(self, num): - if self.__checkForTupleKey('data', num, 'block') is None: - raise KeyError('This object has no key \'block\'') + self._checkForTupleKey('data', num, 'block') return self.scryfallJson['data'][num]['block'] def set_parent_set_code(self, num): - if self.__checkForTupleKey('data', num, 'parent_set_code') is None: - raise KeyError('This object has no key \'parent_set_code\'') + self._checkForTupleKey('data', num, 'parent_set_code') return self.scryfallJson['data'][num]['parent_set_code'] def set_card_count(self, num): - if self.__checkForTupleKey('data', num, 'card_count') is None: - raise KeyError('This object has no key \'card_count\'') + self._checkForTupleKey('data', num, 'card_count') return self.scryfallJson['data'][num]['card_count'] def set_digital(self, num): - if self.__checkForTupleKey('data', num, 'digital') is None: - raise KeyError('This object has no key \'digital\'') + self._checkForTupleKey('data', num, 'digital') return self.scryfallJson['data'][num]['digital'] def set_foil(self, num): - if self.__checkForTupleKey('data', num, 'foil') is None: - raise KeyError('This object has no key \'foil\'') + self._checkForTupleKey('data', num, 'foil') return self.scryfallJson['data'][num]['foil'] def set_icon_svg_uri(self, num): - if self.__checkForTupleKey('data', num, 'icon_svg_uri') is None: - raise KeyError('This object has no key \'icon_svg_uri\'') + self._checkForTupleKey('data', num, 'icon_svg_uri') return self.scryfallJson['data'][num]['icon_svg_uri'] def set_search_uri(self, num): - if self.__checkForTupleKey('data', num, 'search_uri') is None: - raise KeyError('This object has no key \'search_uri\'') + self._checkForTupleKey('data', num, 'search_uri') return self.scryfallJson['data'][num]['search_uri']