\",\\n b\"\",\\n b\"\",\\n ):\\n dammit = UnicodeDammit(data, is_html=True)\\n assert \"euc-jp\" == dammit.original_encoding\\n\\n def test_last_ditch_entity_replacement(self):\\n # This is a UTF-8 document that contains bytestrings\\n # completely incompatible with UTF-8 (ie. encoded with some other\\n # encoding).\\n #\\n # Since there is no consistent encoding for the document,\\n # Unicode, Dammit will eventually encode the document as UTF-8\\n # and encode the incompatible characters as REPLACEMENT\\n # CHARACTER.\\n #\\n # If chardet is installed, it will detect that the document\\n # can be converted into ISO-8859-1 without errors. This happens\\n # to be the wrong encoding, but it is a consistent encoding, so the\\n # code we're testing here won't run.\\n #\\n # So we temporarily disable chardet if it's present.\\n doc = b\"\"\"\\357\\273\\277\\n\\330\\250\\330\\252\\330\\261\\n\\310\\322\\321\\220\\312\\321\\355\\344\"\"\"\\n chardet = bs4.dammit._chardet_dammit\\n logging.disable(logging.WARNING)\\n try:\\n\\n def noop(str):\\n return None\\n\\n bs4.dammit._chardet_dammit = noop\\n dammit = UnicodeDammit(doc)\\n assert True is dammit.contains_replacement_characters\\n assert \"\\ufffd\" in dammit.unicode_markup\\n\\n soup = BeautifulSoup(doc, \"html.parser\")\\n assert soup.contains_replacement_characters\\n finally:\\n logging.disable(logging.NOTSET)\\n bs4.dammit._chardet_dammit = chardet\\n\\n def test_byte_order_mark_removed(self):\\n # A document written in UTF-16LE will have its byte order marker stripped.\\n data = b\"\\xff\\xfe<\\x00a\\x00>\\x00\\xe1\\x00\\xe9\\x00<\\x00/\\x00a\\x00>\\x00\"\\n dammit = UnicodeDammit(data)\\n assert \"áé\" == dammit.unicode_markup\\n assert \"utf-16le\" == dammit.original_encoding\\n\\n def test_known_definite_versus_user_encodings(self):\\n # The known_definite_encodings are used before sniffing the\\n # byte-order mark; the user_encodings are used afterwards.\\n\\n # Here's a document in UTF-16LE.\\n data = b\"\\xff\\xfe<\\x00a\\x00>\\x00\\xe1\\x00\\xe9\\x00<\\x00/\\x00a\\x00>\\x00\"\\n dammit = UnicodeDammit(data)\\n\\n # We can process it as UTF-16 by passing it in as a known\\n # definite encoding.\\n before = UnicodeDammit(data, known_definite_encodings=[\"utf-16\"])\\n assert \"utf-16\" == before.original_encoding\\n\\n # If we pass UTF-18 as a user encoding, it's not even\\n # tried--the encoding sniffed from the byte-order mark takes\\n # precedence.\\n after = UnicodeDammit(data, user_encodings=[\"utf-8\"])\\n assert \"utf-16le\" == after.original_encoding\\n assert [\"utf-16le\"] == [x[0] for x in dammit.tried_encodings]\\n\\n # Here's a document in ISO-8859-8.\\n hebrew = b\"\\xed\\xe5\\xec\\xf9\"\\n dammit = UnicodeDammit(\\n hebrew, known_definite_encodings=[\"utf-8\"], user_encodings=[\"iso-8859-8\"]\\n )\\n\\n # The known_definite_encodings don't work, BOM sniffing does\\n # nothing (it only works for a few UTF encodings), but one of\\n # the user_encodings does work.\\n assert \"iso-8859-8\" == dammit.original_encoding\\n assert [\"utf-8\", \"iso-8859-8\"] == [x[0] for x in dammit.tried_encodings]\\n\\n def test_deprecated_override_encodings(self):\\n # override_encodings is a deprecated alias for\\n # known_definite_encodings.\\n hebrew = b\"\\xed\\xe5\\xec\\xf9\"\\n with warnings.catch_warnings(record=True) as w:\\n dammit = UnicodeDammit(\\n hebrew,\\n known_definite_encodings=[\"shift-jis\"],\\n override_encodings=[\"utf-8\"],\\n user_encodings=[\"iso-8859-8\"],\\n )\\n [warning] = w\\n message = warning.message\\n assert isinstance(message, DeprecationWarning)\\n assert warning.filename == __file__\\n assert \"iso-8859-8\" == dammit.original_encoding\\n\\n # known_definite_encodings and override_encodings were tried\\n # before user_encodings.\\n assert [\"shift-jis\", \"utf-8\", \"iso-8859-8\"] == (\\n [x[0] for x in dammit.tried_encodings]\\n )\\n\\n def test_detwingle(self):\\n # Here's a UTF8 document.\\n utf8 = (\"\\N{SNOWMAN}\" * 3).encode(\"utf8\")\\n\\n # Here's a Windows-1252 document.\\n windows_1252 = (\\n \"\\N{LEFT DOUBLE QUOTATION MARK}Hi, I like Windows!\"\\n \"\\N{RIGHT DOUBLE QUOTATION MARK}\"\\n ).encode(\"windows_1252\")\\n\\n # Through some unholy alchemy, they've been stuck together.\\n doc = utf8 + windows_1252 + utf8\\n\\n # The document can't be turned into UTF-8:\\n with pytest.raises(UnicodeDecodeError):\\n doc.decode(\"utf8\")\\n\\n # Unicode, Dammit thinks the whole document is Windows-1252,\\n # and decodes it into \"☃☃☃“Hi, I like Windows!”☃☃☃\"\\n\\n # But if we run it through fix_embedded_windows_1252, it's fixed:\\n fixed = UnicodeDammit.detwingle(doc)\\n assert \"☃☃☃“Hi, I like Windows!”☃☃☃\" == fixed.decode(\"utf8\")\\n\\n def test_detwingle_ignores_multibyte_characters(self):\\n # Each of these characters has a UTF-8 representation ending\\n # in \\x93. \\x93 is a smart quote if interpreted as\\n # Windows-1252. But our code knows to skip over multibyte\\n # UTF-8 characters, so they'll survive the process unscathed.\\n for tricky_unicode_char in (\\n \"\\N{LATIN SMALL LIGATURE OE}\", # 2-byte char '\\xc5\\x93'\\n \"\\N{LATIN SUBSCRIPT SMALL LETTER X}\", # 3-byte char '\\xe2\\x82\\x93'\\n \"\\xf0\\x90\\x90\\x93\", # This is a CJK character, not sure which one.\\n ):\\n input = tricky_unicode_char.encode(\"utf8\")\\n assert input.endswith(b\"\\x93\")\\n output = UnicodeDammit.detwingle(input)\\n assert output == input\\n\\n def test_find_declared_encoding(self):\\n # Test our ability to find a declared encoding inside an\\n # XML or HTML document.\\n #\\n # Even if the document comes in as Unicode, it may be\\n # interesting to know what encoding was claimed\\n # originally.\\n\\n html_unicode = ''\\n html_bytes = html_unicode.encode(\"ascii\")\\n\\n xml_unicode = ''\\n xml_bytes = xml_unicode.encode(\"ascii\")\\n\\n m = EncodingDetector.find_declared_encoding\\n assert m(html_unicode, is_html=False) is None\\n assert \"utf-8\" == m(html_unicode, is_html=True)\\n assert \"utf-8\" == m(html_bytes, is_html=True)\\n\\n assert \"iso-8859-1\" == m(xml_unicode)\\n assert \"iso-8859-1\" == m(xml_bytes)\\n\\n # Normally, only the first few kilobytes of a document are checked for\\n # an encoding.\\n spacer = b\" \" * 5000\\n assert m(spacer + html_bytes) is None\\n assert m(spacer + xml_bytes) is None\\n\\n # But you can tell find_declared_encoding to search an entire\\n # HTML document.\\n assert (\\n m(spacer + html_bytes, is_html=True, search_entire_document=True) == \"utf-8\"\\n )\\n\\n # The XML encoding declaration has to be the very first thing\\n # in the document. We'll allow whitespace before the document\\n # starts, but nothing else.\\n assert m(xml_bytes, search_entire_document=True) == \"iso-8859-1\"\\n assert m(b\" \" + xml_bytes, search_entire_document=True) == \"iso-8859-1\"\\n assert m(b\"a\" + xml_bytes, search_entire_document=True) is None\\n\\n\\nclass TestEntitySubstitution(object):\\n \"\"\"Standalone tests of the EntitySubstitution class.\"\"\"\\n\\n def setup_method(self):\\n self.sub = EntitySubstitution\\n\\n @pytest.mark.parametrize(\\n \"original,substituted\",\\n [\\n # Basic case. Unicode characters corresponding to named\\n # HTML entites are substituted; others are not.\\n (\"foo\\u2200\\N{SNOWMAN}\\u00f5bar\", \"foo&forall;\\N{SNOWMAN}&otilde;bar\"),\\n # MS smart quotes are a common source of frustration, so we\\n # give them a special test.\\n (\"‘’foo“”\", \"&lsquo;&rsquo;foo&ldquo;&rdquo;\"),\\n ],\\n )\\n def test_substitute_html(self, original, substituted):\\n assert self.sub.substitute_html(original) == substituted\\n\\n def test_html5_entity(self):\\n for entity, u in (\\n # A few spot checks of our ability to recognize\\n # special character sequences and convert them\\n # to named entities.\\n (\"&models;\", \"\\u22a7\"),\\n (\"&Nfr;\", \"\\U0001d511\"),\\n (\"&ngeqq;\", \"\\u2267\\u0338\"),\\n (\"&not;\", \"\\xac\"),\\n (\"&Not;\", \"\\u2aec\"),\\n # We _could_ convert | to &verbarr;, but we don't, because\\n # | is an ASCII character.\\n (\"|\" \"|\"),\\n # Similarly for the fj ligature, which we could convert to\\n # &fjlig;, but we don't.\\n (\"fj\", \"fj\"),\\n # We do convert _these_ ASCII characters to HTML entities,\\n # because that's required to generate valid HTML.\\n (\"&gt;\", \">\"),\\n (\"&lt;\", \"<\"),\\n ):\\n template = \"3 %s 4\"\\n raw = template % u\\n with_entities = template % entity\\n assert self.sub.substitute_html(raw) == with_entities\\n\\n def test_html5_entity_with_variation_selector(self):\\n # Some HTML5 entities correspond either to a single-character\\n # Unicode sequence _or_ to the same character plus U+FE00,\\n # VARIATION SELECTOR 1. We can handle this.\\n data = \"fjords \\u2294 penguins\"\\n markup = \"fjords &sqcup; penguins\"\\n assert self.sub.substitute_html(data) == markup\\n\\n data = \"fjords \\u2294\\ufe00 penguins\"\\n markup = \"fjords &sqcups; penguins\"\\n assert self.sub.substitute_html(data) == markup\\n\\n def test_xml_converstion_includes_no_quotes_if_make_quoted_attribute_is_false(self):\\n s = 'Welcome to \"my bar\"'\\n assert self.sub.substitute_xml(s, False) == s\\n\\n def test_xml_attribute_quoting_normally_uses_double_quotes(self):\\n assert self.sub.substitute_xml(\"Welcome\", True) == '\"Welcome\"'\\n assert self.sub.substitute_xml(\"Bob's Bar\", True) == '\"Bob\\'s Bar\"'\\n\\n def test_xml_attribute_quoting_uses_single_quotes_when_value_contains_double_quotes(\\n self,\\n ):\\n s = 'Welcome to \"my bar\"'\\n assert self.sub.substitute_xml(s, True) == \"'Welcome to \\\"my bar\\\"'\"\\n\\n def test_xml_attribute_quoting_escapes_single_quotes_when_value_contains_both_single_and_double_quotes(\\n self,\\n ):\\n s = 'Welcome to \"Bob\\'s Bar\"'\\n assert self.sub.substitute_xml(s, True) == '\"Welcome to &quot;Bob\\'s Bar&quot;\"'\\n\\n def test_xml_quotes_arent_escaped_when_value_is_not_being_quoted(self):\\n quoted = 'Welcome to \"Bob\\'s Bar\"'\\n assert self.sub.substitute_xml(quoted) == quoted\\n\\n def test_xml_quoting_handles_angle_brackets(self):\\n assert self.sub.substitute_xml(\"foo\") == \"foo&lt;bar&gt;\"\\n\\n def test_xml_quoting_handles_ampersands(self):\\n assert self.sub.substitute_xml(\"AT&T\") == \"AT&amp;T\"\\n\\n def test_xml_quoting_including_ampersands_when_they_are_part_of_an_entity(self):\\n assert self.sub.substitute_xml(\"&Aacute;T&T\") == \"&amp;Aacute;T&amp;T\"\\n\\n def test_xml_quoting_ignoring_ampersands_when_they_are_part_of_an_entity(self):\\n assert (\\n self.sub.substitute_xml_containing_entities(\"&Aacute;T&T\")\\n == \"&Aacute;T&amp;T\"\\n )\\n\\n def test_quotes_not_html_substituted(self):\\n \"\"\"There's no need to do this except inside attribute values.\"\"\"\\n text = 'Bob\\'s \"bar\"'\\n assert self.sub.substitute_html(text) == text\\n\\n @pytest.mark.parametrize(\\n \"markup, old\",\\n [\\n (\"foo & bar\", \"foo &amp; bar\"),\\n (\"foo&\", \"foo&amp;\"),\\n (\"foo&&& bar\", \"foo&amp;&amp;&amp; bar\"),\\n (\"x=1&y=2\", \"x=1&amp;y=2\"),\\n (\"&123\", \"&amp;123\"),\\n (\"&abc\", \"&amp;abc\"),\\n (\"foo &0 bar\", \"foo &amp;0 bar\"),\\n (\"foo &lolwat bar\", \"foo &amp;lolwat bar\"),\\n ],\\n )\\n def test_unambiguous_ampersands_not_escaped(self, markup, old):\\n assert self.sub.substitute_html(markup) == old\\n assert self.sub.substitute_html5_raw(markup) == markup\\n\\n @pytest.mark.parametrize(\\n \"markup,html,html5,html5raw\",\\n [\\n (\"&divide;\", \"&amp;divide;\", \"&amp;divide;\", \"&divide;\"),\\n (\"&nonesuch;\", \"&amp;nonesuch;\", \"&amp;nonesuch;\", \"&amp;nonesuch;\"),\\n (\"&#247;\", \"&amp;#247;\", \"&amp;#247;\", \"&amp;#247;\"),\\n (\"&#xa1;\", \"&amp;#xa1;\", \"&amp;#xa1;\", \"&amp;#xa1;\"),\\n ],\\n )\\n def test_when_entity_ampersands_are_escaped(self, markup, html, html5, html5raw):\\n # The html and html5 formatters always escape the ampersand\\n # that begins an entity reference, because they assume\\n # Beautiful Soup has already converted any unescaped entity references\\n # to Unicode characters.\\n #\\n # The html5_raw formatter does not escape the ampersand that\\n # begins a recognized HTML entity, because it does not\\n # fit the HTML5 definition of an ambiguous ampersand.\\n #\\n # The html5_raw formatter does escape the ampersands in front\\n # of unrecognized named entities, as well as numeric and\\n # hexadecimal entities, because they do fit the definition.\\n assert self.sub.substitute_html(markup) == html\\n assert self.sub.substitute_html5(markup) == html5\\n assert self.sub.substitute_html5_raw(markup) == html5raw\\n\\n @pytest.mark.parametrize(\\n \"markup,expect\", [(\"&nosuchentity;\", \"&amp;nosuchentity;\")]\\n )\\n def test_ambiguous_ampersands_escaped(self, markup, expect):\\n assert self.sub.substitute_html(markup) == expect\\n assert self.sub.substitute_html5_raw(markup) == expect\\n"},"path":{"kind":"string","value":".venv\\Lib\\site-packages\\bs4\\tests\\test_dammit.py"},"filename":{"kind":"string","value":"test_dammit.py"},"language":{"kind":"string","value":"Python"},"size_bytes":{"kind":"number","value":17840,"string":"17,840"},"quality_score":{"kind":"number","value":0.95,"string":"0.95"},"complexity":{"kind":"number","value":0.1339491916859122,"string":"0.133949"},"documentation_ratio":{"kind":"number","value":0.2405405405405405,"string":"0.240541"},"repository":{"kind":"string","value":"node-utils"},"stars":{"kind":"number","value":112,"string":"112"},"created_date":{"kind":"string","value":"2024-12-27T05:03:29.868501"},"license":{"kind":"string","value":"GPL-3.0"},"is_test":{"kind":"bool","value":true,"string":"true"},"file_hash":{"kind":"string","value":"8b9c85f42965e4bb5deeb264ad2fd335"}}},{"rowIdx":1508,"cells":{"content":{"kind":"string","value":"\"\"\"Tests of classes in element.py.\\n\\nThe really big classes -- Tag, PageElement, and NavigableString --\\nare tested in separate files.\\n\"\"\"\\n\\nimport pytest\\nfrom bs4.element import (\\n HTMLAttributeDict,\\n XMLAttributeDict,\\n CharsetMetaAttributeValue,\\n ContentMetaAttributeValue,\\n NamespacedAttribute,\\n ResultSet,\\n)\\n\\nclass TestNamedspacedAttribute:\\n def test_name_may_be_none_or_missing(self):\\n a = NamespacedAttribute(\"xmlns\", None)\\n assert a == \"xmlns\"\\n\\n a = NamespacedAttribute(\"xmlns\", \"\")\\n assert a == \"xmlns\"\\n\\n a = NamespacedAttribute(\"xmlns\")\\n assert a == \"xmlns\"\\n\\n def test_namespace_may_be_none_or_missing(self):\\n a = NamespacedAttribute(None, \"tag\")\\n assert a == \"tag\"\\n\\n a = NamespacedAttribute(\"\", \"tag\")\\n assert a == \"tag\"\\n\\n def test_attribute_is_equivalent_to_colon_separated_string(self):\\n a = NamespacedAttribute(\"a\", \"b\")\\n assert \"a:b\" == a\\n\\n def test_attributes_are_equivalent_if_prefix_and_name_identical(self):\\n a = NamespacedAttribute(\"a\", \"b\", \"c\")\\n b = NamespacedAttribute(\"a\", \"b\", \"c\")\\n assert a == b\\n\\n # The actual namespace is not considered.\\n c = NamespacedAttribute(\"a\", \"b\", None)\\n assert a == c\\n\\n # But name and prefix are important.\\n d = NamespacedAttribute(\"a\", \"z\", \"c\")\\n assert a != d\\n\\n e = NamespacedAttribute(\"z\", \"b\", \"c\")\\n assert a != e\\n\\n\\nclass TestAttributeValueWithCharsetSubstitution:\\n \"\"\"Certain attributes are designed to have the charset of the\\n final document substituted into their value.\\n \"\"\"\\n\\n def test_charset_meta_attribute_value(self):\\n # The value of a CharsetMetaAttributeValue is whatever\\n # encoding the string is in.\\n value = CharsetMetaAttributeValue(\"euc-jp\")\\n assert \"euc-jp\" == value\\n assert \"euc-jp\" == value.original_value\\n assert \"utf8\" == value.substitute_encoding(\"utf8\")\\n assert \"ascii\" == value.substitute_encoding(\"ascii\")\\n\\n # If the target encoding is a Python internal encoding,\\n # no encoding will be mentioned in the output HTML.\\n assert \"\" == value.substitute_encoding(\"palmos\")\\n\\n def test_content_meta_attribute_value(self):\\n value = ContentMetaAttributeValue(\"text/html; charset=euc-jp\")\\n assert \"text/html; charset=euc-jp\" == value\\n assert \"text/html; charset=euc-jp\" == value.original_value\\n assert \"text/html; charset=utf8\" == value.substitute_encoding(\"utf8\")\\n assert \"text/html; charset=ascii\" == value.substitute_encoding(\"ascii\")\\n\\n # If the target encoding is a Python internal encoding, the\\n # charset argument will be omitted altogether.\\n assert \"text/html\" == value.substitute_encoding(\"palmos\")\\n\\n\\nclass TestAttributeDicts:\\n def test_xml_attribute_value_handling(self):\\n # Verify that attribute values are processed according to the\\n # XML spec's rules.\\n d = XMLAttributeDict()\\n d[\"v\"] = 100\\n assert d[\"v\"] == \"100\"\\n d[\"v\"] = 100.123\\n assert d[\"v\"] == \"100.123\"\\n\\n # This preserves Beautiful Soup's old behavior in the absence of\\n # guidance from the spec.\\n d[\"v\"] = False\\n assert d[\"v\"] is False\\n\\n d[\"v\"] = True\\n assert d[\"v\"] is True\\n\\n d[\"v\"] = None\\n assert d[\"v\"] == \"\"\\n\\n def test_html_attribute_value_handling(self):\\n # Verify that attribute values are processed according to the\\n # HTML spec's rules.\\n d = HTMLAttributeDict()\\n d[\"v\"] = 100\\n assert d[\"v\"] == \"100\"\\n d[\"v\"] = 100.123\\n assert d[\"v\"] == \"100.123\"\\n\\n d[\"v\"] = False\\n assert \"v\" not in d\\n\\n d[\"v\"] = None\\n assert \"v\" not in d\\n\\n d[\"v\"] = True\\n assert d[\"v\"] == \"v\"\\n\\n attribute = NamespacedAttribute(\"prefix\", \"name\", \"namespace\")\\n d[attribute] = True\\n assert d[attribute] == \"name\"\\n\\n\\nclass TestResultSet:\\n def test_getattr_exception(self):\\n rs = ResultSet(None)\\n with pytest.raises(AttributeError) as e:\\n rs.name\\n assert (\\n \"\"\"ResultSet object has no attribute \"name\". You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?\"\"\"\\n == str(e.value)\\n )\\n"},"path":{"kind":"string","value":".venv\\Lib\\site-packages\\bs4\\tests\\test_element.py"},"filename":{"kind":"string","value":"test_element.py"},"language":{"kind":"string","value":"Python"},"size_bytes":{"kind":"number","value":4373,"string":"4,373"},"quality_score":{"kind":"number","value":0.95,"string":"0.95"},"complexity":{"kind":"number","value":0.0942028985507246,"string":"0.094203"},"documentation_ratio":{"kind":"number","value":0.1296296296296296,"string":"0.12963"},"repository":{"kind":"string","value":"node-utils"},"stars":{"kind":"number","value":171,"string":"171"},"created_date":{"kind":"string","value":"2025-05-10T22:09:44.041827"},"license":{"kind":"string","value":"BSD-3-Clause"},"is_test":{"kind":"bool","value":true,"string":"true"},"file_hash":{"kind":"string","value":"a6bef2e7f8909569ea4d33389a303226"}}},{"rowIdx":1509,"cells":{"content":{"kind":"string","value":"import pytest\\n\\nfrom bs4.element import Tag\\nfrom bs4.formatter import (\\n Formatter,\\n HTMLFormatter,\\n XMLFormatter,\\n)\\nfrom . import SoupTest\\n\\n\\nclass TestFormatter(SoupTest):\\n def test_default_attributes(self):\\n # Test the default behavior of Formatter.attributes().\\n formatter = Formatter()\\n tag = Tag(name=\"tag\")\\n tag[\"b\"] = \"1\"\\n tag[\"a\"] = \"2\"\\n\\n # Attributes come out sorted by name. In Python 3, attributes\\n # normally come out of a dictionary in the order they were\\n # added.\\n assert [(\"a\", \"2\"), (\"b\", \"1\")] == formatter.attributes(tag)\\n\\n # This works even if Tag.attrs is None, though this shouldn't\\n # normally happen.\\n tag.attrs = None\\n assert [] == formatter.attributes(tag)\\n\\n assert \" \" == formatter.indent\\n\\n def test_sort_attributes(self):\\n # Test the ability to override Formatter.attributes() to,\\n # e.g., disable the normal sorting of attributes.\\n class UnsortedFormatter(Formatter):\\n def attributes(self, tag):\\n self.called_with = tag\\n for k, v in sorted(tag.attrs.items()):\\n if k == \"ignore\":\\n continue\\n yield k, v\\n\\n soup = self.soup('

')\\n formatter = UnsortedFormatter()\\n decoded = soup.decode(formatter=formatter)\\n\\n # attributes() was called on the

tag. It filtered out one\\n # attribute and sorted the other two.\\n assert formatter.called_with == soup.p\\n assert '

' == decoded\\n\\n def test_empty_attributes_are_booleans(self):\\n # Test the behavior of empty_attributes_are_booleans as well\\n # as which Formatters have it enabled.\\n\\n for name in (\"html\", \"minimal\", None):\\n formatter = HTMLFormatter.REGISTRY[name]\\n assert False is formatter.empty_attributes_are_booleans\\n\\n formatter = XMLFormatter.REGISTRY[None]\\n assert False is formatter.empty_attributes_are_booleans\\n\\n formatter = HTMLFormatter.REGISTRY[\"html5\"]\\n assert True is formatter.empty_attributes_are_booleans\\n\\n # Verify that the constructor sets the value.\\n formatter = Formatter(empty_attributes_are_booleans=True)\\n assert True is formatter.empty_attributes_are_booleans\\n\\n # Now demonstrate what it does to markup.\\n for markup in (\"\", ''):\\n soup = self.soup(markup)\\n for formatter in (\"html\", \"minimal\", \"xml\", None):\\n assert b'' == soup.option.encode(\\n formatter=\"html\"\\n )\\n assert b\"\" == soup.option.encode(\\n formatter=\"html5\"\\n )\\n\\n @pytest.mark.parametrize(\\n \"indent,expect\",\\n [\\n (None, \"\\n\\ntext\\n\\n\\n\"),\\n (-1, \"\\n\\ntext\\n\\n\\n\"),\\n (0, \"\\n\\ntext\\n\\n\\n\"),\\n (\"\", \"\\n\\ntext\\n\\n\\n\"),\\n (1, \"\\n \\n text\\n \\n\\n\"),\\n (2, \"\\n \\n text\\n \\n\\n\"),\\n (\"\\t\", \"\\n\\t\\n\\t\\ttext\\n\\t\\n\\n\"),\\n (\"abc\", \"\\nabc\\nabcabctext\\nabc\\n\\n\"),\\n # Some invalid inputs -- the default behavior is used.\\n (object(), \"\\n \\n text\\n \\n\\n\"),\\n (b\"bytes\", \"\\n \\n text\\n \\n\\n\"),\\n ],\\n )\\n def test_indent(self, indent, expect):\\n # Pretty-print a tree with a Formatter set to\\n # indent in a certain way and verify the results.\\n soup = self.soup(\"text\")\\n formatter = Formatter(indent=indent)\\n assert soup.prettify(formatter=formatter) == expect\\n\\n # Pretty-printing only happens with prettify(), not\\n # encode().\\n assert soup.encode(formatter=formatter) != expect\\n\\n def test_default_indent_value(self):\\n formatter = Formatter()\\n assert formatter.indent == \" \"\\n\\n @pytest.mark.parametrize(\"formatter,expect\",\\n [\\n (HTMLFormatter(indent=1), \"

\\n a\\n

\\n\"),\\n (HTMLFormatter(indent=2), \"

\\n a\\n

\\n\"),\\n (XMLFormatter(indent=1), \"

\\n a\\n

\\n\"),\\n (XMLFormatter(indent=\"\\t\"), \"

\\n\\ta\\n

\\n\"),\\n ] )\\n def test_indent_subclasses(self, formatter, expect):\\n soup = self.soup(\"

a

\")\\n assert expect == soup.p.prettify(formatter=formatter)\\n\\n @pytest.mark.parametrize(\\n \"s,expect_html,expect_html5\",\\n [\\n # The html5 formatter is much less aggressive about escaping ampersands\\n # than the html formatter.\\n (\"foo & bar\", \"foo &amp; bar\", \"foo & bar\"),\\n (\"foo&\", \"foo&amp;\", \"foo&\"),\\n (\"foo&&& bar\", \"foo&amp;&amp;&amp; bar\", \"foo&&& bar\"),\\n (\"x=1&y=2\", \"x=1&amp;y=2\", \"x=1&y=2\"),\\n (\"&123\", \"&amp;123\", \"&123\"),\\n (\"&abc\", \"&amp;abc\", \"&abc\"),\\n (\"foo &0 bar\", \"foo &amp;0 bar\", \"foo &0 bar\"),\\n (\"foo &lolwat bar\", \"foo &amp;lolwat bar\", \"foo &lolwat bar\"),\\n # But both formatters escape what the HTML5 spec considers ambiguous ampersands.\\n (\"&nosuchentity;\", \"&amp;nosuchentity;\", \"&amp;nosuchentity;\"),\\n ],\\n )\\n def test_entity_substitution(self, s, expect_html, expect_html5):\\n assert HTMLFormatter.REGISTRY[\"html\"].substitute(s) == expect_html\\n assert HTMLFormatter.REGISTRY[\"html5\"].substitute(s) == expect_html5\\n assert HTMLFormatter.REGISTRY[\"html5-4.12\"].substitute(s) == expect_html\\n\\n def test_entity_round_trip(self):\\n # This is more an explanatory test and a way to avoid regressions than a test of functionality.\\n\\n markup = \"

Some division signs: ÷ &divide; &#247; &#xf7;. These are made with: ÷ &amp;divide; &amp;#247;

\"\\n soup = self.soup(markup)\\n assert (\\n \"Some division signs: ÷ ÷ ÷ ÷. These are made with: ÷ &divide; &#247;\"\\n == soup.p.string\\n )\\n\\n # Oops, I forgot to mention the entity.\\n soup.p.string = soup.p.string + \" &#xf7;\"\\n\\n assert (\\n \"Some division signs: ÷ ÷ ÷ ÷. These are made with: ÷ &divide; &#247; &#xf7;\"\\n == soup.p.string\\n )\\n\\n expect = \"

Some division signs: &divide; &divide; &divide; &divide;. These are made with: &divide; &amp;divide; &amp;#247; &amp;#xf7;

\"\\n assert expect == soup.p.decode(formatter=\"html\")\\n assert expect == soup.p.decode(formatter=\"html5\")\\n\\n markup = \"

a & b

\"\\n soup = self.soup(markup)\\n assert \"

a &amp; b

\" == soup.p.decode(formatter=\"html\")\\n assert \"

a & b

\" == soup.p.decode(formatter=\"html5\")\\n"},"path":{"kind":"string","value":".venv\\Lib\\site-packages\\bs4\\tests\\test_formatter.py"},"filename":{"kind":"string","value":"test_formatter.py"},"language":{"kind":"string","value":"Python"},"size_bytes":{"kind":"number","value":6943,"string":"6,943"},"quality_score":{"kind":"number","value":0.95,"string":"0.95"},"complexity":{"kind":"number","value":0.1,"string":"0.1"},"documentation_ratio":{"kind":"number","value":0.1666666666666666,"string":"0.166667"},"repository":{"kind":"string","value":"node-utils"},"stars":{"kind":"number","value":365,"string":"365"},"created_date":{"kind":"string","value":"2023-07-25T03:50:44.861694"},"license":{"kind":"string","value":"GPL-3.0"},"is_test":{"kind":"bool","value":true,"string":"true"},"file_hash":{"kind":"string","value":"ab6dc4af15f58758f47e504eb919f635"}}},{"rowIdx":1510,"cells":{"content":{"kind":"string","value":"\"\"\"This file contains test cases reported by third parties using\\nfuzzing tools, primarily from Google's oss-fuzz project. Some of these\\nrepresent real problems with Beautiful Soup, but many are problems in\\nlibraries that Beautiful Soup depends on, and many of the test cases\\nrepresent different ways of triggering the same problem.\\n\\nGrouping these test cases together makes it easy to see which test\\ncases represent the same problem, and puts the test cases in close\\nproximity to code that can trigger the problems.\\n\"\"\"\\n\\nimport os\\nimport importlib\\nimport pytest\\nfrom bs4 import (\\n BeautifulSoup,\\n ParserRejectedMarkup,\\n)\\n\\ntry:\\n from soupsieve.util import SelectorSyntaxError\\n has_lxml = importlib.util.find_spec(\"lxml\")\\n has_html5lib = importlib.util.find_spec(\"html5lib\")\\n fully_fuzzable = has_lxml != None and has_html5lib != None\\nexcept ImportError:\\n fully_fuzzable = False\\n\\n\\n@pytest.mark.skipif(\\n not fully_fuzzable, reason=\"Prerequisites for fuzz tests are not installed.\"\\n)\\nclass TestFuzz(object):\\n # Test case markup files from fuzzers are given this extension so\\n # they can be included in builds.\\n TESTCASE_SUFFIX = \".testcase\"\\n\\n # Copied 20230512 from\\n # https://github.com/google/oss-fuzz/blob/4ac6a645a197a695fe76532251feb5067076b3f3/projects/bs4/bs4_fuzzer.py\\n #\\n # Copying the code lets us precisely duplicate the behavior of\\n # oss-fuzz. The downside is that this code changes over time, so\\n # multiple copies of the code must be kept around to run against\\n # older tests. I'm not sure what to do about this, but I may\\n # retire old tests after a time.\\n def fuzz_test_with_css(self, filename: str) -> None:\\n data = self.__markup(filename)\\n parsers = [\"lxml-xml\", \"html5lib\", \"html.parser\", \"lxml\"]\\n try:\\n idx = int(data[0]) % len(parsers)\\n except ValueError:\\n return\\n\\n css_selector, data = data[1:10], data[10:]\\n\\n try:\\n soup = BeautifulSoup(data[1:], features=parsers[idx])\\n except ParserRejectedMarkup:\\n return\\n except ValueError:\\n return\\n\\n list(soup.find_all(True))\\n try:\\n soup.css.select(css_selector.decode(\"utf-8\", \"replace\"))\\n except SelectorSyntaxError:\\n return\\n soup.prettify()\\n\\n # This class of error has been fixed by catching a less helpful\\n # exception from html.parser and raising ParserRejectedMarkup\\n # instead.\\n @pytest.mark.parametrize(\\n \"filename\",\\n [\\n \"clusterfuzz-testcase-minimized-bs4_fuzzer-5703933063462912\",\\n \"crash-ffbdfa8a2b26f13537b68d3794b0478a4090ee4a\",\\n ],\\n )\\n def test_rejected_markup(self, filename):\\n markup = self.__markup(filename)\\n with pytest.raises(ParserRejectedMarkup):\\n BeautifulSoup(markup, \"html.parser\")\\n\\n # This class of error has to do with very deeply nested documents\\n # which overflow the Python call stack when the tree is converted\\n # to a string. This is an issue with Beautiful Soup which was fixed\\n # as part of [bug=1471755].\\n #\\n # These test cases are in the older format that doesn't specify\\n # which parser to use or give a CSS selector.\\n @pytest.mark.parametrize(\\n \"filename\",\\n [\\n \"clusterfuzz-testcase-minimized-bs4_fuzzer-5984173902397440\",\\n \"clusterfuzz-testcase-minimized-bs4_fuzzer-5167584867909632\",\\n \"clusterfuzz-testcase-minimized-bs4_fuzzer-6124268085182464\",\\n \"clusterfuzz-testcase-minimized-bs4_fuzzer-6450958476902400\",\\n ],\\n )\\n def test_deeply_nested_document_without_css(self, filename):\\n # Parsing the document and encoding it back to a string is\\n # sufficient to demonstrate that the overflow problem has\\n # been fixed.\\n markup = self.__markup(filename)\\n BeautifulSoup(markup, \"html.parser\").encode()\\n\\n # This class of error has to do with very deeply nested documents\\n # which overflow the Python call stack when the tree is converted\\n # to a string. This is an issue with Beautiful Soup which was fixed\\n # as part of [bug=1471755].\\n @pytest.mark.parametrize(\\n \"filename\",\\n [\\n \"clusterfuzz-testcase-minimized-bs4_fuzzer-5000587759190016\",\\n \"clusterfuzz-testcase-minimized-bs4_fuzzer-5375146639360000\",\\n \"clusterfuzz-testcase-minimized-bs4_fuzzer-5492400320282624\",\\n ],\\n )\\n def test_deeply_nested_document(self, filename):\\n self.fuzz_test_with_css(filename)\\n\\n @pytest.mark.parametrize(\\n \"filename\",\\n [\\n \"clusterfuzz-testcase-minimized-bs4_fuzzer-4670634698080256\",\\n \"clusterfuzz-testcase-minimized-bs4_fuzzer-5270998950477824\",\\n ],\\n )\\n def test_soupsieve_errors(self, filename):\\n self.fuzz_test_with_css(filename)\\n\\n # This class of error represents problems with html5lib's parser,\\n # not Beautiful Soup. I use\\n # https://github.com/html5lib/html5lib-python/issues/568 to notify\\n # the html5lib developers of these issues.\\n #\\n # These test cases are in the older format that doesn't specify\\n # which parser to use or give a CSS selector.\\n @pytest.mark.skip(reason=\"html5lib-specific problems\")\\n @pytest.mark.parametrize(\\n \"filename\",\\n [\\n # b\"\"\"ÿ

'\\n \"clusterfuzz-testcase-minimized-bs4_fuzzer-4999465949331456\",\\n # b'-