summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2015-08-12 13:44:11 +0200
committerJan Cholasta <jcholast@redhat.com>2015-09-01 11:42:01 +0200
commit8de13bd7dd76f5f5b23d6e4fb84be1a2f1dc5c5e (patch)
treeac6435b79d3e540e907bcc88e3b1c534c2945626 /ipalib
parentfb7943dab454f358316160b4baf99075603a162d (diff)
downloadfreeipa-8de13bd7dd76f5f5b23d6e4fb84be1a2f1dc5c5e.tar.gz
freeipa-8de13bd7dd76f5f5b23d6e4fb84be1a2f1dc5c5e.tar.xz
freeipa-8de13bd7dd76f5f5b23d6e4fb84be1a2f1dc5c5e.zip
Use the print function
In Python 3, `print` is no longer a statement. Call it as a function everywhere, and include the future import to remove the statement in Python 2 code as well. Reviewed-By: Christian Heimes <cheimes@redhat.com> Reviewed-By: Jan Cholasta <jcholast@redhat.com>
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/cli.py31
-rw-r--r--ipalib/messages.py5
-rw-r--r--ipalib/pkcs10.py10
-rw-r--r--ipalib/plugins/dns.py3
-rw-r--r--ipalib/plugins/internal.py5
-rw-r--r--ipalib/plugins/otptoken.py6
-rw-r--r--ipalib/plugins/vault.py4
-rw-r--r--ipalib/x509.py4
8 files changed, 40 insertions, 28 deletions
diff --git a/ipalib/cli.py b/ipalib/cli.py
index 36360008e..206664a88 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -20,6 +20,7 @@
"""
Functionality for Command Line Interface.
"""
+from __future__ import print_function
import textwrap
import sys
@@ -175,7 +176,7 @@ class textui(backend.Backend):
"""
Print exactly like ``print`` statement would.
"""
- print unicode(string)
+ print(unicode(string))
def print_line(self, text, width=None):
"""
@@ -197,7 +198,7 @@ class textui(backend.Backend):
width = self.get_tty_width()
if width is not None and width < len(text):
text = text[:width - 3] + '...'
- print unicode(text)
+ print(unicode(text))
def print_paragraph(self, text, width=None):
"""
@@ -226,7 +227,7 @@ class textui(backend.Backend):
if width is None:
width = self.get_tty_width()
for line in textwrap.wrap(text.strip(), width):
- print line
+ print(line)
def print_indented(self, text, indent=1):
"""
@@ -242,7 +243,7 @@ class textui(backend.Backend):
>>> ui.print_indented('No indentation.', indent=0)
No indentation.
"""
- print (CLI_TAB * indent + text)
+ print((CLI_TAB * indent + text))
def print_keyval(self, rows, indent=1):
"""
@@ -354,7 +355,7 @@ class textui(backend.Backend):
first = True
for entry in entries:
if not first:
- print ''
+ print('')
first = False
self.print_entry(entry, order, labels, flags, print_all, format, indent)
@@ -526,7 +527,7 @@ class textui(backend.Backend):
)
def print_error(self, text):
- print ' ** %s **' % unicode(text)
+ print(' ** %s **' % unicode(text))
def prompt_helper(self, prompt, label, prompt_func=input):
"""Prompt user for input
@@ -537,7 +538,7 @@ class textui(backend.Backend):
try:
return self.decode(prompt_func(self.encode(prompt)))
except (KeyboardInterrupt, EOFError):
- print
+ print()
raise PromptFailed(name=label)
def print_prompt_attribute_error(self, attribute, error):
@@ -804,7 +805,7 @@ class help(frontend.Local):
def _writer(self, outfile):
def writer(string=''):
try:
- print >> outfile, unicode(string)
+ print(unicode(string), file=outfile)
except IOError:
pass
return writer
@@ -882,7 +883,7 @@ class show_mappings(frontend.Command):
out.append((param.cli_name, param.param_spec))
mcl = max(mcl,len(param.cli_name))
for item in out:
- print to_cli(item[0]).ljust(mcl)+' : '+item[1]
+ print(to_cli(item[0]).ljust(mcl)+' : '+item[1])
class console(frontend.Command):
@@ -934,14 +935,14 @@ class show_api(frontend.Command):
first = True
for line in lines:
if line[0] == 0 and not first:
- print ''
+ print('')
if first:
first = False
- print '%s%s %r' % (
+ print('%s%s %r' % (
' ' * line[0],
line[1].ljust(ml),
line[2],
- )
+ ))
if len(lines) == 1:
s = '1 attribute shown.'
else:
@@ -1060,8 +1061,8 @@ class cli(backend.Executioner):
"""
if len(argv) == 0:
self.Command.help(outfile=sys.stderr)
- print >>sys.stderr
- print >>sys.stderr, 'Error: Command not specified'
+ print(file=sys.stderr)
+ print('Error: Command not specified', file=sys.stderr)
exit(2)
(key, argv) = (argv[0], argv[1:])
name = from_cli(key)
@@ -1342,7 +1343,7 @@ def run(api):
raise NotConfiguredError()
sys.exit(api.Backend.cli.run(argv))
except KeyboardInterrupt:
- print ''
+ print('')
api.log.info('operation aborted')
except PublicError as e:
error = e
diff --git a/ipalib/messages.py b/ipalib/messages.py
index 853979506..da8f740be 100644
--- a/ipalib/messages.py
+++ b/ipalib/messages.py
@@ -29,6 +29,7 @@ range, so that it does not clash with PublicError numbers.
Messages also have the 'type' argument, set to one of 'debug', 'info',
'warning', 'error'. This determines the severity of themessage.
"""
+from __future__ import print_function
from inspect import isclass
@@ -258,8 +259,8 @@ public_messages = tuple(sorted(
def print_report(label, classes):
for cls in classes:
- print '%d\t%s' % (cls.errno, cls.__name__)
- print '(%d %s)' % (len(classes), label)
+ print('%d\t%s' % (cls.errno, cls.__name__))
+ print('(%d %s)' % (len(classes), label))
if __name__ == '__main__':
print_report('public messages', public_messages)
diff --git a/ipalib/pkcs10.py b/ipalib/pkcs10.py
index 646708351..1a544b156 100644
--- a/ipalib/pkcs10.py
+++ b/ipalib/pkcs10.py
@@ -17,6 +17,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+from __future__ import print_function
+
import os
import sys
import base64
@@ -256,7 +258,7 @@ if __name__ == '__main__':
csrlines = sys.stdin.readlines()
csr = ''.join(csrlines)
- print load_certificate_request(csr)
- print get_subject(csr)
- print get_subjectaltname(csr)
- print get_friendlyname(csr)
+ print(load_certificate_request(csr))
+ print(get_subject(csr))
+ print(get_subjectaltname(csr))
+ print(get_friendlyname(csr))
diff --git a/ipalib/plugins/dns.py b/ipalib/plugins/dns.py
index 7885f029e..335b58afb 100644
--- a/ipalib/plugins/dns.py
+++ b/ipalib/plugins/dns.py
@@ -19,6 +19,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import absolute_import
+from __future__ import print_function
import netaddr
import time
@@ -4471,7 +4472,7 @@ class dnsforwardzone_add(DNSZoneBase_add):
result = super(dnsforwardzone_add, self).execute(*keys, **options)
self.obj._warning_fw_zone_is_not_effective(result, *keys, **options)
if options.get('idnsforwarders'):
- print result, keys, options
+ print(result, keys, options)
self.obj._warning_if_forwarders_do_not_work(
result, True, *keys, **options)
return result
diff --git a/ipalib/plugins/internal.py b/ipalib/plugins/internal.py
index e1904d2d3..7acd46bcd 100644
--- a/ipalib/plugins/internal.py
+++ b/ipalib/plugins/internal.py
@@ -22,6 +22,7 @@
"""
Plugins not accessible directly through the CLI, commands used internally
"""
+from __future__ import print_function
import json
@@ -138,7 +139,7 @@ class json_metadata(Command):
return retval
def output_for_cli(self, textui, result, *args, **options):
- print json.dumps(result, default=json_serialize)
+ print(json.dumps(result, default=json_serialize))
@register()
@@ -856,6 +857,6 @@ class i18n_messages(Command):
return dict(texts=json_serialize(self.messages))
def output_for_cli(self, textui, result, *args, **options):
- print json.dumps(result, default=json_serialize)
+ print(json.dumps(result, default=json_serialize))
diff --git a/ipalib/plugins/otptoken.py b/ipalib/plugins/otptoken.py
index 57de5b782..bb027eea0 100644
--- a/ipalib/plugins/otptoken.py
+++ b/ipalib/plugins/otptoken.py
@@ -17,6 +17,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+from __future__ import print_function
+
from ipalib.plugins.baseldap import DN, LDAPObject, LDAPAddMember, LDAPRemoveMember
from ipalib.plugins.baseldap import LDAPCreate, LDAPDelete, LDAPUpdate, LDAPSearch, LDAPRetrieve
from ipalib import api, Int, Str, Bool, DateTime, Flag, Bytes, IntEnum, StrEnum, Password, _, ngettext
@@ -352,12 +354,12 @@ class otptoken_add(LDAPCreate):
# Print QR code to terminal if specified
if uri and not options.get('no_qrcode', False):
- print "\n"
+ print("\n")
qr = qrcode.QRCode()
qr.add_data(uri)
qr.make()
qr.print_ascii(tty=True)
- print "\n"
+ print("\n")
return rv
diff --git a/ipalib/plugins/vault.py b/ipalib/plugins/vault.py
index ff6c22c64..a933198c4 100644
--- a/ipalib/plugins/vault.py
+++ b/ipalib/plugins/vault.py
@@ -17,6 +17,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+from __future__ import print_function
+
import base64
import getpass
import io
@@ -482,7 +484,7 @@ class vault(LDAPObject):
if password == password2:
return password
- print ' ** Passwords do not match! **'
+ print(' ** Passwords do not match! **')
def get_existing_password(self):
"""
diff --git a/ipalib/x509.py b/ipalib/x509.py
index 21c287feb..e48d3edf7 100644
--- a/ipalib/x509.py
+++ b/ipalib/x509.py
@@ -31,6 +31,8 @@
# nsscert: the certificate is an NSS Certificate object
# rawcert: the cert is in an unknown format
+from __future__ import print_function
+
import os
import sys
import base64
@@ -407,4 +409,4 @@ if __name__ == '__main__':
nsscert = load_certificate(cert)
- print nsscert
+ print(nsscert)