当前位置: 首页>>代码示例>>Python>>正文


Python inputstream.HTMLInputStream类代码示例

本文整理汇总了Python中html5lib.inputstream.HTMLInputStream的典型用法代码示例。如果您正苦于以下问题:Python HTMLInputStream类的具体用法?Python HTMLInputStream怎么用?Python HTMLInputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了HTMLInputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_python_issue_20007

    def test_python_issue_20007(self):
        """
        Make sure we have a work-around for Python bug #20007
        http://bugs.python.org/issue20007
        """
        class FakeSocket(object):
            def makefile(self, _mode, _bufsize=None):
                return BytesIO(b"HTTP/1.1 200 Ok\r\n\r\nText")

        source = http_client.HTTPResponse(FakeSocket())
        source.begin()
        stream = HTMLInputStream(source)
        self.assertEqual(stream.charsUntil(" "), "Text")
开发者ID:MaloChevillotte,项目名称:html5lib-python,代码行数:13,代码来源:test_stream.py

示例2: test_newlines

 def test_newlines(self):
     stream = HTMLInputStream(codecs.BOM_UTF8 + "a\nbb\r\nccc\rddddxe")
     self.assertEquals(stream.position(), (1, 0))
     self.assertEquals(stream.charsUntil('c'), u"a\nbb\n")
     self.assertEquals(stream.position(), (3, 0))
     self.assertEquals(stream.charsUntil('x'), u"ccc\ndddd")
     self.assertEquals(stream.position(), (4, 4))
     self.assertEquals(stream.charsUntil('e'), u"x")
     self.assertEquals(stream.position(), (4, 5))
开发者ID:alabid,项目名称:html5lib,代码行数:9,代码来源:test_stream.py

示例3: test_python_issue_20007_b

    def test_python_issue_20007_b(self):
        """
        Make sure we have a work-around for Python bug #20007
        http://bugs.python.org/issue20007
        """
        if six.PY2:
            return

        class FakeSocket(object):
            def makefile(self, _mode, _bufsize=None):
                return BytesIO(b"HTTP/1.1 200 Ok\r\n\r\nText")

        source = http_client.HTTPResponse(FakeSocket())
        source.begin()
        wrapped = urllib.response.addinfourl(source, source.msg, "http://example.com")
        stream = HTMLInputStream(wrapped)
        self.assertEqual(stream.charsUntil(" "), "Text")
开发者ID:MaloChevillotte,项目名称:html5lib-python,代码行数:17,代码来源:test_stream.py

示例4: test_position

 def test_position(self):
     stream = HTMLInputStream(codecs.BOM_UTF8 + "a\nbb\nccc\nddde\nf\ngh")
     self.assertEquals(stream.position(), (1, 0))
     self.assertEquals(stream.charsUntil('c'), u"a\nbb\n")
     self.assertEquals(stream.position(), (3, 0))
     stream.unget(u"\n")
     self.assertEquals(stream.position(), (2, 2))
     self.assertEquals(stream.charsUntil('c'), u"\n")
     self.assertEquals(stream.position(), (3, 0))
     stream.unget(u"\n")
     self.assertEquals(stream.position(), (2, 2))
     self.assertEquals(stream.char(), u"\n")
     self.assertEquals(stream.position(), (3, 0))
     self.assertEquals(stream.charsUntil('e'), u"ccc\nddd")
     self.assertEquals(stream.position(), (4, 3))
     self.assertEquals(stream.charsUntil('h'), u"e\nf\ng")
     self.assertEquals(stream.position(), (6, 1))
开发者ID:alabid,项目名称:html5lib,代码行数:17,代码来源:test_stream.py

示例5: test_newlines2

 def test_newlines2(self):
     size = HTMLUnicodeInputStream._defaultChunkSize
     stream = HTMLInputStream("\r" * size + "\n")
     self.assertEqual(stream.charsUntil('x'), "\n" * size)
