def __getitem__(self, key): """Get an attribute, by passing it as a key.""" try: return dict.__getitem__(self, key) except KeyError: raise IndexerAttributeNotFound( 'Cannot find attribute {0!r}'.format(key))
def __getitem__(self, key): """Return Episode or Show-data.""" if key in self: # Key is an episode, return it return dict.__getitem__(self, key) if key in self.data: # Non-numeric request is for show-data return dict.__getitem__(self.data, key) # Data wasn't found, raise appropriate error if isinstance(key, int) or key.isdigit(): # Episode number x was not found raise IndexerSeasonNotFound('Could not find season {0!r}'.format(key)) else: # If it's not numeric, it must be an attribute name, which # doesn't exist, so attribute error. raise IndexerAttributeNotFound('Cannot find attribute {0!r}'.format(key))