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

Side by Side Diff: sitescripts/utils.py

Issue 8625042: Reports - user usefullness (Closed)
Patch Set: Reports - user usefulness Created Oct. 19, 2012, 12:54 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This Source Code is subject to the terms of the Mozilla Public License 3 # This Source Code is subject to the terms of the Mozilla Public License
4 # version 2.0 (the "License"). You can obtain a copy of the License at 4 # version 2.0 (the "License"). You can obtain a copy of the License at
5 # http://mozilla.org/MPL/2.0/. 5 # http://mozilla.org/MPL/2.0/.
6 6
7 import os, sys, codecs, subprocess, sitescripts 7 import os, sys, codecs, subprocess, sitescripts
8 from time import time 8 from time import time
9 from tempfile import mkstemp 9 from tempfile import mkstemp
10 from ConfigParser import SafeConfigParser 10 from ConfigParser import SafeConfigParser
11 11
12 siteScriptsPath = sitescripts.__path__[0] 12 siteScriptsPath = sitescripts.__path__[0]
13 13
14 class memoize:
15 """
16 Decorator that caches a function with arguments return value.
17 """
Wladimir Palant 2012/10/22 13:32:52 Any reason to introduce a new decorator instead of
Andrey Novikov 2012/10/23 14:15:29 I thought you were not considering them on purpose
18 def __init__ (self, f):
19 self.f = f
20 self.mem = {}
21
22 def __call__ (self, *args, **kwargs):
23 if (args, str(kwargs)) in self.mem:
Wladimir Palant 2012/10/22 13:32:52 How about calculating str(kwargs) once at the begi
Andrey Novikov 2012/10/23 14:15:29 Done.
24 return self.mem[args, str(kwargs)]
25 else:
26 tmp = self.f(*args, **kwargs)
27 self.mem[args, str(kwargs)] = tmp
28 return tmp
29
14 class cached(object): 30 class cached(object):
15 """ 31 """
16 Decorator that caches a function's return value for a given number of second s. 32 Decorator that caches a function's return value for a given number of second s.
17 Note that this can only be used with functions that take no arguments. 33 Note that this can only be used with functions that take no arguments.
18 """ 34 """
19 35
20 def __init__(self, timeout): 36 def __init__(self, timeout):
21 self.timeout = timeout 37 self.timeout = timeout
22 self.func = None 38 self.func = None
23 self.lastUpdate = None 39 self.lastUpdate = None
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 def get_unescaped_template_environment(): 137 def get_unescaped_template_environment():
122 """ 138 """
123 Returns a Jinja2 template environment without autoescaping. Don't use this t o 139 Returns a Jinja2 template environment without autoescaping. Don't use this t o
124 generate HTML files! 140 generate HTML files!
125 """ 141 """
126 from sitescripts.templateFilters import filters 142 from sitescripts.templateFilters import filters
127 import jinja2 143 import jinja2
128 env = jinja2.Environment(loader=jinja2.FileSystemLoader(siteScriptsPath)) 144 env = jinja2.Environment(loader=jinja2.FileSystemLoader(siteScriptsPath))
129 env.filters.update(filters) 145 env.filters.update(filters)
130 return env 146 return env
OLDNEW
« sitescripts/reports/utils.py ('K') | « sitescripts/reports/web/updateReport.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld