comparison mercurial/templatefilters.py @ 28883:032c4c2f802a

pycompat: switch to util.urlreq/util.urlerr for py3 compat
author timeless <timeless@mozdev.org>
date Wed, 06 Apr 2016 23:22:12 +0000
parents 11f623b5668f
children 53865692a354
comparison
equal deleted inserted replaced
28882:800ec7c048b0 28883:032c4c2f802a
9 9
10 import cgi 10 import cgi
11 import os 11 import os
12 import re 12 import re
13 import time 13 import time
14 import urllib
15 14
16 from . import ( 15 from . import (
17 encoding, 16 encoding,
18 hbisect, 17 hbisect,
19 node, 18 node,
20 registrar, 19 registrar,
21 templatekw, 20 templatekw,
22 util, 21 util,
23 ) 22 )
23
24 urlerr = util.urlerr
25 urlreq = util.urlreq
24 26
25 # filters are callables like: 27 # filters are callables like:
26 # fn(obj) 28 # fn(obj)
27 # with: 29 # with:
28 # obj - object to be filtered (text, date, list and so on) 30 # obj - object to be filtered (text, date, list and so on)
297 def revescape(text): 299 def revescape(text):
298 """Any text. Escapes all "special" characters, except @. 300 """Any text. Escapes all "special" characters, except @.
299 Forward slashes are escaped twice to prevent web servers from prematurely 301 Forward slashes are escaped twice to prevent web servers from prematurely
300 unescaping them. For example, "@foo bar/baz" becomes "@foo%20bar%252Fbaz". 302 unescaping them. For example, "@foo bar/baz" becomes "@foo%20bar%252Fbaz".
301 """ 303 """
302 return urllib.quote(text, safe='/@').replace('/', '%252F') 304 return urlreq.quote(text, safe='/@').replace('/', '%252F')
303 305
304 @templatefilter('rfc3339date') 306 @templatefilter('rfc3339date')
305 def rfc3339date(text): 307 def rfc3339date(text):
306 """Date. Returns a date using the Internet date format 308 """Date. Returns a date using the Internet date format
307 specified in RFC 3339: "2009-08-18T13:00:13+02:00". 309 specified in RFC 3339: "2009-08-18T13:00:13+02:00".
382 @templatefilter('urlescape') 384 @templatefilter('urlescape')
383 def urlescape(text): 385 def urlescape(text):
384 """Any text. Escapes all "special" characters. For example, 386 """Any text. Escapes all "special" characters. For example,
385 "foo bar" becomes "foo%20bar". 387 "foo bar" becomes "foo%20bar".
386 """ 388 """
387 return urllib.quote(text) 389 return urlreq.quote(text)
388 390
389 @templatefilter('user') 391 @templatefilter('user')
390 def userfilter(text): 392 def userfilter(text):
391 """Any text. Returns a short representation of a user name or email 393 """Any text. Returns a short representation of a user name or email
392 address.""" 394 address."""