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

Side by Side Diff: sitescripts/utils.py

Issue 8793015: Reports - user profile (Closed)
Patch Set: Reports - user profile Created Nov. 7, 2012, 11:39 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/web/showUser.py ('k') | sitescripts/web.py » ('j') | 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-2012 Eyeo GmbH 4 # Copyright (C) 2006-2012 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 os, sys, codecs, subprocess, sitescripts 18 import os, sys, re, codecs, subprocess, sitescripts
19 from time import time 19 from time import time
20 from tempfile import mkstemp 20 from tempfile import mkstemp
21 from ConfigParser import SafeConfigParser 21 from ConfigParser import SafeConfigParser
22 22
23 siteScriptsPath = sitescripts.__path__[0] 23 siteScriptsPath = sitescripts.__path__[0]
24 24
25 class cached(object): 25 class cached(object):
26 """ 26 """
27 Decorator that caches a function's return value for a given number of second s. 27 Decorator that caches a function's return value for a given number of second s.
28 Note that this only works if the string representation of the parameters is 28 Note that this only works if the string representation of the parameters is
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 raise Exception('No config file found. Please put sitescripts.ini into your ho me directory or /etc') 79 raise Exception('No config file found. Please put sitescripts.ini into your ho me directory or /etc')
80 80
81 def setupStderr(stream=sys.stderr): 81 def setupStderr(stream=sys.stderr):
82 """ 82 """
83 Sets up sys.stderr to accept Unicode characters, redirects error output to 83 Sets up sys.stderr to accept Unicode characters, redirects error output to
84 the stream passed in if any. 84 the stream passed in if any.
85 """ 85 """
86 sys.stderr = codecs.getwriter('utf8')(stream) 86 sys.stderr = codecs.getwriter('utf8')(stream)
87 87
88 def anonymizeMail(email):
89 """
90 Anonymizes email to look like a**.n***@g****.c**
91 """
92 return re.sub(r'(?<=[^.@])[^.@]', '*', email)
93
88 def sendMail(template, data): 94 def sendMail(template, data):
89 """ 95 """
90 Sends a mail generated from the template and data given. 96 Sends a mail generated from the template and data given.
91 """ 97 """
92 template = get_template(template, False) 98 template = get_template(template, False)
93 mail = template.render(data) 99 mail = template.render(data)
94 if get_config().get('DEFAULT', 'mailerDebug') == 'yes': 100 if get_config().get('DEFAULT', 'mailerDebug') == 'yes':
95 (handle, path) = mkstemp(prefix='mail_', suffix='.eml', dir='.') 101 (handle, path) = mkstemp(prefix='mail_', suffix='.eml', dir='.')
96 os.close(handle) 102 os.close(handle)
97 f = codecs.open(path, 'wb', encoding='utf-8') 103 f = codecs.open(path, 'wb', encoding='utf-8')
(...skipping 30 matching lines...) Expand all
128 def get_unescaped_template_environment(): 134 def get_unescaped_template_environment():
129 """ 135 """
130 Returns a Jinja2 template environment without autoescaping. Don't use this t o 136 Returns a Jinja2 template environment without autoescaping. Don't use this t o
131 generate HTML files! 137 generate HTML files!
132 """ 138 """
133 from sitescripts.templateFilters import filters 139 from sitescripts.templateFilters import filters
134 import jinja2 140 import jinja2
135 env = jinja2.Environment(loader=jinja2.FileSystemLoader(siteScriptsPath)) 141 env = jinja2.Environment(loader=jinja2.FileSystemLoader(siteScriptsPath))
136 env.filters.update(filters) 142 env.filters.update(filters)
137 return env 143 return env
OLDNEW
« no previous file with comments | « sitescripts/reports/web/showUser.py ('k') | sitescripts/web.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld