summaryrefslogtreecommitdiff
path: root/bs4/element.py
diff options
context:
space:
mode:
authorLeonard Richardson <leonard.richardson@canonical.com>2012-02-23 11:56:40 -0500
committerLeonard Richardson <leonard.richardson@canonical.com>2012-02-23 11:56:40 -0500
commitb7749c50a2c96ccf6982cfa1ca02d883e31e0af9 (patch)
tree404063e3bb580627a6cabad1b80774981d4f5232 /bs4/element.py
parent2f72913160bedb509a8042693328d139e7c6b945 (diff)
Bumped version number.
Diffstat (limited to 'bs4/element.py')
-rw-r--r--bs4/element.py32
1 files changed, 10 insertions, 22 deletions
diff --git a/bs4/element.py b/bs4/element.py
index 7e5810a..c2c4e2e 100644
--- a/bs4/element.py
+++ b/bs4/element.py
@@ -22,29 +22,14 @@ def _alias(attr):
return alias
-class NamespacedAttribute(object):
+class NamespacedAttribute(unicode):
- 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:
- name = self.namespace_abbreviation + ":" + name
- return name
+ def __new__(cls, prefix, name, namespace=None):
+ obj = unicode.__new__(cls, prefix + ":" + name)
+ obj.prefix = prefix
+ obj.name = name
+ obj.namespace = namespace
+ return obj
class PageElement(object):
@@ -686,6 +671,9 @@ class Tag(PageElement):
def has_attr(self, key):
return key in self.attrs
+ def __hash__(self):
+ return str(self).__hash__()
+
def __getitem__(self, key):
"""tag[key] returns the value of the 'key' attribute for the tag,
and throws an exception if it's not there."""