Python io.UnsupportedOperation() Examples
The following are 30
code examples of io.UnsupportedOperation().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
io
, or try the search function
.
Example #1
Source File: inirama.py From linter-pylama with MIT License | 6 votes |
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
Example #2
Source File: stream_output_stream.py From clikit with MIT License | 6 votes |
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()
Example #3
Source File: arm_chromeos.py From script.module.inputstreamhelper with MIT License | 6 votes |
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
Example #4
Source File: utils.py From jawfish with MIT License | 6 votes |
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())
Example #5
Source File: utils.py From pledgeservice with Apache License 2.0 | 6 votes |
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())
Example #6
Source File: utils.py From faces with GNU General Public License v2.0 | 6 votes |
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())
Example #7
Source File: utils.py From pledgeservice with Apache License 2.0 | 6 votes |
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())
Example #8
Source File: utils.py From vulscan with MIT License | 6 votes |
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())
Example #9
Source File: utils.py From faces with GNU General Public License v2.0 | 6 votes |
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())
Example #10
Source File: qtutils.py From qutebrowser with GNU General Public License v3.0 | 6 votes |
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()
Example #11
Source File: base.py From GTDWeb with GNU General Public License v2.0 | 6 votes |
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
Example #12
Source File: base.py From omniduct with MIT License | 5 votes |
def read(self, size=-1): if not self.readable: raise io.UnsupportedOperation("File not open for reading.") return self.__io_buffer.read(size)
Example #13
Source File: base.py From omniduct with MIT License | 5 votes |
def detach(self): raise io.UnsupportedOperation()
Example #14
Source File: utils.py From SalesforceXyTools with Apache License 2.0 | 5 votes |
def super_len(o): total_length = 0 current_position = 0 if hasattr(o, '__len__'): total_length = len(o) elif hasattr(o, 'len'): total_length = o.len elif hasattr(o, 'getvalue'): # e.g. BytesIO, cStringIO.StringIO total_length = len(o.getvalue()) elif hasattr(o, 'fileno'): try: fileno = o.fileno() except io.UnsupportedOperation: pass else: total_length = os.fstat(fileno).st_size # Having used fstat to determine the file length, we need to # confirm that this file was opened up in binary mode. if 'b' not in o.mode: warnings.warn(( "Requests has determined the content-length for this " "request using the binary size of the file: however, the " "file has been opened in text mode (i.e. without the 'b' " "flag in the mode). This may lead to an incorrect " "content-length. In Requests 3.0, support will be removed " "for files in text mode."), FileModeWarning ) if hasattr(o, 'tell'): current_position = o.tell() return max(0, total_length - current_position)
Example #15
Source File: util.py From jbox with MIT License | 5 votes |
def has_fileno(obj): if not hasattr(obj, "fileno"): return False # check BytesIO case and maybe others try: obj.fileno() except (AttributeError, IOError, io.UnsupportedOperation): return False return True
Example #16
Source File: utils.py From jbox with MIT License | 5 votes |
def super_len(o): total_length = 0 current_position = 0 if hasattr(o, '__len__'): total_length = len(o) elif hasattr(o, 'len'): total_length = o.len elif hasattr(o, 'getvalue'): # e.g. BytesIO, cStringIO.StringIO total_length = len(o.getvalue()) elif hasattr(o, 'fileno'): try: fileno = o.fileno() except io.UnsupportedOperation: pass else: total_length = os.fstat(fileno).st_size # Having used fstat to determine the file length, we need to # confirm that this file was opened up in binary mode. if 'b' not in o.mode: warnings.warn(( "Requests has determined the content-length for this " "request using the binary size of the file: however, the " "file has been opened in text mode (i.e. without the 'b' " "flag in the mode). This may lead to an incorrect " "content-length. In Requests 3.0, support will be removed " "for files in text mode."), FileModeWarning ) if hasattr(o, 'tell'): current_position = o.tell() return max(0, total_length - current_position)
Example #17
Source File: _io.py From jawfish with MIT License | 5 votes |
def readable(self): """Return a bool indicating whether object was opened for reading. If False, read() will raise UnsupportedOperation. """ return False
Example #18
Source File: test_qtutils.py From qutebrowser with GNU General Public License v3.0 | 5 votes |
def test_seek_unsupported(self, pyqiodev): """Test seeking with unsupported whence arguments.""" # pylint: disable=no-member,useless-suppression if hasattr(os, 'SEEK_HOLE'): whence = os.SEEK_HOLE elif hasattr(os, 'SEEK_DATA'): whence = os.SEEK_DATA # pylint: enable=no-member,useless-suppression else: pytest.skip("Needs os.SEEK_HOLE or os.SEEK_DATA available.") pyqiodev.open(QIODevice.ReadOnly) with pytest.raises(io.UnsupportedOperation): pyqiodev.seek(0, whence)
Example #19
Source File: base.py From omniduct with MIT License | 5 votes |
def readline(self, size=-1): if not self.readable: raise io.UnsupportedOperation("File not open for reading.") return self.__io_buffer.readline(size)
Example #20
Source File: base.py From omniduct with MIT License | 5 votes |
def readlines(self, hint=-1): if not self.readable: raise io.UnsupportedOperation("File not open for reading.") return self.__io_buffer.readlines(hint)
Example #21
Source File: base.py From omniduct with MIT License | 5 votes |
def write(self, s): if not self.writable: raise io.UnsupportedOperation("File not open for writing.") self.__io_buffer.write(s) self.__modified = True
Example #22
Source File: utils.py From plugin.video.emby with GNU General Public License v3.0 | 5 votes |
def super_len(o): total_length = 0 current_position = 0 if hasattr(o, '__len__'): total_length = len(o) elif hasattr(o, 'len'): total_length = o.len elif hasattr(o, 'getvalue'): # e.g. BytesIO, cStringIO.StringIO total_length = len(o.getvalue()) elif hasattr(o, 'fileno'): try: fileno = o.fileno() except io.UnsupportedOperation: pass else: total_length = os.fstat(fileno).st_size # Having used fstat to determine the file length, we need to # confirm that this file was opened up in binary mode. if 'b' not in o.mode: warnings.warn(( "Requests has determined the content-length for this " "request using the binary size of the file: however, the " "file has been opened in text mode (i.e. without the 'b' " "flag in the mode). This may lead to an incorrect " "content-length. In Requests 3.0, support will be removed " "for files in text mode."), FileModeWarning ) if hasattr(o, 'tell'): current_position = o.tell() return max(0, total_length - current_position)
Example #23
Source File: capture.py From python-netsurv with MIT License | 5 votes |
def fileno(self): raise UnsupportedOperation("redirected stdin is pseudofile, has no fileno()")
Example #24
Source File: faulthandler.py From python-netsurv with MIT License | 5 votes |
def _get_stderr_fileno(): try: return sys.stderr.fileno() except (AttributeError, io.UnsupportedOperation): # python-xdist monkeypatches sys.stderr with an object that is not an actual file. # https://docs.python.org/3/library/faulthandler.html#issue-with-file-descriptors # This is potentially dangerous, but the best we can do. return sys.__stderr__.fileno()
Example #25
Source File: capture.py From python-netsurv with MIT License | 5 votes |
def fileno(self): raise UnsupportedOperation("redirected stdin is pseudofile, has no fileno()")
Example #26
Source File: faulthandler.py From python-netsurv with MIT License | 5 votes |
def _get_stderr_fileno(): try: return sys.stderr.fileno() except (AttributeError, io.UnsupportedOperation): # python-xdist monkeypatches sys.stderr with an object that is not an actual file. # https://docs.python.org/3/library/faulthandler.html#issue-with-file-descriptors # This is potentially dangerous, but the best we can do. return sys.__stderr__.fileno()
Example #27
Source File: test_memoryio.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_detach(self): buf = self.ioclass() self.assertRaises(self.UnsupportedOperation, buf.detach)
Example #28
Source File: test_imghdr.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_unseekable(self): with open(TESTFN, 'wb') as stream: stream.write(self.testdata) with UnseekableIO(TESTFN, 'rb') as stream: with self.assertRaises(io.UnsupportedOperation): imghdr.what(stream)
Example #29
Source File: get-poetry.py From poetry with MIT License | 5 votes |
def is_decorated(): if platform.system().lower() == "windows": return ( os.getenv("ANSICON") is not None or "ON" == os.getenv("ConEmuANSI") or "xterm" == os.getenv("Term") ) if not hasattr(sys.stdout, "fileno"): return False try: return os.isatty(sys.stdout.fileno()) except UnsupportedOperation: return False
Example #30
Source File: get-poetry.py From poetry with MIT License | 5 votes |
def is_interactive(): if not hasattr(sys.stdin, "fileno"): return False try: return os.isatty(sys.stdin.fileno()) except UnsupportedOperation: return False