本文整理汇总了Python中typing.IO.read方法的典型用法代码示例。如果您正苦于以下问题:Python IO.read方法的具体用法?Python IO.read怎么用?Python IO.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类typing.IO
的用法示例。
在下文中一共展示了IO.read方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _from_io
# 需要导入模块: from typing import IO [as 别名]
# 或者: from typing.IO import read [as 别名]
def _from_io(self, source: IO):
"""
Loads an existing JVM ClassFile from any file-like object.
"""
read = source.read
if unpack('>I', source.read(4))[0] != ClassFile.MAGIC:
raise ValueError('invalid magic number')
# The version is swapped on disk to (minor, major), so swap it back.
self.version = unpack('>HH', source.read(4))[::-1]
self._constants.unpack(source)
# ClassFile access_flags, see section #4.1 of the JVM specs.
self.access_flags.unpack(read(2))
# The CONSTANT_Class indexes for "this" class and its superclass.
# Interfaces are a simple list of CONSTANT_Class indexes.
self._this, self._super, interfaces_count = unpack('>HHH', read(6))
self._interfaces = unpack(
f'>{interfaces_count}H',
read(2 * interfaces_count)
)
self.fields.unpack(source)
self.methods.unpack(source)
self.attributes.unpack(source)
示例2: encode
# 需要导入模块: from typing import IO [as 别名]
# 或者: from typing.IO import read [as 别名]
def encode(input: IO, output: IO) -> None:
"""Encode a file; input and output are binary files."""
while True:
s = input.read(MAXBINSIZE)
if not s:
break
while len(s) < MAXBINSIZE:
ns = input.read(MAXBINSIZE-len(s))
if not ns:
break
s += ns
line = binascii.b2a_base64(s)
output.write(line)
示例3: unpack
# 需要导入模块: from typing import IO [as 别名]
# 或者: from typing.IO import read [as 别名]
def unpack(self, source: IO):
"""
Read the Field from the file-like object `fio`.
.. note::
Advanced usage only. You will typically never need to call this
method as it will be called for you when loading a ClassFile.
:param source: Any file-like object providing `read()`
"""
self.access_flags.unpack(source.read(2))
self._name_index, self._descriptor_index = unpack('>HH', source.read(4))
self.attributes.unpack(source)
示例4: unpack
# 需要导入模块: from typing import IO [as 别名]
# 或者: from typing.IO import read [as 别名]
def unpack(self, source: IO):
"""
Read the ConstantPool from the file-like object `source`.
.. note::
Advanced usage only. You will typically never need to call this
method as it will be called for you when loading a ClassFile.
:param source: Any file-like object providing `read()`
"""
count = unpack('>H', source.read(2))[0]
for _ in repeat(None, count):
name_index, length = unpack('>HI', source.read(6))
info_blob = source.read(length)
self._table.append((name_index, info_blob))
示例5: html_table_to_csv
# 需要导入模块: from typing import IO [as 别名]
# 或者: from typing.IO import read [as 别名]
def html_table_to_csv(input_f: IO, output_f: IO, table_num: int) -> None:
doc = bs4.BeautifulSoup(input_f.read(), 'html5lib')
tables = doc.find_all('table')
try:
table = tables[table_num]
trows = table.find_all('tr')
csv_writer = csv.writer(output_f)
for trow in trows:
cells = trow.find_all(RX_TH_OR_TD)
csv_writer.writerow([cell.text.strip() for cell in cells])
except IndexError:
sys.stderr.write('ERROR: no table at index {}\n'.format(table_num))
sys.exit(1)
示例6: get_length
# 需要导入模块: from typing import IO [as 别名]
# 或者: from typing.IO import read [as 别名]
def get_length(stream: IO) -> int:
"""Gets the number of bytes in the stream."""
old_position = stream.tell()
stream.seek(0)
length = 0
try:
while True:
r = stream.read(1024)
if not r:
break
length += len(r)
finally:
stream.seek(old_position)
return length
示例7: parse_html
# 需要导入模块: from typing import IO [as 别名]
# 或者: from typing.IO import read [as 别名]
def parse_html(self, fh: IO) -> Dict[str, Any]:
'''Return head and content elements of the document.'''
capsule = html_parser.parse(fh.read(), maybe_xhtml=True)
doc = etree.adopt_external_document(capsule).getroot()
result = {}
result['head'] = doc.cssselect('head')[0]
for candidate in ('.main-column .section', '.main__content'):
elements = doc.cssselect(candidate)
if elements:
result['main_content'] = elements[0]
break
if 'main_content' not in result:
raise ValueError('No main content element found')
return result
示例8: iter_ceph_ops
# 需要导入模块: from typing import IO [as 别名]
# 或者: from typing.IO import read [as 别名]
def iter_ceph_ops(fd: IO):
data = fd.read()
offset = 0
while offset < len(data):
op, offset = CephOp.unpack(data, offset)
yield op