Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: sitescripts/templateFilters.py

Issue 6246174612783104: Issue 535 - Contact form cannot deal with commas in sender`s name (Closed)
Patch Set: Created May 22, 2014, 8:13 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sitescripts/reports/bin/mailDigests.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus web scripts, 3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2014 Eyeo GmbH 4 # Copyright (C) 2006-2014 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details. 13 # GNU General Public License for more details.
14 # 14 #
15 # You should have received a copy of the GNU General Public License 15 # You should have received a copy of the GNU General Public License
16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
17 17
18 import re, email.header, urllib, time, json 18 import re, email.header, email.utils, urllib, time, json
19 from datetime import date 19 from datetime import date
20 from jinja2.utils import Markup 20 from jinja2.utils import Markup
21 from urlparse import urlparse 21 from urlparse import urlparse
22 22
23 def formattime(value): 23 def formattime(value):
24 try: 24 try:
25 return time.strftime('%Y-%m-%d %H:%M UTC', time.gmtime(int(value))) 25 return time.strftime('%Y-%m-%d %H:%M UTC', time.gmtime(int(value)))
26 except Exception, e: 26 except Exception, e:
27 return 'unknown' 27 return 'unknown'
28 28
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 )) 121 ))
122 else: 122 else:
123 value.sort(lambda a, b: ( 123 value.sort(lambda a, b: (
124 cmp(a.type, b.type) or 124 cmp(a.type, b.type) or
125 cmp(a.deprecated, b.deprecated) or 125 cmp(a.deprecated, b.deprecated) or
126 cmp(a.name.lower(), b.name.lower()) 126 cmp(a.name.lower(), b.name.lower())
127 )) 127 ))
128 return value 128 return value
129 129
130 def formatmime(text): 130 def formatmime(text):
131 # See http://bugs.python.org/issue5871 (not really fixed), Header() will
132 # happily accept non-printable characters including newlines. Make sure to
133 # remove them.
134 text = re.sub(r'[\x00-\x1F]', '', text)
131 return email.header.Header(text).encode() 135 return email.header.Header(text).encode()
132 136
137 def emailaddr((name, addr)):
138 return email.utils.formataddr((name, addr))
139
133 def ljust(value, width=80): 140 def ljust(value, width=80):
134 return unicode(value).ljust(width) 141 return unicode(value).ljust(width)
135 142
136 def rjust(value, width=80): 143 def rjust(value, width=80):
137 return unicode(value).rjust(width) 144 return unicode(value).rjust(width)
138 145
139 def ltruncate(value, length=255, end='...'): 146 def ltruncate(value, length=255, end='...'):
140 value = unicode(value) 147 value = unicode(value)
141 if len(value) <= length: 148 if len(value) <= length:
142 return value 149 return value
(...skipping 25 matching lines...) Expand all
168 filters = { 175 filters = {
169 'formattime': formattime, 176 'formattime': formattime,
170 'timerelative': formatrelativetime, 177 'timerelative': formatrelativetime,
171 'url': formaturl, 178 'url': formaturl,
172 'keepnewlines': formatnewlines, 179 'keepnewlines': formatnewlines,
173 'filtercount': formatfiltercount, 180 'filtercount': formatfiltercount,
174 'buglinks': formatBugLinks, 181 'buglinks': formatBugLinks,
175 'urlencode': urlencode, 182 'urlencode': urlencode,
176 'subscriptionSort': subscriptionSort, 183 'subscriptionSort': subscriptionSort,
177 'mime': formatmime, 184 'mime': formatmime,
185 'emailaddr': emailaddr,
Sebastian Noack 2014/05/23 13:16:18 There is no need to define the emailaddr function
Wladimir Palant 2014/05/23 13:28:29 True, in the initial version this wasn't the case.
178 'ljust': ljust, 186 'ljust': ljust,
179 'rjust': rjust, 187 'rjust': rjust,
180 'ltruncate': ltruncate, 188 'ltruncate': ltruncate,
181 'weekday': formatweekday, 189 'weekday': formatweekday,
182 'bytes': formatbytes, 190 'bytes': formatbytes,
183 'json': toJSON, 191 'json': toJSON,
184 } 192 }
OLDNEW
« no previous file with comments | « sitescripts/reports/bin/mailDigests.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld