changeset 347:d7daec119383

New filter function "urlquote_plus" which quotes a space into a '+' character
author Franz Glasner <fzglas.hg@dom66.de>
date Thu, 10 Jun 2021 22:02:09 +0200
parents 1c207cad532a
children 396d8d9aaead
files CHANGES.txt configmix/variables.py docs/introduction.rst
diffstat 3 files changed, 33 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES.txt	Mon May 10 09:28:14 2021 +0200
+++ b/CHANGES.txt	Thu Jun 10 22:02:09 2021 +0200
@@ -12,6 +12,13 @@
 Pre-1.0 Series
 --------------
 
+n/a (not yet)
+~~~~~~~~~~~~~
+
+- **[feature]**
+  New filter function :py:func:`urlquote_plus`
+
+
 0.14 (2021-05-10)
 ~~~~~~~~~~~~~~~~~
 
--- a/configmix/variables.py	Mon May 10 09:28:14 2021 +0200
+++ b/configmix/variables.py	Thu Jun 10 22:02:09 2021 +0200
@@ -163,25 +163,45 @@
 
     @filter("urlquote")
     def urlquote(config, v):
-        """Filter function to replace all special characters in string using
-        the ``%xx`` escape
+        """Filter function to replace all special characters in string `v`
+        using the ``%xx`` escape
 
         """
         from urllib import quote
         return quote(v.encode("utf-8"), safe=b"").decode("utf-8")
 
+
+    @filter("urlquote_plus")
+    def urlquote_plus(config, v):
+        """Filter function to replace all special characters (including
+        spaces) in string `v` using the ``%xx`` escape
+
+        """
+        from urllib import quote_plus
+        return quote_plus(v.encode("utf-8"), safe=b"").decode("utf-8")
+
 else:
 
     @filter("urlquote")
     def urlquote(config, v):
-        """Filter function to replace all special characters in string using
-        the ``%xx`` escape
+        """Filter function to replace all special characters in string `v`
+        using the ``%xx`` escape
 
         """
         from urllib.parse import quote
         return quote(v, safe="")
 
 
+    @filter("urlquote_plus")
+    def urlquote_plus(config, v):
+        """Filter function to replace all special characters (including
+        spaces) in string `v` using the ``%xx`` escape
+
+        """
+        from urllib.parse import quote_plus
+        return quote_plus(v, safe="")
+
+
 @filter("saslprep")
 def saslprep(config, v):
     """Filter function to perform a `SASLprep` according to :rfc:`4013` on
--- a/docs/introduction.rst	Mon May 10 09:28:14 2021 +0200
+++ b/docs/introduction.rst	Thu Jun 10 22:02:09 2021 +0200
@@ -403,6 +403,8 @@
 
   ``urlquote``
 
+  ``urlquote_plus``
+
   ``saslprep``
 
   ``normpath``