Skip to content

Commit

Permalink
some enhancement and bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
sunng87 committed Apr 25, 2012
1 parent 0d1a34b commit 8fa2d5d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -7,7 +7,7 @@
long_desc=open('README.rst','r').read()

setup(name="slacker-python",
version="0.1.0",
version="0.1.1",
author="Sun Ning",
author_email="sunng@about.me",
description="python client of slacker RPC",
Expand Down
7 changes: 5 additions & 2 deletions slacker/client.py
Expand Up @@ -66,8 +66,11 @@ def call(self, fname, args):
cb = conn.send(req)
result = cb.get()
if isinstance(result, SlackerResponse):
result.desrialize()
return result.body
if result.code == PROTOCOL_RESULT_CODE_SUCCESS:
result.desrialize()
return result.body
else:
raise RuntimeError("Error code: "+ str(result.code))
else:
code = result.code
raise RuntimeError("Error code: " + str(code))
Expand Down
17 changes: 12 additions & 5 deletions slacker/protocol.py
Expand Up @@ -11,6 +11,8 @@
PROTOCOL_CONTENT_TYPE_JSON = 1
PROTOCOL_CONTENT_TYPE_CLJ = 2

PROTOCOL_RESULT_CODE_SUCCESS = 0

class SlackerRequest(object):
def __init__(self, ct, fname, args):
self.ct = ct
Expand All @@ -32,12 +34,14 @@ def __init__(self, ct, code, body):
self.body = body

def serialize(self):
serializer = json if self.ct == PROTOCOL_CONTENT_TYPE_JSON else clj
self.body = serializer.dumps(self.body)
if self.body is not None:
serializer = json if self.ct == PROTOCOL_CONTENT_TYPE_JSON else clj
self.body = serializer.dumps(self.body)

def desrialize(self):
serializer = json if self.ct == PROTOCOL_CONTENT_TYPE_JSON else clj
self.body = serializer.loads(self.body)
if self.body is not None:
serializer = json if self.ct == PROTOCOL_CONTENT_TYPE_JSON else clj
self.body = serializer.loads(self.body)

class SlackerError(object):
def __init__(self, ct, code):
Expand Down Expand Up @@ -76,7 +80,10 @@ def readResponse(fd):

## read body
l = struct.unpack(">I", fd.recv(4))[0]
body = struct.unpack(str(l)+"s", fd.recv(l))[0]
if l > 0:
body = struct.unpack(str(l)+"s", fd.recv(l))[0]
else:
body = None

return SlackerResponse(ct, rc, body)

Expand Down

0 comments on commit 8fa2d5d

Please sign in to comment.