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

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

Issue 830593003: Update mojo sdk to rev 9fbbc4f0fef1187312316c0ed992342474e139f1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cherry-pick mojo 9d3b8dd17f12d20035a14737fdc38dd926890ff8 Created 5 years, 11 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
11 import struct 11 import struct
12 12
13 import mojo.bindings.reflection as reflection 13 import mojo_bindings.reflection as reflection
14 import mojo.bindings.serialization as serialization 14 import mojo_bindings.serialization as serialization
15 15
16 # pylint: disable=E0611,F0401 16 # pylint: disable=E0611,F0401
17 import mojo.system 17 import mojo_system
18 18
19 19
20 class Type(object): 20 class Type(object):
21 """Describes the type of a struct field or a method parameter,""" 21 """Describes the type of a struct field or a method parameter,"""
22 22
23 def Convert(self, value): # pylint: disable=R0201 23 def Convert(self, value): # pylint: disable=R0201
24 """ 24 """
25 Convert the given value into its canonical representation, raising an 25 Convert the given value into its canonical representation, raising an
26 exception if the value cannot be converted. 26 exception if the value cannot be converted.
27 """ 27 """
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 'Trying to serialize null for non nullable type.') 233 'Trying to serialize null for non nullable type.')
234 if not handle.IsValid(): 234 if not handle.IsValid():
235 return (-1, []) 235 return (-1, [])
236 return (handle_offset, [handle]) 236 return (handle_offset, [handle])
237 237
238 def Deserialize(self, value, context): 238 def Deserialize(self, value, context):
239 if value == -1: 239 if value == -1:
240 if not self.nullable: 240 if not self.nullable:
241 raise serialization.DeserializationException( 241 raise serialization.DeserializationException(
242 'Trying to deserialize null for non nullable type.') 242 'Trying to deserialize null for non nullable type.')
243 return self.FromHandle(mojo.system.Handle()) 243 return self.FromHandle(mojo_system.Handle())
244 return self.FromHandle(context.ClaimHandle(value)) 244 return self.FromHandle(context.ClaimHandle(value))
245 245
246 def FromHandle(self, handle): 246 def FromHandle(self, handle):
247 raise NotImplementedError() 247 raise NotImplementedError()
248 248
249 def ToHandle(self, value): 249 def ToHandle(self, value):
250 raise NotImplementedError() 250 raise NotImplementedError()
251 251
252 252
253 class HandleType(BaseHandleType): 253 class HandleType(BaseHandleType):
254 """Type object for handles.""" 254 """Type object for handles."""
255 255
256 def Convert(self, value): 256 def Convert(self, value):
257 if value is None: 257 if value is None:
258 return mojo.system.Handle() 258 return mojo_system.Handle()
259 if not isinstance(value, mojo.system.Handle): 259 if not isinstance(value, mojo_system.Handle):
260 raise TypeError('%r is not a handle' % value) 260 raise TypeError('%r is not a handle' % value)
261 return value 261 return value
262 262
263 def FromHandle(self, handle): 263 def FromHandle(self, handle):
264 return handle 264 return handle
265 265
266 def ToHandle(self, value): 266 def ToHandle(self, value):
267 return value 267 return value
268 268
269 269
270 class InterfaceRequestType(BaseHandleType): 270 class InterfaceRequestType(BaseHandleType):
271 """Type object for interface requests.""" 271 """Type object for interface requests."""
272 272
273 def Convert(self, value): 273 def Convert(self, value):
274 if value is None: 274 if value is None:
275 return reflection.InterfaceRequest(mojo.system.Handle()) 275 return reflection.InterfaceRequest(mojo_system.Handle())
276 if not isinstance(value, reflection.InterfaceRequest): 276 if not isinstance(value, reflection.InterfaceRequest):
277 raise TypeError('%r is not an interface request' % value) 277 raise TypeError('%r is not an interface request' % value)
278 return value 278 return value
279 279
280 def FromHandle(self, handle): 280 def FromHandle(self, handle):
281 return reflection.InterfaceRequest(handle) 281 return reflection.InterfaceRequest(handle)
282 282
283 def ToHandle(self, value): 283 def ToHandle(self, value):
284 return value.PassMessagePipe() 284 return value.PassMessagePipe()
285 285
(...skipping 17 matching lines...) Expand all
303 self._interface = self._interface_getter() 303 self._interface = self._interface_getter()
304 return self._interface 304 return self._interface
305 305
306 def FromHandle(self, handle): 306 def FromHandle(self, handle):
307 if handle.IsValid(): 307 if handle.IsValid():
308 return self.interface.manager.Proxy(handle) 308 return self.interface.manager.Proxy(handle)
309 return None 309 return None
310 310
311 def ToHandle(self, value): 311 def ToHandle(self, value):
312 if not value: 312 if not value:
313 return mojo.system.Handle() 313 return mojo_system.Handle()
314 if isinstance(value, reflection.InterfaceProxy): 314 if isinstance(value, reflection.InterfaceProxy):
315 return value.manager.PassMessagePipe() 315 return value.manager.PassMessagePipe()
316 pipe = mojo.system.MessagePipe() 316 pipe = mojo_system.MessagePipe()
317 self.interface.manager.Bind(value, pipe.handle0) 317 self.interface.manager.Bind(value, pipe.handle0)
318 return pipe.handle1 318 return pipe.handle1
319 319
320 320
321 class BaseArrayType(PointerType): 321 class BaseArrayType(PointerType):
322 """Abstract Type object for arrays.""" 322 """Abstract Type object for arrays."""
323 323
324 def __init__(self, nullable=False, length=0): 324 def __init__(self, nullable=False, length=0):
325 PointerType.__init__(self, nullable) 325 PointerType.__init__(self, nullable)
326 self.length = length 326 self.length = length
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 687
688 688
689 def _ConvertByteToBooleans(value, min_size=0): 689 def _ConvertByteToBooleans(value, min_size=0):
690 """Unpack an integer into a list of booleans.""" 690 """Unpack an integer into a list of booleans."""
691 res = [] 691 res = []
692 while value: 692 while value:
693 res.append(bool(value&1)) 693 res.append(bool(value&1))
694 value = value / 2 694 value = value / 2
695 res.extend([False] * (min_size - len(res))) 695 res.extend([False] * (min_size - len(res)))
696 return res 696 return res
OLDNEW
« no previous file with comments | « mojo/public/python/mojo_bindings/__init__.py ('k') | mojo/public/python/mojo_bindings/messaging.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698