summaryrefslogtreecommitdiff
path: root/bs4/__init__.py
diff options
context:
space:
mode:
authorLeonard Richardson <leonard.richardson@canonical.com>2012-02-23 13:55:51 -0500
committerLeonard Richardson <leonard.richardson@canonical.com>2012-02-23 13:55:51 -0500
commit97b54c4bdbee0f109c444b50d8102ae8d7abb7c4 (patch)
tree8feb3c4387fa5dc67c810f76c9a831ebf523898d /bs4/__init__.py
parent328204928bd22ca9e8aeac0a3208645d9f82f264 (diff)
parentdeaeb40977719ea821a62f41d75e2c9f48559094 (diff)
The namespace stuff seems to work, and it's definitely an improvement on the status quo, so in it goes.
Diffstat (limited to 'bs4/__init__.py')
-rw-r--r--bs4/__init__.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/bs4/__init__.py b/bs4/__init__.py
index 13dac85..9b5c155 100644
--- a/bs4/__init__.py
+++ b/bs4/__init__.py
@@ -17,7 +17,7 @@ http://www.crummy.com/software/BeautifulSoup/bs4/doc/
"""
__author__ = "Leonard Richardson (leonardr@segfault.org)"
-__version__ = "4.0.0b7"
+__version__ = "4.0.0b8"
__copyright__ = "Copyright (c) 2004-2012 Leonard Richardson"
__license__ = "MIT"
@@ -193,9 +193,9 @@ class BeautifulSoup(Tag):
self.tagStack = []
self.pushTag(self)
- def new_tag(self, name, **attrs):
+ def new_tag(self, name, namespace=None, nsprefix=None, **attrs):
"""Create a new tag associated with this soup."""
- return Tag(None, self.builder, name, attrs)
+ return Tag(None, self.builder, name, namespace, nsprefix, attrs)
def new_string(self, s):
"""Create a new NavigableString associated with this soup."""
@@ -249,7 +249,7 @@ class BeautifulSoup(Tag):
self.previous_element = o
self.currentTag.contents.append(o)
- def _popToTag(self, name, inclusivePop=True):
+ def _popToTag(self, name, nsprefix=None, inclusivePop=True):
"""Pops the tag stack up to and including the most recent
instance of the given tag. If inclusivePop is false, pops the tag
stack up to but *not* including the most recent instqance of
@@ -262,7 +262,8 @@ class BeautifulSoup(Tag):
mostRecentTag = None
for i in range(len(self.tagStack) - 1, 0, -1):
- if name == self.tagStack[i].name:
+ if (name == self.tagStack[i].name
+ and nsprefix == self.tagStack[i].nsprefix == nsprefix):
numPops = len(self.tagStack) - i
break
if not inclusivePop:
@@ -272,7 +273,7 @@ class BeautifulSoup(Tag):
mostRecentTag = self.popTag()
return mostRecentTag
- def handle_starttag(self, name, attrs):
+ def handle_starttag(self, name, namespace, nsprefix, attrs):
"""Push a start tag on to the stack.
If this method returns None, the tag was rejected by the
@@ -281,7 +282,7 @@ class BeautifulSoup(Tag):
don't call handle_endtag.
"""
- #print "Start tag %s: %s" % (name, attrs)
+ # print "Start tag %s: %s" % (name, attrs)
self.endData()
if (self.parse_only and len(self.tagStack) <= 1
@@ -289,8 +290,8 @@ class BeautifulSoup(Tag):
or not self.parse_only.search_tag(name, attrs))):
return None
- tag = Tag(self, self.builder, name, attrs, self.currentTag,
- self.previous_element)
+ tag = Tag(self, self.builder, name, namespace, nsprefix, attrs,
+ self.currentTag, self.previous_element)
if tag is None:
return tag
if self.previous_element:
@@ -299,10 +300,10 @@ class BeautifulSoup(Tag):
self.pushTag(tag)
return tag
- def handle_endtag(self, name):
+ def handle_endtag(self, name, nsprefix=None):
#print "End tag: " + name
self.endData()
- self._popToTag(name)
+ self._popToTag(name, nsprefix)
def handle_data(self, data):
self.currentData.append(data)