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

Function _sanitizeHTML

pattern/web/feed/feedparser.py:2859–2899  ·  view source on GitHub ↗
(htmlSource, encoding, _type)

Source from the content-addressed store, hash-verified

2857
2858
2859def _sanitizeHTML(htmlSource, encoding, _type):
2860 if not _SGML_AVAILABLE:
2861 return htmlSource
2862 p = _HTMLSanitizer(encoding, _type)
2863 htmlSource = htmlSource.replace('<![CDATA[', '&lt;![CDATA[')
2864 p.feed(htmlSource)
2865 data = p.output()
2866 if TIDY_MARKUP:
2867 # loop through list of preferred Tidy interfaces looking for one that's installed,
2868 # then set up a common _tidy function to wrap the interface-specific API.
2869 _tidy = None
2870 for tidy_interface in PREFERRED_TIDY_INTERFACES:
2871 try:
2872 if tidy_interface == "uTidy":
2873 from tidy import parseString as _utidy
2874 def _tidy(data, **kwargs):
2875 return str(_utidy(data, **kwargs))
2876 break
2877 elif tidy_interface == "mxTidy":
2878 from mx.Tidy import Tidy as _mxtidy
2879 def _tidy(data, **kwargs):
2880 nerrors, nwarnings, data, errordata = _mxtidy.tidy(data, **kwargs)
2881 return data
2882 break
2883 except:
2884 pass
2885 if _tidy:
2886 utf8 = isinstance(data, unicode)
2887 if utf8:
2888 data = data.encode('utf-8')
2889 data = _tidy(data, output_xhtml=1, numeric_entities=1, wrap=0, char_encoding="utf8")
2890 if utf8:
2891 data = unicode(data, 'utf-8')
2892 if data.count('<body'):
2893 data = data.split('<body', 1)[1]
2894 if data.count('>'):
2895 data = data.split('>', 1)[1]
2896 if data.count('</body'):
2897 data = data.split('</body', 1)[0]
2898 data = data.strip().replace('\r\n', '\n')
2899 return data
2900
2901class _FeedURLHandler(urllib2.HTTPDigestAuthHandler, urllib2.HTTPRedirectHandler, urllib2.HTTPDefaultErrorHandler):
2902 def http_error_default(self, req, fp, code, msg, headers):

Callers 1

popMethod · 0.85

Calls 8

_HTMLSanitizerClass · 0.85
_tidyFunction · 0.85
outputMethod · 0.80
stripMethod · 0.80
feedMethod · 0.45
encodeMethod · 0.45
countMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…