當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。