comparison 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
comparison
equal deleted inserted replaced
346:1c207cad532a 347:d7daec119383
161 # 161 #
162 if PY2: 162 if PY2:
163 163
164 @filter("urlquote") 164 @filter("urlquote")
165 def urlquote(config, v): 165 def urlquote(config, v):
166 """Filter function to replace all special characters in string using 166 """Filter function to replace all special characters in string `v`
167 the ``%xx`` escape 167 using the ``%xx`` escape
168 168
169 """ 169 """
170 from urllib import quote 170 from urllib import quote
171 return quote(v.encode("utf-8"), safe=b"").decode("utf-8") 171 return quote(v.encode("utf-8"), safe=b"").decode("utf-8")
172 172
173
174 @filter("urlquote_plus")
175 def urlquote_plus(config, v):
176 """Filter function to replace all special characters (including
177 spaces) in string `v` using the ``%xx`` escape
178
179 """
180 from urllib import quote_plus
181 return quote_plus(v.encode("utf-8"), safe=b"").decode("utf-8")
182
173 else: 183 else:
174 184
175 @filter("urlquote") 185 @filter("urlquote")
176 def urlquote(config, v): 186 def urlquote(config, v):
177 """Filter function to replace all special characters in string using 187 """Filter function to replace all special characters in string `v`
178 the ``%xx`` escape 188 using the ``%xx`` escape
179 189
180 """ 190 """
181 from urllib.parse import quote 191 from urllib.parse import quote
182 return quote(v, safe="") 192 return quote(v, safe="")
193
194
195 @filter("urlquote_plus")
196 def urlquote_plus(config, v):
197 """Filter function to replace all special characters (including
198 spaces) in string `v` using the ``%xx`` escape
199
200 """
201 from urllib.parse import quote_plus
202 return quote_plus(v, safe="")
183 203
184 204
185 @filter("saslprep") 205 @filter("saslprep")
186 def saslprep(config, v): 206 def saslprep(config, v):
187 """Filter function to perform a `SASLprep` according to :rfc:`4013` on 207 """Filter function to perform a `SASLprep` according to :rfc:`4013` on