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

Method __init__

pattern/web/soup/BeautifulSoup.py:1769–1801  ·  view source on GitHub ↗
(self, markup, overrideEncodings=[],
                 smartQuotesTo='xml', isHTML=False)

Source from the content-addressed store, hash-verified

1767 "x-sjis" : "shift-jis" }
1768
1769 def __init__(self, markup, overrideEncodings=[],
1770 smartQuotesTo='xml', isHTML=False):
1771 self.declaredHTMLEncoding = None
1772 self.markup, documentEncoding, sniffedEncoding = \
1773 self._detectEncoding(markup, isHTML)
1774 self.smartQuotesTo = smartQuotesTo
1775 self.triedEncodings = []
1776 if markup == '' or isinstance(markup, unicode):
1777 self.originalEncoding = None
1778 self.unicode = unicode(markup)
1779 return
1780
1781 u = None
1782 for proposedEncoding in overrideEncodings:
1783 u = self._convertFrom(proposedEncoding)
1784 if u: break
1785 if not u:
1786 for proposedEncoding in (documentEncoding, sniffedEncoding):
1787 u = self._convertFrom(proposedEncoding)
1788 if u: break
1789
1790 # If no luck and we have auto-detection library, try that:
1791 if not u and chardet and not isinstance(self.markup, unicode):
1792 u = self._convertFrom(chardet.detect(self.markup)['encoding'])
1793
1794 # As a last resort, try utf-8 and windows-1252:
1795 if not u:
1796 for proposed_encoding in ("utf-8", "windows-1252"):
1797 u = self._convertFrom(proposed_encoding)
1798 if u: break
1799
1800 self.unicode = u
1801 if not u: self.originalEncoding = None
1802
1803 def _subMSChar(self, orig):
1804 """Changes a MS smart quote character to an XML or HTML

Callers

nothing calls this directly

Calls 2

_detectEncodingMethod · 0.95
_convertFromMethod · 0.95

Tested by

no test coverage detected