def __getitem__(self, hash_value):
    """
    retrieve the record from the file which hashed to the given value.

    :return: the item in the indexed file that hashed to the given value.
    :raise IndexError:
    """
    # if we haven't seen this one yet, expand the index until we do..
    if hash_value not in self._index:
      if self._no_reindex:
        raise IndexError("No such hash value in index: " + str(hash_value))
      self.__build_index(until=hash_value)

    # if we still haven't seen it, fail; it cannot be retrieved (at least,
    # not at the moment)
    if hash_value not in self._index:
      fn = (" (" + str(self._indexed_filename) + ") "
            if self._indexed_filename is not None else "")
      raise IndexError("Unable to retrieve record (" + str(hash_value) +
                       ") from indexed file" + fn +
                       "; reason: no such record found")

    # we got a match to the hash_value, attempt to seek to this location and
    # return the next element
    orig_pos = self._indexed_file_handle.tell()
    self._indexed_file_handle.seek(self._index[hash_value])
    r_iter = self.record_iterator(self._indexed_file_handle)
    try:
      return r_iter.next()
    except StopIteration:
      fn = (" (for " + str(self._indexed_filename) + ")"
            if self._indexed_filename is None else "")
      raise IndexError("Fatal error, index" + fn +
                       " specifies location beyond end of indexed file")
    finally:
      self._indexed_file_handle.seek(orig_pos)
def __getitem__ ( self , hash_value ) : if hash_value not in self . _index : if self . _no_reindex : raise IndexError ( "No such hash value in index: " + str ( hash_value ) ) self . __build_index ( until = hash_value ) if hash_value not in self . _index : fn = ( " (" + str ( self . _indexed_filename ) + ") " if self . _indexed_filename is not None else "" ) raise IndexError ( "Unable to retrieve record (" + str ( hash_value ) + ") from indexed file" + fn + "; reason: no such record found" ) orig_pos = self . _indexed_file_handle . tell ( ) self . _indexed_file_handle . seek ( self . _index [ hash_value ] ) r_iter = self . record_iterator ( self . _indexed_file_handle ) try : return r_iter . next ( ) except StopIteration : fn = ( " (for " + str ( self . _indexed_filename ) + ")" if self . _indexed_filename is None else "" ) raise IndexError ( "Fatal error, index" + fn + " specifies location beyond end of indexed file" ) finally : self . _indexed_file_handle . seek ( orig_pos )
retrieve the record from the file which hashed to the given value.

    :return: the item in the indexed file that hashed to the given value.
    :raise IndexError: