THRIFT-4548: python binary accelerated protocol with multiplexing via decoration (#1547)
* Fix binary accelerated protocol with multiplexing
TMultiplexedProtocol objects did not inherit from TProtocol, so the
decorated protocol object passed into the binary accelerated C extension
was not really a TProtocol object, which caused errors. This
implementation decorates the protocol object by dynamically creating a
new class that extends both the class of the protocol being decorated
and TMultiplexedProtocol.
* THRIFT-4548: remove known failures for py multiplexed client cross tests
* Call super with args for python2 & pep8 fixes
* THRIFT-3877: disable known failures for http cpp tests
This closes #1535
diff --git a/lib/py/src/protocol/TMultiplexedProtocol.py b/lib/py/src/protocol/TMultiplexedProtocol.py
index 309f896..0f8390f 100644
--- a/lib/py/src/protocol/TMultiplexedProtocol.py
+++ b/lib/py/src/protocol/TMultiplexedProtocol.py
@@ -25,16 +25,15 @@
class TMultiplexedProtocol(TProtocolDecorator.TProtocolDecorator):
def __init__(self, protocol, serviceName):
- TProtocolDecorator.TProtocolDecorator.__init__(self, protocol)
self.serviceName = serviceName
def writeMessageBegin(self, name, type, seqid):
if (type == TMessageType.CALL or
type == TMessageType.ONEWAY):
- self.protocol.writeMessageBegin(
+ super(TMultiplexedProtocol, self).writeMessageBegin(
self.serviceName + SEPARATOR + name,
type,
seqid
)
else:
- self.protocol.writeMessageBegin(name, type, seqid)
+ super(TMultiplexedProtocol, self).writeMessageBegin(name, type, seqid)
diff --git a/lib/py/src/protocol/TProtocolDecorator.py b/lib/py/src/protocol/TProtocolDecorator.py
index 8b270a4..f5546c7 100644
--- a/lib/py/src/protocol/TProtocolDecorator.py
+++ b/lib/py/src/protocol/TProtocolDecorator.py
@@ -17,34 +17,10 @@
# under the License.
#
-import types
-from thrift.protocol.TProtocol import TProtocolBase
-
-
-class TProtocolDecorator():
- def __init__(self, protocol):
- TProtocolBase(protocol)
- self.protocol = protocol
-
- def __getattr__(self, name):
- if hasattr(self.protocol, name):
- member = getattr(self.protocol, name)
- if type(member) in [
- types.MethodType,
- types.FunctionType,
- types.LambdaType,
- types.BuiltinFunctionType,
- types.BuiltinMethodType,
- ]:
- return lambda *args, **kwargs: self._wrap(member, args, kwargs)
- else:
- return member
- raise AttributeError(name)
-
- def _wrap(self, func, args, kwargs):
- if isinstance(func, types.MethodType):
- result = func(*args, **kwargs)
- else:
- result = func(self.protocol, *args, **kwargs)
- return result
+class TProtocolDecorator(object):
+ def __new__(cls, protocol, *args, **kwargs):
+ decorated_cls = type(''.join(['Decorated', protocol.__class__.__name__]),
+ (cls, protocol.__class__),
+ protocol.__dict__)
+ return object.__new__(decorated_cls)