Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Added service multiplexing support. #79

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
981bab3
Added service multiplexing support.
Jan 22, 2015
04d4ce9
fix pep8 issues
Jan 22, 2015
a6141fa
New Parser
hit9 Jan 23, 2015
568b991
Referenced enum value should be named
hit9 Jan 23, 2015
3f72b00
Fix module_name and child/father searching on ref
hit9 Jan 23, 2015
208917a
Add thrift_loader cache
hit9 Jan 23, 2015
3e45b97
Use tuple as container types
hit9 Jan 23, 2015
42dbd02
Fix result spec
hit9 Jan 23, 2015
2fc6d71
Default required is False
hit9 Jan 23, 2015
728487d
Move thrift parsing cache to parser; and add option `enable_cache`
hit9 Jan 23, 2015
0632630
Fix result struct ttype VOID
hit9 Jan 23, 2015
5d964c7
Remove old parser tests
hit9 Jan 23, 2015
01f39d0
Use splitext
hit9 Jan 23, 2015
8cc624b
Extends services from father
hit9 Jan 23, 2015
8e0d621
Add more tests cases for PR#80
hit9 Jan 23, 2015
b51a5fa
Referenced constant should be a named enum value or another constant
hit9 Jan 24, 2015
4cfd5af
Add more test cases
hit9 Jan 24, 2015
8af6f9f
Referenced enum values must be named
hit9 Jan 24, 2015
4cfb80d
Add tests for enums/structs
hit9 Jan 24, 2015
022ccdf
Tests case for structs/services and flakes8 fixes
hit9 Jan 24, 2015
39a62af
Add test-case for e-service-extends
hit9 Jan 24, 2015
039cf26
Flake8 fixed
hit9 Jan 24, 2015
f9f9216
Add names-to-values and values-to-names for enums
hit9 Jan 24, 2015
6dc0a26
Cyclig including (dead including) checking
hit9 Jan 24, 2015
a77d6fe
Add test case for dead include
hit9 Jan 24, 2015
01a2010
better assert uniqueness by catching processor module name
Feb 9, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions examples/multiplexer/dingdong.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# ding service demo
service DingService {
/*
* Sexy c style comment
*/
string ding(),
}
23 changes: 23 additions & 0 deletions examples/multiplexer/multiplexed_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-

import thriftpy
from thriftpy.rpc import client_context

dd_thrift = thriftpy.load("dingdong.thrift", module_name="dd_thrift")
pp_thrift = thriftpy.load("pingpong.thrift", module_name="pp_thrift")


def main():
with client_context(dd_thrift.DingService, '127.0.0.1', 9090) as c:
# ring that doorbell
dong = c.ding()
print(dong)

with client_context(pp_thrift.PingService, '127.0.0.1', 9090) as c:
# play table tennis like a champ
pong = c.ping()
print(pong)


if __name__ == '__main__':
main()
41 changes: 41 additions & 0 deletions examples/multiplexer/multiplexed_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-

import thriftpy
from thriftpy.protocol import TBinaryProtocolFactory
from thriftpy.server import TThreadedServer
from thriftpy.thrift import TProcessor, TMultiplexingProcessor
from thriftpy.transport import TBufferedTransportFactory, TServerSocket


dd_thrift = thriftpy.load("dingdong.thrift", module_name="dd_thrift")
pp_thrift = thriftpy.load("pingpong.thrift", module_name="pp_thrift")


class DingDispatcher(object):
def ding(self):
print("ding dong!")
return 'dong'


class PingDispatcher(object):
def ping(self):
print("ping pong!")
return 'pong'


def main():
dd_proc = TProcessor(dd_thrift.DingService, DingDispatcher())
pp_proc = TProcessor(pp_thrift.PingService, PingDispatcher())

mux_proc = TMultiplexingProcessor()
mux_proc.register_processor(dd_proc)
mux_proc.register_processor(pp_proc)

server = TThreadedServer(mux_proc, TServerSocket(),
iprot_factory=TBinaryProtocolFactory(),
itrans_factory=TBufferedTransportFactory())
server.serve()


if __name__ == '__main__':
main()
7 changes: 7 additions & 0 deletions examples/multiplexer/pingpong.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# ping service demo
service PingService {
/*
* Sexy c style comment
*/
string ping(),
}
2 changes: 1 addition & 1 deletion tests/addressbook.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const i16 DEFAULT_LIST_SIZE = 10
typedef i32 timestamp

enum PhoneType {
MOBILE,
MOBILE = 0,
HOME,
WORK,
}
Expand Down
7 changes: 7 additions & 0 deletions tests/multiplexed.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
service ThingOneService {
bool doThingOne();
}

