Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 4 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Commits on Nov 10, 2012
@alexer Removed unneeded code from Object
The method to be called is chosen based on structvalue, so
we only need to handle one case per method.
15c374d
@alexer Removed unneeded code from Object
The contained object is always a Struct, so parse_value always exists.
7318220
@alexer Removed structcode initialization from Object, since it's already ini…
…tialized in Field
549bf1d
@alexer Made Object.check_value() actually check the values 1bb284a
Showing with 17 additions and 31 deletions.
  1. +17 −31 Xlib/protocol/rq.py
View
48 Xlib/protocol/rq.py
@@ -546,50 +546,33 @@ def pack_value(self, val):
class Object(ValueField):
- structcode = None
-
def __init__(self, name, type, default = None):
ValueField.__init__(self, name, default)
self.type = type
self.structcode = self.type.structcode
self.structvalues = self.type.structvalues
def parse_binary_value(self, data, display, length, format):
- if self.type.structcode is None:
- return self.type.parse_binary(data, display)
-
- else:
- scode = '=' + self.type.structcode
- slen = struct.calcsize(scode)
-
- v = struct.unpack(scode, data[:slen])
- if self.type.structvalues == 1:
- v = v[0]
-
- if self.type.parse_value is not None:
- v = self.type.parse_value(v, display)
-
- return v, buffer(data, slen)
+ return self.type.parse_binary(data, display)
def parse_value(self, val, display):
- if self.type.parse_value is None:
- return val
- else:
- return self.type.parse_value(val, display)
+ return self.type.parse_value(val, display)
def pack_value(self, val):
- # Single-char values, we'll assume that mean an integer
- if self.type.structcode and len(self.type.structcode) == 1:
- return struct.pack('=' + self.type.structcode, val), None, None
- else:
- return self.type.pack_value(val)
+ return self.type.pack_value(val)
def check_value(self, val):
- if self.type.structcode is None:
- return val
-
if type(val) is types.TupleType:
- return val
+ vals = []
+ i = 0
+ for f in self.type.fields:
+ if f.name:
+ if f.check_value is None:
+ vals.append(val[i])
+ else:
+ vals.append(f.check_value(val[i]))
+ i = i + 1
+ return vals
if type(val) is types.DictType:
data = val
@@ -601,7 +584,10 @@ def check_value(self, val):
vals = []
for f in self.type.fields:
if f.name:
- vals.append(data[f.name])
+ if f.check_value is None:
+ vals.append(data[f.name])
+ else:
+ vals.append(f.check_value(data[f.name]))
return vals

No commit comments for this range

Something went wrong with that request. Please try again.