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

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

Issue 1508613003: Require an explicit ServiceName annotation for interfaces in Python. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years 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 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 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 metaclasses used by the mojo python bindings for interfaces. 6 The metaclasses used by the mojo python bindings for interfaces.
7 7
8 It is splitted from mojo_bindings.reflection because it uses some generated code 8 It is splitted from mojo_bindings.reflection because it uses some generated code
9 that would create a cyclic dependency. 9 that would create a cyclic dependency.
10 """ 10 """
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 return type.__new__(mcs, name, bases, dictionary) 60 return type.__new__(mcs, name, bases, dictionary)
61 61
62 descriptor = dictionary.pop('DESCRIPTOR', {}) 62 descriptor = dictionary.pop('DESCRIPTOR', {})
63 63
64 methods = [_MethodDescriptor(x) for x in descriptor.get('methods', [])] 64 methods = [_MethodDescriptor(x) for x in descriptor.get('methods', [])]
65 for method in methods: 65 for method in methods:
66 dictionary[method.name] = _NotImplemented 66 dictionary[method.name] = _NotImplemented
67 fully_qualified_name = descriptor['fully_qualified_name'] 67 fully_qualified_name = descriptor['fully_qualified_name']
68 68
69 interface_manager = InterfaceManager( 69 interface_manager = InterfaceManager(
70 fully_qualified_name, descriptor['version'], methods) 70 name, descriptor['version'], methods, fully_qualified_name)
71 dictionary.update({ 71 dictionary.update({
72 'manager': None, 72 'manager': None,
73 '_interface_manager': interface_manager, 73 '_interface_manager': interface_manager,
74 }) 74 })
75 75
76 interface_class = type.__new__(mcs, name, bases, dictionary) 76 interface_class = type.__new__(mcs, name, bases, dictionary)
77 interface_manager.interface_class = interface_class 77 interface_manager.interface_class = interface_class
78 return interface_class 78 return interface_class
79 79
80 @property 80 @property
81 def manager(cls): 81 def manager(cls):
82 return cls._interface_manager 82 return cls._interface_manager
83 83
84 # Prevent adding new attributes, or mutating constants. 84 # Prevent adding new attributes, or mutating constants.
85 def __setattr__(cls, key, value): 85 def __setattr__(cls, key, value):
86 raise AttributeError('can\'t set attribute') 86 raise AttributeError('can\'t set attribute')
87 87
88 # Prevent deleting constants. 88 # Prevent deleting constants.
89 def __delattr__(cls, key): 89 def __delattr__(cls, key):
90 raise AttributeError('can\'t delete attribute') 90 raise AttributeError('can\'t delete attribute')
91 91
92 92
93 class InterfaceManager(object): 93 class InterfaceManager(object):
94 """ 94 """
95 Manager for an interface class. The manager contains the operation that allows 95 Manager for an interface class. The manager contains the operation that allows
96 to bind an implementation to a pipe, or to generate a proxy for an interface 96 to bind an implementation to a pipe, or to generate a proxy for an interface
97 over a pipe. 97 over a pipe.
98 """ 98 """
99 99
100 def __init__(self, name, version, methods): 100 def __init__(self, name, version, methods, service_name):
101 self.name = name 101 self.name = name
102 self.version = version 102 self.version = version
103 self.methods = methods 103 self.methods = methods
104 self.service_name = service_name
104 self.interface_class = None 105 self.interface_class = None
105 self._proxy_class = None 106 self._proxy_class = None
106 self._stub_class = None 107 self._stub_class = None
107 108
108 def Proxy(self, handle, version=0): 109 def Proxy(self, handle, version=0):
109 router = messaging.Router(handle) 110 router = messaging.Router(handle)
110 error_handler = _ProxyErrorHandler() 111 error_handler = _ProxyErrorHandler()
111 router.SetErrorHandler(error_handler) 112 router.SetErrorHandler(error_handler)
112 router.Start() 113 router.Start()
113 return self._InternalProxy(router, error_handler, version) 114 return self._InternalProxy(router, error_handler, version)
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 payload = message.payload 458 payload = message.payload
458 query = ( 459 query = (
459 interface_control_messages_mojom.RunOrClosePipeMessageParams.Deserialize( 460 interface_control_messages_mojom.RunOrClosePipeMessageParams.Deserialize(
460 serialization.RootDeserializationContext(payload.data, 461 serialization.RootDeserializationContext(payload.data,
461 payload.handles))) 462 payload.handles)))
462 return query.require_version.version <= manager.interface_manager.version 463 return query.require_version.version <= manager.interface_manager.version
463 464
464 465
465 def _NotImplemented(*_1, **_2): 466 def _NotImplemented(*_1, **_2):
466 raise NotImplementedError() 467 raise NotImplementedError()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698