Files
deb-python-wsme/wsme/protocols/__init__.py
Christophe de Vienne a06989e1a5 Split the controller module into api, protocols and root.
--HG--
rename : wsme/rest.py => wsme/protocols/rest.py
rename : wsme/tests/test_controller.py => wsme/tests/test_api.py
2011-10-28 11:59:30 +02:00

38 lines
914 B
Python

import weakref
import pkg_resources
__all__ = [
'CallContext',
'register_protocol', 'getprotocol',
]
registered_protocols = {}
class CallContext(object):
def __init__(self, request):
self.request = weakref.proxy(request)
self.path = None
self.func = None
self.funcdef = None
def register_protocol(protocol):
registered_protocols[protocol.name] = protocol
def getprotocol(name, **options):
protocol_class = registered_protocols.get(name)
if protocol_class is None:
for entry_point in pkg_resources.iter_entry_points(
'wsme.protocols', name):
if entry_point.name == name:
protocol_class = entry_point.load()
if protocol_class is None:
raise ValueError("Cannot find protocol '%s'" % name)
registered_protocols[name] = protocol_class
return protocol_class(**options)