Skip to content

Commit 7069b07

Browse files
committed
protocol: improve support for binary strings
Rename rq.Bytes to rq.Binary and rq.FixedString to rq.FixedBinary so it's clear what those fields are used for.
1 parent 0089da2 commit 7069b07

3 files changed

Lines changed: 8 additions & 13 deletions

File tree

‎Xlib/ext/security.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class SecurityGenerateAuthorization(rq.ReplyRequest):
7272
rq.LengthOf('auth_data', 2),
7373
rq.Card32('value_mask'),
7474
rq.String8('auth_proto'),
75-
rq.Bytes('auth_data'),
75+
rq.Binary('auth_data'),
7676
rq.List('values', rq.Card32Obj)
7777
)
7878
_reply = rq.Struct(rq.ReplyCode(),
@@ -82,11 +82,11 @@ class SecurityGenerateAuthorization(rq.ReplyRequest):
8282
AUTHID('authid'),
8383
rq.LengthOf('auth_data_return', 2),
8484
rq.Pad(18),
85-
rq.Bytes('auth_data_return')
85+
rq.Binary('auth_data_return')
8686
)
8787

8888

89-
def generate_authorization(self, auth_proto, auth_data='', timeout=None,
89+
def generate_authorization(self, auth_proto, auth_data=b'', timeout=None,
9090
trust_level=None, group=None, event_mask=None):
9191
value_mask = 0
9292
values = []

‎Xlib/protocol/event.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class AnyEvent(rq.Event):
2929
_fields = rq.Struct( rq.Card8('type'),
3030
rq.Card8('detail'),
3131
rq.Card16('sequence_number'),
32-
rq.FixedString('data', 28),
32+
rq.FixedBinary('data', 28),
3333
)
3434

3535
class KeyButtonPointer(rq.Event):

‎Xlib/protocol/rq.py‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -364,26 +364,23 @@ def __init__(self, name):
364364
X.SouthEastGravity))
365365

366366

367-
class FixedString(ValueField):
367+
class FixedBinary(ValueField):
368368
structvalues = 1
369369

370370
def __init__(self, name, size):
371371
ValueField.__init__(self, name)
372372
self.structcode = '{0}s'.format(size)
373373

374374

375-
class Bytes(ValueField):
375+
class Binary(ValueField):
376376
structcode = None
377377

378378
def __init__(self, name, pad = 1):
379379
ValueField.__init__(self, name)
380380
self.pad = pad
381381

382382
def pack_value(self, val):
383-
if isinstance(val, bytes):
384-
val_bytes = val
385-
else:
386-
val_bytes = val.encode()
383+
val_bytes = val
387384
slen = len(val_bytes)
388385

389386
if self.pad:
@@ -400,9 +397,7 @@ def parse_binary_value(self, data, display, length, format):
400397
else:
401398
slen = length
402399

403-
data_bytes = data[:length]
404-
405-
return data_bytes, data[slen:]
400+
return data[:length], data[slen:]
406401

407402

408403
class String8(ValueField):

0 commit comments

Comments
 (0)