| |
- builtins.object
-
- Strings
class Strings(builtins.object) |
|
Strings(filename: str, chars: bytes = b'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"\\#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ ', minimum_chars: int = 5, number_bad_chars: int = 0, accepted_bad_chars: bytes = b'', encoding: str = 'latin1')
This class implement a Strings getter from binary file.
>>> with open("test", 'wb') as f: f.write(b"abc\x00\x01ab\x00cdeF\x00\x01")
14
>>> strings = Strings("test", chars=b"abcde", minimum_chars=3, number_bad_chars=1, accepted_bad_chars=b"\x00")
>>> for line in strings.reader(): print(line)
abc
abcde
>>> import os; os.remove("test") |
|
Methods defined here:
- __init__(self, filename: str, chars: bytes = b'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"\\#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ ', minimum_chars: int = 5, number_bad_chars: int = 0, accepted_bad_chars: bytes = b'', encoding: str = 'latin1')
- Initialize self. See help(type(self)) for accurate signature.
- analyse_char(self, char: bytes) -> str
- This function analyse a byte and return strings found.
>>> strings = Strings(None)
>>> [strings.analyse_char(x) for x in (b"a", b"b", b"c", b"d", b"e", b"\x00")]
[None, None, None, None, None, 'abcde']
>>> strings = Strings(None, number_bad_chars=1)
>>> [strings.analyse_char(x) for x in (b"a", b"b", b"\x00", b"c", b"d", b"e", b"\x00", b"\x00")]
[None, None, None, None, None, None, None, 'abcde']
>>> strings = Strings(None, number_bad_chars=1, accepted_bad_chars=b"\x00")
>>> [strings.analyse_char(x) for x in (b"a", b"b", b"\x00", b"c", b"d", b"e", b"\x00", b"\x00")]
[None, None, None, None, None, None, None, 'abcde']
>>> strings = Strings(None)
>>> [strings.analyse_char(x) for x in (b"a", b"b", b"\x00", b"c", b"d", b"e", b"\x00", b"\x00")]
[None, None, None, None, None, None, None, None]
>>> strings = Strings(None, number_bad_chars=1, accepted_bad_chars=b"\x01")
>>> [strings.analyse_char(x) for x in (b"a", b"b", b"\x00", b"c", b"d", b"e", b"\x00", b"\x00")]
[None, None, None, None, None, None, None, None]
- reader(self) -> Generator[str, NoneType, NoneType]
- This function read file 1 chars by 1 chars and yield lines.
>>> with open("test", 'wb') as f: f.write(b"abc\x00\x01ab\x00cdeF\x00\x01")
14
>>> strings = Strings("test", chars=b"abcde", minimum_chars=3, number_bad_chars=1, accepted_bad_chars=b"\x00")
>>> for line in strings.reader(): print(line)
abc
abcde
>>> import os; os.remove("test")
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
| |