Merged from trunk -r12771:12779
authorFabian Groffen <grobian@gentoo.org>
Sun, 8 Mar 2009 21:06:09 +0000 (21:06 -0000)
committerFabian Groffen <grobian@gentoo.org>
Sun, 8 Mar 2009 21:06:09 +0000 (21:06 -0000)
   | 12772   | Fix LazyItemsDict.update() to create new _SingletonWrapper   |
   | zmedico | instances that reference self.                               |

   | 12773   | Simplify LazyItemsDict internals.                            |
   | zmedico |                                                              |

   | 12774   | Allow unicode type values in config.__setitem__(). Thanks to |
   | zmedico | Arfrever Frehtes Taifersar Arahesis for this patch.          |

   | 12775   | Always use basestring instead of str with isinstance().      |
   | zmedico |                                                              |

   | 12776   | Fix __getitem__ to convert mtime to long, and remove         |
   | zmedico | unreachable code from _parse_data().                         |

   | 12777   | Fix an issue with incomplete deepcopy of _LazyItem instances |
   | zmedico | inside LazyItemsDict.__deepcopy__(). Thanks to Arfrever for  |
   |         | reporting.                                                   |

   | 12778   | Remove unnecessary list() from previous commit.              |
   | zmedico |                                                              |

   | 12779   | Use slice instead of startwith in stack_* incremental        |
   | zmedico | processing.                                                  |

svn path=/main/branches/prefix/; revision=12787

pym/_emerge/__init__.py
pym/portage/__init__.py
pym/portage/cache/flat_hash.py
pym/portage/cache/template.py
pym/portage/mail.py
pym/portage/process.py
pym/portage/util.py

index b8d31a09ef307a0c0f928ae87be06a91c4bf127f..58dc1dba241392b1dbec0cf460d63799b7e6e33b 100644 (file)
@@ -9769,7 +9769,7 @@ class JobStatusDisplay(object):
                        object.__setattr__(self, "_term_codes", term_codes)
                encoding = sys.getdefaultencoding()
                for k, v in self._term_codes.items():
-                       if not isinstance(v, str):
+                       if not isinstance(v, basestring):
                                self._term_codes[k] = v.decode(encoding, 'replace')
 
        def _init_term(self):
index 4ac8bffc216769f89ec657dc18d78696cb7af76a..4ed25e280b5867a3542e2114edf910826ee0a395 100644 (file)
@@ -2991,7 +2991,7 @@ class config(object):
 
        def __setitem__(self,mykey,myvalue):
                "set a value; will be thrown away at reset() time"
-               if not isinstance(myvalue, str):
+               if not isinstance(myvalue, basestring):
                        raise ValueError("Invalid type being used as a value: '%s': '%s'" % (str(mykey),str(myvalue)))
                self.modifying()
                self.modifiedkeys += [mykey]
index dda380e1c6be624620598ec1e1ff1583a853b48f..f6bf6d078e774b72563c122e6753f953f3dc89d1 100644 (file)
@@ -33,6 +33,16 @@ class database(fs_template.FsBased):
                                        """Backward compatibility with old cache that uses mtime
                                        mangling."""
                                        d["_mtime_"] = long(os.fstat(myf.fileno()).st_mtime)
+                               mtime = d.get('_mtime_')
+                               if mtime is None:
+                                       raise cache_errors.CacheCorruption(cpv,
+                                               '_mtime_ field is missing')
+                               try:
+                                       mtime = long(mtime)
+                               except ValueError:
+                                       raise cache_errors.CacheCorruption(cpv,
+                                               '_mtime_ conversion to long failed: %s' % (mtime,))
+                               d['_mtime_'] = mtime
                                return d
                        finally:
                                myf.close()
@@ -52,14 +62,6 @@ class database(fs_template.FsBased):
                else:
                        d["_eclasses_"] = {}
                return d
-               
-               for x in self._known_keys:
-                       if x not in d:
-                               d[x] = ''
-
-
-               return d
-
 
        def _setitem(self, cpv, values):
 #              import pdb;pdb.set_trace()
index 7fce8ef179e2b4c042e58d23922fc599ed277bb5..e782163384537a50ad4ee840979eb6fdad5ce24f 100644 (file)
@@ -169,7 +169,7 @@ class database(object):
                for key,match in match_dict.iteritems():
                        # XXX this sucks.
                        try:
-                               if isinstance(match, str):
+                               if isinstance(match, basestring):
                                        restricts[key] = re.compile(match).match
                                else:
                                        restricts[key] = re.compile(match[0],match[1]).match
index cf6ebd134e116a6ae3b3353d3c6fef85aa6ae0d9..72b4112649a39e1be7e224c37bc8385298fc1441 100644 (file)
@@ -17,7 +17,7 @@ def create_message(sender, recipient, subject, body, attachments=None):
                for x in attachments:
                        if isinstance(x, BaseMessage):
                                mymessage.attach(x)
-                       elif isinstance(x, str):
+                       elif isinstance(x, basestring):
                                mymessage.attach(TextMessage(x))
                        else:
                                raise portage.exception.PortageException("Can't handle type of attachment: %s" % type(x))
