本文整理匯總了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]