summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-08-11 21:30:36 +0000
committerZac Medico <zmedico@gentoo.org>2009-08-11 21:30:36 +0000
commitaa3c8d52c4686ff9bb6a45f324569135c2f7dad6 (patch)
tree32f0fc57a3e0d2efbd34894cf8410b00c62f7797
parent2e9112e43f05b9ddd62c56e1d31142c1dc581928 (diff)
downloadportage-aa3c8d52c4686ff9bb6a45f324569135c2f7dad6.tar.gz
portage-aa3c8d52c4686ff9bb6a45f324569135c2f7dad6.tar.bz2
portage-aa3c8d52c4686ff9bb6a45f324569135c2f7dad6.zip
Update imports to import portage.os (with unicode wrappers), and use
_unicode_encode() and _unicode_decode() where appropriate. svn path=/main/trunk/; revision=13999
-rw-r--r--pym/portage/__init__.py1
-rw-r--r--pym/portage/util.py34
2 files changed, 16 insertions, 19 deletions
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py
index efb5ce79c..9a40f7ad7 100644
--- a/pym/portage/__init__.py
+++ b/pym/portage/__init__.py
@@ -66,6 +66,7 @@ try:
'get_operator,isjustname,isspecific,isvalidatom,' + \
'match_from_list,match_to_list',
'portage.eclass_cache',
+ 'portage.exception',
'portage.getbinpkg',
'portage.locks',
'portage.locks:lockdir,lockfile,unlockdir,unlockfile',
diff --git a/pym/portage/util.py b/pym/portage/util.py
index a12b8a18e..fee786826 100644
--- a/pym/portage/util.py
+++ b/pym/portage/util.py
@@ -22,9 +22,12 @@ import stat
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
@@ -56,9 +59,9 @@ def writemsg(mystr,noiselevel=0,fd=None):
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()
@@ -321,8 +324,8 @@ def grablines(myfilename,recursive=0):
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:
@@ -357,10 +360,10 @@ def shlex_split(s):
"""
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):
@@ -388,9 +391,9 @@ def getconfig(mycfg, tolerant=0, allow_sourcing=False, expand=True):
# 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'
@@ -451,10 +454,8 @@ def getconfig(mycfg, tolerant=0, allow_sourcing=False, expand=True):
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]
@@ -585,7 +586,7 @@ def pickle_read(filename,default=None,debug=0):
return default
data = None
try:
- myf = open(filename, 'rb')
+ myf = open(_unicode_encode(filename), 'rb')
mypickle = pickle.Unpickler(myf)
data = mypickle.load()
myf.close()
@@ -801,11 +802,6 @@ def apply_recursive_permissions(top, uid=-1, gid=-1,
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.