index 7c0fb342f3acfafae42c1b5e4c386ef245205b80..6f449c3d6da8b325918883acd6309d667e0b0f70 100644 (file)
@@ -175,7 +175,7 @@ def spawn(mycommand, env={}, opt_name=None, fd_pipes=None, returnpid=False,
        """
 
        # mycommand is either a str or a list
-       if isinstance(mycommand, str):
+       if isinstance(mycommand, basestring):
                mycommand = mycommand.split()
 
        # If an absolute path to an executable file isn't given
index 9461512e2ce2dbd787d4a59e7bdaf430b38ae89b..2d965355e3c5eef882e6de8b58e2e90328b5d152 100644 (file)
@@ -178,7 +178,7 @@ def stack_dictlist(original_dicts, incremental=0, incrementals=[], ignore_none=0
                                                if thing == "-*":
                                                        final_dict[y] = []
                                                        continue
-                                               elif thing.startswith("-"):
+                                               elif thing[:1] == '-':
                                                        try:
                                                                final_dict[y].remove(thing[1:])
                                                        except ValueError:
@@ -224,7 +224,7 @@ def stack_lists(lists, incremental=1):
                        if incremental:
                                if y == "-*":
                                        new_list.clear()
-                               elif y.startswith("-"):
+                               elif y[:1] == '-':
                                        new_list.pop(y[1:], None)
                                else:
                                        new_list[y] = True
@@ -1072,19 +1072,18 @@ class LazyItemsDict(dict):
        def addLazyItem(self, item_key, value_callable, *pargs, **kwargs):
                """Add a lazy item for the given key.  When the item is requested,
                value_callable will be called with *pargs and **kwargs arguments."""
-               if not pargs:
-                       pargs = None
-               if not kwargs:
-                       kwargs = None
-               self.lazy_items[item_key] = (value_callable, pargs, kwargs)
+               self.lazy_items[item_key] = \
+                       self._LazyItem(value_callable, pargs, kwargs, False)
                # make it show up in self.keys(), etc...
                dict.__setitem__(self, item_key, None)
+
        def addLazySingleton(self, item_key, value_callable, *pargs, **kwargs):
                """This is like addLazyItem except value_callable will only be called
                a maximum of 1 time and the result will be cached for future requests."""
-               self.addLazyItem(item_key,
-                       self._SingletonWrapper(self, item_key, value_callable,
-                               *pargs, **kwargs))
+               self.lazy_items[item_key] = \
+                       self._LazyItem(value_callable, pargs, kwargs, True)
+               # make it show up in self.keys(), etc...
+               dict.__setitem__(self, item_key, None)
 
        def update(self, *args, **kwargs):
                if len(args) > 1:
@@ -1111,14 +1110,21 @@ class LazyItemsDict(dict):
 
        def __getitem__(self, item_key):
                if item_key in self.lazy_items:
-                       value_callable, pargs, kwargs = self.lazy_items[item_key]
+                       lazy_item = self.lazy_items[item_key]
+                       pargs = lazy_item.pargs
                        if pargs is None:
                                pargs = ()
+                       kwargs = lazy_item.kwargs
                        if kwargs is None:
                                kwargs = {}
-                       return value_callable(*pargs, **kwargs)
+                       result = lazy_item.func(*pargs, **kwargs)
+                       if lazy_item.singleton:
+                               self[item_key] = result
+                       return result
+
                else:
                        return dict.__getitem__(self, item_key)
+
        def __setitem__(self, item_key, value):
                if item_key in self.lazy_items:
                        del self.lazy_items[item_key]
@@ -1167,35 +1173,30 @@ class LazyItemsDict(dict):
                        k_copy = deepcopy(k, memo)
                        if k in self.lazy_items:
                                lazy_item = self.lazy_items[k]
-                               try:
-                                       result.lazy_items[k_copy] = deepcopy(lazy_item, memo)
-                               except TypeError:
-                                       # If deepcopy fails for a lazy singleton, try to
-                                       # evaluate the singleton and deepcopy the result.
-                                       if not isinstance(lazy_item[0], self._SingletonWrapper):
-                                               raise
+                               if lazy_item.singleton:
                                        dict.__setitem__(result, k_copy, deepcopy(self[k], memo))
                                else:
+                                       result.lazy_items[k_copy] = deepcopy(lazy_item, memo)
                                        dict.__setitem__(result, k_copy, None)
                        else:
                                dict.__setitem__(result, k_copy, deepcopy(self[k], memo))
                return result
 
-       class _SingletonWrapper(object):
+       class _LazyItem(object):
+
+               __slots__ = ('func', 'pargs', 'kwargs', 'singleton')
 
-               __slots__ = ('_parent', '_key', '_callable', '_pargs', '_kwargs')
+               def __init__(self, func, pargs, kwargs, singleton):
 
-               def __init__(self, parent, key, value_callable, *pargs, **kwargs):
-                       self._parent = parent
-                       self._key = key
-                       self._callable = value_callable
-                       self._pargs = pargs
-                       self._kwargs = kwargs
+                       if not pargs:
+                               pargs = None
+                       if not kwargs:
+                               kwargs = None
 
-               def __call__(self):
-                       value = self._callable(*self._pargs, **self._kwargs)
-                       self._parent[self._key] = value
-                       return value
+                       self.func = func
+                       self.pargs = pargs
+                       self.kwargs = kwargs
+                       self.singleton = singleton
 
 class ConfigProtect(object):
        def __init__(self, myroot, protect_list, mask_list):