Use unicode_literals more.
authorZac Medico <zmedico@gentoo.org>
Fri, 18 Jan 2013 21:33:08 +0000 (13:33 -0800)
committerZac Medico <zmedico@gentoo.org>
Fri, 18 Jan 2013 21:36:47 +0000 (13:36 -0800)
This helps to ensure consistent results, regardless of whether we're
using Python 2 or Python 3.

47 files changed:
bin/portageq
bin/repoman
pym/_emerge/DependencyArg.py
pym/_emerge/FakeVartree.py
pym/_emerge/JobStatusDisplay.py
pym/_emerge/Package.py
pym/_emerge/Scheduler.py
pym/_emerge/UseFlagDisplay.py
pym/_emerge/actions.py
pym/_emerge/depgraph.py
pym/_emerge/emergelog.py
pym/_emerge/resolver/circular_dependency.py
pym/_emerge/resolver/output.py
pym/_emerge/resolver/output_helpers.py
pym/_emerge/resolver/slot_collision.py
pym/portage/__init__.py
pym/portage/const.py
pym/portage/dbapi/__init__.py
pym/portage/dbapi/_expand_new_virt.py
pym/portage/dbapi/bintree.py
pym/portage/dbapi/cpv_expand.py
pym/portage/dbapi/dep_expand.py
pym/portage/dbapi/porttree.py
pym/portage/dbapi/vartree.py
pym/portage/dbapi/virtual.py
pym/portage/dep/__init__.py
pym/portage/dep/_slot_operator.py
pym/portage/dep/dep_check.py
pym/portage/elog/mod_save_summary.py
pym/portage/getbinpkg.py
pym/portage/manifest.py
pym/portage/news.py
pym/portage/package/ebuild/_config/special_env_vars.py
pym/portage/package/ebuild/_ipc/QueryCommand.py
pym/portage/package/ebuild/config.py
pym/portage/package/ebuild/doebuild.py
pym/portage/package/ebuild/prepare_build_dirs.py
pym/portage/repository/config.py
pym/portage/update.py
pym/portage/util/digraph.py
pym/portage/util/movefile.py
pym/portage/versions.py
pym/portage/xml/metadata.py
pym/repoman/checks.py
pym/repoman/errors.py
pym/repoman/herdbase.py
pym/repoman/utilities.py

index ee776ef4f939fa02d4b161c578af5650c65db588..826c92d128d10ca173b72f17e948b661923b5d87 100755 (executable)
@@ -2,7 +2,7 @@
 # Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
-from __future__ import print_function
+from __future__ import print_function, unicode_literals
 
 import signal
 import sys
@@ -101,9 +101,7 @@ def has_version(argv):
                        try:
                                atom = portage.dep.Atom(argv[1], allow_repo=allow_repo, eapi=eapi)
                        except portage.exception.InvalidAtom as e:
-                               warnings.append(
-                                       portage._unicode_decode("QA Notice: %s: %s") % \
-                                       ('has_version', e))
+                               warnings.append("QA Notice: %s: %s" % ('has_version', e))
                atom = eval_atom_use(atom)
 
        if warnings:
@@ -149,9 +147,7 @@ def best_version(argv):
                        try:
                                atom = portage.dep.Atom(argv[1], allow_repo=allow_repo, eapi=eapi)
                        except portage.exception.InvalidAtom as e:
-                               warnings.append(
-                                       portage._unicode_decode("QA Notice: %s: %s") % \
-                                       ('best_version', e))
+                               warnings.append("QA Notice: %s: %s" % ('best_version', e))
                atom = eval_atom_use(atom)
 
        if warnings:
index 4c00d5bca519306e88540348b0b1e6b79e92aadb..11f2b13bbbc1cf8bfab98b96d7f210dfc4362727 100755 (executable)
@@ -6,7 +6,7 @@
 # Then, check to make sure deps are satisfiable (to avoid "can't find match for" problems)
 # that last one is tricky because multiple profiles need to be checked.
 
-from __future__ import print_function
+from __future__ import print_function, unicode_literals
 
 import calendar
 import codecs
index 80134c804f7f32ea927e25347f91e917e2db68af..29a0072c4ef0d9b134a1d5f6a30ca6b5a5c6909f 100644 (file)
@@ -1,9 +1,11 @@
-# Copyright 1999-2012 Gentoo Foundation
+# Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 import sys
 
-from portage import _encodings, _unicode_encode, _unicode_decode
+from portage import _encodings, _unicode_encode
 
 class DependencyArg(object):
 
@@ -31,10 +33,10 @@ class DependencyArg(object):
                return hash((self.arg, self.root_config.root))
 
        def __str__(self):
-               # Force unicode format string for python-2.x safety,
+               # Use unicode_literals format string for python-2.x safety,
                # ensuring that self.arg.__unicode__() is used
                # when necessary.
-               return _unicode_decode("%s") % (self.arg,)
+               return "%s" % (self.arg,)
 
        if sys.hexversion < 0x3000000:
 
index 058c1c70f7e8ccac3cf75e178df703c9910df60f..fd87f6c9da4045ea400e0aa566d4133cebbb96b4 100644 (file)
@@ -1,6 +1,8 @@
-# Copyright 1999-2012 Gentoo Foundation
+# Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 import sys
 import warnings
 
index 5b9b2216f06a65bad66b72b8010ee3489b29963b..f48b2135fdb24db89772a027cbc51bb26ae24515 100644 (file)
@@ -1,6 +1,8 @@
-# Copyright 1999-2011 Gentoo Foundation
+# Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 import formatter
 import io
 import sys
@@ -9,7 +11,6 @@ import time
 import portage
 from portage import os
 from portage import _encodings
-from portage import _unicode_decode
 from portage import _unicode_encode
 from portage.output import xtermTitle
 
@@ -233,10 +234,10 @@ class JobStatusDisplay(object):
        def _display_status(self):
                # Don't use len(self._completed_tasks) here since that also
                # can include uninstall tasks.
-               curval_str = str(self.curval)
-               maxval_str = str(self.maxval)
-               running_str = str(self.running)
-               failed_str = str(self.failed)
+               curval_str = "%s" % (self.curval,)
+               maxval_str = "%s" % (self.maxval,)
+               running_str = "%s" % (self.running,)
+               failed_str = "%s" % (self.failed,)
                load_avg_str = self._load_avg_str()
 
                color_output = io.StringIO()
@@ -248,36 +249,36 @@ class JobStatusDisplay(object):
                f = formatter.AbstractFormatter(style_writer)
 
                number_style = "INFORM"
-               f.add_literal_data(_unicode_decode("Jobs: "))
+               f.add_literal_data("Jobs: ")
                f.push_style(number_style)
-               f.add_literal_data(_unicode_decode(curval_str))
+               f.add_literal_data(curval_str)
                f.pop_style()
-               f.add_literal_data(_unicode_decode(" of "))
+               f.add_literal_data(" of ")
                f.push_style(number_style)
-               f.add_literal_data(_unicode_decode(maxval_str))
+               f.add_literal_data(maxval_str)
                f.pop_style()
-               f.add_literal_data(_unicode_decode(" complete"))
+               f.add_literal_data(" complete")
 
                if self.running:
-                       f.add_literal_data(_unicode_decode(", "))
+                       f.add_literal_data(", ")
                        f.push_style(number_style)
-                       f.add_literal_data(_unicode_decode(running_str))
+                       f.add_literal_data(running_str)
                        f.pop_style()
-                       f.add_literal_data(_unicode_decode(" running"))
+                       f.add_literal_data(" running")
 
                if self.failed:
-                       f.add_literal_data(_unicode_decode(", "))
+                       f.add_literal_data(", ")
                        f.push_style(number_style)
-                       f.add_literal_data(_unicode_decode(failed_str))
+                       f.add_literal_data(failed_str)
                        f.pop_style()
