From 51467851aa0c584cc163fed2e70b04f7918afc8f Mon Sep 17 00:00:00 2001 From: Avasam Date: Wed, 16 Nov 2022 19:22:09 -0500 Subject: [PATCH 1/2] Prefer `bool` over `Literal[0, 1, None]` --- Xlib/display.py | 8 ++++---- Xlib/error.py | 2 +- Xlib/protocol/display.py | 28 ++++++++++++++-------------- Xlib/protocol/rq.py | 20 ++++++++++---------- Xlib/xobject/drawable.py | 6 +++--- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Xlib/display.py b/Xlib/display.py index e0f7b5c8..87b9aa61 100644 --- a/Xlib/display.py +++ b/Xlib/display.py @@ -71,7 +71,7 @@ def __init__(self, *args, **keys): protocol_display.Display.__init__(self, *args, **keys) self._atom_cache = {} - def get_atom(self, atomname, only_if_exists=0): + def get_atom(self, atomname, only_if_exists=False): if atomname in self._atom_cache: return self._atom_cache[atomname] @@ -473,7 +473,7 @@ def rebind_string(self, keysym, newstring): ### X requests ### - def intern_atom(self, name, only_if_exists = 0): + def intern_atom(self, name, only_if_exists = False): """Intern the string name, returning its atom number. If only_if_exists is true and the atom does not already exist, it will not be created and X.NONE is returned.""" @@ -482,7 +482,7 @@ def intern_atom(self, name, only_if_exists = 0): only_if_exists = only_if_exists) return r.atom - def get_atom(self, atom, only_if_exists = 0): + def get_atom(self, atom, only_if_exists = False): """Alias for intern_atom, using internal cache""" return self.display.get_atom(atom, only_if_exists) @@ -501,7 +501,7 @@ def get_selection_owner(self, selection): selection = selection) return r.owner - def send_event(self, destination, event, event_mask = 0, propagate = 0, + def send_event(self, destination, event, event_mask = 0, propagate = False, onerror = None): """Send a synthetic event to the window destination which can be a window object, or X.PointerWindow or X.InputFocus. event is the diff --git a/Xlib/error.py b/Xlib/error.py index cb6d0d07..3b6e13f8 100644 --- a/Xlib/error.py +++ b/Xlib/error.py @@ -70,7 +70,7 @@ class XError(rq.GetAttrData, Exception): ) def __init__(self, display, data): - self._data, data = self._fields.parse_binary(data, display, rawdict = 1) + self._data, _ = self._fields.parse_binary(data, display, rawdict = True) def __str__(self): s = [] diff --git a/Xlib/protocol/display.py b/Xlib/protocol/display.py index 56623c35..4bd939e9 100644 --- a/Xlib/protocol/display.py +++ b/Xlib/protocol/display.py @@ -214,7 +214,7 @@ def next_event(self): # Call send_and_recv, which will return when # something has occured - self.send_and_recv(event = 1) + self.send_and_recv(event = True) # Before looping around, lock the event queue against # modifications. @@ -240,7 +240,7 @@ def pending_events(self): # Make a send_and_recv pass, receiving any events self.send_recv_lock.acquire() - self.send_and_recv(recv = 1) + self.send_and_recv(recv = True) # Lock the queue, get the event count, and unlock again. self.event_queue_write_lock.acquire() @@ -252,7 +252,7 @@ def pending_events(self): def flush(self): self.check_for_error() self.send_recv_lock.acquire() - self.send_and_recv(flush = 1) + self.send_and_recv(flush = True) def close(self): self.flush() @@ -384,7 +384,7 @@ def close_internal(self, whom): self.socket_error_lock.release() - def send_and_recv(self, flush = None, event = None, request = None, recv = None): + def send_and_recv(self, flush = False, event = False, request = None, recv = False): """send_and_recv(flush = None, event = None, request = None, recv = None) Perform I/O, or wait for some other thread to do it for us. @@ -689,8 +689,8 @@ def parse_response(self, request): return self.parse_connection_setup() # Parse ordinary server response - gotreq = 0 - while 1: + gotreq = False + while True: if self.data_recv: # Check the first byte to find out what kind of response it is rtype = byte2int(self.data_recv) @@ -772,7 +772,7 @@ def parse_error_response(self, request): else: self.default_error_handler(e) - return 0 + return False def default_error_handler(self, err): @@ -937,7 +937,7 @@ def parse_connection_setup(self): # Only the ConnectionSetupRequest has been sent so far r = self.sent_requests[0] - while 1: + while True: # print 'data_send:', repr(self.data_send) # print 'data_recv:', repr(self.data_recv) @@ -946,7 +946,7 @@ def parse_connection_setup(self): # The full response haven't arrived yet if len(self.data_recv) < alen: - return 0 + return False # Connection failed or further authentication is needed. # Set reason to the reason string @@ -956,22 +956,22 @@ def parse_connection_setup(self): # Else connection succeeded, parse the reply else: x, d = r._success_reply.parse_binary(self.data_recv[:alen], - self, rawdict = 1) + self, rawdict = True) r._data.update(x) del self.sent_requests[0] self.data_recv = self.data_recv[alen:] - return 1 + return True else: # The base reply is 8 bytes long if len(self.data_recv) < 8: - return 0 + return False r._data, d = r._reply.parse_binary(self.data_recv[:8], - self, rawdict = 1) + self, rawdict = True) self.data_recv = self.data_recv[8:] # Loop around to see if we have got the additional data @@ -1066,7 +1066,7 @@ def __init__(self, display, *args, **keys): # Don't bother about locking, since no other threads have # access to the display yet - display.request_queue.append((self, 1)) + display.request_queue.append((self, True)) # However, we must lock send_and_recv, but we don't have # to loop. diff --git a/Xlib/protocol/rq.py b/Xlib/protocol/rq.py index 86cb2def..e2042ca6 100644 --- a/Xlib/protocol/rq.py +++ b/Xlib/protocol/rq.py @@ -119,7 +119,7 @@ class Field(object): check_value = None parse_value = None - keyword_args = 0 + keyword_args = False def __init__(self): pass @@ -724,7 +724,7 @@ def pack_value(self, value): class ValueList(Field): structcode = None - keyword_args = 1 + keyword_args = True default = 'usekeywords' def __init__(self, name, mask, pad, *fields): @@ -1089,7 +1089,7 @@ def pack_value(self, value): raise BadDataError('%s is not a tuple or a list' % (value)) - def parse_value(self, val, display, rawdict = 0): + def parse_value(self, val, display, rawdict = False): """This function is used by List and Object fields to convert Struct objects with no var_fields into Python values. @@ -1132,9 +1132,9 @@ def parse_value(self, val, display, rawdict = 0): return DictWrapper(ret) return ret - def parse_binary(self, data, display, rawdict = 0): + def parse_binary(self, data, display, rawdict = False): - """values, remdata = s.parse_binary(data, display, rawdict = 0) + """values, remdata = s.parse_binary(data, display, rawdict = False) Convert a binary representation of the structure into Python values. @@ -1355,16 +1355,16 @@ def _set_error(self, error): return 0 class ReplyRequest(GetAttrData): - def __init__(self, display, defer = 0, *args, **keys): + def __init__(self, display, defer = False, *args, **keys): self._display = display self._binary = self._request.to_binary(*args, **keys) self._serial = None - self._data = None + self._data = {} self._error = None self._response_lock = lock.allocate_lock() - self._display.send_request(self, 1) + self._display.send_request(self, True) if not defer: self.reply() @@ -1390,7 +1390,7 @@ def reply(self): def _parse_response(self, data): self._response_lock.acquire() - self._data, d = self._reply.parse_binary(data, self._display, rawdict = 1) + self._data, d = self._reply.parse_binary(data, self._display, rawdict = True) self._response_lock.release() def _set_error(self, error): @@ -1409,7 +1409,7 @@ def __init__(self, binarydata = None, display = None, if binarydata: self._binary = binarydata self._data, data = self._fields.parse_binary(binarydata, display, - rawdict = 1) + rawdict = True) # split event type into type and send_event bit self._data['send_event'] = not not self._data['type'] & 0x80 self._data['type'] = self._data['type'] & 0x7f diff --git a/Xlib/xobject/drawable.py b/Xlib/xobject/drawable.py index c36a9738..698fd3b2 100644 --- a/Xlib/xobject/drawable.py +++ b/Xlib/xobject/drawable.py @@ -451,7 +451,7 @@ def delete_property(self, property, onerror = None): window = self.id, property = property) - def get_property(self, property, property_type, offset, length, delete = 0): + def get_property(self, property, property_type, offset, length, delete = False): r = request.GetProperty(display = self.display, delete = delete, window = self.id, @@ -516,7 +516,7 @@ def convert_selection(self, selection, target, property, time, onerror = None): property = property, time = time) - def send_event(self, event, event_mask = 0, propagate = 0, onerror = None): + def send_event(self, event, event_mask = 0, propagate = False, onerror = None): request.SendEvent(display = self.display, onerror = onerror, propagate = propagate, @@ -629,7 +629,7 @@ def set_input_focus(self, revert_to, time, onerror = None): focus = self.id, time = time) - def clear_area(self, x = 0, y = 0, width = 0, height = 0, exposures = 0, onerror = None): + def clear_area(self, x = 0, y = 0, width = 0, height = 0, exposures = False, onerror = None): request.ClearArea(display = self.display, onerror = onerror, exposures = exposures, From fdce3b20f1335b985596c43416bbd1ad79645e04 Mon Sep 17 00:00:00 2001 From: Avasam Date: Fri, 18 Nov 2022 15:42:54 -0500 Subject: [PATCH 2/2] fix accidental data change --- Xlib/protocol/display.py | 2 +- Xlib/protocol/rq.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Xlib/protocol/display.py b/Xlib/protocol/display.py index 4bd939e9..0d910dab 100644 --- a/Xlib/protocol/display.py +++ b/Xlib/protocol/display.py @@ -402,7 +402,7 @@ def send_and_recv(self, flush = False, event = False, request = None, recv = Fal To wait for an event to be received, event should be true. To wait for a response to a certain request (either an error - or a response), request should be set the that request's + or a response), request should be set to that request's serial number. To just read any pending data from the server, recv should be true. diff --git a/Xlib/protocol/rq.py b/Xlib/protocol/rq.py index e2042ca6..2e435e25 100644 --- a/Xlib/protocol/rq.py +++ b/Xlib/protocol/rq.py @@ -1359,7 +1359,7 @@ def __init__(self, display, defer = False, *args, **keys): self._display = display self._binary = self._request.to_binary(*args, **keys) self._serial = None - self._data = {} + self._data = None self._error = None self._response_lock = lock.allocate_lock() pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy