diff configmix/variables.py @ 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 f529ca46dd50
children 83f76a41cf7c
line wrap: on
line diff
--- 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