Skip to content

Commit

Permalink
Fix flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
xvblack authored and lxyu committed Apr 15, 2015
1 parent 586a150 commit ed66f77
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
8 changes: 6 additions & 2 deletions examples/multiplexer/multiplexed_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@
dd_thrift = thriftpy.load("dingdong.thrift", module_name="dd_thrift")
pp_thrift = thriftpy.load("pingpong.thrift", module_name="pp_thrift")

DD_SERVICE_NAME = "dd_thrift"
PP_SERVICE_NAME = "pp_thrift"



def main():
binary_factory = TBinaryProtocolFactory()
dd_factory = TMultiplexingProtocolFactory(binary_factory, "dd_thrift")
dd_factory = TMultiplexingProtocolFactory(binary_factory, DD_SERVICE_NAME)
with client_context(dd_thrift.DingService, '127.0.0.1', 9090,
proto_factory=dd_factory) as c:
# ring that doorbell
dong = c.ding()
print(dong)

pp_factory = TMultiplexingProtocolFactory(binary_factory, "pp_thrift")
pp_factory = TMultiplexingProtocolFactory(binary_factory, PP_SERVICE_NAME)
with client_context(pp_thrift.PingService, '127.0.0.1', 9090,
proto_factory=pp_factory) as c:
# play table tennis like a champ
Expand Down
6 changes: 4 additions & 2 deletions examples/multiplexer/multiplexed_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
dd_thrift = thriftpy.load("dingdong.thrift", module_name="dd_thrift")
pp_thrift = thriftpy.load("pingpong.thrift", module_name="pp_thrift")

DD_SERVICE_NAME = "dd_thrift"
PP_SERVICE_NAME = "pp_thrift"

class DingDispatcher(object):
def ding(self):
Expand All @@ -28,8 +30,8 @@ def main():
pp_proc = TProcessor(pp_thrift.PingService, PingDispatcher())

mux_proc = TMultiplexingProcessor()
mux_proc.register_processor("dd_thrift", dd_proc)
mux_proc.register_processor("pp_thrift", pp_proc)
mux_proc.register_processor(DD_SERVICE_NAME, dd_proc)
mux_proc.register_processor(PP_SERVICE_NAME, pp_proc)

server = TThreadedServer(mux_proc, TServerSocket(),
iprot_factory=TBinaryProtocolFactory(),
Expand Down
6 changes: 4 additions & 2 deletions tests/test_multiplexed.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import pytest

import thriftpy
from thriftpy.protocol import TBinaryProtocolFactory
from thrift.protocol import TMultiplexingProtocolFactory
from thriftpy.protocol import (
TBinaryProtocolFactory,
TMultiplexingProtocolFactory
)
from thriftpy.rpc import client_context
from thriftpy.server import TThreadedServer
from thriftpy.thrift import TProcessor, TMultiplexingProcessor
Expand Down
2 changes: 1 addition & 1 deletion thriftpy/protocol/multiplex.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __getattr__(self, name):

def write_message_begin(self, name, ttype, seqid):
self.proto.write_message_begin(
self.service_name + TMultiplexingProcessor.Separator + name,
self.service_name + TMultiplexingProcessor.SEPARATOR + name,
ttype, seqid)


Expand Down
4 changes: 2 additions & 2 deletions thriftpy/thrift.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def process(self, iprot, oprot):


class TMultiplexingProcessor(TProcessor):
Separator = ":"
SEPARATOR = ":"

processors = {}
service_map = {}
Expand All @@ -268,7 +268,7 @@ def register_processor(self, service_name, processor):
def process_in(self, iprot):
api, type, seqid = iprot.read_message_begin()

service_name, api = api.split(TMultiplexingProcessor.Separator)
service_name, api = api.split(TMultiplexingProcessor.SEPARATOR)

if service_name not in self.processors:
iprot.skip(TType.STRUCT)
Expand Down

0 comments on commit ed66f77

Please sign in to comment.