开发者ID:MaloChevillotte,项目名称:html5lib-python,代码行数:4,代码来源:test_stream.py

示例6: test_utf_16

 def test_utf_16(self):
     stream = HTMLInputStream((' ' * 1025).encode('utf-16'))
     self.assertTrue(stream.charEncoding[0] in ['utf-16-le', 'utf-16-be'], stream.charEncoding)
     self.assertEqual(len(stream.charsUntil(' ', True)), 1025)
开发者ID:MaloChevillotte,项目名称:html5lib-python,代码行数:4,代码来源:test_stream.py

示例7: test_bom

 def test_bom(self):
     stream = HTMLInputStream(codecs.BOM_UTF8 + b"'")
     self.assertEqual(stream.charEncoding[0], 'utf-8')
     self.assertEqual(stream.char(), "'")
开发者ID:MaloChevillotte,项目名称:html5lib-python,代码行数:4,代码来源:test_stream.py

示例8: test_char_ascii

 def test_char_ascii(self):
     stream = HTMLInputStream(b"'", encoding='ascii')
     self.assertEqual(stream.charEncoding[0].name, 'windows-1252')
     self.assertEqual(stream.char(), "'")
开发者ID:DKChan,项目名称:html5lib-python,代码行数:4,代码来源:test_stream.py

示例9: test_char_null

 def test_char_null(self):
     stream = HTMLInputStream("\x00")
     self.assertEquals(stream.char(), u'\ufffd')
开发者ID:1974kpkpkp,项目名称:WebGL,代码行数:3,代码来源:test_stream.py

示例10: test_char_utf8

def test_char_utf8():
    stream = HTMLInputStream('\u2018'.encode('utf-8'), encoding='utf-8')
    assert stream.charEncoding[0].name == 'utf-8'
    assert stream.char() == '\u2018'
开发者ID:adamchainz,项目名称:html5lib-python,代码行数:4,代码来源:test_stream.py

示例11: test_char_utf8

 def test_char_utf8(self):
     stream = HTMLInputStream('\u2018'.encode('utf-8'), encoding='utf-8')
     self.assertEqual(stream.charEncoding[0], 'utf-8')
     self.assertEqual(stream.char(), '\u2018')
开发者ID:MaloChevillotte,项目名称:html5lib-python,代码行数:4,代码来源:test_stream.py

示例12: test_char_utf8

 def test_char_utf8(self):
     stream = HTMLInputStream(u'\u2018'.encode(u'utf-8'), encoding=u'utf-8')
     self.assertEquals(stream.charEncoding[0], u'utf-8')
     self.assertEquals(stream.char(), u'\u2018')
开发者ID:mikkorantalainen,项目名称:html5lib,代码行数:4,代码来源:test_stream.py

示例13: test_char_ascii

 def test_char_ascii(self):
     stream = HTMLInputStream("'", encoding=u'ascii')
     self.assertEquals(stream.charEncoding[0], u'ascii')
     self.assertEquals(stream.char(), u"'")
开发者ID:mikkorantalainen,项目名称:html5lib,代码行数:4,代码来源:test_stream.py

示例14: test_newlines2

def test_newlines2():
    size = HTMLUnicodeInputStream._defaultChunkSize
    stream = HTMLInputStream("\r" * size + "\n")
    assert stream.charsUntil('x') == "\n" * size
开发者ID:adamchainz,项目名称:html5lib-python,代码行数:4,代码来源:test_stream.py

示例15: test_utf_16

def test_utf_16():
    stream = HTMLInputStream((' ' * 1025).encode('utf-16'))
    assert stream.charEncoding[0].name in ['utf-16le', 'utf-16be']
    assert len(stream.charsUntil(' ', True)) == 1025
开发者ID:adamchainz,项目名称:html5lib-python,代码行数:4,代码来源:test_stream.py


注:本文中的html5lib.inputstream.HTMLInputStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。