mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 01:52:56 +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,26 +1,25 @@
|
|||
from abc import ABCMeta, abstractmethod
|
||||
|
||||
import abc
|
||||
import argparse
|
||||
import Object
|
||||
|
||||
class Cmd(Object.Object): # export
|
||||
# compatible with Python 2 *and* 3
|
||||
ABC = abc.ABCMeta('ABC', (object,), {'__slots__': ()})
|
||||
|
||||
__metaclass__=ABCMeta
|
||||
class Cmd(ABC): # export
|
||||
|
||||
@abstractmethod
|
||||
@abc.abstractmethod
|
||||
def run(self, args):
|
||||
pass
|
||||
|
||||
def __init__(self, name, help):
|
||||
self.name = name
|
||||
self.name = name
|
||||
self.help = help
|
||||
|
||||
def _run(self, args):
|
||||
pass
|
||||
|
||||
def add_parser(self, parsers):
|
||||
r = parsers.add_parser(self.name, help=self.help,
|
||||
r = parsers.add_parser(self.name, help=self.help,
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||
r.set_defaults(func=self.run)
|
||||
r.set_defaults(func=self.run)
|
||||
return r
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue