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

Commit

Permalink
fix thrift_spec bug
Browse files Browse the repository at this point in the history
  • Loading branch information
maralla committed Mar 10, 2015
1 parent 01184c0 commit e14a63d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
12 changes: 6 additions & 6 deletions tests/test_protocol_cybinary.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

class TItem(TPayload):
thrift_spec = {
1: (TType.I32, "id"),
2: (TType.LIST, "phones", (TType.STRING)),
1: (TType.I32, "id", False),
2: (TType.LIST, "phones", TType.STRING, False),
}
default_spec = [("id", None), ("phones", None)]

Expand Down Expand Up @@ -214,8 +214,8 @@ def test_read_huge_args():

class Hello(TPayload):
thrift_spec = {
1: (TType.STRING, "name"),
2: (TType.STRING, "world"),
1: (TType.STRING, "name", False),
2: (TType.STRING, "world", False),
}
default_spec = [("name", None), ("world", None)]

Expand Down Expand Up @@ -346,8 +346,8 @@ def test_read_wrong_arg_type():

class TWrongTypeItem(TPayload):
thrift_spec = {
1: (TType.STRING, "id"),
2: (TType.LIST, "phones", (TType.STRING)),
1: (TType.STRING, "id", False),
2: (TType.LIST, "phones", TType.STRING, False),
}
default_spec = [("id", None), ("phones", None)]

Expand Down
7 changes: 7 additions & 0 deletions tests/test_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ def remove(self, name):
c.add(person)
return True

def get_phonenumbers(self, name, count):
return [addressbook.PhoneNumber(number="sdaf"),
addressbook.PhoneNumber(number='saf')]

def add(self, person):
with client(port=6099) as c:
c.hello("jane")
Expand Down Expand Up @@ -266,6 +270,9 @@ def test_tracked_client_not_tracked_server(not_tracked_server):
assert c._upgraded is False
c.ping()
c.hello("cat")
a = c.get_phonenumbers("hello", 54)
assert len(a) == 2
assert a[0].number == 'sdaf' and a[1].number == 'saf'


def test_request_id_func():
Expand Down
4 changes: 2 additions & 2 deletions thriftpy/protocol/cybin/cybin.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ cdef inline read_struct(CyTransportBase buf, obj):
continue

name = field_spec[1]
if len(field_spec) == 2:
if len(field_spec) <= 3:
spec = None
else:
spec = field_spec[2]
Expand All @@ -138,7 +138,7 @@ cdef inline write_struct(CyTransportBase buf, obj):
for fid, field_spec in thrift_spec.items():
f_type = field_spec[0]
f_name = field_spec[1]
if len(field_spec) == 2:
if len(field_spec) <= 3:
container_spec = None
else:
container_spec = field_spec[2]
Expand Down
4 changes: 2 additions & 2 deletions thriftpy/thrift.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ class TApplicationException(TException):
"""Application level thrift exceptions."""

thrift_spec = {
1: (TType.STRING, 'message'),
2: (TType.I32, 'type'),
1: (TType.STRING, 'message', False),
2: (TType.I32, 'type', False),
}

UNKNOWN = 0
Expand Down

0 comments on commit e14a63d

Please sign in to comment.