(self, element, stripWhitespace=1)
| 786 | self.elementstack.append([element, expectingText, []]) |
| 787 | |
| 788 | def pop(self, element, stripWhitespace=1): |
| 789 | if not self.elementstack: return |
| 790 | if self.elementstack[-1][0] != element: return |
| 791 | |
| 792 | element, expectingText, pieces = self.elementstack.pop() |
| 793 | |
| 794 | if self.version == 'atom10' and self.contentparams.get('type','text') == 'application/xhtml+xml': |
| 795 | # remove enclosing child element, but only if it is a <div> and |
| 796 | # only if all the remaining content is nested underneath it. |
| 797 | # This means that the divs would be retained in the following: |
| 798 | # <div>foo</div><div>bar</div> |
| 799 | while pieces and len(pieces)>1 and not pieces[-1].strip(): |
| 800 | del pieces[-1] |
| 801 | while pieces and len(pieces)>1 and not pieces[0].strip(): |
| 802 | del pieces[0] |
| 803 | if pieces and (pieces[0] == '<div>' or pieces[0].startswith('<div ')) and pieces[-1]=='</div>': |
| 804 | depth = 0 |
| 805 | for piece in pieces[:-1]: |
| 806 | if piece.startswith('</'): |
| 807 | depth -= 1 |
| 808 | if depth == 0: break |
| 809 | elif piece.startswith('<') and not piece.endswith('/>'): |
| 810 | depth += 1 |
| 811 | else: |
| 812 | pieces = pieces[1:-1] |
| 813 | |
| 814 | # Ensure each piece is a str for Python 3 |
| 815 | for (i, v) in enumerate(pieces): |
| 816 | if not isinstance(v, basestring): |
| 817 | pieces[i] = v.decode('utf-8') |
| 818 | |
| 819 | output = ''.join(pieces) |
| 820 | if stripWhitespace: |
| 821 | output = output.strip() |
| 822 | if not expectingText: return output |
| 823 | |
| 824 | # decode base64 content |
| 825 | if base64 and self.contentparams.get('base64', 0): |
| 826 | try: |
| 827 | output = _base64decode(output) |
| 828 | except binascii.Error: |
| 829 | pass |
| 830 | except binascii.Incomplete: |
| 831 | pass |
| 832 | except TypeError: |
| 833 | # In Python 3, base64 takes and outputs bytes, not str |
| 834 | # This may not be the most correct way to accomplish this |
| 835 | output = _base64decode(output.encode('utf-8')).decode('utf-8') |
| 836 | |
| 837 | # resolve relative URIs |
| 838 | if (element in self.can_be_relative_uri) and output: |
| 839 | output = self.resolveURI(output) |
| 840 | |
| 841 | # decode entities within embedded markup |
| 842 | if not self.contentparams.get('base64', 0): |
| 843 | output = self.decodeEntities(element, output) |
| 844 | |
| 845 | if self.lookslikehtml(output): |
no test coverage detected