aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2020-07-16 14:16:27 +0200
committerMichał Górny <mgorny@gentoo.org>2020-07-16 20:04:43 +0200
commit8aaf817db51f0369095b0f7d93cdbecdfc32c869 (patch)
tree93aba669b4382810b7f6a00de506ccce69f283e9 /lib/_emerge
parentBinTestCase: export PORTAGE_PYTHON (diff)
downloadportage-8aaf817db51f0369095b0f7d93cdbecdfc32c869.tar.gz
portage-8aaf817db51f0369095b0f7d93cdbecdfc32c869.tar.bz2
portage-8aaf817db51f0369095b0f7d93cdbecdfc32c869.zip
Eliminate the most of explicit py3 conditionals
Eliminate the most of py2/py3 conditions in the code. Leave a few where the relevant code is unclear, they will be addressed later. Reviewed-by: Zac Medico <zmedico@gentoo.org> Closes: https://github.com/gentoo/portage/pull/574 Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'lib/_emerge')
-rw-r--r--lib/_emerge/DependencyArg.py10
-rw-r--r--lib/_emerge/JobStatusDisplay.py4
-rw-r--r--lib/_emerge/Package.py8
-rw-r--r--lib/_emerge/PackageVirtualDbapi.py3
-rw-r--r--lib/_emerge/SequentialTaskQueue.py3
-rw-r--r--lib/_emerge/TaskSequence.py3
-rw-r--r--lib/_emerge/UseFlagDisplay.py8
-rw-r--r--lib/_emerge/UserQuery.py17
-rw-r--r--lib/_emerge/actions.py2
-rw-r--r--lib/_emerge/resolver/DbapiProvidesIndex.py3
-rw-r--r--lib/_emerge/resolver/output_helpers.py16
-rw-r--r--lib/_emerge/resolver/slot_collision.py8
12 files changed, 7 insertions, 78 deletions
diff --git a/lib/_emerge/DependencyArg.py b/lib/_emerge/DependencyArg.py
index 87f255f10..a997f0f90 100644
--- a/lib/_emerge/DependencyArg.py
+++ b/lib/_emerge/DependencyArg.py
@@ -31,14 +31,4 @@ class DependencyArg(object):
return hash((self.arg, self.root_config.root))
def __str__(self):
- # Use unicode_literals format string for python-2.x safety,
- # ensuring that self.arg.__unicode__() is used
- # when necessary.
return "%s" % (self.arg,)
-
- if sys.hexversion < 0x3000000:
-
- __unicode__ = __str__
-
- def __str__(self):
- return _unicode_encode(self.__unicode__(), encoding=_encodings['content'])
diff --git a/lib/_emerge/JobStatusDisplay.py b/lib/_emerge/JobStatusDisplay.py
index b3160a4cc..2ef3f8465 100644
--- a/lib/_emerge/JobStatusDisplay.py
+++ b/lib/_emerge/JobStatusDisplay.py
@@ -83,9 +83,7 @@ class JobStatusDisplay(object):
# avoid potential UnicodeEncodeError
s = _unicode_encode(s,
encoding=_encodings['stdio'], errors='backslashreplace')
- out = self.out
- if sys.hexversion >= 0x3000000:
- out = out.buffer
+ out = self.out.buffer
out.write(s)
out.flush()
diff --git a/lib/_emerge/Package.py b/lib/_emerge/Package.py
index 76f4066bb..1fb0bb20b 100644
--- a/lib/_emerge/Package.py
+++ b/lib/_emerge/Package.py
@@ -528,14 +528,6 @@ class Package(Task):
s += ")"
return s
- if sys.hexversion < 0x3000000:
-
- __unicode__ = __str__
-
- def __str__(self):
- return _unicode_encode(self.__unicode__(),
- encoding=_encodings['content'])
-
class _use_class(object):
__slots__ = ("enabled", "_expand", "_expand_hidden",
diff --git a/lib/_emerge/PackageVirtualDbapi.py b/lib/_emerge/PackageVirtualDbapi.py
index 26293dd98..957eab594 100644
--- a/lib/_emerge/PackageVirtualDbapi.py
+++ b/lib/_emerge/PackageVirtualDbapi.py
@@ -41,9 +41,6 @@ class PackageVirtualDbapi(dbapi):
def __bool__(self):
return bool(self._cpv_map)
- if sys.hexversion < 0x3000000:
- __nonzero__ = __bool__
-
def __iter__(self):
return iter(self._cpv_map.values())
diff --git a/lib/_emerge/SequentialTaskQueue.py b/lib/_emerge/SequentialTaskQueue.py
index d2551b1c6..1cadbca41 100644
--- a/lib/_emerge/SequentialTaskQueue.py
+++ b/lib/_emerge/SequentialTaskQueue.py
@@ -85,8 +85,5 @@ class SequentialTaskQueue(SlotObject):
def __bool__(self):
return bool(self._task_queue or self.running_tasks)
- if sys.hexversion < 0x3000000:
- __nonzero__ = __bool__
-
def __len__(self):
return len(self._task_queue) + len(self.running_tasks)
diff --git a/lib/_emerge/TaskSequence.py b/lib/_emerge/TaskSequence.py
index 1f2ba94c2..2fd349810 100644
--- a/lib/_emerge/TaskSequence.py
+++ b/lib/_emerge/TaskSequence.py
@@ -54,8 +54,5 @@ class TaskSequence(CompositeTask):
def __bool__(self):
return bool(self._task_queue)
- if sys.hexversion < 0x3000000:
- __nonzero__ = __bool__
-
def __len__(self):
return len(self._task_queue)
diff --git a/lib/_emerge/UseFlagDisplay.py b/lib/_emerge/UseFlagDisplay.py
index c16e7ba0d..6f6e27fb8 100644
--- a/lib/_emerge/UseFlagDisplay.py
+++ b/lib/_emerge/UseFlagDisplay.py
@@ -30,14 +30,6 @@ class UseFlagDisplay(object):
s = '(%s)' % s
return s
- if sys.hexversion < 0x3000000:
-
- __unicode__ = __str__
-
- def __str__(self):
- return _unicode_encode(self.__unicode__(),
- encoding=_encodings['content'])
-
def _cmp_combined(a, b):
"""
Sort by name, combining enabled and disabled flags.
diff --git a/lib/_emerge/UserQuery.py b/lib/_emerge/UserQuery.py
index faa32cf50..a9b3a4865 100644
--- a/lib/_emerge/UserQuery.py
+++ b/lib/_emerge/UserQuery.py
@@ -54,17 +54,12 @@ class UserQuery(object):
print(bold(prompt), end=' ')
try:
while True:
- if sys.hexversion >= 0x3000000:
- try:
- response = input("[%s] " %
- "/".join([colours[i](responses[i])
- for i in range(len(responses))]))
- except UnicodeDecodeError as e:
- response = _unicode_decode(e.object).rstrip('\n')
- else:
- response=raw_input("["+"/".join([colours[i](responses[i])
- for i in range(len(responses))])+"] ")
- response = _unicode_decode(response)
+ try:
+ response = input("[%s] " %
+ "/".join([colours[i](responses[i])
+ for i in range(len(responses))]))
+ except UnicodeDecodeError as e:
+ response = _unicode_decode(e.object).rstrip('\n')
if response or not enter_invalid:
for key in responses:
# An empty response will match the
diff --git a/lib/_emerge/actions.py b/lib/_emerge/actions.py
index dc54372a3..e717bc828 100644
--- a/lib/_emerge/actions.py
+++ b/lib/_emerge/actions.py
@@ -3194,8 +3194,6 @@ def run_action(emerge_config):
if not "--pretend" in emerge_config.opts:
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.
diff --git a/lib/_emerge/resolver/DbapiProvidesIndex.py b/lib/_emerge/resolver/DbapiProvidesIndex.py
index 1650edd4e..9d122a7e5 100644
--- a/lib/_emerge/resolver/DbapiProvidesIndex.py
+++ b/lib/_emerge/resolver/DbapiProvidesIndex.py
@@ -73,9 +73,6 @@ class PackageDbapiProvidesIndex(DbapiProvidesIndex):
def __bool__(self):
return bool(self._db)
- if sys.hexversion < 0x3000000:
- __nonzero__ = __bool__
-
def __iter__(self):
return iter(self._db)
diff --git a/lib/_emerge/resolver/output_helpers.py b/lib/_emerge/resolver/output_helpers.py
index 4279590dc..0616bb6ac 100644
--- a/lib/_emerge/resolver/output_helpers.py
+++ b/lib/_emerge/resolver/output_helpers.py
@@ -76,14 +76,6 @@ class _RepoDisplay(object):
" indicates that the source repository could not be determined\n")
return "".join(output)
- if sys.hexversion < 0x3000000:
-
- __unicode__ = __str__
-
- def __str__(self):
- return _unicode_encode(self.__unicode__(),
- encoding=_encodings['content'])
-
class _PackageCounters(object):
@@ -677,11 +669,3 @@ class PkgAttrDisplay(SlotObject):
output.append(self.mask)
return "".join(output)
-
- if sys.hexversion < 0x3000000:
-
- __unicode__ = __str__
-
- def __str__(self):
- return _unicode_encode(self.__unicode__(),
- encoding=_encodings['content'])
diff --git a/lib/_emerge/resolver/slot_collision.py b/lib/_emerge/resolver/slot_collision.py
index 0bed08785..e77433fb8 100644
--- a/lib/_emerge/resolver/slot_collision.py
+++ b/lib/_emerge/resolver/slot_collision.py
@@ -1130,14 +1130,6 @@ class _solution_candidate_generator(object):
def __str__(self):
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.