From 8e455bc332c3f616d52b424e2f1fa43ddddc4b83 Mon Sep 17 00:00:00 2001 From: Sebastian Molenda Date: Mon, 21 Mar 2022 10:06:24 +0100 Subject: [PATCH 1/3] Add option to enable/disable compression on endpoints --- pubnub/endpoints/endpoint.py | 11 +++++++++-- pubnub/endpoints/file_operations/send_file.py | 7 +++++++ pubnub/endpoints/pubsub/fire.py | 7 +++++++ pubnub/endpoints/pubsub/publish.py | 7 +++++++ 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/pubnub/endpoints/endpoint.py b/pubnub/endpoints/endpoint.py index 808d985e..d9996652 100644 --- a/pubnub/endpoints/endpoint.py +++ b/pubnub/endpoints/endpoint.py @@ -29,6 +29,7 @@ def __init__(self, pubnub): self.pubnub = pubnub self._cancellation_event = None self._sort_params = False + self._use_compression = self.pubnub.config.should_compress def cancellation_event(self, event): self._cancellation_event = event @@ -88,9 +89,12 @@ def allow_redirects(self): def use_base_path(self): return True + def is_compressable(self): + return False + def request_headers(self): headers = {} - if self.pubnub.config.should_compress: + if self.__compress_request(): headers["Content-Encoding"] = "gzip" if self.http_method() == HttpMethod.POST: headers["Content-type"] = "application/json" @@ -108,7 +112,7 @@ def encoded_params(self): def options(self): data = self.build_data() - if data and self.pubnub.config.should_compress: + if data and self.__compress_request(): data = zlib.compress(data.encode('utf-8'), level=2) return RequestOptions( path=self.build_path(), @@ -284,3 +288,6 @@ def create_exception(self, category, response, response_info, exception): exception.status = status return exception + + def __compress_request(self): + return (self.is_compressable() and self._use_compression) diff --git a/pubnub/endpoints/file_operations/send_file.py b/pubnub/endpoints/file_operations/send_file.py index f4e8f7c6..ebd29809 100644 --- a/pubnub/endpoints/file_operations/send_file.py +++ b/pubnub/endpoints/file_operations/send_file.py @@ -61,6 +61,13 @@ def build_file_upload_request(self): def http_method(self): return HttpMethod.POST + def use_compression(self, compress=True): + self._use_compression = bool(compress) + return self + + def is_compressable(self): + return True + def custom_params(self): return {} diff --git a/pubnub/endpoints/pubsub/fire.py b/pubnub/endpoints/pubsub/fire.py index 27b834ff..0a9ac3db 100644 --- a/pubnub/endpoints/pubsub/fire.py +++ b/pubnub/endpoints/pubsub/fire.py @@ -30,6 +30,13 @@ def use_post(self, use_post): self._use_post = bool(use_post) return self + def is_compressable(self): + return True + + def use_compression(self, compress=True): + self._use_compression = bool(compress) + return self + def meta(self, meta): self._meta = meta return self diff --git a/pubnub/endpoints/pubsub/publish.py b/pubnub/endpoints/pubsub/publish.py index ae07d6ec..ede7e6c9 100644 --- a/pubnub/endpoints/pubsub/publish.py +++ b/pubnub/endpoints/pubsub/publish.py @@ -34,6 +34,13 @@ def use_post(self, use_post): self._use_post = bool(use_post) return self + def use_compression(self, compress=True): + self._use_compression = bool(compress) + return self + + def is_compressable(self): + return True + def should_store(self, should_store): self._should_store = bool(should_store) return self From 30426fd1bfc2d8ecb608dd364219406a0b0d0ede Mon Sep 17 00:00:00 2001 From: Sebastian Molenda Date: Mon, 21 Mar 2022 11:01:52 +0100 Subject: [PATCH 2/3] fix requirements --- requirements-dev.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index f7bf5244..ac488d76 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -8,4 +8,4 @@ aiohttp requests cbor2 behave --e git://github.com/pubnub/vcrpy.git@aiotthp_redirect_enabled#egg=vcrpy \ No newline at end of file +-e git+https://github.com/pubnub/vcrpy.git@aiotthp_redirect_enabled#egg=vcrpy From 9cd7b5658f3112de7e66fdb07f369dec03b437af Mon Sep 17 00:00:00 2001 From: Client Engineering Bot <60980775+Client Engineering Bot@users.noreply.github.com> Date: Mon, 21 Mar 2022 11:45:11 +0000 Subject: [PATCH 3/3] PubNub SDK v6.2.0 release. --- .pubnub.yml | 13 +++++++++---- CHANGELOG.md | 6 ++++++ pubnub/pubnub_core.py | 2 +- setup.py | 2 +- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index c30bb834..03c13a46 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,5 @@ name: python -version: 6.1.0 +version: 6.2.0 schema: 1 scm: github.com/pubnub/python sdks: @@ -18,7 +18,7 @@ sdks: distributions: - distribution-type: library distribution-repository: package - package-name: pubnub-6.1.0 + package-name: pubnub-6.2.0 location: https://pypi.org/project/pubnub/ supported-platforms: supported-operating-systems: @@ -97,8 +97,8 @@ sdks: - distribution-type: library distribution-repository: git release - package-name: pubnub-6.1.0 - location: https://github.com/pubnub/python/releases/download/v6.1.0/pubnub-6.1.0.tar.gz + package-name: pubnub-6.2.0 + location: https://github.com/pubnub/python/releases/download/v6.2.0/pubnub-6.2.0.tar.gz supported-platforms: supported-operating-systems: Linux: @@ -169,6 +169,11 @@ sdks: license-url: https://github.com/aio-libs/aiohttp/blob/master/LICENSE.txt is-required: Required changelog: + - date: 2022-03-21 + version: v6.2.0 + changes: + - type: feature + text: "Add methods to change use compression option on chosen endpoints." - date: 2022-03-01 version: v6.1.0 changes: diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ff4ce71..ebeb14b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v6.2.0 +March 21 2022 + +#### Added +- Add methods to change use compression option on chosen endpoints. + ## v6.1.0 March 01 2022 diff --git a/pubnub/pubnub_core.py b/pubnub/pubnub_core.py index 7677877d..11fc57a2 100644 --- a/pubnub/pubnub_core.py +++ b/pubnub/pubnub_core.py @@ -65,7 +65,7 @@ class PubNubCore: """A base class for PubNub Python API implementations""" - SDK_VERSION = "6.1.0" + SDK_VERSION = "6.2.0" SDK_NAME = "PubNub-Python" TIMESTAMP_DIVIDER = 1000 diff --git a/setup.py b/setup.py index 769ec73c..21923bcb 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='pubnub', - version='6.1.0', + version='6.2.0', description='PubNub Real-time push service in the cloud', author='PubNub', author_email='support@pubnub.com',