A Python utility.
Project description
wftutil
☤ The Basics
WTF A Python utility / library
☤ 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
☤ Example
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--
''')
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', {})
...
☤ 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
Release history Release notifications | RSS feed
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
Close
Hashes for wtfutil-1.0.27-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7575cea086cdb6a8ec2b5e7c3a569b8042d09b69256bd6d6a1a7d6e3ab5ac69b |
|
MD5 | 89c8cad6e3054a8a4ddf8ffab807fc9a |
|
BLAKE2b-256 | e7c3cdd2440c2122e68ee279db46eb8f9fd1700bf43cfe771ce1051fe7ea3cbc |