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

Delta Between Two Patch Sets: sitescripts/cms/converters.py

Issue 5567002995326976: Multiple CMS improvements (Closed)
Left Patch Set: Created Dec. 11, 2013, 10:08 a.m.
Right Patch Set: Addressed comments Created Dec. 11, 2013, 12:02 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/cms/bin/test_server.py ('k') | sitescripts/cms/sources.py » ('j') | 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 Converter.__init__(self, *args, **kwargs) 176 Converter.__init__(self, *args, **kwargs)
177 177
178 filters = { 178 filters = {
179 "translate": self.translate, 179 "translate": self.translate,
180 "linkify": self.linkify, 180 "linkify": self.linkify,
181 "toclist": self.toclist, 181 "toclist": self.toclist,
182 } 182 }
183 183
184 for filename in self._params["source"].list_files("filters"): 184 for filename in self._params["source"].list_files("filters"):
185 root, ext = os.path.splitext(filename) 185 root, ext = os.path.splitext(filename)
186 if ext != ".py": 186 if ext.lower() != ".py":
Sebastian Noack 2013/12/11 11:38:29 You might want to compare the file extension case-
Wladimir Palant 2013/12/11 12:05:19 Then we should do the same everywhere else where w
187 continue 187 continue
188 188
189 path = "%s/%s" % ("filters", filename) 189 path = "%s/%s" % ("filters", filename)
190 code = self._params["source"].read_file(path) 190 code = self._params["source"].read_file(path)
191 module = imp.new_module(root.replace("/", ".")) 191 module = imp.new_module(root.replace("/", "."))
192 exec code in module.__dict__ 192 exec code in module.__dict__
193 193
194 func = os.path.basename(root) 194 func = os.path.basename(root)
195 if func not in module.__dict__: 195 if not hasattr(module, func):
Sebastian Noack 2013/12/11 11:38:29 You should use the getattr/setattr/hasattr/delattr
196 raise Exception("Expected function %s not found in filter file %s" % (fu nc, filename)) 196 raise Exception("Expected function %s not found in filter file %s" % (fu nc, filename))
197 filters[func] = module.__dict__[func] 197 filters[func] = getattr(module, func)
Sebastian Noack 2013/12/11 11:38:29 See above: getattr(module, func)
198 filters[func].__module__ = module # Prevent garbage collection 198 filters[func].module_ref = module # Prevent garbage collection
Sebastian Noack 2013/12/11 11:38:29 The __module__ attribute of objects is supposed to
Wladimir Palant 2013/12/11 12:05:19 Ok, clashing with a predefined property was uninte
199 199
200 self._env = get_custom_template_environment(filters) 200 self._env = get_custom_template_environment(filters)
201 201
202 def get_html(self, source): 202 def get_html(self, source):
203 template = self._env.from_string(source) 203 template = self._env.from_string(source)
204 return template.render(self._params) 204 return template.render(self._params)
205 205
206 def translate(self, name, page=None, links=[]): 206 def translate(self, name, page=None, links=[]):
207 if page == None: 207 if page == None:
208 localedata = self._params["localedata"] 208 localedata = self._params["localedata"]
(...skipping 28 matching lines...) Expand all
237 stack.pop() 237 stack.pop()
238 stack[-1]["subitems"].append(item) 238 stack[-1]["subitems"].append(item)
239 stack.append(item) 239 stack.append(item)
240 return structured 240 return structured
241 241
242 converters = { 242 converters = {
243 "raw": RawConverter, 243 "raw": RawConverter,
244 "md": MarkdownConverter, 244 "md": MarkdownConverter,
245 "tmpl": TemplateConverter, 245 "tmpl": TemplateConverter,
246 } 246 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld