diff options
author | Leonard Richardson <leonard.richardson@canonical.com> | 2012-02-23 11:16:45 -0500 |
---|---|---|
committer | Leonard Richardson <leonard.richardson@canonical.com> | 2012-02-23 11:16:45 -0500 |
commit | 2f72913160bedb509a8042693328d139e7c6b945 (patch) | |
tree | eddcc9af34a533cdb06a1158b408f1856cb3982d /bs4/element.py | |
parent | 0339d1f4a0f7306cb8c1ef4d7cd609b06e33eb27 (diff) |
Namespaced attributes are equal if they correspond to the same string.
Diffstat (limited to 'bs4/element.py')
-rw-r--r-- | bs4/element.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/bs4/element.py b/bs4/element.py index fdb90e0..7e5810a 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -24,11 +24,22 @@ def _alias(attr): class NamespacedAttribute(object): - def __init__(self, namespace_abbreviation, name, namespace): + def __init__(self, namespace_abbreviation, name, namespace=None): self.namespace_abbreviation = namespace_abbreviation self.name = name self.namespace = namespace + def __eq__(self, other): + if isinstance(other, NamespacedAttribute): + return ( + self.namespace_abbreviation == other.namespace_abbreviation + and self.name == other.name + and self.namespace == other.namespace) + elif isinstance(other, basestring): + return str(self) == other + else: + return super(NamespacedAttribute, self).__eq__(other) + def __str__(self): name = self.name if self.namespace_abbreviation: |