[ZODB-Dev] Typechecking oid in getitem

Christian Reis kiko at async.com.br
Mon May 19 15:38:17 EDT 2003


On Mon, May 19, 2003 at 05:53:35PM +0100, Toby Dickenson wrote:
> On Monday 19 May 2003 5:41 pm, Christian Reis wrote:
> > On Mon, May 19, 2003 at 01:16:26PM -0300, Christian Reis wrote:
> > > Note that many places we already do try: except KeyError, so maybe it
> > > would be a matter of changing KeyError to (KeyError, TypeError) in these
> > > places?
> >
> > How does this look?
> 
> POSKeyError implies "object not found under that oid", not "malformatted oid".
> 
> What about something like
> 
>          try:
>              pos=_index[oid]
>          except KeyError:
>              raise POSKeyError(oid)
> +        except TypeError:
> +            raise TypeError('malformatted oid %r' % (oid,))

Okay, sounds good. How does this look? 

Index: FileStorage.py
===================================================================
RCS file: /cvs-repository/ZODB3/ZODB/FileStorage.py,v
retrieving revision 1.132
diff -u -r1.132 FileStorage.py
--- FileStorage.py	16 May 2003 20:19:15 -0000	1.132
+++ FileStorage.py	19 May 2003 17:37:37 -0000
@@ -595,6 +595,8 @@
             pos=_index[oid]
         except KeyError:
             raise POSKeyError(oid)
+        except TypeError:
+            raise TypeError('malformatted oid %r' % (oid,))
         file.seek(pos)
         read=file.read
         h=read(DATA_HDR_LEN)
@@ -616,6 +618,8 @@
             pos = _index[oid]
         except KeyError:
             raise POSKeyError(oid)
+        except TypeError:
+            raise TypeError('malformatted oid %r' % (oid,))
         file.seek(pos)
         read = file.read
         h = read(DATA_HDR_LEN)
@@ -655,6 +659,8 @@
                 pos = self._index[oid]
             except KeyError:
                 raise POSKeyError(oid)
+            except TypeError:
+                raise TypeError('malformatted oid %r' % (oid,))
             while 1:
                 seek(pos)
                 h=read(DATA_HDR_LEN)
@@ -686,6 +692,8 @@
                 pos = self._index[oid]
             except KeyError:
                 raise POSKeyError(oid)
+            except TypeError:
+                raise TypeError('malformatted oid %r' % (oid,))
             file=self._file
             file.seek(pos)
             doid,serial,prev,tloc,vlen = unpack(">8s8s8s8sH", file.read(34))
@@ -1082,7 +1090,12 @@
     def getSerial(self, oid):
         self._lock_acquire()
         try:
-            return self._getSerial(oid, self._index[oid])
+            try:
+                return self._getSerial(oid, self._index[oid])
+            except KeyError:
+                raise POSKeyError(oid)
+            except TypeError:
+                raise TypeError('malformatted oid %r' % (oid,))
         finally:
             self._lock_release()
 
@@ -1370,7 +1383,12 @@
             file=self._file
             seek=file.seek
             read=file.read
-            pos=self._index[oid]
+            try:
+                pos=self._index[oid]
+            except KeyError:
+                raise POSKeyError(oid)
+            except TypeError:
+                raise TypeError('malformatted oid %r' % (oid,))
             wantver=version
 
             while 1:
@@ -1503,6 +1521,8 @@
             pos = self._index[oid]
         except KeyError:
             return None
+        except TypeError:
+            raise TypeError('malformatted oid %r' % (oid,))
         self._file.seek(pos)
         # first 8 bytes are oid, second 8 bytes are serialno
         h = self._file.read(16)

Take care,
--
Christian Reis, Senior Engineer, Async Open Source, Brazil.
http://async.com.br/~kiko/ | [+55 16] 261 2331 | NMFL



More information about the ZODB-Dev mailing list