Renders the contents of this tag as a Unicode string. :param indent_level: Each line of the rendering will be indented this many spaces. :param eventual_encoding: The tag is destined to be encoded into this encoding. This method is _not_ responsible
(self, indent_level=None,
eventual_encoding=DEFAULT_OUTPUT_ENCODING,
formatter="minimal")
| 1162 | return self.encode(encoding, True, formatter=formatter) |
| 1163 | |
| 1164 | def decode_contents(self, indent_level=None, |
| 1165 | eventual_encoding=DEFAULT_OUTPUT_ENCODING, |
| 1166 | formatter="minimal"): |
| 1167 | """Renders the contents of this tag as a Unicode string. |
| 1168 | |
| 1169 | :param indent_level: Each line of the rendering will be |
| 1170 | indented this many spaces. |
| 1171 | |
| 1172 | :param eventual_encoding: The tag is destined to be |
| 1173 | encoded into this encoding. This method is _not_ |
| 1174 | responsible for performing that encoding. This information |
| 1175 | is passed in so that it can be substituted in if the |
| 1176 | document contains a <META> tag that mentions the document's |
| 1177 | encoding. |
| 1178 | |
| 1179 | :param formatter: The output formatter responsible for converting |
| 1180 | entities to Unicode characters. |
| 1181 | """ |
| 1182 | # First off, turn a string formatter into a function. This |
| 1183 | # will stop the lookup from happening over and over again. |
| 1184 | if not isinstance(formatter, collections.Callable): |
| 1185 | formatter = self._formatter_for_name(formatter) |
| 1186 | |
| 1187 | pretty_print = (indent_level is not None) |
| 1188 | s = [] |
| 1189 | for c in self: |
| 1190 | text = None |
| 1191 | if isinstance(c, NavigableString): |
| 1192 | text = c.output_ready(formatter) |
| 1193 | elif isinstance(c, Tag): |
| 1194 | s.append(c.decode(indent_level, eventual_encoding, |
| 1195 | formatter)) |
| 1196 | if text and indent_level and not self.name == 'pre': |
| 1197 | text = text.strip() |
| 1198 | if text: |
| 1199 | if pretty_print and not self.name == 'pre': |
| 1200 | s.append(" " * (indent_level - 1)) |
| 1201 | s.append(text) |
| 1202 | if pretty_print and not self.name == 'pre': |
| 1203 | s.append("\n") |
| 1204 | return ''.join(s) |
| 1205 | |
| 1206 | def encode_contents( |
| 1207 | self, indent_level=None, encoding=DEFAULT_OUTPUT_ENCODING, |