THRIFT-4780: finish the server implementation of multi in python server
- Add default processor handling to python multi
diff --git a/lib/py/src/TMultiplexedProcessor.py b/lib/py/src/TMultiplexedProcessor.py
index 8d929ac..bd10d9b 100644
--- a/lib/py/src/TMultiplexedProcessor.py
+++ b/lib/py/src/TMultiplexedProcessor.py
@@ -24,8 +24,18 @@
class TMultiplexedProcessor(TProcessor):
def __init__(self):
+ self.defaultProcessor = None
self.services = {}
+ def registerDefault(self, processor):
+ """
+ If a non-multiplexed processor connects to the server and wants to
+ communicate, use the given processor to handle it. This mechanism
+ allows servers to upgrade from non-multiplexed to multiplexed in a
+ backwards-compatible way and still handle old clients.
+ """
+ self.defaultProcessor = processor
+
def registerProcessor(self, serviceName, processor):
self.services[serviceName] = processor
@@ -38,10 +48,14 @@
index = name.find(TMultiplexedProtocol.SEPARATOR)
if index < 0:
- raise TProtocolException(
- TProtocolException.NOT_IMPLEMENTED,
- "Service name not found in message name: " + name + ". " +
- "Did you forget to use TMultiplexedProtocol in your client?")
+ if self.defaultProcessor:
+ return self.defaultProcessor.process(
+ StoredMessageProtocol(iprot, (name, type, seqid)), oprot)
+ else:
+ raise TProtocolException(
+ TProtocolException.NOT_IMPLEMENTED,
+ "Service name not found in message name: " + name + ". " +
+ "Did you forget to use TMultiplexedProtocol in your client?")
serviceName = name[0:index]
call = name[index + len(TMultiplexedProtocol.SEPARATOR):]
diff --git a/lib/py/src/protocol/__init__.py b/lib/py/src/protocol/__init__.py
index 7148f66..06647a2 100644
--- a/lib/py/src/protocol/__init__.py
+++ b/lib/py/src/protocol/__init__.py
@@ -18,4 +18,4 @@
#
__all__ = ['fastbinary', 'TBase', 'TBinaryProtocol', 'TCompactProtocol',
- 'TJSONProtocol', 'TProtocol']
+ 'TJSONProtocol', 'TProtocol', 'TProtocolDecorator']