Convert to python 3

This commit is contained in:
Itai Shirav 2020-02-07 13:37:11 +02:00
parent acccfbcaad
commit 17b5c629ac

View File

@ -52,8 +52,6 @@ def get_method_sig(method):
default_arg = _get_default_arg(argspec.args, argspec.defaults, arg_index) default_arg = _get_default_arg(argspec.args, argspec.defaults, arg_index)
if default_arg.has_default: if default_arg.has_default:
val = default_arg.default_value val = default_arg.default_value
if isinstance(val, basestring):
val = '"' + val + '"'
args.append("%s=%s" % (arg, val)) args.append("%s=%s" % (arg, val))
else: else:
args.append(arg) args.append(arg)
@ -73,45 +71,45 @@ def docstring(obj):
indentation = min(len(line) - len(line.lstrip()) for line in lines if line.strip()) indentation = min(len(line) - len(line.lstrip()) for line in lines if line.strip())
# Output the lines without the indentation # Output the lines without the indentation
for line in lines: for line in lines:
print line[indentation:] print(line[indentation:])
print print()
def class_doc(cls, list_methods=True): def class_doc(cls, list_methods=True):
bases = ', '.join([b.__name__ for b in cls.__bases__]) bases = ', '.join([b.__name__ for b in cls.__bases__])
print '###', cls.__name__ print('###', cls.__name__)
print print()
if bases != 'object': if bases != 'object':
print 'Extends', bases print('Extends', bases)
print print()
docstring(cls) docstring(cls)
for name, method in inspect.getmembers(cls, inspect.ismethod): for name, method in inspect.getmembers(cls, lambda m: inspect.ismethod(m) or inspect.isfunction(m)):
if name == '__init__': if name == '__init__':
# Initializer # Initializer
print '####', get_method_sig(method).replace(name, cls.__name__) print('####', get_method_sig(method).replace(name, cls.__name__))
elif name[0] == '_': elif name[0] == '_':
# Private method # Private method
continue continue
elif method.__self__ == cls: elif hasattr(method, '__self__') and method.__self__ == cls:
# Class method # Class method
if not list_methods: if not list_methods:
continue continue
print '#### %s.%s' % (cls.__name__, get_method_sig(method)) print('#### %s.%s' % (cls.__name__, get_method_sig(method)))
else: else:
# Regular method # Regular method
if not list_methods: if not list_methods:
continue continue
print '####', get_method_sig(method) print('####', get_method_sig(method))
print print()
docstring(method) docstring(method)
print print()
def module_doc(classes, list_methods=True): def module_doc(classes, list_methods=True):
mdl = classes[0].__module__ mdl = classes[0].__module__
print mdl print(mdl)
print '-' * len(mdl) print('-' * len(mdl))
print print()
for cls in classes: for cls in classes:
class_doc(cls, list_methods) class_doc(cls, list_methods)
@ -128,9 +126,9 @@ if __name__ == '__main__':
from infi.clickhouse_orm import models from infi.clickhouse_orm import models
from infi.clickhouse_orm import query from infi.clickhouse_orm import query
print 'Class Reference' print('Class Reference')
print '===============' print('===============')
print print()
module_doc([database.Database, database.DatabaseException]) module_doc([database.Database, database.DatabaseException])
module_doc([models.Model, models.BufferModel, models.DistributedModel]) module_doc([models.Model, models.BufferModel, models.DistributedModel])
module_doc(sorted([fields.Field] + all_subclasses(fields.Field), key=lambda x: x.__name__), False) module_doc(sorted([fields.Field] + all_subclasses(fields.Field), key=lambda x: x.__name__), False)