Skip to content

Commit a407b39

Browse files
committed
is_binary method in helpers module
1 parent c72e5ec commit a407b39

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Changelog
22

33
## [Unreleased]
4+
### Added
5+
- `is_binary` method in `helpers` module, by @HardNorth
46

57
## [5.5.4]
68
### Added

reportportal_client/helpers.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,3 +391,19 @@ async def await_if_necessary(obj: Optional[Any]) -> Optional[Any]:
391391
elif asyncio.iscoroutinefunction(obj):
392392
return await obj()
393393
return obj
394+
395+
396+
def is_binary(iterable: Union[bytes, bytearray, str]) -> bool:
397+
"""Check if given iterable is binary.
398+
399+
:param iterable: iterable to check
400+
:return: True if iterable contains binary bytes, False otherwise
401+
"""
402+
if isinstance(iterable, str):
403+
byte_iterable = iterable.encode('utf-8')
404+
else:
405+
byte_iterable = iterable
406+
407+
if 0x00 in byte_iterable:
408+
return True
409+
return False

0 commit comments

Comments
 (0)