summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Cristau <julien.cristau@logilab.fr>2014-11-28 14:23:50 +0100
committerJulien Cristau <julien.cristau@logilab.fr>2014-11-28 14:23:50 +0100
commit20fece159101728c243b660e69cefdb0dceddcb9 (patch)
treed7fb119ca4e331e9ef584f6c3d048ef1721a7890
parent6da786adbb6f7ad3e2d8bd31db6151778a08685b (diff)
downloadlogilab-common-20fece159101728c243b660e69cefdb0dceddcb9.tar.gz
Fix python3 syntax errors
Closes #278550
-rw-r--r--cli.py34
-rw-r--r--daemon.py2
-rw-r--r--dbf.py7
-rw-r--r--optparser.py8
-rw-r--r--test/data/module.py30
-rw-r--r--test/data/module2.py8
-rw-r--r--test/data/noendingnewline.py8
-rw-r--r--test/data/nonregr.py4
-rw-r--r--test/data/sub/momo.py4
-rw-r--r--urllib2ext.py4
10 files changed, 51 insertions, 58 deletions
diff --git a/cli.py b/cli.py
index 0ad4e4c..cdeef97 100644
--- a/cli.py
+++ b/cli.py
@@ -33,15 +33,17 @@ Example::
help_do_pionce = ("pionce", "pionce duree", _("met ton corps en veille"))
def do_pionce(self):
- print 'nap is good'
+ print('nap is good')
help_do_ronfle = ("ronfle", "ronfle volume", _("met les autres en veille"))
def do_ronfle(self):
- print 'fuuuuuuuuuuuu rhhhhhrhrhrrh'
+ print('fuuuuuuuuuuuu rhhhhhrhrhrrh')
cl = BookShell()
"""
+from __future__ import print_function
+
__docformat__ = "restructuredtext en"
from six.moves import builtins, input
@@ -66,7 +68,7 @@ def init_readline(complete_method, histfile=None):
import atexit
atexit.register(readline.write_history_file, histfile)
except:
- print 'readline is not available :-('
+ print('readline is not available :-(')
class Completer :
@@ -157,10 +159,10 @@ class CLIHelper:
return self.commands.keys()
def _print_help(self, cmd, syntax, explanation):
- print _('Command %s') % cmd
- print _('Syntax: %s') % syntax
- print '\t', explanation
- print
+ print(_('Command %s') % cmd)
+ print(_('Syntax: %s') % syntax)
+ print('\t', explanation)
+ print()
# predefined commands #####################################################
@@ -170,20 +172,20 @@ class CLIHelper:
if command in self._command_help:
self._print_help(*self._command_help[command])
elif command is None or command not in self._topics:
- print _("Use help <topic> or help <command>.")
- print _("Available topics are:")
+ print(_("Use help <topic> or help <command>."))
+ print(_("Available topics are:"))
topics = sorted(self._topics.keys())
for topic in topics:
- print '\t', topic
- print
- print _("Available commands are:")
+ print('\t', topic)
+ print()
+ print(_("Available commands are:"))
commands = self.commands.keys()
commands.sort()
for command in commands:
- print '\t', command[len(self.CMD_PREFIX):]
+ print('\t', command[len(self.CMD_PREFIX):])
else:
- print _('Available commands about %s:') % command
+ print(_('Available commands about %s:') % command)
print
for command_help_method in self._topics[command]:
try:
@@ -194,8 +196,8 @@ class CLIHelper:
except:
import traceback
traceback.print_exc()
- print 'ERROR in help method %s'% (
- command_help_method.__name__)
+ print('ERROR in help method %s'% (
+ command_help_method.__name__))
help_do_help = ("help", "help [topic|command]",
_("print help message for the given topic/command or \
diff --git a/daemon.py b/daemon.py
index 2f2caea..40319a4 100644
--- a/daemon.py
+++ b/daemon.py
@@ -51,7 +51,7 @@ def setugid(user):
os.environ['HOME'] = passwd.pw_dir
-def daemonize(pidfile=None, uid=None, umask=077):
+def daemonize(pidfile=None, uid=None, umask=0o77):
"""daemonize a Unix process. Set paranoid umask by default.
Return 1 in the original process, 2 in the first fork, and None for the
diff --git a/dbf.py b/dbf.py
index bb1b9e6..ab142b2 100644
--- a/dbf.py
+++ b/dbf.py
@@ -30,6 +30,7 @@ Usage:
http://www.physics.ox.ac.uk/users/santoso/Software.Repository.html
page says code is "available as is without any warranty or support".
"""
+from __future__ import print_function
import struct
import os, os.path
@@ -79,7 +80,7 @@ class Dbase:
def open(self, db_name):
filesize = os.path.getsize(db_name)
if filesize <= 68:
- raise IOError, 'The file is not large enough to be a dbf file'
+ raise IOError('The file is not large enough to be a dbf file')
self.fdb = open(db_name, 'rb')
@@ -152,7 +153,7 @@ class Dbase:
This function accept record number from 0 to N-1
"""
if rec_no < 0 or rec_no > self.num_records:
- raise Exception, 'Unable to extract data outside the range'
+ raise Exception('Unable to extract data outside the range')
offset = self.header['Record Size'] * rec_no
data = self.db_data[offset:offset+self.row_len]
@@ -227,4 +228,4 @@ def readDbf(filename):
if __name__=='__main__':
rec = readDbf('dbf/sptable.dbf')
for line in rec:
- print '%s %s' % (line['GENUS'].strip(), line['SPECIES'].strip())
+ print('%s %s' % (line['GENUS'].strip(), line['SPECIES'].strip()))
diff --git a/optparser.py b/optparser.py
index 0263dab..aa17750 100644
--- a/optparser.py
+++ b/optparser.py
@@ -29,6 +29,8 @@ Example:
With mymod.build that defines two functions run and add_options
"""
+from __future__ import print_function
+
__docformat__ = "restructuredtext en"
from warnings import warn
@@ -55,9 +57,9 @@ class OptionParser(optparse.OptionParser):
def print_main_help(self):
optparse.OptionParser.print_help(self)
- print '\ncommands:'
+ print('\ncommands:')
for cmdname, (_, help) in self._commands.items():
- print '% 10s - %s' % (cmdname, help)
+ print('% 10s - %s' % (cmdname, help))
def parse_command(self, args):
if len(args) == 0:
@@ -78,7 +80,7 @@ class OptionParser(optparse.OptionParser):
# optparse inserts self.description between usage and options help
self.description = help
if isinstance(mod_or_f, str):
- exec 'from %s import run, add_options' % mod_or_f
+ exec('from %s import run, add_options' % mod_or_f)
else:
run, add_options = mod_or_f
add_options(self)
diff --git a/test/data/module.py b/test/data/module.py
index 62de658..493e676 100644
--- a/test/data/module.py
+++ b/test/data/module.py
@@ -1,7 +1,7 @@
# -*- coding: Latin-1 -*-
"""test module for astng
"""
-
+from __future__ import print_function
from logilab.common import modutils, Execute as spawn
from logilab.common.astutils import *
@@ -21,7 +21,7 @@ def global_access(key, val):
else:
break
else:
- print '!!!'
+ print('!!!')
class YO:
"""hehe"""
@@ -36,7 +36,7 @@ class YO:
except:
raise
-#print '*****>',YO.__dict__
+#print('*****>',YO.__dict__)
class YOUPI(YO):
class_attr = None
@@ -51,9 +51,9 @@ class YOUPI(YO):
local = None
autre = [a for a, b in MY_DICT if b]
if b in autre:
- print 'yo',
+ print('yo', end=' ')
elif a in autre:
- print 'hehe'
+ print('hehe')
global_access(local, val=autre)
finally:
return local
@@ -65,23 +65,5 @@ class YOUPI(YO):
def class_method(cls):
"""class method test"""
- exec a in b
+ exec(a, b)
class_method = classmethod(class_method)
-
-
-def nested_args(a, (b, c, d)):
- """nested arguments test"""
- print a, b, c, d
- while 1:
- if a:
- break
- a += +1
- else:
- b += -2
- if c:
- d = a and b or c
- else:
- c = a and b or d
- map(lambda x, y: (y, x), a)
-
-redirect = nested_args
diff --git a/test/data/module2.py b/test/data/module2.py
index 78976c4..51509f3 100644
--- a/test/data/module2.py
+++ b/test/data/module2.py
@@ -37,14 +37,14 @@ del YO.member
del YO
[SYN1, SYN2] = Concrete0, Concrete1
-assert `1`
+assert '1'
b = 1 | 2 & 3 ^ 8
-exec 'c = 3'
-exec 'c = 3' in {}, {}
+exec('c = 3')
+exec('c = 3', {}, {})
def raise_string(a=2, *args, **kwargs):
raise 'pas glop'
- raise Exception, 'yo'
+ raise Exception('yo')
yield 'coucou'
a = b + 2
diff --git a/test/data/noendingnewline.py b/test/data/noendingnewline.py
index 703b124..110f902 100644
--- a/test/data/noendingnewline.py
+++ b/test/data/noendingnewline.py
@@ -1,4 +1,4 @@
-
+from __future__ import print_function
import unittest
@@ -20,7 +20,7 @@ class TestCase(unittest.TestCase):
def xxx(self):
if False:
pass
- print 'a'
+ print('a')
if False:
pass
@@ -28,9 +28,9 @@ class TestCase(unittest.TestCase):
if False:
pass
- print 'rara'
+ print('rara')
if __name__ == '__main__':
- print 'test2'
+ print('test2')
unittest.main()
diff --git a/test/data/nonregr.py b/test/data/nonregr.py
index 24ecc7c..a4b5ef7 100644
--- a/test/data/nonregr.py
+++ b/test/data/nonregr.py
@@ -1,3 +1,5 @@
+from __future__ import print_function
+
try:
enumerate = enumerate
except NameError:
@@ -11,4 +13,4 @@ except NameError:
def toto(value):
for k, v in value:
- print v.get('yo')
+ print(v.get('yo'))
diff --git a/test/data/sub/momo.py b/test/data/sub/momo.py
index e2600f5..746b5d0 100644
--- a/test/data/sub/momo.py
+++ b/test/data/sub/momo.py
@@ -1 +1,3 @@
-print 'yo'
+from __future__ import print_function
+
+print('yo')
diff --git a/urllib2ext.py b/urllib2ext.py
index 3e7a36d..339aec0 100644
--- a/urllib2ext.py
+++ b/urllib2ext.py
@@ -1,3 +1,5 @@
+from __future__ import print_function
+
import logging
import urllib2
@@ -84,4 +86,4 @@ if __name__ == '__main__':
# test with url sys.argv[1]
h = HTTPGssapiAuthHandler()
response = urllib2.build_opener(h, ch).open(sys.argv[1])
- print '\nresponse: %s\n--------------\n' % response.code, response.info()
+ print('\nresponse: %s\n--------------\n' % response.code, response.info())