MCPcopy Index your code
hub / github.com/clips/pattern / pop

Method pop

pattern/web/feed/feedparser.py:848–1015  ·  view source on GitHub ↗
(self, element, stripWhitespace=1)

Source from the content-addressed store, hash-verified

846 self.elementstack.append([element, expectingText, []])
847
848 def pop(self, element, stripWhitespace=1):
849 if not self.elementstack:
850 return
851 if self.elementstack[-1][0] != element:
852 return
853
854 element, expectingText, pieces = self.elementstack.pop()
855
856 if self.version == u'atom10' and self.contentparams.get('type', u'text') == u'application/xhtml+xml':
857 # remove enclosing child element, but only if it is a <div> and
858 # only if all the remaining content is nested underneath it.
859 # This means that the divs would be retained in the following:
860 # <div>foo</div><div>bar</div>
861 while pieces and len(pieces)>1 and not pieces[-1].strip():
862 del pieces[-1]
863 while pieces and len(pieces)>1 and not pieces[0].strip():
864 del pieces[0]
865 if pieces and (pieces[0] == '<div>' or pieces[0].startswith('<div ')) and pieces[-1]=='</div>':
866 depth = 0
867 for piece in pieces[:-1]:
868 if piece.startswith('</'):
869 depth -= 1
870 if depth == 0:
871 break
872 elif piece.startswith('<') and not piece.endswith('/>'):
873 depth += 1
874 else:
875 pieces = pieces[1:-1]
876
877 # Ensure each piece is a str for Python 3
878 for (i, v) in enumerate(pieces):
879 if not isinstance(v, unicode):
880 pieces[i] = v.decode('utf-8')
881
882 output = u''.join(pieces)
883 if stripWhitespace:
884 output = output.strip()
885 if not expectingText:
886 return output
887
888 # decode base64 content
889 if base64 and self.contentparams.get('base64', 0):
890 try:
891 output = _base64decode(output)
892 except binascii.Error:
893 pass
894 except binascii.Incomplete:
895 pass
896 except TypeError:
897 # In Python 3, base64 takes and outputs bytes, not str
898 # This may not be the most correct way to accomplish this
899 output = _base64decode(output.encode('utf-8')).decode('utf-8')
900
901 # resolve relative URIs
902 if (element in self.can_be_relative_uri) and output:
903 output = self.resolveURI(output)
904
905 # decode entities within embedded markup

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
lenFunction · 0.85
_resolveRelativeURIsFunction · 0.85
_parseMicroformatsFunction · 0.85
_sanitizeHTMLFunction · 0.85

Tested by

no test coverage detected