#!/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' #