rustorb 0.1.0__cp39-abi3-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rustorb/CORBA.py +1785 -0
- rustorb/DynamicAny.py +403 -0
- rustorb/Messaging.py +26 -0
- rustorb/PortableServer.py +461 -0
- rustorb/PortableServer__POA.py +40 -0
- rustorb/TimeBase.py +9 -0
- rustorb/__init__.py +12 -0
- rustorb/_native.pyd +0 -0
- rustorb/_native.pyi +186 -0
- rustorb/_rt.py +577 -0
- rustorb/_types.py +226 -0
- rustorb/timeouts.py +79 -0
- rustorb-0.1.0.dist-info/METADATA +51 -0
- rustorb-0.1.0.dist-info/RECORD +16 -0
- rustorb-0.1.0.dist-info/WHEEL +4 -0
- rustorb-0.1.0.dist-info/sboms/rustorb-python.cyclonedx.json +1344 -0
rustorb/CORBA.py
ADDED
|
@@ -0,0 +1,1785 @@
|
|
|
1
|
+
"""The CORBA module of the IDL to Python mapping.
|
|
2
|
+
|
|
3
|
+
TypeCodes, ``Any`` values, the exception hierarchy, object references and
|
|
4
|
+
the ORB (``CORBA.ORB_init``). The ORB, invocations and the POA are those
|
|
5
|
+
of the native module ``rustorb._native``; the TypeCodes, values and
|
|
6
|
+
exceptions are plain Python, so generated code can be imported without
|
|
7
|
+
it.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import atexit as _atexit
|
|
11
|
+
import builtins as _builtins
|
|
12
|
+
import decimal as _decimal
|
|
13
|
+
import reprlib as _reprlib
|
|
14
|
+
import threading as _threading
|
|
15
|
+
import time as _time
|
|
16
|
+
from typing import Optional
|
|
17
|
+
|
|
18
|
+
from . import _types
|
|
19
|
+
|
|
20
|
+
try:
|
|
21
|
+
from . import _native
|
|
22
|
+
except ImportError: # the pure-Python parts work without it
|
|
23
|
+
_native = None # type: ignore[assignment]
|
|
24
|
+
|
|
25
|
+
# ---------------------------------------------------------------------------
|
|
26
|
+
# TCKind
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
_TCKIND_NAMES = (
|
|
30
|
+
"tk_null",
|
|
31
|
+
"tk_void",
|
|
32
|
+
"tk_short",
|
|
33
|
+
"tk_long",
|
|
34
|
+
"tk_ushort",
|
|
35
|
+
"tk_ulong",
|
|
36
|
+
"tk_float",
|
|
37
|
+
"tk_double",
|
|
38
|
+
"tk_boolean",
|
|
39
|
+
"tk_char",
|
|
40
|
+
"tk_octet",
|
|
41
|
+
"tk_any",
|
|
42
|
+
"tk_TypeCode",
|
|
43
|
+
"tk_Principal",
|
|
44
|
+
"tk_objref",
|
|
45
|
+
"tk_struct",
|
|
46
|
+
"tk_union",
|
|
47
|
+
"tk_enum",
|
|
48
|
+
"tk_string",
|
|
49
|
+
"tk_sequence",
|
|
50
|
+
"tk_array",
|
|
51
|
+
"tk_alias",
|
|
52
|
+
"tk_except",
|
|
53
|
+
"tk_longlong",
|
|
54
|
+
"tk_ulonglong",
|
|
55
|
+
"tk_longdouble",
|
|
56
|
+
"tk_wchar",
|
|
57
|
+
"tk_wstring",
|
|
58
|
+
"tk_fixed",
|
|
59
|
+
"tk_value",
|
|
60
|
+
"tk_value_box",
|
|
61
|
+
"tk_native",
|
|
62
|
+
"tk_abstract_interface",
|
|
63
|
+
"tk_local_interface",
|
|
64
|
+
)
|
|
65
|
+
TCKind = _types.Enum("IDL:omg.org/CORBA/TCKind:1.0", _TCKIND_NAMES)
|
|
66
|
+
(
|
|
67
|
+
tk_null,
|
|
68
|
+
tk_void,
|
|
69
|
+
tk_short,
|
|
70
|
+
tk_long,
|
|
71
|
+
tk_ushort,
|
|
72
|
+
tk_ulong,
|
|
73
|
+
tk_float,
|
|
74
|
+
tk_double,
|
|
75
|
+
tk_boolean,
|
|
76
|
+
tk_char,
|
|
77
|
+
tk_octet,
|
|
78
|
+
tk_any,
|
|
79
|
+
tk_TypeCode,
|
|
80
|
+
tk_Principal,
|
|
81
|
+
tk_objref,
|
|
82
|
+
tk_struct,
|
|
83
|
+
tk_union,
|
|
84
|
+
tk_enum,
|
|
85
|
+
tk_string,
|
|
86
|
+
tk_sequence,
|
|
87
|
+
tk_array,
|
|
88
|
+
tk_alias,
|
|
89
|
+
tk_except,
|
|
90
|
+
tk_longlong,
|
|
91
|
+
tk_ulonglong,
|
|
92
|
+
tk_longdouble,
|
|
93
|
+
tk_wchar,
|
|
94
|
+
tk_wstring,
|
|
95
|
+
tk_fixed,
|
|
96
|
+
tk_value,
|
|
97
|
+
tk_value_box,
|
|
98
|
+
tk_native,
|
|
99
|
+
tk_abstract_interface,
|
|
100
|
+
tk_local_interface,
|
|
101
|
+
) = TCKind._items
|
|
102
|
+
|
|
103
|
+
#: Type modifiers of valuetypes (``TypeCode.type_modifier``).
|
|
104
|
+
VM_NONE = 0
|
|
105
|
+
VM_CUSTOM = 1
|
|
106
|
+
VM_ABSTRACT = 2
|
|
107
|
+
VM_TRUNCATABLE = 3
|
|
108
|
+
|
|
109
|
+
#: Visibility of valuetype state members (``TypeCode.member_visibility``).
|
|
110
|
+
PRIVATE_MEMBER = 0
|
|
111
|
+
PUBLIC_MEMBER = 1
|
|
112
|
+
|
|
113
|
+
# ---------------------------------------------------------------------------
|
|
114
|
+
# Exceptions
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
class Exception(_builtins.Exception): # noqa: A001 - the name is fixed by the mapping
|
|
118
|
+
"""Base of every CORBA exception."""
|
|
119
|
+
|
|
120
|
+
_NP_RepositoryId: Optional[str] = None
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class UserException(Exception):
|
|
124
|
+
"""Base of the exceptions declared in IDL."""
|
|
125
|
+
|
|
126
|
+
_NP_members: tuple = ()
|
|
127
|
+
|
|
128
|
+
def __init__(self, *args, **kw):
|
|
129
|
+
_types._init_members(self, type(self).__name__, self._NP_members, args, kw)
|
|
130
|
+
Exception.__init__(self, *[getattr(self, m) for m in self._NP_members])
|
|
131
|
+
|
|
132
|
+
def __repr__(self):
|
|
133
|
+
return _types._repr_members(self, self._NP_members)
|
|
134
|
+
|
|
135
|
+
__str__ = __repr__
|
|
136
|
+
|
|
137
|
+
def __eq__(self, other):
|
|
138
|
+
return type(other) is type(self) and all(
|
|
139
|
+
getattr(self, m) == getattr(other, m) for m in self._NP_members
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
def __ne__(self, other):
|
|
143
|
+
return not self.__eq__(other)
|
|
144
|
+
|
|
145
|
+
__hash__ = Exception.__hash__
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
#: The IDL boolean constants of the Python mapping.
|
|
149
|
+
TRUE = True
|
|
150
|
+
FALSE = False
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
_completion = _types.Enum(
|
|
154
|
+
"IDL:omg.org/CORBA/completion_status:1.0",
|
|
155
|
+
("COMPLETED_YES", "COMPLETED_NO", "COMPLETED_MAYBE"),
|
|
156
|
+
)
|
|
157
|
+
completion_status = _completion
|
|
158
|
+
COMPLETED_YES, COMPLETED_NO, COMPLETED_MAYBE = _completion._items
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
class SystemException(Exception):
|
|
162
|
+
"""Base of the standard system exceptions: ``minor`` and ``completed``."""
|
|
163
|
+
|
|
164
|
+
def __init__(self, minor=0, completed=COMPLETED_NO):
|
|
165
|
+
Exception.__init__(self, minor, completed)
|
|
166
|
+
self.minor = minor
|
|
167
|
+
self.completed = completed
|
|
168
|
+
|
|
169
|
+
def __repr__(self):
|
|
170
|
+
return "CORBA.%s(0x%x, %r)" % (type(self).__name__, self.minor, self.completed)
|
|
171
|
+
|
|
172
|
+
__str__ = __repr__
|
|
173
|
+
|
|
174
|
+
def __eq__(self, other):
|
|
175
|
+
return (
|
|
176
|
+
type(other) is type(self)
|
|
177
|
+
and self.minor == other.minor
|
|
178
|
+
and self.completed == other.completed
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
def __ne__(self, other):
|
|
182
|
+
return not self.__eq__(other)
|
|
183
|
+
|
|
184
|
+
__hash__ = Exception.__hash__
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
#: Repository ID -> class of every system exception.
|
|
188
|
+
system_exceptions: dict = {}
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def _system_exception(name):
|
|
192
|
+
cls = type(
|
|
193
|
+
name,
|
|
194
|
+
(SystemException,),
|
|
195
|
+
{"_NP_RepositoryId": "IDL:omg.org/CORBA/%s:1.0" % name, "__module__": __name__},
|
|
196
|
+
)
|
|
197
|
+
system_exceptions[cls._NP_RepositoryId] = cls
|
|
198
|
+
return cls
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
UNKNOWN = _system_exception("UNKNOWN")
|
|
202
|
+
BAD_PARAM = _system_exception("BAD_PARAM")
|
|
203
|
+
NO_MEMORY = _system_exception("NO_MEMORY")
|
|
204
|
+
IMP_LIMIT = _system_exception("IMP_LIMIT")
|
|
205
|
+
COMM_FAILURE = _system_exception("COMM_FAILURE")
|
|
206
|
+
INV_OBJREF = _system_exception("INV_OBJREF")
|
|
207
|
+
NO_PERMISSION = _system_exception("NO_PERMISSION")
|
|
208
|
+
INTERNAL = _system_exception("INTERNAL")
|
|
209
|
+
MARSHAL = _system_exception("MARSHAL")
|
|
210
|
+
INITIALIZE = _system_exception("INITIALIZE")
|
|
211
|
+
NO_IMPLEMENT = _system_exception("NO_IMPLEMENT")
|
|
212
|
+
BAD_TYPECODE = _system_exception("BAD_TYPECODE")
|
|
213
|
+
BAD_OPERATION = _system_exception("BAD_OPERATION")
|
|
214
|
+
NO_RESOURCES = _system_exception("NO_RESOURCES")
|
|
215
|
+
NO_RESPONSE = _system_exception("NO_RESPONSE")
|
|
216
|
+
PERSIST_STORE = _system_exception("PERSIST_STORE")
|
|
217
|
+
BAD_INV_ORDER = _system_exception("BAD_INV_ORDER")
|
|
218
|
+
TRANSIENT = _system_exception("TRANSIENT")
|
|
219
|
+
FREE_MEM = _system_exception("FREE_MEM")
|
|
220
|
+
INV_IDENT = _system_exception("INV_IDENT")
|
|
221
|
+
INV_FLAG = _system_exception("INV_FLAG")
|
|
222
|
+
INTF_REPOS = _system_exception("INTF_REPOS")
|
|
223
|
+
BAD_CONTEXT = _system_exception("BAD_CONTEXT")
|
|
224
|
+
OBJ_ADAPTER = _system_exception("OBJ_ADAPTER")
|
|
225
|
+
DATA_CONVERSION = _system_exception("DATA_CONVERSION")
|
|
226
|
+
OBJECT_NOT_EXIST = _system_exception("OBJECT_NOT_EXIST")
|
|
227
|
+
TRANSACTION_REQUIRED = _system_exception("TRANSACTION_REQUIRED")
|
|
228
|
+
TRANSACTION_ROLLEDBACK = _system_exception("TRANSACTION_ROLLEDBACK")
|
|
229
|
+
INVALID_TRANSACTION = _system_exception("INVALID_TRANSACTION")
|
|
230
|
+
INV_POLICY = _system_exception("INV_POLICY")
|
|
231
|
+
CODESET_INCOMPATIBLE = _system_exception("CODESET_INCOMPATIBLE")
|
|
232
|
+
REBIND = _system_exception("REBIND")
|
|
233
|
+
TIMEOUT = _system_exception("TIMEOUT")
|
|
234
|
+
TRANSACTION_UNAVAILABLE = _system_exception("TRANSACTION_UNAVAILABLE")
|
|
235
|
+
TRANSACTION_MODE = _system_exception("TRANSACTION_MODE")
|
|
236
|
+
BAD_QOS = _system_exception("BAD_QOS")
|
|
237
|
+
INVALID_ACTIVITY = _system_exception("INVALID_ACTIVITY")
|
|
238
|
+
ACTIVITY_COMPLETED = _system_exception("ACTIVITY_COMPLETED")
|
|
239
|
+
ACTIVITY_REQUIRED = _system_exception("ACTIVITY_REQUIRED")
|
|
240
|
+
|
|
241
|
+
# ---------------------------------------------------------------------------
|
|
242
|
+
# TypeCode
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
class TypeCode(object):
|
|
246
|
+
"""A CORBA TypeCode. Made by the ``TC_*`` constants and by generated
|
|
247
|
+
code (``_tc_Name``); compare with :meth:`equal`."""
|
|
248
|
+
|
|
249
|
+
class Bounds(UserException):
|
|
250
|
+
_NP_RepositoryId = "IDL:omg.org/CORBA/TypeCode/Bounds:1.0"
|
|
251
|
+
|
|
252
|
+
class BadKind(UserException):
|
|
253
|
+
_NP_RepositoryId = "IDL:omg.org/CORBA/TypeCode/BadKind:1.0"
|
|
254
|
+
|
|
255
|
+
def __init__(self, kind, repoId="", name="", **params):
|
|
256
|
+
self._k = kind
|
|
257
|
+
self._id = repoId
|
|
258
|
+
self._name = name
|
|
259
|
+
# members: [(name, TypeCode)]; labels: [value] for unions
|
|
260
|
+
self._members = params.get("members")
|
|
261
|
+
self._labels = params.get("labels")
|
|
262
|
+
self._disc = params.get("discriminator")
|
|
263
|
+
self._default = params.get("default", -1)
|
|
264
|
+
self._content = params.get("content")
|
|
265
|
+
self._length = params.get("length", 0)
|
|
266
|
+
self._digits = params.get("digits", 0)
|
|
267
|
+
self._scale = params.get("scale", 0)
|
|
268
|
+
self._class = params.get("cls")
|
|
269
|
+
# valuetypes: members are [(name, TypeCode, visibility)]
|
|
270
|
+
self._modifier = params.get("modifier", VM_NONE)
|
|
271
|
+
self._base = params.get("base")
|
|
272
|
+
|
|
273
|
+
def __repr__(self):
|
|
274
|
+
if self._id:
|
|
275
|
+
return "CORBA.TypeCode(%s, %r)" % (self._k._n, self._id)
|
|
276
|
+
return "CORBA.TypeCode(%s)" % self._k._n
|
|
277
|
+
|
|
278
|
+
# -- standard operations --
|
|
279
|
+
|
|
280
|
+
def kind(self):
|
|
281
|
+
return self._k
|
|
282
|
+
|
|
283
|
+
def _need(self, *kinds):
|
|
284
|
+
if self._k not in kinds:
|
|
285
|
+
raise TypeCode.BadKind()
|
|
286
|
+
|
|
287
|
+
def id(self):
|
|
288
|
+
self._need(
|
|
289
|
+
tk_objref,
|
|
290
|
+
tk_struct,
|
|
291
|
+
tk_union,
|
|
292
|
+
tk_enum,
|
|
293
|
+
tk_alias,
|
|
294
|
+
tk_except,
|
|
295
|
+
tk_value,
|
|
296
|
+
tk_value_box,
|
|
297
|
+
tk_native,
|
|
298
|
+
tk_abstract_interface,
|
|
299
|
+
tk_local_interface,
|
|
300
|
+
)
|
|
301
|
+
return self._id
|
|
302
|
+
|
|
303
|
+
def name(self):
|
|
304
|
+
self._need(
|
|
305
|
+
tk_objref,
|
|
306
|
+
tk_struct,
|
|
307
|
+
tk_union,
|
|
308
|
+
tk_enum,
|
|
309
|
+
tk_alias,
|
|
310
|
+
tk_except,
|
|
311
|
+
tk_value,
|
|
312
|
+
tk_value_box,
|
|
313
|
+
tk_native,
|
|
314
|
+
tk_abstract_interface,
|
|
315
|
+
tk_local_interface,
|
|
316
|
+
)
|
|
317
|
+
return self._name
|
|
318
|
+
|
|
319
|
+
def member_count(self):
|
|
320
|
+
self._need(tk_struct, tk_union, tk_enum, tk_except, tk_value)
|
|
321
|
+
return len(self._members)
|
|
322
|
+
|
|
323
|
+
def _member(self, index):
|
|
324
|
+
self._need(tk_struct, tk_union, tk_enum, tk_except, tk_value)
|
|
325
|
+
if not 0 <= index < len(self._members):
|
|
326
|
+
raise TypeCode.Bounds()
|
|
327
|
+
return self._members[index]
|
|
328
|
+
|
|
329
|
+
def member_name(self, index):
|
|
330
|
+
m = self._member(index)
|
|
331
|
+
return m if self._k is tk_enum else m[0]
|
|
332
|
+
|
|
333
|
+
def member_type(self, index):
|
|
334
|
+
self._need(tk_struct, tk_union, tk_except, tk_value)
|
|
335
|
+
return self._member(index)[1]
|
|
336
|
+
|
|
337
|
+
def member_visibility(self, index):
|
|
338
|
+
self._need(tk_value)
|
|
339
|
+
return self._member(index)[2]
|
|
340
|
+
|
|
341
|
+
def type_modifier(self):
|
|
342
|
+
self._need(tk_value)
|
|
343
|
+
return self._modifier
|
|
344
|
+
|
|
345
|
+
def concrete_base_type(self):
|
|
346
|
+
self._need(tk_value)
|
|
347
|
+
return self._base if self._base is not None else TC_null
|
|
348
|
+
|
|
349
|
+
def member_label(self, index):
|
|
350
|
+
self._need(tk_union)
|
|
351
|
+
self._member(index)
|
|
352
|
+
if index == self._default:
|
|
353
|
+
return Any(TC_octet, 0)
|
|
354
|
+
return Any(self._disc, self._labels[index])
|
|
355
|
+
|
|
356
|
+
def discriminator_type(self):
|
|
357
|
+
self._need(tk_union)
|
|
358
|
+
return self._disc
|
|
359
|
+
|
|
360
|
+
def default_index(self):
|
|
361
|
+
self._need(tk_union)
|
|
362
|
+
return self._default
|
|
363
|
+
|
|
364
|
+
def length(self):
|
|
365
|
+
self._need(tk_string, tk_wstring, tk_sequence, tk_array)
|
|
366
|
+
return self._length
|
|
367
|
+
|
|
368
|
+
def content_type(self):
|
|
369
|
+
self._need(tk_sequence, tk_array, tk_alias, tk_value_box)
|
|
370
|
+
return self._content
|
|
371
|
+
|
|
372
|
+
def fixed_digits(self):
|
|
373
|
+
self._need(tk_fixed)
|
|
374
|
+
return self._digits
|
|
375
|
+
|
|
376
|
+
def fixed_scale(self):
|
|
377
|
+
self._need(tk_fixed)
|
|
378
|
+
return self._scale
|
|
379
|
+
|
|
380
|
+
def equal(self, other):
|
|
381
|
+
return _tc_equal(self, other, set(), alias=True)
|
|
382
|
+
|
|
383
|
+
def equivalent(self, other):
|
|
384
|
+
return _tc_equal(_unalias(self), _unalias(other), set(), alias=False)
|
|
385
|
+
|
|
386
|
+
def get_compact_typecode(self):
|
|
387
|
+
return self
|
|
388
|
+
|
|
389
|
+
# -- for the ORB --
|
|
390
|
+
|
|
391
|
+
def _NP_class(self):
|
|
392
|
+
"""The Python class of values of this type (struct, union, exception,
|
|
393
|
+
enum type), or None."""
|
|
394
|
+
return self._class
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
def _unalias(tc):
|
|
398
|
+
while tc._k is tk_alias:
|
|
399
|
+
tc = tc._content
|
|
400
|
+
return tc
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
def _tc_equal(a, b, seen, alias):
|
|
404
|
+
if a is b:
|
|
405
|
+
return True
|
|
406
|
+
if not isinstance(b, TypeCode):
|
|
407
|
+
return False
|
|
408
|
+
if not alias:
|
|
409
|
+
a, b = _unalias(a), _unalias(b)
|
|
410
|
+
if a._k is not b._k:
|
|
411
|
+
return False
|
|
412
|
+
key = (id(a), id(b))
|
|
413
|
+
if key in seen:
|
|
414
|
+
return True # recursive types: assume equal while comparing
|
|
415
|
+
seen.add(key)
|
|
416
|
+
k = a._k
|
|
417
|
+
if k in (
|
|
418
|
+
tk_objref,
|
|
419
|
+
tk_struct,
|
|
420
|
+
tk_union,
|
|
421
|
+
tk_enum,
|
|
422
|
+
tk_alias,
|
|
423
|
+
tk_except,
|
|
424
|
+
tk_value,
|
|
425
|
+
tk_value_box,
|
|
426
|
+
tk_native,
|
|
427
|
+
tk_abstract_interface,
|
|
428
|
+
tk_local_interface,
|
|
429
|
+
):
|
|
430
|
+
if a._id != b._id or a._name != b._name:
|
|
431
|
+
return False
|
|
432
|
+
if k is tk_value:
|
|
433
|
+
if a._modifier != b._modifier or len(a._members) != len(b._members):
|
|
434
|
+
return False
|
|
435
|
+
if (a._base is None) != (b._base is None):
|
|
436
|
+
return False
|
|
437
|
+
if a._base is not None and not _tc_equal(a._base, b._base, seen, alias):
|
|
438
|
+
return False
|
|
439
|
+
for (an, at, av), (bn, bt, bv) in zip(a._members, b._members):
|
|
440
|
+
if an != bn or av != bv or not _tc_equal(at, bt, seen, alias):
|
|
441
|
+
return False
|
|
442
|
+
return True
|
|
443
|
+
if k is tk_enum:
|
|
444
|
+
return list(a._members) == list(b._members)
|
|
445
|
+
if k in (tk_struct, tk_except, tk_union):
|
|
446
|
+
if len(a._members) != len(b._members):
|
|
447
|
+
return False
|
|
448
|
+
for (an, at), (bn, bt) in zip(a._members, b._members):
|
|
449
|
+
if an != bn or not _tc_equal(at, bt, seen, alias):
|
|
450
|
+
return False
|
|
451
|
+
if k is tk_union:
|
|
452
|
+
return (
|
|
453
|
+
a._default == b._default
|
|
454
|
+
and _tc_equal(a._disc, b._disc, seen, alias)
|
|
455
|
+
and list(a._labels) == list(b._labels)
|
|
456
|
+
)
|
|
457
|
+
return True
|
|
458
|
+
if k in (tk_string, tk_wstring):
|
|
459
|
+
return a._length == b._length
|
|
460
|
+
if k in (tk_sequence, tk_array):
|
|
461
|
+
return a._length == b._length and _tc_equal(a._content, b._content, seen, alias)
|
|
462
|
+
if k in (tk_alias, tk_value_box):
|
|
463
|
+
return _tc_equal(a._content, b._content, seen, alias)
|
|
464
|
+
if k is tk_fixed:
|
|
465
|
+
return a._digits == b._digits and a._scale == b._scale
|
|
466
|
+
return True
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
TC_null = TypeCode(tk_null)
|
|
470
|
+
TC_void = TypeCode(tk_void)
|
|
471
|
+
TC_short = TypeCode(tk_short)
|
|
472
|
+
TC_long = TypeCode(tk_long)
|
|
473
|
+
TC_ushort = TypeCode(tk_ushort)
|
|
474
|
+
TC_ulong = TypeCode(tk_ulong)
|
|
475
|
+
TC_float = TypeCode(tk_float)
|
|
476
|
+
TC_double = TypeCode(tk_double)
|
|
477
|
+
TC_boolean = TypeCode(tk_boolean)
|
|
478
|
+
TC_char = TypeCode(tk_char)
|
|
479
|
+
TC_octet = TypeCode(tk_octet)
|
|
480
|
+
TC_any = TypeCode(tk_any)
|
|
481
|
+
TC_TypeCode = TypeCode(tk_TypeCode)
|
|
482
|
+
TC_Principal = TypeCode(tk_Principal)
|
|
483
|
+
TC_Object = TypeCode(tk_objref, "IDL:omg.org/CORBA/Object:1.0", "Object")
|
|
484
|
+
TC_string = TypeCode(tk_string)
|
|
485
|
+
TC_longlong = TypeCode(tk_longlong)
|
|
486
|
+
TC_ulonglong = TypeCode(tk_ulonglong)
|
|
487
|
+
TC_longdouble = TypeCode(tk_longdouble)
|
|
488
|
+
TC_wchar = TypeCode(tk_wchar)
|
|
489
|
+
TC_wstring = TypeCode(tk_wstring)
|
|
490
|
+
|
|
491
|
+
#: TCKind value -> TypeCode of the kinds without parameters.
|
|
492
|
+
_SIMPLE = {
|
|
493
|
+
tc._k._v: tc
|
|
494
|
+
for tc in (
|
|
495
|
+
TC_null,
|
|
496
|
+
TC_void,
|
|
497
|
+
TC_short,
|
|
498
|
+
TC_long,
|
|
499
|
+
TC_ushort,
|
|
500
|
+
TC_ulong,
|
|
501
|
+
TC_float,
|
|
502
|
+
TC_double,
|
|
503
|
+
TC_boolean,
|
|
504
|
+
TC_char,
|
|
505
|
+
TC_octet,
|
|
506
|
+
TC_any,
|
|
507
|
+
TC_TypeCode,
|
|
508
|
+
TC_Principal,
|
|
509
|
+
TC_longlong,
|
|
510
|
+
TC_ulonglong,
|
|
511
|
+
TC_longdouble,
|
|
512
|
+
TC_wchar,
|
|
513
|
+
)
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
# ---------------------------------------------------------------------------
|
|
517
|
+
# Any
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
class Any(object):
|
|
521
|
+
"""A value with its TypeCode: ``CORBA.Any(CORBA.TC_long, 1)``."""
|
|
522
|
+
|
|
523
|
+
def __init__(self, typecode, value):
|
|
524
|
+
self._t = typecode
|
|
525
|
+
self._v = value
|
|
526
|
+
|
|
527
|
+
def typecode(self):
|
|
528
|
+
return self._t
|
|
529
|
+
|
|
530
|
+
def value(self):
|
|
531
|
+
return self._v
|
|
532
|
+
|
|
533
|
+
def __repr__(self):
|
|
534
|
+
return "CORBA.Any(%r, %r)" % (self._t, self._v)
|
|
535
|
+
|
|
536
|
+
def __eq__(self, other):
|
|
537
|
+
return isinstance(other, Any) and self._t.equal(other._t) and self._v == other._v
|
|
538
|
+
|
|
539
|
+
def __ne__(self, other):
|
|
540
|
+
return not self.__eq__(other)
|
|
541
|
+
|
|
542
|
+
__hash__ = None # type: ignore[assignment]
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
# ---------------------------------------------------------------------------
|
|
546
|
+
# Fixed point
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
class fixed(object):
|
|
550
|
+
"""An IDL ``fixed`` value: ``CORBA.fixed("12.50")``.
|
|
551
|
+
|
|
552
|
+
The value is kept without trailing zeros after the point
|
|
553
|
+
(``fixed("12.50")`` has 3 digits and scale 1). ``value()`` is the value
|
|
554
|
+
as an integer scaled by ``10 ** decimals()``.
|
|
555
|
+
"""
|
|
556
|
+
|
|
557
|
+
__slots__ = ("_d",)
|
|
558
|
+
|
|
559
|
+
def __init__(self, value):
|
|
560
|
+
d = _decimal.Decimal(str(value) if not isinstance(value, _decimal.Decimal) else value)
|
|
561
|
+
# The default context rounds to 28 digits; a fixed has up to 31.
|
|
562
|
+
with _decimal.localcontext() as ctx:
|
|
563
|
+
ctx.prec = 64
|
|
564
|
+
if d == d.to_integral_value():
|
|
565
|
+
d = d.quantize(_decimal.Decimal(1))
|
|
566
|
+
else:
|
|
567
|
+
d = d.normalize()
|
|
568
|
+
self._d = d
|
|
569
|
+
|
|
570
|
+
def precision(self):
|
|
571
|
+
t = self._d.as_tuple()
|
|
572
|
+
return max(len(t.digits) + max(0, t.exponent), self.decimals())
|
|
573
|
+
|
|
574
|
+
def decimals(self):
|
|
575
|
+
return max(0, -self._d.as_tuple().exponent)
|
|
576
|
+
|
|
577
|
+
def value(self):
|
|
578
|
+
with _decimal.localcontext() as ctx:
|
|
579
|
+
ctx.prec = 64
|
|
580
|
+
return int(self._d.scaleb(self.decimals()))
|
|
581
|
+
|
|
582
|
+
def __repr__(self):
|
|
583
|
+
return 'fixed("%s")' % self
|
|
584
|
+
|
|
585
|
+
def __str__(self):
|
|
586
|
+
return str(self._d)
|
|
587
|
+
|
|
588
|
+
def __eq__(self, other):
|
|
589
|
+
if isinstance(other, fixed):
|
|
590
|
+
return self._d == other._d
|
|
591
|
+
return self._d == other
|
|
592
|
+
|
|
593
|
+
def __ne__(self, other):
|
|
594
|
+
return not self.__eq__(other)
|
|
595
|
+
|
|
596
|
+
def __hash__(self):
|
|
597
|
+
return hash(self._d)
|
|
598
|
+
|
|
599
|
+
def __float__(self):
|
|
600
|
+
return float(self._d)
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
# ---------------------------------------------------------------------------
|
|
604
|
+
# Object references
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
class ValueBase(object):
|
|
608
|
+
"""Base class of the classes of valuetypes.
|
|
609
|
+
|
|
610
|
+
``_NP_members`` names the state members, those of the base valuetypes
|
|
611
|
+
first. An instance is made with all of them, by position or by name,
|
|
612
|
+
or with none, to set afterwards (as value factories do).
|
|
613
|
+
"""
|
|
614
|
+
|
|
615
|
+
_NP_RepositoryId = "IDL:omg.org/CORBA/ValueBase:1.0"
|
|
616
|
+
_NP_members: tuple = ()
|
|
617
|
+
|
|
618
|
+
def __init__(self, *args, **kw):
|
|
619
|
+
if not args and not kw:
|
|
620
|
+
return
|
|
621
|
+
names = self._NP_members
|
|
622
|
+
if len(args) > len(names):
|
|
623
|
+
raise TypeError(
|
|
624
|
+
"%s takes %d state members, not %d" % (type(self).__name__, len(names), len(args))
|
|
625
|
+
)
|
|
626
|
+
values = dict(zip(names, args))
|
|
627
|
+
for k, v in kw.items():
|
|
628
|
+
if k not in names or k in values:
|
|
629
|
+
raise TypeError("%s: unexpected or repeated member %r" % (type(self).__name__, k))
|
|
630
|
+
values[k] = v
|
|
631
|
+
if len(values) != len(names):
|
|
632
|
+
missing = [n for n in names if n not in values]
|
|
633
|
+
raise TypeError("%s: missing members %s" % (type(self).__name__, ", ".join(missing)))
|
|
634
|
+
for k, v in values.items():
|
|
635
|
+
setattr(self, k, v)
|
|
636
|
+
|
|
637
|
+
@_reprlib.recursive_repr()
|
|
638
|
+
def __repr__(self):
|
|
639
|
+
return "%s(%s)" % (
|
|
640
|
+
type(self).__name__,
|
|
641
|
+
", ".join("%s=%r" % (n, getattr(self, n, None)) for n in self._NP_members),
|
|
642
|
+
)
|
|
643
|
+
|
|
644
|
+
|
|
645
|
+
TC_ValueBase = TypeCode(tk_value, ValueBase._NP_RepositoryId, "ValueBase", members=[], cls=ValueBase)
|
|
646
|
+
_tc_ValueBase = TC_ValueBase
|
|
647
|
+
# Any abstract interface: a reference or a value.
|
|
648
|
+
TC_AbstractBase = TypeCode(tk_abstract_interface, "IDL:omg.org/CORBA/AbstractBase:1.0", "AbstractBase")
|
|
649
|
+
_tc_AbstractBase = TC_AbstractBase
|
|
650
|
+
|
|
651
|
+
|
|
652
|
+
class CustomMarshal(object):
|
|
653
|
+
"""Base class of the classes of custom valuetypes (``custom
|
|
654
|
+
valuetype``): the implementation writes the state of an instance in
|
|
655
|
+
:meth:`marshal` and reads it back in :meth:`unmarshal`, in the same
|
|
656
|
+
order. A value factory registered for the type makes the instances
|
|
657
|
+
to unmarshal."""
|
|
658
|
+
|
|
659
|
+
def marshal(self, os):
|
|
660
|
+
"""Write the state to ``os``, a :class:`DataOutputStream`."""
|
|
661
|
+
raise NO_IMPLEMENT(0, COMPLETED_NO)
|
|
662
|
+
|
|
663
|
+
def unmarshal(self, is_):
|
|
664
|
+
"""Read the state from ``is_``, a :class:`DataInputStream`."""
|
|
665
|
+
raise NO_IMPLEMENT(0, COMPLETED_NO)
|
|
666
|
+
|
|
667
|
+
|
|
668
|
+
def _data_types():
|
|
669
|
+
return [
|
|
670
|
+
("any", TC_any),
|
|
671
|
+
("boolean", TC_boolean),
|
|
672
|
+
("char", TC_char),
|
|
673
|
+
("wchar", TC_wchar),
|
|
674
|
+
("octet", TC_octet),
|
|
675
|
+
("short", TC_short),
|
|
676
|
+
("ushort", TC_ushort),
|
|
677
|
+
("long", TC_long),
|
|
678
|
+
("ulong", TC_ulong),
|
|
679
|
+
("longlong", TC_longlong),
|
|
680
|
+
("ulonglong", TC_ulonglong),
|
|
681
|
+
("float", TC_float),
|
|
682
|
+
("double", TC_double),
|
|
683
|
+
("longdouble", TC_longdouble),
|
|
684
|
+
]
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
class DataOutputStream(object):
|
|
688
|
+
"""What :meth:`CustomMarshal.marshal` writes to (``CORBA::
|
|
689
|
+
DataOutputStream``): each ``write_<type>`` writes one item as CDR, and
|
|
690
|
+
``write_<type>_array(seq, offset, length)`` writes ``length`` elements
|
|
691
|
+
of ``seq`` from ``offset``, without a length. Values written with
|
|
692
|
+
:meth:`write_Value` keep their sharing with the rest of the message."""
|
|
693
|
+
|
|
694
|
+
def __init__(self):
|
|
695
|
+
#: [(TypeCode, value)] written so far.
|
|
696
|
+
self._items = []
|
|
697
|
+
|
|
698
|
+
def _write(self, tc, value):
|
|
699
|
+
self._items.append((tc, value))
|
|
700
|
+
|
|
701
|
+
def _write_array(self, tc, seq, offset, length):
|
|
702
|
+
if offset < 0 or length < 0 or offset + length > len(seq):
|
|
703
|
+
raise BAD_PARAM(0, COMPLETED_NO)
|
|
704
|
+
for v in seq[offset:offset + length]:
|
|
705
|
+
self._write(tc, v)
|
|
706
|
+
|
|
707
|
+
def write_string(self, value):
|
|
708
|
+
self._write(TC_string, value)
|
|
709
|
+
|
|
710
|
+
def write_wstring(self, value):
|
|
711
|
+
self._write(TC_wstring, value)
|
|
712
|
+
|
|
713
|
+
def write_Object(self, value):
|
|
714
|
+
self._write(TC_Object, value)
|
|
715
|
+
|
|
716
|
+
def write_Value(self, value):
|
|
717
|
+
self._write(TC_ValueBase, value)
|
|
718
|
+
|
|
719
|
+
def write_Abstract(self, value):
|
|
720
|
+
self._write(TC_AbstractBase, value)
|
|
721
|
+
|
|
722
|
+
def write_TypeCode(self, value):
|
|
723
|
+
self._write(TC_TypeCode, value)
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
class DataInputStream(object):
|
|
727
|
+
"""What :meth:`CustomMarshal.unmarshal` reads from (``CORBA::
|
|
728
|
+
DataInputStream``): each ``read_<type>()`` reads one item, and
|
|
729
|
+
``read_<type>_array(seq, offset, length)`` reads ``length`` elements
|
|
730
|
+
into ``seq`` from ``offset`` and returns the sequence (``seq`` is an
|
|
731
|
+
inout parameter)."""
|
|
732
|
+
|
|
733
|
+
def __init__(self, native):
|
|
734
|
+
self._n = native
|
|
735
|
+
|
|
736
|
+
def _read_array(self, tc, seq, offset, length):
|
|
737
|
+
if offset < 0 or length < 0:
|
|
738
|
+
raise BAD_PARAM(0, COMPLETED_NO)
|
|
739
|
+
values = [self._n.read(tc) for _ in range(length)]
|
|
740
|
+
if isinstance(seq, (bytes, str)):
|
|
741
|
+
join = bytes(values) if isinstance(seq, bytes) else "".join(values)
|
|
742
|
+
pad = seq[:0] + (b"\0" if isinstance(seq, bytes) else "\0") * max(0, offset - len(seq))
|
|
743
|
+
return seq[:offset] + pad + join + seq[offset + length:]
|
|
744
|
+
seq = list(seq)
|
|
745
|
+
if len(seq) < offset:
|
|
746
|
+
seq.extend([None] * (offset - len(seq)))
|
|
747
|
+
seq[offset:offset + length] = values
|
|
748
|
+
return seq
|
|
749
|
+
|
|
750
|
+
def read_string(self):
|
|
751
|
+
return self._n.read(TC_string)
|
|
752
|
+
|
|
753
|
+
def read_wstring(self):
|
|
754
|
+
return self._n.read(TC_wstring)
|
|
755
|
+
|
|
756
|
+
def read_Object(self):
|
|
757
|
+
return self._n.read(TC_Object)
|
|
758
|
+
|
|
759
|
+
def read_Value(self):
|
|
760
|
+
return self._n.read(TC_ValueBase)
|
|
761
|
+
|
|
762
|
+
def read_Abstract(self):
|
|
763
|
+
return self._n.read(TC_AbstractBase)
|
|
764
|
+
|
|
765
|
+
def read_TypeCode(self):
|
|
766
|
+
return self._n.read(TC_TypeCode)
|
|
767
|
+
|
|
768
|
+
|
|
769
|
+
def _data_methods():
|
|
770
|
+
def writer(tc):
|
|
771
|
+
return lambda self, value: self._write(tc, value)
|
|
772
|
+
|
|
773
|
+
def array_writer(tc):
|
|
774
|
+
return lambda self, seq, offset, length: self._write_array(tc, seq, offset, length)
|
|
775
|
+
|
|
776
|
+
def reader(tc):
|
|
777
|
+
return lambda self: self._n.read(tc)
|
|
778
|
+
|
|
779
|
+
def array_reader(tc):
|
|
780
|
+
return lambda self, seq, offset, length: self._read_array(tc, seq, offset, length)
|
|
781
|
+
|
|
782
|
+
for name, tc in _data_types():
|
|
783
|
+
setattr(DataOutputStream, "write_" + name, writer(tc))
|
|
784
|
+
setattr(DataOutputStream, "write_%s_array" % name, array_writer(tc))
|
|
785
|
+
setattr(DataInputStream, "read_" + name, reader(tc))
|
|
786
|
+
setattr(DataInputStream, "read_%s_array" % name, array_reader(tc))
|
|
787
|
+
|
|
788
|
+
|
|
789
|
+
_data_methods()
|
|
790
|
+
|
|
791
|
+
|
|
792
|
+
class Object(object):
|
|
793
|
+
"""Base of object references. A nil reference is ``None``.
|
|
794
|
+
|
|
795
|
+
References are made by the ORB; the stub classes generated from IDL
|
|
796
|
+
derive from this class.
|
|
797
|
+
"""
|
|
798
|
+
|
|
799
|
+
_NP_RepositoryId = "IDL:omg.org/CORBA/Object:1.0"
|
|
800
|
+
#: The nil reference, as for the interface classes of generated code.
|
|
801
|
+
_nil = None
|
|
802
|
+
|
|
803
|
+
def __init__(self, obj=None):
|
|
804
|
+
self._obj = obj
|
|
805
|
+
|
|
806
|
+
def _orb_object(self):
|
|
807
|
+
if self._obj is None:
|
|
808
|
+
raise NO_IMPLEMENT(0, COMPLETED_NO)
|
|
809
|
+
return self._obj
|
|
810
|
+
|
|
811
|
+
def _invoke(self, op, args):
|
|
812
|
+
"""Call operation ``op`` (an ``Operation`` of the generated code)."""
|
|
813
|
+
return self._orb_object().invoke(op, args)
|
|
814
|
+
|
|
815
|
+
def _is_a(self, repoId):
|
|
816
|
+
return self._orb_object().is_a(repoId)
|
|
817
|
+
|
|
818
|
+
def _non_existent(self):
|
|
819
|
+
return self._orb_object().non_existent()
|
|
820
|
+
|
|
821
|
+
def _is_equivalent(self, other):
|
|
822
|
+
if other is None:
|
|
823
|
+
return False
|
|
824
|
+
return self._orb_object().is_equivalent(other._orb_object())
|
|
825
|
+
|
|
826
|
+
def _hash(self, maximum):
|
|
827
|
+
return self._orb_object().hash(maximum)
|
|
828
|
+
|
|
829
|
+
def _duplicate(self, obj=None):
|
|
830
|
+
return self
|
|
831
|
+
|
|
832
|
+
def _release(self):
|
|
833
|
+
pass
|
|
834
|
+
|
|
835
|
+
def _narrow(self, cls):
|
|
836
|
+
"""This reference as an instance of the stub class of ``cls`` (an
|
|
837
|
+
interface class of generated code), or None if the object does not
|
|
838
|
+
have that interface."""
|
|
839
|
+
from . import _rt
|
|
840
|
+
|
|
841
|
+
return _rt.narrow(self, cls)
|
|
842
|
+
|
|
843
|
+
def _unchecked_narrow(self, cls):
|
|
844
|
+
from . import _rt
|
|
845
|
+
|
|
846
|
+
return _rt.narrow(self, cls, checked=False)
|
|
847
|
+
|
|
848
|
+
def _get_interface(self):
|
|
849
|
+
raise NO_IMPLEMENT(0, COMPLETED_NO)
|
|
850
|
+
|
|
851
|
+
# -- the DII --
|
|
852
|
+
|
|
853
|
+
def _request(self, operation):
|
|
854
|
+
"""A ``CORBA.Request`` for ``operation``, with no arguments and a
|
|
855
|
+
``void`` result."""
|
|
856
|
+
return Request(self, operation)
|
|
857
|
+
|
|
858
|
+
def _create_request(self, ctx, operation, arg_list, result, exceptions=None, ctxlist=None, req_flags=0):
|
|
859
|
+
"""``create_request``: a ``CORBA.Request`` for ``operation`` with
|
|
860
|
+
the arguments ``arg_list`` (an NVList, or None), the result
|
|
861
|
+
``result`` (a NamedValue, or None for ``void``) and the user
|
|
862
|
+
exceptions ``exceptions`` (TypeCodes). Contexts are not supported:
|
|
863
|
+
``ctx`` and ``ctxlist`` must be None."""
|
|
864
|
+
if ctx is not None or ctxlist:
|
|
865
|
+
raise NO_IMPLEMENT(0, COMPLETED_NO)
|
|
866
|
+
return Request(self, operation, arg_list, result, exceptions or ())
|
|
867
|
+
|
|
868
|
+
# -- policies --
|
|
869
|
+
|
|
870
|
+
def _get_client_policy(self, type):
|
|
871
|
+
"""The policy of type ``type`` for calls on this reference: the
|
|
872
|
+
reference's override, else the calling thread's, else the ORB's;
|
|
873
|
+
None if there is none."""
|
|
874
|
+
value = self._orb_object().client_policy(type)
|
|
875
|
+
return None if value is None else _make_policy(type, value)
|
|
876
|
+
|
|
877
|
+
#: rustorb reads no policies from IORs: the effective policy is the
|
|
878
|
+
#: client's.
|
|
879
|
+
_get_policy = _get_client_policy
|
|
880
|
+
|
|
881
|
+
def _set_policy_overrides(self, policies, set_add):
|
|
882
|
+
"""A new reference to the object with the overrides ``policies``
|
|
883
|
+
(``SET_OVERRIDE`` replaces this reference's, ``ADD_OVERRIDE`` adds
|
|
884
|
+
to them). NO_PERMISSION for a policy that cannot override, such as
|
|
885
|
+
a POA policy."""
|
|
886
|
+
native = self._orb_object().set_policy_overrides(
|
|
887
|
+
_raw_policies(policies), _override_mode(set_add)
|
|
888
|
+
)
|
|
889
|
+
return type(self)(native)
|
|
890
|
+
|
|
891
|
+
def _get_policy_overrides(self, types):
|
|
892
|
+
return [_make_policy(t, v) for t, v in self._orb_object().policy_overrides(list(types))]
|
|
893
|
+
|
|
894
|
+
def _validate_connection(self):
|
|
895
|
+
"""Binds the reference with a LocateRequest: ``(True, [])``, or the
|
|
896
|
+
system exception of the failure."""
|
|
897
|
+
return self._orb_object().validate_connection(), []
|
|
898
|
+
|
|
899
|
+
def __repr__(self):
|
|
900
|
+
return "<%s.%s %s>" % (
|
|
901
|
+
type(self).__module__,
|
|
902
|
+
type(self).__name__,
|
|
903
|
+
"nil" if self._obj is None else repr(self._obj.type_id()),
|
|
904
|
+
)
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
def is_nil(obj):
|
|
908
|
+
return obj is None
|
|
909
|
+
|
|
910
|
+
|
|
911
|
+
# ---------------------------------------------------------------------------
|
|
912
|
+
# The DII and the DSI
|
|
913
|
+
|
|
914
|
+
#: The modes of an argument (``CORBA::Flags``).
|
|
915
|
+
ARG_IN = 1
|
|
916
|
+
ARG_OUT = 2
|
|
917
|
+
ARG_INOUT = 3
|
|
918
|
+
|
|
919
|
+
|
|
920
|
+
class NamedValue(object):
|
|
921
|
+
"""``CORBA::NamedValue``: an argument's ``name``, value (``argument``,
|
|
922
|
+
a ``CORBA.Any``) and mode (``arg_modes``, ``ARG_IN``...). The Any of an
|
|
923
|
+
``out`` argument gives its type; its value comes with the reply."""
|
|
924
|
+
|
|
925
|
+
def __init__(self, name, argument, arg_modes):
|
|
926
|
+
self.name = name
|
|
927
|
+
self.argument = argument
|
|
928
|
+
self.arg_modes = arg_modes
|
|
929
|
+
|
|
930
|
+
def __repr__(self):
|
|
931
|
+
return "CORBA.NamedValue(%r, %r, %r)" % (self.name, self.argument, self.arg_modes)
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
class NVList(object):
|
|
935
|
+
"""``CORBA::NVList``, a list of named values."""
|
|
936
|
+
|
|
937
|
+
def __init__(self, items=()):
|
|
938
|
+
self._items = list(items)
|
|
939
|
+
|
|
940
|
+
def count(self):
|
|
941
|
+
return len(self._items)
|
|
942
|
+
|
|
943
|
+
def add(self, flags):
|
|
944
|
+
return self.add_item("", flags)
|
|
945
|
+
|
|
946
|
+
def add_item(self, item_name, flags):
|
|
947
|
+
nv = NamedValue(item_name, Any(TC_null, None), flags)
|
|
948
|
+
self._items.append(nv)
|
|
949
|
+
return nv
|
|
950
|
+
|
|
951
|
+
def add_value(self, item_name, value, flags):
|
|
952
|
+
nv = NamedValue(item_name, value, flags)
|
|
953
|
+
self._items.append(nv)
|
|
954
|
+
return nv
|
|
955
|
+
|
|
956
|
+
def item(self, index):
|
|
957
|
+
try:
|
|
958
|
+
return self._items[index]
|
|
959
|
+
except IndexError:
|
|
960
|
+
raise Bounds()
|
|
961
|
+
|
|
962
|
+
def remove(self, index):
|
|
963
|
+
try:
|
|
964
|
+
del self._items[index]
|
|
965
|
+
except IndexError:
|
|
966
|
+
raise Bounds()
|
|
967
|
+
|
|
968
|
+
def __len__(self):
|
|
969
|
+
return len(self._items)
|
|
970
|
+
|
|
971
|
+
def __iter__(self):
|
|
972
|
+
return iter(self._items)
|
|
973
|
+
|
|
974
|
+
def __getitem__(self, index):
|
|
975
|
+
return self._items[index]
|
|
976
|
+
|
|
977
|
+
def _modes(self):
|
|
978
|
+
for nv in self._items:
|
|
979
|
+
if nv.arg_modes & 3 not in (ARG_IN, ARG_OUT, ARG_INOUT):
|
|
980
|
+
raise BAD_PARAM(0, COMPLETED_NO)
|
|
981
|
+
|
|
982
|
+
|
|
983
|
+
class Bounds(UserException):
|
|
984
|
+
_NP_RepositoryId = "IDL:omg.org/CORBA/Bounds:1.0"
|
|
985
|
+
|
|
986
|
+
|
|
987
|
+
class Request(object):
|
|
988
|
+
"""``CORBA::Request``: a call built at run time (the DII), from
|
|
989
|
+
``obj._request(operation)`` or ``obj._create_request(...)``.
|
|
990
|
+
|
|
991
|
+
Arguments are added with ``add_in_arg(value)``, ``add_inout_arg(value)``
|
|
992
|
+
(``CORBA.Any`` values) and ``add_out_arg(tc)``, or are the NVList given to
|
|
993
|
+
``_create_request``; ``set_return_type(tc)`` gives the result type
|
|
994
|
+
(``void`` by default) and ``add_exception(tc)`` the user exceptions it
|
|
995
|
+
may raise. After ``invoke()`` (or ``send_deferred()`` and
|
|
996
|
+
``get_response()``) the ``out`` and ``inout`` arguments hold the
|
|
997
|
+
values sent back and ``return_value()`` the result. A listed user
|
|
998
|
+
exception is raised; an unlisted one is ``UNKNOWN``.
|
|
999
|
+
"""
|
|
1000
|
+
|
|
1001
|
+
def __init__(self, target, operation, arguments=None, result=None, exceptions=()):
|
|
1002
|
+
self._target = target
|
|
1003
|
+
self._operation = operation
|
|
1004
|
+
self._arguments = arguments if arguments is not None else NVList()
|
|
1005
|
+
self._result = result if result is not None else NamedValue("", Any(TC_void, None), 0)
|
|
1006
|
+
self._exceptions = list(exceptions)
|
|
1007
|
+
self._native = _native_module().Request(target._orb_object(), operation)
|
|
1008
|
+
|
|
1009
|
+
def target(self):
|
|
1010
|
+
return self._target
|
|
1011
|
+
|
|
1012
|
+
def operation(self):
|
|
1013
|
+
return self._operation
|
|
1014
|
+
|
|
1015
|
+
def arguments(self):
|
|
1016
|
+
return self._arguments
|
|
1017
|
+
|
|
1018
|
+
def result(self):
|
|
1019
|
+
return self._result
|
|
1020
|
+
|
|
1021
|
+
def exceptions(self):
|
|
1022
|
+
return list(self._exceptions)
|
|
1023
|
+
|
|
1024
|
+
def ctx(self, *args):
|
|
1025
|
+
raise NO_IMPLEMENT(0, COMPLETED_NO)
|
|
1026
|
+
|
|
1027
|
+
contexts = ctx
|
|
1028
|
+
|
|
1029
|
+
def add_in_arg(self, value, name=""):
|
|
1030
|
+
self._arguments.add_value(name, value, ARG_IN)
|
|
1031
|
+
|
|
1032
|
+
def add_inout_arg(self, value, name=""):
|
|
1033
|
+
self._arguments.add_value(name, value, ARG_INOUT)
|
|
1034
|
+
|
|
1035
|
+
def add_out_arg(self, tc, name=""):
|
|
1036
|
+
self._arguments.add_value(name, Any(tc, None), ARG_OUT)
|
|
1037
|
+
|
|
1038
|
+
def set_return_type(self, tc):
|
|
1039
|
+
self._result.argument = Any(tc, None)
|
|
1040
|
+
|
|
1041
|
+
def add_exception(self, tc):
|
|
1042
|
+
self._exceptions.append(tc)
|
|
1043
|
+
|
|
1044
|
+
def return_value(self):
|
|
1045
|
+
return self._result.argument
|
|
1046
|
+
|
|
1047
|
+
def _call_args(self):
|
|
1048
|
+
self._arguments._modes()
|
|
1049
|
+
return (
|
|
1050
|
+
[(nv.name, nv.argument, nv.arg_modes & 3) for nv in self._arguments],
|
|
1051
|
+
self._result.argument.typecode(),
|
|
1052
|
+
list(self._exceptions),
|
|
1053
|
+
)
|
|
1054
|
+
|
|
1055
|
+
def _collect(self, outputs):
|
|
1056
|
+
result, values = outputs
|
|
1057
|
+
for nv, value in zip(self._arguments, values):
|
|
1058
|
+
if nv.arg_modes & 3 != ARG_IN and value is not None:
|
|
1059
|
+
nv.argument = value
|
|
1060
|
+
self._result.argument = result
|
|
1061
|
+
|
|
1062
|
+
def _new_native(self):
|
|
1063
|
+
# A new native request for each call: the exception list may grow.
|
|
1064
|
+
self._native = _native_module().Request(self._target._orb_object(), self._operation)
|
|
1065
|
+
return self._native
|
|
1066
|
+
|
|
1067
|
+
def invoke(self, invoke_flags=0):
|
|
1068
|
+
self._collect(self._new_native().invoke(*self._call_args()))
|
|
1069
|
+
|
|
1070
|
+
def send_oneway(self):
|
|
1071
|
+
self._new_native().send_oneway(*self._call_args())
|
|
1072
|
+
|
|
1073
|
+
def send_deferred(self):
|
|
1074
|
+
self._new_native().send_deferred(*self._call_args())
|
|
1075
|
+
|
|
1076
|
+
def send(self, invoke_flags=0):
|
|
1077
|
+
self.send_deferred()
|
|
1078
|
+
|
|
1079
|
+
def poll_response(self):
|
|
1080
|
+
return self._native.poll_response()
|
|
1081
|
+
|
|
1082
|
+
def get_response(self, response_flags=0):
|
|
1083
|
+
self._collect(self._native.get_response())
|
|
1084
|
+
|
|
1085
|
+
|
|
1086
|
+
class ServerRequest(object):
|
|
1087
|
+
"""``CORBA::ServerRequest``: a request to a
|
|
1088
|
+
``PortableServer.DynamicImplementation``, given to its ``invoke``.
|
|
1089
|
+
|
|
1090
|
+
``arguments(nvlist)`` reads the ``in`` and ``inout`` arguments into the
|
|
1091
|
+
NVList, whose TypeCodes and modes describe the parameters (the Anys'
|
|
1092
|
+
values are ignored). The servant then sets the ``argument`` of the
|
|
1093
|
+
``out`` and ``inout`` items, and calls ``set_result(any)`` or
|
|
1094
|
+
``set_exception(any)`` (an Any of a user exception). A system
|
|
1095
|
+
exception is raised from ``invoke``.
|
|
1096
|
+
"""
|
|
1097
|
+
|
|
1098
|
+
def __init__(self, native):
|
|
1099
|
+
self._native = native
|
|
1100
|
+
self._params = None
|
|
1101
|
+
self._raised = False
|
|
1102
|
+
|
|
1103
|
+
def operation(self):
|
|
1104
|
+
return self._native.operation()
|
|
1105
|
+
|
|
1106
|
+
def arguments(self, nvlist):
|
|
1107
|
+
if self._params is not None:
|
|
1108
|
+
raise BAD_INV_ORDER(0, COMPLETED_NO)
|
|
1109
|
+
nvlist._modes()
|
|
1110
|
+
values = self._native.arguments(
|
|
1111
|
+
[(nv.name, nv.argument.typecode(), nv.arg_modes & 3) for nv in nvlist]
|
|
1112
|
+
)
|
|
1113
|
+
self._unset = []
|
|
1114
|
+
for nv, value in zip(nvlist, values):
|
|
1115
|
+
if value is not None:
|
|
1116
|
+
nv.argument = value
|
|
1117
|
+
self._unset.append(nv.argument if value is None else None)
|
|
1118
|
+
self._params = nvlist
|
|
1119
|
+
return nvlist
|
|
1120
|
+
|
|
1121
|
+
def set_result(self, value):
|
|
1122
|
+
self._native.set_result(value)
|
|
1123
|
+
|
|
1124
|
+
def set_exception(self, value):
|
|
1125
|
+
self._native.set_exception(value)
|
|
1126
|
+
self._raised = True
|
|
1127
|
+
|
|
1128
|
+
def ctx(self):
|
|
1129
|
+
raise NO_IMPLEMENT(0, COMPLETED_NO)
|
|
1130
|
+
|
|
1131
|
+
def _NP_finish(self):
|
|
1132
|
+
if self._params is None or self._raised:
|
|
1133
|
+
return
|
|
1134
|
+
# An out argument the servant did not set (still the Any given to
|
|
1135
|
+
# arguments()) is left so: the reply then fails with BAD_PARAM.
|
|
1136
|
+
self._native.set_out_values(
|
|
1137
|
+
[
|
|
1138
|
+
None if nv.arg_modes & 3 == ARG_IN or nv.argument is unset else nv.argument
|
|
1139
|
+
for nv, unset in zip(self._params, self._unset)
|
|
1140
|
+
]
|
|
1141
|
+
)
|
|
1142
|
+
|
|
1143
|
+
|
|
1144
|
+
class LocalObject(Object):
|
|
1145
|
+
"""Base of local objects (the POA, its manager, policies): they live in
|
|
1146
|
+
this process only and have no IOR."""
|
|
1147
|
+
|
|
1148
|
+
def _is_a(self, repoId):
|
|
1149
|
+
return repoId == "IDL:omg.org/CORBA/Object:1.0" or any(
|
|
1150
|
+
getattr(c, "_NP_RepositoryId", None) == repoId for c in type(self).__mro__
|
|
1151
|
+
)
|
|
1152
|
+
|
|
1153
|
+
def _non_existent(self):
|
|
1154
|
+
return False
|
|
1155
|
+
|
|
1156
|
+
def _is_equivalent(self, other):
|
|
1157
|
+
return self is other
|
|
1158
|
+
|
|
1159
|
+
def _hash(self, maximum):
|
|
1160
|
+
return hash(self) % maximum
|
|
1161
|
+
|
|
1162
|
+
def _narrow(self, cls):
|
|
1163
|
+
return self if isinstance(self, cls) else None
|
|
1164
|
+
|
|
1165
|
+
_unchecked_narrow = _narrow
|
|
1166
|
+
|
|
1167
|
+
|
|
1168
|
+
class Policy(LocalObject):
|
|
1169
|
+
"""``CORBA::Policy``. The POA's ``create_*_policy`` operations make
|
|
1170
|
+
them; ``value`` is the enumerator of the policy value."""
|
|
1171
|
+
|
|
1172
|
+
_NP_RepositoryId = "IDL:omg.org/CORBA/Policy:1.0"
|
|
1173
|
+
policy_type = 0
|
|
1174
|
+
|
|
1175
|
+
def __init__(self, value):
|
|
1176
|
+
LocalObject.__init__(self)
|
|
1177
|
+
self.value = value
|
|
1178
|
+
|
|
1179
|
+
def _get_policy_type(self):
|
|
1180
|
+
return self.policy_type
|
|
1181
|
+
|
|
1182
|
+
def _get_value(self):
|
|
1183
|
+
return self.value
|
|
1184
|
+
|
|
1185
|
+
def copy(self):
|
|
1186
|
+
return type(self)(self.value)
|
|
1187
|
+
|
|
1188
|
+
def destroy(self):
|
|
1189
|
+
pass
|
|
1190
|
+
|
|
1191
|
+
def _rorb_raw(self):
|
|
1192
|
+
"""The type and value of the policy for the native module."""
|
|
1193
|
+
return self.policy_type, int(self.value)
|
|
1194
|
+
|
|
1195
|
+
|
|
1196
|
+
#: CORBA::PolicyErrorCode
|
|
1197
|
+
BAD_POLICY = 0
|
|
1198
|
+
UNSUPPORTED_POLICY = 1
|
|
1199
|
+
BAD_POLICY_TYPE = 2
|
|
1200
|
+
BAD_POLICY_VALUE = 3
|
|
1201
|
+
UNSUPPORTED_POLICY_VALUE = 4
|
|
1202
|
+
|
|
1203
|
+
|
|
1204
|
+
class PolicyError(UserException):
|
|
1205
|
+
_NP_RepositoryId = "IDL:omg.org/CORBA/PolicyError:1.0"
|
|
1206
|
+
_NP_members = ("reason",)
|
|
1207
|
+
|
|
1208
|
+
|
|
1209
|
+
class InvalidPolicies(UserException):
|
|
1210
|
+
_NP_RepositoryId = "IDL:omg.org/CORBA/InvalidPolicies:1.0"
|
|
1211
|
+
_NP_members = ("indices",)
|
|
1212
|
+
|
|
1213
|
+
|
|
1214
|
+
_override = _types.Enum("IDL:omg.org/CORBA/SetOverrideType:1.0", ("SET_OVERRIDE", "ADD_OVERRIDE"))
|
|
1215
|
+
SetOverrideType = _override
|
|
1216
|
+
SET_OVERRIDE, ADD_OVERRIDE = _override._items
|
|
1217
|
+
|
|
1218
|
+
|
|
1219
|
+
def _override_mode(set_add):
|
|
1220
|
+
"""True for ADD_OVERRIDE."""
|
|
1221
|
+
if set_add is ADD_OVERRIDE:
|
|
1222
|
+
return True
|
|
1223
|
+
if set_add is SET_OVERRIDE:
|
|
1224
|
+
return False
|
|
1225
|
+
raise BAD_PARAM(0, COMPLETED_NO)
|
|
1226
|
+
|
|
1227
|
+
|
|
1228
|
+
def _raw_policies(policies):
|
|
1229
|
+
raw = []
|
|
1230
|
+
for p in policies:
|
|
1231
|
+
if not isinstance(p, Policy):
|
|
1232
|
+
raise BAD_PARAM(0, COMPLETED_NO)
|
|
1233
|
+
raw.append(p._rorb_raw())
|
|
1234
|
+
return raw
|
|
1235
|
+
|
|
1236
|
+
|
|
1237
|
+
def _make_policy(type, value):
|
|
1238
|
+
"""The policy object of a type and value from the native module."""
|
|
1239
|
+
if type == 32:
|
|
1240
|
+
from . import Messaging
|
|
1241
|
+
|
|
1242
|
+
return Messaging.RelativeRoundtripTimeoutPolicy(value)
|
|
1243
|
+
from . import PortableServer
|
|
1244
|
+
|
|
1245
|
+
return PortableServer._make_policy(type, value)
|
|
1246
|
+
|
|
1247
|
+
|
|
1248
|
+
def _native_module():
|
|
1249
|
+
if _native is None:
|
|
1250
|
+
raise INITIALIZE(0, COMPLETED_NO)
|
|
1251
|
+
return _native
|
|
1252
|
+
|
|
1253
|
+
|
|
1254
|
+
class PolicyManager(LocalObject):
|
|
1255
|
+
"""The policy overrides of the ORB (initial reference
|
|
1256
|
+
``ORBPolicyManager``). ``set_policy_overrides`` raises NO_PERMISSION
|
|
1257
|
+
for a policy that cannot override, BAD_PARAM for two of one type."""
|
|
1258
|
+
|
|
1259
|
+
_NP_RepositoryId = "IDL:omg.org/CORBA/PolicyManager:1.0"
|
|
1260
|
+
|
|
1261
|
+
def __init__(self, native):
|
|
1262
|
+
LocalObject.__init__(self)
|
|
1263
|
+
self._native = native
|
|
1264
|
+
|
|
1265
|
+
def get_policy_overrides(self, ts):
|
|
1266
|
+
return [_make_policy(t, v) for t, v in self._native.policy_overrides(list(ts))]
|
|
1267
|
+
|
|
1268
|
+
def set_policy_overrides(self, policies, set_add):
|
|
1269
|
+
self._native.set_policy_overrides(_raw_policies(policies), _override_mode(set_add))
|
|
1270
|
+
|
|
1271
|
+
|
|
1272
|
+
class Current(LocalObject):
|
|
1273
|
+
_NP_RepositoryId = "IDL:omg.org/CORBA/Current:1.0"
|
|
1274
|
+
|
|
1275
|
+
|
|
1276
|
+
class PolicyCurrent(PolicyManager, Current):
|
|
1277
|
+
"""The policy overrides of the calling thread (initial reference
|
|
1278
|
+
``PolicyCurrent``), for every ORB."""
|
|
1279
|
+
|
|
1280
|
+
_NP_RepositoryId = "IDL:omg.org/CORBA/PolicyCurrent:1.0"
|
|
1281
|
+
|
|
1282
|
+
def __init__(self):
|
|
1283
|
+
LocalObject.__init__(self)
|
|
1284
|
+
|
|
1285
|
+
def get_policy_overrides(self, ts):
|
|
1286
|
+
native = _native_module()
|
|
1287
|
+
return [_make_policy(t, v) for t, v in native.thread_policy_overrides(list(ts))]
|
|
1288
|
+
|
|
1289
|
+
def set_policy_overrides(self, policies, set_add):
|
|
1290
|
+
_native_module().set_thread_policy_overrides(
|
|
1291
|
+
_raw_policies(policies), _override_mode(set_add)
|
|
1292
|
+
)
|
|
1293
|
+
|
|
1294
|
+
|
|
1295
|
+
class ServiceDetail(_types.Struct):
|
|
1296
|
+
_NP_RepositoryId = "IDL:omg.org/CORBA/ServiceDetail:1.0"
|
|
1297
|
+
_NP_members = ("service_detail_type", "service_detail")
|
|
1298
|
+
|
|
1299
|
+
|
|
1300
|
+
class ServiceInformation(_types.Struct):
|
|
1301
|
+
_NP_RepositoryId = "IDL:omg.org/CORBA/ServiceInformation:1.0"
|
|
1302
|
+
_NP_members = ("service_options", "service_details")
|
|
1303
|
+
|
|
1304
|
+
|
|
1305
|
+
# ---------------------------------------------------------------------------
|
|
1306
|
+
# The ORB
|
|
1307
|
+
|
|
1308
|
+
#: The ORB identifier of ``ORB_init``.
|
|
1309
|
+
ORB_ID = "rustorb"
|
|
1310
|
+
|
|
1311
|
+
_orbs: dict = {}
|
|
1312
|
+
_orbs_lock = _threading.Lock()
|
|
1313
|
+
|
|
1314
|
+
|
|
1315
|
+
class ORB(object):
|
|
1316
|
+
"""``CORBA::ORB``, made by :func:`ORB_init`."""
|
|
1317
|
+
|
|
1318
|
+
_NP_RepositoryId = "IDL:omg.org/CORBA/ORB:1.0"
|
|
1319
|
+
|
|
1320
|
+
class InvalidName(UserException):
|
|
1321
|
+
_NP_RepositoryId = "IDL:omg.org/CORBA/ORB/InvalidName:1.0"
|
|
1322
|
+
|
|
1323
|
+
def __init__(self, native, orb_id):
|
|
1324
|
+
self._native = native
|
|
1325
|
+
self._id = orb_id
|
|
1326
|
+
self._root_poa = None
|
|
1327
|
+
self._ins_poa = None
|
|
1328
|
+
self._lock = _threading.Lock()
|
|
1329
|
+
self._destroyed = False
|
|
1330
|
+
# Requests of send_multiple_requests_deferred not yet collected.
|
|
1331
|
+
self._deferred = []
|
|
1332
|
+
|
|
1333
|
+
def id(self):
|
|
1334
|
+
return self._id
|
|
1335
|
+
|
|
1336
|
+
# -- the DII --
|
|
1337
|
+
|
|
1338
|
+
def create_list(self, count):
|
|
1339
|
+
"""An empty ``CORBA.NVList`` (``count`` is only a hint)."""
|
|
1340
|
+
return NVList()
|
|
1341
|
+
|
|
1342
|
+
def create_operation_list(self, oper):
|
|
1343
|
+
raise NO_IMPLEMENT(0, COMPLETED_NO)
|
|
1344
|
+
|
|
1345
|
+
def create_named_value(self, name, value, flags):
|
|
1346
|
+
return NamedValue(name, value, flags)
|
|
1347
|
+
|
|
1348
|
+
def create_exception_list(self):
|
|
1349
|
+
return []
|
|
1350
|
+
|
|
1351
|
+
def send_multiple_requests_oneway(self, requests):
|
|
1352
|
+
for r in requests:
|
|
1353
|
+
r.send_oneway()
|
|
1354
|
+
|
|
1355
|
+
def send_multiple_requests_deferred(self, requests):
|
|
1356
|
+
with self._lock:
|
|
1357
|
+
for r in requests:
|
|
1358
|
+
r.send_deferred()
|
|
1359
|
+
self._deferred.append(r)
|
|
1360
|
+
|
|
1361
|
+
def poll_next_response(self):
|
|
1362
|
+
"""Whether a response to ``send_multiple_requests_deferred`` has
|
|
1363
|
+
arrived."""
|
|
1364
|
+
with self._lock:
|
|
1365
|
+
return any(r.poll_response() for r in self._deferred)
|
|
1366
|
+
|
|
1367
|
+
def get_next_response(self):
|
|
1368
|
+
"""The next request of ``send_multiple_requests_deferred`` whose
|
|
1369
|
+
response has arrived; waits for one. Its ``get_response()`` then
|
|
1370
|
+
takes the response at once (raising its exception, if any).
|
|
1371
|
+
``BAD_INV_ORDER`` when none is outstanding."""
|
|
1372
|
+
while True:
|
|
1373
|
+
with self._lock:
|
|
1374
|
+
if not self._deferred:
|
|
1375
|
+
raise BAD_INV_ORDER(0, COMPLETED_NO)
|
|
1376
|
+
for i, r in enumerate(self._deferred):
|
|
1377
|
+
if r.poll_response():
|
|
1378
|
+
del self._deferred[i]
|
|
1379
|
+
break
|
|
1380
|
+
else:
|
|
1381
|
+
r = None
|
|
1382
|
+
if r is not None:
|
|
1383
|
+
return r
|
|
1384
|
+
_time.sleep(0.001)
|
|
1385
|
+
|
|
1386
|
+
def string_to_object(self, s):
|
|
1387
|
+
from . import _rt
|
|
1388
|
+
|
|
1389
|
+
native = self._native.string_to_object(s)
|
|
1390
|
+
if native is None:
|
|
1391
|
+
return None
|
|
1392
|
+
return _rt.make_objref(native, Object._NP_RepositoryId)
|
|
1393
|
+
|
|
1394
|
+
def object_to_string(self, obj):
|
|
1395
|
+
if obj is None:
|
|
1396
|
+
return self._native.object_to_string(None)
|
|
1397
|
+
return self._native.object_to_string(obj._orb_object())
|
|
1398
|
+
|
|
1399
|
+
def resolve_initial_references(self, identifier):
|
|
1400
|
+
from . import _rt
|
|
1401
|
+
|
|
1402
|
+
if identifier == "RootPOA":
|
|
1403
|
+
return self._get_root_poa()
|
|
1404
|
+
if identifier == "POACurrent":
|
|
1405
|
+
from . import PortableServer
|
|
1406
|
+
|
|
1407
|
+
return PortableServer.Current()
|
|
1408
|
+
if identifier == "omniINSPOA":
|
|
1409
|
+
return self._get_ins_poa()
|
|
1410
|
+
if identifier == "ORBPolicyManager":
|
|
1411
|
+
return PolicyManager(self._native)
|
|
1412
|
+
if identifier == "PolicyCurrent":
|
|
1413
|
+
return PolicyCurrent()
|
|
1414
|
+
if identifier == "DynAnyFactory":
|
|
1415
|
+
from . import DynamicAny
|
|
1416
|
+
|
|
1417
|
+
return DynamicAny.DynAnyFactory()
|
|
1418
|
+
local = self._native.resolve_local_initial_reference(identifier)
|
|
1419
|
+
if local is not None:
|
|
1420
|
+
return local
|
|
1421
|
+
try:
|
|
1422
|
+
native = self._native.resolve_initial_references(identifier)
|
|
1423
|
+
except LookupError:
|
|
1424
|
+
raise ORB.InvalidName()
|
|
1425
|
+
return _rt.make_objref(native, Object._NP_RepositoryId)
|
|
1426
|
+
|
|
1427
|
+
#: The names resolve_initial_references answers without the core.
|
|
1428
|
+
_LOCAL_SERVICES = (
|
|
1429
|
+
"RootPOA",
|
|
1430
|
+
"POACurrent",
|
|
1431
|
+
"omniINSPOA",
|
|
1432
|
+
"ORBPolicyManager",
|
|
1433
|
+
"PolicyCurrent",
|
|
1434
|
+
"DynAnyFactory",
|
|
1435
|
+
)
|
|
1436
|
+
|
|
1437
|
+
def list_initial_services(self):
|
|
1438
|
+
return list(self._LOCAL_SERVICES) + list(self._native.list_initial_services())
|
|
1439
|
+
|
|
1440
|
+
def register_initial_reference(self, identifier, obj):
|
|
1441
|
+
"""Makes ``resolve_initial_references(identifier)`` return
|
|
1442
|
+
``obj``, a reference or a local object. InvalidName for an empty
|
|
1443
|
+
name or one that is already an initial reference, BAD_PARAM (minor
|
|
1444
|
+
27) for nil."""
|
|
1445
|
+
if identifier in self._LOCAL_SERVICES:
|
|
1446
|
+
raise ORB.InvalidName()
|
|
1447
|
+
try:
|
|
1448
|
+
if isinstance(obj, Object) and obj._obj is not None:
|
|
1449
|
+
self._native.register_initial_reference(identifier, obj._obj)
|
|
1450
|
+
elif obj is None:
|
|
1451
|
+
self._native.register_initial_reference(identifier, None)
|
|
1452
|
+
else:
|
|
1453
|
+
self._native.register_local_initial_reference(identifier, obj)
|
|
1454
|
+
except LookupError:
|
|
1455
|
+
raise ORB.InvalidName()
|
|
1456
|
+
|
|
1457
|
+
def get_service_information(self, service_type):
|
|
1458
|
+
"""rustorb offers no services (such as security):
|
|
1459
|
+
``(False, ServiceInformation)``."""
|
|
1460
|
+
return False, ServiceInformation([], [])
|
|
1461
|
+
|
|
1462
|
+
def create_policy(self, type, val):
|
|
1463
|
+
"""A POA policy from its enumerator, or a
|
|
1464
|
+
``Messaging.RelativeRoundtripTimeoutPolicy`` from a
|
|
1465
|
+
``TimeBase::TimeT`` (unsigned long long, in units of 100 ns), in
|
|
1466
|
+
the any ``val``. PolicyError: BAD_POLICY for a type rustorb does not
|
|
1467
|
+
know, BAD_POLICY_TYPE for an any of the wrong type,
|
|
1468
|
+
BAD_POLICY_VALUE for an enumerator out of range."""
|
|
1469
|
+
if not isinstance(val, Any):
|
|
1470
|
+
raise BAD_PARAM(0, COMPLETED_NO)
|
|
1471
|
+
value, reason = self._native.create_policy(type, val)
|
|
1472
|
+
if reason is not None:
|
|
1473
|
+
raise PolicyError(reason)
|
|
1474
|
+
return _make_policy(type, value)
|
|
1475
|
+
|
|
1476
|
+
def _get_root_poa(self):
|
|
1477
|
+
with self._lock:
|
|
1478
|
+
if self._root_poa is None:
|
|
1479
|
+
from . import PortableServer
|
|
1480
|
+
|
|
1481
|
+
self._root_poa = PortableServer._wrap_poa(self._native.root_poa())
|
|
1482
|
+
return self._root_poa
|
|
1483
|
+
|
|
1484
|
+
def _get_ins_poa(self):
|
|
1485
|
+
# omniORB's "omniINSPOA" (OpenRTM-aist uses it): a child of the
|
|
1486
|
+
# RootPOA with its own manager, where references have the object
|
|
1487
|
+
# id as their object key, for corbaloc::host:port/ID. The keys
|
|
1488
|
+
# stay the same across restarts whatever the lifespan policy, so
|
|
1489
|
+
# it is TRANSIENT, which needs no fixed port.
|
|
1490
|
+
root = self._get_root_poa()
|
|
1491
|
+
with self._lock:
|
|
1492
|
+
if self._ins_poa is None:
|
|
1493
|
+
from . import PortableServer
|
|
1494
|
+
|
|
1495
|
+
policy = root.create_id_assignment_policy(PortableServer.USER_ID)
|
|
1496
|
+
native = root._native.create_poa(
|
|
1497
|
+
"omniINSPOA", None, [(policy.policy_type, int(policy.value))]
|
|
1498
|
+
)
|
|
1499
|
+
self._ins_poa = PortableServer._INSPOA(native, self._native)
|
|
1500
|
+
return self._ins_poa
|
|
1501
|
+
|
|
1502
|
+
def run(self):
|
|
1503
|
+
self._native.run()
|
|
1504
|
+
|
|
1505
|
+
def work_pending(self):
|
|
1506
|
+
return self._native.work_pending()
|
|
1507
|
+
|
|
1508
|
+
def perform_work(self):
|
|
1509
|
+
self._native.perform_work()
|
|
1510
|
+
|
|
1511
|
+
def shutdown(self, wait_for_completion):
|
|
1512
|
+
self._native.shutdown(bool(wait_for_completion))
|
|
1513
|
+
|
|
1514
|
+
def destroy(self):
|
|
1515
|
+
with _orbs_lock:
|
|
1516
|
+
if _orbs.get(self._id) is self:
|
|
1517
|
+
del _orbs[self._id]
|
|
1518
|
+
self._destroyed = True
|
|
1519
|
+
self._native.destroy()
|
|
1520
|
+
|
|
1521
|
+
# -- TypeCodes --
|
|
1522
|
+
|
|
1523
|
+
def create_struct_tc(self, id, name, members):
|
|
1524
|
+
return _create_struct_like(tk_struct, id, name, members)
|
|
1525
|
+
|
|
1526
|
+
def create_exception_tc(self, id, name, members):
|
|
1527
|
+
return _create_struct_like(tk_except, id, name, members)
|
|
1528
|
+
|
|
1529
|
+
def create_union_tc(self, id, name, discriminator_type, members):
|
|
1530
|
+
from . import _rt
|
|
1531
|
+
|
|
1532
|
+
labels, ms, default = [], [], -1
|
|
1533
|
+
for i, m in enumerate(members):
|
|
1534
|
+
m_name, label, m_type = _member_fields(m, 3)
|
|
1535
|
+
if isinstance(label, Any) and label._t._k is tk_octet and label._v == 0:
|
|
1536
|
+
if default >= 0:
|
|
1537
|
+
raise BAD_PARAM(0, COMPLETED_NO)
|
|
1538
|
+
default = i
|
|
1539
|
+
labels.append(None)
|
|
1540
|
+
else:
|
|
1541
|
+
labels.append(label._v if isinstance(label, Any) else label)
|
|
1542
|
+
ms.append((m_name, m_type))
|
|
1543
|
+
tc = TypeCode(
|
|
1544
|
+
tk_union,
|
|
1545
|
+
id,
|
|
1546
|
+
name,
|
|
1547
|
+
members=ms,
|
|
1548
|
+
labels=labels,
|
|
1549
|
+
discriminator=discriminator_type,
|
|
1550
|
+
default=default,
|
|
1551
|
+
)
|
|
1552
|
+
_resolve_recursive(tc, id)
|
|
1553
|
+
_rt.make_class(tc)
|
|
1554
|
+
return tc
|
|
1555
|
+
|
|
1556
|
+
def create_enum_tc(self, id, name, members):
|
|
1557
|
+
from . import _rt
|
|
1558
|
+
|
|
1559
|
+
tc = TypeCode(tk_enum, id, name, members=list(members))
|
|
1560
|
+
_rt.make_class(tc)
|
|
1561
|
+
return tc
|
|
1562
|
+
|
|
1563
|
+
def create_alias_tc(self, id, name, original_type):
|
|
1564
|
+
return TypeCode(tk_alias, id, name, content=original_type)
|
|
1565
|
+
|
|
1566
|
+
def create_value_box_tc(self, id, name, boxed_type):
|
|
1567
|
+
return TypeCode(tk_value_box, id, name, content=boxed_type)
|
|
1568
|
+
|
|
1569
|
+
def create_value_tc(self, id, name, type_modifier, concrete_base, members):
|
|
1570
|
+
"""A valuetype TypeCode. ``members`` are :class:`ValueMember`
|
|
1571
|
+
(or ``(name, type, access)`` tuples); ``concrete_base`` may be None
|
|
1572
|
+
or ``TC_null``."""
|
|
1573
|
+
from . import _rt
|
|
1574
|
+
|
|
1575
|
+
if concrete_base is not None and concrete_base._k is tk_null:
|
|
1576
|
+
concrete_base = None
|
|
1577
|
+
tc = TypeCode(
|
|
1578
|
+
tk_value,
|
|
1579
|
+
id,
|
|
1580
|
+
name,
|
|
1581
|
+
modifier=type_modifier,
|
|
1582
|
+
base=concrete_base,
|
|
1583
|
+
members=[
|
|
1584
|
+
(m.name, m.type, m.access) if isinstance(m, ValueMember) else tuple(m)[:3]
|
|
1585
|
+
for m in members
|
|
1586
|
+
],
|
|
1587
|
+
)
|
|
1588
|
+
_resolve_recursive(tc, id)
|
|
1589
|
+
_rt.make_class(tc)
|
|
1590
|
+
return tc
|
|
1591
|
+
|
|
1592
|
+
# -- value factories --
|
|
1593
|
+
|
|
1594
|
+
def register_value_factory(self, id, factory):
|
|
1595
|
+
"""Registers ``factory`` (a callable without arguments that
|
|
1596
|
+
returns a new instance) for the valuetype ``id``; returns the
|
|
1597
|
+
factory it replaces, or None."""
|
|
1598
|
+
from . import _rt
|
|
1599
|
+
|
|
1600
|
+
return _rt.register_value_factory(id, factory)
|
|
1601
|
+
|
|
1602
|
+
def unregister_value_factory(self, id):
|
|
1603
|
+
from . import _rt
|
|
1604
|
+
|
|
1605
|
+
if _rt.unregister_value_factory(id) is None:
|
|
1606
|
+
raise BAD_PARAM(0, COMPLETED_NO)
|
|
1607
|
+
|
|
1608
|
+
def lookup_value_factory(self, id):
|
|
1609
|
+
from . import _rt
|
|
1610
|
+
|
|
1611
|
+
return _rt.lookup_value_factory(id)
|
|
1612
|
+
|
|
1613
|
+
def create_interface_tc(self, id, name):
|
|
1614
|
+
return TypeCode(tk_objref, id, name)
|
|
1615
|
+
|
|
1616
|
+
def create_abstract_interface_tc(self, id, name):
|
|
1617
|
+
return TypeCode(tk_abstract_interface, id, name)
|
|
1618
|
+
|
|
1619
|
+
def create_local_interface_tc(self, id, name):
|
|
1620
|
+
return TypeCode(tk_local_interface, id, name)
|
|
1621
|
+
|
|
1622
|
+
def create_native_tc(self, id, name):
|
|
1623
|
+
return TypeCode(tk_native, id, name)
|
|
1624
|
+
|
|
1625
|
+
def create_string_tc(self, bound):
|
|
1626
|
+
return TypeCode(tk_string, length=bound)
|
|
1627
|
+
|
|
1628
|
+
def create_wstring_tc(self, bound):
|
|
1629
|
+
return TypeCode(tk_wstring, length=bound)
|
|
1630
|
+
|
|
1631
|
+
def create_fixed_tc(self, digits, scale):
|
|
1632
|
+
return TypeCode(tk_fixed, digits=digits, scale=scale)
|
|
1633
|
+
|
|
1634
|
+
def create_sequence_tc(self, bound, element_type):
|
|
1635
|
+
return TypeCode(tk_sequence, content=element_type, length=bound)
|
|
1636
|
+
|
|
1637
|
+
def create_array_tc(self, length, element_type):
|
|
1638
|
+
return TypeCode(tk_array, content=element_type, length=length)
|
|
1639
|
+
|
|
1640
|
+
def create_recursive_tc(self, id):
|
|
1641
|
+
"""A placeholder for the struct or union ``id``, to use in its member
|
|
1642
|
+
types; ``create_struct_tc`` and ``create_union_tc`` replace it."""
|
|
1643
|
+
tc = TypeCode(tk_null, id)
|
|
1644
|
+
tc._recursive = True
|
|
1645
|
+
return tc
|
|
1646
|
+
|
|
1647
|
+
def __repr__(self):
|
|
1648
|
+
return "<CORBA.ORB %r>" % self._id
|
|
1649
|
+
|
|
1650
|
+
|
|
1651
|
+
class StructMember(_types.Struct):
|
|
1652
|
+
"""A member for ``ORB.create_struct_tc``: ``name``, ``type`` and
|
|
1653
|
+
``type_def`` (unused, may be None)."""
|
|
1654
|
+
|
|
1655
|
+
_NP_RepositoryId = "IDL:omg.org/CORBA/StructMember:1.0"
|
|
1656
|
+
_NP_members = ("name", "type", "type_def")
|
|
1657
|
+
|
|
1658
|
+
def __init__(self, name, type, type_def=None): # noqa: A002
|
|
1659
|
+
self.name = name
|
|
1660
|
+
self.type = type
|
|
1661
|
+
self.type_def = type_def
|
|
1662
|
+
|
|
1663
|
+
|
|
1664
|
+
class UnionMember(_types.Struct):
|
|
1665
|
+
"""A member for ``ORB.create_union_tc``: ``name``, ``label`` (an Any;
|
|
1666
|
+
the octet 0 for the default member), ``type`` and ``type_def``."""
|
|
1667
|
+
|
|
1668
|
+
_NP_RepositoryId = "IDL:omg.org/CORBA/UnionMember:1.0"
|
|
1669
|
+
_NP_members = ("name", "label", "type", "type_def")
|
|
1670
|
+
|
|
1671
|
+
def __init__(self, name, label, type, type_def=None): # noqa: A002
|
|
1672
|
+
self.name = name
|
|
1673
|
+
self.label = label
|
|
1674
|
+
self.type = type
|
|
1675
|
+
self.type_def = type_def
|
|
1676
|
+
|
|
1677
|
+
|
|
1678
|
+
class ValueMember(_types.Struct):
|
|
1679
|
+
"""A member for ``ORB.create_value_tc``."""
|
|
1680
|
+
|
|
1681
|
+
_NP_RepositoryId = "IDL:omg.org/CORBA/ValueMember:1.0"
|
|
1682
|
+
_NP_members = ("name", "id", "defined_in", "version", "type", "type_def", "access")
|
|
1683
|
+
|
|
1684
|
+
def __init__(
|
|
1685
|
+
self, name, id, defined_in, version, type, type_def=None, access=PUBLIC_MEMBER
|
|
1686
|
+
): # noqa: A002
|
|
1687
|
+
self.name = name
|
|
1688
|
+
self.id = id
|
|
1689
|
+
self.defined_in = defined_in
|
|
1690
|
+
self.version = version
|
|
1691
|
+
self.type = type
|
|
1692
|
+
self.type_def = type_def
|
|
1693
|
+
self.access = access
|
|
1694
|
+
|
|
1695
|
+
|
|
1696
|
+
def _member_fields(m, n):
|
|
1697
|
+
"""(name, type) of a StructMember, (name, label, type) of a
|
|
1698
|
+
UnionMember, or the same from a tuple."""
|
|
1699
|
+
if isinstance(m, StructMember):
|
|
1700
|
+
return m.name, m.type
|
|
1701
|
+
if isinstance(m, UnionMember):
|
|
1702
|
+
return m.name, m.label, m.type
|
|
1703
|
+
return tuple(m)[:n]
|
|
1704
|
+
|
|
1705
|
+
|
|
1706
|
+
def _create_struct_like(kind, id, name, members):
|
|
1707
|
+
from . import _rt
|
|
1708
|
+
|
|
1709
|
+
tc = TypeCode(kind, id, name, members=[_member_fields(m, 2) for m in members])
|
|
1710
|
+
_resolve_recursive(tc, id)
|
|
1711
|
+
_rt.make_class(tc)
|
|
1712
|
+
return tc
|
|
1713
|
+
|
|
1714
|
+
|
|
1715
|
+
def _resolve_recursive(tc, id):
|
|
1716
|
+
"""Replace the placeholders of ``create_recursive_tc(id)`` in the member
|
|
1717
|
+
types of ``tc`` by ``tc``."""
|
|
1718
|
+
seen = set()
|
|
1719
|
+
|
|
1720
|
+
def fix(t):
|
|
1721
|
+
if getattr(t, "_recursive", False) and t._id == id:
|
|
1722
|
+
return tc
|
|
1723
|
+
if id_(t) in seen:
|
|
1724
|
+
return t
|
|
1725
|
+
seen.add(id_(t))
|
|
1726
|
+
if t._content is not None:
|
|
1727
|
+
t._content = fix(t._content)
|
|
1728
|
+
if t._disc is not None:
|
|
1729
|
+
t._disc = fix(t._disc)
|
|
1730
|
+
if t._base is not None:
|
|
1731
|
+
t._base = fix(t._base)
|
|
1732
|
+
if t._members is not None and t._k is not tk_enum:
|
|
1733
|
+
t._members = [(m[0], fix(m[1])) + tuple(m[2:]) for m in t._members]
|
|
1734
|
+
return t
|
|
1735
|
+
|
|
1736
|
+
id_ = _builtins.id
|
|
1737
|
+
seen.add(id_(tc))
|
|
1738
|
+
if tc._members is not None:
|
|
1739
|
+
tc._members = [(m[0], fix(m[1])) + tuple(m[2:]) for m in tc._members]
|
|
1740
|
+
|
|
1741
|
+
|
|
1742
|
+
def ORB_init(argv=None, orb_identifier=ORB_ID):
|
|
1743
|
+
"""Initialises the ORB ``orb_identifier``, or returns it if it exists.
|
|
1744
|
+
|
|
1745
|
+
ORB options (``-ORBInitRef``, ``-ORBendPoint``...) are taken from
|
|
1746
|
+
``argv`` and removed from it when it is a list.
|
|
1747
|
+
"""
|
|
1748
|
+
if _native is None:
|
|
1749
|
+
raise INITIALIZE(0, COMPLETED_NO)
|
|
1750
|
+
if argv is None:
|
|
1751
|
+
argv = []
|
|
1752
|
+
with _orbs_lock:
|
|
1753
|
+
orb = _orbs.get(orb_identifier)
|
|
1754
|
+
if orb is not None:
|
|
1755
|
+
return orb
|
|
1756
|
+
native, rest = _native.Orb.init([str(a) for a in argv])
|
|
1757
|
+
if isinstance(argv, list):
|
|
1758
|
+
argv[:] = rest
|
|
1759
|
+
orb = ORB(native, orb_identifier)
|
|
1760
|
+
_orbs[orb_identifier] = orb
|
|
1761
|
+
from . import _rt
|
|
1762
|
+
|
|
1763
|
+
_rt.flush_values()
|
|
1764
|
+
return orb
|
|
1765
|
+
|
|
1766
|
+
|
|
1767
|
+
def _default_orb():
|
|
1768
|
+
"""The first ORB that was initialised and is not destroyed."""
|
|
1769
|
+
with _orbs_lock:
|
|
1770
|
+
for orb in _orbs.values():
|
|
1771
|
+
return orb
|
|
1772
|
+
raise BAD_INV_ORDER(0, COMPLETED_NO)
|
|
1773
|
+
|
|
1774
|
+
|
|
1775
|
+
@_atexit.register
|
|
1776
|
+
def _destroy_orbs():
|
|
1777
|
+
# Servants run on ORB threads; finish their requests while the
|
|
1778
|
+
# interpreter can still run them.
|
|
1779
|
+
with _orbs_lock:
|
|
1780
|
+
orbs = list(_orbs.values())
|
|
1781
|
+
for orb in orbs:
|
|
1782
|
+
try:
|
|
1783
|
+
orb.destroy()
|
|
1784
|
+
except Exception: # already destroyed
|
|
1785
|
+
pass
|