Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
bs4.builder.DetectsXMLParsedAsHTML Class Reference
Inheritance diagram for bs4.builder.DetectsXMLParsedAsHTML:
Inheritance graph
[legend]
Collaboration diagram for bs4.builder.DetectsXMLParsedAsHTML:
Collaboration graph
[legend]

Public Member Functions

bool warn_if_markup_looks_like_xml (cls, Optional[_RawMarkup] markup, int stacklevel=3)
 

Static Public Attributes

Pattern LOOKS_LIKE_HTML = re.compile("<[^ +]html", re.I)
 
Pattern LOOKS_LIKE_HTML_B = re.compile(b"<[^ +]html", re.I)
 
str XML_PREFIX = "<?xml"
 
bytes XML_PREFIX_B = b"<?xml"
 

Protected Member Functions

None _warn (cls, int stacklevel=5)
 
None _initialize_xml_detector (self)
 
None _document_might_be_xml (self, str processing_instruction)
 
None _root_tag_encountered (self, str name)
 

Protected Attributes

 _first_processing_instruction
 
 _root_tag_name
 

Static Protected Attributes

Optional _first_processing_instruction [str]
 
Optional _root_tag_name [str]
 

Detailed Description

A mixin class for any class (a TreeBuilder, or some class used by a
TreeBuilder) that's in a position to detect whether an XML
document is being incorrectly parsed as HTML, and issue an
appropriate warning.

This requires being able to observe an incoming processing
instruction that might be an XML declaration, and also able to
observe tags as they're opened. If you can't do that for a given
`TreeBuilder`, there's a less reliable implementation based on
examining the raw markup.

Member Function Documentation

◆ _document_might_be_xml()

None bs4.builder.DetectsXMLParsedAsHTML._document_might_be_xml (   self,
str  processing_instruction 
)
protected
Call this method when encountering an XML declaration, or a
"processing instruction" that might be an XML declaration.

This helps Beautiful Soup detect potential issues later, if
the XML document turns out to be a non-XHTML document that's
being parsed as XML.

◆ _initialize_xml_detector()

None bs4.builder.DetectsXMLParsedAsHTML._initialize_xml_detector (   self)
protected
Call this method before parsing a document.

◆ _root_tag_encountered()

None bs4.builder.DetectsXMLParsedAsHTML._root_tag_encountered (   self,
str  name 
)
protected
Call this when you encounter the document's root tag.

This is where we actually check whether an XML document is
being incorrectly parsed as HTML, and issue the warning.

◆ _warn()

None bs4.builder.DetectsXMLParsedAsHTML._warn (   cls,
int   stacklevel = 5 
)
protected
Issue a warning about XML being parsed as HTML.

◆ warn_if_markup_looks_like_xml()

bool bs4.builder.DetectsXMLParsedAsHTML.warn_if_markup_looks_like_xml (   cls,
Optional[_RawMarkup]  markup,
int   stacklevel = 3 
)
Perform a check on some markup to see if it looks like XML
that's not XHTML. If so, issue a warning.

This is much less reliable than doing the check while parsing,
but some of the tree builders can't do that.

:param stacklevel: The stacklevel of the code calling this\
 function.

:return: True if the markup looks like non-XHTML XML, False
 otherwise.

The documentation for this class was generated from the following file: