From 252d279bed4b3384b6e3e8bd4ed5f26d0d9eb44b Mon Sep 17 00:00:00 2001 From: rangeesh Date: Tue, 8 Jan 2019 19:26:23 +0530 Subject: [PATCH 1/6] Raw Protocol added --- kwikapi/protocols.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/kwikapi/protocols.py b/kwikapi/protocols.py index f5953ab..4922dcf 100644 --- a/kwikapi/protocols.py +++ b/kwikapi/protocols.py @@ -118,6 +118,31 @@ def get_record_separator(cls): def get_mime_type(): return 'application/pickle' +class RawProtocol(BaseProtocol): + @staticmethod + def get_name(): + return 'raw' + + @staticmethod + def serialize(data): + return data + + @staticmethod + def deserialize(data): + return data + + @classmethod + def deserialize_stream(cls, data): + return data + + @classmethod + def get_record_separator(cls): + return b'' + + @staticmethod + def get_mime_type(): + return 'application/octet-stream' + class NumpyProtocol(BaseProtocol): @staticmethod @@ -180,6 +205,7 @@ def get_mime_type(): MessagePackProtocol, PickleProtocol, NumpyProtocol, + RawProtocol, ]) DEFAULT_PROTOCOL = JsonProtocol.get_name() From ce53885574a9a47018af606574e11234588337e2 Mon Sep 17 00:00:00 2001 From: rangeesh Date: Tue, 8 Jan 2019 19:28:24 +0530 Subject: [PATCH 2/6] version changes --- .travis.yml | 4 ++-- setup.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5eef1db..13373da 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,8 +16,8 @@ deploy: - LICENSE - kwikapi/api.py - kwikapi/__init__.py - name: kwikapi-0.4.7 - tag_name: 0.4.7 + name: kwikapi-0.4.8 + tag_name: 0.4.8 on: repo: deep-compute/kwikapi - provider: pypi diff --git a/setup.py b/setup.py index 0e73553..114fd9e 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages -version = '0.4.7' +version = '0.4.8' setup( name="kwikapi", version=version, From 30335622839ea74f8e35f3bf114212e7ea519f04 Mon Sep 17 00:00:00 2001 From: shivam Date: Mon, 21 Jan 2019 18:41:46 +0530 Subject: [PATCH 3/6] bug fix for raw protocol --- kwikapi/api.py | 5 +++-- kwikapi/protocols.py | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/kwikapi/api.py b/kwikapi/api.py index 6492214..252c3f7 100644 --- a/kwikapi/api.py +++ b/kwikapi/api.py @@ -493,10 +493,11 @@ def handle_request(self, request): # Serialize the response if request.fn.__func__.func_info['gives_stream']: - result = self._wrap_stream(request, result) + result = self._wrap_stream(request, result) if protocol.should_wrap() else result n, t = response.write(result, protocol, stream=True) else: - n, t = response.write(dict(success=True, result=result), protocol) + result = dict(success=True, result=result) if protocol.should_wrap() else result + n, t = response.write(result, protocol) request.log.info('kwikapi.handle_request', function=rinfo.function, namespace=rinfo.namespace, diff --git a/kwikapi/protocols.py b/kwikapi/protocols.py index 4922dcf..1f3736e 100644 --- a/kwikapi/protocols.py +++ b/kwikapi/protocols.py @@ -35,6 +35,14 @@ def get_record_separator(self): def get_mime_type(self): pass + @staticmethod + def should_wrap(): + ''' + FIXME: add description here with examples + to show why this is required + ''' + return True + class JsonProtocol(BaseProtocol): @staticmethod @@ -143,6 +151,10 @@ def get_record_separator(cls): def get_mime_type(): return 'application/octet-stream' + @classmethod + def should_wrap(cls): + return False + class NumpyProtocol(BaseProtocol): @staticmethod From d69006919decd796733daaacbd83920a4319f31b Mon Sep 17 00:00:00 2001 From: shivam Date: Mon, 21 Jan 2019 18:51:10 +0530 Subject: [PATCH 4/6] resolved FIXME in should_wrap --- kwikapi/protocols.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kwikapi/protocols.py b/kwikapi/protocols.py index 1f3736e..42b68a7 100644 --- a/kwikapi/protocols.py +++ b/kwikapi/protocols.py @@ -38,8 +38,12 @@ def get_mime_type(self): @staticmethod def should_wrap(): ''' - FIXME: add description here with examples - to show why this is required + While returning the response the, + kwikapi will wrap the response as - + {success: value, result: value} + + This is applicable to all the protocols, + except the raw protocol ''' return True From de70ef48ada220dc04fd632e33ef36946574241f Mon Sep 17 00:00:00 2001 From: shivam Date: Tue, 22 Jan 2019 10:23:52 +0530 Subject: [PATCH 5/6] made requested changes --- kwikapi/protocols.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kwikapi/protocols.py b/kwikapi/protocols.py index 42b68a7..b50ca26 100644 --- a/kwikapi/protocols.py +++ b/kwikapi/protocols.py @@ -42,8 +42,9 @@ def should_wrap(): kwikapi will wrap the response as - {success: value, result: value} - This is applicable to all the protocols, - except the raw protocol + This method, can used in above situation, + if no wrapping is required, + override this method in the protocol class. ''' return True From 53575c7b03ea072e2aee6b2d1d98eedde6b2ba28 Mon Sep 17 00:00:00 2001 From: shivam Date: Tue, 22 Jan 2019 10:39:41 +0530 Subject: [PATCH 6/6] changed the version number --- .travis.yml | 4 ++-- setup.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 13373da..7d8e988 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,8 +16,8 @@ deploy: - LICENSE - kwikapi/api.py - kwikapi/__init__.py - name: kwikapi-0.4.8 - tag_name: 0.4.8 + name: kwikapi-0.4.9 + tag_name: 0.4.9 on: repo: deep-compute/kwikapi - provider: pypi diff --git a/setup.py b/setup.py index 114fd9e..82e2cd2 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages -version = '0.4.8' +version = '0.4.9' setup( name="kwikapi", version=version,