stringtools (Stringtools)

Author:

Description:

This Module supports functionality around string operations.

Submodules:

Unittest:

See also the unittest documentation.

Module Documentation:

stringtools.gzip_compress(s, compresslevel=9)

Method to compress a stream of bytes.

Parameters:
  • s (str) – The bytestream (string) to be compressed

  • compresslevel (int) – An optional compressionn level (default is 9)

Returns:

The compressed bytestream

Return type:

str

Example:

import sys
sys.path.append('../..')

import stringtools
import report

report.stdoutLoggingConfigure(log_name_lvl=[('root', 'DEBUG'), ])
print(stringtools.hexlify(stringtools.gzip_compress(15 * b'\x00' + 15 * b'\xff')))

Will result to the following output:

(26): 1f 8b 08 00 20 25 56 67 02 ff 63 60 40 01 ff 51 01 00 2d 8a 7d de 1e 00 00 00
stringtools.gzip_extract(s)

Method to extract data from a compress stream of bytes.

Parameters:

s (str) – The compressed bytestream (string) to be extracted

Returns:

The extracted data

Return type:

str

Example:

import sys
sys.path.append('../..')

import stringtools
import report

report.stdoutLoggingConfigure(log_name_lvl=[('root', 'DEBUG'), ])
print(stringtools.hexlify(stringtools.gzip_extract(b'\x1f\x8b\x08\x00\xd0\x82\xe5\x5c\x02\xff\x63\x60\x40\x01\xff\x51\x01\x00\x2d\x8a\x7d\xde\x1e\x00\x00\x00')))

Will result to the following output:

(30): 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
stringtools.hexlify(s)

Method to hexlify a string.

Parameters:

s (str) – A string including the bytes to be hexlified.

Returns:

The hexlified string

Return type:

str

Example:

import sys
sys.path.append('../..')

import stringtools

print(stringtools.hexlify(b'A stringexample with non printable characters like \x12'))

Will result to the following output:

(52): 41 20 73 74 72 69 6e 67 65 78 61 6d 70 6c 65 20 77 69 74 68 20 6e 6f 6e 20 70 72 69 6e 74 61 62 6c 65 20 63 68 61 72 61 63 74 65 72 73 20 6c 69 6b 65 20 12