Skip to content

Commit 9f406d4

Browse files
Avasamvasily-v-ryabov
authored andcommitted
Prefer bool over Literal[0, 1, None]
1 parent 1127b31 commit 9f406d4

File tree

5 files changed

+32
-32
lines changed

5 files changed

+32
-32
lines changed

Xlib/display.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def __init__(self, *args, **keys):
7171
protocol_display.Display.__init__(self, *args, **keys)
7272
self._atom_cache = {}
7373

74-
def get_atom(self, atomname, only_if_exists=0):
74+
def get_atom(self, atomname, only_if_exists=False):
7575
if atomname in self._atom_cache:
7676
return self._atom_cache[atomname]
7777

@@ -473,7 +473,7 @@ def rebind_string(self, keysym, newstring):
473473
### X requests
474474
###
475475

476-
def intern_atom(self, name, only_if_exists = 0):
476+
def intern_atom(self, name, only_if_exists = False):
477477
"""Intern the string name, returning its atom number. If
478478
only_if_exists is true and the atom does not already exist, it
479479
will not be created and X.NONE is returned."""
@@ -482,7 +482,7 @@ def intern_atom(self, name, only_if_exists = 0):
482482
only_if_exists = only_if_exists)
483483
return r.atom
484484

485-
def get_atom(self, atom, only_if_exists = 0):
485+
def get_atom(self, atom, only_if_exists = False):
486486
"""Alias for intern_atom, using internal cache"""
487487
return self.display.get_atom(atom, only_if_exists)
488488

@@ -501,7 +501,7 @@ def get_selection_owner(self, selection):
501501
selection = selection)
502502
return r.owner
503503

504-
def send_event(self, destination, event, event_mask = 0, propagate = 0,
504+
def send_event(self, destination, event, event_mask = 0, propagate = False,
505505
onerror = None):
506506
"""Send a synthetic event to the window destination which can be
507507
a window object, or X.PointerWindow or X.InputFocus. event is the

Xlib/error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class XError(rq.GetAttrData, Exception):
7070
)
7171

7272
def __init__(self, display, data):
73-
self._data, data = self._fields.parse_binary(data, display, rawdict = 1)
73+
self._data, _ = self._fields.parse_binary(data, display, rawdict = True)
7474

7575
def __str__(self):
7676
s = []

Xlib/protocol/display.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def next_event(self):
214214

215215
# Call send_and_recv, which will return when
216216
# something has occured
217-
self.send_and_recv(event = 1)
217+
self.send_and_recv(event = True)
218218

219219
# Before looping around, lock the event queue against
220220
# modifications.
@@ -240,7 +240,7 @@ def pending_events(self):
240240

241241
# Make a send_and_recv pass, receiving any events
242242
self.send_recv_lock.acquire()
243-
self.send_and_recv(recv = 1)
243+
self.send_and_recv(recv = True)
244244

245245
# Lock the queue, get the event count, and unlock again.
246246
self.event_queue_write_lock.acquire()
@@ -252,7 +252,7 @@ def pending_events(self):
252252
def flush(self):
253253
self.check_for_error()
254254
self.send_recv_lock.acquire()
255-
self.send_and_recv(flush = 1)
255+
self.send_and_recv(flush = True)
256256

257257
def close(self):
258258
self.flush()
@@ -384,7 +384,7 @@ def close_internal(self, whom):
384384
self.socket_error_lock.release()
385385

386386

387-
def send_and_recv(self, flush = None, event = None, request = None, recv = None):
387+
def send_and_recv(self, flush = False, event = False, request = None, recv = False):
388388
"""send_and_recv(flush = None, event = None, request = None, recv = None)
389389
390390
Perform I/O, or wait for some other thread to do it for us.
@@ -689,8 +689,8 @@ def parse_response(self, request):
689689
return self.parse_connection_setup()
690690

691691
# Parse ordinary server response
692-
gotreq = 0
693-
while 1:
692+
gotreq = False
693+
while True:
694694
if self.data_recv:
695695
# Check the first byte to find out what kind of response it is
696696
rtype = byte2int(self.data_recv)
@@ -772,7 +772,7 @@ def parse_error_response(self, request):
772772
else:
773773
self.default_error_handler(e)
774774

775-
return 0
775+
return False
776776

777777

778778
def default_error_handler(self, err):
@@ -937,7 +937,7 @@ def parse_connection_setup(self):
937937
# Only the ConnectionSetupRequest has been sent so far
938938
r = self.sent_requests[0]
939939

940-
while 1:
940+
while True:
941941
# print 'data_send:', repr(self.data_send)
942942
# print 'data_recv:', repr(self.data_recv)
943943

@@ -946,7 +946,7 @@ def parse_connection_setup(self):
946946

947947
# The full response haven't arrived yet
948948
if len(self.data_recv) < alen:
949-
return 0
949+
return False
950950

951951
# Connection failed or further authentication is needed.
952952
# Set reason to the reason string
@@ -956,22 +956,22 @@ def parse_connection_setup(self):
956956
# Else connection succeeded, parse the reply
957957
else:
958958
x, d = r._success_reply.parse_binary(self.data_recv[:alen],
959-
self, rawdict = 1)
959+
self, rawdict = True)
960960
r._data.update(x)
961961

