diff --git a/setup.cfg b/setup.cfg index 9780042..4020402 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = yamlhttpforms -version = 0.0.4 +version = 0.0.5 author = Daniil F. author_email = mail@placeholder123.to description = HTTP forms defined in YAML diff --git a/src/yamlhttpforms/html.py b/src/yamlhttpforms/html.py index 37610f7..70463a3 100644 --- a/src/yamlhttpforms/html.py +++ b/src/yamlhttpforms/html.py @@ -1,4 +1,6 @@ +import sys from typing import Dict, TYPE_CHECKING + from bs4.element import Tag if TYPE_CHECKING: @@ -8,6 +10,8 @@ if TYPE_CHECKING: INPUT, SELECT, OPTION = 'input', 'select', 'option' NAME, VALUE, SELECTED = 'name', 'value', 'selected' +NON_PRINTABLE_TO_NONE = {code: None for code in range(sys.maxunicode + 1) if not chr(code).isprintable()} + class WrongInterface(Exception): pass @@ -29,6 +33,10 @@ class UnknownField(WrongInterface): pass +def printable_only(string: str) -> str: + return string.translate(NON_PRINTABLE_TO_NONE) + + def check_select_field_options(field_tag: Tag, field_interface: 'FormField', check_defaults: bool = True) -> None: """ Compares the `options` and `default` attributes of a `'FormField'` object with the options of its HTML counterpart. @@ -45,7 +53,7 @@ def check_select_field_options(field_tag: Tag, field_interface: 'FormField', che `FieldInterfaceWrong` if the `default` is not equal to the value of the