diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2011-10-01 20:49:36 +0000 |
---|---|---|
committer | Lorry <lorry@roadtrain.codethink.co.uk> | 2012-09-27 13:27:51 +0000 |
commit | 921ced43c48c1d170452a7b251b94cc96ec8dd44 (patch) | |
tree | 3c4a89176ea67fe4c7bf7b375488361a823c95fa /mercurial/templatefilters.py | |
parent | 9039c805b0a7e36220101323f82735f08a104b37 (diff) | |
download | mercurial-tarball-master.tar.gz |
Imported from /srv/lorry/lorry-area/mercurial-tarball/mercurial-1.9.3.tar.gz.HEADmercurial-1.9.3master
Diffstat (limited to 'mercurial/templatefilters.py')
-rw-r--r-- | mercurial/templatefilters.py | 47 |
1 files changed, 7 insertions, 40 deletions
diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py index b5264f2..389be70 100644 --- a/mercurial/templatefilters.py +++ b/mercurial/templatefilters.py @@ -7,7 +7,6 @@ import cgi, re, os, time, urllib import encoding, node, util -import hbisect def addbreaks(text): """:addbreaks: Any text. Add an XHTML "<br />" tag before the end of @@ -189,13 +188,13 @@ def json(obj): return '"%s"' % jsonescape(u) elif isinstance(obj, unicode): return '"%s"' % jsonescape(obj) - elif util.safehasattr(obj, 'keys'): + elif hasattr(obj, 'keys'): out = [] for k, v in obj.iteritems(): s = '%s: %s' % (json(k), json(v)) out.append(s) return '{' + ', '.join(out) + '}' - elif util.safehasattr(obj, '__iter__'): + elif hasattr(obj, '__iter__'): out = [] for i in obj: out.append(json(i)) @@ -242,29 +241,12 @@ def permissions(flags): return "-rw-r--r--" def person(author): - """:person: Any text. Returns the name before an email address, - interpreting it as per RFC 5322. - - >>> person('foo@bar') - 'foo' - >>> person('Foo Bar <foo@bar>') - 'Foo Bar' - >>> person('"Foo Bar" <foo@bar>') - 'Foo Bar' - >>> person('"Foo \"buz\" Bar" <foo@bar>') - 'Foo "buz" Bar' - >>> # The following are invalid, but do exist in real-life - ... - >>> person('Foo "buz" Bar <foo@bar>') - 'Foo "buz" Bar' - >>> person('"Foo Bar <foo@bar>') - 'Foo Bar' - """ - if '@' not in author: + """:person: Any text. Returns the text before an email address.""" + if not '@' in author: return author f = author.find('<') if f != -1: - return author[:f].strip(' "').replace('\\"', '"') + return author[:f].rstrip() f = author.find('@') return author[:f].replace('.', ' ') @@ -286,14 +268,6 @@ def short(text): """ return text[:12] -def shortbisect(text): - """:shortbisect: Any text. Treats `text` as a bisection status, and - returns a single-character representing the status (G: good, B: bad, - S: skipped, U: untested, I: ignored). Returns single space if `text` - is not a valid bisection status. - """ - return hbisect.shortlabel(text) or ' ' - def shortdate(text): """:shortdate: Date. Returns a date like "2006-09-18".""" return util.shortdate(text) @@ -305,7 +279,7 @@ def stringify(thing): """:stringify: Any type. Turns the value into text by converting values into text and concatenating them. """ - if util.safehasattr(thing, '__iter__') and not isinstance(thing, str): + if hasattr(thing, '__iter__') and not isinstance(thing, str): return "".join([stringify(t) for t in thing if t is not None]) return str(thing) @@ -336,14 +310,9 @@ def urlescape(text): return urllib.quote(text) def userfilter(text): - """:user: Any text. Returns a short representation of a user name or email - address.""" + """:user: Any text. Returns the user portion of an email address.""" return util.shortuser(text) -def emailuser(text): - """:emailuser: Any text. Returns the user portion of an email address.""" - return util.emailuser(text) - def xmlescape(text): text = (text .replace('&', '&') @@ -378,7 +347,6 @@ filters = { "rfc3339date": rfc3339date, "rfc822date": rfc822date, "short": short, - "shortbisect": shortbisect, "shortdate": shortdate, "stringescape": stringescape, "stringify": stringify, @@ -387,7 +355,6 @@ filters = { "tabindent": tabindent, "urlescape": urlescape, "user": userfilter, - "emailuser": emailuser, "xmlescape": xmlescape, } |