當前位置: 首頁>>代碼示例>>Python>>正文


Python dammit.UnicodeDammit方法代碼示例

本文整理匯總了Python中bs4.dammit.UnicodeDammit方法的典型用法代碼示例。如果您正苦於以下問題:Python dammit.UnicodeDammit方法的具體用法?Python dammit.UnicodeDammit怎麽用?Python dammit.UnicodeDammit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在bs4.dammit的用法示例。


在下文中一共展示了dammit.UnicodeDammit方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: prepare_markup

# 需要導入模塊: from bs4 import dammit [as 別名]
# 或者: from bs4.dammit import UnicodeDammit [as 別名]
def prepare_markup(self, markup, user_specified_encoding=None,
                       document_declared_encoding=None, exclude_encodings=None):
        """
        :return: A 4-tuple (markup, original encoding, encoding
        declared within markup, whether any characters had to be
        replaced with REPLACEMENT CHARACTER).
        """
        if isinstance(markup, unicode):
            yield (markup, None, None, False)
            return

        try_encodings = [user_specified_encoding, document_declared_encoding]
        dammit = UnicodeDammit(markup, try_encodings, is_html=True,
                               exclude_encodings=exclude_encodings)
        yield (dammit.markup, dammit.original_encoding,
               dammit.declared_html_encoding,
               dammit.contains_replacement_characters) 
開發者ID:MarcelloLins,項目名稱:ServerlessCrawler-VancouverRealState,代碼行數:19,代碼來源:_htmlparser.py

示例2: prepare_markup

# 需要導入模塊: from bs4 import dammit [as 別名]
# 或者: from bs4.dammit import UnicodeDammit [as 別名]
def prepare_markup(self, markup, user_specified_encoding=None,
                       document_declared_encoding=None):
        """
        :return: A 4-tuple (markup, original encoding, encoding
        declared within markup, whether any characters had to be
        replaced with REPLACEMENT CHARACTER).
        """
        if isinstance(markup, unicode):
            yield (markup, None, None, False)
            return

        try_encodings = [user_specified_encoding, document_declared_encoding]
        dammit = UnicodeDammit(markup, try_encodings, is_html=True)
        yield (dammit.markup, dammit.original_encoding,
               dammit.declared_html_encoding,
               dammit.contains_replacement_characters) 
開發者ID:MayOneUS,項目名稱:pledgeservice,代碼行數:18,代碼來源:_htmlparser.py

示例3: prepare_markup

# 需要導入模塊: from bs4 import dammit [as 別名]
# 或者: from bs4.dammit import UnicodeDammit [as 別名]
def prepare_markup(self, markup, user_specified_encoding=None,
                       document_declared_encoding=None, exclude_encodings=None):
        """
        :return: A 4-tuple (markup, original encoding, encoding
        declared within markup, whether any characters had to be
        replaced with REPLACEMENT CHARACTER).
        """
        if isinstance(markup, str):
            yield (markup, None, None, False)
            return

        try_encodings = [user_specified_encoding, document_declared_encoding]
        dammit = UnicodeDammit(markup, try_encodings, is_html=True,
                               exclude_encodings=exclude_encodings)
        yield (dammit.markup, dammit.original_encoding,
               dammit.declared_html_encoding,
               dammit.contains_replacement_characters) 
開發者ID:the-ethan-hunt,項目名稱:B.E.N.J.I.,代碼行數:19,代碼來源:_htmlparser.py

示例4: prepare_markup

# 需要導入模塊: from bs4 import dammit [as 別名]
# 或者: from bs4.dammit import UnicodeDammit [as 別名]
def prepare_markup(self, markup, user_specified_encoding=None,
                       document_declared_encoding=None):
        """
        :return: A 4-tuple (markup, original encoding, encoding
        declared within markup, whether any characters had to be
        replaced with REPLACEMENT CHARACTER).
        """
        if isinstance(markup, unicode):
            return markup, None, None, False

        try_encodings = [user_specified_encoding, document_declared_encoding]
        dammit = UnicodeDammit(markup, try_encodings, is_html=True)
        return (dammit.markup, dammit.original_encoding,
                dammit.declared_html_encoding,
                dammit.contains_replacement_characters) 
