From: Zac Medico Date: Tue, 11 Aug 2009 21:30:36 +0000 (-0000) Subject: Update imports to import portage.os (with unicode wrappers), and use X-Git-Tag: v2.2_rc39~106 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=aa3c8d52c4686ff9bb6a45f324569135c2f7dad6;p=portage.git Update imports to import portage.os (with unicode wrappers), and use _unicode_encode() and _unicode_decode() where appropriate. svn path=/main/trunk/; revision=13999 --- 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.