Represents an imported template. All the exported names of the template are available as attributes on this object. Additionally converting it into an unicode- or bytestrings renders the contents.
| 1137 | |
| 1138 | @implements_to_string |
| 1139 | class TemplateModule(object): |
| 1140 | """Represents an imported template. All the exported names of the |
| 1141 | template are available as attributes on this object. Additionally |
| 1142 | converting it into an unicode- or bytestrings renders the contents. |
| 1143 | """ |
| 1144 | |
| 1145 | def __init__(self, template, context, body_stream=None): |
| 1146 | if body_stream is None: |
| 1147 | if context.environment.is_async: |
| 1148 | raise RuntimeError('Async mode requires a body stream ' |
| 1149 | 'to be passed to a template module. Use ' |
| 1150 | 'the async methods of the API you are ' |
| 1151 | 'using.') |
| 1152 | body_stream = list(template.root_render_func(context)) |
| 1153 | self._body_stream = body_stream |
| 1154 | self.__dict__.update(context.get_exported()) |
| 1155 | self.__name__ = template.name |
| 1156 | |
| 1157 | def __html__(self): |
| 1158 | return Markup(concat(self._body_stream)) |
| 1159 | |
| 1160 | def __str__(self): |
| 1161 | return concat(self._body_stream) |
| 1162 | |
| 1163 | def __repr__(self): |
| 1164 | if self.__name__ is None: |
| 1165 | name = 'memory:%x' % id(self) |
| 1166 | else: |
| 1167 | name = repr(self.__name__) |
| 1168 | return '<%s %s>' % (self.__class__.__name__, name) |
| 1169 | |
| 1170 | |
| 1171 | class TemplateExpression(object): |
no outgoing calls
no test coverage detected
searching dependent graphs…