MCPcopy
hub / github.com/pyload/pyload / pop

Method pop

module/lib/feedparser.py:788–948  ·  view source on GitHub ↗
(self, element, stripWhitespace=1)

Source from the content-addressed store, hash-verified

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):

Callers 15

unknown_endtagMethod · 0.95
popContentMethod · 0.95
_end_imageMethod · 0.95
_end_textinputMethod · 0.95
_end_authorMethod · 0.95
_end_itunes_ownerMethod · 0.95
_end_contributorMethod · 0.95
_end_nameMethod · 0.95
_end_widthMethod · 0.95
_end_heightMethod · 0.95
_end_urlMethod · 0.95
_end_emailMethod · 0.95

Calls 15

resolveURIMethod · 0.95
decodeEntitiesMethod · 0.95
lookslikehtmlMethod · 0.95
mapContentTypeMethod · 0.95
_addTagMethod · 0.95
_start_enclosureMethod · 0.95
_addXFNMethod · 0.95
_getContextMethod · 0.95
_resolveRelativeURIsFunction · 0.85
_parseMicroformatsFunction · 0.85
_sanitizeHTMLFunction · 0.85
decodeMethod · 0.80

Tested by

no test coverage detected