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


Python IO.read方法代码示例

本文整理汇总了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)
开发者ID:TkTech,项目名称:Jawa,代码行数:30,代码来源:cf.py

示例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)
开发者ID:bogdan-kulynych,项目名称:mypy,代码行数:15,代码来源:base64.py

示例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)
开发者ID:TkTech,项目名称:Jawa,代码行数:16,代码来源:fields.py

示例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))
开发者ID:TkTech,项目名称:Jawa,代码行数:18,代码来源:attribute.py

示例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)
开发者ID:clarkgrubb,项目名称:data-tools,代码行数:15,代码来源:html_table_to_csv.py

示例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
开发者ID:ESultanik,项目名称:lenticrypt,代码行数:16,代码来源:iowrapper.py

示例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
开发者ID:mongodb,项目名称:mut,代码行数:20,代码来源:Document.py

示例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
开发者ID:Mirantis,项目名称:ceph-monitoring,代码行数:8,代码来源:osd_ops.py


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