def __getitem__(self, item): if isinstance(item, slice): return [self.results[ii] for ii in range(*item.indices(len(self)))] elif isinstance(item, int): return self.results[item] else: raise TypeError("Invalid argument type")
def __getitem__(self, item): if isinstance(item, slice): return [self.results[ii] for ii in range(*item.indices(len(self)))] elif isinstance(item, int): return self.results[item] else: raise TypeError("Invalid argument type")
def __getitem__(self, item): if isinstance(item, slice): if item.step and item.step != 1: raise ValueError("steps not supported") must_count_result_set = False if item.start is None or item.start == 0: start = 0 else: start = item.start if item.start < 0: must_count_result_set = True if item.stop is None or item.stop == 0: numrows = 0 else: numrows = item.stop - start if item.stop < 0: must_count_result_set = True elif numrows <= 0: return [] if must_count_result_set: log.debug('Must count result set') # general case item_range = range(*item.indices(len(self))) if not len(item_range): return [] start, numrows = item_range[0], len(item_range) try: return list(self._perform_query(start, numrows)) except StopIteration: return [] elif isinstance(item, int): if item < 0: item += len(self) if item < 0: return None try: return next(self._perform_query(item, 1)) except StopIteration: return None else: raise TypeError("invalid type")
def __getitem__(self, item): if isinstance(item, slice): if item.step and item.step != 1: raise ValueError("steps not supported") must_count_result_set = False if item.start is None or item.start == 0: start = 0 else: start = item.start if item.start < 0: must_count_result_set = True if item.stop is None or item.stop == 0: numrows = 0 else: numrows = item.stop - start if item.stop < 0: must_count_result_set = True elif numrows <= 0: return [] if must_count_result_set: log.debug('Must count result set') # general case item_range = range(*item.indices(len(self))) if not len(item_range): return [] start, numrows = item_range[0], len(item_range) try: return list(self._perform_query(start, numrows)) except StopIteration: return [] elif isinstance(item, int): if item < 0: item += len(self) if item < 0: return None try: return next(self._perform_query(item, 1)) except StopIteration: return None else: raise TypeError("invalid type")
def _refresh_if_needed(self, request_ret): refresh_required = False if request_ret.status_code not in range(200, 300): try: message = json.loads(request_ret.text)[0] except: message = request_ret.text raise ServerError(request_ret.status_code, message, result="Did not update {} record.".format( self.__class__.__name__)) else: try: message = request_ret.json() log.debug("Received response: %s" % message) if list(message.keys()) == ["result"]: post_result = message.get("result", None) if post_result and post_result != "success": raise ServerError( request_ret.status_code, post_result, result="Did not update {0:s} record.".format( self.__class__.__name__)) else: refresh_required = True else: self._info = json.loads(request_ret.text) if message.keys() == ["id"]: # if all we got back was an ID, try refreshing to get the entire record. log.debug( "Only received an ID back from the server, forcing a refresh" ) refresh_required = True else: self._full_init = True except: refresh_required = True self._dirty_attributes = {} if refresh_required: self.refresh() return self._model_unique_id