diff options
author | Leonard Richardson <leonard.richardson@canonical.com> | 2011-02-18 12:10:10 -0500 |
---|---|---|
committer | Leonard Richardson <leonard.richardson@canonical.com> | 2011-02-18 12:10:10 -0500 |
commit | 0dda99b15112df7225e647db9702fbd62dcc8ea8 (patch) | |
tree | 1127d44d52716738835c6ab2128fdb1561bc7cc2 /beautifulsoup/__init__.py | |
parent | 66cbef12d959149746b3361f227f2a0328a31469 (diff) | |
parent | 945b719a28c229178e710b749d2af4d00a81bdba (diff) |
Defer to html5lib's Unicode converter rather than using Unicode, Dammit. The lxml treebuilder still uses UD.
Diffstat (limited to 'beautifulsoup/__init__.py')
-rw-r--r-- | beautifulsoup/__init__.py | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/beautifulsoup/__init__.py b/beautifulsoup/__init__.py index f2c20de..32ea73f 100644 --- a/beautifulsoup/__init__.py +++ b/beautifulsoup/__init__.py @@ -144,37 +144,29 @@ class BeautifulStoneSoup(Tag): self.builder.soup = self self.parseOnlyThese = parseOnlyThese - self.fromEncoding = fromEncoding self.reset() if hasattr(markup, 'read'): # It's a file-type object. markup = markup.read() - self.markup = markup + self.markup, self.originalEncoding, self.declaredHTMLEncoding = ( + self.builder.prepare_markup(markup, fromEncoding)) + try: - self._feed(isHTML=self.builder.assume_html) + self._feed() except StopParsing: pass - self.markup = None # The markup can now be GCed. + + # Clear out the markup and the builder so they can be CGed. + self.markup = None self.builder.soup = None - self.builder = None # So can the builder. + self.builder = None - def _feed(self, inDocumentEncoding=None, isHTML=False): + def _feed(self): # Convert the document to Unicode. - markup = self.markup - if isinstance(markup, unicode): - if not hasattr(self, 'originalEncoding'): - self.originalEncoding = None - else: - dammit = UnicodeDammit\ - (markup, [self.fromEncoding, inDocumentEncoding], - isHTML=isHTML) - markup = dammit.unicode - self.originalEncoding = dammit.originalEncoding - self.declaredHTMLEncoding = dammit.declaredHTMLEncoding self.builder.reset() - self.builder.feed(markup) + self.builder.feed(self.markup) # Close out any unfinished strings and close all the open tags. self.endData() while self.currentTag.name != self.ROOT_TAG_NAME: |