service ThingTwoService {
bool doThingTwo();
}
9 changes: 9 additions & 0 deletions tests/parser-cases/comments.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* C/CPP like comments
*/

/**
* Silly comments
*/

# Python like comments
32 changes: 32 additions & 0 deletions tests/parser-cases/constants.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const i16 int16 = 3
const i32 int32 = 800
const i64 int64 = 123456789
const string tstr = "hello world"
const double tdouble = 1.3
typedef i32 Integer32
const Integer32 integer32 = 900
const list<i32> tlist = [1, 2, 3]
const set<i32> tset = [1, 2, 3]
const map<string, string> tmap1 = {"key": "val"}
const map<string, Integer32> tmap2 = {"key": 32}

# https://github.com/eleme/thriftpy/pull/69
enum Country {
US = 1,
UK = 2,
CA = 3,
CN = 4
}

const Country my_country = Country.CN;

struct Person {
1: string name,
2: Country country = Country.US
}

const Person tom = {"name": "tom"}

# https://github.com/eleme/thriftpy/issues/75
const map<Country, string> country_map = {
Country.US: "US", Country.UK: "UK", Country.CA: "CA", Country.CN: "CN"}
1 change: 1 addition & 0 deletions tests/parser-cases/e_dead_include_0.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include "e_dead_include_1.thrift"
1 change: 1 addition & 0 deletions tests/parser-cases/e_dead_include_1.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include "e_dead_include_2.thrift"
1 change: 1 addition & 0 deletions tests/parser-cases/e_dead_include_2.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include "e_dead_include_3.thrift"
1 change: 1 addition & 0 deletions tests/parser-cases/e_dead_include_3.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include "e_dead_include_1.thrift"
5 changes: 5 additions & 0 deletions tests/parser-cases/e_service_extends_0.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include "shared.thrift"

service PingService extends shared.NotExistService {

}
13 changes: 13 additions & 0 deletions tests/parser-cases/e_structs_0.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
struct User {
1: required string name,
2: optional string avatar
}

struct Post {
1: required string title,
2: required string content,
3: required User user,
}

const Post post = {'title': 'hello world', 'content': 'hello',
'user': {}}
7 changes: 7 additions & 0 deletions tests/parser-cases/e_structs_1.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
struct User {
1: string name,
2: i32 age,
3: string email
}

const User user = {'avatar': '/avatar.jpg'}
1 change: 1 addition & 0 deletions tests/parser-cases/e_type_error_0.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const i32 int32 = 1.7;
1 change: 1 addition & 0 deletions tests/parser-cases/e_type_error_1.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const map<string, map<string, i32>> dct = {'key': {'key1': '1'}}
6 changes: 6 additions & 0 deletions tests/parser-cases/e_type_error_2.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
struct Person {
1: string name,
2: i32 age,
}

const Person jack = {'name': 'jack', 'age': 1.8}
1 change: 1 addition & 0 deletions tests/parser-cases/e_value_ref_0.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const i32 dct = ref;
7 changes: 7 additions & 0 deletions tests/parser-cases/e_value_ref_1.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enum Lang {
CPP = 0,
Python,
Ruby = 2,
}

const i32 my_lang = Lang.Python;
5 changes: 5 additions & 0 deletions tests/parser-cases/e_value_ref_2.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
struct Cookbook {
1: string name
}

const Cookbook cookbook = Cookbook
23 changes: 23 additions & 0 deletions tests/parser-cases/enums.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
enum Lang {
C,
Go,
Java,
Javascript,
PHP,
Python,
Ruby,
}


enum Country {
US = 1,
UK,
CN,
}


enum OS {
OSX,
Win = 3,
Linux
}
3 changes: 3 additions & 0 deletions tests/parser-cases/include.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include "included.thrift"

const included.Timestamp datetime = 1422009523
1 change: 1 addition & 0 deletions tests/parser-cases/included.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
typedef i64 Timestamp
11 changes: 0 additions & 11 deletions tests/parser-cases/json/comments.json

This file was deleted.

19 changes: 0 additions & 19 deletions tests/parser-cases/json/consts.json

This file was deleted.

27 changes: 0 additions & 27 deletions tests/parser-cases/json/enums.json

This file was deleted.

13 changes: 0 additions & 13 deletions tests/parser-cases/json/escape.json

This file was deleted.

28 changes: 0 additions & 28 deletions tests/parser-cases/json/exceptions.json

This file was deleted.

29 changes: 0 additions & 29 deletions tests/parser-cases/json/includes.json

This file was deleted.

11 changes: 0 additions & 11 deletions tests/parser-cases/json/namespaces.json

This file was deleted.

Loading