本文整理汇总了Python中io.UnsupportedOperation方法的典型用法代码示例。如果您正苦于以下问题:Python io.UnsupportedOperation方法的具体用法?Python io.UnsupportedOperation怎么用?Python io.UnsupportedOperation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io
的用法示例。
在下文中一共展示了io.UnsupportedOperation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read
# 需要导入模块: import io [as 别名]
# 或者: from io import UnsupportedOperation [as 别名]
def read(self, length): # type: (int) -> str
"""
Reads the given amount of characters from the stream.
"""
if self.is_closed():
raise io.UnsupportedOperation("Cannot read from a closed input.")
try:
data = self._stream.read(length)
except EOFError:
return ""
if data:
return data
return ""
示例2: seek_stream
# 需要导入模块: import io [as 别名]
# 或者: from io import UnsupportedOperation [as 别名]
def seek_stream(self, seek_pos):
"""Move position of bstream to seek_pos"""
try:
self.bstream[0].seek(seek_pos)
self.bstream[1] = seek_pos
return
except UnsupportedOperation:
chunksize = 4 * 1024**2
if seek_pos >= self.bstream[1]:
while seek_pos - self.bstream[1] > chunksize:
self.read_stream(chunksize)
self.read_stream(seek_pos - self.bstream[1])
return
self.bstream[0].close()
self.bstream[1] = 0
self.bstream = self.get_bstream(self.imgpath)
while seek_pos - self.bstream[1] > chunksize:
self.read_stream(chunksize)
self.read_stream(seek_pos - self.bstream[1])
return
示例3: super_len
# 需要导入模块: import io [as 别名]
# 或者: from io import UnsupportedOperation [as 别名]
def super_len(o):
if hasattr(o, '__len__'):
return len(o)
if hasattr(o, 'len'):
return o.len
if hasattr(o, 'fileno'):
try:
fileno = o.fileno()
except io.UnsupportedOperation:
pass
else:
return os.fstat(fileno).st_size
if hasattr(o, 'getvalue'):
# e.g. BytesIO, cStringIO.StringIO
return len(o.getvalue())
示例4: seek
# 需要导入模块: import io [as 别名]
# 或者: from io import UnsupportedOperation [as 别名]
def seek(self, offset: int, whence: int = io.SEEK_SET) -> int:
self._check_open()
self._check_random()
if whence == io.SEEK_SET:
ok = self.dev.seek(offset)
elif whence == io.SEEK_CUR:
ok = self.dev.seek(self.tell() + offset)
elif whence == io.SEEK_END:
ok = self.dev.seek(len(self) + offset)
else:
raise io.UnsupportedOperation("whence = {} is not "
"supported!".format(whence))
if not ok:
raise QtOSError(self.dev, msg="seek failed!")
return self.dev.pos()
示例5: read
# 需要导入模块: import io [as 别名]
# 或者: from io import UnsupportedOperation [as 别名]
def read(self, *files, **params):
""" Read and parse INI files.
:param *files: Files for reading
:param **params: Params for parsing
Set `update=False` for prevent values redefinition.
"""
for f in files:
try:
with io.open(f, encoding='utf-8') as ff:
NS_LOGGER.info('Read from `{0}`'.format(ff.name))
self.parse(ff.read(), **params)
except (IOError, TypeError, SyntaxError, io.UnsupportedOperation):
if not self.silent_read:
NS_LOGGER.error('Reading error `{0}`'.format(ff.name))
raise
示例6: chunks
# 需要导入模块: import io [as 别名]
# 或者: from io import UnsupportedOperation [as 别名]
def chunks(self, chunk_size=None):
"""
Read the file and yield chunks of ``chunk_size`` bytes (defaults to
``UploadedFile.DEFAULT_CHUNK_SIZE``).
"""
if not chunk_size:
chunk_size = self.DEFAULT_CHUNK_SIZE
try:
self.seek(0)
except (AttributeError, UnsupportedOperation):
pass
while True:
data = self.read(chunk_size)
if not data:
break
yield data
示例7: write
# 需要导入模块: import io [as 别名]
# 或者: from io import UnsupportedOperation [as 别名]
def write(self, string): # type: (str) -> None
"""
Writes a string to the stream.
"""
if self.is_closed():
raise io.UnsupportedOperation("Cannot write to a closed input.")
self._stream.write(string)
self._stream.flush()
示例8: flush
# 需要导入模块: import io [as 别名]
# 或者: from io import UnsupportedOperation [as 别名]
def flush(self): # type: () -> None
"""
Flushes the stream and forces all pending text to be written out.
"""
if self.is_closed():
raise io.UnsupportedOperation("Cannot write to a closed input.")
self._stream.flush()
示例9: read_line
# 需要导入模块: import io [as 别名]
# 或者: from io import UnsupportedOperation [as 别名]
def read_line(self, length=None): # type: (Optional[int]) -> str
"""
Reads a line from the stream.
"""
if self.is_closed():
raise io.UnsupportedOperation("Cannot read from a closed input.")
try:
return self._stream.readline(length) or ""
except EOFError:
return ""
示例10: __new__
# 需要导入模块: import io [as 别名]
# 或者: from io import UnsupportedOperation [as 别名]
def __new__(cls, *args, **kwargs):
return open(*args, **kwargs)
# In normal operation, both `UnsupportedOperation`s should be bound to the
# same object.
示例11: _unsupported
# 需要导入模块: import io [as 别名]
# 或者: from io import UnsupportedOperation [as 别名]
def _unsupported(self, name):
"""Internal: raise an IOError exception for unsupported operations."""
raise UnsupportedOperation("%s.%s() not supported" %
(self.__class__.__name__, name))
### Positioning ###
示例12: seekable
# 需要导入模块: import io [as 别名]
# 或者: from io import UnsupportedOperation [as 别名]
def seekable(self):
"""Return a bool indicating whether object supports random access.
If False, seek(), tell() and truncate() will raise UnsupportedOperation.
This method may need to do a test seek().
"""
return False
示例13: readable
# 需要导入模块: import io [as 别名]
# 或者: from io import UnsupportedOperation [as 别名]
def readable(self):
"""Return a bool indicating whether object was opened for reading.
If False, read() will raise UnsupportedOperation.
"""
return False
示例14: _checkReadable
# 需要导入模块: import io [as 别名]
# 或者: from io import UnsupportedOperation [as 别名]
def _checkReadable(self, msg=None):
"""Internal: raise UnsupportedOperation if file is not readable
"""
if not self.readable():
raise UnsupportedOperation("File or stream is not readable."
if msg is None else msg)
示例15: writable
# 需要导入模块: import io [as 别名]
# 或者: from io import UnsupportedOperation [as 别名]
def writable(self):
"""Return a bool indicating whether object was opened for writing.
If False, write() and truncate() will raise UnsupportedOperation.
"""
return False