Skip to main content

Removes control characters / non-printing characters from strings and binaries

Project description

A function to remove control characters / non-printing characters from strings and binaries
$pip install get-the-hell-out-of-here

from get_the_hell_out_of_here import remove_escaped_characters

import numpy as np

test1 = np.array(["hi, my friend", "are you fine?"]).tobytes() #lets create some test data



#numpy as bytes

b"h\x00\x00\x00i\x00\x00\x00,\x00\x00\x00 \x00\x00\x00m\x00\x00\x00y\x00\x00\x00 \x00\x00\x00f\x00\x00\x00r\x00\x00\x00i\x00\x00\x00e\x00\x00\x00n\x00\x00\x00d\x00\x00\x00a\x00\x00\x00r\x00\x00\x00e\x00\x00\x00 \x00\x00\x00y\x00\x00\x00o\x00\x00\x00u\x00\x00\x00 \x00\x00\x00f\x00\x00\x00i\x00\x00\x00n\x00\x00\x00e\x00\x00\x00?\x00\x00\x00"

print(remove_escaped_characters(test1))

#Result:  b'hi, my friendare you fine?'



test2 = b"h\\x00\\x00\\x00i\\x00\\x00\\x00,\\x00\\x00\\x00 \\x00\\x00\\x00m\\x00\\x00\\x00y\\x00\\x00\\x00 \\x00\\x00\\x00f\\x00\\x00\\x00r\\x00\\x00\\x00i\\x00\\x00\\x00e\\x00\\x00\\x00n\\x00\\x00\\x00d\\x00\\x00\\x00a\\x00\\x00\\x00r\\x00\\x00\\x00e\\x00\\x00\\x00 \\x00\\x00\\x00y\\x00\\x00\\x00o\\x00\\x00\\x00u\\x00\\x00\\x00 \\x00\\x00\\x00f\\x00\\x00\\x00i\\x00\\x00\\x00n\\x00\\x00\\x00e\\x00\\x00\\x00?\\x00\\x00\\x00" #double escaped

print(remove_escaped_characters(test2))

# Result:   b'hi, my friendare you fine?'





test3 = "h\x00\x00\x00i\x00\x00\x00,\x00\x00\x00 \x00\x00\x00m\x00\x00\x00y\x00\x00\x00 \x00\x00\x00f\x00\x00\x00r\x00\x00\x00i\x00\x00\x00e\x00\x00\x00n\x00\x00\x00d\x00\x00\x00a\x00\x00\x00r\x00\x00\x00e\x00\x00\x00 \x00\x00\x00y\x00\x00\x00o\x00\x00\x00u\x00\x00\x00 \x00\x00\x00f\x00\x00\x00i\x00\x00\x00n\x00\x00\x00e\x00\x00\x00?\x00\x00\x00" #as string

print(remove_escaped_characters(test3))

#Result: hi, my friendare you fine?



test4 = "h\\x00\\x00\\x00i\\x00\\x00\\x00,\\x00\\x00\\x00 \\x00\\x00\\x00m\\x00\\x00\\x00y\\x00\\x00\\x00 \\x00\\x00\\x00f\\x00\\x00\\x00r\\x00\\x00\\x00i\\x00\\x00\\x00e\\x00\\x00\\x00n\\x00\\x00\\x00d\\x00\\x00\\x00a\\x00\\x00\\x00r\\x00\\x00\\x00e\\x00\\x00\\x00 \\x00\\x00\\x00y\\x00\\x00\\x00o\\x00\\x00\\x00u\\x00\\x00\\x00 \\x00\\x00\\x00f\\x00\\x00\\x00i\\x00\\x00\\x00n\\x00\\x00\\x00e\\x00\\x00\\x00?\\x00\\x00\\x00"  #as string - double escaped

print(remove_escaped_characters(test4))

#Result: hi, my friendare you fine?

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

get_the_hell_out_of_here-0.12.tar.gz (5.2 kB view hashes)

Uploaded Source

Built Distribution

get_the_hell_out_of_here-0.12-py3-none-any.whl (5.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page