from dispatch import Dispatcher, Message def print_message(message): print(message) print(message.langauge) if message.reqex: print message.reqex.groups() numbers = [18182124554] def check_message(message): if message.number in numbers: return True def fall_through(message): print(message) assert 0 dispatcher = Dispatcher() dispatcher.catchAll(fall_through) dispatcher.addMatcher(check_message,print_message) dispatcher.addMatcher(r'^(bal).(\w+)',print_message) dispatcher.addMatcher(r'^(solde).(\w+)',print_message,langauge="fr") dispatcher.addMatcher(r'^(add).(\w+).(\d+)',print_message) if __name__ == '__main__': dispatcher.matchMessage(Message(text="bal.asd123",number=18182124551))
""" """ from pyramid_beaker import session_factory_from_settings from pyramid.authentication import AuthTktAuthenticationPolicy from pyramid.authorization import ACLAuthorizationPolicy from pyramid.exceptions import Forbidden from pyramid.exceptions import NotFound import pyramid_handlers from dispatch import Dispatcher from gateway.messaging import findMeter dispatcher = Dispatcher() dispatcher.addMatcher(findMeter, 'gateway.messaging.parse_meter_message') dispatcher.addMatcher(r'^\(job=gateway-ping', 'gateway.messaging.gateway_ping') # Allow consumers to check their balance dispatcher.addMatcher(r'^(bal).(\w+)', 'gateway.consumer.get_balance', language='en') dispatcher.addMatcher(r'^(solde).(\w+)', 'gateway.consumer.get_balance', language='fr') dispatcher.addMatcher(r'^(2).(\w+)', 'gateway.consumer.get_balance', language='fr') # Allow consumers to add credit to their account dispatcher.addMatcher(r'^(add).(\w+).(\d+)', 'gateway.consumer.add_credit', language='en') dispatcher.addMatcher(r'^(recharge).(\w+).(\d+)', 'gateway.consumer.add_credit', language='fr') dispatcher.addMatcher(r'^(9).(\w+).(\w+)',