From cb5b71d9d90f6d3fb70eb9fca297d4e12dda3a3f Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Wed, 1 Feb 2012 11:28:12 -0500 Subject: Got the new-tag test to pass. --- bs4/element.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'bs4/element.py') diff --git a/bs4/element.py b/bs4/element.py index 9344f45..5cadfc9 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -440,13 +440,18 @@ class Tag(PageElement): """Represents a found HTML tag with its attributes and contents.""" - def __init__(self, parser, builder, name, attrs=None, parent=None, - previous=None): + def __init__(self, parser=None, builder=None, name=None, attrs=None, + parent=None, previous=None): "Basic constructor." - # We don't actually store the parser object: that lets extracted - # chunks be garbage-collected. - self.parser_class = parser.__class__ + if parser is None: + self.parser_class = None + else: + # We don't actually store the parser object: that lets extracted + # chunks be garbage-collected. + self.parser_class = parser.__class__ + if name is None: + raise ValueError("No value provided for new tag's name.") self.name = name if attrs is None: attrs = {} @@ -458,9 +463,13 @@ class Tag(PageElement): self.hidden = False # Set up any substitutions, such as the charset in a META tag. - self.contains_substitutions = builder.set_up_substitutions(self) + if builder is not None: + self.contains_substitutions = builder.set_up_substitutions(self) - self.can_be_empty_element = builder.can_be_empty_element(name) + self.can_be_empty_element = builder.can_be_empty_element(name) + else: + self.contains_substitutions = False + self.can_be_empty_element = False parserClass = _alias("parser_class") # BS3 -- cgit v1.2.3