Skip to content

Commit 451ab0f

Browse files
seba-alnClient Engineering Bot
andauthored
Add option to enable/disable compression on endpoints (#116)
* Add option to enable/disable compression on endpoints * fix requirements * PubNub SDK v6.2.0 release. Co-authored-by: Client Engineering Bot <60980775+Client Engineering Bot@users.noreply.github.com>
1 parent a059d0d commit 451ab0f

File tree

9 files changed

+48
-9
lines changed

9 files changed

+48
-9
lines changed

.pubnub.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: python
2-
version: 6.1.0
2+
version: 6.2.0
33
schema: 1
44
scm: github.com/pubnub/python
55
sdks:
@@ -18,7 +18,7 @@ sdks:
1818
distributions:
1919
- distribution-type: library
2020
distribution-repository: package
21-
package-name: pubnub-6.1.0
21+
package-name: pubnub-6.2.0
2222
location: https://pypi.org/project/pubnub/
2323
supported-platforms:
2424
supported-operating-systems:
@@ -97,8 +97,8 @@ sdks:
9797
-
9898
distribution-type: library
9999
distribution-repository: git release
100-
package-name: pubnub-6.1.0
101-
location: https://github.com/pubnub/python/releases/download/v6.1.0/pubnub-6.1.0.tar.gz
100+
package-name: pubnub-6.2.0
101+
location: https://github.com/pubnub/python/releases/download/v6.2.0/pubnub-6.2.0.tar.gz
102102
supported-platforms:
103103
supported-operating-systems:
104104
Linux:
@@ -169,6 +169,11 @@ sdks:
169169
license-url: https://github.com/aio-libs/aiohttp/blob/master/LICENSE.txt
170170
is-required: Required
171171
changelog:
172+
- date: 2022-03-21
173+
version: v6.2.0
174+
changes:
175+
- type: feature
176+
text: "Add methods to change use compression option on chosen endpoints."
172177
- date: 2022-03-01
173178
version: v6.1.0
174179
changes:

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v6.2.0
2+
March 21 2022
3+
4+
#### Added
5+
- Add methods to change use compression option on chosen endpoints.
6+
17
## v6.1.0
28
March 01 2022
39

pubnub/endpoints/endpoint.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def __init__(self, pubnub):
2929
self.pubnub = pubnub
3030
self._cancellation_event = None
3131
self._sort_params = False
32+
self._use_compression = self.pubnub.config.should_compress
3233

3334
def cancellation_event(self, event):
3435
self._cancellation_event = event
@@ -88,9 +89,12 @@ def allow_redirects(self):
8889
def use_base_path(self):
8990
return True
9091

92+
def is_compressable(self):
93+
return False
94+
9195
def request_headers(self):
9296
headers = {}
93-
if self.pubnub.config.should_compress:
97+
if self.__compress_request():
9498
headers["Content-Encoding"] = "gzip"
9599
if self.http_method() == HttpMethod.POST:
96100
headers["Content-type"] = "application/json"
@@ -108,7 +112,7 @@ def encoded_params(self):
108112

109113
def options(self):
110114
data = self.build_data()
111-
if data and self.pubnub.config.should_compress:
115+
if data and self.__compress_request():
112116
data = zlib.compress(data.encode('utf-8'), level=2)
113117
return RequestOptions(
114118
path=self.build_path(),
@@ -284,3 +288,6 @@ def create_exception(self, category, response, response_info, exception):
284288
exception.status = status
285289

286290
return exception
291+
292+
def __compress_request(self):
293+
return (self.is_compressable() and self._use_compression)

pubnub/endpoints/file_operations/send_file.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ def build_file_upload_request(self):
6161
def http_method(self):
6262
return HttpMethod.POST
6363

64+
def use_compression(self, compress=True):
65+
self._use_compression = bool(compress)
66+
return self
67+
68+
def is_compressable(self):
69+
return True
70+
6471
def custom_params(self):
6572
return {}
6673

pubnub/endpoints/pubsub/fire.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ def use_post(self, use_post):
3030
self._use_post = bool(use_post)
3131
return self
3232

33+
def is_compressable(self):
34+
return True
35+
36+
def use_compression(self, compress=True):
37+
self._use_compression = bool(compress)
38+
return self
39+
3340
def meta(self, meta):
3441
self._meta = meta
3542
return self

pubnub/endpoints/pubsub/publish.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ def use_post(self, use_post):
3434
self._use_post = bool(use_post)
3535
return self
3636

37+
def use_compression(self, compress=True):
38+
self._use_compression = bool(compress)
39+
return self
40+
41+
def is_compressable(self):
42+
return True
43+
3744
def should_store(self, should_store):
3845
self._should_store = bool(should_store)
3946
return self

pubnub/pubnub_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565

6666
class PubNubCore:
6767
"""A base class for PubNub Python API implementations"""
68-
SDK_VERSION = "6.1.0"
68+
SDK_VERSION = "6.2.0"
6969
SDK_NAME = "PubNub-Python"
7070

7171
TIMESTAMP_DIVIDER = 1000

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ aiohttp
88
requests
99
cbor2
1010
behave
11-
-e git://github.com/pubnub/vcrpy.git@aiotthp_redirect_enabled#egg=vcrpy
11+
-e git+https://github.com/pubnub/vcrpy.git@aiotthp_redirect_enabled#egg=vcrpy

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='pubnub',
5-
version='6.1.0',
5+
version='6.2.0',
66
description='PubNub Real-time push service in the cloud',
77
author='PubNub',
88
author_email='support@pubnub.com',

0 commit comments

Comments
 (0)