MCPcopy Create free account
hub / github.com/clips/pattern / __init__

Method __init__

pattern/web/soup/BeautifulSoup.py:1083–1150  ·  view source on GitHub ↗

The Soup object is initialized as the 'root tag', and the provided markup (which can be a string or a file-like object) is fed into the underlying parser. sgmllib will process most bad HTML, and the BeautifulSoup class has some tricks for dealing with some HTML that

(self, markup="", parseOnlyThese=None, fromEncoding=None,
                 markupMassage=True, smartQuotesTo=XML_ENTITIES,
                 convertEntities=None, selfClosingTags=None, isHTML=False)

Source from the content-addressed store, hash-verified

1081 STRIP_ASCII_SPACES = { 9: None, 10: None, 12: None, 13: None, 32: None, }
1082
1083 def __init__(self, markup="", parseOnlyThese=None, fromEncoding=None,
1084 markupMassage=True, smartQuotesTo=XML_ENTITIES,
1085 convertEntities=None, selfClosingTags=None, isHTML=False):
1086 """The Soup object is initialized as the 'root tag', and the
1087 provided markup (which can be a string or a file-like object)
1088 is fed into the underlying parser.
1089
1090 sgmllib will process most bad HTML, and the BeautifulSoup
1091 class has some tricks for dealing with some HTML that kills
1092 sgmllib, but Beautiful Soup can nonetheless choke or lose data
1093 if your data uses self-closing tags or declarations
1094 incorrectly.
1095
1096 By default, Beautiful Soup uses regexes to sanitize input,
1097 avoiding the vast majority of these problems. If the problems
1098 don't apply to you, pass in False for markupMassage, and
1099 you'll get better performance.
1100
1101 The default parser massage techniques fix the two most common
1102 instances of invalid HTML that choke sgmllib:
1103
1104 <br/> (No space between name of closing tag and tag close)
1105 <! --Comment--> (Extraneous whitespace in declaration)
1106
1107 You can pass in a custom list of (RE object, replace method)
1108 tuples to get Beautiful Soup to scrub your input the way you
1109 want."""
1110
1111 self.parseOnlyThese = parseOnlyThese
1112 self.fromEncoding = fromEncoding
1113 self.smartQuotesTo = smartQuotesTo
1114 self.convertEntities = convertEntities
1115 # Set the rules for how we'll deal with the entities we
1116 # encounter
1117 if self.convertEntities:
1118 # It doesn't make sense to convert encoded characters to
1119 # entities even while you're converting entities to Unicode.
1120 # Just convert it all to Unicode.
1121 self.smartQuotesTo = None
1122 if convertEntities == self.HTML_ENTITIES:
1123 self.convertXMLEntities = False
1124 self.convertHTMLEntities = True
1125 self.escapeUnrecognizedEntities = True
1126 elif convertEntities == self.XHTML_ENTITIES:
1127 self.convertXMLEntities = True
1128 self.convertHTMLEntities = True
1129 self.escapeUnrecognizedEntities = False
1130 elif convertEntities == self.XML_ENTITIES:
1131 self.convertXMLEntities = True
1132 self.convertHTMLEntities = False
1133 self.escapeUnrecognizedEntities = False
1134 else:
1135 self.convertXMLEntities = False
1136 self.convertHTMLEntities = False
1137 self.escapeUnrecognizedEntities = False
1138
1139 self.instanceSelfClosingTags = buildTagMap(None, selfClosingTags)
1140 SGMLParser.__init__(self)

Callers

nothing calls this directly

Calls 4

_feedMethod · 0.95
buildTagMapFunction · 0.85
__init__Method · 0.45
readMethod · 0.45

Tested by

no test coverage detected