diff options
author | Zac Medico <zmedico@gentoo.org> | 2009-08-14 22:57:44 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2009-08-14 22:57:44 +0000 |
commit | 92136a3820029b7060fea0dfd0f37497685acd1f (patch) | |
tree | 31dcbe8bbda33bf18f42e4bac033d3c90dc98741 | |
parent | fbac2506e4b508ee510c4a15835dcd99a5e5877e (diff) | |
download | portage-92136a3820029b7060fea0dfd0f37497685acd1f.tar.gz portage-92136a3820029b7060fea0dfd0f37497685acd1f.tar.bz2 portage-92136a3820029b7060fea0dfd0f37497685acd1f.zip |
Update imports to import portage.os (with unicode wrappers), and use
_unicode_encode() and _unicode_decode() where appropriate.
svn path=/main/trunk/; revision=14052
-rw-r--r-- | pym/portage/__init__.py | 3 | ||||
-rw-r--r-- | pym/portage/sets/__init__.py | 2 | ||||
-rw-r--r-- | pym/portage/sets/dbapi.py | 4 | ||||
-rw-r--r-- | pym/portage/sets/files.py | 45 | ||||
-rw-r--r-- | pym/portage/sets/profiles.py | 3 | ||||
-rw-r--r-- | pym/portage/sets/security.py | 2 | ||||
-rw-r--r-- | pym/portage/sets/shell.py | 6 |
7 files changed, 40 insertions, 25 deletions
diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index 87863abdb..9d2c03317 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -197,6 +197,9 @@ class _unicode_module_wrapper(object): result = _unicode_func_wrapper(result, encoding=encoding) return result +# Assume utf_8 fs encoding everywhere except in merge code. +_fs_encoding = 'utf_8' + _merge_encoding = sys.getfilesystemencoding() import os as _os diff --git a/pym/portage/sets/__init__.py b/pym/portage/sets/__init__.py index 2d85007ec..f52c7fa1a 100644 --- a/pym/portage/sets/__init__.py +++ b/pym/portage/sets/__init__.py @@ -5,7 +5,7 @@ __all__ = ["SETPREFIX", "get_boolean", "SetConfigError", "SetConfig", "load_default_config"] -import os +from portage import os from ConfigParser import SafeConfigParser, NoOptionError from portage import load_mod from portage.const import USER_CONFIG_PATH, GLOBAL_CONFIG_PATH diff --git a/pym/portage/sets/dbapi.py b/pym/portage/sets/dbapi.py index 0f82bd1c9..5cd6c6ba1 100644 --- a/pym/portage/sets/dbapi.py +++ b/pym/portage/sets/dbapi.py @@ -2,6 +2,9 @@ # Distributed under the terms of the GNU General Public License v2 # $Id$ +import time + +from portage import os from portage.versions import catpkgsplit, catsplit, pkgcmp, best from portage.dep import Atom from portage.localization import _ @@ -280,7 +283,6 @@ class AgeSet(EverythingSet): self._age = age def _filter(self, atom): - import time, os cpv = self._db.match(atom)[0] path = self._db.getpath(cpv, filename="COUNTER") diff --git a/pym/portage/sets/files.py b/pym/portage/sets/files.py index b5ad9a05d..acf556b7f 100644 --- a/pym/portage/sets/files.py +++ b/pym/portage/sets/files.py @@ -3,10 +3,13 @@ # $Id$ import errno -import os import re from itertools import chain +from portage import os +from portage import _fs_encoding +from portage import _unicode_decode +from portage import _unicode_encode from portage.util import grabfile, write_atomic, ensure_dirs, normalize_path from portage.const import PRIVATE_PATH, USER_CONFIG_PATH from portage.localization import _ @@ -126,35 +129,43 @@ class StaticFileSet(EditablePackageSet): except KeyError: raise SetConfigError(_("Could not find repository '%s'") % match.groupdict()["reponame"]) + try: + directory = _unicode_decode(directory, + encoding=_fs_encoding, errors='strict') + # Now verify that we can also encode it. + _unicode_encode(directory, + encoding=_fs_encoding, errors='strict') + except UnicodeError: + directory = _unicode_decode(directory, + encoding=_fs_encoding, errors='replace') + raise SetConfigError( + _("Directory path contains invalid character(s) for encoding '%s': '%s'") \ + % (_fs_encoding, directory)) + if os.path.isdir(directory): directory = normalize_path(directory) - if isinstance(directory, unicode): - # Avoid UnicodeDecodeError raised from - # os.path.join when called by os.walk. - directory_unicode = directory - directory = directory.encode('utf_8', 'replace') - else: - directory_unicode = unicode(directory, - encoding='utf_8', errors='replace') - for parent, dirs, files in os.walk(directory): - if not isinstance(parent, unicode): - parent = unicode(parent, - encoding='utf_8', errors='replace') + try: + parent = _unicode_decode(parent, + encoding=_fs_encoding, errors='strict') + except UnicodeDecodeError: + continue for d in dirs[:]: if d[:1] == '.': dirs.remove(d) for filename in files: - if not isinstance(filename, unicode): - filename = unicode(filename, - encoding='utf_8', errors='replace') + try: + filename = _unicode_decode(filename, + encoding=_fs_encoding, errors='strict') + except UnicodeDecodeError: + continue if filename[:1] == '.': continue if filename.endswith(".metadata"): continue filename = os.path.join(parent, - filename)[1 + len(directory_unicode):] + filename)[1 + len(directory):] myname = name_pattern.replace("$name", filename) myname = myname.replace("${name}", filename) rValue[myname] = StaticFileSet( diff --git a/pym/portage/sets/profiles.py b/pym/portage/sets/profiles.py index 9c1dcbe86..da3a25e86 100644 --- a/pym/portage/sets/profiles.py +++ b/pym/portage/sets/profiles.py @@ -3,7 +3,8 @@ # $Id$ import logging -import os + +from portage import os from portage.util import grabfile_package, stack_lists from portage.sets.base import PackageSet from portage.sets import get_boolean diff --git a/pym/portage/sets/security.py b/pym/portage/sets/security.py index 12503d9a5..115c0f3bd 100644 --- a/pym/portage/sets/security.py +++ b/pym/portage/sets/security.py @@ -2,9 +2,7 @@ # Distributed under the terms of the GNU General Public License v2 # $Id$ -import os import portage.glsa as glsa -from portage.util import grabfile, write_atomic from portage.sets.base import PackageSet from portage.versions import catpkgsplit, pkgcmp from portage.sets import get_boolean diff --git a/pym/portage/sets/shell.py b/pym/portage/sets/shell.py index 25ccb03c7..658353ef2 100644 --- a/pym/portage/sets/shell.py +++ b/pym/portage/sets/shell.py @@ -3,8 +3,9 @@ # $Id$ import subprocess -import os +from portage import os +from portage import _unicode_decode from portage.sets.base import PackageSet from portage.sets import SetConfigError @@ -35,8 +36,7 @@ class CommandOutputSet(PackageSet): pipe = subprocess.Popen(self._command, stdout=subprocess.PIPE, shell=True) stdout, stderr = pipe.communicate() if pipe.wait() == os.EX_OK: - self._setAtoms(unicode(stdout, - encoding='utf_8', errors='replace').splitlines()) + self._setAtoms(_unicode_decode(stdout).splitlines()) def singleBuilder(self, options, settings, trees): if not "command" in options: |