コード例 #1
0
ファイル: utest_utils.py プロジェクト: cfobel/durus
 def e(self):
     s = BytesIO()
     durus.utils.TRACE = True
     for x in ('', 'a', 'ab', 'a' * 1000):
         x = as_bytes(x)
         s.seek(0)
         write_int8_str(s, x)
         s.seek(0)
         assert x == read_int8_str(s)
     durus.utils.TRACE = False
コード例 #2
0
 def _build_index(self, repair):
     self.fp.seek(0)
     if read(self.fp, len(self.MAGIC)) != self.MAGIC:
         raise IOError("invalid storage (missing magic in %r)" % self.fp)
     index_offset = read_int8(self.fp)
     assert index_offset > 0
     self.fp.seek(index_offset)
     tmp_index = loads(decompress(read_int8_str(self.fp)))
     self.index = {}
     def oid_as_bytes(oid):
         if isinstance(oid, byte_string):
             return oid
         else:
             return oid.encode('latin1')
     for tmp_oid in tmp_index:
         self.index[oid_as_bytes(tmp_oid)] = tmp_index[tmp_oid]
     del tmp_index
     while 1:
         # Read one transaction each time here.
         oids = {}
         transaction_offset = self.fp.tell()
         try:
             while 1:
                 object_record_offset = self.fp.tell()
                 record = self._read_block()
                 if len(record) == 0:
                     break # normal termination
                 if len(record) < 12:
                     raise ShortRead("Bad record size")
                 oid = record[0:8]
                 oids[oid] = object_record_offset
             # We've reached the normal end of a transaction.
             self.index.update(oids)
             oids.clear()
         except (ValueError, IOError):
             if self.fp.tell() > transaction_offset:
                 if not repair:
                     raise
                 # The transaction was malformed. Attempt repair.
                 self.fp.seek(transaction_offset)
                 self.fp.truncate()
             break
コード例 #3
0
 def get_item_at_position(self, position):
     """(int) -> str, str
     """
     self.file.seek(position)
     record = read_int8_str(self.file)
     return record[:8], record[8:]
コード例 #4
0
ファイル: shelf.py プロジェクト: Schevo/durus
 def get_item_at_position(self, position):
     """(int) -> str, str
     """
     self.file.seek(position)
     record = read_int8_str(self.file)
     return record[:8], record[8:]