Python io.RawIOBase() Examples
The following are 30
code examples of io.RawIOBase().
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: test_unix_events.py From ironpython3 with Apache License 2.0 | 6 votes |
def setUp(self): self.loop = self.new_test_loop() self.protocol = test_utils.make_test_protocol(asyncio.BaseProtocol) self.pipe = mock.Mock(spec_set=io.RawIOBase) self.pipe.fileno.return_value = 5 blocking_patcher = mock.patch('asyncio.unix_events._set_nonblocking') blocking_patcher.start() self.addCleanup(blocking_patcher.stop) fstat_patcher = mock.patch('os.fstat') m_fstat = fstat_patcher.start() st = mock.Mock() st.st_mode = stat.S_IFSOCK m_fstat.return_value = st self.addCleanup(fstat_patcher.stop)
Example #2
Source File: test_unix_events.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def setUp(self): self.loop = self.new_test_loop() self.protocol = test_utils.make_test_protocol(asyncio.BaseProtocol) self.pipe = mock.Mock(spec_set=io.RawIOBase) self.pipe.fileno.return_value = 5 blocking_patcher = mock.patch('asyncio.unix_events._set_nonblocking') blocking_patcher.start() self.addCleanup(blocking_patcher.stop) fstat_patcher = mock.patch('os.fstat') m_fstat = fstat_patcher.start() st = mock.Mock() st.st_mode = stat.S_IFSOCK m_fstat.return_value = st self.addCleanup(fstat_patcher.stop)
Example #3
Source File: test_unix_events.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def setUp(self): self.loop = self.new_test_loop() self.protocol = test_utils.make_test_protocol(asyncio.Protocol) self.pipe = mock.Mock(spec_set=io.RawIOBase) self.pipe.fileno.return_value = 5 blocking_patcher = mock.patch('asyncio.unix_events._set_nonblocking') blocking_patcher.start() self.addCleanup(blocking_patcher.stop) fstat_patcher = mock.patch('os.fstat') m_fstat = fstat_patcher.start() st = mock.Mock() st.st_mode = stat.S_IFIFO m_fstat.return_value = st self.addCleanup(fstat_patcher.stop)
Example #4
Source File: hasher.py From resolwe with Apache License 2.0 | 6 votes |
def compute(self, stream_in: RawIOBase, stream_out: RawIOBase = None): """Compute and return the hash for the given stream. The data is read from stream_in until EOF, given to the hasher, and written unmodified to the stream_out (unless it is None). :param stream_in: input stream. :type stream_in: io.RawIOBase :param stream_out: output stream. :type stream_out: io.RawIOBase """ self._init_hashers() read_bytes = self.chunk_size while read_bytes == self.chunk_size: data = stream_in.read(self.chunk_size) read_bytes = len(data) for hasher in self._hashers.values(): hasher.update(data) if stream_out is not None: stream_out.write(data)
Example #5
Source File: multipart.py From py-ipfs-http-client with MIT License | 6 votes |
def _gen_file(self, filename, file_location=None, file=None, content_type=None): """Yields the entire contents of a file. Parameters ---------- filename : str Filename of the file being opened and added to the HTTP body file_location : str Full path to the file being added, including the filename file : io.RawIOBase The binary file-like object whose contents should be streamed No contents will be streamed if this is ``None``. content_type : str The Content-Type of the file; if not set a value will be guessed """ yield from self._gen_file_start(filename, file_location, content_type) if file: yield from self._gen_file_chunks(file) yield from self._gen_file_end()
Example #6
Source File: test_unix_events.py From ironpython3 with Apache License 2.0 | 6 votes |
def setUp(self): self.loop = self.new_test_loop() self.protocol = test_utils.make_test_protocol(asyncio.Protocol) self.pipe = mock.Mock(spec_set=io.RawIOBase) self.pipe.fileno.return_value = 5 blocking_patcher = mock.patch('asyncio.unix_events._set_nonblocking') blocking_patcher.start() self.addCleanup(blocking_patcher.stop) fstat_patcher = mock.patch('os.fstat') m_fstat = fstat_patcher.start() st = mock.Mock() st.st_mode = stat.S_IFIFO m_fstat.return_value = st self.addCleanup(fstat_patcher.stop)
Example #7
Source File: manifest.py From commandment with MIT License | 6 votes |
def chunked_hash(stream: Union[io.RawIOBase, io.BufferedIOBase], chunk_size: int = DEFAULT_MD5_CHUNK_SIZE) -> List[bytes]: """Create a list of hashes of chunk_size size in bytes. Args: stream (Union[io.RawIOBase, io.BufferedIOBase]): The steam containing the bytes to be hashed. chunk_size (int): The md5 chunk size. Default is 10485760 (which is required for InstallApplication). Returns: List[str]: A list of md5 hashes calculated for each chunk """ chunk = stream.read(chunk_size) hashes = [] while chunk is not None: h = hashlib.md5() h.update(chunk) md5 = h.digest() hashes.append(md5) chunk = stream.read(chunk_size) return hashes
Example #8
Source File: _socketio.py From scalyr-agent-2 with Apache License 2.0 | 5 votes |
def __init__(self, sock, mode): if mode not in ("r", "w", "rw", "rb", "wb", "rwb"): raise ValueError("invalid mode: %r" % mode) io.RawIOBase.__init__(self) self._sock = sock if "b" not in mode: mode += "b" self._mode = mode self._reading = "r" in mode self._writing = "w" in mode self._timeout_occurred = False
Example #9
Source File: test_subprocess.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_io_unbuffered_works(self): p = subprocess.Popen([sys.executable, "-c", "import sys; sys.exit(0)"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=0) try: self.assertIsInstance(p.stdin, io.RawIOBase) self.assertIsInstance(p.stdout, io.RawIOBase) self.assertIsInstance(p.stderr, io.RawIOBase) finally: p.stdin.close() p.stdout.close() p.stderr.close() p.wait()
Example #10
Source File: test_pathlib.py From ironpython3 with Apache License 2.0 | 5 votes |
def test_open_common(self): p = self.cls(BASE) with (p / 'fileA').open('r') as f: self.assertIsInstance(f, io.TextIOBase) self.assertEqual(f.read(), "this is file A\n") with (p / 'fileA').open('rb') as f: self.assertIsInstance(f, io.BufferedIOBase) self.assertEqual(f.read().strip(), b"this is file A") with (p / 'fileA').open('rb', buffering=0) as f: self.assertIsInstance(f, io.RawIOBase) self.assertEqual(f.read().strip(), b"this is file A")
Example #11
Source File: socket.py From ironpython3 with Apache License 2.0 | 5 votes |
def close(self): """Close the SocketIO object. This doesn't close the underlying socket, except if all references to it have disappeared. """ if self.closed: return io.RawIOBase.close(self) self._sock._decref_socketios() self._sock = None
Example #12
Source File: _socketio.py From scalyr-agent-2 with Apache License 2.0 | 5 votes |
def close(self): """Close the SocketIO object. This doesn't close the underlying socket, except if all references to it have disappeared. """ if self.closed: return io.RawIOBase.close(self) self._sock._decref_socketios() self._sock = None
Example #13
Source File: socket.py From cadquery-freecad-module with GNU Lesser General Public License v3.0 | 5 votes |
def __init__(self, sock, mode): if mode not in ("r", "w", "rw", "rb", "wb", "rwb"): raise ValueError("invalid mode: %r" % mode) io.RawIOBase.__init__(self) self._sock = sock if "b" not in mode: mode += "b" self._mode = mode self._reading = "r" in mode self._writing = "w" in mode self._timeout_occurred = False
Example #14
Source File: _winconsole.py From Building-Recommendation-Systems-with-Python with MIT License | 5 votes |
def isatty(self): io.RawIOBase.isatty(self) return True
Example #15
Source File: _winconsole.py From Building-Recommendation-Systems-with-Python with MIT License | 5 votes |
def isatty(self): io.RawIOBase.isatty(self) return True
Example #16
Source File: _winconsole.py From Financial-Portfolio-Flask with MIT License | 5 votes |
def isatty(self): io.RawIOBase.isatty(self) return True
Example #17
Source File: rarfile.py From addon with GNU General Public License v3.0 | 5 votes |
def open(self, fname, mode='r', psw=None): """Returns file-like object (:class:`RarExtFile`) from where the data can be read. The object implements :class:`io.RawIOBase` interface, so it can be further wrapped with :class:`io.BufferedReader` and :class:`io.TextIOWrapper`. On older Python where io module is not available, it implements only .read(), .seek(), .tell() and .close() methods. The object is seekable, although the seeking is fast only on uncompressed files, on compressed files the seeking is implemented by reading ahead and/or restarting the decompression. Parameters: fname file name or RarInfo instance. mode must be 'r' psw password to use for extracting. """ if mode != 'r': raise NotImplementedError("RarFile.open() supports only mode=r") # entry lookup inf = self.getinfo(fname) if inf.isdir(): raise TypeError("Directory does not have any data: " + inf.filename) # check password if inf.needs_password(): psw = psw or self._password if psw is None: raise PasswordRequired("File %s requires password" % inf.filename) else: psw = None return self._file_parser.open(inf, psw)
Example #18
Source File: _winconsole.py From pipenv with MIT License | 5 votes |
def isatty(self): io.RawIOBase.isatty(self) return True
Example #19
Source File: test_subprocess.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_io_unbuffered_works(self): p = subprocess.Popen([sys.executable, "-c", "import sys; sys.exit(0)"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=0) try: self.assertIsInstance(p.stdin, io.RawIOBase) self.assertIsInstance(p.stdout, io.RawIOBase) self.assertIsInstance(p.stderr, io.RawIOBase) finally: p.stdin.close() p.stdout.close() p.stderr.close() p.wait()
Example #20
Source File: test_pathlib.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def test_open_common(self): p = self.cls(BASE) with (p / 'fileA').open('r') as f: self.assertIsInstance(f, io.TextIOBase) self.assertEqual(f.read(), "this is file A\n") with (p / 'fileA').open('rb') as f: self.assertIsInstance(f, io.BufferedIOBase) self.assertEqual(f.read().strip(), b"this is file A") with (p / 'fileA').open('rb', buffering=0) as f: self.assertIsInstance(f, io.RawIOBase) self.assertEqual(f.read().strip(), b"this is file A")
Example #21
Source File: socket.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def close(self): """Close the SocketIO object. This doesn't close the underlying socket, except if all references to it have disappeared. """ if self.closed: return io.RawIOBase.close(self) self._sock._decref_socketios() self._sock = None
Example #22
Source File: socket.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def __init__(self, sock, mode): if mode not in ("r", "w", "rw", "rb", "wb", "rwb"): raise ValueError("invalid mode: %r" % mode) io.RawIOBase.__init__(self) self._sock = sock if "b" not in mode: mode += "b" self._mode = mode self._reading = "r" in mode self._writing = "w" in mode self._timeout_occurred = False
Example #23
Source File: saxutils.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def _gettextwriter(out, encoding): if out is None: import sys return sys.stdout if isinstance(out, io.TextIOBase): # use a text writer as is return out if isinstance(out, (codecs.StreamWriter, codecs.StreamReaderWriter)): # use a codecs stream writer as is return out # wrap a binary writer with TextIOWrapper if isinstance(out, io.RawIOBase): # Keep the original file open when the TextIOWrapper is # destroyed class _wrapper: __class__ = out.__class__ def __getattr__(self, name): return getattr(out, name) buffer = _wrapper() buffer.close = lambda: None else: # This is to handle passed objects that aren't in the # IOBase hierarchy, but just have a write method buffer = io.BufferedIOBase() buffer.writable = lambda: True buffer.write = out.write try: # TextIOWrapper uses this methods to determine # if BOM (for UTF-16, etc) should be added buffer.seekable = out.seekable buffer.tell = out.tell except AttributeError: pass return io.TextIOWrapper(buffer, encoding=encoding, errors='xmlcharrefreplace', newline='\n', write_through=True)
Example #24
Source File: _socketio.py From aws-servicebroker with Apache License 2.0 | 5 votes |
def close(self): """Close the SocketIO object. This doesn't close the underlying socket, except if all references to it have disappeared. """ if self.closed: return io.RawIOBase.close(self) self._sock._decref_socketios() self._sock = None
Example #25
Source File: _socketio.py From aws-servicebroker with Apache License 2.0 | 5 votes |
def __init__(self, sock, mode): if mode not in ("r", "w", "rw", "rb", "wb", "rwb"): raise ValueError("invalid mode: %r" % mode) io.RawIOBase.__init__(self) self._sock = sock if "b" not in mode: mode += "b" self._mode = mode self._reading = "r" in mode self._writing = "w" in mode self._timeout_occurred = False
Example #26
Source File: socket.py From kgsgo-dataset-preprocessor with Mozilla Public License 2.0 | 5 votes |
def close(self): """Close the SocketIO object. This doesn't close the underlying socket, except if all references to it have disappeared. """ if self.closed: return io.RawIOBase.close(self) self._sock._decref_socketios() self._sock = None
Example #27
Source File: socket.py From kgsgo-dataset-preprocessor with Mozilla Public License 2.0 | 5 votes |
def __init__(self, sock, mode): if mode not in ("r", "w", "rw", "rb", "wb", "rwb"): raise ValueError("invalid mode: %r" % mode) io.RawIOBase.__init__(self) self._sock = sock if "b" not in mode: mode += "b" self._mode = mode self._reading = "r" in mode self._writing = "w" in mode self._timeout_occurred = False
Example #28
Source File: socket.py From pycopia with Apache License 2.0 | 5 votes |
def close(self): """Close the SocketIO object. This doesn't close the underlying socket, except if all references to it have disappeared. """ if self.closed: return io.RawIOBase.close(self) self._sock._decref_socketios() self._sock = None
Example #29
Source File: socket.py From pycopia with Apache License 2.0 | 5 votes |
def __init__(self, sock, mode): if mode not in ("r", "w", "rw", "rb", "wb", "rwb"): raise ValueError("invalid mode: %r" % mode) io.RawIOBase.__init__(self) self._sock = sock if "b" not in mode: mode += "b" self._mode = mode self._reading = "r" in mode self._writing = "w" in mode self._timeout_occurred = False
Example #30
Source File: _winconsole.py From pipenv with MIT License | 5 votes |
def isatty(self): io.RawIOBase.isatty(self) return True