comparison genshi/template/loader.py @ 822:ce5ad2d540b3

Get rid of some Python 2.3 legacy that's no longer needed now that 2.4 is the baseline.
author cmlenz
date Wed, 11 Mar 2009 22:14:32 +0000
parents 7cf2407671c2
children 4376010bb97e
comparison
equal deleted inserted replaced
819:185b9b1784d1 822:ce5ad2d540b3
262 encoding = self.default_encoding 262 encoding = self.default_encoding
263 return cls(fileobj, filepath=filepath, filename=filename, loader=self, 263 return cls(fileobj, filepath=filepath, filename=filename, loader=self,
264 encoding=encoding, lookup=self.variable_lookup, 264 encoding=encoding, lookup=self.variable_lookup,
265 allow_exec=self.allow_exec) 265 allow_exec=self.allow_exec)
266 266
267 @staticmethod
267 def directory(path): 268 def directory(path):
268 """Loader factory for loading templates from a local directory. 269 """Loader factory for loading templates from a local directory.
269 270
270 :param path: the path to the local directory containing the templates 271 :param path: the path to the local directory containing the templates
271 :return: the loader function to load templates from the given directory 272 :return: the loader function to load templates from the given directory
277 mtime = os.path.getmtime(filepath) 278 mtime = os.path.getmtime(filepath)
278 def _uptodate(): 279 def _uptodate():
279 return mtime == os.path.getmtime(filepath) 280 return mtime == os.path.getmtime(filepath)
280 return filepath, filename, fileobj, _uptodate 281 return filepath, filename, fileobj, _uptodate
281 return _load_from_directory 282 return _load_from_directory
282 directory = staticmethod(directory) 283
283 284 @staticmethod
284 def package(name, path): 285 def package(name, path):
285 """Loader factory for loading templates from egg package data. 286 """Loader factory for loading templates from egg package data.
286 287
287 :param name: the name of the package containing the resources 288 :param name: the name of the package containing the resources
288 :param path: the path inside the package data 289 :param path: the path inside the package data
292 from pkg_resources import resource_stream 293 from pkg_resources import resource_stream
293 def _load_from_package(filename): 294 def _load_from_package(filename):
294 filepath = os.path.join(path, filename) 295 filepath = os.path.join(path, filename)
295 return filepath, filename, resource_stream(name, filepath), None 296 return filepath, filename, resource_stream(name, filepath), None
296 return _load_from_package 297 return _load_from_package
297 package = staticmethod(package) 298
298 299 @staticmethod
299 def prefixed(**delegates): 300 def prefixed(**delegates):
300 """Factory for a load function that delegates to other loaders 301 """Factory for a load function that delegates to other loaders
301 depending on the prefix of the requested template path. 302 depending on the prefix of the requested template path.
302 303
303 The prefix is stripped from the filename when passing on the load 304 The prefix is stripped from the filename when passing on the load
325 filename[len(prefix):].lstrip('/\\') 326 filename[len(prefix):].lstrip('/\\')
326 ) 327 )
327 return filepath, filename, fileobj, uptodate 328 return filepath, filename, fileobj, uptodate
328 raise TemplateNotFound(filename, delegates.keys()) 329 raise TemplateNotFound(filename, delegates.keys())
329 return _dispatch_by_prefix 330 return _dispatch_by_prefix
330 prefixed = staticmethod(prefixed) 331
331 332
332 directory = TemplateLoader.directory 333 directory = TemplateLoader.directory
333 package = TemplateLoader.package 334 package = TemplateLoader.package
334 prefixed = TemplateLoader.prefixed 335 prefixed = TemplateLoader.prefixed
Copyright (C) 2012-2017 Edgewall Software