[Pywikipedia-l] SVN: [5470] trunk/pywikipedia/diskcache.py

nicdumz at svn.wikimedia.org nicdumz at svn.wikimedia.org
Fri May 30 10:31:38 UTC 2008


Revision: 5470
Author:   nicdumz
Date:     2008-05-30 10:31:38 +0000 (Fri, 30 May 2008)

Log Message:
-----------
Increasing the length field size from 4 to 6 : some en: messages were longer

Modified Paths:
--------------
    trunk/pywikipedia/diskcache.py

Modified: trunk/pywikipedia/diskcache.py
===================================================================
--- trunk/pywikipedia/diskcache.py	2008-05-30 05:46:52 UTC (rev 5469)
+++ trunk/pywikipedia/diskcache.py	2008-05-30 10:31:38 UTC (rev 5470)
@@ -1,4 +1,5 @@
 import random
+import sys
 import os
 # http://mail.python.org/pipermail/python-list/2006-March/375280.html
 try:
@@ -47,10 +48,10 @@
                 
             if len(key) > 0xFF:
                 raise RuntimeError('Key length must be smaller than %i' % 0xFF)
-            if len(value) > 0xFFFF:
-                raise RuntimeError('Value length must be smaller than %i' % 0xFFFF)
+            if len(value) > 0xFFFFFF:
+                raise RuntimeError('Value length must be smaller than %i' % 0xFFFFFF)
                 
-            self.cache_file.write('%02x%s%04x%s' % (len(key), key, len(value), value))
+            self.cache_file.write('%02x%s%06x%s' % (len(key), key, len(value), value))
             
         self.lookup = lookup
         self.cache_file.seek(0)
@@ -93,7 +94,7 @@
             length = int(self.read(2, key), 16)
             k = self.read(length, key)
             if k == key:
-                length = int(self.read(4, key), 16)
+                length = int(self.read(6, key), 16)
                 value = self.read(length, key).decode('utf-8')
                 if len(self.cache) > self.max_size:
                     del self.cache[0]
@@ -103,7 +104,7 @@
             elif k[0] != index:
                 raise KeyError(key)
             
-            length = int(self.read(4, key), 16)
+            length = int(self.read(6, key), 16)
             self.cache_file.seek(length, os.SEEK_CUR)
         
         





More information about the Pywikipedia-l mailing list