add 'U' conversion for format strings to unquote their content

(#74)
This commit is contained in:
Mike Fährmann 2018-02-25 21:57:59 +01:00
parent 8cdce21dcb
commit 2fad0b1f1b
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 5 additions and 0 deletions

View File

@ -284,6 +284,7 @@ class Formatter():
- "u": calls str.upper
- "c": calls str.capitalize
- "C": calls string.capwords
- "U": calls urllib.parse.unquote
- Example: {f!l} -> "example"; {f!u} -> "EXAMPLE"
Extra Format Specifiers:
@ -298,6 +299,7 @@ class Formatter():
"u": str.upper,
"c": str.capitalize,
"C": string.capwords,
"U": urllib.parse.unquote,
"s": str,
"r": repr,
"a": ascii,

View File

@ -145,6 +145,7 @@ class TestFormatter(unittest.TestCase):
kwdict = {
"a": "hElLo wOrLd",
"b": "äöü",
"u": "%27%3C%20/%20%3E%27",
"name": "Name",
"title1": "Title",
"title2": "",
@ -157,6 +158,8 @@ class TestFormatter(unittest.TestCase):
self._run_test("{a!u}", "HELLO WORLD")
self._run_test("{a!c}", "Hello world")
self._run_test("{a!C}", "Hello World")
self._run_test("{a!U}", self.kwdict["a"])
self._run_test("{u!U}", "'< / >'")
self._run_test("{a!s}", self.kwdict["a"])
self._run_test("{a!r}", "'" + self.kwdict["a"] + "'")
self._run_test("{a!a}", "'" + self.kwdict["a"] + "'")