-                       f.add_literal_data(_unicode_decode(" failed"))
+                       f.add_literal_data(" failed")
 
                padding = self._jobs_column_width - len(plain_output.getvalue())
                if padding > 0:
-                       f.add_literal_data(padding * _unicode_decode(" "))
+                       f.add_literal_data(padding * " ")
 
-               f.add_literal_data(_unicode_decode("Load avg: "))
-               f.add_literal_data(_unicode_decode(load_avg_str))
+               f.add_literal_data("Load avg: ")
+               f.add_literal_data(load_avg_str)
 
                # Truncate to fit width, to avoid making the terminal scroll if the
                # line overflows (happens when the load average is large).
index f3be19b6dbc2fdb729a705c85d60e2410a1fd319..09d8b9310484ae13923968a59a7f6bd683aeb416 100644 (file)
@@ -1,6 +1,8 @@
-# Copyright 1999-2012 Gentoo Foundation
+# Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 import sys
 from itertools import chain
 import warnings
@@ -259,8 +261,7 @@ class Package(Task):
                                use_reduce(v, eapi=dep_eapi, matchall=True,
                                        is_valid_flag=dep_valid_flag, token_class=Atom)
                        except InvalidDependString as e:
-                               self._invalid_metadata("PROVIDE.syntax",
-                                       _unicode_decode("%s: %s") % (k, e))
+                               self._invalid_metadata("PROVIDE.syntax", "%s: %s" % (k, e))
 
                for k in self._use_conditional_misc_keys:
                        v = self._metadata.get(k)
@@ -283,11 +284,7 @@ class Package(Task):
                                        check_required_use(v, (),
                                                self.iuse.is_valid_flag, eapi=eapi)
                                except InvalidDependString as e:
-                                       # Force unicode format string for python-2.x safety,
-                                       # ensuring that PortageException.__unicode__() is used
-                                       # when necessary.
-                                       self._invalid_metadata(k + ".syntax",
-                                               _unicode_decode("%s: %s") % (k, e))
+                                       self._invalid_metadata(k + ".syntax", "%s: %s" % (k, e))
 
                k = 'SRC_URI'
                v = self._metadata.get(k)
@@ -416,7 +413,7 @@ class Package(Task):
                # format string, since that will result in the
                # PortageException.__str__() method being invoked,
                # followed by unsafe decoding that may result in a
-               # UnicodeDecodeError. Therefore, use _unicode_decode()
+               # UnicodeDecodeError. Therefore, use unicode_literals
                # to ensure that format strings are unicode, so that
                # PortageException.__unicode__() is used when necessary
                # in python-2.x.
@@ -428,19 +425,17 @@ class Package(Task):
                                                continue
                                        categorized_error = True
                                        self._invalid_metadata(error.category,
-                                               _unicode_decode("%s: %s") % (k, error))
+                                               "%s: %s" % (k, error))
 
                        if not categorized_error:
-                               self._invalid_metadata(qacat,
-                                       _unicode_decode("%s: %s") % (k, e))
+                               self._invalid_metadata(qacat,"%s: %s" % (k, e))
                else:
                        # For installed packages, show the path of the file
                        # containing the invalid metadata, since the user may
                        # want to fix the deps by hand.
                        vardb = self.root_config.trees['vartree'].dbapi
                        path = vardb.getpath(self.cpv, filename=k)
-                       self._invalid_metadata(qacat,
-                               _unicode_decode("%s: %s in '%s'") % (k, e, path))
+                       self._invalid_metadata(qacat, "%s: %s in '%s'" % (k, e, path))
 
        def _invalid_metadata(self, msg_type, msg):
                if self._invalid is None:
index c2f2459f405a04d3313485a3d02857c8b2b6d424..c495ae09453114ea01eecb49fd97a36c3b65b7e3 100644 (file)
@@ -1,7 +1,7 @@
 # Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
-from __future__ import print_function
+from __future__ import print_function, unicode_literals
 
 from collections import deque
 import gc
@@ -18,7 +18,7 @@ import zlib
 import portage
 from portage import os
 from portage import _encodings
-from portage import _unicode_decode, _unicode_encode
+from portage import _unicode_encode
 from portage.cache.mappings import slot_dict_class
 from portage.elog.messages import eerror
 from portage.localization import _
@@ -1145,9 +1145,9 @@ class Scheduler(PollScheduler):
                                printer.eerror(line)
                        printer.eerror("")
                        for failed_pkg in self._failed_pkgs_all:
-                               # Use _unicode_decode() to force unicode format string so
+                               # Use unicode_literals to force unicode format string so
                                # that Package.__unicode__() is called in python2.
-                               msg = _unicode_decode(" %s") % (failed_pkg.pkg,)
+                               msg = " %s" % (failed_pkg.pkg,)
                                log_path = self._locate_failure_log(failed_pkg)
                                if log_path is not None:
                                        msg += ", Log file:"
index 3daca19e1dd30815d05bfd1e56fb06b4a85d6c79..f460474548b50582f249271c3f079fb3740f87fc 100644 (file)
@@ -1,10 +1,12 @@
-# Copyright 1999-2011 Gentoo Foundation
+# Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 from itertools import chain
 import sys
 
-from portage import _encodings, _unicode_decode, _unicode_encode
+from portage import _encodings, _unicode_encode
 from portage.output import red
 from portage.util import cmp_sort_key
 from portage.output import blue
@@ -114,9 +116,9 @@ def pkg_use_display(pkg, opts, modified_use=None):
                        flags.sort(key=UseFlagDisplay.sort_combined)
                else:
                        flags.sort(key=UseFlagDisplay.sort_separated)
-               # Use _unicode_decode() to force unicode format string so
+               # Use unicode_literals to force unicode format string so
                # that UseFlagDisplay.__unicode__() is called in python2.
                flag_displays.append('%s="%s"' % (varname,
-                       ' '.join(_unicode_decode("%s") % (f,) for f in flags)))
+                       ' '.join("%s" % (f,) for f in flags)))
 
        return ' '.join(flag_displays)
index 589680a51af4ec5963dbb304a41397c873dde69f..a95d7a1c5f6776d42715ed117123ec2899ee0032 100644 (file)
@@ -1,7 +1,7 @@
 # Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
-from __future__ import print_function
+from __future__ import print_function, unicode_literals
 
 import errno
 import logging
