MCPcopy Create free account
hub / github.com/clips/pattern / _convertFrom

Method _convertFrom

pattern/web/soup/BeautifulSoup.py:1814–1840  ·  view source on GitHub ↗
(self, proposed)

Source from the content-addressed store, hash-verified

1812 return sub
1813
1814 def _convertFrom(self, proposed):
1815 proposed = self.find_codec(proposed)
1816 if not proposed or proposed in self.triedEncodings:
1817 return None
1818 self.triedEncodings.append(proposed)
1819 markup = self.markup
1820
1821 # Convert smart quotes to HTML if coming from an encoding
1822 # that might have them.
1823 if self.smartQuotesTo and proposed.lower() in("windows-1252",
1824 "iso-8859-1",
1825 "iso-8859-2"):
1826 markup = re.compile("([\x80-\x9f])").sub \
1827 (lambda(x): self._subMSChar(x.group(1)),
1828 markup)
1829
1830 try:
1831 # print "Trying to convert document to %s" % proposed
1832 u = self._toUnicode(markup, proposed)
1833 self.markup = u
1834 self.originalEncoding = proposed
1835 except Exception, e:
1836 # print "That didn't work!"
1837 # print e
1838 return None
1839 #print "Correct encoding: %s" % proposed
1840 return self.markup
1841
1842 def _toUnicode(self, data, encoding):
1843 '''Given a string and its encoding, decodes the string into Unicode.

Callers 1

__init__Method · 0.95

Calls 5

find_codecMethod · 0.95
_subMSCharMethod · 0.95
_toUnicodeMethod · 0.95
appendMethod · 0.45
groupMethod · 0.45

Tested by

no test coverage detected