import string
import sys
+import portage
+from portage import os
+from portage import _unicode_encode
+from portage import _unicode_decode
from portage.exception import PortageException, FileNotFound, \
OperationNotPermitted, PermissionDenied, ReadOnlyFileSystem
-import portage.exception
from portage.dep import isvalidatom
from portage.proxy.objectproxy import ObjectProxy
from portage.cache.mappings import UserDict
if fd is None:
fd = sys.stderr
if noiselevel <= noiselimit:
- if sys.hexversion < 0x3000000 and isinstance(mystr, unicode):
+ if sys.hexversion < 0x3000000:
# avoid potential UnicodeEncodeError
- mystr = mystr.encode('utf_8', 'replace')
+ mystr = _unicode_encode(mystr)
fd.write(mystr)
fd.flush()
os.path.join(myfilename, f), recursive))
else:
try:
- myfile = codecs.open(myfilename, mode='r',
- encoding='utf_8', errors='replace')
+ myfile = codecs.open(_unicode_encode(myfilename),
+ mode='r', encoding='utf_8', errors='replace')
mylines = myfile.readlines()
myfile.close()
except IOError, e:
"""
is_unicode = sys.hexversion < 0x3000000 and isinstance(s, unicode)
if is_unicode:
- s = s.encode('utf_8', 'replace')
+ s = _unicode_encode(s)
rval = shlex.split(s)
if is_unicode:
- rval = [unicode(x, encoding='utf_8', errors='replace') for x in rval]
+ rval = [_unicode_decode(x) for x in rval]
return rval
class _tolerant_shlex(shlex.shlex):
# NOTE: shex doesn't seem to supported unicode objects
# (produces spurious \0 characters with python-2.6.2)
if sys.hexversion < 0x3000000:
- content = open(mycfg, 'rb').read()
+ content = open(_unicode_encode(mycfg), 'rb').read()
else:
- content = open(mycfg, mode='r',
+ content = open(_unicode_encode(mycfg), mode='r',
encoding='utf_8', errors='replace').read()
if content and content[-1] != '\n':
content += '\n'
raise portage.exception.CorruptionError("ParseError: Unexpected EOF: "+str(mycfg)+": line "+str(lex.lineno))
else:
return mykeys
- if not isinstance(key, unicode):
- key = unicode(key, encoding='utf_8', errors='replace')
- if not isinstance(val, unicode):
- val = unicode(val, encoding='utf_8', errors='replace')
+ key = _unicode_decode(key)
+ val = _unicode_decode(val)
if expand:
mykeys[key] = varexpand(val, expand_map)
expand_map[key] = mykeys[key]
return default
data = None
try:
- myf = open(filename, 'rb')
+ myf = open(_unicode_encode(filename), 'rb')
mypickle = pickle.Unpickler(myf)
data = mypickle.load()
myf.close()
Returns True if all permissions are applied and False if some are left
unapplied."""
- if isinstance(top, unicode):
- # Avoid UnicodeDecodeError raised from
- # os.path.join when called by os.walk.
- top = top.encode('utf_8', 'replace')
-
if onerror is None:
# Default behavior is to dump errors to stderr so they won't
# go unnoticed. Callers can pass in a quiet instance.