import os, sys
DIR = os.path.dirname(os.path.abspath(__file__))
def import_module(name, path):
#import imp
#try:
# mod_fp, mod_path, mod_desc = imp.find_module(name, [path])
# mod = getattr( imp.load_module(name, mod_fp, mod_path, mod_desc), name )
#except ImportError as exc:
# mod = None
# sys.stderr.write("Error: failed to import module ({})".format(exc))
#finally:
# if mod_fp: mod_fp.close()
#return mod
import importlib.util, sys
spec = importlib.util.spec_from_file_location(name, path+name+'.py')
mod = importlib.util.module_from_spec(spec)
sys.modules[name] = mod
spec.loader.exec_module(mod)
return getattr(mod, name)
# import the Paginator.py (as a) module, probably you will want to place this in another dir/package
Paginator = import_module('Paginator', os.path.join(DIR, '../src/py/'))
if not Paginator:
print ('Could not load the Paginator Module')
sys.exit(1)
else:
pass
def echo(s):
print(str(s) + "\n")
echo('Paginator.VERSION = ' + Paginator.VERSION + "\n")
p1 = Paginator(100, 10)
p2 = Paginator(1000, 10, 3).option('prev-text', 'Prev').option('next-text', 'Next').option('placeholder', '{page}').option('url-pattern', '/category/{page}')
p3 = Paginator(100, 10, 2)
echo(p1)
echo(p2)
echo(p3)
echo(p1.option('type', 'selectbox'))
echo(p2.option('type', 'selectbox'))
echo(p3.option('type', 'selectbox'))
|