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])
import portage
from portage import os
from portage import _encodings
+from portage import _unicode_decode
from portage import _unicode_encode
import fcntl
import codecs
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):
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])
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):