Python gi.repository.GLib.IO_IN Examples
The following are 27
code examples of gi.repository.GLib.IO_IN().
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
gi.repository.GLib
, or try the search function
.
Example #1
Source File: test_server.py From mopidy-mpd with Apache License 2.0 | 6 votes |
def test_handle_connection(self): self.mock.accept_connection.return_value = ( sentinel.sock, sentinel.addr, ) self.mock.maximum_connections_exceeded.return_value = False assert network.Server.handle_connection( self.mock, sentinel.fileno, GLib.IO_IN ) self.mock.accept_connection.assert_called_once_with() self.mock.maximum_connections_exceeded.assert_called_once_with() self.mock.init_connection.assert_called_once_with( sentinel.sock, sentinel.addr ) assert 0 == self.mock.reject_connection.call_count
Example #2
Source File: test_server.py From mopidy-mpd with Apache License 2.0 | 6 votes |
def test_handle_connection_exceeded_connections(self): self.mock.accept_connection.return_value = ( sentinel.sock, sentinel.addr, ) self.mock.maximum_connections_exceeded.return_value = True assert network.Server.handle_connection( self.mock, sentinel.fileno, GLib.IO_IN ) self.mock.accept_connection.assert_called_once_with() self.mock.maximum_connections_exceeded.assert_called_once_with() self.mock.reject_connection.assert_called_once_with( sentinel.sock, sentinel.addr ) assert 0 == self.mock.init_connection.call_count
Example #3
Source File: glib_events.py From pychess with GNU General Public License v3.0 | 6 votes |
def sock_accept(self, sock): channel = self._channel_from_socket(sock) source = GLib.io_create_watch(channel, GLib.IO_IN) def sock_connection_received(sock): return (True, sock.accept()) @asyncio.coroutine def accept_coro(future, conn): # Coroutine closing the accept socket if the future is cancelled try: return (yield from future) except futures.CancelledError: sock.close() raise future = self._delayed(source, sock_connection_received, sock) return self.create_task(accept_coro(future, sock))
Example #4
Source File: winetricks_cache_backup.py From games_nebula with GNU General Public License v3.0 | 6 votes |
def copy_files(self, file_name, action): if action == 'make_backup': command = ['cp', '-R', self.winetricks_cache + '/' + file_name, self.winetricks_cache_backup] elif action == 'restore_backup': command = ['cp', '-R', self.winetricks_cache_backup + '/' + file_name, self.winetricks_cache] self.pid, stdin, stdout, stderr = GLib.spawn_async(command, flags=GLib.SpawnFlags.SEARCH_PATH|GLib.SpawnFlags.DO_NOT_REAP_CHILD, standard_output=True, standard_error=True) io = GLib.IOChannel(stdout) self.source_id_out = io.add_watch(GLib.IO_IN|GLib.IO_HUP, self.watch_process, 'copy_files', priority=GLib.PRIORITY_HIGH)
Example #5
Source File: test_connection.py From mopidy-mpd with Apache License 2.0 | 5 votes |
def test_send_callback_respects_io_err(self): self.mock._sock = Mock(spec=socket.SocketType) self.mock._sock.send.return_value = 1 self.mock.send_lock = Mock() self.mock.actor_ref = Mock() self.mock.send_buffer = b"" assert network.Connection.send_callback( self.mock, sentinel.fd, (GLib.IO_IN | GLib.IO_ERR) ) self.mock.stop.assert_called_once_with(any_unicode)
Example #6
Source File: main.py From gagar with GNU General Public License v3.0 | 5 votes |
def gtk_watch_client(client): # watch client's websocket in GTK main loop # `or True` is for always returning True to keep watching GLib.io_add_watch(client.ws, GLib.IO_IN, lambda ws, _: client.on_message() or True) GLib.io_add_watch(client.ws, GLib.IO_ERR, lambda ws, _: client.subscriber.on_sock_error() or True) GLib.io_add_watch(client.ws, GLib.IO_HUP, lambda ws, _: client.disconnect() or True)
Example #7
Source File: stats_counter.py From Apostrophe with GNU General Public License v3.0 | 5 votes |
def __init__(self, callback): super().__init__() # Worker process to handle counting. self.counting = False self.count_pending_text = None self.parent_conn, child_conn = Pipe() Process(target=self.do_count, args=(child_conn,), daemon=True).start() GLib.io_add_watch( self.parent_conn.fileno(), GLib.PRIORITY_LOW, GLib.IO_IN, self.on_counted, callback)
Example #8
Source File: btk.py From btk with MIT License | 5 votes |
def NewConnection(self, device, fd, fd_properties): print("New control connection (%s, %d, %s)" % (device, fd, fd_properties)) self.conns[device] = HIDConnection(fd) def new_intr_conn(ssock, ip_type): sock, info = ssock.accept() print("interrupt connection:", info) self.conns[device].register_intr_socks(sock) return False GLib.io_add_watch(self.sock, GLib.IO_IN, new_intr_conn)
Example #9
Source File: btk.py From btk with MIT License | 5 votes |
def __init__(self, ctrl_fd): self.ctrl_fd = ctrl_fd self.ctrl_io_id = GLib.io_add_watch( self.ctrl_fd, GLib.IO_IN, self.ctrl_data_cb )
Example #10
Source File: glib_events.py From pychess with GNU General Public License v3.0 | 5 votes |
def add_reader(self, fileobj, callback, *args): fd = self._fileobj_to_fd(fileobj) self._ensure_fd_no_transport(fd) self.remove_reader(fd) channel = self._channel_from_socket(fd) source = GLib.io_create_watch(channel, GLib.IO_IN | GLib.IO_HUP | GLib.IO_ERR | GLib.IO_NVAL) assert fd not in self._readers self._readers[fd] = GLibHandle( loop=self, source=source, repeat=True, callback=callback, args=args)
Example #11
Source File: glib_events.py From pychess with GNU General Public License v3.0 | 5 votes |
def _channel_read(self, channel, nbytes, read_func=None): if read_func is None: read_func = lambda channel, nbytes: channel.read(nbytes) source = GLib.io_create_watch(channel, GLib.IO_IN | GLib.IO_HUP) def channel_readable(read_func, channel, nbytes): return (True, read_func(channel, nbytes)) return self._delayed(source, channel_readable, read_func, channel, nbytes)
Example #12
Source File: inputhookgtk3.py From Computable with MIT License | 5 votes |
def inputhook_gtk3(): GLib.io_add_watch(sys.stdin, GLib.IO_IN, _main_quit) Gtk.main() return 0
Example #13
Source File: test_connection.py From mopidy-mpd with Apache License 2.0 | 5 votes |
def test_send_callback_sends_partial_data(self): self.mock.send_lock = Mock() self.mock.send_lock.acquire.return_value = True self.mock.send_buffer = b"data" self.mock.send.return_value = b"ta" assert network.Connection.send_callback( self.mock, sentinel.fd, GLib.IO_IN ) self.mock.send.assert_called_once_with(b"data") assert b"ta" == self.mock.send_buffer
Example #14
Source File: test_connection.py From mopidy-mpd with Apache License 2.0 | 5 votes |
def test_send_callback_sends_all_data(self): self.mock.send_lock = Mock() self.mock.send_lock.acquire.return_value = True self.mock.send_buffer = b"data" self.mock.send.return_value = b"" assert network.Connection.send_callback( self.mock, sentinel.fd, GLib.IO_IN ) self.mock.disable_send.assert_called_once_with() self.mock.send.assert_called_once_with(b"data") assert b"" == self.mock.send_buffer
Example #15
Source File: test_connection.py From mopidy-mpd with Apache License 2.0 | 5 votes |
def test_send_callback_fails_to_acquire_lock(self): self.mock.send_lock = Mock() self.mock.send_lock.acquire.return_value = False self.mock.send_buffer = b"" self.mock._sock = Mock(spec=socket.SocketType) self.mock._sock.send.return_value = 0 assert network.Connection.send_callback( self.mock, sentinel.fd, GLib.IO_IN ) self.mock.send_lock.acquire.assert_called_once_with(False) assert 0 == self.mock._sock.send.call_count
Example #16
Source File: test_connection.py From mopidy-mpd with Apache License 2.0 | 5 votes |
def test_send_callback_respects_io_hup_and_io_err(self): self.mock._sock = Mock(spec=socket.SocketType) self.mock._sock.send.return_value = 1 self.mock.send_lock = Mock() self.mock.actor_ref = Mock() self.mock.send_buffer = b"" assert network.Connection.send_callback( self.mock, sentinel.fd, ((GLib.IO_IN | GLib.IO_HUP) | GLib.IO_ERR) ) self.mock.stop.assert_called_once_with(any_unicode)
Example #17
Source File: test_connection.py From mopidy-mpd with Apache License 2.0 | 5 votes |
def test_send_callback_respects_io_hup(self): self.mock._sock = Mock(spec=socket.SocketType) self.mock._sock.send.return_value = 1 self.mock.send_lock = Mock() self.mock.actor_ref = Mock() self.mock.send_buffer = b"" assert network.Connection.send_callback( self.mock, sentinel.fd, (GLib.IO_IN | GLib.IO_HUP) ) self.mock.stop.assert_called_once_with(any_unicode)
Example #18
Source File: test_connection.py From mopidy-mpd with Apache License 2.0 | 5 votes |
def test_recv_callback_unrecoverable_error(self): self.mock._sock = Mock(spec=socket.SocketType) self.mock._sock.recv.side_effect = socket.error assert network.Connection.recv_callback( self.mock, sentinel.fd, GLib.IO_IN ) self.mock.stop.assert_called_once_with(any_unicode)
Example #19
Source File: test_connection.py From mopidy-mpd with Apache License 2.0 | 5 votes |
def test_recv_callback_recoverable_error(self): self.mock._sock = Mock(spec=socket.SocketType) for error in (errno.EWOULDBLOCK, errno.EINTR): self.mock._sock.recv.side_effect = socket.error(error, "") assert network.Connection.recv_callback( self.mock, sentinel.fd, GLib.IO_IN ) assert 0 == self.mock.stop.call_count
Example #20
Source File: test_connection.py From mopidy-mpd with Apache License 2.0 | 5 votes |
def test_recv_callback_handles_dead_actors(self): self.mock._sock = Mock(spec=socket.SocketType) self.mock._sock.recv.return_value = b"data" self.mock.actor_ref = Mock() self.mock.actor_ref.tell.side_effect = pykka.ActorDeadError() assert network.Connection.recv_callback( self.mock, sentinel.fd, GLib.IO_IN ) self.mock.stop.assert_called_once_with(any_unicode)
Example #21
Source File: test_connection.py From mopidy-mpd with Apache License 2.0 | 5 votes |
def test_recv_callback_sends_data_to_actor(self): self.mock._sock = Mock(spec=socket.SocketType) self.mock._sock.recv.return_value = b"data" self.mock.actor_ref = Mock() assert network.Connection.recv_callback( self.mock, sentinel.fd, GLib.IO_IN ) self.mock.actor_ref.tell.assert_called_once_with({"received": b"data"})
Example #22
Source File: test_connection.py From mopidy-mpd with Apache License 2.0 | 5 votes |
def test_recv_callback_respects_io_hup_and_io_err(self): self.mock._sock = Mock(spec=socket.SocketType) self.mock.actor_ref = Mock() assert network.Connection.recv_callback( self.mock, sentinel.fd, ((GLib.IO_IN | GLib.IO_HUP) | GLib.IO_ERR) ) self.mock.stop.assert_called_once_with(any_unicode)
Example #23
Source File: test_connection.py From mopidy-mpd with Apache License 2.0 | 5 votes |
def test_recv_callback_respects_io_hup(self): self.mock._sock = Mock(spec=socket.SocketType) self.mock.actor_ref = Mock() assert network.Connection.recv_callback( self.mock, sentinel.fd, (GLib.IO_IN | GLib.IO_HUP) ) self.mock.stop.assert_called_once_with(any_unicode)
Example #24
Source File: test_connection.py From mopidy-mpd with Apache License 2.0 | 5 votes |
def test_recv_callback_respects_io_err(self): self.mock._sock = Mock(spec=socket.SocketType) self.mock.actor_ref = Mock() assert network.Connection.recv_callback( self.mock, sentinel.fd, (GLib.IO_IN | GLib.IO_ERR) ) self.mock.stop.assert_called_once_with(any_unicode)
Example #25
Source File: test_server.py From mopidy-mpd with Apache License 2.0 | 5 votes |
def test_register_server_socket_sets_up_io_watch(self): network.Server.register_server_socket(self.mock, sentinel.fileno) GLib.io_add_watch.assert_called_once_with( sentinel.fileno, GLib.IO_IN, self.mock.handle_connection )
Example #26
Source File: network.py From mopidy-mpd with Apache License 2.0 | 5 votes |
def enable_recv(self): if self.recv_id is not None: return try: self.recv_id = GLib.io_add_watch( self._sock.fileno(), GLib.IO_IN | GLib.IO_ERR | GLib.IO_HUP, self.recv_callback, ) except OSError as exc: self.stop(f"Problem with connection: {exc}")
Example #27
Source File: network.py From mopidy-mpd with Apache License 2.0 | 5 votes |
def register_server_socket(self, fileno): return GLib.io_add_watch(fileno, GLib.IO_IN, self.handle_connection)