comparison genshi/filters/transform.py @ 958:6fc92535c888 experimental-performance-improvement-exploration

Be more careful about what is passed into streams as events and remove many uses of _ensure as a result. An ATTRS event is added for handling Attributes returned by gensh.path.select().
author hodgestar
date Tue, 13 Mar 2012 03:03:02 +0000
parents 1e8c33345e52
children
comparison
equal deleted inserted replaced
957:51ab60299647 958:6fc92535c888
50 50
51 import re 51 import re
52 import sys 52 import sys
53 53
54 from genshi.builder import Element 54 from genshi.builder import Element
55 from genshi.core import Stream, Attrs, QName, TEXT, START, END, _ensure, Markup 55 from genshi.core import Stream, Attrs, QName, TEXT, START, END, \
56 _text_to_stream, Markup
56 from genshi.path import Path 57 from genshi.path import Path
57 58
58 __all__ = ['Transformer', 'StreamBuffer', 'InjectorTransformation', 'ENTER', 59 __all__ = ['Transformer', 'StreamBuffer', 'InjectorTransformation', 'ENTER',
59 'EXIT', 'INSIDE', 'OUTSIDE', 'BREAK'] 60 'EXIT', 'INSIDE', 'OUTSIDE', 'BREAK']
60 61
1058 1059
1059 def _inject(self): 1060 def _inject(self):
1060 content = self.content 1061 content = self.content
1061 if hasattr(content, '__call__'): 1062 if hasattr(content, '__call__'):
1062 content = content() 1063 content = content()
1063 for event in _ensure(content): 1064 if isinstance(content, basestring):
1065 content = _text_to_stream(content)
1066 for event in content:
1064 yield None, event 1067 yield None, event
1065 1068
1066 1069
1067 class ReplaceTransformation(InjectorTransformation): 1070 class ReplaceTransformation(InjectorTransformation):
1068 """Replace selection with content.""" 1071 """Replace selection with content."""
Copyright (C) 2012-2017 Edgewall Software