1- # $Id: rq.py,v 1.13 2002-02-12 10: 11:11 petli Exp $
1+ # $Id: rq.py,v 1.14 2002-02-25 11:09:23 petli Exp $
22#
33# Xlib.protocol.rq -- structure primitives for request, events and errors
44#
5- # Copyright (C) 2000,2001 Peter Liljenberg <petli@ctrl-c.liu.se>
5+ # Copyright (C) 2000-2002 Peter Liljenberg <petli@ctrl-c.liu.se>
66#
77# This program is free software; you can redistribute it and/or modify
88# it under the terms of the GNU General Public License as published by
@@ -446,9 +446,10 @@ class List(ValueField):
446446
447447 structcode = None
448448
449- def __init__ (self , name , type ):
449+ def __init__ (self , name , type , pad = 1 ):
450450 ValueField .__init__ (self , name )
451451 self .type = type
452+ self .pad = pad
452453
453454 def parse_binary_value (self , data , display , length , format ):
454455 if length is None :
@@ -501,7 +502,8 @@ def parse_binary_value(self, data, display, length, format):
501502
502503 data = buffer (data , pos )
503504
504- data = buffer (data , len (data ) % 4 )
505+ if self .pad :
506+ data = buffer (data , len (data ) % 4 )
505507
506508 return ret , data
507509
@@ -517,15 +519,16 @@ def pack_value(self, val):
517519
518520 data = string .join (data , '' )
519521
520- dlen = len (data )
521- data = data + '\0 ' * ((4 - dlen % 4 ) % 4 )
522+ if self .pad :
523+ dlen = len (data )
524+ data = data + '\0 ' * ((4 - dlen % 4 ) % 4 )
522525
523526 return data , len (val ), None
524527
525528
526529class FixedList (List ):
527- def __init__ (self , name , size , type ):
528- List .__init__ (self , name , type )
530+ def __init__ (self , name , size , type , pad = 1 ):
531+ List .__init__ (self , name , type , pad )
529532 self .size = size
530533
531534 def parse_binary_value (self , data , display , length , format ):
@@ -721,7 +724,7 @@ def parse_binary_value(self, data, display, length, format):
721724 if mask & flag :
722725 if field .structcode :
723726 vals = struct .unpack ('=' + field .structcode ,
724- data [:struct .calcsize (field .structcode )])
727+ data [:struct .calcsize ('=' + field .structcode )])
725728 if field .structvalues == 1 :
726729 vals = vals [0 ]
727730
0 commit comments