1 #!/usr/bin/env python 2 # encoding: utf-8 3 4 import logging, urlparse 5 6 class ReqHBase(object): 7 @classmethod 8 def dispatch(cls, req): 9 result = -1 10 targetf = 'do_%s' % urlparse.urlsplit(req)[2].split('/')[-1] 11 12 try: handler = getattr(cls, targetf) 13 except AttributeError: 14 logging.error("no '%s' function in '%s'" % (targetf, str(cls))) 15 else: # is it a function? 16 if callable(handler): 17 try: result = handler(req) 18 except Exception, e: logging.exception(str(e)) 19 else: 20 logging.error("'%s' not callable in '%s'" % (targetf, str(cls))) 21 return(result)