Skip to main content

A Python utility.

Project description

wftutil

☤ The Basics

WTF A Python utility / library

https://github.com/vicrack

☤ Installation

Of course, the recommended installation method is pipenv <http://pipenv.org>_::

pipenv install wtfutil

or

pip install wtfutil

☤ Features

fileutil
sqlutil
notifyutil
httputil
hashutil
strutil

Internally, numerous optimizations have been implemented for Python requests, such as resolving HTTPS proxy issues on Windows, removing SSL verification, and addressing urllib3 warnings, among others

urllib3.disable_warnings() remove_ssl_verify() patch_redirect() patch_getproxies()

☤ Example

☤ HTTP Request

from wtfutil import util
# 1. get requests session
# def requests_session(proxies=False, max_retries=1, timeout=30, debug=False, base_url=None, user_agent=None, use_cache=None):
req1 = util.requests_session(timeout=30, max_retries=1)
req1.post('http://localhost:8080/xxx')

req2 = util.requests_session(base_url='http://localhost:8080', timeout=30, max_retries=1)
req2.post('/xxx/update')
from wtfutil import util
# send http raw
util.httpraw('''
POST /a/bbbb?id=1&type=jsp HTTP/1.1
Host: abc.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:88.0) Gecko/20100101 Firefox/88.0
Content-Length: 1
Accept-Charset: utf-8
Content-Type: multipart/; boundary=----WebKitFormBoundaryzxcxzcxz
Accept-Encoding: gzip

------WebKitFormBoundaryzxcxzcxz
Content-Disposition: form-data; name="upload";filename="f.jsp"

test
------WebKitFormBoundaryzxcxzcxz
Content-Disposition: form-data; name="submit"

submit
------WebKitFormBoundaryzxcxzcxz--
    ''')

☤ String、File IO

from wtfutil import util
# read and write file
# def read_lines(filepath, encoding='utf-8', not_exists_ok: bool = False) -> list:
urls = util.read_lines('input_url.txt')
# def read_text(filepath, encoding='utf-8', not_exists_ok: bool = False) -> str:
data = util.read_text('input.txt')
data_bytes = util.read_bytes('input.txt')
# def write_text(filepath, content, mode='w', encoding='utf-8'):
util.write_text('output.txt', 'test')
util.write_lines('output.txt', ['te','st'])
...
# like py3.9 removesuffix
util.removesuffix('test123456', '456')
util.removeprefix('test123456', 'test')
util.str_to_bool('yes')

util.write_json('/tmp/test.json', {})

☤ Encode / Decode

from wtfutil import util

# encode, decode
util.base64encode(data)
util.base64decode(data)
util.base64urlencode(data)
util.base64urldecode(data)
util.uuencode(data)
util.url_encode_all(data)

# hash
util.str_md5('xxx')
util.str_sha1('xxx')
util.file_md5('/etc/hosts')
util.str_sha1('/etc/hosts')
...

☤ Encrypt / Decrypt

from wtfutil import util

util.rsa_encrypt
util.rsa_decrypt
util.des_encrypt
util.des_decrypt
...

☤ Thank You

Thanks for checking this library out! I hope you find it useful.

Of course, there's always room for improvement. Feel free to https://github.com/vicrack

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

wtfutil-1.0.38-py2.py3-none-any.whl (27.0 kB view hashes)

Uploaded Python 2 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