From 1f47f7b6b29cd1229264edf75194652824d94705 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sat, 30 Aug 2014 20:15:19 +0200 Subject: refactor protocol handling, fix #332 --- libmproxy/protocol/handle.py | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'libmproxy/protocol/handle.py') diff --git a/libmproxy/protocol/handle.py b/libmproxy/protocol/handle.py index a238b349..100c7368 100644 --- a/libmproxy/protocol/handle.py +++ b/libmproxy/protocol/handle.py @@ -6,21 +6,12 @@ protocols = { 'tcp': dict(handler=tcp.TCPHandler) } - -def _handler(conntype, connection_handler): - if conntype in protocols: - return protocols[conntype]["handler"](connection_handler) - - raise NotImplementedError # pragma: nocover - - -def handle_messages(conntype, connection_handler): - return _handler(conntype, connection_handler).handle_messages() - - -def handle_error(conntype, connection_handler, error): - return _handler(conntype, connection_handler).handle_error(error) - - -def handle_server_reconnect(conntype, connection_handler, state): - return _handler(conntype, connection_handler).handle_server_reconnect(state) \ No newline at end of file +def protocol_handler(protocol): + """ + @type protocol: str + @returns: libmproxy.protocol.primitives.ProtocolHandler + """ + if protocol in protocols: + return protocols[protocol]["handler"] + + raise NotImplementedError("Unknown Protocol: %s" % protocol) # pragma: nocover \ No newline at end of file -- cgit v1.2.3