Support both Python 2 and 3 in portage._unicode_encode() and portage._unicode_decode().
authorArfrever Frehtes Taifersar Arahesis <arfrever@gentoo.org>
Mon, 21 Sep 2009 14:15:49 +0000 (14:15 -0000)
committerArfrever Frehtes Taifersar Arahesis <arfrever@gentoo.org>
Mon, 21 Sep 2009 14:15:49 +0000 (14:15 -0000)
Update decoding in some files.

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

bin/portageq
pym/_emerge/EbuildMetadataPhase.py
pym/_emerge/main.py
pym/portage/__init__.py

index 59eedc59f82e652982fb595f03f23c72f2a0ff4a..34c4fb401e05620a771369693cdfb79ab71e228e 100755 (executable)
@@ -610,7 +610,7 @@ def main():
                os.environ["ROOT"] = sys.argv[2]
 
        args = sys.argv[2:]
-       if args and not isinstance(args[0], unicode):
+       if args and sys.hexversion < 0x3000000 and not isinstance(args[0], unicode):
                for i in range(len(args)):
                        args[i] = portage._unicode_decode(args[i])
 
index 07d993b7d1d14ba45eadd24663140345213773fd..1231b1b115feb10c1f480d024ff06d5a0900dbf5 100644 (file)
@@ -9,6 +9,7 @@ from portage.cache.mappings import slot_dict_class
 import portage
 from portage import os
 from portage import _encodings
+from portage import _unicode_decode
 from portage import _unicode_encode
 import fcntl
 import codecs
@@ -122,7 +123,7 @@ class EbuildMetadataPhase(SubProcess):
        def _set_returncode(self, wait_retval):
                SubProcess._set_returncode(self, wait_retval)
                if self.returncode == os.EX_OK:
-                       metadata_lines = ''.join(unicode(chunk,
+                       metadata_lines = ''.join(_unicode_decode(chunk,
                                encoding=_encodings['repo.content'], errors='replace')
                                for chunk in self._raw_metadata).splitlines()
                        if len(portage.auxdbkeys) != len(metadata_lines):
index 9a101803fb7eed5c9912fa9292caedaf242c74ab..83b50df633b83475dcc66aa3c4a4e03cc989fd11 100644 (file)
@@ -769,7 +769,7 @@ def parse_opts(tmpcmdline, silent=False):
        if myaction is None and myoptions.deselect is True:
                myaction = 'deselect'
 
-       if myargs and not isinstance(myargs[0], unicode):
+       if sys.hexversion < 0x3000000 and not isinstance(myargs[0], unicode):
                for i in range(len(myargs)):
                        myargs[i] = portage._unicode_decode(myargs[i])
 
index 4b19cb9d9ff790c58ffe9601d3aae257e0bdc92a..c8dff4c5c8c146620bc9167b283b5be57a3f570b 100644 (file)
@@ -142,18 +142,16 @@ if _encodings['merge'] is None:
 
 def _unicode_encode(s, encoding=_encodings['content'],
        errors='backslashreplace'):
-       if isinstance(s, unicode):
+       if not isinstance(s, bytes):
                s = s.encode(encoding, errors)
        return s
 
 def _unicode_decode(s, encoding=_encodings['content'], errors='replace'):
-       if not isinstance(s, unicode):
-               if sys.hexversion < 0x3000000:
-                       if isinstance(s, basestring):
-                               s = unicode(s, encoding=encoding, errors=errors)
+       if isinstance(s, bytes):
+               if sys.hexversion >= 0x3000000:
+                       s = str(s, encoding=encoding, errors=errors)
                else:
-                       if isinstance(s, bytes):
-                               s = unicode(s, encoding=encoding, errors=errors)
+                       s = unicode(s, encoding=encoding, errors=errors)
        return s
 
 class _unicode_func_wrapper(object):