(self, containerClass=NavigableString)
| 285 | self.preserve_whitespace_tag_stack.append(tag) |
| 286 | |
| 287 | def endData(self, containerClass=NavigableString): |
| 288 | if self.current_data: |
| 289 | current_data = ''.join(self.current_data) |
| 290 | # If whitespace is not preserved, and this string contains |
| 291 | # nothing but ASCII spaces, replace it with a single space |
| 292 | # or newline. |
| 293 | if not self.preserve_whitespace_tag_stack: |
| 294 | strippable = True |
| 295 | for i in current_data: |
| 296 | if i not in self.ASCII_SPACES: |
| 297 | strippable = False |
| 298 | break |
| 299 | if strippable: |
| 300 | if '\n' in current_data: |
| 301 | current_data = '\n' |
| 302 | else: |
| 303 | current_data = ' ' |
| 304 | |
| 305 | # Reset the data collector. |
| 306 | self.current_data = [] |
| 307 | |
| 308 | # Should we add this string to the tree at all? |
| 309 | if self.parse_only and len(self.tagStack) <= 1 and \ |
| 310 | (not self.parse_only.text or \ |
| 311 | not self.parse_only.search(current_data)): |
| 312 | return |
| 313 | |
| 314 | o = containerClass(current_data) |
| 315 | self.object_was_parsed(o) |
| 316 | |
| 317 | def object_was_parsed(self, o, parent=None, most_recent_element=None): |
| 318 | """Add an object to the parse tree.""" |
no test coverage detected