cloud-files 4.27.0__py3-none-any.whl → 6.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
cloudfiles/compression.py CHANGED
@@ -171,7 +171,7 @@ def gzip_compress(content, compresslevel=None):
171
171
  compresslevel = 9
172
172
 
173
173
  if deflate:
174
- return deflate.gzip_compress(content, compresslevel)
174
+ return bytes(deflate.gzip_compress(content, compresslevel))
175
175
 
176
176
  stringio = BytesIO()
177
177
  gzip_obj = gzip.GzipFile(mode='wb', fileobj=stringio, compresslevel=compresslevel)
@@ -190,14 +190,19 @@ def gunzip(content):
190
190
  raise DecompressionError('File contains zero bytes.')
191
191
 
192
192
  gzip_magic_numbers = [ 0x1f, 0x8b ]
193
- first_two_bytes = [ byte for byte in bytearray(content)[:2] ]
193
+
194
+ if isinstance(content, (bytes, bytearray)):
195
+ first_two_bytes = list(content[:2])
196
+ else:
197
+ first_two_bytes = [ byte for byte in bytearray(content)[:2] ]
198
+
194
199
  if first_two_bytes != gzip_magic_numbers:
195
200
  raise DecompressionError('File is not in gzip format. Magic numbers {}, {} did not match {}, {}.'.format(
196
201
  hex(first_two_bytes[0]), hex(first_two_bytes[1]), hex(gzip_magic_numbers[0]), hex(gzip_magic_numbers[1])
197
202
  ))
198
203
 
199
204
  if deflate:
200
- return deflate.gzip_decompress(content)
205
+ return bytes(deflate.gzip_decompress(content))
201
206
 
202
207
  stringio = BytesIO(content)
203
208
  with gzip.GzipFile(mode='rb', fileobj=stringio) as gfile:
cloudfiles/exceptions.py CHANGED
@@ -14,6 +14,10 @@ class CompressionError(Exception):
14
14
  """
15
15
  pass
16
16
 
17
+ class AuthorizationError(Exception):
18
+ """Authorization Error"""
19
+ pass
20
+
17
21
  class UnsupportedCompressionType(Exception):
18
22
  """
19
23
  Raised when attempting to use a compression type which is unsupported
cloudfiles/gcs.py CHANGED
@@ -78,14 +78,18 @@ def composite_upload(
78
78
  cache_control:Optional[str] = None,
79
79
  storage_class:Optional[str] = None,
80
80
  compress:CompressType = None,
81
+ skip_compress:bool = False,
81
82
  ) -> int:
82
83
  from .cloudfiles import CloudFiles, CloudFile
83
84
 
84
85
  content_encoding = compression.normalize_encoding(compress)
85
86
  if isinstance(handle, bytes):
86
- handle = io.BytesIO(
87
- compression.compress(handle, compress)
88
- )
87
+ if skip_compress:
88
+ handle = io.BytesIO(handle)
89
+ else:
90
+ handle = io.BytesIO(
91
+ compression.compress(handle, compress)
92
+ )
89
93
  content_encoding = compression.normalize_encoding(compress)
90
94
 
91
95
  path = paths.extract(cloudpath)