Inside _parse_data(), don't rely on the magic 22 line count for the flat_list
authorZac Medico <zmedico@gentoo.org>
Thu, 20 Nov 2008 21:02:40 +0000 (21:02 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 20 Nov 2008 21:02:40 +0000 (21:02 -0000)
format, since it doesn't make a significant performance difference and it
places an artificial limit on the number of keys that can be stored.

svn path=/main/trunk/; revision=12008

pym/portage/cache/metadata.py

index 1c65ee8be241f8132c73430f1d2a341b450fdbd1..c3c83a019eebe9dec9aa802edd6bf44f25acea18 100644 (file)
@@ -3,7 +3,7 @@
 # License: GPL2
 # $Id$
 
-import os, stat, types
+import os, re, stat, types
 from portage.cache import flat_hash
 import portage.eclass_cache 
 from portage.cache.template import reconstruct_eclasses
@@ -22,6 +22,8 @@ class database(flat_hash.database):
 
        autocommits = True
 
+       _hashed_re = re.compile('^(\\w+)=([^\n]*)')
+
        def __init__(self, location, *args, **config):
                loc = location
                super(database, self).__init__(location, *args, **config)
@@ -33,34 +35,23 @@ class database(flat_hash.database):
 
 
        def _parse_data(self, data, cpv):
-               # easy attempt first.
+               _hashed_re_match = self._hashed_re.match
                data = list(data)
-               if len(data) != magic_line_count:
-                       d = flat_hash.database._parse_data(self, data, cpv)
-               else:
-                       # this one's interesting.
-                       d = {}
-
-                       for line in data:
-                               # yes, meant to iterate over a string.
-                               hashed = False
-                               # poor mans enumerate.  replace when python 2.3 is required
-                               for idx, c in zip(range(len(line)), line):
-                                       if not c.isalpha():
-                                               if c == "=" and idx > 0:
-                                                       hashed = True
-                                                       d[line[:idx]] = line[idx + 1:].rstrip("\n")
-                                               elif c == "_" or c.isdigit():
-                                                       continue
-                                               break
+               d = {}
 
-                               if not hashed:
-                                       # non hashed.
-                                       d.clear()
-                                       # poor mans enumerate.  replace when python 2.3 is required
-                                       for idx, key in zip(range(len(self.auxdbkey_order)), self.auxdbkey_order):
-                                               d[key] = data[idx].strip()
-                                       break
+               for line in data:
+                       hashed = False
+                       hashed_match = _hashed_re_match(line)
+                       if hashed_match is None:
+                               d.clear()
+                               try:
+                                       for i, key in enumerate(self.auxdbkey_order):
+                                               d[key] = data[i].rstrip("\n")
+                               except IndexError:
+                                       pass
+                               break
+                       else:
+                               d[hashed_match.group(1)] = hashed_match.group(2)
 
                if "_eclasses_" not in d:
                        if "INHERITED" in d: