From 8dded616004052245e1edd353350bc9eeec67563 Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Mon, 24 Aug 2009 09:34:26 +0000 Subject: [PATCH] Merged from trunk -r14087:14097 | 14088 | Use _content_encoding where appropriate. | | zmedico | | | 14089 | Use the new portage.output._init(config_root) function. | | zmedico | | | 14090 | Use _content_encoding and _fs_encoding, and use strict | | zmedico | unicode exceptions where appropriate. | | 14091 | Replace the _{content,fs,merge}_encoding attributes with an | | zmedico | _encodings dict. | | 14092 | Use errors='backslashreplace' instead of 'replace' for the | | zmedico | default _unicode_encode() argument ('replace' substitutes | | | '?', which is not as useful). | | 14093 | Use portage.os and _encodings['fs'] where appropriate. | | zmedico | | | 14094 | Use portage.os and _encodings where appropriate. | | zmedico | | | 14095 | Use portage.os and _encodings where appropriate. | | zmedico | | | 14096 | Remove unused os import. | | zmedico | | | 14097 | Use portage.os and _encodings where appropriate. | | zmedico | | svn path=/main/branches/prefix/; revision=14141 --- pym/_emerge/actions.py | 2 +- pym/portage/__init__.py | 123 ++++++++++++++++++++--------------- pym/portage/cvstree.py | 19 ++++-- pym/portage/dbapi/vartree.py | 57 ++++++++++------ pym/portage/getbinpkg.py | 17 +++-- pym/portage/glsa.py | 14 +++- pym/portage/mail.py | 55 +++++++++------- pym/repoman/checks.py | 1 - pym/repoman/utilities.py | 10 ++- 9 files changed, 187 insertions(+), 111 deletions(-) diff --git a/pym/_emerge/actions.py b/pym/_emerge/actions.py index fe64d786c..82545cbc6 100644 --- a/pym/_emerge/actions.py +++ b/pym/_emerge/actions.py @@ -2644,7 +2644,7 @@ def load_emerge_config(trees=None): mtimedbfile = os.path.join("/", portage.CACHE_PATH.lstrip(os.path.sep), "mtimedb") mtimedb = portage.MtimeDB(mtimedbfile) - + portage.output._init(config_root=settings['PORTAGE_CONFIGROOT']) return settings, trees, mtimedb def chk_updated_cfg_files(target_root, config_protect): diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index 74ad998ff..07f4901e1 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -119,20 +119,26 @@ except ImportError, e: sys.stderr.write(" "+str(e)+"\n\n") raise -# Assume utf_8 encoding for content of all files. -_content_encoding = 'utf_8' - -# Assume utf_8 fs encoding everywhere except in merge code. -_fs_encoding = 'utf_8' +# Assume utf_8 fs encoding everywhere except in merge code, where the +# user's locale is respected. +_encodings = { + 'content' : 'utf_8', + 'fs' : 'utf_8', + 'merge' : sys.getfilesystemencoding(), +} -_merge_encoding = sys.getfilesystemencoding() +# Deprecated attributes. Instead use _encodings directly. +_content_encoding = _encodings['content'] +_fs_encoding = _encodings['fs'] +_merge_encoding = _encodings['merge'] -def _unicode_encode(s, encoding=_content_encoding, errors='replace'): +def _unicode_encode(s, encoding=_encodings['content'], + errors='backslashreplace'): if isinstance(s, unicode): s = s.encode(encoding, errors) return s -def _unicode_decode(s, encoding=_content_encoding, errors='replace'): +def _unicode_decode(s, encoding=_encodings['content'], errors='replace'): if not isinstance(s, unicode): if sys.hexversion < 0x3000000: if isinstance(s, basestring): @@ -155,7 +161,7 @@ class _unicode_func_wrapper(object): """ __slots__ = ('_func', '_encoding') - def __init__(self, func, encoding='utf_8'): + def __init__(self, func, encoding=_encodings['fs']): self._func = func self._encoding = encoding @@ -201,7 +207,7 @@ class _unicode_module_wrapper(object): """ __slots__ = ('_mod', '_encoding', '_overrides') - def __init__(self, mod, encoding='utf_8', overrides=None): + def __init__(self, mod, encoding=_encodings['fs'], overrides=None): object.__setattr__(self, '_mod', mod) object.__setattr__(self, '_encoding', encoding) object.__setattr__(self, '_overrides', overrides) @@ -233,12 +239,12 @@ _os_overrides = { } os = _unicode_module_wrapper(_os, overrides=_os_overrides, - encoding=_fs_encoding) + encoding=_encodings['fs']) _os_merge = _unicode_module_wrapper(_os, - encoding=_merge_encoding, overrides=_os_overrides) + encoding=_encodings['merge'], overrides=_os_overrides) import shutil as _shutil -shutil = _unicode_module_wrapper(_shutil, encoding=_fs_encoding) +shutil = _unicode_module_wrapper(_shutil, encoding=_encodings['fs']) # Imports below this point rely on the above unicode wrapper definitions. _selinux = None @@ -246,8 +252,10 @@ selinux = None _selinux_merge = None try: import portage._selinux - selinux = _unicode_module_wrapper(_selinux, encoding=_fs_encoding) - _selinux_merge = _unicode_module_wrapper(_selinux, encoding=_merge_encoding) + selinux = _unicode_module_wrapper(_selinux, + encoding=_encodings['fs']) + _selinux_merge = _unicode_module_wrapper(_selinux, + encoding=_encodings['merge']) except OSError, e: sys.stderr.write("!!! SELinux not loaded: %s\n" % str(e)) del e @@ -1007,8 +1015,9 @@ def env_update(makelinks=1, target_root=None, prev_mtimes=None, contents=None, ldsoconf_path = os.path.join(target_root, EPREFIX_LSTRIP, "etc", "ld.so.conf") try: - myld = codecs.open(_unicode_encode(ldsoconf_path), mode='r', - encoding='utf_8', errors='replace') + myld = codecs.open(_unicode_encode(ldsoconf_path, + encoding=_encodings['fs'], errors='strict'), + mode='r', encoding=_encodings['content'], errors='replace') myldlines=myld.readlines() myld.close() oldld=[] @@ -1189,8 +1198,9 @@ def ExtractKernelVersion(base_dir): lines = [] pathname = os.path.join(base_dir, 'Makefile') try: - f = codecs.open(_unicode_encode(pathname), mode='r', - encoding='utf_8', errors='replace') + f = codecs.open(_unicode_encode(pathname, + encoding=_encodings['fs'], errors='strict'), mode='r', + encoding=_encodings['content'], errors='replace') except OSError, details: return (None, str(details)) except IOError, details: @@ -1652,8 +1662,9 @@ class config(object): parentsFile = os.path.join(currentPath, "parent") eapi_file = os.path.join(currentPath, "eapi") try: - eapi = codecs.open(_unicode_encode(eapi_file), - mode='r', encoding='utf_8', errors='replace' + eapi = codecs.open(_unicode_encode(eapi_file, + encoding=_encodings['fs'], errors='strict'), + mode='r', encoding=_encodings['content'], errors='replace' ).readline().strip() except IOError: pass @@ -2001,8 +2012,10 @@ class config(object): try: repo_conf_parser.readfp( codecs.open( - _unicode_encode(self._local_repo_conf_path), mode='r', - encoding='utf_8', errors='replace')) + _unicode_encode(self._local_repo_conf_path, + encoding=_encodings['fs'], errors='strict'), + mode='r', encoding=_encodings['content'], errors='replace') + ) except EnvironmentError, e: if e.errno != errno.ENOENT: raise @@ -4879,8 +4892,9 @@ def fetch(myuris, mysettings, listonly=0, fetchonly=0, locks_in_subdir=".locks", if (mystat[stat.ST_SIZE]<100000) and (len(myfile)>4) and not ((myfile[-5:]==".html") or (myfile[-4:]==".htm")): html404=re.compile(".*(not found|404).*",re.I|re.M) if html404.search(codecs.open( - _unicode_encode(myfile_path), mode='r', - encoding='utf_8', errors='replace' + _unicode_encode(myfile_path, + encoding=_encodings['fs'], errors='strict'), + mode='r', encoding=_encodings['content'], errors='replace' ).read()): try: os.unlink(mysettings["DISTDIR"]+"/"+myfile) @@ -5307,13 +5321,13 @@ def digestcheck(myfiles, mysettings, strict=0, justmanifest=0): for parent, dirs, files in os.walk(filesdir): try: parent = _unicode_decode(parent, - encoding=_fs_encoding, errors='strict') + encoding=_encodings['fs'], errors='strict') except UnicodeDecodeError: parent = _unicode_decode(parent, - encoding=_fs_encoding, errors='replace') + encoding=_encodings['fs'], errors='replace') writemsg(_("!!! Path contains invalid " "character(s) for encoding '%s': '%s'") \ - % (_fs_encoding, parent), noiselevel=-1) + % (_encodings['fs'], parent), noiselevel=-1) if strict: return 0 continue @@ -5323,16 +5337,16 @@ def digestcheck(myfiles, mysettings, strict=0, justmanifest=0): for f in files: try: f = _unicode_decode(f, - encoding=_fs_encoding, errors='strict') + encoding=_encodings['fs'], errors='strict') except UnicodeDecodeError: f = _unicode_decode(f, - encoding=_fs_encoding, errors='replace') + encoding=_encodings['fs'], errors='replace') if f.startswith("."): continue f = os.path.join(parent, f)[len(filesdir) + 1:] writemsg(_("!!! File name contains invalid " "character(s) for encoding '%s': '%s'") \ - % (_fs_encoding, f), noiselevel=-1) + % (_encodings['fs'], f), noiselevel=-1) if strict: return 0 continue @@ -5455,8 +5469,9 @@ def _check_build_log(mysettings, out=None): if logfile is None: return try: - f = codecs.open(_unicode_encode(logfile), mode='r', - encoding='utf_8', errors='replace') + f = codecs.open(_unicode_encode(logfile, + encoding=_encodings['fs'], errors='strict'), + mode='r', encoding=_encodings['content'], errors='replace') except EnvironmentError: return @@ -5603,14 +5618,14 @@ def _post_src_install_uid_fix(mysettings, out=None): for parent, dirs, files in os.walk(destdir): try: parent = _unicode_decode(parent, - encoding=_merge_encoding, errors='strict') + encoding=_encodings['merge'], errors='strict') except UnicodeDecodeError: new_parent = _unicode_decode(parent, - encoding=_merge_encoding, errors='replace') + encoding=_encodings['merge'], errors='replace') new_parent = _unicode_encode(new_parent, - encoding=_merge_encoding, errors='backslashreplace') + encoding=_encodings['merge'], errors='backslashreplace') new_parent = _unicode_decode(new_parent, - encoding=_merge_encoding, errors='replace') + encoding=_encodings['merge'], errors='replace') os.rename(parent, new_parent) unicode_error = True unicode_errors.append(new_parent[len(destdir):]) @@ -5619,16 +5634,16 @@ def _post_src_install_uid_fix(mysettings, out=None): for fname in chain(dirs, files): try: fname = _unicode_decode(fname, - encoding=_merge_encoding, errors='strict') + encoding=_encodings['merge'], errors='strict') except UnicodeDecodeError: fpath = _os.path.join( - parent.encode(_merge_encoding), fname) + parent.encode(_encodings['merge']), fname) new_fname = _unicode_decode(fname, - encoding=_merge_encoding, errors='replace') + encoding=_encodings['merge'], errors='replace') new_fname = _unicode_encode(new_fname, - encoding=_merge_encoding, errors='backslashreplace') + encoding=_encodings['merge'], errors='backslashreplace') new_fname = _unicode_decode(new_fname, - encoding=_merge_encoding, errors='replace') + encoding=_encodings['merge'], errors='replace') new_fpath = os.path.join(parent, new_fname) os.rename(fpath, new_fpath) unicode_error = True @@ -5653,7 +5668,7 @@ def _post_src_install_uid_fix(mysettings, out=None): if mystat.st_gid == portage_gid: mygid = inst_gid apply_secpass_permissions( - _unicode_encode(fpath, encoding=_merge_encoding), + _unicode_encode(fpath, encoding=_encodings['merge']), uid=myuid, gid=mygid, mode=mystat.st_mode, stat_cached=mystat, follow_links=False) @@ -5685,7 +5700,7 @@ def _merge_unicode_error(errors): msg = _("This package installs one or more file names containing " "characters that do not match your current locale " "settings. The current setting for filesystem encoding is '%s'.") \ - % _merge_encoding + % _encodings['merge'] lines.extend(wrap(msg, 72)) lines.append("") @@ -5693,7 +5708,7 @@ def _merge_unicode_error(errors): lines.extend("\t" + x for x in errors) lines.append("") - if _merge_encoding.lower().replace('_', '').replace('-', '') != 'utf8': + if _encodings['merge'].lower().replace('_', '').replace('-', '') != 'utf8': msg = _("For best results, UTF-8 encoding is recommended. See " "the Gentoo Linux Localization Guide for instructions " "about how to configure your locale for UTF-8 encoding:") @@ -5934,8 +5949,9 @@ def doebuild_environment(myebuild, mydo, myroot, mysettings, debug, use_cache, m pass elif 'parse-eapi-ebuild-head' in mysettings.features: eapi = _parse_eapi_ebuild_head( - codecs.open(_unicode_encode(ebuild_path), - mode='r', encoding='utf_8', errors='replace')) + codecs.open(_unicode_encode(ebuild_path, + encoding=_encodings['fs'], errors='strict'), + mode='r', encoding=_encodings['content'], errors='replace')) if eapi is not None: if not eapi_is_supported(eapi): @@ -6101,8 +6117,9 @@ def _adjust_perms_msg(settings, msg): if background and log_path is not None: try: - log_file = codecs.open(_unicode_encode(log_path), mode='a', - encoding='utf_8', errors='replace') + log_file = codecs.open(_unicode_encode(log_path, + encoding=_encodings['fs'], errors='strict'), + mode='a', encoding=_encodings['content'], errors='replace') except IOError: def write(msg): pass @@ -7151,7 +7168,7 @@ def _movefile(src, dest, **kwargs): "mv '%s' '%s'" % (src, dest)) def movefile(src, dest, newmtime=None, sstat=None, mysettings=None, - hardlink_candidates=None, encoding=_fs_encoding): + hardlink_candidates=None, encoding=_encodings['fs']): """moves a file from src to dest, preserving all permissions and attributes; mtime will be preserved even when moving across filesystems. Returns true on success and false on failure. Move is atomic.""" @@ -8470,8 +8487,9 @@ def deprecated_profile_check(settings=None): DEPRECATED_PROFILE_FILE.lstrip(os.sep)) if not os.access(deprecated_profile_file, os.R_OK): return False - dcontent = codecs.open(_unicode_encode(deprecated_profile_file), - mode='r', encoding='utf_8', errors='replace').readlines() + dcontent = codecs.open(_unicode_encode(deprecated_profile_file, + encoding=_encodings['fs'], errors='strict'), + mode='r', encoding=_encodings['content'], errors='replace').readlines() writemsg(colorize("BAD", _("\n!!! Your current profile is " "deprecated and not supported anymore.")) + "\n", noiselevel=-1) if not dcontent: @@ -8867,6 +8885,7 @@ def init_legacy_globals(): break root = settings["ROOT"] + output._init(config_root=settings['PORTAGE_CONFIGROOT']) # ======================================================================== diff --git a/pym/portage/cvstree.py b/pym/portage/cvstree.py index d283fb47f..a35c5fcf1 100644 --- a/pym/portage/cvstree.py +++ b/pym/portage/cvstree.py @@ -3,9 +3,13 @@ # Distributed under the terms of the GNU General Public License v2 # $Id$ +import codecs +import re +import time -import os,time,sys,re -from stat import * +from portage import os +from portage import _encodings +from portage import _unicode_encode # [D]/Name/Version/Date/Flags/Tags @@ -43,7 +47,10 @@ def isadded(entries, path): filename=os.path.basename(path) try: - myfile=open(basedir+"/CVS/Entries","r") + myfile = codecs.open( + _unicode_encode(os.path.join(basedir, 'CVS', 'Entries'), + encoding=_encodings['fs'], errors='strict'), + mode='r', encoding=_encodings['content'], errors='strict') except IOError: return 0 mylines=myfile.readlines() @@ -194,7 +201,9 @@ def getentries(mydir,recursive=0): if not os.path.exists(mydir): return entries try: - myfile=open(myfn, "r") + myfile = codecs.open(_unicode_encode(myfn, + encoding=_encodings['fs'], errors='strict'), + mode='r', encoding=_encodings['content'], errors='strict') mylines=myfile.readlines() myfile.close() except SystemExit, e: @@ -269,7 +278,7 @@ def getentries(mydir,recursive=0): if file=="digest-framerd-2.4.3": print "stat'ing" mystat=os.stat(mydir+"/"+file) - mytime=time.asctime(time.gmtime(mystat[ST_MTIME])) + mytime = time.asctime(time.gmtime(long(mystat.st_mtime))) if "status" not in entries["files"][file]: if file=="digest-framerd-2.4.3": print "status not set" diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index fec39fb22..f1ed5a569 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -38,6 +38,7 @@ from portage import listdir, dep_expand, digraph, flatten, key_expand, \ # This is a special version of the os module, wrapped for unicode support. from portage import os +from portage import _content_encoding from portage import _fs_encoding from portage import _merge_encoding from portage import _os_merge @@ -1537,7 +1538,8 @@ class vardbapi(dbapi): counter, = self.aux_get(cpv, aux_keys) except KeyError: continue - h.update(counter) + h.update(_unicode_encode(counter, + encoding=_content_encoding, errors='replace')) return h.hexdigest() def cpv_inject(self, mycpv): @@ -1949,8 +1951,10 @@ class vardbapi(dbapi): results.append(long(st.st_mtime)) continue try: - myf = codecs.open(_unicode_encode(os.path.join(mydir, x)), - mode='r', encoding='utf_8', errors='replace') + myf = codecs.open( + _unicode_encode(os.path.join(mydir, x), + encoding=_fs_encoding, errors='strict'), + mode='r', encoding=_content_encoding, errors='replace') try: myd = myf.read() finally: @@ -2018,8 +2022,10 @@ class vardbapi(dbapi): new_vdb = False counter = -1 try: - cfile = codecs.open(_unicode_encode(self._counter_path), mode='r', - encoding='utf_8', errors='replace') + cfile = codecs.open( + _unicode_encode(self._counter_path, + encoding=_fs_encoding, errors='strict'), + mode='r', encoding=_content_encoding, errors='replace') except EnvironmentError, e: new_vdb = not bool(self.cpv_all()) if not new_vdb: @@ -2154,7 +2160,8 @@ class vardbapi(dbapi): h = self._new_hash() # Always use a constant utf_8 encoding here, since # the "default" encoding can change. - h.update(portage._unicode_encode(s)) + h.update(_unicode_encode(s, + encoding=_content_encoding, errors='replace')) h = h.hexdigest() h = h[-self._hex_chars:] h = int(h, 16) @@ -2602,8 +2609,9 @@ class dblink(object): return self.contentscache pkgfiles = {} try: - myc = codecs.open(_unicode_encode(contents_file), mode='r', - encoding='utf_8', errors='replace') + myc = codecs.open(_unicode_encode(contents_file, + encoding=_content_encoding, errors='strict'), + mode='r', encoding=_content_encoding, errors='replace') except EnvironmentError, e: if e.errno != errno.ENOENT: raise @@ -3938,8 +3946,10 @@ class dblink(object): for var_name in ('CHOST', 'SLOT'): try: val = codecs.open(_unicode_encode( - os.path.join(inforoot, var_name)), mode='r', - encoding='utf_8', errors='replace').readline().strip() + os.path.join(inforoot, var_name), + encoding=_fs_encoding, errors='strict'), + mode='r', encoding=_content_encoding, errors='replace' + ).readline().strip() except EnvironmentError, e: if e.errno != errno.ENOENT: raise @@ -4285,8 +4295,9 @@ class dblink(object): # open CONTENTS file (possibly overwriting old one) for recording outfile = codecs.open(_unicode_encode( - os.path.join(self.dbtmpdir, 'CONTENTS')), - mode='w', encoding='utf_8', errors='replace') + os.path.join(self.dbtmpdir, 'CONTENTS'), + encoding=_fs_encoding, errors='strict'), + mode='w', encoding=_content_encoding, errors='replace') self.updateprotect() @@ -4884,8 +4895,11 @@ class dblink(object): "returns contents of a file with whitespace converted to spaces" if not os.path.exists(self.dbdir+"/"+name): return "" - mydata = codecs.open(_unicode_encode(os.path.join(self.dbdir, name)), - mode='r', encoding='utf_8', errors='replace').read().split() + mydata = codecs.open( + _unicode_encode(os.path.join(self.dbdir, name), + encoding=_fs_encoding, errors='strict'), + mode='r', encoding=_content_encoding, errors='replace' + ).read().split() return " ".join(mydata) def copyfile(self,fname): @@ -4894,8 +4908,9 @@ class dblink(object): def getfile(self,fname): if not os.path.exists(self.dbdir+"/"+fname): return "" - return codecs.open(_unicode_encode(os.path.join(self.dbdir, fname)), - mode='r', encoding='utf_8', errors='replace').read() + return codecs.open(_unicode_encode(os.path.join(self.dbdir, fname), + encoding=_fs_encoding, errors='strict'), + mode='r', encoding=_content_encoding, errors='replace').read() def setfile(self,fname,data): mode = 'w' @@ -4907,8 +4922,9 @@ class dblink(object): if not os.path.exists(self.dbdir+"/"+ename): return [] mylines = codecs.open(_unicode_encode( - os.path.join(self.dbdir, ename)), mode='r', - encoding='utf_8', errors='replace').readlines() + os.path.join(self.dbdir, ename), + encoding=_fs_encoding, errors='strict'), + mode='r', encoding=_content_encoding, errors='replace').readlines() myreturn = [] for x in mylines: for y in x[:-1].split(): @@ -4917,8 +4933,9 @@ class dblink(object): def setelements(self,mylist,ename): myelement = codecs.open(_unicode_encode( - os.path.join(self.dbdir, ename)), mode='w', - encoding='utf_8', errors='replace') + os.path.join(self.dbdir, ename), + encoding=_fs_encoding, errors='strict'), mode='w', + encoding=_content_encoding, errors='replace') for x in mylist: myelement.write(x+"\n") myelement.close() diff --git a/pym/portage/getbinpkg.py b/pym/portage/getbinpkg.py index 04baf8fc5..459b3fff7 100644 --- a/pym/portage/getbinpkg.py +++ b/pym/portage/getbinpkg.py @@ -7,9 +7,12 @@ from portage.output import colorize from portage.cache.mappings import slot_dict_class from portage.localization import _ import portage +from portage import os +from portage import _encodings +from portage import _unicode_encode + import HTMLParser import sys -import os import socket import time import tempfile @@ -487,7 +490,8 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache= out = sys.stdout try: - metadatafile = open(metadatafilename, 'rb') + metadatafile = open(_unicode_encode(metadatafilename, + encoding=_encodings['fs'], errors='strict'), 'rb') mypickle = pickle.Unpickler(metadatafile) try: mypickle.find_global = None @@ -582,7 +586,8 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache= sys.stderr.write("!!! "+str(e)+"\n") sys.stderr.flush() try: - metadatafile = open(metadatafilename, 'wb') + metadatafile = open(_unicode_encode(metadatafilename, + encoding=_encodings['fs'], errors='strict'), 'wb') pickle.dump(metadata, metadatafile, protocol=2) metadatafile.close() except SystemExit, e: @@ -674,11 +679,13 @@ def dir_get_metadata(baseurl, conn=None, chunk_size=3000, verbose=1, usingcache= try: if "modified" in metadata[baseurl] and metadata[baseurl]["modified"]: metadata[baseurl]["timestamp"] = int(time.time()) - metadatafile = open(metadatafilename, 'wb') + metadatafile = open(_unicode_encode(metadatafilename, + encoding=_encodings['fs'], errors='strict'), 'wb') pickle.dump(metadata, metadatafile, protocol=2) metadatafile.close() if makepickle: - metadatafile = open(makepickle, 'wb') + metadatafile = open(_unicode_encode(makepickle, + encoding=_encodings['fs'], errors='strict'), 'wb') pickle.dump(metadata[baseurl]["data"], metadatafile, protocol=2) metadatafile.close() except SystemExit, e: diff --git a/pym/portage/glsa.py b/pym/portage/glsa.py index 008cb86dc..db297995d 100644 --- a/pym/portage/glsa.py +++ b/pym/portage/glsa.py @@ -2,12 +2,16 @@ # Distributed under the terms of the GNU General Public License v2 # $Id$ -import os +import codecs import sys import urllib import re import xml.dom.minidom +from portage import os +from portage import _encodings +from portage import _unicode_decode +from portage import _unicode_encode from portage.versions import pkgsplit, catpkgsplit, pkgcmp, best from portage.util import grabfile from portage.const import CACHE_PATH @@ -435,6 +439,8 @@ class Glsa: @type portdbapi: portage.dbapi.porttree.portdbapi @param portdbapi: ebuild repository """ + myid = _unicode_decode(myid, + encoding=_encodings['content'], errors='strict') if re.match(r'\d{6}-\d{2}', myid): self.type = "id" elif os.path.exists(myid): @@ -647,7 +653,11 @@ class Glsa: @returns: None """ if not self.isApplied(): - checkfile = open(os.path.join(os.sep, self.config["ROOT"], CACHE_PATH.lstrip(os.sep), "glsa"), "a+") + checkfile = codecs.open( + _unicode_encode(os.path.join(os.sep, self.config["ROOT"], + CACHE_PATH.lstrip(os.sep), "glsa"), + encoding=_encodings['fs'], errors='strict'), + mode='a+', encoding=_encodings['content'], errors='strict') checkfile.write(self.nr+"\n") checkfile.close() return None diff --git a/pym/portage/mail.py b/pym/portage/mail.py index 767c66b3f..ce2f6760d 100644 --- a/pym/portage/mail.py +++ b/pym/portage/mail.py @@ -3,24 +3,32 @@ # Distributed under the terms of the GNU General Public License v2 # $Id$ -import portage.exception, socket, smtplib, os, sys, time from email.MIMEText import MIMEText as TextMessage from email.MIMEMultipart import MIMEMultipart as MultipartMessage from email.MIMEBase import MIMEBase as BaseMessage from email.header import Header +import smtplib +import socket +import sys +import time + +from portage import os +from portage import _content_encoding +from portage import _unicode_encode from portage.localization import _ +import portage def create_message(sender, recipient, subject, body, attachments=None): if sys.hexversion < 0x3000000: - if isinstance(sender, unicode): - sender = sender.encode('utf_8', 'replace') - if isinstance(recipient, unicode): - recipient = recipient.encode('utf_8', 'replace') - if isinstance(subject, unicode): - subject = subject.encode('utf_8', 'replace') - if isinstance(body, unicode): - body = body.encode('utf_8', 'replace') + sender = _unicode_encode(sender, + encoding=_content_encoding, errors='strict') + recipient = _unicode_encode(recipient, + encoding=_content_encoding, errors='strict') + subject = _unicode_encode(subject, + encoding=_content_encoding, errors='replace') + body = _unicode_encode(body, + encoding=_content_encoding, errors='replace') if attachments == None: mymessage = TextMessage(body) @@ -31,8 +39,9 @@ def create_message(sender, recipient, subject, body, attachments=None): if isinstance(x, BaseMessage): mymessage.attach(x) elif isinstance(x, basestring): - if sys.hexversion < 0x3000000 and isinstance(x, unicode): - x = x.encode('utf_8', 'replace') + if sys.hexversion < 0x3000000: + x = _unicode_encode(x, + encoding=_content_encoding, errors='replace') mymessage.attach(TextMessage(x)) else: raise portage.exception.PortageException(_("Can't handle type of attachment: %s") % type(x)) @@ -82,18 +91,18 @@ def send_mail(mysettings, message): myfrom = message.get("From") if sys.hexversion < 0x3000000: - if isinstance(myrecipient, unicode): - myrecipient = myrecipient.encode('utf_8', 'replace') - if isinstance(mymailhost, unicode): - mymailhost = mymailhost.encode('utf_8', 'replace') - if isinstance(mymailport, unicode): - mymailport = mymailport.encode('utf_8', 'replace') - if isinstance(myfrom, unicode): - myfrom = myfrom.encode('utf_8', 'replace') - if isinstance(mymailuser, unicode): - mymailuser = mymailuser.encode('utf_8', 'replace') - if isinstance(mymailpasswd, unicode): - mymailpasswd = mymailpasswd.encode('utf_8', 'replace') + myrecipient = _unicode_encode(myrecipient, + encoding=_content_encoding, errors='strict') + mymailhost = _unicode_encode(mymailhost, + encoding=_content_encoding, errors='strict') + mymailport = _unicode_encode(mymailport, + encoding=_content_encoding, errors='strict') + myfrom = _unicode_encode(myfrom, + encoding=_content_encoding, errors='strict') + mymailuser = _unicode_encode(mymailuser, + encoding=_content_encoding, errors='strict') + mymailpasswd = _unicode_encode(mymailpasswd, + encoding=_content_encoding, errors='strict') # user wants to use a sendmail binary instead of smtp if mymailhost[0] == os.sep and os.path.exists(mymailhost): diff --git a/pym/repoman/checks.py b/pym/repoman/checks.py index 76425a817..bfb262545 100644 --- a/pym/repoman/checks.py +++ b/pym/repoman/checks.py @@ -6,7 +6,6 @@ """This module contains functions used in Repoman to ascertain the quality and correctness of an ebuild.""" -import os import re import time import repoman.errors as errors diff --git a/pym/repoman/utilities.py b/pym/repoman/utilities.py index 9ea5ff467..cf32399d3 100644 --- a/pym/repoman/utilities.py +++ b/pym/repoman/utilities.py @@ -18,16 +18,19 @@ __all__ = [ "parse_metadata_use" ] +import codecs import commands import errno import itertools import logging -import os import sys from xml.dom import minidom from xml.dom import NotFoundErr from xml.parsers.expat import ExpatError +from portage import os +from portage import _encodings +from portage import _unicode_encode from portage import output from portage.output import red, green from portage.process import find_binary @@ -282,7 +285,10 @@ def get_commit_message_with_editor(editor, message=None): if not (os.WIFEXITED(retval) and os.WEXITSTATUS(retval) == os.EX_OK): return None try: - mylines = open(filename).readlines() + mylines = codecs.open(_unicode_encode(filename, + encoding=_encodings['fs'], errors='strict'), + mode='r', encoding=_encodings['content'], errors='replace' + ).readlines() except OSError, e: if e.errno != errno.ENOENT: raise -- 2.26.2