mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 09:53:32 +01:00
Fix multiple Python 3 compatibility issues
Changes in Python 3 that made the code choke: o basestring is merged into str o print() needs parentesis o Class inheritance syntax changed o Abstract baseclass (ABCMeta) syntax changed o map.iteritems() is replaced by map.items() o Inconsistent use of tabs and spaces are no longer tolerated Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
6eaad195a8
commit
6dd594d47b
8 changed files with 44 additions and 32 deletions
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/python2
|
||||
#!/usr/bin/python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import print_function
|
||||
|
|
@ -93,9 +93,9 @@ class Cmd(jwutils.Cmd):
|
|||
|
||||
@staticmethod
|
||||
def _replace_cpp_symbol(data, src, target, context=None):
|
||||
stopc = "^a-zA-Z0-9_"
|
||||
stopa = "(^|[" + stopc + "])"
|
||||
stope = "([" + stopc + "]|$)"
|
||||
stopc = "^a-zA-Z0-9_"
|
||||
stopa = "(^|[" + stopc + "])"
|
||||
stope = "([" + stopc + "]|$)"
|
||||
f = stopa + src + stope
|
||||
t = "\\1" + target + "\\2"
|
||||
done = False
|
||||
|
|
@ -125,7 +125,7 @@ class Cmd(jwutils.Cmd):
|
|||
with open(path) as infile, open(tmp, 'w') as outfile:
|
||||
data = infile.read()
|
||||
#slog(NOTICE, "-- opened", path)
|
||||
for src, target in replacements.iteritems():
|
||||
for src, target in replacements.items():
|
||||
#slog(NOTICE, "replacing", src, "to", target)
|
||||
odata = data
|
||||
#data = data.replace(src, target)
|
||||
|
|
@ -148,7 +148,7 @@ class Cmd(jwutils.Cmd):
|
|||
if func is None:
|
||||
func = self._replace_pattern
|
||||
for line in iter(string.splitlines()):
|
||||
for src, target in replacements.iteritems():
|
||||
for src, target in replacements.items():
|
||||
line = func(line, src, target)
|
||||
r = r + line
|
||||
return r
|
||||
|
|
@ -223,12 +223,12 @@ class Cmd(jwutils.Cmd):
|
|||
|
||||
def _init(self, args):
|
||||
if args.replace_patterns_from is not None:
|
||||
self.replacements = dict()
|
||||
self.replacements = dict()
|
||||
with open(args.replace_patterns_from) as infile:
|
||||
for line in infile:
|
||||
s = re.split('->', line)
|
||||
self.replacements[s[0]] = s[1].rstrip('\n')
|
||||
#slog(NOTICE, "replacements =", self.replacements)
|
||||
#slog(NOTICE, "replacements =", self.replacements)
|
||||
|
||||
# overriding
|
||||
def run(self, args):
|
||||
|
|
@ -286,7 +286,7 @@ class CmdReplaceCppSymbols(Cmd):
|
|||
def _init(self, args):
|
||||
r = super(CmdReplaceCppSymbols, self)._init(args)
|
||||
self.file_truncs = set()
|
||||
if self.replacements is not None:
|
||||
if self.replacements is not None:
|
||||
for patt in self.replacements:
|
||||
self.file_truncs.add(patt.lower())
|
||||
return r
|
||||
|
|
@ -303,7 +303,7 @@ class CmdReplaceCppSymbols(Cmd):
|
|||
continue
|
||||
if not trunc.lower() in self.file_truncs:
|
||||
continue
|
||||
for patt, repl in self.replacements.iteritems():
|
||||
for patt, repl in self.replacements.items():
|
||||
if patt == trunc:
|
||||
path = dir + '/' + name
|
||||
new_path = dir + '/' + repl + ext
|
||||
|
|
@ -393,7 +393,7 @@ class CmdAddCppNamespace(Cmd):
|
|||
def _init(self, args):
|
||||
r = super(CmdAddCppNamespace, self)._init(args)
|
||||
self.file_truncs = set()
|
||||
if self.replacements is not None:
|
||||
if self.replacements is not None:
|
||||
for patt in self.replacements:
|
||||
self.file_truncs.add(patt.lower())
|
||||
return r
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue