comparison markup/core.py @ 96:35d681a94763

Add an XHTML serialization method. Now really need to get rid of some code duplication in the `markup.output` module.
author cmlenz
date Fri, 21 Jul 2006 11:39:32 +0000
parents e82d1bb07464
children 5e9987f34e6c
comparison
equal deleted inserted replaced
95:7d6426183a90 96:35d681a94763
66 66
67 def render(self, method='xml', encoding='utf-8', filters=None, **kwargs): 67 def render(self, method='xml', encoding='utf-8', filters=None, **kwargs):
68 """Return a string representation of the stream. 68 """Return a string representation of the stream.
69 69
70 @param method: determines how the stream is serialized; can be either 70 @param method: determines how the stream is serialized; can be either
71 'xml' or 'html', or a custom `Serializer` subclass 71 "xml", "xhtml", or "html", or a custom `Serializer`
72 subclass
72 @param encoding: how the output string should be encoded; if set to 73 @param encoding: how the output string should be encoded; if set to
73 `None`, this method returns a `unicode` object 74 `None`, this method returns a `unicode` object
74 75
75 Any additional keyword arguments are passed to the serializer, and thus 76 Any additional keyword arguments are passed to the serializer, and thus
76 depend on the `method` parameter value. 77 depend on the `method` parameter value.
97 Unlike the `render()` method, this method is a generator that returns 98 Unlike the `render()` method, this method is a generator that returns
98 the serialized output incrementally, as opposed to returning a single 99 the serialized output incrementally, as opposed to returning a single
99 string. 100 string.
100 101
101 @param method: determines how the stream is serialized; can be either 102 @param method: determines how the stream is serialized; can be either
102 'xml' or 'html', or a custom `Serializer` subclass 103 "xml", "xhtml", or "html", or a custom `Serializer`
104 subclass
103 @param filters: list of filters to apply to the stream before 105 @param filters: list of filters to apply to the stream before
104 serialization. The default is to apply whitespace 106 serialization. The default is to apply whitespace
105 reduction using `markup.filters.WhitespaceFilter`. 107 reduction using `markup.filters.WhitespaceFilter`.
106 """ 108 """
107 from markup.filters import WhitespaceFilter 109 from markup.filters import WhitespaceFilter
108 from markup import output 110 from markup import output
109 cls = method 111 cls = method
110 if isinstance(method, basestring): 112 if isinstance(method, basestring):
111 cls = {'xml': output.XMLSerializer, 113 cls = {'xml': output.XMLSerializer,
112 'html': output.HTMLSerializer}[method] 114 'xhtml': output.XHTMLSerializer,
115 'html': output.HTMLSerializer}[method]
113 else: 116 else:
114 assert issubclass(cls, output.Serializer) 117 assert issubclass(cls, output.Serializer)
115 serializer = cls(**kwargs) 118 serializer = cls(**kwargs)
116 119
117 stream = self 120 stream = self
Copyright (C) 2012-2017 Edgewall Software