comparison mercurial/templatefilters.py @ 37084:f0b6fbea00cf

stringutil: bulk-replace call sites to point to new module This might conflict with other patches floating around, sorry.
author Yuya Nishihara <yuya@tcha.org>
date Thu, 22 Mar 2018 21:56:20 +0900
parents 32f9b7e3f056
children fb7140f1d09d
comparison
equal deleted inserted replaced
37083:f99d64e8a4e4 37084:f0b6fbea00cf
19 registrar, 19 registrar,
20 templateutil, 20 templateutil,
21 url, 21 url,
22 util, 22 util,
23 ) 23 )
24 from .utils import dateutil 24 from .utils import (
25 dateutil,
26 stringutil,
27 )
25 28
26 urlerr = util.urlerr 29 urlerr = util.urlerr
27 urlreq = util.urlreq 30 urlreq = util.urlreq
28 31
29 if pycompat.ispy3: 32 if pycompat.ispy3:
126 def email(text): 129 def email(text):
127 """Any text. Extracts the first string that looks like an email 130 """Any text. Extracts the first string that looks like an email
128 address. Example: ``User <user@example.com>`` becomes 131 address. Example: ``User <user@example.com>`` becomes
129 ``user@example.com``. 132 ``user@example.com``.
130 """ 133 """
131 return util.email(text) 134 return stringutil.email(text)
132 135
133 @templatefilter('escape') 136 @templatefilter('escape')
134 def escape(text): 137 def escape(text):
135 """Any text. Replaces the special XML/XHTML characters "&", "<" 138 """Any text. Replaces the special XML/XHTML characters "&", "<"
136 and ">" with XML entities, and filters out NUL characters. 139 and ">" with XML entities, and filters out NUL characters.
160 encoding.unitolocal(uctext[w:])) 163 encoding.unitolocal(uctext[w:]))
161 break 164 break
162 yield text[start:m.start(0)], m.group(1) 165 yield text[start:m.start(0)], m.group(1)
163 start = m.end(1) 166 start = m.end(1)
164 167
165 return "".join([util.wrap(space_re.sub(' ', util.wrap(para, width)), 168 return "".join([stringutil.wrap(space_re.sub(' ',
166 width, initindent, hangindent) + rest 169 stringutil.wrap(para, width)),
170 width, initindent, hangindent) + rest
167 for para, rest in findparas()]) 171 for para, rest in findparas()])
168 172
169 @templatefilter('fill68') 173 @templatefilter('fill68')
170 def fill68(text): 174 def fill68(text):
171 """Any text. Wraps the text to fit in 68 columns.""" 175 """Any text. Wraps the text to fit in 68 columns."""
367 """Any text. Split text into a list of lines.""" 371 """Any text. Split text into a list of lines."""
368 return templateutil.hybridlist(text.splitlines(), name='line') 372 return templateutil.hybridlist(text.splitlines(), name='line')
369 373
370 @templatefilter('stringescape') 374 @templatefilter('stringescape')
371 def stringescape(text): 375 def stringescape(text):
372 return util.escapestr(text) 376 return stringutil.escapestr(text)
373 377
374 @templatefilter('stringify') 378 @templatefilter('stringify')
375 def stringify(thing): 379 def stringify(thing):
376 """Any type. Turns the value into text by converting values into 380 """Any type. Turns the value into text by converting values into
377 text and concatenating them. 381 text and concatenating them.
410 414
411 @templatefilter('user') 415 @templatefilter('user')
412 def userfilter(text): 416 def userfilter(text):
413 """Any text. Returns a short representation of a user name or email 417 """Any text. Returns a short representation of a user name or email
414 address.""" 418 address."""
415 return util.shortuser(text) 419 return stringutil.shortuser(text)
416 420
417 @templatefilter('emailuser') 421 @templatefilter('emailuser')
418 def emailuser(text): 422 def emailuser(text):
419 """Any text. Returns the user portion of an email address.""" 423 """Any text. Returns the user portion of an email address."""
420 return util.emailuser(text) 424 return stringutil.emailuser(text)
421 425
422 @templatefilter('utf8') 426 @templatefilter('utf8')
423 def utf8(text): 427 def utf8(text):
424 """Any text. Converts from the local character encoding to UTF-8.""" 428 """Any text. Converts from the local character encoding to UTF-8."""
425 return encoding.fromlocal(text) 429 return encoding.fromlocal(text)