forked from Thriftpy/thriftpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename multiplexing -> multiplexed enforce type check in write_message_begin
- Loading branch information
Showing
6 changed files
with
47 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,34 @@ | ||
from thriftpy.thrift import TMultiplexingProcessor | ||
# -*- coding: utf-8 -*- | ||
|
||
from thriftpy.thrift import TMultiplexedProcessor, TMessageType | ||
|
||
class TMultiplexingProtocol(object): | ||
|
||
""" | ||
Multiplex protocol | ||
for writing message begin, it prepend the service name to the api | ||
for other functions, it simply delegate to the original protocol | ||
|
||
class TMultiplexedProtocol(object): | ||
"""Multiplex the protocol by prepend service name to api for every api call. | ||
Can be used together with all original protocols. | ||
""" | ||
|
||
def __init__(self, proto, service_name): | ||
self.service_name = service_name | ||
self.proto = proto | ||
self._proto = proto | ||
|
||
def __getattr__(self, name): | ||
return getattr(self.proto, name) | ||
return getattr(self._proto, name) | ||
|
||
def write_message_begin(self, name, ttype, seqid): | ||
self.proto.write_message_begin( | ||
self.service_name + TMultiplexingProcessor.SEPARATOR + name, | ||
ttype, seqid) | ||
|
||
if ttype in (TMessageType.CALL, TMessageType.ONEWAY): | ||
self._proto.write_message_begin( | ||
self.service_name + TMultiplexedProcessor.SEPARATOR + name, | ||
ttype, seqid) | ||
else: | ||
self._proto.write_message_begin(name, ttype, seqid) | ||
|
||
class TMultiplexingProtocolFactory(object): | ||
|
||
class TMultiplexedProtocolFactory(object): | ||
def __init__(self, proto_factory, service_name): | ||
self.proto_factory = proto_factory | ||
self._proto_factory = proto_factory | ||
self.service_name = service_name | ||
|
||
def get_protocol(self, trans): | ||
proto = self.proto_factory.get_protocol(trans) | ||
multi_proto = TMultiplexingProtocol(proto, self.service_name) | ||
return multi_proto | ||
proto = self._proto_factory.get_protocol(trans) | ||
return TMultiplexedProtocol(proto, self.service_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters