From a7ab21b82202d9b8e6bddb7657de6774ebfc9071 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Thu, 9 Apr 2009 16:07:19 -0400 Subject: Made it possible to pass in a dict as attrs. --- BeautifulSoup.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'BeautifulSoup.py') diff --git a/BeautifulSoup.py b/BeautifulSoup.py index 99ce460..aceb6d3 100644 --- a/BeautifulSoup.py +++ b/BeautifulSoup.py @@ -509,6 +509,8 @@ class Tag(PageElement, Entities): self.isSelfClosing = builder.isSelfClosingTag(name) if attrs == None: attrs = [] + if isinstance(attrs, types.DictType): + self.attrMap = attrs self.attrs = attrs self.contents = [] self.setup(parent, previous) @@ -523,8 +525,10 @@ class Tag(PageElement, Entities): if val is None: return kval return (k, re.sub("&(#\d+|#x[0-9a-fA-F]+|\w+);", convert_one, val)) - - self.attrs = map(convert, self.attrs) + if isinstance(attrs, types.DictType): + self.attrs = [convert(kv) for kv in attrs.items()] + else: + self.attrs = map(convert, attrs) def get(self, key, default=None): """Returns the value of the 'key' attribute for the tag, or @@ -1660,6 +1664,8 @@ class BeautifulSoup(BeautifulStoneSoup): def _defaultBuilder(self): return HTMLParserBuilder() +class ICantBelieveItsBeautifulSoup(BeautifulStoneSoup): + pass class StopParsing(Exception): pass -- cgit v1.2.3