File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change 1
1
# Changelog
2
2
3
3
## [ Unreleased]
4
+ ### Added
5
+ - ` is_binary ` method in ` helpers ` module, by @HardNorth
4
6
5
7
## [ 5.5.4]
6
8
### Added
Original file line number Diff line number Diff line change @@ -391,3 +391,19 @@ async def await_if_necessary(obj: Optional[Any]) -> Optional[Any]:
391
391
elif asyncio .iscoroutinefunction (obj ):
392
392
return await obj ()
393
393
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
You can’t perform that action at this time.
0 commit comments