Merged from trunk -r15166:15169
authorFabian Groffen <grobian@gentoo.org>
Tue, 5 Jan 2010 19:26:14 +0000 (19:26 -0000)
committerFabian Groffen <grobian@gentoo.org>
Tue, 5 Jan 2010 19:26:14 +0000 (19:26 -0000)
   | 15167   | Rearrange _selinux ImportError handling so the workaround    |
   | zmedico | for bug #298310 isn't necessary.                             |

   | 15168   | Handle AttributeError inside atomic_ofstream.__del__. Thanks |
   | zmedico | to Cardoe for reporting.                                     |

   | 15169   | In python-2.x, convert PortageException.value attribute from |
   | zmedico | unicode to str in order to avoid empty output with string    |
   |         | format operator.                                             |

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

pym/portage/__init__.py
pym/portage/exception.py
pym/portage/util.py

index aa499cba33c77b21efab8a03a778e104099aae16..a2bb7fb292f87407e2c27b03be9902bc18f2293e 100644 (file)
@@ -289,23 +289,19 @@ import shutil as _shutil
 shutil = _unicode_module_wrapper(_shutil, encoding=_encodings['fs'])
 
 # Imports below this point rely on the above unicode wrapper definitions.
-_selinux = None
-selinux = None
-_selinux_merge = None
 try:
        import portage._selinux
-       # Make sure the _selinux attribute is correctly reinitialized after
-       # reload(portage) is called. See bug #298310.
-       _selinux = sys.modules['portage._selinux']
        selinux = _unicode_module_wrapper(_selinux,
                encoding=_encodings['fs'])
        _selinux_merge = _unicode_module_wrapper(_selinux,
                encoding=_encodings['merge'])
-except OSError as e:
-       sys.stderr.write("!!! SELinux not loaded: %s\n" % str(e))
+except (ImportError, OSError) as e:
+       if isinstance(e, OSError):
+               sys.stderr.write("!!! SELinux not loaded: %s\n" % str(e))
        del e
-except ImportError:
-       pass
+       _selinux = None
+       selinux = None
+       _selinux_merge = None
 
 from portage.manifest import Manifest
 
index 85efc2767af64d50227704b886a42fc777cc2da7..900dab7df0f188fc61f807ec949949ac225e75d1 100644 (file)
@@ -3,6 +3,7 @@
 # $Id$
 
 import sys
+from portage import _unicode_encode
 from portage.localization import _
 
 if sys.hexversion >= 0x3000000:
@@ -12,6 +13,10 @@ class PortageException(Exception):
        """General superclass for portage exceptions"""
        def __init__(self,value):
                self.value = value[:]
+               if sys.hexversion < 0x3000000 and isinstance(self.value, unicode):
+                       # Workaround for string formatting operator and unicode value
+                       # attribute triggering empty output in formatted string.
+                       self.value = _unicode_encode(self.value)
        def __str__(self):
                if isinstance(self.value, basestring):
                        return self.value
index a507edbc83fee3295a379a68197a2824587eab2c..e8a33f3ca53b7cf8ca80501bd9e50dc26a39b4bb 100644 (file)
@@ -1010,9 +1010,13 @@ class atomic_ofstream(ObjectProxy):
        def __del__(self):
                """If the user does not explicitely call close(), it is
                assumed that an error has occurred, so we abort()."""
-               f = object.__getattribute__(self, '_file')
-               if not f.closed:
-                       self.abort()
+               try:
+                       f = object.__getattribute__(self, '_file')
+               except AttributeError:
+                       pass
+               else:
+                       if not f.closed:
+                               self.abort()
                # ensure destructor from the base class is called
                base_destructor = getattr(ObjectProxy, '__del__', None)
                if base_destructor is not None: