本文整理汇总了Python中html5lib.inputstream.HTMLInputStream.charsUntil方法的典型用法代码示例。如果您正苦于以下问题:Python HTMLInputStream.charsUntil方法的具体用法?Python HTMLInputStream.charsUntil怎么用?Python HTMLInputStream.charsUntil使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类html5lib.inputstream.HTMLInputStream
的用法示例。
在下文中一共展示了HTMLInputStream.charsUntil方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_newlines
# 需要导入模块: from html5lib.inputstream import HTMLInputStream [as 别名]
# 或者: from html5lib.inputstream.HTMLInputStream import charsUntil [as 别名]
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))
示例2: test_position
# 需要导入模块: from html5lib.inputstream import HTMLInputStream [as 别名]
# 或者: from html5lib.inputstream.HTMLInputStream import charsUntil [as 别名]
def test_position(self):
stream = HTMLInputStream(codecs.BOM_UTF8 + "a\nbb\nccc\nddd")
self.assertEquals(stream.position(), (1, 0))
self.assertEquals(stream.charsUntil('c'),u"a\nbb\n")
self.assertEquals(stream.position(), (3, 0))
stream.unget("a\nbb\n")
self.assertEquals(stream.position(), (1, 0))
self.assertEquals(stream.charsUntil('c'),u"a\nbb\n")
self.assertEquals(stream.position(), (3, 0))
stream.unget("\n")
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))
示例3: test_python_issue_20007
# 需要导入模块: from html5lib.inputstream import HTMLInputStream [as 别名]
# 或者: from html5lib.inputstream.HTMLInputStream import charsUntil [as 别名]
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")
示例4: test_python_issue_20007_b
# 需要导入模块: from html5lib.inputstream import HTMLInputStream [as 别名]
# 或者: from html5lib.inputstream.HTMLInputStream import charsUntil [as 别名]
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")
示例5: test_newlines2
# 需要导入模块: from html5lib.inputstream import HTMLInputStream [as 别名]
# 或者: from html5lib.inputstream.HTMLInputStream import charsUntil [as 别名]
def test_newlines2(self):
size = HTMLUnicodeInputStream._defaultChunkSize
stream = HTMLInputStream("\r" * size + "\n")
self.assertEqual(stream.charsUntil('x'), "\n" * size)
示例6: test_utf_16
# 需要导入模块: from html5lib.inputstream import HTMLInputStream [as 别名]
# 或者: from html5lib.inputstream.HTMLInputStream import charsUntil [as 别名]
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)
示例7: test_newlines2
# 需要导入模块: from html5lib.inputstream import HTMLInputStream [as 别名]
# 或者: from html5lib.inputstream.HTMLInputStream import charsUntil [as 别名]
def test_newlines2():
size = HTMLUnicodeInputStream._defaultChunkSize
stream = HTMLInputStream("\r" * size + "\n")
assert stream.charsUntil('x') == "\n" * size
示例8: test_utf_16
# 需要导入模块: from html5lib.inputstream import HTMLInputStream [as 别名]
# 或者: from html5lib.inputstream.HTMLInputStream import charsUntil [as 别名]
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