def transformIterable(self, result, encoding): """Apply the transform if required """ result = self.parseTree(result) if result is None: return None DevelopmentMode = Globals.DevelopmentMode runtrace = (DevelopmentMode and self.request.get( 'diazo.debug', '').lower() in ('1', 'y', 'yes', 't', 'true')) try: etree.clear_error_log() settings = self.getSettings() if settings.doctype: result.doctype = settings.doctype if not result.doctype.endswith('\n'): result.doctype += '\n' transform = self.setupTransform(runtrace=runtrace) if transform is None: return None cache = None if not DevelopmentMode: cache = getCache(settings) parameterExpressions = settings.parameterExpressions or {} params = prepareThemeParameters(findContext(self.request), self.request, parameterExpressions, cache) transformed = transform(result.tree, **params) error_log = transform.error_log if transformed is not None: # Transformed worked, swap content with result result.tree = transformed except etree.LxmlError as e: if not (DevelopmentMode): raise error_log = e.error_log runtrace = True if runtrace: from diazo.runtrace import generate_debug_html # Add debug information to end of body body = result.tree.xpath('/html/body')[0] body.insert( -1, generate_debug_html( findContext(self.request).portal_url() + '/++resource++diazo-debug', rules=settings.rules, rules_parser=getParser('rules', settings.readNetwork), error_log=error_log, )) return result
def transformIterable(self, result, encoding): """Apply the transform if required """ result = self.parseTree(result) if result is None: return None DevelopmentMode = Globals.DevelopmentMode runtrace = (DevelopmentMode and self.request.get('diazo.debug', '').lower() in ('1', 'y', 'yes', 't', 'true')) try: etree.clear_error_log() settings = self.getSettings() if settings.doctype: result.doctype = settings.doctype if not result.doctype.endswith('\n'): result.doctype += '\n' transform = self.setupTransform(runtrace=runtrace) if transform is None: return None cache = None if not DevelopmentMode: cache = getCache(settings) parameterExpressions = settings.parameterExpressions or {} params = prepareThemeParameters(findContext(self.request), self.request, parameterExpressions, cache) transformed = transform(result.tree, **params) error_log = transform.error_log if transformed is not None: # Transformed worked, swap content with result result.tree = transformed except etree.LxmlError as e: if not(DevelopmentMode): raise error_log = e.error_log runtrace = True if runtrace: from diazo.runtrace import generate_debug_html # Add debug information to end of body body = result.tree.xpath('/html/body')[0] body.insert(-1, generate_debug_html( findContext(self.request).portal_url() + '/++resource++diazo-debug', rules=settings.rules, rules_parser=getParser('rules', settings.readNetwork), error_log = error_log, )) return result
def transformIterable(self, result, encoding): """Apply the transform if required """ # Obtain settings. Do nothing if not found policy = theming_policy(self.request) settings = policy.getSettings() if settings is None: return None if not policy.isThemeEnabled(): return None result = self.parseTree(result) if result is None: return None debug_mode = getConfiguration().debug_mode runtrace = self.debug_theme() try: etree.clear_error_log() if settings.doctype: result.doctype = settings.doctype if not result.doctype.endswith('\n'): result.doctype += '\n' transform = self.setupTransform(runtrace=runtrace) if transform is None: return None cache = None if not debug_mode: cache = policy.getCache() parameterExpressions = settings.parameterExpressions or {} params = prepareThemeParameters(findContext(self.request), self.request, parameterExpressions, cache) transformed = transform(result.tree, **params) error_log = transform.error_log if transformed is not None: # Transformed worked, swap content with result result.tree = transformed except etree.LxmlError as e: if not (debug_mode): raise error_log = e.error_log runtrace = True if runtrace: from diazo.runtrace import generate_debug_html # Add debug information to end of body body = result.tree.xpath('/html/body')[0] debug_url = findContext( self.request).portal_url() + '/++resource++diazo-debug' body.insert( -1, generate_debug_html( debug_url, rules=settings.rules, rules_parser=getParser('rules', settings.readNetwork), error_log=error_log, )) return result
def transformIterable(self, result, encoding): """Apply the transform if required """ # Obtain settings. Do nothing if not found policy = theming_policy(self.request) settings = policy.getSettings() if settings is None: return None if not policy.isThemeEnabled(): return None result = self.parseTree(result) if result is None: return None debug_mode = getConfiguration().debug_mode runtrace = self.debug_theme() try: etree.clear_error_log() if settings.doctype: result.doctype = settings.doctype if not result.doctype.endswith('\n'): result.doctype += '\n' transform = self.setupTransform(runtrace=runtrace) if transform is None: return None cache = None if not debug_mode: cache = policy.getCache() parameterExpressions = settings.parameterExpressions or {} params = prepareThemeParameters( findContext(self.request), self.request, parameterExpressions, cache ) transformed = transform(result.tree, **params) error_log = transform.error_log if transformed is not None: # Transformed worked, swap content with result result.tree = transformed except etree.LxmlError as e: if not(debug_mode): raise error_log = e.error_log runtrace = True if runtrace: from diazo.runtrace import generate_debug_html # Add debug information to end of body body = result.tree.xpath('/html/body')[0] debug_url = findContext( self.request ).portal_url() + '/++resource++diazo-debug' body.insert( -1, generate_debug_html( debug_url, rules=settings.rules, rules_parser=getParser('rules', settings.readNetwork), error_log=error_log, ) ) return result
def transformIterable(self, result, encoding): """Apply the transform if required """ # Obtain settings. Do nothing if not found settings = self.getSettings() if settings is None: return None if not isThemeEnabled(self.request, settings): return None result = self.parseTree(result) if result is None: return None DevelopmentMode = Globals.DevelopmentMode diazo_debug = self.request.get("diazo.debug", "").lower() runtrace = DevelopmentMode and diazo_debug in ("1", "y", "yes", "t", "true") try: etree.clear_error_log() if settings.doctype: result.doctype = settings.doctype if not result.doctype.endswith("\n"): result.doctype += "\n" transform = self.setupTransform(runtrace=runtrace) if transform is None: return None cache = None if not DevelopmentMode: cache = getCache(settings) parameterExpressions = settings.parameterExpressions or {} params = prepareThemeParameters(findContext(self.request), self.request, parameterExpressions, cache) transformed = transform(result.tree, **params) error_log = transform.error_log if transformed is not None: # Transformed worked, swap content with result result.tree = transformed except etree.LxmlError as e: if not (DevelopmentMode): raise error_log = e.error_log runtrace = True if runtrace: from diazo.runtrace import generate_debug_html # Add debug information to end of body body = result.tree.xpath("/html/body")[0] debug_url = findContext(self.request).portal_url() + "/++resource++diazo-debug" body.insert( -1, generate_debug_html( debug_url, rules=settings.rules, rules_parser=getParser("rules", settings.readNetwork), error_log=error_log, ), ) return result