add conversion to remove invisible char then strip

pull/3747/head
johnnylau 2 years ago
parent c9a7345228
commit 62621ce18c
No known key found for this signature in database
GPG Key ID: 51660AB66999DC62

@ -407,6 +407,7 @@ _CONVERSIONS = {
"s": str,
"r": repr,
"a": ascii,
"i": util.remove_invisible_chars_strip,
}
_FORMAT_SPECIFIERS = {
"?": _parse_optional,

@ -21,6 +21,7 @@ import datetime
import functools
import itertools
import subprocess
import unicodedata
import urllib.parse
from http.cookiejar import Cookie
from email.utils import mktime_tz, parsedate_tz
@ -209,6 +210,10 @@ def to_string(value):
return ", ".join(map(str, value))
return str(value)
def remove_invisible_chars_strip(text):
"""Remove all invisible characters from 'text' then strip"""
return "".join(c for c in text if unicodedata.category(c)[0] != "C").strip()
def datetime_to_timestamp(dt):
"""Convert naive UTC datetime to timestamp"""

Loading…
Cancel
Save