本文整理汇总了Python中io.py方法的典型用法代码示例。如果您正苦于以下问题:Python io.py方法的具体用法?Python io.py怎么用?Python io.py使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io
的用法示例。
在下文中一共展示了io.py方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_hierarchy
# 需要导入模块: import io [as 别名]
# 或者: from io import py [as 别名]
def test_hierarchy():
files = """
relimp:
- __init__.py
- a:
- __init__.py
- amodule.py: |
from ..b import bmodule
- b:
- __init__.py
- bmodule.py
"""
with create_files(files, cleanup=True) as workdir:
os.system("tree " + workdir)
deps = simpledeps('relimp')
assert 'relimp.b -> relimp.a.amodule' in deps
assert 'relimp.b.bmodule -> relimp.a.amodule' in deps
示例2: test_relative_imports
# 需要导入模块: import io [as 别名]
# 或者: from io import py [as 别名]
def test_relative_imports():
files = """
relimp:
- __init__.py
- a.py: |
from . import b
- b.py
"""
with create_files(files) as workdir:
assert simpledeps('relimp') == {'relimp.b -> relimp.a'}
示例3: test_relative_imports2
# 需要导入模块: import io [as 别名]
# 或者: from io import py [as 别名]
def test_relative_imports2():
files = """
relimp:
- __init__.py
- a.py: |
from . import b
- b.py: |
from . import c
- c.py
"""
with create_files(files) as workdir:
deps = simpledeps('relimp')
assert 'relimp.c -> relimp.b' in deps
assert 'relimp.b -> relimp.a' in deps
示例4: test_relative_imports3
# 需要导入模块: import io [as 别名]
# 或者: from io import py [as 别名]
def test_relative_imports3():
files = """
relimp:
- __init__.py
- a.py: |
from .b import c
- b.py
"""
with create_files(files) as workdir:
assert simpledeps('relimp') == {'relimp.b -> relimp.a'}
示例5: test_relative_imports_same_name_with_std
# 需要导入模块: import io [as 别名]
# 或者: from io import py [as 别名]
def test_relative_imports_same_name_with_std():
files = """
relimp:
- __init__.py
- io.py: |
import io
"""
with create_files(files) as workdir:
if sys.version_info < (3,): # pragma: nocover
deps = {'relimp.io -> relimp.io'}
else: # pragma: nocover
deps = {'io -> relimp.io'}
assert simpledeps('relimp', '--pylib') == deps
示例6: test_relative_imports_same_name_with_std_future
# 需要导入模块: import io [as 别名]
# 或者: from io import py [as 别名]
def test_relative_imports_same_name_with_std_future():
files = """
relimp:
- __init__.py
- io.py: |
from __future__ import absolute_import
import io
"""
with create_files(files) as workdir:
deps = {
'__future__ -> relimp.io',
'io -> relimp.io'
}
assert simpledeps('relimp', '--pylib') == deps
示例7: _get_decoder_func
# 需要导入模块: import io [as 别名]
# 或者: from io import py [as 别名]
def _get_decoder_func(self, schema_id, payload, is_key=False):
if schema_id in self.id_to_decoder_func:
return self.id_to_decoder_func[schema_id]
# fetch writer schema from schema reg
try:
writer_schema_obj = self.registry_client.get_by_id(schema_id)
except ClientError as e:
raise SerializerError("unable to fetch schema with id %d: %s" % (schema_id, str(e)))
if writer_schema_obj is None:
raise SerializerError("unable to fetch schema with id %d" % (schema_id))
curr_pos = payload.tell()
reader_schema_obj = self.reader_key_schema if is_key else self.reader_value_schema
if HAS_FAST:
# try to use fast avro
try:
fast_avro_writer_schema = parse_schema(writer_schema_obj.to_json())
fast_avro_reader_schema = parse_schema(reader_schema_obj.to_json())
schemaless_reader(payload, fast_avro_writer_schema)
# If we reach this point, this means we have fastavro and it can
# do this deserialization. Rewind since this method just determines
# the reader function and we need to deserialize again along the
# normal path.
payload.seek(curr_pos)
self.id_to_decoder_func[schema_id] = lambda p: schemaless_reader(
p, fast_avro_writer_schema, fast_avro_reader_schema)
return self.id_to_decoder_func[schema_id]
except Exception:
# Fast avro failed, fall thru to standard avro below.
pass
# here means we should just delegate to slow avro
# rewind
payload.seek(curr_pos)
# Avro DatumReader py2/py3 inconsistency, hence no param keywords
# should be revisited later
# https://github.com/apache/avro/blob/master/lang/py3/avro/io.py#L459
# https://github.com/apache/avro/blob/master/lang/py/src/avro/io.py#L423
# def __init__(self, writers_schema=None, readers_schema=None)
# def __init__(self, writer_schema=None, reader_schema=None)
avro_reader = avro.io.DatumReader(writer_schema_obj, reader_schema_obj)
def decoder(p):
bin_decoder = avro.io.BinaryDecoder(p)
return avro_reader.read(bin_decoder)
self.id_to_decoder_func[schema_id] = decoder
return self.id_to_decoder_func[schema_id]