diff options
author | Leonard Richardson <leonard.richardson@canonical.com> | 2012-02-16 16:33:40 -0500 |
---|---|---|
committer | Leonard Richardson <leonard.richardson@canonical.com> | 2012-02-16 16:33:40 -0500 |
commit | e1b321db7331752a3aea8dd7070dd0db4c60c51d (patch) | |
tree | 96ce9539fb1e0dbb1dc8b4f264737159e9a2cd1d /bs4/element.py | |
parent | 1a50d9623831990ae0a78ea3a7e66fa098fe92ac (diff) |
It's a start, at least.
Diffstat (limited to 'bs4/element.py')
-rw-r--r-- | bs4/element.py | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/bs4/element.py b/bs4/element.py index 513407c..926fb8f 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -22,6 +22,20 @@ def _alias(attr): return alias +class NamespacedAttribute(object): + + def __init__(self, namespace_abbreviation, name, namespace): + self.namespace_abbreviation = namespace_abbreviation + self.name = name + self.namespace = namespace + + def __str__(self): + name = self.name + if self.namespace_abbreviation: + name = self.namespace_abbreviation + ":" + name + return name + + class PageElement(object): """Contains the navigational information for some part of the page (either a tag or a piece of text)""" @@ -507,8 +521,8 @@ class Tag(PageElement): """Represents a found HTML tag with its attributes and contents.""" - def __init__(self, parser=None, builder=None, name=None, attrs=None, - parent=None, previous=None): + def __init__(self, parser=None, builder=None, name=None, namespace=None, + attrs=None, parent=None, previous=None): "Basic constructor." if parser is None: @@ -520,6 +534,7 @@ class Tag(PageElement): if name is None: raise ValueError("No value provided for new tag's name.") self.name = name + self.namespace = namespace if attrs is None: attrs = {} else: @@ -779,7 +794,7 @@ class Tag(PageElement): and '%SOUP-ENCODING%' in val): val = self.substitute_encoding(val, eventual_encoding) - decoded = (key + '=' + decoded = (str(key) + '=' + EntitySubstitution.substitute_xml(val, True)) attrs.append(decoded) close = '' |