comparison decoupage/web.py @ 107:450aff4c97e3

py35 compat
author Jeff Hammel <k0scist@gmail.com>
date Fri, 31 Mar 2017 17:06:59 -0700
parents 747c7e337c56
children 8298abd49954
comparison
equal deleted inserted replaced
106:1f84c6def8bd 107:450aff4c97e3
101 self.formats = {} 101 self.formats = {}
102 for _format in iter_entry_points('decoupage.formats'): 102 for _format in iter_entry_points('decoupage.formats'):
103 try: 103 try:
104 _cls = _format.load() 104 _cls = _format.load()
105 _instance = _cls(self, **format_args.get(_format.name, {})) 105 _instance = _cls(self, **format_args.get(_format.name, {}))
106 except Exception, e: 106 except Exception as e:
107 # record the error, but persist 107 # record the error, but persist
108 print >> sys.stderr, "Couldn't load format: %s" % _format 108 sys.stderr.write("Couldn't load format: {}\n{}\n".format(_format, e))
109 print >> sys.stderr, e
110 continue 109 continue
111 self.formats[_format.name] = _instance 110 self.formats[_format.name] = _instance
112 111
113 # pluggable index data formatters 112 # pluggable index data formatters
114 self.formatters = {} 113 self.formatters = {}
116 try: 115 try:
117 _formatter = formatter.load() 116 _formatter = formatter.load()
118 template_dir = resource_filename(formatter.module_name, 'templates') 117 template_dir = resource_filename(formatter.module_name, 'templates')
119 if template_dir not in self.template_directories and os.path.isdir(template_dir): 118 if template_dir not in self.template_directories and os.path.isdir(template_dir):
120 self.template_directories.append(template_dir) 119 self.template_directories.append(template_dir)
121 except Exception, e: 120 except Exception as e:
122 # record the error, but persist 121 # record the error, but persist
123 print >> sys.stderr, "Couldn't load formatter: %s" % formatter 122 sys.stderr.write("Couldn't load formatter: {}\n{}\n".format(formatter, e))
124 print >> sys.stderr, e
125 continue 123 continue
126 self.formatters[formatter.name] = _formatter 124 self.formatters[formatter.name] = _formatter
127 125
128 # template loader 126 # template loader
129 self.loader = TemplateLoader(self.template_directories, 127 self.loader = TemplateLoader(self.template_directories,
245 # extend template `search_path` to include local directory 243 # extend template `search_path` to include local directory
246 self.loader.search_path.insert(0, directory) 244 self.loader.search_path.insert(0, directory)
247 try: 245 try:
248 template = self.loader.load(template) 246 template = self.loader.load(template)
249 res = template.generate(**data).render('html', doctype='html') 247 res = template.generate(**data).render('html', doctype='html')
250 except (TemplateError, TemplateSyntaxError, TemplateNotFound), e: 248 except (TemplateError, TemplateSyntaxError, TemplateNotFound) as e:
251 if local_index: 249 if local_index:
252 print repr(e) 250 print (repr(e))
253 return self.fileserver(local_index) 251 return self.fileserver(local_index)
254 raise 252 raise
255 finally: 253 finally:
256 self.loader.search_path.pop(0) 254 self.loader.search_path.pop(0)
257 255