def __init__(self, block): ''' Initialise with Block `block`. ''' RawIOBase.__init__(self) self.isdir = False self.block = block self._offset = 0
def __init__(self, fileno, mode='r', closefd=True): RawIOBase.__init__(self) # Python 2: pylint:disable=no-member,non-parent-init-called self._closefd = closefd self._fileno = fileno make_nonblocking(fileno) readable = 'r' in mode writable = 'w' in mode self.hub = get_hub() io_watcher = self.hub.loop.io try: if readable: self._read_event = io_watcher(fileno, 1) if writable: self._write_event = io_watcher(fileno, 2) except: # If anything goes wrong, it's important to go ahead and # close these watchers *now*, especially under libuv, so # that they don't get eventually reclaimed by the garbage # collector at some random time, thanks to the C level # slot (even though we don't seem to have any actual references # at the Python level). Previously, if we didn't close now, # that random close in the future would cause issues if we had duplicated # the fileno (if a wrapping with statement had closed an open fileobject, # for example) # test__fileobject can show a failure if this doesn't happen # TRAVIS=true GEVENT_LOOP=libuv python -m gevent.tests.test__fileobject \ # TestFileObjectPosix.test_seek TestFileObjectThread.test_bufsize_0 self.close() raise
def __init__(self, fileno, open_descriptor, closefd=True): RawIOBase.__init__(self) self._closefd = closefd self._fileno = fileno self.mode = open_descriptor.fileio_mode make_nonblocking(fileno) readable = open_descriptor.can_read writable = open_descriptor.can_write self.hub = get_hub() io_watcher = self.hub.loop.io try: if readable: self._read_watcher = io_watcher(fileno, 1) if writable: self._write_watcher = io_watcher(fileno, 2) except: # If anything goes wrong, it's important to go ahead and # close these watchers *now*, especially under libuv, so # that they don't get eventually reclaimed by the garbage # collector at some random time, thanks to the C level # slot (even though we don't seem to have any actual references # at the Python level). Previously, if we didn't close now, # that random close in the future would cause issues if we had duplicated # the fileno (if a wrapping with statement had closed an open fileobject, # for example) # test__fileobject can show a failure if this doesn't happen # TRAVIS=true GEVENT_LOOP=libuv python -m gevent.tests.test__fileobject \ # TestFileObjectPosix.test_seek TestFileObjectThread.test_bufsize_0 self.close() raise
def __init__(self, name, mode="r", storage_parameters=None, **kwargs): RawIOBase.__init__(self) ObjectIOBase.__init__(self, name, mode=mode) if storage_parameters is not None: storage_parameters = storage_parameters.copy() try: self._cache["_head"] = storage_parameters.pop("airfs.raw_io._head") except (AttributeError, KeyError): pass try: self._system = storage_parameters.pop("airfs.system_cached") except (AttributeError, KeyError): self._system = None if not self._system: self._system = self._SYSTEM_CLASS( storage_parameters=storage_parameters, **kwargs ) self._client_kwargs = self._system.get_client_kwargs(name) self._is_raw_of_buffered = False if self._writable: self._write_buffer = bytearray() if "a" in mode: if self._exists() == 1: with handle_os_exceptions(): self._init_append() elif self._exists() == 0: with handle_os_exceptions(): self._create() else: raise PermissionError( "Insufficient permission to check if file already exists." ) elif "x" in mode and self._exists() == 1: raise FileExistsError elif "x" in mode and self._exists() == -1: raise PermissionError( "Insufficient permission to check if file already exists." ) else: with handle_os_exceptions(): self._create() else: with handle_os_exceptions(): self._head()
def __init__(self, fileno, mode='r', closefd=True): RawIOBase.__init__(self) # Python 2: pylint:disable=no-member,non-parent-init-called self._closefd = closefd self._fileno = fileno make_nonblocking(fileno) readable = 'r' in mode writable = 'w' in mode self.hub = get_hub() io_watcher = self.hub.loop.io if readable: self._read_event = io_watcher(fileno, 1) if writable: self._write_event = io_watcher(fileno, 2)
def __init__(self, rf, inf): """Fill common fields""" RawIOBase.__init__(self) # standard io.* properties self.name = inf.filename self.mode = 'rb' self.rf = rf self.inf = inf self.crc_check = rf._crc_check self.fd = None self.CRC = 0 self.remain = 0 self._open()
def __init__(self, fileno, mode='r', closefd=True): RawIOBase.__init__(self) # Python 2: pylint:disable=no-member,non-parent-init-called self._closed = False self._closefd = closefd self._fileno = fileno make_nonblocking(fileno) self._readable = 'r' in mode self._writable = 'w' in mode self.hub = get_hub() io_watcher = self.hub.loop.io if self._readable: self._read_event = io_watcher(fileno, 1) if self._writable: self._write_event = io_watcher(fileno, 2) self._seekable = None
def __init__(self, fileno, mode='r', closefd=True): RawIOBase.__init__(self) self._closed = False self._closefd = closefd self._fileno = fileno make_nonblocking(fileno) self._readable = 'r' in mode self._writable = 'w' in mode self.hub = get_hub() io = self.hub.loop.io if self._readable: self._read_event = io(fileno, 1) else: self._read_event = None if self._writable: self._write_event = io(fileno, 2) else: self._write_event = None
def __init__(self, *args, **kwargs): RawIOBase.__init__(self) FtdiSerial.__init__(self, *args, **kwargs)
def __init__(self, sock): RawIOBase.__init__(self) self._sock = sock
def __init__(self, name, mode='r', storage_parameters=None, **kwargs): RawIOBase.__init__(self) ObjectIOBase.__init__(self, name, mode=mode) if storage_parameters is not None: storage_parameters = storage_parameters.copy() # Try to get cached head for this file try: self._cache['_head'] = storage_parameters.pop( 'pycosio.raw_io._head') except (AttributeError, KeyError): pass # Initializes system try: # Try to get cached system self._system = storage_parameters.pop('pycosio.system_cached') except (AttributeError, KeyError): self._system = None if not self._system: # If none cached, create a new system self._system = self._SYSTEM_CLASS( storage_parameters=storage_parameters, **kwargs) # Gets storage local path from URL self._path = self._system.relpath(name) self._client_kwargs = self._system.get_client_kwargs(name) # Mark as standalone RAW to avoid flush conflicts on close self._is_raw_of_buffered = False # Configures write mode if self._writable: self._write_buffer = bytearray() # Initializes starting data if 'a' in mode: # Initialize with existing file content if self._exists() == 1: with handle_os_exceptions(): self._init_append() # Create new file elif self._exists() == 0: with handle_os_exceptions(): self._create() else: raise PermissionError( "Insufficient permission to check if file already " "exists.") # Checks if object exists, # and raise if it is the case elif 'x' in mode and self._exists() == 1: raise FileExistsError elif 'x' in mode and self._exists() == -1: raise PermissionError( "Insufficient permission to check if file already " "exists.") # Create new file else: with handle_os_exceptions(): self._create() # Configure read mode else: # Get header and checks files exists with handle_os_exceptions(): self._head()