summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArfrever Frehtes Taifersar Arahesis <arfrever@gentoo.org>2009-09-21 14:15:49 +0000
committerArfrever Frehtes Taifersar Arahesis <arfrever@gentoo.org>2009-09-21 14:15:49 +0000
commit2f9b8514e4d4b15569ebc88e7da36f5ae972c37e (patch)
tree2135fe4428dd3e9ec4c8226885fae1d30e14514a
parentff3b5059ea1b37ac27ae917441fd6f7a4e1eff8d (diff)
downloadportage-2f9b8514e4d4b15569ebc88e7da36f5ae972c37e.tar.gz
portage-2f9b8514e4d4b15569ebc88e7da36f5ae972c37e.tar.bz2
portage-2f9b8514e4d4b15569ebc88e7da36f5ae972c37e.zip
Support both Python 2 and 3 in portage._unicode_encode() and portage._unicode_decode().
Update decoding in some files. svn path=/main/trunk/; revision=14321
-rwxr-xr-xbin/portageq2
-rw-r--r--pym/_emerge/EbuildMetadataPhase.py3
-rw-r--r--pym/_emerge/main.py2
-rw-r--r--pym/portage/__init__.py12
4 files changed, 9 insertions, 10 deletions
diff --git a/bin/portageq b/bin/portageq
index 59eedc59f..34c4fb401 100755
--- a/bin/portageq
+++ b/bin/portageq
@@ -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])
diff --git a/pym/_emerge/EbuildMetadataPhase.py b/pym/_emerge/EbuildMetadataPhase.py
index 07d993b7d..1231b1b11 100644
--- a/pym/_emerge/EbuildMetadataPhase.py
+++ b/pym/_emerge/EbuildMetadataPhase.py
@@ -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):
diff --git a/pym/_emerge/main.py b/pym/_emerge/main.py
index 9a101803f..83b50df63 100644
--- a/pym/_emerge/main.py
+++ b/pym/_emerge/main.py
@@ -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])
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index 4b19cb9d9..c8dff4c5c 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -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):