PHP Classes

File: test/python/

Recommend this page to a friend!
  Classes of Nikos M.  >  Dromeo PHP Router Library  >  test/python/  >  Download  
File: test/python/
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Dromeo PHP Router Library
Route HTTP requests to functions with URL patterns
Author: By
Last change: v.1.1.2 contd, JS: fix original match index computation issue
Date: 3 months ago
Size: 1,535 bytes


Class file image Download
#!/usr/bin/env python import os, sys import pprint 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 the engine (as a) module, probably you will want to place this in another dir/package Dromeo = import_module('Dromeo', os.path.join(os.path.dirname(__file__), '../../src/python/')) if not Dromeo: print ('Could not load the Dromeo Module') sys.exit(1) else: print ('Dromeo Module loaded succesfully') def defaultHandler(route, *args): print('Default Handler') print(pprint.pformat(route, 4)) router1 = Dromeo() router2 = Dromeo() router1.on([ { 'route':'/foo/{:user}/{:id}', 'name': 'route1', 'handler': defaultHandler } ]) router2.on([ { 'route':'/foo{/%ALPHA%-%ALPHA%:user(2)}', 'name': 'route2', 'handler': defaultHandler } ]) print('Dromeo.VERSION = ', Dromeo.VERSION) print("\n") router1.route('/FOO/USER/ID'.lower(), '*', True, '/FOO/USER/ID', 'ORIG') router1.route('/FOO/Foo/ID'.lower(), '*', True, '/FOO/Foo/ID', 'ORIG') router2.route('/FOO/USER-User'.lower(), '*', True, '/FOO/USER-User', 'ORIG') router2.route('/FOO/Foo-fOO'.lower(), '*', True, '/FOO/Foo-fOO', 'ORIG')