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


Python io.UnsupportedOperation方法代码示例

本文整理汇总了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 "" 
开发者ID:sdispater,项目名称:clikit,代码行数:18,代码来源:stream_input_stream.py

示例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 
开发者ID:emilsvennesson,项目名称:script.module.inputstreamhelper,代码行数:27,代码来源:arm_chromeos.py

示例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()) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:20,代码来源:utils.py

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

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

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

示例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() 
开发者ID:sdispater,项目名称:clikit,代码行数:11,代码来源:stream_output_stream.py

示例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() 
开发者ID:sdispater,项目名称:clikit,代码行数:10,代码来源:stream_output_stream.py

示例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 "" 
开发者ID:sdispater,项目名称:clikit,代码行数:13,代码来源:stream_input_stream.py

示例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. 
开发者ID:war-and-code,项目名称:jawfish,代码行数:8,代码来源:_io.py

示例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 ### 
开发者ID:war-and-code,项目名称:jawfish,代码行数:8,代码来源:_io.py

示例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 
开发者ID:war-and-code,项目名称:jawfish,代码行数:9,代码来源:_io.py

示例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 
开发者ID:war-and-code,项目名称:jawfish,代码行数:8,代码来源:_io.py

示例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) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:8,代码来源:_io.py

示例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 
开发者ID:war-and-code,项目名称:jawfish,代码行数:8,代码来源:_io.py


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