Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Side by Side Diff: mojo/public/python/mojo/bindings/descriptor.py

Issue 622593002: mojo: Allow circular dependencies between structs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """ 5 """
6 The descriptors used to define generated elements of the mojo python bindings. 6 The descriptors used to define generated elements of the mojo python bindings.
7 """ 7 """
8 8
9 import array 9 import array
10 import itertools 10 import itertools
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 result = array.array(self.array_typecode) 365 result = array.array(self.array_typecode)
366 result.fromstring(buffer(data, 366 result.fromstring(buffer(data,
367 serialization.HEADER_STRUCT.size, 367 serialization.HEADER_STRUCT.size,
368 size - serialization.HEADER_STRUCT.size)) 368 size - serialization.HEADER_STRUCT.size))
369 return result 369 return result
370 370
371 371
372 class StructType(PointerType): 372 class StructType(PointerType):
373 """Type object for structs.""" 373 """Type object for structs."""
374 374
375 def __init__(self, struct_type, nullable=False): 375 def __init__(self, struct_type_getter, nullable=False):
376 PointerType.__init__(self) 376 PointerType.__init__(self)
377 self.struct_type = struct_type 377 self._struct_type_getter = struct_type_getter
378 self._struct_type = None
378 self.nullable = nullable 379 self.nullable = nullable
379 380
381 @property
382 def struct_type(self):
383 if not self._struct_type:
384 self._struct_type = self._struct_type_getter()
385 return self._struct_type
386
380 def Convert(self, value): 387 def Convert(self, value):
381 if value is None or isinstance(value, self.struct_type): 388 if value is None or isinstance(value, self.struct_type):
382 return value 389 return value
383 raise TypeError('%r is not an instance of %r' % (value, self.struct_type)) 390 raise TypeError('%r is not an instance of %r' % (value, self.struct_type))
384 391
385 def GetDefaultValue(self, value): 392 def GetDefaultValue(self, value):
386 if value: 393 if value:
387 return self.struct_type() 394 return self.struct_type()
388 return None 395 return None
389 396
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 553
547 554
548 def _ConvertByteToBooleans(value, min_size=0): 555 def _ConvertByteToBooleans(value, min_size=0):
549 "Unpack an integer into a list of booleans.""" 556 "Unpack an integer into a list of booleans."""
550 res = [] 557 res = []
551 while value: 558 while value:
552 res.append(bool(value&1)) 559 res.append(bool(value&1))
553 value = value / 2 560 value = value / 2
554 res.extend([False] * (min_size - len(res))) 561 res.extend([False] * (min_size - len(res)))
555 return res 562 return res
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698