From aa84238845256d484e27b62643ab3d59563e5195 Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Fri, 1 Feb 2019 23:01:31 -0200 Subject: [PATCH] I give up for now, might come back to this later --- README.md | 3 +- htformtool.py | 493 +++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 5 + 3 files changed, 500 insertions(+), 1 deletion(-) create mode 100755 htformtool.py create mode 100644 requirements.txt diff --git a/README.md b/README.md index 7fcae87..1b8164c 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ -# python.htformtool +# HTFormTool +An attempt at passing off a very basic CLI tool as some sort of web browser. diff --git a/htformtool.py b/htformtool.py new file mode 100755 index 0000000..218daa7 --- /dev/null +++ b/htformtool.py @@ -0,0 +1,493 @@ +#!/usr/bin/env python3 + +import requests +from bs4 import BeautifulSoup +import click + +from enum import Enum + +VERSION = '0.1.0' + +sess = requests.Session() +base_headers = { + # request (x)html form + 'Accept': 'text/html,application/xhtml+xml', + 'User-Agent': 'htformtool/{version}'.format(version=VERSION), + } +# +post_headers = { + # request confirmation code + 'Accept': 'text/plain', + } + +def hide_ua(ctx, param, value): + if not value or ctx.resilient_parsing: + return + base_headers['User-Agent'] = None + +def split_on_ascii_whitespace(inp): + start_position = 0 + end_position = 0 + tokens = [] + while start_position < len(inp) and inp[start_position] in '\x09\x0A\x0C\x0D\x20': + start_position = start_position + 1 + while start_position < len(inp): + end_position = start_position + while end_position < len(inp) and inp[end_position] not in '\x09\x0A\x0C\x0D\x20': + end_position = end_position + 1 + tokens.append(inp[start_position:end_position]) + start_position = end_position + while start_position < len(inp) and inp[start_position] in '\x09\x0A\x0C\x0D\x20': + start_position = start_position + 1 + return tokens + +def ascii_lowercase(s): + import string + return s.translate(str.maketrans(string.ascii_uppercase, string.ascii_lowercase)) + +def get_encoding(label): + # fuck + if ascii_lowercase(label) not in ('unicode-1-1-utf-8', 'utf-8', 'utf8'): + raise NotImplementedError + import codecs + return codecs.lookup('utf-8') + +import re +newline_normalize = re.compile('\x0D(?!\x0A)|(? types + HIDDEN = 'hidden' + TEXT = 'text' + SEARCH = 'search' + TELEPHONE = 'tel' + URL = 'url' + EMAIL = 'email' + PASSWORD = 'password' + DATE = 'date' + MONTH = 'month' + WEEK = 'week' + TIME = 'time' + LOCAL_DATE_AND_TIME = 'datetime-local' + NUMBER = 'number' + RANGE = 'range' + COLOR = 'color' + CHECKBOX = 'checkbox' + RADIO = 'radio' + FILE = 'file' + SUBMIT = 'submit' + IMAGE = 'image' + RESET = 'reset' + BUTTON = 'button' + + # custom, htformtool-specific types + CREDENTIALS = 'credentials' + + # non- types + TEXTAREA = 'textarea' + SELECT = 'select' + + #