962962
del self.sent_requests[0]
963963

964964
self.data_recv = self.data_recv[alen:]
965965

966-
return 1
966+
return True
967967

968968
else:
969969
# The base reply is 8 bytes long
970970
if len(self.data_recv) < 8:
971-
return 0
971+
return False
972972

973973
r._data, d = r._reply.parse_binary(self.data_recv[:8],
974-
self, rawdict = 1)
974+
self, rawdict = True)
975975
self.data_recv = self.data_recv[8:]
976976

977977
# Loop around to see if we have got the additional data
@@ -1066,7 +1066,7 @@ def __init__(self, display, *args, **keys):
10661066
# Don't bother about locking, since no other threads have
10671067
# access to the display yet
10681068

1069-
display.request_queue.append((self, 1))
1069+
display.request_queue.append((self, True))
10701070

10711071
# However, we must lock send_and_recv, but we don't have
10721072
# to loop.

Xlib/protocol/rq.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class Field(object):
118118
check_value = None
119119
parse_value = None
120120

121-
keyword_args = 0
121+
keyword_args = False
122122

123123
def __init__(self):
124124
pass
@@ -723,7 +723,7 @@ def pack_value(self, value):
723723

724724
class ValueList(Field):
725725
structcode = None
726-
keyword_args = 1
726+
keyword_args = True
727727
default = 'usekeywords'
728728

729729
def __init__(self, name, mask, pad, *fields):
@@ -1088,7 +1088,7 @@ def pack_value(self, value):
10881088
raise BadDataError('%s is not a tuple or a list' % (value))
10891089

10901090

1091-
def parse_value(self, val, display, rawdict = 0):
1091+
def parse_value(self, val, display, rawdict = False):
10921092

10931093
"""This function is used by List and Object fields to convert
10941094
Struct objects with no var_fields into Python values.
@@ -1131,9 +1131,9 @@ def parse_value(self, val, display, rawdict = 0):
11311131
return DictWrapper(ret)
11321132
return ret
11331133

1134-
def parse_binary(self, data, display, rawdict = 0):
1134+
def parse_binary(self, data, display, rawdict = False):
11351135

1136-
"""values, remdata = s.parse_binary(data, display, rawdict = 0)
1136+
"""values, remdata = s.parse_binary(data, display, rawdict = False)
11371137
11381138
Convert a binary representation of the structure into Python values.
11391139
@@ -1354,16 +1354,16 @@ def _set_error(self, error):
13541354
return 0
13551355

13561356
class ReplyRequest(GetAttrData):
1357-
def __init__(self, display, defer = 0, *args, **keys):
1357+
def __init__(self, display, defer = False, *args, **keys):
13581358
self._display = display
13591359
self._binary = self._request.to_binary(*args, **keys)
13601360
self._serial = None
1361-
self._data = None
1361+
self._data = {}
13621362
self._error = None
13631363

13641364
self._response_lock = lock.allocate_lock()
13651365

1366-
self._display.send_request(self, 1)
1366+
self._display.send_request(self, True)
13671367
if not defer:
13681368
self.reply()
13691369

@@ -1389,7 +1389,7 @@ def reply(self):
13891389

13901390
def _parse_response(self, data):
13911391
self._response_lock.acquire()
1392-
self._data, d = self._reply.parse_binary(data, self._display, rawdict = 1)
1392+
self._data, d = self._reply.parse_binary(data, self._display, rawdict = True)
13931393
self._response_lock.release()
13941394

13951395
def _set_error(self, error):
@@ -1408,7 +1408,7 @@ def __init__(self, binarydata = None, display = None,
14081408
if binarydata:
14091409
self._binary = binarydata
14101410
self._data, data = self._fields.parse_binary(binarydata, display,
1411-
rawdict = 1)
1411+
rawdict = True)
14121412
# split event type into type and send_event bit
14131413
self._data['send_event'] = not not self._data['type'] & 0x80
14141414
self._data['type'] = self._data['type'] & 0x7f

Xlib/xobject/drawable.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ def delete_property(self, property, onerror = None):
451451
window = self.id,
452452
property = property)
453453

454-
def get_property(self, property, property_type, offset, length, delete = 0):
454+
def get_property(self, property, property_type, offset, length, delete = False):
455455
r = request.GetProperty(display = self.display,
456456
delete = delete,
457457
window = self.id,
@@ -516,7 +516,7 @@ def convert_selection(self, selection, target, property, time, onerror = None):
516516
property = property,
517517
time = time)
518518

519-
def send_event(self, event, event_mask = 0, propagate = 0, onerror = None):
519+
def send_event(self, event, event_mask = 0, propagate = False, onerror = None):
520520
request.SendEvent(display = self.display,
521521
onerror = onerror,
522522
propagate = propagate,
@@ -629,7 +629,7 @@ def set_input_focus(self, revert_to, time, onerror = None):
629629
focus = self.id,
630630
time = time)
631631

632-
def clear_area(self, x = 0, y = 0, width = 0, height = 0, exposures = 0, onerror = None):
632+
def clear_area(self, x = 0, y = 0, width = 0, height = 0, exposures = False, onerror = None):
633633
request.ClearArea(display = self.display,
634634
onerror = onerror,
635635
exposures = exposures,

0 commit comments

Comments
 (0)