comparison piecrust/templating/pystacheengine.py @ 440:32c7c2d219d2

performance: Refactor how data is managed to reduce copying. * Make use of `collections.abc.Mapping` to better identify things that are supposed to look like dictionaries. * Instead of handling "overlay" of data in a dict tree in each different data object, make all objects `Mapping`s and handle merging at a higher level with the new `MergedMapping` object. * Since this new object is read-only, remove the need for deep-copying of app and page configurations. * Split data classes into separate modules.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 28 Jun 2015 08:22:39 -0700
parents ca5a3c970263
children 96d363e2da4b
comparison
equal deleted inserted replaced
439:c0700c6d9545 440:32c7c2d219d2
1 import logging 1 import logging
2 import collections.abc
2 import pystache 3 import pystache
3 import pystache.common 4 import pystache.common
4 from piecrust.templating.base import ( 5 from piecrust.templating.base import (
5 TemplateEngine, TemplateNotFoundError, TemplatingError) 6 TemplateEngine, TemplateNotFoundError, TemplatingError)
6 7
68 def _workaround(stack, name): 69 def _workaround(stack, name):
69 # Pystache will treat anything that's not a string or a dict as 70 # Pystache will treat anything that's not a string or a dict as
70 # a list. This is just plain wrong, but it will take a while before 71 # a list. This is just plain wrong, but it will take a while before
71 # the project can get patches on Pypi. 72 # the project can get patches on Pypi.
72 res = mrc(stack, name) 73 res = mrc(stack, name)
73 if res is not None and res.__class__.__name__ in _knowns: 74 if res is not None and (
75 res.__class__.__name__ in _knowns or
76 isinstance(res, collections.abc.Mapping)):
74 res = [res] 77 res = [res]
75 return res 78 return res
76 79
77 return _workaround 80 return _workaround
78 81