Пример #1
0
from ReStruct		import restruct
from WHIutils		import logging

import simplejson	as json

log				= logging.getLogger('ChaosRouter')
log.setLevel(logging.DEBUG)

class ValidationLib(object):
    def is_digit(self, value, **kwargs):
        return value.isdigit()

    def is_number(self, value, **kwargs):
        try:
            float(value)
            return True
        except:
            return False

    def not_empty(self, value, **kwargs):
        return not not value

validationlib		= ValidationLib()

class MethodLib(object):
    pass
methodlib		= MethodLib()

class ChaosRouter(object):
Пример #2
0
from chaosrouter	import ChaosRouter
from WHIutils		import logging, Routing
import simplejson	as json
import sqlite3

log				= logging.getLogger('ChaosRouter Test')
log.setLevel(logging.DEBUG)

def row_factory(cursor, row):
    d = {}
    for idx, col in enumerate(cursor.description):
        d[col[0]]= row[idx]
    return d

conn			= sqlite3.connect( "testing.sql" )
conn.row_factory	= row_factory

cursor			= conn.cursor()
cursor.execute("""
SELECT name FROM sqlite_master WHERE type='table';
""")
print json.dumps(cursor.fetchall(), indent=4)


router			= ChaosRouter('./routes.json', cursor=cursor)
endpoint		= router.route('/get/people')

result			= endpoint.execute()
print "tested."
print json.dumps(result, indent=4)