##// END OF EJS Templates
stringutil: move person function from templatefilters...
Connor Sheehan -
r37173:fb7140f1 default
parent child Browse files
Show More
@@ -292,29 +292,8 b' def permissions(flags):'
292 def person(author):
292 def person(author):
293 """Any text. Returns the name before an email address,
293 """Any text. Returns the name before an email address,
294 interpreting it as per RFC 5322.
294 interpreting it as per RFC 5322.
295
296 >>> person(b'foo@bar')
297 'foo'
298 >>> person(b'Foo Bar <foo@bar>')
299 'Foo Bar'
300 >>> person(b'"Foo Bar" <foo@bar>')
301 'Foo Bar'
302 >>> person(b'"Foo \"buz\" Bar" <foo@bar>')
303 'Foo "buz" Bar'
304 >>> # The following are invalid, but do exist in real-life
305 ...
306 >>> person(b'Foo "buz" Bar <foo@bar>')
307 'Foo "buz" Bar'
308 >>> person(b'"Foo Bar <foo@bar>')
309 'Foo Bar'
310 """
295 """
311 if '@' not in author:
296 return stringutil.person(author)
312 return author
313 f = author.find('<')
314 if f != -1:
315 return author[:f].strip(' "').replace('\\"', '"')
316 f = author.find('@')
317 return author[:f].replace('.', ' ')
318
297
319 @templatefilter('revescape')
298 @templatefilter('revescape')
320 def revescape(text):
299 def revescape(text):
@@ -131,6 +131,33 b' def email(author):'
131 r = None
131 r = None
132 return author[author.find('<') + 1:r]
132 return author[author.find('<') + 1:r]
133
133
134 def person(author):
135 """Returns the name before an email address,
136 interpreting it as per RFC 5322
137
138 >>> person(b'foo@bar')
139 'foo'
140 >>> person(b'Foo Bar <foo@bar>')
141 'Foo Bar'
142 >>> person(b'"Foo Bar" <foo@bar>')
143 'Foo Bar'
144 >>> person(b'"Foo \"buz\" Bar" <foo@bar>')
145 'Foo "buz" Bar'
146 >>> # The following are invalid, but do exist in real-life
147 ...
148 >>> person(b'Foo "buz" Bar <foo@bar>')
149 'Foo "buz" Bar'
150 >>> person(b'"Foo Bar <foo@bar>')
151 'Foo Bar'
152 """
153 if '@' not in author:
154 return author
155 f = author.find('<')
156 if f != -1:
157 return author[:f].strip(' "').replace('\\"', '"')
158 f = author.find('@')
159 return author[:f].replace('.', ' ')
160
134 _correctauthorformat = remod.compile(br'^[^<]+\s\<[^<>]+@[^<>]+\>$')
161 _correctauthorformat = remod.compile(br'^[^<]+\s\<[^<>]+@[^<>]+\>$')
135
162
136 def isauthorwellformed(author):
163 def isauthorwellformed(author):
General Comments 0
You need to be logged in to leave comments. Login now