Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit 3d9f960

Browse files
committed
cleanup of application/octet-stream duplicate code
1 parent cbf250f commit 3d9f960

File tree

1 file changed

+0
-29
lines changed

1 file changed

+0
-29
lines changed

CloudFlare/cloudflare.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -486,35 +486,6 @@ def _raw(self, method, headers, parts, identifiers, params, data_str, data_json,
486486
return {'success': True, 'result': response_data}
487487
return {'success': True, 'result': str(response_data)}
488488

489-
if response_type == 'application/octet-stream' and isinstance(response_data, (int, float)):
490-
# it's raw/binary - just pass thru
491-
return {'success': True, 'result': response_data}
492-
493-
if response_type == 'application/octet-stream' and isinstance(response_data, (bytes, bytearray)):
494-
# API says it's text; but maybe it's actually JSON? - should be fixed in API
495-
if hasattr(response_data, 'decode'):
496-
try:
497-
response_data = response_data.decode('utf-8')
498-
except UnicodeDecodeError as e:
499-
# clearly not a string that can be decoded!
500-
if self.logger:
501-
self.logger.debug('Response: decode(utf-8) failed, reverting to binary response')
502-
# return binary
503-
return {'success': True, 'result': response_data}
504-
try:
505-
if response_data == '':
506-
# This should really be 'null' but it isn't. Even then, it's wrong!
507-
response_data = None
508-
else:
509-
response_data = json.loads(response_data)
510-
except ValueError:
511-
# So it wasn't JSON - moving on as if it's text!
512-
pass
513-
514-
if isinstance(response_data, dict) and 'success' in response_data:
515-
return response_data
516-
return {'success': True, 'result': response_data}
517-
518489
if response_type in ['application/pdf', 'application/zip'] or response_type[0:6] in ['audio/', 'image/', 'video/']:
519490
# it's raw/binary - just pass thru
520491
return {'success': True, 'result': response_data}

0 commit comments

Comments
 (0)