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