開發者ID:einstein95,項目名稱:crunchy-xml-decoder,代碼行數:17,代碼來源:_htmlparser.py

示例5: prepare_markup

# 需要導入模塊: from bs4 import dammit [as 別名]
# 或者: from bs4.dammit import UnicodeDammit [as 別名]
def prepare_markup(self, markup, user_specified_encoding=None,
                       document_declared_encoding=None):
        """
        :return: A 3-tuple (markup, original encoding, encoding
        declared within markup).
        """
        if isinstance(markup, unicode):
            return markup, None, None, False

        try_encodings = [user_specified_encoding, document_declared_encoding]
        dammit = UnicodeDammit(markup, try_encodings, is_html=True)
        return (dammit.markup, dammit.original_encoding,
                dammit.declared_html_encoding,
                dammit.contains_replacement_characters) 
開發者ID:einstein95,項目名稱:crunchy-xml-decoder,代碼行數:16,代碼來源:_lxml.py

示例6: test_smart_quote_substitution

# 需要導入模塊: from bs4 import dammit [as 別名]
# 或者: from bs4.dammit import UnicodeDammit [as 別名]
def test_smart_quote_substitution(self):
        # MS smart quotes are a common source of frustration, so we
        # give them a special test.
        quotes = b"\x91\x92foo\x93\x94"
        dammit = UnicodeDammit(quotes)
        self.assertEqual(self.sub.substitute_html(dammit.markup),
                          "‘’foo“”") 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:9,代碼來源:test_soup.py

示例7: test_smart_quotes_to_unicode

# 需要導入模塊: from bs4 import dammit [as 別名]
# 或者: from bs4.dammit import UnicodeDammit [as 別名]
def test_smart_quotes_to_unicode(self):
        markup = b"<foo>\x91\x92\x93\x94</foo>"
        dammit = UnicodeDammit(markup)
        self.assertEqual(
            dammit.unicode_markup, "<foo>\u2018\u2019\u201c\u201d</foo>") 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:7,代碼來源:test_soup.py

示例8: test_smart_quotes_to_xml_entities

# 需要導入模塊: from bs4 import dammit [as 別名]
# 或者: from bs4.dammit import UnicodeDammit [as 別名]
def test_smart_quotes_to_xml_entities(self):
        markup = b"<foo>\x91\x92\x93\x94</foo>"
        dammit = UnicodeDammit(markup, smart_quotes_to="xml")
        self.assertEqual(
            dammit.unicode_markup, "<foo>&#x2018;&#x2019;&#x201C;&#x201D;</foo>") 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:7,代碼來源:test_soup.py

示例9: test_smart_quotes_to_html_entities

# 需要導入模塊: from bs4 import dammit [as 別名]
# 或者: from bs4.dammit import UnicodeDammit [as 別名]
def test_smart_quotes_to_html_entities(self):
        markup = b"<foo>\x91\x92\x93\x94</foo>"
        dammit = UnicodeDammit(markup, smart_quotes_to="html")
        self.assertEqual(
            dammit.unicode_markup, "<foo>&lsquo;&rsquo;&ldquo;&rdquo;</foo>") 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:7,代碼來源:test_soup.py

示例10: test_detect_utf8

# 需要導入模塊: from bs4 import dammit [as 別名]
# 或者: from bs4.dammit import UnicodeDammit [as 別名]
def test_detect_utf8(self):
        utf8 = b"\xc3\xa9"
        dammit = UnicodeDammit(utf8)
        self.assertEqual(dammit.unicode_markup, '\xe9')
        self.assertEqual(dammit.original_encoding, 'utf-8') 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:7,代碼來源:test_soup.py


注:本文中的bs4.dammit.UnicodeDammit方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。