diff options
author | Leonard Richardson <leonardr@segfault.org> | 2016-07-17 10:09:30 -0400 |
---|---|---|
committer | Leonard Richardson <leonardr@segfault.org> | 2016-07-17 10:09:30 -0400 |
commit | 3cbfb6672f24c123fe52fcd6b28bd0a5478b0161 (patch) | |
tree | b462b218b4bd283923280d52ab831ed2a30e825c /bs4 | |
parent | da49326601e36e20b54cda255995225c71727793 (diff) | |
download | beautifulsoup4-3cbfb6672f24c123fe52fcd6b28bd0a5478b0161.tar.gz |
Use known_xml instead of continually adding underscores to is_xml.
Diffstat (limited to 'bs4')
-rw-r--r-- | bs4/__init__.py | 1 | ||||
-rw-r--r-- | bs4/element.py | 23 |
2 files changed, 14 insertions, 10 deletions
diff --git a/bs4/__init__.py b/bs4/__init__.py index 80b6d93..37993ce 100644 --- a/bs4/__init__.py +++ b/bs4/__init__.py @@ -182,6 +182,7 @@ class BeautifulSoup(Tag): self.builder = builder self.is_xml = builder.is_xml + self.known_xml = self.is_xml self.builder.soup = self self.parse_only = parse_only diff --git a/bs4/element.py b/bs4/element.py index 99c9b39..84c4a6e 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -172,13 +172,19 @@ class PageElement(object): This is used when mapping a formatter name ("minimal") to an appropriate function (one that performs entity-substitution on - the contents of <script> and <style> tags, or not). It's + the contents of <script> and <style> tags, or not). It can be inefficient, but it should be called very rarely. """ - if self.__is_xml is not None: - return self.__is_xml + if self.known_xml is not None: + # Most of the time we will have determined this when the + # document is parsed. + return self.known_xml + + # Otherwise, it's likely that this element was created by + # direct invocation of the constructor from within the user's + # Python code. if self.parent is None: - # This is the top-level object. It should have .is_xml set + # This is the top-level object. It should have .known_xml set # from tree creation. If not, take a guess--BS is usually # used on HTML markup. return getattr(self, 'is_xml', False) @@ -684,11 +690,8 @@ class NavigableString(unicode, PageElement): # We can't tell just by looking at a string whether it's contained # in an XML document or an HTML document. - __is_xml = None - @property - def _is_xml(self): - return None + known_xml = None def __new__(cls, value): """Create a new NavigableString. @@ -837,9 +840,9 @@ class Tag(PageElement): # If possible, determine ahead of time whether this tag is an # XML tag. if builder: - self.__is_xml = builder.is_xml + self.known_xml = builder.is_xml else: - self.__is_xml = is_xml + self.known_xml = is_xml self.attrs = attrs self.contents = [] self.setup(parent, previous) |