From 5cc72902e068be15b1fadc53aa293084469cac43 Mon Sep 17 00:00:00 2001 From: Michal Vyskocil Date: Tue, 9 Apr 2013 13:02:24 +0200 Subject: [PATCH] python3 compatibility: raw_input raw_input has been removed and equals to input in py3. Unfortunatelly no __future__ statement exists for that. Ensure all modules uses osc.core.raw_input except osc.cmdln, where there is NameError way implemented. --- osc/build.py | 2 +- osc/cmdln.py | 6 +++++- osc/core.py | 6 ++++-- osc/oscssl.py | 2 ++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/osc/build.py b/osc/build.py index 176e3926..dbb251fe 100644 --- a/osc/build.py +++ b/osc/build.py @@ -17,7 +17,7 @@ except ImportError: from tempfile import NamedTemporaryFile, mkdtemp from osc.fetch import * from osc.core import get_buildinfo, store_read_apiurl, store_read_project, store_read_package, meta_exists, quote_plus, get_buildconfig, is_package_dir -from osc.core import get_binarylist, get_binary_file, run_external +from osc.core import get_binarylist, get_binary_file, run_external, raw_input from osc.util import rpmquery, debquery, archquery import osc.conf from . import oscerr diff --git a/osc/cmdln.py b/osc/cmdln.py index 48708041..fb4c415d 100644 --- a/osc/cmdln.py +++ b/osc/cmdln.py @@ -405,7 +405,11 @@ class RawCmdln(cmd.Cmd): else: if self.use_rawinput: try: - line = raw_input(self._prompt_str) + try: + #python 2.x + line = raw_input(self._prompt_str) + except NameError: + line = input(self._prompt_str) except EOFError: line = 'EOF' else: diff --git a/osc/core.py b/osc/core.py index c0a4974d..303ed32f 100644 --- a/osc/core.py +++ b/osc/core.py @@ -6554,12 +6554,14 @@ def get_user_projpkgs(apiurl, user, role=None, exclude_projects=[], proj=True, p def raw_input(*args): try: import builtins + func = builtins.input except ImportError: #python 2.7 - import __builtin__ as builtins + import __builtin__ + func = __builtin__.raw_input try: - return builtins.raw_input(*args) + return func(*args) except EOFError: # interpret ctrl-d as user abort raise oscerr.UserAbort() diff --git a/osc/oscssl.py b/osc/oscssl.py index 3b5ec46a..5a1983e7 100644 --- a/osc/oscssl.py +++ b/osc/oscssl.py @@ -21,6 +21,8 @@ except ImportError: from urlparse import urlparse from httplib import HTTPSConnection +from .core import raw_input + class TrustedCertStore: _tmptrusted = {}