summaryrefslogtreecommitdiff
path: root/beautifulsoup
diff options
context:
space:
mode:
authorLeonard Richardson <leonard.richardson@canonical.com>2011-02-13 19:40:29 -0500
committerLeonard Richardson <leonard.richardson@canonical.com>2011-02-13 19:40:29 -0500
commit09c9ca430e49449cc39cbeb7556230cb62df9b19 (patch)
treebf94e18ac8887851dcf84cb5140aa453a1b74316 /beautifulsoup
parent4191d5ff45015c6fac1db0bbdd7b3fcaff234424 (diff)
Added tests for namespaced doctypes.
Diffstat (limited to 'beautifulsoup')
-rw-r--r--beautifulsoup/__init__.py14
-rw-r--r--beautifulsoup/builder/lxml_builder.py4
-rw-r--r--beautifulsoup/element.py10
3 files changed, 21 insertions, 7 deletions
diff --git a/beautifulsoup/__init__.py b/beautifulsoup/__init__.py
index 4a7e18b..ddf51f9 100644
--- a/beautifulsoup/__init__.py
+++ b/beautifulsoup/__init__.py
@@ -222,11 +222,15 @@ class BeautifulStoneSoup(Tag):
not self.parseOnlyThese.search(currentData)):
return
o = containerClass(currentData)
- o.setup(self.currentTag, self.previous)
- if self.previous:
- self.previous.next = o
- self.previous = o
- self.currentTag.contents.append(o)
+ self.object_was_parsed(o)
+
+ def object_was_parsed(self, o):
+ """Add an object to the parse tree."""
+ o.setup(self.currentTag, self.previous)
+ if self.previous:
+ self.previous.next = o
+ self.previous = o
+ self.currentTag.contents.append(o)
def _popToTag(self, name, inclusivePop=True):
diff --git a/beautifulsoup/builder/lxml_builder.py b/beautifulsoup/builder/lxml_builder.py
index 86ac183..9ced9f0 100644
--- a/beautifulsoup/builder/lxml_builder.py
+++ b/beautifulsoup/builder/lxml_builder.py
@@ -32,8 +32,8 @@ class LXMLTreeBuilder(HTMLTreeBuilder):
def doctype(self, name, pubid, system):
self.soup.endData()
- self.soup.handle_data(name)
- self.soup.endData(Doctype)
+ doctype = Doctype.for_name_and_ids(name, pubid, system)
+ self.soup.object_was_parsed(doctype)
def comment(self, content):
"Handle comments as Comment objects."
diff --git a/beautifulsoup/element.py b/beautifulsoup/element.py
index b2e0e12..8749114 100644
--- a/beautifulsoup/element.py
+++ b/beautifulsoup/element.py
@@ -372,6 +372,16 @@ class Declaration(NavigableString):
class Doctype(NavigableString):
+ @classmethod
+ def for_name_and_ids(cls, name, pub_id, system_id):
+ value = name
+ if pub_id is not None:
+ value += ' PUBLIC "%s"' % pub_id
+ if system_id is not None:
+ value += ' SYSTEM "%s"' % system_id
+
+ return Doctype(value)
+
def decodeGivenEventualEncoding(self, eventualEncoding):
return u'<!DOCTYPE ' + self + u'>'