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

Delta Between Two Patch Sets: sitescripts/utils.py

Issue 11481051: Update stats processing (Closed)
Left Patch Set: Created Aug. 23, 2013, 3:53 p.m.
Right Patch Set: Improved performance using memoization Created Aug. 29, 2013, 1:39 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « sitescripts/templateFilters.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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-2013 Eyeo GmbH 4 # Copyright (C) 2006-2013 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,
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 """Parses and returns a Jinja2 template""" 112 """Parses and returns a Jinja2 template"""
113 key = (template, autoescape) 113 key = (template, autoescape)
114 if not key in _template_cache: 114 if not key in _template_cache:
115 if autoescape: 115 if autoescape:
116 env = get_template_environment() 116 env = get_template_environment()
117 else: 117 else:
118 env = get_unescaped_template_environment() 118 env = get_unescaped_template_environment()
119 _template_cache[key] = env.get_template(template) 119 _template_cache[key] = env.get_template(template)
120 return _template_cache[key] 120 return _template_cache[key]
121 121
122 @cached(()) 122 @cached(float("inf"))
123 def get_template_environment(): 123 def get_template_environment():
124 """ 124 """
125 Returns a Jinja2 template environment with autoescaping enabled. 125 Returns a Jinja2 template environment with autoescaping enabled.
126 """ 126 """
127 from sitescripts.templateFilters import filters 127 from sitescripts.templateFilters import filters
128 import jinja2 128 import jinja2
129 env = jinja2.Environment(loader=jinja2.FileSystemLoader(siteScriptsPath), auto escape=True, extensions=['jinja2.ext.autoescape']) 129 env = jinja2.Environment(loader=jinja2.FileSystemLoader(siteScriptsPath), auto escape=True)
130 env.filters.update(filters) 130 env.filters.update(filters)
131 return env 131 return env
132 132
133 @cached(()) 133 @cached(float("inf"))
134 def get_unescaped_template_environment(): 134 def get_unescaped_template_environment():
135 """ 135 """
136 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
137 generate HTML files! 137 generate HTML files!
138 """ 138 """
139 from sitescripts.templateFilters import filters 139 from sitescripts.templateFilters import filters
140 import jinja2 140 import jinja2
141 env = jinja2.Environment(loader=jinja2.FileSystemLoader(siteScriptsPath)) 141 env = jinja2.Environment(loader=jinja2.FileSystemLoader(siteScriptsPath))
142 env.filters.update(filters) 142 env.filters.update(filters)
143 return env 143 return env
144 144
145 def get_custom_template_environment(additional_filters): 145 def get_custom_template_environment(additional_filters):
146 """ 146 """
147 Returns a custom Jinja2 template environment with additional filters. 147 Returns a custom Jinja2 template environment with additional filters.
148 """ 148 """
149 from sitescripts.templateFilters import filters 149 from sitescripts.templateFilters import filters
150 import jinja2 150 import jinja2
151 env = jinja2.Environment(loader=jinja2.FileSystemLoader(siteScriptsPath), auto escape=True, extensions=['jinja2.ext.autoescape']) 151 env = jinja2.Environment(loader=jinja2.FileSystemLoader(siteScriptsPath), auto escape=True)
152 env.filters.update(filters) 152 env.filters.update(filters)
153 env.filters.update(additional_filters) 153 env.filters.update(additional_filters)
154 return env 154 return env
LEFTRIGHT

Powered by Google App Engine
This is Rietveld