@@ -1207,11 +1207,11 @@ def calc_depclean(settings, trees, ldpath_mtimes,
                                priority = priority_map[dep_type]
 
                                if debug:
-                                       writemsg_level(_unicode_decode("\nParent:    %s\n") \
+                                       writemsg_level("\nParent:    %s\n"
                                                % (node,), noiselevel=-1, level=logging.DEBUG)
-                                       writemsg_level(_unicode_decode(  "Depstring: %s\n") \
+                                       writemsg_level(  "Depstring: %s\n"
                                                % (depstr,), noiselevel=-1, level=logging.DEBUG)
-                                       writemsg_level(_unicode_decode(  "Priority:  %s\n") \
+                                       writemsg_level(  "Priority:  %s\n"
                                                % (priority,), noiselevel=-1, level=logging.DEBUG)
 
                                try:
@@ -1225,7 +1225,7 @@ def calc_depclean(settings, trees, ldpath_mtimes,
 
                                if debug:
                                        writemsg_level("Candidates: [%s]\n" % \
-                                               ', '.join(_unicode_decode("'%s'") % (x,) for x in atoms),
+                                               ', '.join("'%s'" % (x,) for x in atoms),
                                                noiselevel=-1, level=logging.DEBUG)
 
                                for atom in atoms:
@@ -3750,10 +3750,15 @@ def run_action(settings, trees, mtimedb, myaction, myopts, myfiles,
                        portage.util.ensure_dirs(_emerge.emergelog._emerge_log_dir)
 
        if not "--pretend" in myopts:
-               emergelog(xterm_titles, "Started emerge on: "+\
-                       _unicode_decode(
-                               time.strftime("%b %d, %Y %H:%M:%S", time.localtime()),
-                               encoding=_encodings['content'], errors='replace'))
+               time_fmt = "%b %d, %Y %H:%M:%S"
+               if sys.hexversion < 0x3000000:
+                       time_fmt = portage._unicode_encode(time_fmt)
+               time_str = time.strftime(time_fmt, time.localtime(time.time()))
+               # Avoid potential UnicodeDecodeError in Python 2, since strftime
+               # returns bytes in Python 2, and %b may contain non-ascii chars.
+               time_str = _unicode_decode(time_str,
+                       encoding=_encodings['content'], errors='replace')
+               emergelog(xterm_titles, "Started emerge on: %s" % time_str)
                myelogstr=""
                if myopts:
                        opt_list = []
index 92e3b1c9d7681e9b4a58fa2200d70cb726476837..b5dba31dc41b55e36b9448b05e71120a9ebb8ea4 100644 (file)
@@ -1,7 +1,7 @@
-# Copyright 1999-2012 Gentoo Foundation
+# Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
-from __future__ import print_function
+from __future__ import print_function, unicode_literals
 
 import errno
 import io
@@ -3187,7 +3187,7 @@ class depgraph(object):
                                        if not node.installed:
                                                raise
                        affecting_use.difference_update(node.use.mask, node.use.force)
-                       pkg_name = _unicode_decode("%s") % (node.cpv,)
+                       pkg_name = "%s" % (node.cpv,)
                        if affecting_use:
                                usedep = []
                                for flag in affecting_use:
@@ -3242,7 +3242,7 @@ class depgraph(object):
                                        node_type = "set"
                                else:
                                        node_type = "argument"
-                               dep_chain.append((_unicode_decode("%s") % (node,), node_type))
+                               dep_chain.append(("%s" % (node,), node_type))
 
                        elif node is not start_node:
                                for ppkg, patom in all_parents[child]:
@@ -3284,7 +3284,7 @@ class depgraph(object):
                                affecting_use.difference_update(node.use.mask, \
                                        node.use.force)
 
-                               pkg_name = _unicode_decode("%s") % (node.cpv,)
+                               pkg_name = "%s" % (node.cpv,)
                                if affecting_use:
                                        usedep = []
                                        for flag in affecting_use:
@@ -3336,8 +3336,7 @@ class depgraph(object):
                                if self._dynamic_config.digraph.parent_nodes(parent_arg):
                                        selected_parent = parent_arg
                                else:
-                                       dep_chain.append(
-                                               (_unicode_decode("%s") % (parent_arg,), "argument"))
+                                       dep_chain.append(("%s" % (parent_arg,), "argument"))
                                        selected_parent = None
 
                        node = selected_parent
@@ -3373,7 +3372,7 @@ class depgraph(object):
                if arg:
                        xinfo='"%s"' % arg
                if isinstance(myparent, AtomArg):
-                       xinfo = _unicode_decode('"%s"') % (myparent,)
+                       xinfo = '"%s"' % (myparent,)
                # Discard null/ from failed cpv_expand category expansion.
                xinfo = xinfo.replace("null/", "")
                if root != self._frozen_config._running_root.root:
@@ -3751,8 +3750,7 @@ class depgraph(object):
                        dep_chain = self._get_dep_chain(myparent, atom)
                        for node, node_type in dep_chain:
                                msg.append('(dependency required by "%s" [%s])' % \
-                                               (colorize('INFORM', _unicode_decode("%s") % \
-                                               (node)), node_type))
+                                               (colorize('INFORM', "%s" % (node)), node_type))
 
                if msg:
                        writemsg("\n".join(msg), noiselevel=-1)
@@ -5039,7 +5037,7 @@ class depgraph(object):
                                                        # matches (this can happen if an atom lacks a
                                                        # category).
                                                        show_invalid_depstring_notice(
-                                                               pkg, depstr, _unicode_decode("%s") % (e,))
+                                                               pkg, depstr, "%s" % (e,))
                                                        del e
                                                        raise
                                                if not success:
@@ -5069,8 +5067,7 @@ class depgraph(object):
                                                except portage.exception.InvalidAtom as e:
                                                        depstr = " ".join(vardb.aux_get(pkg.cpv, dep_keys))
                                                        show_invalid_depstring_notice(
-                                                               pkg, depstr,
-                                                               _unicode_decode("Invalid Atom: %s") % (e,))
+                                                               pkg, depstr, "Invalid Atom: %s" % (e,))
                                                        return False
                                for cpv in stale_cache:
                                        del blocker_cache[cpv]
index b1b093f52989fbe66360ccdf532de84fe7cc1d8f..aea94f74e1caf86c77f11f0b09aeebd4fe7f82ac 100644 (file)
@@ -1,7 +1,7 @@
-# Copyright 1999-2011 Gentoo Foundation
+# Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
-from __future__ import print_function
+from __future__ import unicode_literals
 
 import io
 import sys
@@ -20,10 +20,6 @@ from portage.output import xtermTitle
 _disable = True
 _emerge_log_dir = '/var/log'
 
-# Coerce to unicode, in order to prevent TypeError when writing
-# raw bytes to TextIOWrapper with python2.
-_log_fmt = _unicode_decode("%.0f: %s\n")
-
 def emergelog(xterm_titles, mystr, short_msg=None):
 
        if _disable:
@@ -51,10 +47,10 @@ def emergelog(xterm_titles, mystr, short_msg=None):
                                mode=0o660)
                mylock = portage.locks.lockfile(file_path)
                try:
-                       mylogfile.write(_log_fmt % (time.time(), mystr))
+                       mylogfile.write("%.0f: %s\n" % (time.time(), mystr))
                        mylogfile.close()
                finally:
                        portage.locks.unlockfile(mylock)
        except (IOError,OSError,portage.exception.PortageException) as e:
                if secpass >= 1:
-                       print("emergelog():",e, file=sys.stderr)
+                       portage.util.writemsg("emergelog(): %s\n" % (e,), noiselevel=-1)
index 52561239e249dc72ec4b8b9c0df862d5194cf808..6380b22c7fe216bed8fb89fc53fb9b082d8c232f 100644 (file)
@@ -1,7 +1,7 @@
-# Copyright 2010-2012 Gentoo Foundation
+# Copyright 2010-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
-from __future__ import print_function
+from __future__ import print_function, unicode_literals
 
 from itertools import chain, product
 import logging
index 3d6af66d4dcb246eb2a7265cc36cef60ed1c24be..651a4f73c5309f63449c2c3d3a0bfc63e5c3bef5 100644 (file)
@@ -1,9 +1,11 @@
-# Copyright 2010-2012 Gentoo Foundation
+# Copyright 2010-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 """Resolver output display operation.
 """
 
+from __future__ import unicode_literals
+
 __all__ = (
        "Display",
        )
@@ -11,7 +13,6 @@ __all__ = (
 import sys
 
 from portage import os
-from portage import _unicode_decode
 from portage.dbapi.dep_expand import dep_expand
 from portage.dep import cpvequal, _repo_separator, _slot_separator
 from portage.eapi import _get_eapi_attrs
@@ -567,9 +568,9 @@ class Display(object):
                """
                writemsg_stdout('\n%s\n' % (self.counters,), noiselevel=-1)
                if show_repos:
-                       # Use _unicode_decode() to force unicode format string so
+                       # Use unicode_literals to force unicode format string so
                        # that RepoDisplay.__unicode__() is called in python2.
-                       writemsg_stdout(_unicode_decode("%s") % (self.conf.repo_display,),
+                       writemsg_stdout("%s" % (self.conf.repo_display,),
                                noiselevel=-1)
                return
 
index 1fc083ae12020f1fc49c4a193bbb39f3d396a618..ccaa0f2d76dc04342261a51c422ccf9bb35381ae 100644 (file)
@@ -1,9 +1,12 @@
-# Copyright 2010-2012 Gentoo Foundation
+# Copyright 2010-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 """Contains private support functions for the Display class
 in output.py
 """
+
+from __future__ import unicode_literals
+
 __all__ = (
        )
 
index 8b2f4b888a62b1bc7617b17fd521d3c41ebcf5a2..f07b01a44409f6c0cc580ac4e39f3dde226d35de 100644 (file)
@@ -1,10 +1,11 @@
-# Copyright 2010-2012 Gentoo Foundation
+# Copyright 2010-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
-from __future__ import print_function
+from __future__ import print_function, unicode_literals
 
 import sys
 
+from portage import _encodings, _unicode_encode
 from _emerge.AtomArg import AtomArg
 from _emerge.Package import Package
 from _emerge.PackageArg import PackageArg
@@ -150,7 +151,7 @@ class slot_conflict_handler(object):
                        if self.debug:
                                writemsg("\nNew configuration:\n", noiselevel=-1)
                                for pkg in config:
-                                       writemsg("   " + str(pkg) + "\n", noiselevel=-1)
+                                       writemsg("   %s\n" % (pkg,), noiselevel=-1)
                                writemsg("\n", noiselevel=-1)
 
                        new_solutions = self._check_configuration(config, all_conflict_atoms_by_slotatom, conflict_nodes)
@@ -249,14 +250,14 @@ class slot_conflict_handler(object):
 
                for (slot_atom, root), pkgs \
                        in self.slot_collision_info.items():
-                       msg.append(str(slot_atom))
+                       msg.append("%s" % (slot_atom,))
                        if root != self.depgraph._frozen_config._running_root.root:
                                msg.append(" for %s" % (root,))
                        msg.append("\n\n")
 
                        for pkg in pkgs:
                                msg.append(indent)
-                               msg.append(str(pkg))
+                               msg.append("%s" % (pkg,))
                                parent_atoms = self.all_parents.get(pkg)
                                if parent_atoms:
                                        #Create a list of collision reasons and map them to sets
@@ -394,7 +395,7 @@ class slot_conflict_handler(object):
 
                                        def highlight_violations(atom, version, use=[]):
                                                """Colorize parts of an atom"""
-                                               atom_str = str(atom)
+                                               atom_str = "%s" % (atom,)
                                                if version:
                                                        op = atom.operator
                                                        ver = None
@@ -449,7 +450,7 @@ class slot_conflict_handler(object):
                                                        (PackageArg, AtomArg)):
                                                        # For PackageArg and AtomArg types, it's
                                                        # redundant to display the atom attribute.
-                                                       msg.append(str(parent))
+                                                       msg.append("%s" % (parent,))
                                                else:
                                                        # Display the specific atom from SetArg or
                                                        # Package types.
@@ -567,7 +568,9 @@ class slot_conflict_handler(object):
                                        if pkg.iuse.all.symmetric_difference(other_pkg.iuse.all) \
                                                or _pkg_use_enabled(pkg).symmetric_difference(_pkg_use_enabled(other_pkg)):
                                                if self.debug:
-                                                       writemsg(str(pkg) + " has pending USE changes. Rejecting configuration.\n", noiselevel=-1)
+                                                       writemsg(("%s has pending USE changes. "
+                                                               "Rejecting configuration.\n") % (pkg,),
+                                                               noiselevel=-1)
                                                return False
 
                #A list of dicts. Keeps one dict per slot conflict. [ { flag1: "enabled" }, { flag2: "disabled" } ]
@@ -590,16 +593,18 @@ class slot_conflict_handler(object):
                                if not i.findAtomForPackage(pkg, modified_use=_pkg_use_enabled(pkg)):
                                        #Version range does not match.
                                        if self.debug:
-                                               writemsg(str(pkg) + " does not satify all version requirements." + \
-                                                       " Rejecting configuration.\n", noiselevel=-1)
+                                               writemsg(("%s does not satify all version "
+                                                       "requirements. Rejecting configuration.\n") %
+                                                       (pkg,), noiselevel=-1)
                                        return False
 
                                if not pkg.iuse.is_valid_flag(atom.unevaluated_atom.use.required):
                                        #Missing IUSE.
                                        #FIXME: This needs to support use dep defaults.
                                        if self.debug:
-                                               writemsg(str(pkg) + " misses needed flags from IUSE." + \
-                                                       " Rejecting configuration.\n", noiselevel=-1)
+                                               writemsg(("%s misses needed flags from IUSE."
+                                                       " Rejecting configuration.\n") % (pkg,),
+                                                       noiselevel=-1)
                                        return False
 
                                if not isinstance(ppkg, Package) or ppkg.installed:
@@ -624,8 +629,9 @@ class slot_conflict_handler(object):
                                        #We can't change USE of an installed package (only of an ebuild, but that is already
                                        #part of the conflict, isn't it?
                                        if self.debug:
-                                               writemsg(str(pkg) + ": installed package would need USE changes." + \
-                                                       " Rejecting configuration.\n", noiselevel=-1)
+                                               writemsg(("%s: installed package would need USE"
+                                                       " changes. Rejecting configuration.\n") % (pkg,),
+                                                       noiselevel=-1)
                                        return False
 
                                #Compute the required USE changes. A flag can be forced to "enabled" or "disabled",
@@ -679,7 +685,7 @@ class slot_conflict_handler(object):
                if self.debug:
                        writemsg("All involved flags:\n", noiselevel=-1)
                        for id, involved_flags in enumerate(all_involved_flags):
-                               writemsg("   " + str(config[id]) + "\n", noiselevel=-1)
+                               writemsg("   %s\n" % (config[id],), noiselevel=-1)
                                for flag, state in involved_flags.items():
                                        writemsg("     " + flag + ": " + state + "\n", noiselevel=-1)
 
@@ -762,7 +768,7 @@ class slot_conflict_handler(object):
                                                inner_first = False
                                        else:
                                                msg += ", "
-                                       msg += flag + ": " + str(state)
+                                       msg += flag + ": %s" % (state,)
                                msg += "}"
                        msg += "]\n"
                        writemsg(msg, noiselevel=-1)
@@ -866,8 +872,9 @@ class slot_conflict_handler(object):
                                        #We managed to create a new problem with our changes.
                                        is_valid_solution = False
                                        if self.debug:
-                                               writemsg("new conflict introduced: " + str(pkg) + \
-                                                       " does not match " + new_atom + " from " + str(ppkg) + "\n", noiselevel=-1)
+                                               writemsg(("new conflict introduced: %s"
+                                                       " does not match %s from %s\n") %
+                                                       (pkg, new_atom, ppkg), noiselevel=-1)
                                        break
 
                        if not is_valid_solution:
@@ -954,8 +961,16 @@ class _solution_candidate_generator(object):
                        else:
                                return self.value == other.value
                def __str__(self):
-                       return str(self.value)
-       
+                       return "%s" % (self.value,)
+
+               if sys.hexversion < 0x3000000:
+
+                       __unicode__ = __str__
+
+                       def __str__(self):
+                               return _unicode_encode(self.__unicode__(),
+                                       encoding=_encodings['content'], errors='backslashreplace')
+
        def __init__(self, all_involved_flags):
                #A copy of all_involved_flags with all "cond" values
                #replaced by a _value_helper object.
index 6d7b1019e6b4c2eebb8453d980a903fce53dceed..3bae4defff20004c935e08d67e0faa22f2794bcd 100644 (file)
@@ -2,6 +2,8 @@
 # Copyright 1998-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 VERSION="HEAD"
 
 # ===========================================================================
index 8c5bbf308e62f847548ac6df47fccac3b005d52f..3859a1666c91edc9de233346c9e67c78da4b8b44 100644 (file)
@@ -1,7 +1,9 @@
 # portage: Constants
-# Copyright 1998-2012 Gentoo Foundation
+# Copyright 1998-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 import os
 
 # ===========================================================================
index 49b72937df64485096717f360b07ec4a3e47839f..5828bcacd88434597b43ecb423f6b27eaf7c47f0 100644 (file)
@@ -1,6 +1,8 @@
-# Copyright 1998-2012 Gentoo Foundation
+# Copyright 1998-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 __all__ = ["dbapi"]
 
 import re
index 95b2c28cd45369a37ef155e406b81064c5976549..9aa603d1149ff973fe47f05943ec6bf318dd90de 100644 (file)
@@ -1,6 +1,8 @@
-# Copyright 2011-2012 Gentoo Foundation
+# Copyright 2011-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 import portage
 from portage.dep import Atom, _get_useflag_re
 from portage.eapi import _get_eapi_attrs
index f6fc11498dec530f2369b21f57f79ba2e54c87da..875e955151c3a2e733c17ab2cacefb15c91763d2 100644 (file)
@@ -1,6 +1,8 @@
-# Copyright 1998-2012 Gentoo Foundation
+# Copyright 1998-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 __all__ = ["bindbapi", "binarytree"]
 
 import portage
@@ -138,15 +140,15 @@ class bindbapi(fakedbapi):
                        if myval:
                                mydata[x] = " ".join(myval.split())
 
-               if not mydata.setdefault('EAPI', _unicode_decode('0')):
-                       mydata['EAPI'] = _unicode_decode('0')
+               if not mydata.setdefault('EAPI', '0'):
+                       mydata['EAPI'] = '0'
 
                if cache_me:
                        aux_cache = self._aux_cache_slot_dict()
                        for x in self._aux_cache_keys:
-                               aux_cache[x] = mydata.get(x, _unicode_decode(''))
+                               aux_cache[x] = mydata.get(x, '')
                        self._aux_cache[mycpv] = aux_cache
-               return [mydata.get(x, _unicode_decode('')) for x in wants]
+               return [mydata.get(x, '') for x in wants]
 
        def aux_update(self, cpv, values):
                if not self.bintree.populated:
index 947194cca8270fa904b307a351afd5e6329f4987..70ee782457ec3bee93e0794dd868b42b52bb73ba 100644 (file)
@@ -1,6 +1,8 @@
-# Copyright 2010-2011 Gentoo Foundation
+# Copyright 2010-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 __all__ = ["cpv_expand"]
 
 import portage
index bb211c739682aafddb5345a29430c5f6cc25c9a7..3de5d8fc3d01ca68e727887bd5d3379c3de4bfdb 100644 (file)
@@ -1,6 +1,8 @@
-# Copyright 2010-2012 Gentoo Foundation
+# Copyright 2010-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 __all__ = ["dep_expand"]
 
 import re
index cf4b142310e009ee824a6d82b021a7d27a847dce..321b6758aa1cf1cfa3cd61a3afb65f1b4d0e6027 100644 (file)
@@ -1,6 +1,8 @@
 # Copyright 1998-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 __all__ = [
        "close_portdbapi_caches", "FetchlistDict", "portagetree", "portdbapi"
 ]
index 09130fb385a9e657183f995e1138a1edd74ed69f..30add8a89abf738f0de2a8b6c077e5b24390bdc6 100644 (file)
@@ -1,6 +1,8 @@
 # Copyright 1998-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 __all__ = [
        "vardbapi", "vartree", "dblink"] + \
        ["write_contents", "tar_contents"]
@@ -594,7 +596,7 @@ class vardbapi(dbapi):
                                getattr(e, 'errno', None) in (errno.ENOENT, errno.EACCES):
                                pass
                        else:
-                               writemsg(_unicode_decode(_("!!! Error loading '%s': %s\n")) % \
+                               writemsg(_("!!! Error loading '%s': %s\n") % \
                                        (self._aux_cache_filename, e), noiselevel=-1)
                        del e
 
@@ -714,7 +716,7 @@ class vardbapi(dbapi):
                if _get_slot_re(eapi_attrs).match(mydata['SLOT']) is None:
                        # Empty or invalid slot triggers InvalidAtom exceptions when
                        # generating slot atoms for packages, so translate it to '0' here.
-                       mydata['SLOT'] = _unicode_decode('0')
+                       mydata['SLOT'] = '0'
 
                return [mydata[x] for x in wants]
 
@@ -750,7 +752,7 @@ class vardbapi(dbapi):
                                        self._aux_cache_keys_re.match(x) is None:
                                        env_keys.append(x)
                                        continue
-                               myd = _unicode_decode('')
+                               myd = ''
 
                        # Preserve \n for metadata that is known to
                        # contain multiple lines.
@@ -764,13 +766,13 @@ class vardbapi(dbapi):
                        for k in env_keys:
                                v = env_results.get(k)
                                if v is None:
-                                       v = _unicode_decode('')
+                                       v = ''
                                if self._aux_multi_line_re.match(k) is None:
                                        v = " ".join(v.split())
                                results[k] = v
 
                if results.get("EAPI") == "":
-                       results[_unicode_decode("EAPI")] = _unicode_decode('0')
+                       results["EAPI"] = '0'
 
                return results
 
@@ -1607,7 +1609,7 @@ class dblink(object):
                if myroot == os.path.sep:
                        myroot = None
                # used to generate parent dir entries
-               dir_entry = (_unicode_decode("dir"),)
+               dir_entry = ("dir",)
                eroot_split_len = len(self.settings["EROOT"].split(os.sep)) - 1
                pos = 0
                errors = []
@@ -1896,7 +1898,7 @@ class dblink(object):
                                showMessage(_("!!! FAILED prerm: %s\n") % \
                                        os.path.join(self.dbdir, "EAPI"),
                                        level=logging.ERROR, noiselevel=-1)
-                               showMessage(_unicode_decode("%s\n") % (eapi_unsupported,),
+                               showMessage("%s\n" % (eapi_unsupported,),
                                        level=logging.ERROR, noiselevel=-1)
                        elif os.path.isfile(myebuildpath):
                                phase = EbuildPhase(background=background,
@@ -3963,7 +3965,7 @@ class dblink(object):
                        encoding=_encodings['fs'], errors='strict'),
                        mode='w', encoding=_encodings['repo.content'],
                        errors='backslashreplace') as f:
-                       f.write(_unicode_decode(str(counter)))
+                       f.write("%s" % counter)
 
                self.updateprotect()
 
@@ -4859,7 +4861,7 @@ class dblink(object):
                        mode='w', encoding=_encodings['repo.content'],
                        errors='backslashreplace') as f:
                        for x in mylist:
-                               f.write(_unicode_decode(x + "\n"))
+                               f.write("%s\n" % x)
 
        def isregular(self):
                "Is this a regular package (does it have a CATEGORY file?  A dblink can be virtual *and* regular)"
index 30d6c227fe54c848a6bfca69a6c270c226148c0f..ba9745c2a4601fc1a6b90131b01eadd51b1b4c5c 100644 (file)
@@ -1,6 +1,7 @@
-# Copyright 1998-2012 Gentoo Foundation
+# Copyright 1998-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
 
 from portage.dbapi import dbapi
 from portage.dbapi.dep_expand import dep_expand
index 67383e882aa75405e07e4df7db6f2e57cb9380e3..511753116d81f6890bff0d3db9e7715f01897a86 100644 (file)
@@ -2,6 +2,8 @@
 # Copyright 2003-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 __all__ = [
        'Atom', 'best_match_to_list', 'cpvequal',
        'dep_getcpv', 'dep_getkey', 'dep_getslot',
index 2fcfb48b3e8be45d9096b038ced0815d0ab2fbb1..7b6444403ad5584781a843750e8d3137b6207787 100644 (file)
@@ -1,6 +1,8 @@
-# Copyright 2012 Gentoo Foundation
+# Copyright 2012-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 from portage.dep import Atom, paren_enclose, use_reduce
 from portage.eapi import _get_eapi_attrs
 from portage.exception import InvalidData
index b5f8d0d7ed14a1914788aedd61cd524b918c7008..6e3d0865a2cea01e6133d90e6b98f5be3b187f7e 100644 (file)
@@ -1,12 +1,13 @@
-# Copyright 2010-2012 Gentoo Foundation
+# Copyright 2010-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 __all__ = ['dep_check', 'dep_eval', 'dep_wordreduce', 'dep_zapdeps']
 
 import logging
 
 import portage
-from portage import _unicode_decode
 from portage.dep import Atom, match_from_list, use_reduce
 from portage.exception import InvalidDependString, ParseError
 from portage.localization import _
@@ -183,7 +184,7 @@ def _expand_new_virtuals(mysplit, edebug, mydbapi, mysettings, myroot="/",
                                        del mytrees["virt_parent"]
 
                        if not mycheck[0]:
-                               raise ParseError(_unicode_decode("%s: %s '%s'") % \
+                               raise ParseError("%s: %s '%s'" % \
                                        (pkg, mycheck[1], depstring))
 
                        # pull in the new-style virtual
@@ -605,7 +606,7 @@ def dep_check(depstring, mydbapi, mysettings, use="yes", mode=None, myuse=None,
                        masklist=mymasks, matchall=(use=="all"), excludeall=useforce,
                        opconvert=True, token_class=Atom, eapi=eapi)
                except InvalidDependString as e:
-                       return [0, _unicode_decode("%s") % (e,)]
+                       return [0, "%s" % (e,)]
 
        if mysplit == []:
                #dependencies were reduced to nothing
@@ -619,7 +620,7 @@ def dep_check(depstring, mydbapi, mysettings, use="yes", mode=None, myuse=None,
                        use_force=useforce, use_mask=mymasks, use_cache=use_cache,
                        use_binaries=use_binaries, myroot=myroot, trees=trees)
        except ParseError as e:
-               return [0, _unicode_decode("%s") % (e,)]
+               return [0, "%s" % (e,)]
 
        mysplit2=mysplit[:]
        mysplit2=dep_wordreduce(mysplit2,mysettings,mydbapi,mode,use_cache=use_cache)
index 3ad1dd3b8ba9a5b2a827121834e87b8cf3a5c862..786f894548c212084b716533855d1d320641a353 100644 (file)
@@ -1,9 +1,12 @@
 # elog/mod_save_summary.py - elog dispatch module
-# Copyright 2006-2012 Gentoo Foundation
+# Copyright 2006-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 import errno
 import io
+import sys
 import time
 import portage
 from portage import os
@@ -71,17 +74,19 @@ def process(mysettings, key, logentries, fulltext):
        apply_permissions(elogfilename, uid=logfile_uid, gid=elogdir_gid,
                mode=elogdir_grp_mode, mask=0)
 
-       time_str = time.strftime("%Y-%m-%d %H:%M:%S %Z",
-               time.localtime(time.time()))
-       # Avoid potential UnicodeDecodeError later.
+       time_fmt = "%Y-%m-%d %H:%M:%S %Z"
+       if sys.hexversion < 0x3000000:
+               time_fmt = _unicode_encode(time_fmt)
+       time_str = time.strftime(time_fmt, time.localtime(time.time()))
+       # Avoid potential UnicodeDecodeError in Python 2, since strftime
+       # returns bytes in Python 2, and %Z may contain non-ascii chars.
        time_str = _unicode_decode(time_str,
                encoding=_encodings['content'], errors='replace')
-       elogfile.write(_unicode_decode(
-               _(">>> Messages generated by process " +
+       elogfile.write(_(">>> Messages generated by process "
                "%(pid)d on %(time)s for package %(pkg)s:\n\n") %
-               {"pid": os.getpid(), "time": time_str, "pkg": key}))
+               {"pid": os.getpid(), "time": time_str, "pkg": key})
        elogfile.write(_unicode_decode(fulltext))
-       elogfile.write(_unicode_decode("\n"))
+       elogfile.write("\n")
        elogfile.close()
 
        return elogfilename
index 947bd3e92a1d8ab82846728eb4f7343f3251f56b..77c1c8f7968df16069fb84e465cbc2f31fdeb67c 100644 (file)
@@ -1,7 +1,9 @@
 # getbinpkg.py -- Portage binary-package helper functions
-# Copyright 2003-2012 Gentoo Foundation
+# Copyright 2003-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 from portage.output import colorize
 from portage.cache.mappings import slot_dict_class
 from portage.localization import _
index 71837e074a9008e8101200f71afe214276b96801..513f1ca8f18efa463073e584b50ac0a3abde8899 100644 (file)
@@ -1,6 +1,8 @@
 # Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 import errno
 import io
 import re
index bbd93257ac49478b5188a2265457aa2e85046592..94ec8f1648110d723f724d71af163e6ccf7cd875 100644 (file)
@@ -1,8 +1,8 @@
 # portage: news management code
-# Copyright 2006-2011 Gentoo Foundation
+# Copyright 2006-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
-from __future__ import print_function
+from __future__ import print_function, unicode_literals
 
 __all__ = ["NewsManager", "NewsItem", "DisplayRestriction",
        "DisplayProfileRestriction", "DisplayKeywordRestriction",
@@ -388,7 +388,7 @@ def count_unread_news(portdb, vardb, repos=None, update=True):
                        # NOTE: The NewsManager typically handles permission errors by
                        # returning silently, so PermissionDenied won't necessarily be
                        # raised even if we do trigger a permission error above.
-                       msg = _unicode_decode("Permission denied: '%s'\n") % (e,)
+                       msg = "Permission denied: '%s'\n" % (e,)
                        if msg in permission_msgs:
                                pass
                        else:
index 93bb98a428e047a600bd61aa1a9de0cba4e1e112..98e68d2bd01ce7f0769f61e29da821af2d637e07 100644 (file)
@@ -1,6 +1,8 @@
-# Copyright 2010-2012 Gentoo Foundation
+# Copyright 2010-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 __all__ = (
        'case_insensitive_vars', 'default_globals', 'env_blacklist', \
        'environ_filter', 'environ_whitelist', 'environ_whitelist_re',
index fa8b506d79482e005949a85368f3e5b599f214f5..351c95628082f64b94a1ac49e5d6716ff06373b2 100644 (file)
@@ -1,11 +1,12 @@
-# Copyright 2010-2012 Gentoo Foundation
+# Copyright 2010-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 import io
 
 import portage
 from portage import os
-from portage import _unicode_decode
 from portage.dep import Atom, _repo_name_re
 from portage.eapi import eapi_has_repo_deps
 from portage.elog import messages as elog_messages
@@ -65,7 +66,7 @@ class QueryCommand(IpcCommand):
                        try:
                                atom = Atom(args[0], allow_repo=allow_repo, eapi=eapi)
                        except InvalidAtom as e:
-                               warnings.append(_unicode_decode("QA Notice: %s: %s") % (cmd, e))
+                               warnings.append("QA Notice: %s: %s" % (cmd, e))
 
                        use = self.settings.get('PORTAGE_BUILT_USE')
                        if use is None:
index 1364a3d167a5b8b69f416687a9a225d6ab6a6d44..4df3c96bbf12caeeff1d5c13b4cf395b095d7018 100644 (file)
@@ -1,6 +1,8 @@
 # Copyright 2010-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 __all__ = [
        'autouse', 'best_from_dict', 'check_config_instance', 'config',
 ]
@@ -2378,7 +2380,7 @@ class config(object):
                                return portage._pym_path
 
                        elif mykey == "PORTAGE_GID":
-                               return _unicode_decode(str(portage_gid))
+                               return "%s" % portage_gid
 
                for d in self.lookuplist:
                        try:
index bef19892c61f33500e1f2d66d2d9e97cd64a9c83..3e8ff013847f397ac540f9029f4d01f2ad06faa9 100644 (file)
@@ -1,6 +1,8 @@
 # Copyright 2010-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 __all__ = ['doebuild', 'doebuild_environment', 'spawn', 'spawnebuild']
 
 import grp
@@ -1742,7 +1744,7 @@ def _post_src_install_write_metadata(settings):
                'BUILD_TIME'), encoding=_encodings['fs'], errors='strict'),
                mode='w', encoding=_encodings['repo.content'],
                errors='strict') as f:
-               f.write(_unicode_decode("%.0f\n" % (time.time(),)))
+               f.write("%.0f\n" % (time.time(),))
 
        use = frozenset(settings['PORTAGE_USE'].split())
        for k in _vdb_use_conditional_keys:
@@ -1774,7 +1776,7 @@ def _post_src_install_write_metadata(settings):
                        k), encoding=_encodings['fs'], errors='strict'),
                        mode='w', encoding=_encodings['repo.content'],
                        errors='strict') as f:
-                       f.write(_unicode_decode(v + '\n'))
+                       f.write('%s\n' % v)
 
        if eapi_attrs.slot_operator:
                deps = evaluate_slot_operator_equal_deps(settings, use, QueryCommand.get_db())
@@ -1790,7 +1792,7 @@ def _post_src_install_write_metadata(settings):
                                k), encoding=_encodings['fs'], errors='strict'),
                                mode='w', encoding=_encodings['repo.content'],
                                errors='strict') as f:
-                               f.write(_unicode_decode(v + '\n'))
+                               f.write('%s\n' % v)
 
 def _preinst_bsdflags(mysettings):
        if bsd_chflags:
@@ -1999,7 +2001,7 @@ def _post_src_install_uid_fix(mysettings, out):
                'SIZE'), encoding=_encodings['fs'], errors='strict'),
                mode='w', encoding=_encodings['repo.content'],
                errors='strict')
-       f.write(_unicode_decode(str(size) + '\n'))
+       f.write('%d\n' % size)
        f.close()
 
        _reapply_bsdflags_to_image(mysettings)
index b8fbdc5cf89295394933e661d19256b6b99337a2..6782160e401a5d8281913d67744dbd4f9cce2413 100644 (file)
@@ -1,6 +1,8 @@
-# Copyright 2010-2011 Gentoo Foundation
+# Copyright 2010-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 __all__ = ['prepare_build_dirs']
 
 import errno
@@ -338,12 +340,12 @@ def _prepare_workdir(mysettings):
                        try:
                                _ensure_log_subdirs(logdir, log_subdir)
                        except PortageException as e:
-                               writemsg(_unicode_decode("!!! %s\n") % (e,), noiselevel=-1)
+                               writemsg("!!! %s\n" % (e,), noiselevel=-1)
 
                        if os.access(log_subdir, os.W_OK):
                                logdir_subdir_ok = True
                        else:
-                               writemsg(_unicode_decode("!!! %s: %s\n") %
+                               writemsg("!!! %s: %s\n" %
                                        (_("Permission Denied"), log_subdir), noiselevel=-1)
 
        tmpdir_log_path = os.path.join(
index 3d29fd924f6879a43fd3673297f3f0687ed410c4..a1c1f79cee10819de57eb5234f8c303de16ecaf3 100644 (file)
@@ -1,6 +1,8 @@
-# Copyright 2010-2012 Gentoo Foundation
+# Copyright 2010-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 import io
 import logging
 import warnings
@@ -320,7 +322,7 @@ class RepoConfig(object):
                d = {}
                for k in self.__slots__:
                        d[k] = getattr(self, k, None)
-               return _unicode_decode("%s") % (d,)
+               return "%s" % (d,)
 
        if sys.hexversion < 0x3000000:
 
@@ -431,9 +433,9 @@ class RepoConfigLoader(object):
                                try:
                                        read_file(f)
                                except ParsingError as e:
-                                       writemsg(_unicode_decode(
-                                               _("!!! Error while reading repo config file: %s\n")
-                                               ) % e, noiselevel=-1)
+                                       writemsg(
+                                               _("!!! Error while reading repo config file: %s\n") % e,
+                                               noiselevel=-1)
                        finally:
                                if f is not None:
                                        f.close()
index 3f76030766e776b3d20f3e614a2d29e048e60a43..f518510c4d79c73383201152423a23e26e7fa308 100644 (file)
@@ -1,6 +1,8 @@
-# Copyright 1999-2012 Gentoo Foundation
+# Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 import errno
 import io
 import re
index f3ae658c94613aba5dda95b8b2c698e687a26068..f752e28a83e4277d55f00e9587df29edcdd7d96b 100644 (file)
@@ -1,12 +1,13 @@
-# Copyright 2010-2011 Gentoo Foundation
+# Copyright 2010-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 __all__ = ['digraph']
 
 from collections import deque
 import sys
 
-from portage import _unicode_decode
 from portage.util import writemsg
 
 class digraph(object):
@@ -272,18 +273,17 @@ class digraph(object):
        def debug_print(self):
                def output(s):
                        writemsg(s, noiselevel=-1)
-               # Use _unicode_decode() to force unicode format
+               # Use unicode_literals to force unicode format
                # strings for python-2.x safety, ensuring that
                # node.__unicode__() is used when necessary.
                for node in self.nodes:
-                       output(_unicode_decode("%s ") % (node,))
+                       output("%s " % (node,))
                        if self.nodes[node][0]:
                                output("depends on\n")
                        else:
                                output("(no children)\n")
                        for child, priorities in self.nodes[node][0].items():
-                               output(_unicode_decode("  %s (%s)\n") % \
-                                       (child, priorities[-1],))
+                               output("  %s (%s)\n" % (child, priorities[-1],))
 
        def bfs(self, start, ignore_priority=None):
                if start not in self:
index 57375f2197ab6517fa3ab9645801882ff8006ef5..bf95f1a40908ab1795f830a5b2d118372192c5ca 100644 (file)
@@ -1,6 +1,8 @@
-# Copyright 2010-2012 Gentoo Foundation
+# Copyright 2010-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 __all__ = ['movefile']
 
 import errno
@@ -111,7 +113,7 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None,
        except Exception as e:
                writemsg("!!! %s\n" % _("Stating source file failed... movefile()"),
                        noiselevel=-1)
-               writemsg(_unicode_decode("!!! %s\n") % (e,), noiselevel=-1)
+               writemsg("!!! %s\n" % (e,), noiselevel=-1)
                return None
 
        destexists=1
@@ -180,7 +182,7 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None,
                        writemsg("!!! %s\n" % _("failed to properly create symlink:"),
                                noiselevel=-1)
                        writemsg("!!! %s -> %s\n" % (dest, target), noiselevel=-1)
-                       writemsg(_unicode_decode("!!! %s\n") % (e,), noiselevel=-1)
+                       writemsg("!!! %s\n" % (e,), noiselevel=-1)
                        return None
 
        hardlinked = False
@@ -232,7 +234,7 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None,
                                # Some random error.
                                writemsg("!!! %s\n" % _("Failed to move %(src)s to %(dest)s") %
                                        {"src": src, "dest": dest}, noiselevel=-1)
-                               writemsg(_unicode_decode("!!! %s\n") % (e,), noiselevel=-1)
+                               writemsg("!!! %s\n" % (e,), noiselevel=-1)
                                return None
                        # Invalid cross-device-link 'bind' mounted or actually Cross-Device
        if renamefailed:
@@ -263,7 +265,7 @@ def movefile(src, dest, newmtime=None, sstat=None, mysettings=None,
                        except Exception as e:
                                writemsg("!!! %s\n" % _('copy %(src)s -> %(dest)s failed.') %
                                        {"src": src, "dest": dest}, noiselevel=-1)
-                               writemsg(_unicode_decode("!!! %s\n") % (e,), noiselevel=-1)
+                               writemsg("!!! %s\n" % (e,), noiselevel=-1)
                                return None
                else:
                        #we don't yet handle special, so we need to fall back to /bin/mv
index a9b7e64fea717ceaa4d585f4ab1c6b2affb2423c..d78873f9ee4b16b9096f6bb2c228fd320cf94459 100644 (file)
@@ -1,7 +1,9 @@
 # versions.py -- core Portage functionality
-# Copyright 1998-2012 Gentoo Foundation
+# Copyright 1998-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 __all__ = [
        'best', 'catpkgsplit', 'catsplit',
        'cpv_getkey', 'cpv_getversion', 'cpv_sort_key', 'pkgcmp',  'pkgsplit',
@@ -79,7 +81,7 @@ def _get_pv_re(eapi_attrs):
        else:
                pv_re = _pv['dots_disallowed_in_PN']
 
-       pv_re = re.compile(_unicode_decode('^' + pv_re + '$'), re.VERBOSE | re.UNICODE)
+       pv_re = re.compile(r'^' + pv_re + r'$', re.VERBOSE | re.UNICODE)
 
        _pv_re_cache[cache_key] = pv_re
        return pv_re
index 113b118a439443bea1f1b05570ee52b4f68e74ff..fcd9dc0e3efe7462dd79dd4ba7915c6adafb4e1c 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2010-2012 Gentoo Foundation
+# Copyright 2010-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 """Provides an easy-to-use python interface to Gentoo's metadata.xml file.
@@ -28,6 +28,8 @@
                'Thomas Mills Hinkle'
 """
 
+from __future__ import unicode_literals
+
 __all__ = ('MetaDataXML',)
 
 import sys
@@ -58,7 +60,7 @@ except (ImportError, SystemError, RuntimeError, Exception):
 
 import re
 import xml.etree.ElementTree
-from portage import _encodings, _unicode_encode, _unicode_decode
+from portage import _encodings, _unicode_encode
 from portage.util import unique_everseen
 
 class _MetadataTreeBuilder(xml.etree.ElementTree.TreeBuilder):
@@ -208,7 +210,7 @@ class MetaDataXML(object):
                except ImportError:
                        pass
                except ExpatError as e:
-                       raise SyntaxError(_unicode_decode("%s") % (e,))
+                       raise SyntaxError("%s" % (e,))
 
                if isinstance(herds, etree.ElementTree):
                        herds_etree = herds
index 36c98631bd542554a4c2ab2fdc861bb1ce7ef872..83ce2ed6e7199bcd5f8557c483c6045626c7d3b2 100644 (file)
@@ -1,10 +1,12 @@
 # repoman: Checks
-# Copyright 2007-2012 Gentoo Foundation
+# Copyright 2007-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 """This module contains functions used in Repoman to ascertain the quality
 and correctness of an ebuild."""
 
+from __future__ import unicode_literals
+
 import codecs
 from itertools import chain
 import re
index c515502c45639bc065259eefbac36f723d029f9a..51ffeb838981bb0bdf43715c868033d1508acdfc 100644 (file)
@@ -1,7 +1,9 @@
 # repoman: Error Messages
-# Copyright 2007-2011 Gentoo Foundation
+# Copyright 2007-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+from __future__ import unicode_literals
+
 COPYRIGHT_ERROR = 'Invalid Gentoo Copyright on line: %d'
 LICENSE_ERROR = 'Invalid Gentoo/GPL License on line: %d'
 CVS_HEADER_ERROR = 'Malformed CVS Header on line: %d'
index 4c420d0ec26efbc11562afadf2413f75898acbef..c5b88ff1734733eb78b16e3f62f348111a3f5d93 100644 (file)
@@ -1,8 +1,10 @@
 # -*- coding: utf-8 -*-
 # repoman: Herd database analysis
-# Copyright 2010-2012 Gentoo Foundation
+# Copyright 2010-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2 or later
 
+from __future__ import unicode_literals
+
 import errno
 import xml.etree.ElementTree
 try:
@@ -63,7 +65,7 @@ def make_herd_base(filename):
                        parser=xml.etree.ElementTree.XMLParser(
                                target=_HerdsTreeBuilder()))
        except ExpatError as e:
-               raise ParseError("metadata.xml: " + str(e))
+               raise ParseError("metadata.xml: %s" % (e,))
        except EnvironmentError as e:
                func_call = "open('%s')" % filename
                if e.errno == errno.EACCES:
index b4080741d86568cc6cb006326c0c0d230f0ba4df..8d24abb95ecd79680882115c5c8820e6c72aaf92 100644 (file)
@@ -1,11 +1,11 @@
 # repoman: Utilities
-# Copyright 2007-2012 Gentoo Foundation
+# Copyright 2007-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 """This module contains utility functions to help repoman find ebuilds to
 scan"""
 
-from __future__ import print_function
+from __future__ import print_function, unicode_literals
 
 __all__ = [
        "detect_vcs_conflicts",
@@ -310,12 +310,12 @@ def format_qa_output(formatter, stats, fails, dofull, dofail, options, qawarning
        # we only want key value pairs where value > 0 
        for category, number in \
                filter(lambda myitem: myitem[1] > 0, iter(stats.items())):
-               formatter.add_literal_data(_unicode_decode("  " + category.ljust(30)))
+               formatter.add_literal_data("  " + category.ljust(30))
                if category in qawarnings:
                        formatter.push_style("WARN")
                else:
                        formatter.push_style("BAD")
-               formatter.add_literal_data(_unicode_decode(str(number)))
+               formatter.add_literal_data("%s" % number)
                formatter.pop_style()
                formatter.add_line_break()
                if not dofull:
@@ -326,7 +326,7 @@ def format_qa_output(formatter, stats, fails, dofull, dofail, options, qawarning
                        if not full and len(fails_list) > 12:
                                fails_list = fails_list[:12]
                        for failure in fails_list:
-                               formatter.add_literal_data(_unicode_decode("   " + failure))
+                               formatter.add_literal_data("   " + failure)
                                formatter.add_line_break()
 
 
@@ -775,7 +775,7 @@ def UpdateChangeLog(pkgdir, user, msg, skel_path, category, package,
                                line = line.replace('<PACKAGE_NAME>', package)
                                line = _update_copyright_year(year, line)
                                header_lines.append(line)
-                       header_lines.append(_unicode_decode('\n'))
+                       header_lines.append('\n')
                        clskel_file.close()
 
                # write new ChangeLog entry
@@ -785,10 +785,10 @@ def UpdateChangeLog(pkgdir, user, msg, skel_path, category, package,
                        if not fn.endswith('.ebuild'):
                                continue
                        ebuild = fn.split(os.sep)[-1][0:-7] 
-                       clnew_lines.append(_unicode_decode('*%s (%s)\n' % (ebuild, date)))
+                       clnew_lines.append('*%s (%s)\n' % (ebuild, date))
                        newebuild = True
                if newebuild:
-                       clnew_lines.append(_unicode_decode('\n'))
+                       clnew_lines.append('\n')
                trivial_files = ('ChangeLog', 'Manifest')
                display_new = ['+' + elem for elem in new
                        if elem not in trivial_files]
@@ -815,19 +815,19 @@ def UpdateChangeLog(pkgdir, user, msg, skel_path, category, package,
                for line in textwrap.wrap(mesg, 80, \
                                initial_indent='  ', subsequent_indent='  ', \
                                break_on_hyphens=False):
-                       clnew_lines.append(_unicode_decode('%s\n' % line))
+                       clnew_lines.append('%s\n' % line)
                for line in textwrap.wrap(msg, 80, \
                                initial_indent='  ', subsequent_indent='  '):
-                       clnew_lines.append(_unicode_decode('%s\n' % line))
+                       clnew_lines.append('%s\n' % line)
                # Don't append a trailing newline if the file is new.
                if clold_file is not None:
-                       clnew_lines.append(_unicode_decode('\n'))
+                       clnew_lines.append('\n')
 
                f = io.open(f, mode='w', encoding=_encodings['repo.content'],
                        errors='backslashreplace')
 
                for line in clnew_lines:
-                       f.write(_unicode_decode(line))
+                       f.write(line)
 
                # append stuff from old ChangeLog
                if clold_file is not None: