zeroc-ice 3.7.11__cp313-cp313-macosx_10_13_universal2.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.
Files changed (142) hide show
  1. Glacier2/Metrics_ice.py +82 -0
  2. Glacier2/PermissionsVerifierF_ice.py +32 -0
  3. Glacier2/PermissionsVerifier_ice.py +284 -0
  4. Glacier2/RouterF_ice.py +28 -0
  5. Glacier2/Router_ice.py +618 -0
  6. Glacier2/SSLInfo_ice.py +179 -0
  7. Glacier2/Session_ice.py +1103 -0
  8. Glacier2/__init__.py +226 -0
  9. Ice/BuiltinSequences_ice.py +65 -0
  10. Ice/CommunicatorF_ice.py +27 -0
  11. Ice/Communicator_ice.py +469 -0
  12. Ice/ConnectionF_ice.py +33 -0
  13. Ice/Connection_ice.py +680 -0
  14. Ice/Current_ice.py +175 -0
  15. Ice/EndpointF_ice.py +45 -0
  16. Ice/EndpointTypes_ice.py +54 -0
  17. Ice/Endpoint_ice.py +304 -0
  18. Ice/FacetMap_ice.py +27 -0
  19. Ice/Identity_ice.py +133 -0
  20. Ice/ImplicitContextF_ice.py +27 -0
  21. Ice/ImplicitContext_ice.py +119 -0
  22. Ice/InstrumentationF_ice.py +38 -0
  23. Ice/Instrumentation_ice.py +566 -0
  24. Ice/LocalException_ice.py +1715 -0
  25. Ice/LocatorF_ice.py +32 -0
  26. Ice/Locator_ice.py +728 -0
  27. Ice/LoggerF_ice.py +27 -0
  28. Ice/Logger_ice.py +96 -0
  29. Ice/Metrics_ice.py +864 -0
  30. Ice/ObjectAdapterF_ice.py +27 -0
  31. Ice/ObjectAdapter_ice.py +461 -0
  32. Ice/ObjectFactory_ice.py +68 -0
  33. Ice/PluginF_ice.py +30 -0
  34. Ice/Plugin_ice.py +136 -0
  35. Ice/ProcessF_ice.py +28 -0
  36. Ice/Process_ice.py +175 -0
  37. Ice/PropertiesAdmin_ice.py +247 -0
  38. Ice/PropertiesF_ice.py +31 -0
  39. Ice/Properties_ice.py +199 -0
  40. Ice/Py3/IceFuture.py +52 -0
  41. Ice/Py3/__init__.py +3 -0
  42. Ice/RemoteLogger_ice.py +617 -0
  43. Ice/RouterF_ice.py +28 -0
  44. Ice/Router_ice.py +350 -0
  45. Ice/ServantLocatorF_ice.py +27 -0
  46. Ice/ServantLocator_ice.py +110 -0
  47. Ice/SliceChecksumDict_ice.py +29 -0
  48. Ice/ValueFactory_ice.py +125 -0
  49. Ice/Version_ice.py +217 -0
  50. Ice/__init__.py +2008 -0
  51. IceBox/IceBox_ice.py +644 -0
  52. IceBox/__init__.py +10 -0
  53. IceGrid/Admin_ice.py +6662 -0
  54. IceGrid/Descriptor_ice.py +1795 -0
  55. IceGrid/Exception_ice.py +592 -0
  56. IceGrid/FileParser_ice.py +171 -0
  57. IceGrid/PluginFacade_ice.py +288 -0
  58. IceGrid/Registry_ice.py +985 -0
  59. IceGrid/Session_ice.py +406 -0
  60. IceGrid/UserAccountMapper_ice.py +166 -0
  61. IceGrid/__init__.py +17 -0
  62. IceMX/__init__.py +12 -0
  63. IcePatch2/FileInfo_ice.py +287 -0
  64. IcePatch2/FileServer_ice.py +555 -0
  65. IcePatch2/__init__.py +11 -0
  66. IcePy.cpython-313-darwin.so +0 -0
  67. IceStorm/IceStorm_ice.py +1265 -0
  68. IceStorm/Metrics_ice.py +106 -0
  69. IceStorm/__init__.py +10 -0
  70. slice/Glacier2/Metrics.ice +88 -0
  71. slice/Glacier2/PermissionsVerifier.ice +111 -0
  72. slice/Glacier2/PermissionsVerifierF.ice +30 -0
  73. slice/Glacier2/Router.ice +186 -0
  74. slice/Glacier2/RouterF.ice +29 -0
  75. slice/Glacier2/SSLInfo.ice +59 -0
  76. slice/Glacier2/Session.ice +274 -0
  77. slice/Ice/BuiltinSequences.ice +59 -0
  78. slice/Ice/Communicator.ice +676 -0
  79. slice/Ice/CommunicatorF.ice +31 -0
  80. slice/Ice/Connection.ice +516 -0
  81. slice/Ice/ConnectionF.ice +33 -0
  82. slice/Ice/Current.ice +170 -0
  83. slice/Ice/Endpoint.ice +291 -0
  84. slice/Ice/EndpointF.ice +43 -0
  85. slice/Ice/EndpointTypes.ice +48 -0
  86. slice/Ice/FacetMap.ice +36 -0
  87. slice/Ice/Identity.ice +75 -0
  88. slice/Ice/ImplicitContext.ice +119 -0
  89. slice/Ice/ImplicitContextF.ice +30 -0
  90. slice/Ice/Instrumentation.ice +509 -0
  91. slice/Ice/InstrumentationF.ice +38 -0
  92. slice/Ice/LocalException.ice +1040 -0
  93. slice/Ice/Locator.ice +239 -0
  94. slice/Ice/LocatorF.ice +32 -0
  95. slice/Ice/Logger.ice +99 -0
  96. slice/Ice/LoggerF.ice +31 -0
  97. slice/Ice/Metrics.ice +436 -0
  98. slice/Ice/ObjectAdapter.ice +710 -0
  99. slice/Ice/ObjectAdapterF.ice +31 -0
  100. slice/Ice/ObjectFactory.ice +71 -0
  101. slice/Ice/Plugin.ice +131 -0
  102. slice/Ice/PluginF.ice +36 -0
  103. slice/Ice/Process.ice +64 -0
  104. slice/Ice/ProcessF.ice +31 -0
  105. slice/Ice/Properties.ice +244 -0
  106. slice/Ice/PropertiesAdmin.ice +87 -0
  107. slice/Ice/PropertiesF.ice +32 -0
  108. slice/Ice/RemoteLogger.ice +226 -0
  109. slice/Ice/Router.ice +103 -0
  110. slice/Ice/RouterF.ice +31 -0
  111. slice/Ice/ServantLocator.ice +136 -0
  112. slice/Ice/ServantLocatorF.ice +31 -0
  113. slice/Ice/SliceChecksumDict.ice +36 -0
  114. slice/Ice/ValueFactory.ice +133 -0
  115. slice/Ice/Version.ice +51 -0
  116. slice/IceBT/ConnectionInfo.ice +59 -0
  117. slice/IceBT/EndpointInfo.ice +57 -0
  118. slice/IceBT/Types.ice +45 -0
  119. slice/IceBox/IceBox.ice +216 -0
  120. slice/IceGrid/Admin.ice +1957 -0
  121. slice/IceGrid/Descriptor.ice +1094 -0
  122. slice/IceGrid/Exception.ice +396 -0
  123. slice/IceGrid/FileParser.ice +72 -0
  124. slice/IceGrid/PluginFacade.ice +329 -0
  125. slice/IceGrid/Registry.ice +269 -0
  126. slice/IceGrid/Session.ice +128 -0
  127. slice/IceGrid/UserAccountMapper.ice +69 -0
  128. slice/IceIAP/ConnectionInfo.ice +74 -0
  129. slice/IceIAP/EndpointInfo.ice +68 -0
  130. slice/IcePatch2/FileInfo.ice +85 -0
  131. slice/IcePatch2/FileServer.ice +191 -0
  132. slice/IceSSL/ConnectionInfo.ice +54 -0
  133. slice/IceSSL/ConnectionInfoF.ice +31 -0
  134. slice/IceSSL/EndpointInfo.ice +45 -0
  135. slice/IceStorm/IceStorm.ice +414 -0
  136. slice/IceStorm/Metrics.ice +83 -0
  137. slice2py.py +21 -0
  138. zeroc_ice-3.7.11.dist-info/METADATA +97 -0
  139. zeroc_ice-3.7.11.dist-info/RECORD +142 -0
  140. zeroc_ice-3.7.11.dist-info/WHEEL +5 -0
  141. zeroc_ice-3.7.11.dist-info/entry_points.txt +2 -0
  142. zeroc_ice-3.7.11.dist-info/top_level.txt +10 -0
Ice/__init__.py ADDED
@@ -0,0 +1,2008 @@
1
+ #
2
+ # Copyright (c) ZeroC, Inc. All rights reserved.
3
+ #
4
+
5
+ """
6
+ Ice module
7
+ """
8
+
9
+ import sys, string, os, threading, warnings, datetime, logging, time, inspect, traceback, types, array
10
+
11
+ #
12
+ # RTTI problems can occur in C++ code unless we modify Python's dlopen flags.
13
+ # Note that changing these flags might cause problems for other extensions
14
+ # loaded by the application (see bug 3660), so we restore the original settings
15
+ # after loading IcePy.
16
+ #
17
+ _dlopenflags = -1
18
+ try:
19
+ _dlopenflags = sys.getdlopenflags()
20
+
21
+ try:
22
+ import dl
23
+ sys.setdlopenflags(dl.RTLD_NOW|dl.RTLD_GLOBAL)
24
+ except ImportError:
25
+ #
26
+ # If the dl module is not available and we're running on a Linux
27
+ # platform, use the hard coded value of RTLD_NOW|RTLD_GLOBAL.
28
+ #
29
+ if sys.platform.startswith("linux"):
30
+ sys.setdlopenflags(258)
31
+ pass
32
+
33
+ except AttributeError:
34
+ #
35
+ # sys.getdlopenflags() is not supported (we're probably running on Windows).
36
+ #
37
+ pass
38
+
39
+ #
40
+ # Import the Python extension.
41
+ #
42
+ import IcePy
43
+
44
+ #
45
+ # Restore the dlopen flags.
46
+ #
47
+ if _dlopenflags >= 0:
48
+ sys.setdlopenflags(_dlopenflags)
49
+
50
+ #
51
+ # Give the extension an opportunity to clean up before a graceful exit.
52
+ #
53
+ import atexit
54
+ atexit.register(IcePy.cleanup)
55
+
56
+ #
57
+ # Add some symbols to the Ice module.
58
+ #
59
+ ObjectPrx = IcePy.ObjectPrx
60
+ stringVersion = IcePy.stringVersion
61
+ intVersion = IcePy.intVersion
62
+ currentProtocol = IcePy.currentProtocol
63
+ currentProtocolEncoding = IcePy.currentProtocolEncoding
64
+ currentEncoding = IcePy.currentEncoding
65
+ stringToProtocolVersion = IcePy.stringToProtocolVersion
66
+ protocolVersionToString = IcePy.protocolVersionToString
67
+ stringToEncodingVersion = IcePy.stringToEncodingVersion
68
+ encodingVersionToString = IcePy.encodingVersionToString
69
+ generateUUID = IcePy.generateUUID
70
+ loadSlice = IcePy.loadSlice
71
+ AsyncResult = IcePy.AsyncResult
72
+ Unset = IcePy.Unset
73
+
74
+ def Python35():
75
+ return sys.version_info[:2] >= (3, 5)
76
+
77
+ if Python35():
78
+ from Ice.Py3.IceFuture import FutureBase, wrap_future
79
+ else:
80
+ FutureBase = object
81
+
82
+ class Future(FutureBase):
83
+ def __init__(self):
84
+ self._result = None
85
+ self._exception = None
86
+ self._condition = threading.Condition()
87
+ self._doneCallbacks = []
88
+ self._state = Future.StateRunning
89
+
90
+ def cancel(self):
91
+ callbacks = []
92
+ with self._condition:
93
+ if self._state == Future.StateDone:
94
+ return False
95
+
96
+ if self._state == Future.StateCancelled:
97
+ return True
98
+
99
+ self._state = Future.StateCancelled
100
+ callbacks = self._doneCallbacks
101
+ self._doneCallbacks = []
102
+ self._condition.notify_all()
103
+
104
+ self._callCallbacks(callbacks)
105
+
106
+ return True
107
+
108
+ def cancelled(self):
109
+ with self._condition:
110
+ return self._state == Future.StateCancelled
111
+
112
+ def running(self):
113
+ with self._condition:
114
+ return self._state == Future.StateRunning
115
+
116
+ def done(self):
117
+ with self._condition:
118
+ return self._state in [Future.StateCancelled, Future.StateDone]
119
+
120
+ def add_done_callback(self, fn):
121
+ with self._condition:
122
+ if self._state == Future.StateRunning:
123
+ self._doneCallbacks.append(fn)
124
+ return
125
+ fn(self)
126
+
127
+ def result(self, timeout=None):
128
+ with self._condition:
129
+ if not self._wait(timeout, lambda: self._state == Future.StateRunning):
130
+ raise TimeoutException()
131
+ if self._state == Future.StateCancelled:
132
+ raise InvocationCanceledException()
133
+ elif self._exception:
134
+ raise self._exception
135
+ else:
136
+ return self._result
137
+
138
+ def exception(self, timeout=None):
139
+ with self._condition:
140
+ if not self._wait(timeout, lambda: self._state == Future.StateRunning):
141
+ raise TimeoutException()
142
+ if self._state == Future.StateCancelled:
143
+ raise InvocationCanceledException()
144
+ else:
145
+ return self._exception
146
+
147
+ def set_result(self, result):
148
+ callbacks = []
149
+ with self._condition:
150
+ if self._state != Future.StateRunning:
151
+ return
152
+ self._result = result
153
+ self._state = Future.StateDone
154
+ callbacks = self._doneCallbacks
155
+ self._doneCallbacks = []
156
+ self._condition.notify_all()
157
+
158
+ self._callCallbacks(callbacks)
159
+
160
+ def set_exception(self, ex):
161
+ callbacks = []
162
+ with self._condition:
163
+ if self._state != Future.StateRunning:
164
+ return
165
+ self._exception = ex
166
+ self._state = Future.StateDone
167
+ callbacks = self._doneCallbacks
168
+ self._doneCallbacks = []
169
+ self._condition.notify_all()
170
+
171
+ self._callCallbacks(callbacks)
172
+
173
+ @staticmethod
174
+ def completed(result):
175
+ f = Future()
176
+ f.set_result(result)
177
+ return f
178
+
179
+ def _wait(self, timeout, testFn=None):
180
+ # Must be called with _condition acquired
181
+
182
+ while testFn():
183
+ if timeout:
184
+ start = time.time()
185
+ self._condition.wait(timeout)
186
+ # Subtract the elapsed time so far from the timeout
187
+ timeout -= (time.time() - start)
188
+ if timeout <= 0:
189
+ return False
190
+ else:
191
+ self._condition.wait()
192
+
193
+ return True
194
+
195
+ def _callCallbacks(self, callbacks):
196
+ for callback in callbacks:
197
+ try:
198
+ callback(self)
199
+ except:
200
+ self._warn('done callback raised exception')
201
+
202
+ def _warn(self, msg):
203
+ logging.getLogger("Ice.Future").exception(msg)
204
+
205
+ StateRunning = 'running'
206
+ StateCancelled = 'cancelled'
207
+ StateDone = 'done'
208
+
209
+ class InvocationFuture(Future):
210
+ def __init__(self, operation, asyncResult):
211
+ Future.__init__(self)
212
+ assert(asyncResult)
213
+ self._operation = operation
214
+ self._asyncResult = asyncResult # May be None for a batch invocation.
215
+ self._sent = False
216
+ self._sentSynchronously = False
217
+ self._sentCallbacks = []
218
+
219
+ def cancel(self):
220
+ self._asyncResult.cancel()
221
+ return Future.cancel(self)
222
+
223
+ def add_done_callback_async(self, fn):
224
+ def callback():
225
+ try:
226
+ fn(self)
227
+ except:
228
+ self._warn('done callback raised exception')
229
+
230
+ with self._condition:
231
+ if self._state == Future.StateRunning:
232
+ self._doneCallbacks.append(fn)
233
+ return
234
+ self._asyncResult.callLater(callback)
235
+
236
+ def is_sent(self):
237
+ with self._condition:
238
+ return self._sent
239
+
240
+ def is_sent_synchronously(self):
241
+ with self._condition:
242
+ return self._sentSynchronously
243
+
244
+ def add_sent_callback(self, fn):
245
+ with self._condition:
246
+ if not self._sent:
247
+ self._sentCallbacks.append(fn)
248
+ return
249
+ fn(self, self._sentSynchronously)
250
+
251
+ def add_sent_callback_async(self, fn):
252
+ def callback():
253
+ try:
254
+ fn(self, self._sentSynchronously)
255
+ except:
256
+ self._warn('sent callback raised exception')
257
+
258
+ with self._condition:
259
+ if not self._sent:
260
+ self._sentCallbacks.append(fn)
261
+ return
262
+ self._asyncResult.callLater(callback)
263
+
264
+ def sent(self, timeout=None):
265
+ with self._condition:
266
+ if not self._wait(timeout, lambda: not self._sent):
267
+ raise TimeoutException()
268
+ if self._state == Future.StateCancelled:
269
+ raise InvocationCanceledException()
270
+ elif self._exception:
271
+ raise self._exception
272
+ else:
273
+ return self._sentSynchronously
274
+
275
+ def set_sent(self, sentSynchronously):
276
+ callbacks = []
277
+ with self._condition:
278
+ if self._sent:
279
+ return
280
+
281
+ self._sent = True
282
+ self._sentSynchronously = sentSynchronously
283
+ callbacks = self._sentCallbacks
284
+ self._sentCallbacks = []
285
+ self._condition.notify_all()
286
+
287
+ for callback in callbacks:
288
+ try:
289
+ callback(self, sentSynchronously)
290
+ except Exception:
291
+ self._warn('sent callback raised exception')
292
+
293
+ def operation(self):
294
+ return self._operation
295
+
296
+ def proxy(self):
297
+ return self._asyncResult.getProxy()
298
+
299
+ def connection(self):
300
+ return self._asyncResult.getConnection()
301
+
302
+ def communicator(self):
303
+ return self._asyncResult.getCommunicator()
304
+
305
+ def _warn(self, msg):
306
+ communicator = self.communicator()
307
+ if communicator:
308
+ if communicator.getProperties().getPropertyAsIntWithDefault("Ice.Warn.AMICallback", 1) > 0:
309
+ communicator.getLogger().warning("Ice.Future: " + msg + ":\n" + traceback.format_exc())
310
+ else:
311
+ logging.getLogger("Ice.Future").exception(msg)
312
+
313
+ #
314
+ # This value is used as the default value for struct types in the constructors
315
+ # of user-defined types. It allows us to determine whether the application has
316
+ # supplied a value. (See bug 3676)
317
+ #
318
+ _struct_marker = object()
319
+
320
+ #
321
+ # Core Ice types.
322
+ #
323
+ class Value(object):
324
+
325
+ def ice_id(self):
326
+ '''Obtains the type id corresponding to the most-derived Slice
327
+ interface supported by the target object.
328
+ Returns:
329
+ The type id.
330
+ '''
331
+ return '::Ice::Object'
332
+
333
+ @staticmethod
334
+ def ice_staticId():
335
+ '''Obtains the type id of this Slice class or interface.
336
+ Returns:
337
+ The type id.
338
+ '''
339
+ return '::Ice::Object'
340
+
341
+ #
342
+ # Do not define these here. They will be invoked if defined by a subclass.
343
+ #
344
+ #def ice_preMarshal(self):
345
+ # pass
346
+ #
347
+ #def ice_postUnmarshal(self):
348
+ # pass
349
+
350
+ def ice_getSlicedData(self):
351
+ '''Returns the sliced data if the value has a preserved-slice base class and has been sliced during
352
+ un-marshaling of the value, null is returned otherwise.
353
+ Returns:
354
+ The sliced data or null.
355
+ '''
356
+ return getattr(self, "_ice_slicedData", None);
357
+
358
+ class InterfaceByValue(Value):
359
+
360
+ def __init__(self, id):
361
+ self.id = id
362
+
363
+ def ice_id(self):
364
+ return self.id
365
+
366
+ class Object(object):
367
+
368
+ def ice_isA(self, id, current=None):
369
+ '''Determines whether the target object supports the interface denoted
370
+ by the given Slice type id.
371
+ Arguments:
372
+ id The Slice type id
373
+ Returns:
374
+ True if the target object supports the interface, or False otherwise.
375
+ '''
376
+ return id in self.ice_ids(current)
377
+
378
+ def ice_ping(self, current=None):
379
+ '''A reachability test for the target object.'''
380
+ pass
381
+
382
+ def ice_ids(self, current=None):
383
+ '''Obtains the type ids corresponding to the Slice interface
384
+ that are supported by the target object.
385
+ Returns:
386
+ A list of type ids.
387
+ '''
388
+ return [ self.ice_id(current) ]
389
+
390
+ def ice_id(self, current=None):
391
+ '''Obtains the type id corresponding to the most-derived Slice
392
+ interface supported by the target object.
393
+ Returns:
394
+ The type id.
395
+ '''
396
+ return '::Ice::Object'
397
+
398
+ @staticmethod
399
+ def ice_staticId():
400
+ '''Obtains the type id of this Slice class or interface.
401
+ Returns:
402
+ The type id.
403
+ '''
404
+ return '::Ice::Object'
405
+
406
+ def _iceDispatch(self, cb, method, args):
407
+ # Invoke the given servant method. Exceptions can propagate to the caller.
408
+ result = method(*args)
409
+
410
+ # Check for a future.
411
+ if isinstance(result, Future) or callable(getattr(result, "add_done_callback", None)):
412
+ def handler(future):
413
+ try:
414
+ cb.response(future.result())
415
+ except:
416
+ cb.exception(sys.exc_info()[1])
417
+ result.add_done_callback(handler)
418
+ elif Python35() and inspect.iscoroutine(result): # The iscoroutine() function was added in Python 3.5.
419
+ self._iceDispatchCoroutine(cb, result)
420
+ else:
421
+ cb.response(result)
422
+
423
+ def _iceDispatchCoroutine(self, cb, coro, value=None, exception=None):
424
+ try:
425
+ if exception:
426
+ result = coro.throw(exception)
427
+ else:
428
+ result = coro.send(value)
429
+
430
+ if result is None:
431
+ # The result can be None if the coroutine performs a bare yield (such as asyncio.sleep(0))
432
+ cb.response(None)
433
+ elif isinstance(result, Future) or callable(getattr(result, "add_done_callback", None)):
434
+ # If we've received a future from the coroutine setup a done callback to continue the dispatching
435
+ # when the future completes.
436
+ def handler(future):
437
+ try:
438
+ self._iceDispatchCoroutine(cb, coro, value=future.result())
439
+ except:
440
+ self._iceDispatchCoroutine(cb, coro, exception=sys.exc_info()[1])
441
+ result.add_done_callback(handler)
442
+ else:
443
+ raise RuntimeError('unexpected value of type ' + str(type(result)) + ' provided by coroutine')
444
+ except StopIteration as ex:
445
+ # StopIteration is raised when the coroutine completes.
446
+ cb.response(ex.value)
447
+ except:
448
+ cb.exception(sys.exc_info()[1])
449
+
450
+ class Blobject(Object):
451
+ '''Special-purpose servant base class that allows a subclass to
452
+ handle synchronous Ice invocations as "blobs" of bytes.'''
453
+
454
+ def ice_invoke(self, bytes, current):
455
+ '''Dispatch a synchronous Ice invocation. The operation's
456
+ arguments are encoded in the bytes argument. The return
457
+ value must be a tuple of two values: the first is a
458
+ boolean indicating whether the operation succeeded (True)
459
+ or raised a user exception (False), and the second is
460
+ the encoded form of the operation's results or the user
461
+ exception.
462
+ '''
463
+ pass
464
+
465
+ class BlobjectAsync(Object):
466
+ '''Special-purpose servant base class that allows a subclass to
467
+ handle asynchronous Ice invocations as "blobs" of bytes.'''
468
+
469
+ def ice_invoke(self, bytes, current):
470
+ '''Dispatch an asynchronous Ice invocation. The operation's
471
+ arguments are encoded in the bytes argument. The result must be
472
+ a tuple of two values: the first is a boolean indicating whether the
473
+ operation succeeded (True) or raised a user exception (False), and
474
+ the second is the encoded form of the operation's results or the user
475
+ exception. The subclass can either return the tuple directly (for
476
+ synchronous completion) or return a future that is eventually
477
+ completed with the tuple.
478
+ '''
479
+ pass
480
+
481
+ #
482
+ # Exceptions.
483
+ #
484
+ class Exception(Exception): # Derives from built-in base 'Exception' class.
485
+ '''The base class for all Ice exceptions.'''
486
+ def __str__(self):
487
+ return self.__class__.__name__
488
+
489
+ def ice_name(self):
490
+ '''Returns the type name of this exception.'''
491
+ return self.ice_id()[2:]
492
+
493
+ def ice_id(self):
494
+ '''Returns the type id of this exception.'''
495
+ return self._ice_id
496
+
497
+ class LocalException(Exception):
498
+ '''The base class for all Ice run-time exceptions.'''
499
+ def __init__(self, args=''):
500
+ self.args = args
501
+
502
+ class UserException(Exception):
503
+ '''The base class for all user-defined exceptions.'''
504
+
505
+ def ice_getSlicedData(self):
506
+ '''Returns the sliced data if the value has a preserved-slice base class and has been sliced during
507
+ un-marshaling of the value, null is returned otherwise.
508
+ Returns:
509
+ The sliced data or null.
510
+ '''
511
+ return getattr(self, "_ice_slicedData", None);
512
+
513
+ class EnumBase(object):
514
+ def __init__(self, _n, _v):
515
+ self._name = _n
516
+ self._value = _v
517
+
518
+ def __str__(self):
519
+ return self._name
520
+
521
+ __repr__ = __str__
522
+
523
+ def __hash__(self):
524
+ return self._value
525
+
526
+ def __lt__(self, other):
527
+ if isinstance(other, self.__class__):
528
+ return self._value < other._value
529
+ elif other == None:
530
+ return False
531
+ return NotImplemented
532
+
533
+ def __le__(self, other):
534
+ if isinstance(other, self.__class__):
535
+ return self._value <= other._value
536
+ elif other is None:
537
+ return False
538
+ return NotImplemented
539
+
540
+ def __eq__(self, other):
541
+ if isinstance(other, self.__class__):
542
+ return self._value == other._value
543
+ elif other == None:
544
+ return False
545
+ return NotImplemented
546
+
547
+ def __ne__(self, other):
548
+ if isinstance(other, self.__class__):
549
+ return self._value != other._value
550
+ elif other == None:
551
+ return False
552
+ return NotImplemented
553
+
554
+ def __gt__(self, other):
555
+ if isinstance(other, self.__class__):
556
+ return self._value > other._value;
557
+ elif other == None:
558
+ return False
559
+ return NotImplemented
560
+
561
+ def __ge__(self, other):
562
+ if isinstance(other, self.__class__):
563
+ return self._value >= other._value
564
+ elif other == None:
565
+ return False
566
+ return NotImplemented
567
+
568
+ def _getName(self):
569
+ return self._name
570
+
571
+ def _getValue(self):
572
+ return self._value
573
+
574
+ name = property(_getName)
575
+ value = property(_getValue)
576
+
577
+ class SlicedData(object):
578
+ #
579
+ # Members:
580
+ #
581
+ # slices - tuple of SliceInfo
582
+ #
583
+ pass
584
+
585
+ class SliceInfo(object):
586
+ #
587
+ # Members:
588
+ #
589
+ # typeId - string
590
+ # compactId - int
591
+ # bytes - string/bytes
592
+ # instances - tuple of Ice.Value
593
+ # hasOptionalMembers - boolean
594
+ # isLastSlice - boolean
595
+ pass
596
+
597
+ #
598
+ # Native PropertiesAdmin admin facet.
599
+ #
600
+ NativePropertiesAdmin = IcePy.NativePropertiesAdmin
601
+
602
+ class PropertiesAdminUpdateCallback(object):
603
+ '''Callback class to get notifications of property updates passed
604
+ through the Properties admin facet'''
605
+
606
+ def updated(self, props):
607
+ pass
608
+
609
+ class UnknownSlicedValue(Value):
610
+ #
611
+ # Members:
612
+ #
613
+ # unknownTypeId - string
614
+
615
+ def ice_id(self):
616
+ return self.unknownTypeId
617
+
618
+ def getSliceDir():
619
+ '''Convenience function for locating the directory containing the Slice files.'''
620
+
621
+ #
622
+ # Get the parent of the directory containing this file (__init__.py).
623
+ #
624
+ pyHome = os.path.join(os.path.dirname(__file__), "..")
625
+
626
+ #
627
+ # Detect setup.py installation in site-packages. The slice
628
+ # files live one level above this file.
629
+ #
630
+ dir = os.path.join(pyHome, "slice")
631
+ if os.path.isdir(dir):
632
+ return dir
633
+
634
+ #
635
+ # For an installation from a source distribution, a binary tarball, or a
636
+ # Windows installer, the "slice" directory is a sibling of the "python"
637
+ # directory.
638
+ #
639
+ dir = os.path.join(pyHome, "..", "slice")
640
+ if os.path.exists(dir):
641
+ return os.path.normpath(dir)
642
+
643
+ #
644
+ # In a source distribution, the "slice" directory is an extra level higher.
645
+ # directory.
646
+ #
647
+ dir = os.path.join(pyHome, "..", "..", "slice")
648
+ if os.path.exists(dir):
649
+ return os.path.normpath(dir)
650
+
651
+ if sys.platform[:5] == "linux":
652
+ #
653
+ # Check the default Linux location.
654
+ #
655
+ dir = os.path.join("/", "usr", "share", "ice", "slice")
656
+ if os.path.exists(dir):
657
+ return dir
658
+
659
+ elif sys.platform == "darwin":
660
+ #
661
+ # Check the default macOS homebrew location.
662
+ #
663
+ dir = os.path.join("/", "usr", "local", "share", "ice", "slice")
664
+ if os.path.exists(dir):
665
+ return dir
666
+
667
+ return None
668
+
669
+ #
670
+ # Utilities for use by generated code.
671
+ #
672
+
673
+ _pendingModules = {}
674
+
675
+ def openModule(name):
676
+ global _pendingModules
677
+ if name in sys.modules:
678
+ result = sys.modules[name]
679
+ elif name in _pendingModules:
680
+ result = _pendingModules[name]
681
+ else:
682
+ result = createModule(name)
683
+
684
+ return result
685
+
686
+ def createModule(name):
687
+ global _pendingModules
688
+ l = name.split(".")
689
+ curr = ''
690
+ mod = None
691
+
692
+ for s in l:
693
+ curr = curr + s
694
+
695
+ if curr in sys.modules:
696
+ mod = sys.modules[curr]
697
+ elif curr in _pendingModules:
698
+ mod = _pendingModules[curr]
699
+ else:
700
+ nmod = types.ModuleType(curr)
701
+ _pendingModules[curr] = nmod
702
+ mod = nmod
703
+
704
+ curr = curr + "."
705
+
706
+ return mod
707
+
708
+ def updateModule(name):
709
+ global _pendingModules
710
+ if name in _pendingModules:
711
+ pendingModule = _pendingModules[name]
712
+ mod = sys.modules[name]
713
+ mod.__dict__.update(pendingModule.__dict__)
714
+ del _pendingModules[name]
715
+
716
+ def updateModules():
717
+ global _pendingModules
718
+ for name in _pendingModules.keys():
719
+ if name in sys.modules:
720
+ sys.modules[name].__dict__.update(_pendingModules[name].__dict__)
721
+ else:
722
+ sys.modules[name] = _pendingModules[name]
723
+ _pendingModules = {}
724
+
725
+ def createTempClass():
726
+ class __temp: pass
727
+ return __temp
728
+
729
+ class FormatType(object):
730
+ def __init__(self, val):
731
+ assert(val >= 0 and val < 3)
732
+ self.value = val
733
+
734
+ FormatType.DefaultFormat = FormatType(0)
735
+ FormatType.CompactFormat = FormatType(1)
736
+ FormatType.SlicedFormat = FormatType(2)
737
+
738
+ #
739
+ # Forward declarations.
740
+ #
741
+ IcePy._t_Object = IcePy.declareClass('::Ice::Object')
742
+ IcePy._t_Value = IcePy.declareValue('::Ice::Object')
743
+ IcePy._t_ObjectPrx = IcePy.declareProxy('::Ice::Object')
744
+ IcePy._t_LocalObject = IcePy.declareValue('::Ice::LocalObject')
745
+
746
+ #
747
+ # Slice checksum dictionary.
748
+ #
749
+ sliceChecksums = {}
750
+
751
+ #
752
+ # Import generated Ice modules.
753
+ #
754
+ import Ice.BuiltinSequences_ice
755
+ import Ice.Current_ice
756
+ import Ice.Communicator_ice
757
+ import Ice.ImplicitContext_ice
758
+ import Ice.Endpoint_ice
759
+ import Ice.EndpointTypes_ice
760
+ import Ice.Identity_ice
761
+ import Ice.LocalException_ice
762
+ import Ice.Locator_ice
763
+ import Ice.Logger_ice
764
+ import Ice.ObjectAdapter_ice
765
+ import Ice.ObjectFactory_ice
766
+ import Ice.ValueFactory_ice
767
+ import Ice.Process_ice
768
+ import Ice.Properties_ice
769
+ import Ice.RemoteLogger_ice
770
+ import Ice.Router_ice
771
+ import Ice.ServantLocator_ice
772
+ import Ice.Connection_ice
773
+ import Ice.Version_ice
774
+ import Ice.Instrumentation_ice
775
+ import Ice.Metrics_ice
776
+
777
+ #
778
+ # Replace EndpointInfo with our implementation.
779
+ #
780
+ del EndpointInfo
781
+ EndpointInfo = IcePy.EndpointInfo
782
+ del IPEndpointInfo
783
+ IPEndpointInfo = IcePy.IPEndpointInfo
784
+ del TCPEndpointInfo
785
+ TCPEndpointInfo = IcePy.TCPEndpointInfo
786
+ del UDPEndpointInfo
787
+ UDPEndpointInfo = IcePy.UDPEndpointInfo
788
+ del WSEndpointInfo
789
+ WSEndpointInfo = IcePy.WSEndpointInfo
790
+ del OpaqueEndpointInfo
791
+ OpaqueEndpointInfo = IcePy.OpaqueEndpointInfo
792
+
793
+ SSLEndpointInfo = IcePy.SSLEndpointInfo
794
+
795
+ #
796
+ # Replace ConnectionInfo with our implementation.
797
+ #
798
+ del ConnectionInfo
799
+ ConnectionInfo = IcePy.ConnectionInfo
800
+ del IPConnectionInfo
801
+ IPConnectionInfo = IcePy.IPConnectionInfo
802
+ del TCPConnectionInfo
803
+ TCPConnectionInfo = IcePy.TCPConnectionInfo
804
+ del UDPConnectionInfo
805
+ UDPConnectionInfo = IcePy.UDPConnectionInfo
806
+ del WSConnectionInfo
807
+ WSConnectionInfo = IcePy.WSConnectionInfo
808
+
809
+ SSLConnectionInfo = IcePy.SSLConnectionInfo
810
+
811
+ class ThreadNotification(object):
812
+ '''Base class for thread notification callbacks. A subclass must
813
+ define the start and stop methods.'''
814
+
815
+ def __init__(self):
816
+ pass
817
+
818
+ def start():
819
+ '''Invoked in the context of a thread created by the Ice run time.'''
820
+ pass
821
+
822
+ def stop():
823
+ '''Invoked in the context of an Ice run-time thread that is about
824
+ to terminate.'''
825
+ pass
826
+
827
+ class BatchRequestInterceptor(object):
828
+ '''Base class for batch request interceptor. A subclass must
829
+ define the enqueue method.'''
830
+
831
+ def __init__(self):
832
+ pass
833
+
834
+ def enqueue(self, request, queueCount, queueSize):
835
+ '''Invoked when a request is batched.'''
836
+ pass
837
+
838
+ #
839
+ # Initialization data.
840
+ #
841
+ class InitializationData(object):
842
+ '''The attributes of this class are used to initialize a new
843
+ communicator instance. The supported attributes are as follows:
844
+
845
+ properties: An instance of Ice.Properties. You can use the
846
+ Ice.createProperties function to create a new property set.
847
+
848
+ logger: An instance of Ice.Logger.
849
+
850
+ threadStart: A callable that is invoked for each new Ice thread that is started.
851
+
852
+ threadStop: A callable that is invoked when an Ice thread is stopped.
853
+
854
+ dispatcher: A callable that is invoked when Ice needs to dispatch an activity. The callable
855
+ receives two arguments: a callable and an Ice.Connection object. The dispatcher must
856
+ eventually invoke the callable with no arguments.
857
+
858
+ batchRequestInterceptor: A callable that will be invoked when a batch request is queued.
859
+ The callable receives three arguments: a BatchRequest object, an integer representing
860
+ the number of requests in the queue, and an integer representing the number of bytes
861
+ consumed by the requests in the queue. The interceptor must eventually invoke the
862
+ enqueue method on the BatchRequest object.
863
+
864
+ valueFactoryManager: An object that implements ValueFactoryManager.
865
+ '''
866
+ def __init__(self):
867
+ self.properties = None
868
+ self.logger = None
869
+ self.threadHook = None # Deprecated.
870
+ self.threadStart = None
871
+ self.threadStop = None
872
+ self.dispatcher = None
873
+ self.batchRequestInterceptor = None
874
+ self.valueFactoryManager = None
875
+
876
+ #
877
+ # Communicator wrapper.
878
+ #
879
+ class CommunicatorI(Communicator):
880
+ def __init__(self, impl):
881
+ self._impl = impl
882
+ impl._setWrapper(self)
883
+
884
+ def __enter__(self):
885
+ return self
886
+
887
+ def __exit__(self, type, value, traceback):
888
+ self._impl.destroy()
889
+
890
+ def getImpl(self):
891
+ return self._impl
892
+
893
+ def destroy(self):
894
+ self._impl.destroy()
895
+
896
+ def shutdown(self):
897
+ self._impl.shutdown()
898
+
899
+ def waitForShutdown(self):
900
+ #
901
+ # If invoked by the main thread, waitForShutdown only blocks for
902
+ # the specified timeout in order to give us a chance to handle
903
+ # signals.
904
+ #
905
+ while not self._impl.waitForShutdown(500):
906
+ pass
907
+
908
+ def isShutdown(self):
909
+ return self._impl.isShutdown()
910
+
911
+ def stringToProxy(self, str):
912
+ return self._impl.stringToProxy(str)
913
+
914
+ def proxyToString(self, obj):
915
+ return self._impl.proxyToString(obj)
916
+
917
+ def propertyToProxy(self, str):
918
+ return self._impl.propertyToProxy(str)
919
+
920
+ def proxyToProperty(self, obj, str):
921
+ return self._impl.proxyToProperty(obj, str)
922
+
923
+ def stringToIdentity(self, str):
924
+ return self._impl.stringToIdentity(str)
925
+
926
+ def identityToString(self, ident):
927
+ return self._impl.identityToString(ident)
928
+
929
+ def createObjectAdapter(self, name):
930
+ adapter = self._impl.createObjectAdapter(name)
931
+ return ObjectAdapterI(adapter)
932
+
933
+ def createObjectAdapterWithEndpoints(self, name, endpoints):
934
+ adapter = self._impl.createObjectAdapterWithEndpoints(name, endpoints)
935
+ return ObjectAdapterI(adapter)
936
+
937
+ def createObjectAdapterWithRouter(self, name, router):
938
+ adapter = self._impl.createObjectAdapterWithRouter(name, router)
939
+ return ObjectAdapterI(adapter)
940
+
941
+ def addObjectFactory(self, factory, id):
942
+ # The extension implementation requires an extra argument that is a value factory
943
+ self._impl.addObjectFactory(factory, id, lambda s, factory=factory: factory.create(s))
944
+
945
+ def findObjectFactory(self, id):
946
+ return self._impl.findObjectFactory(id)
947
+
948
+ def getValueFactoryManager(self):
949
+ return self._impl.getValueFactoryManager()
950
+
951
+ def getImplicitContext(self):
952
+ context = self._impl.getImplicitContext()
953
+ if context == None:
954
+ return None;
955
+ else:
956
+ return ImplicitContextI(context)
957
+
958
+ def getProperties(self):
959
+ properties = self._impl.getProperties()
960
+ return PropertiesI(properties)
961
+
962
+ def getLogger(self):
963
+ logger = self._impl.getLogger()
964
+ if isinstance(logger, Logger):
965
+ return logger
966
+ else:
967
+ return LoggerI(logger)
968
+
969
+ def getStats(self):
970
+ raise RuntimeError("operation `getStats' not implemented")
971
+
972
+ def getDefaultRouter(self):
973
+ return self._impl.getDefaultRouter()
974
+
975
+ def setDefaultRouter(self, rtr):
976
+ self._impl.setDefaultRouter(rtr)
977
+
978
+ def getDefaultLocator(self):
979
+ return self._impl.getDefaultLocator()
980
+
981
+ def setDefaultLocator(self, loc):
982
+ self._impl.setDefaultLocator(loc)
983
+
984
+ def getPluginManager(self):
985
+ raise RuntimeError("operation `getPluginManager' not implemented")
986
+
987
+ def flushBatchRequests(self, compress):
988
+ self._impl.flushBatchRequests(compress)
989
+
990
+ def flushBatchRequestsAsync(self, compress):
991
+ return self._impl.flushBatchRequestsAsync(compress)
992
+
993
+ def begin_flushBatchRequests(self, compress, _ex=None, _sent=None):
994
+ return self._impl.begin_flushBatchRequests(compress, _ex, _sent)
995
+
996
+ def end_flushBatchRequests(self, r):
997
+ return self._impl.end_flushBatchRequests(r)
998
+
999
+ def createAdmin(self, adminAdapter, adminIdentity):
1000
+ return self._impl.createAdmin(adminAdapter, adminIdentity)
1001
+
1002
+ def getAdmin(self):
1003
+ return self._impl.getAdmin()
1004
+
1005
+ def addAdminFacet(self, servant, facet):
1006
+ self._impl.addAdminFacet(servant, facet)
1007
+
1008
+ def findAdminFacet(self, facet):
1009
+ return self._impl.findAdminFacet(facet)
1010
+
1011
+ def findAllAdminFacets(self):
1012
+ return self._impl.findAllAdminFacets()
1013
+
1014
+ def removeAdminFacet(self, facet):
1015
+ return self._impl.removeAdminFacet(facet)
1016
+
1017
+ #
1018
+ # Ice.initialize()
1019
+ #
1020
+ def initialize(args=None, data=None):
1021
+ '''Initializes a new communicator. The optional arguments represent
1022
+ an argument list (such as sys.argv) and an instance of InitializationData.
1023
+ You can invoke this function as follows:
1024
+
1025
+ Ice.initialize()
1026
+ Ice.initialize(args)
1027
+ Ice.initialize(data)
1028
+ Ice.initialize(args, data)
1029
+
1030
+ If you supply an argument list, the function removes those arguments from
1031
+ the list that were recognized by the Ice run time.
1032
+ '''
1033
+ communicator = IcePy.Communicator(args, data)
1034
+ return CommunicatorI(communicator)
1035
+
1036
+ #
1037
+ # Ice.identityToString
1038
+ #
1039
+ def identityToString(id, toStringMode=None):
1040
+ return IcePy.identityToString(id, toStringMode)
1041
+
1042
+ #
1043
+ # Ice.stringToIdentity
1044
+ #
1045
+ def stringToIdentity(str):
1046
+ return IcePy.stringToIdentity(str)
1047
+
1048
+ #
1049
+ # ObjectAdapter wrapper.
1050
+ #
1051
+ class ObjectAdapterI(ObjectAdapter):
1052
+ def __init__(self, impl):
1053
+ self._impl = impl
1054
+
1055
+ def getName(self):
1056
+ return self._impl.getName()
1057
+
1058
+ def getCommunicator(self):
1059
+ communicator = self._impl.getCommunicator()
1060
+ return communicator._getWrapper()
1061
+
1062
+ def activate(self):
1063
+ self._impl.activate()
1064
+
1065
+ def hold(self):
1066
+ self._impl.hold()
1067
+
1068
+ def waitForHold(self):
1069
+ #
1070
+ # If invoked by the main thread, waitForHold only blocks for
1071
+ # the specified timeout in order to give us a chance to handle
1072
+ # signals.
1073
+ #
1074
+ while not self._impl.waitForHold(1000):
1075
+ pass
1076
+
1077
+ def deactivate(self):
1078
+ self._impl.deactivate()
1079
+
1080
+ def waitForDeactivate(self):
1081
+ #
1082
+ # If invoked by the main thread, waitForDeactivate only blocks for
1083
+ # the specified timeout in order to give us a chance to handle
1084
+ # signals.
1085
+ #
1086
+ while not self._impl.waitForDeactivate(1000):
1087
+ pass
1088
+
1089
+ def isDeactivated(self):
1090
+ self._impl.isDeactivated()
1091
+
1092
+ def destroy(self):
1093
+ self._impl.destroy()
1094
+
1095
+ def add(self, servant, id):
1096
+ return self._impl.add(servant, id)
1097
+
1098
+ def addFacet(self, servant, id, facet):
1099
+ return self._impl.addFacet(servant, id, facet)
1100
+
1101
+ def addWithUUID(self, servant):
1102
+ return self._impl.addWithUUID(servant)
1103
+
1104
+ def addFacetWithUUID(self, servant, facet):
1105
+ return self._impl.addFacetWIthUUID(servant, facet)
1106
+
1107
+ def addDefaultServant(self, servant, category):
1108
+ self._impl.addDefaultServant(servant, category)
1109
+
1110
+ def remove(self, id):
1111
+ return self._impl.remove(id)
1112
+
1113
+ def removeFacet(self, id, facet):
1114
+ return self._impl.removeFacet(id, facet)
1115
+
1116
+ def removeAllFacets(self, id):
1117
+ return self._impl.removeAllFacets(id)
1118
+
1119
+ def removeDefaultServant(self, category):
1120
+ return self._impl.removeDefaultServant(category)
1121
+
1122
+ def find(self, id):
1123
+ return self._impl.find(id)
1124
+
1125
+ def findFacet(self, id, facet):
1126
+ return self._impl.findFacet(id, facet)
1127
+
1128
+ def findAllFacets(self, id):
1129
+ return self._impl.findAllFacets(id)
1130
+
1131
+ def findByProxy(self, proxy):
1132
+ return self._impl.findByProxy(proxy)
1133
+
1134
+ def findDefaultServant(self, category):
1135
+ return self._impl.findDefaultServant(category)
1136
+
1137
+ def addServantLocator(self, locator, category):
1138
+ self._impl.addServantLocator(locator, category)
1139
+
1140
+ def removeServantLocator(self, category):
1141
+ return self._impl.removeServantLocator(category)
1142
+
1143
+ def findServantLocator(self, category):
1144
+ return self._impl.findServantLocator(category)
1145
+
1146
+ def createProxy(self, id):
1147
+ return self._impl.createProxy(id)
1148
+
1149
+ def createDirectProxy(self, id):
1150
+ return self._impl.createDirectProxy(id)
1151
+
1152
+ def createIndirectProxy(self, id):
1153
+ return self._impl.createIndirectProxy(id)
1154
+
1155
+ def createReverseProxy(self, id):
1156
+ return self._impl.createReverseProxy(id)
1157
+
1158
+ def setLocator(self, loc):
1159
+ self._impl.setLocator(loc)
1160
+
1161
+ def getLocator(self):
1162
+ return self._impl.getLocator()
1163
+
1164
+ def getEndpoints(self):
1165
+ return self._impl.getEndpoints()
1166
+
1167
+ def refreshPublishedEndpoints(self):
1168
+ self._impl.refreshPublishedEndpoints()
1169
+
1170
+ def getPublishedEndpoints(self):
1171
+ return self._impl.getPublishedEndpoints()
1172
+
1173
+ def setPublishedEndpoints(self, newEndpoints):
1174
+ self._impl.setPublishedEndpoints(newEndpoints)
1175
+
1176
+ #
1177
+ # Logger wrapper.
1178
+ #
1179
+ class LoggerI(Logger):
1180
+ def __init__(self, impl):
1181
+ self._impl = impl
1182
+
1183
+ def _print(self, message):
1184
+ return self._impl._print(message)
1185
+
1186
+ def trace(self, category, message):
1187
+ return self._impl.trace(category, message)
1188
+
1189
+ def warning(self, message):
1190
+ return self._impl.warning(message)
1191
+
1192
+ def error(self, message):
1193
+ return self._impl.error(message)
1194
+
1195
+ def getPrefix(self):
1196
+ return self._impl.getPrefix()
1197
+
1198
+ def cloneWithPrefix(self, prefix):
1199
+ logger = self._impl.cloneWithPrefix(prefix)
1200
+ return LoggerI(logger)
1201
+
1202
+ #
1203
+ # Properties wrapper.
1204
+ #
1205
+ class PropertiesI(Properties):
1206
+ def __init__(self, impl):
1207
+ self._impl = impl
1208
+
1209
+ def getProperty(self, key):
1210
+ return self._impl.getProperty(key)
1211
+
1212
+ def getPropertyWithDefault(self, key, value):
1213
+ return self._impl.getPropertyWithDefault(key, value)
1214
+
1215
+ def getPropertyAsInt(self, key):
1216
+ return self._impl.getPropertyAsInt(key)
1217
+
1218
+ def getPropertyAsIntWithDefault(self, key, value):
1219
+ return self._impl.getPropertyAsIntWithDefault(key, value)
1220
+
1221
+ def getPropertyAsList(self, key):
1222
+ return self._impl.getPropertyAsList(key)
1223
+
1224
+ def getPropertyAsListWithDefault(self, key, value):
1225
+ return self._impl.getPropertyAsListWithDefault(key, value)
1226
+
1227
+ def getPropertiesForPrefix(self, prefix):
1228
+ return self._impl.getPropertiesForPrefix(prefix)
1229
+
1230
+ def setProperty(self, key, value):
1231
+ self._impl.setProperty(key, value)
1232
+
1233
+ def getCommandLineOptions(self):
1234
+ return self._impl.getCommandLineOptions()
1235
+
1236
+ def parseCommandLineOptions(self, prefix, options):
1237
+ return self._impl.parseCommandLineOptions(prefix, options)
1238
+
1239
+ def parseIceCommandLineOptions(self, options):
1240
+ return self._impl.parseIceCommandLineOptions(options)
1241
+
1242
+ def load(self, file):
1243
+ self._impl.load(file)
1244
+
1245
+ def clone(self):
1246
+ properties = self._impl.clone()
1247
+ return PropertiesI(properties)
1248
+
1249
+ def __iter__(self):
1250
+ dict = self._impl.getPropertiesForPrefix('')
1251
+ return iter(dict)
1252
+
1253
+ def __str__(self):
1254
+ return str(self._impl)
1255
+
1256
+ #
1257
+ # Ice.createProperties()
1258
+ #
1259
+ def createProperties(args=None, defaults=None):
1260
+ '''Creates a new property set. The optional arguments represent
1261
+ an argument list (such as sys.argv) and a property set that supplies
1262
+ default values. You can invoke this function as follows:
1263
+
1264
+ Ice.createProperties()
1265
+ Ice.createProperties(args)
1266
+ Ice.createProperties(defaults)
1267
+ Ice.createProperties(args, defaults)
1268
+
1269
+ If you supply an argument list, the function removes those arguments
1270
+ from the list that were recognized by the Ice run time.
1271
+ '''
1272
+
1273
+ properties = IcePy.createProperties(args, defaults)
1274
+ return PropertiesI(properties)
1275
+
1276
+ #
1277
+ # Ice.getProcessLogger()
1278
+ # Ice.setProcessLogger()
1279
+ #
1280
+ def getProcessLogger():
1281
+ '''Returns the default logger object.'''
1282
+ logger = IcePy.getProcessLogger()
1283
+ if isinstance(logger, Logger):
1284
+ return logger
1285
+ else:
1286
+ return LoggerI(logger)
1287
+
1288
+ def setProcessLogger(logger):
1289
+ '''Sets the default logger object.'''
1290
+ IcePy.setProcessLogger(logger)
1291
+
1292
+ #
1293
+ # ImplicitContext wrapper
1294
+ #
1295
+ class ImplicitContextI(ImplicitContext):
1296
+ def __init__(self, impl):
1297
+ self._impl = impl
1298
+
1299
+ def setContext(self, ctx):
1300
+ self._impl.setContext(ctx)
1301
+
1302
+ def getContext(self):
1303
+ return self._impl.getContext()
1304
+
1305
+ def containsKey(self, key):
1306
+ return self._impl.containsKey(key)
1307
+
1308
+ def get(self, key):
1309
+ return self._impl.get(key)
1310
+
1311
+ def put(self, key, value):
1312
+ return self._impl.put(key, value)
1313
+
1314
+ def remove(self, key):
1315
+ return self._impl.remove(key)
1316
+
1317
+ #
1318
+ # Its not possible to block in a python signal handler since this
1319
+ # blocks the main thread from doing further work. As such we queue the
1320
+ # signal with a worker thread which then "dispatches" the signal to
1321
+ # the registered callback object.
1322
+ #
1323
+ # Note the interface is the same as the C++ CtrlCHandler
1324
+ # implementation, however, the implementation is different.
1325
+ #
1326
+ class CtrlCHandler(threading.Thread):
1327
+ # Class variable referring to the one and only handler for use
1328
+ # from the signal handling callback.
1329
+ _self = None
1330
+
1331
+ def __init__(self):
1332
+ threading.Thread.__init__(self)
1333
+
1334
+ if CtrlCHandler._self != None:
1335
+ raise RuntimeError("Only a single instance of a CtrlCHandler can be instantiated.")
1336
+ CtrlCHandler._self = self
1337
+
1338
+ # State variables. These are not class static variables.
1339
+ self._condVar = threading.Condition()
1340
+ self._queue = []
1341
+ self._done = False
1342
+ self._callback = None
1343
+
1344
+ #
1345
+ # Setup and install signal handlers
1346
+ #
1347
+ if 'SIGHUP' in signal.__dict__:
1348
+ signal.signal(signal.SIGHUP, CtrlCHandler.signalHandler)
1349
+ if 'SIGBREAK' in signal.__dict__:
1350
+ signal.signal(signal.SIGBREAK, CtrlCHandler.signalHandler)
1351
+ signal.signal(signal.SIGINT, CtrlCHandler.signalHandler)
1352
+ signal.signal(signal.SIGTERM, CtrlCHandler.signalHandler)
1353
+
1354
+ # Start the thread once everything else is done.
1355
+ self.start()
1356
+
1357
+ # Dequeue and dispatch signals.
1358
+ def run(self):
1359
+ while True:
1360
+ self._condVar.acquire()
1361
+ while len(self._queue) == 0 and not self._done:
1362
+ self._condVar.wait()
1363
+ if self._done:
1364
+ self._condVar.release()
1365
+ break
1366
+ sig, callback = self._queue.pop()
1367
+ self._condVar.release()
1368
+ if callback:
1369
+ callback(sig)
1370
+
1371
+ # Destroy the object. Wait for the thread to terminate and cleanup
1372
+ # the internal state.
1373
+ def destroy(self):
1374
+ self._condVar.acquire()
1375
+ self._done = True
1376
+ self._condVar.notify()
1377
+ self._condVar.release()
1378
+
1379
+ # Wait for the thread to terminate
1380
+ self.join()
1381
+ #
1382
+ # Cleanup any state set by the CtrlCHandler.
1383
+ #
1384
+ if 'SIGHUP' in signal.__dict__:
1385
+ signal.signal(signal.SIGHUP, signal.SIG_DFL)
1386
+ if 'SIGBREAK' in signal.__dict__:
1387
+ signal.signal(signal.SIGBREAK, signal.SIG_DFL)
1388
+ signal.signal(signal.SIGINT, signal.SIG_DFL)
1389
+ signal.signal(signal.SIGTERM, signal.SIG_DFL)
1390
+ CtrlCHandler._self = None
1391
+
1392
+ def setCallback(self, callback):
1393
+ self._condVar.acquire()
1394
+ self._callback = callback
1395
+ self._condVar.release()
1396
+
1397
+ def getCallback(self):
1398
+ self._condVar.acquire()
1399
+ callback = self._callback
1400
+ self._condVar.release()
1401
+ return callback
1402
+
1403
+ # Private. Only called by the signal handling mechanism.
1404
+ def signalHandler(self, sig, frame):
1405
+ self._self._condVar.acquire()
1406
+ #
1407
+ # The signal AND the current callback are queued together.
1408
+ #
1409
+ self._self._queue.append([sig, self._self._callback])
1410
+ self._self._condVar.notify()
1411
+ self._self._condVar.release()
1412
+ signalHandler = classmethod(signalHandler)
1413
+
1414
+ #
1415
+ # Application logger.
1416
+ #
1417
+ class _ApplicationLoggerI(Logger):
1418
+ def __init__(self, prefix):
1419
+ if len(prefix) > 0:
1420
+ self._prefix = prefix + ": "
1421
+ else:
1422
+ self._prefix = ""
1423
+ self._outputMutex = threading.Lock()
1424
+
1425
+ def _print(self, message):
1426
+ s = "[ " + str(datetime.datetime.now()) + " " + self._prefix
1427
+ self._outputMutex.acquire()
1428
+ sys.stderr.write(message + "\n")
1429
+ self._outputMutex.release()
1430
+
1431
+ def trace(self, category, message):
1432
+ s = "[ " + str(datetime.datetime.now()) + " " + self._prefix
1433
+ if len(category) > 0:
1434
+ s += category + ": "
1435
+ s += message + " ]"
1436
+
1437
+ s = s.replace("\n", "\n ")
1438
+
1439
+ self._outputMutex.acquire()
1440
+ sys.stderr.write(s + "\n")
1441
+ self._outputMutex.release()
1442
+
1443
+ def warning(self, message):
1444
+ self._outputMutex.acquire()
1445
+ sys.stderr.write(str(datetime.datetime.now()) + " " + self._prefix + "warning: " + message + "\n")
1446
+ self._outputMutex.release()
1447
+
1448
+ def error(self, message):
1449
+ self._outputMutex.acquire()
1450
+ sys.stderr.write(str(datetime.datetime.now()) + " " + self._prefix + "error: " + message + "\n")
1451
+ self._outputMutex.release()
1452
+
1453
+ #
1454
+ # Application class.
1455
+ #
1456
+ import signal
1457
+ class Application(object):
1458
+ '''Convenience class that initializes a communicator and reacts
1459
+ gracefully to signals. An application must define a subclass
1460
+ of this class and supply an implementation of the run method.
1461
+ '''
1462
+
1463
+ def __init__(self, signalPolicy=0): # HandleSignals=0
1464
+ '''The constructor accepts an optional argument indicating
1465
+ whether to handle signals. The value should be either
1466
+ Application.HandleSignals (the default) or
1467
+ Application.NoSignalHandling.
1468
+ '''
1469
+ if type(self) == Application:
1470
+ raise RuntimeError("Ice.Application is an abstract class")
1471
+ Application._signalPolicy = signalPolicy
1472
+
1473
+ def main(self, args, configFile=None, initData=None):
1474
+ '''The main entry point for the Application class. The arguments
1475
+ are an argument list (such as sys.argv), the name of an Ice
1476
+ configuration file (optional), and an instance of
1477
+ InitializationData (optional). This method does not return
1478
+ until after the completion of the run method. The return
1479
+ value is an integer representing the exit status.
1480
+ '''
1481
+
1482
+ if Application._communicator:
1483
+ getProcessLogger().error(args[0] + ": only one instance of the Application class can be used")
1484
+ return 1
1485
+
1486
+ #
1487
+ # We parse the properties here to extract Ice.ProgramName.
1488
+ #
1489
+ if not initData:
1490
+ initData = InitializationData()
1491
+ if configFile:
1492
+ try:
1493
+ initData.properties = createProperties(None, initData.properties)
1494
+ initData.properties.load(configFile)
1495
+ except:
1496
+ getProcessLogger().error(traceback.format_exc())
1497
+ return 1
1498
+ initData.properties = createProperties(args, initData.properties)
1499
+
1500
+ #
1501
+ # If the process logger is the default logger, we replace it with a
1502
+ # a logger which is using the program name for the prefix.
1503
+ #
1504
+ if isinstance(getProcessLogger(), LoggerI):
1505
+ setProcessLogger(_ApplicationLoggerI(initData.properties.getProperty("Ice.ProgramName")))
1506
+
1507
+ #
1508
+ # Install our handler for the signals we are interested in. We assume main()
1509
+ # is called from the main thread.
1510
+ #
1511
+ if Application._signalPolicy == Application.HandleSignals:
1512
+ Application._ctrlCHandler = CtrlCHandler()
1513
+
1514
+ try:
1515
+ Application._interrupted = False
1516
+ Application._appName = initData.properties.getPropertyWithDefault("Ice.ProgramName", args[0])
1517
+ Application._application = self
1518
+
1519
+ #
1520
+ # Used by _destroyOnInterruptCallback and _shutdownOnInterruptCallback.
1521
+ #
1522
+ Application._nohup = initData.properties.getPropertyAsInt("Ice.Nohup") > 0
1523
+
1524
+ #
1525
+ # The default is to destroy when a signal is received.
1526
+ #
1527
+ if Application._signalPolicy == Application.HandleSignals:
1528
+ Application.destroyOnInterrupt()
1529
+
1530
+ status = self.doMain(args, initData)
1531
+ except:
1532
+ getProcessLogger().error(traceback.format_exc())
1533
+ status = 1
1534
+ #
1535
+ # Set _ctrlCHandler to 0 only once communicator.destroy() has
1536
+ # completed.
1537
+ #
1538
+ if Application._signalPolicy == Application.HandleSignals:
1539
+ Application._ctrlCHandler.destroy()
1540
+ Application._ctrlCHandler = None
1541
+
1542
+ return status
1543
+
1544
+ def doMain(self, args, initData):
1545
+ try:
1546
+ Application._communicator = initialize(args, initData)
1547
+ Application._destroyed = False
1548
+ status = self.run(args)
1549
+
1550
+ except:
1551
+ getProcessLogger().error(traceback.format_exc())
1552
+ status = 1
1553
+
1554
+ #
1555
+ # Don't want any new interrupt and at this point (post-run),
1556
+ # it would not make sense to release a held signal to run
1557
+ # shutdown or destroy.
1558
+ #
1559
+ if Application._signalPolicy == Application.HandleSignals:
1560
+ Application.ignoreInterrupt()
1561
+
1562
+ Application._condVar.acquire()
1563
+ while Application._callbackInProgress:
1564
+ Application._condVar.wait()
1565
+ if Application._destroyed:
1566
+ Application._communicator = None
1567
+ else:
1568
+ Application._destroyed = True
1569
+ #
1570
+ # And _communicator != 0, meaning will be destroyed
1571
+ # next, _destroyed = true also ensures that any
1572
+ # remaining callback won't do anything
1573
+ #
1574
+ Application._application = None
1575
+ Application._condVar.release()
1576
+
1577
+ if Application._communicator:
1578
+ try:
1579
+ Application._communicator.destroy()
1580
+ except:
1581
+ getProcessLogger().error(traceback.format_exc())
1582
+ status = 1
1583
+ Application._communicator = None
1584
+ return status
1585
+
1586
+ def run(self, args):
1587
+ '''This method must be overridden in a subclass. The base
1588
+ class supplies an argument list from which all Ice arguments
1589
+ have already been removed. The method returns an integer
1590
+ exit status (0 is success, non-zero is failure).
1591
+ '''
1592
+ raise RuntimeError('run() not implemented')
1593
+
1594
+ def interruptCallback(self, sig):
1595
+ '''Subclass hook to intercept an interrupt.'''
1596
+ pass
1597
+
1598
+ def appName(self):
1599
+ '''Returns the application name (the first element of
1600
+ the argument list).'''
1601
+ return self._appName
1602
+ appName = classmethod(appName)
1603
+
1604
+ def communicator(self):
1605
+ '''Returns the communicator that was initialized for
1606
+ the application.'''
1607
+ return self._communicator
1608
+ communicator = classmethod(communicator)
1609
+
1610
+ def destroyOnInterrupt(self):
1611
+ '''Configures the application to destroy its communicator
1612
+ when interrupted by a signal.'''
1613
+ if Application._signalPolicy == Application.HandleSignals:
1614
+ self._condVar.acquire()
1615
+ if self._ctrlCHandler.getCallback() == self._holdInterruptCallback:
1616
+ self._released = True
1617
+ self._condVar.notify()
1618
+ self._ctrlCHandler.setCallback(self._destroyOnInterruptCallback)
1619
+ self._condVar.release()
1620
+ else:
1621
+ getProcessLogger().error(Application._appName + \
1622
+ ": warning: interrupt method called on Application configured to not handle interrupts.")
1623
+ destroyOnInterrupt = classmethod(destroyOnInterrupt)
1624
+
1625
+ def shutdownOnInterrupt(self):
1626
+ '''Configures the application to shutdown its communicator
1627
+ when interrupted by a signal.'''
1628
+ if Application._signalPolicy == Application.HandleSignals:
1629
+ self._condVar.acquire()
1630
+ if self._ctrlCHandler.getCallback() == self._holdInterruptCallback:
1631
+ self._released = True
1632
+ self._condVar.notify()
1633
+ self._ctrlCHandler.setCallback(self._shutdownOnInterruptCallback)
1634
+ self._condVar.release()
1635
+ else:
1636
+ getProcessLogger().error(Application._appName + \
1637
+ ": warning: interrupt method called on Application configured to not handle interrupts.")
1638
+ shutdownOnInterrupt = classmethod(shutdownOnInterrupt)
1639
+
1640
+ def ignoreInterrupt(self):
1641
+ '''Configures the application to ignore signals.'''
1642
+ if Application._signalPolicy == Application.HandleSignals:
1643
+ self._condVar.acquire()
1644
+ if self._ctrlCHandler.getCallback() == self._holdInterruptCallback:
1645
+ self._released = True
1646
+ self._condVar.notify()
1647
+ self._ctrlCHandler.setCallback(None)
1648
+ self._condVar.release()
1649
+ else:
1650
+ getProcessLogger().error(Application._appName + \
1651
+ ": warning: interrupt method called on Application configured to not handle interrupts.")
1652
+ ignoreInterrupt = classmethod(ignoreInterrupt)
1653
+
1654
+ def callbackOnInterrupt(self):
1655
+ '''Configures the application to invoke interruptCallback
1656
+ when interrupted by a signal.'''
1657
+ if Application._signalPolicy == Application.HandleSignals:
1658
+ self._condVar.acquire()
1659
+ if self._ctrlCHandler.getCallback() == self._holdInterruptCallback:
1660
+ self._released = True
1661
+ self._condVar.notify()
1662
+ self._ctrlCHandler.setCallback(self._callbackOnInterruptCallback)
1663
+ self._condVar.release()
1664
+ else:
1665
+ getProcessLogger().error(Application._appName + \
1666
+ ": warning: interrupt method called on Application configured to not handle interrupts.")
1667
+ callbackOnInterrupt = classmethod(callbackOnInterrupt)
1668
+
1669
+ def holdInterrupt(self):
1670
+ '''Configures the application to queue an interrupt for
1671
+ later processing.'''
1672
+ if Application._signalPolicy == Application.HandleSignals:
1673
+ self._condVar.acquire()
1674
+ if self._ctrlCHandler.getCallback() != self._holdInterruptCallback:
1675
+ self._previousCallback = self._ctrlCHandler.getCallback()
1676
+ self._released = False
1677
+ self._ctrlCHandler.setCallback(self._holdInterruptCallback)
1678
+ # else, we were already holding signals
1679
+ self._condVar.release()
1680
+ else:
1681
+ getProcessLogger().error(Application._appName + \
1682
+ ": warning: interrupt method called on Application configured to not handle interrupts.")
1683
+ holdInterrupt = classmethod(holdInterrupt)
1684
+
1685
+ def releaseInterrupt(self):
1686
+ '''Instructs the application to process any queued interrupt.'''
1687
+ if Application._signalPolicy == Application.HandleSignals:
1688
+ self._condVar.acquire()
1689
+ if self._ctrlCHandler.getCallback() == self._holdInterruptCallback:
1690
+ #
1691
+ # Note that it's very possible no signal is held;
1692
+ # in this case the callback is just replaced and
1693
+ # setting _released to true and signalling _condVar
1694
+ # do no harm.
1695
+ #
1696
+ self._released = True
1697
+ self._ctrlCHandler.setCallback(self._previousCallback)
1698
+ self._condVar.notify()
1699
+ # Else nothing to release.
1700
+ self._condVar.release()
1701
+ else:
1702
+ getProcessLogger().error(Application._appName + \
1703
+ ": warning: interrupt method called on Application configured to not handle interrupts.")
1704
+ releaseInterrupt = classmethod(releaseInterrupt)
1705
+
1706
+ def interrupted(self):
1707
+ '''Returns True if the application was interrupted by a
1708
+ signal, or False otherwise.'''
1709
+ self._condVar.acquire()
1710
+ result = self._interrupted
1711
+ self._condVar.release()
1712
+ return result
1713
+ interrupted = classmethod(interrupted)
1714
+
1715
+ def _holdInterruptCallback(self, sig):
1716
+ self._condVar.acquire()
1717
+ while not self._released:
1718
+ self._condVar.wait()
1719
+ if self._destroyed:
1720
+ #
1721
+ # Being destroyed by main thread
1722
+ #
1723
+ self._condVar.release()
1724
+ return
1725
+ callback = self._ctrlCHandler.getCallback()
1726
+ self._condVar.release()
1727
+ if callback:
1728
+ callback(sig)
1729
+ _holdInterruptCallback = classmethod(_holdInterruptCallback)
1730
+
1731
+ def _destroyOnInterruptCallback(self, sig):
1732
+ self._condVar.acquire()
1733
+ if self._destroyed or self._nohup and sig == signal.SIGHUP:
1734
+ #
1735
+ # Being destroyed by main thread, or nohup.
1736
+ #
1737
+ self._condVar.release()
1738
+ return
1739
+
1740
+ self._callbackInProcess = True
1741
+ self._interrupted = True
1742
+ self._destroyed = True
1743
+ self._condVar.release()
1744
+
1745
+ try:
1746
+ self._communicator.destroy()
1747
+ except:
1748
+ getProcessLogger().error(self._appName + " (while destroying in response to signal " + str(sig) + "):" + \
1749
+ traceback.format_exc())
1750
+
1751
+ self._condVar.acquire()
1752
+ self._callbackInProcess = False
1753
+ self._condVar.notify()
1754
+ self._condVar.release()
1755
+ _destroyOnInterruptCallback = classmethod(_destroyOnInterruptCallback)
1756
+
1757
+ def _shutdownOnInterruptCallback(self, sig):
1758
+ self._condVar.acquire()
1759
+ if self._destroyed or self._nohup and sig == signal.SIGHUP:
1760
+ #
1761
+ # Being destroyed by main thread, or nohup.
1762
+ #
1763
+ self._condVar.release()
1764
+ return
1765
+
1766
+ self._callbackInProcess = True
1767
+ self._interrupted = True
1768
+ self._condVar.release()
1769
+
1770
+ try:
1771
+ self._communicator.shutdown()
1772
+ except:
1773
+ getProcessLogger().error(self._appName + " (while shutting down in response to signal " + str(sig) + \
1774
+ "):" + traceback.format_exc())
1775
+
1776
+ self._condVar.acquire()
1777
+ self._callbackInProcess = False
1778
+ self._condVar.notify()
1779
+ self._condVar.release()
1780
+ _shutdownOnInterruptCallback = classmethod(_shutdownOnInterruptCallback)
1781
+
1782
+ def _callbackOnInterruptCallback(self, sig):
1783
+ self._condVar.acquire()
1784
+ if self._destroyed:
1785
+ #
1786
+ # Being destroyed by main thread.
1787
+ #
1788
+ self._condVar.release()
1789
+ return
1790
+ # For SIGHUP the user callback is always called. It can decide
1791
+ # what to do.
1792
+
1793
+ self._callbackInProcess = True
1794
+ self._interrupted = True
1795
+ self._condVar.release()
1796
+
1797
+ try:
1798
+ self._application.interruptCallback(sig)
1799
+ except:
1800
+ getProcessLogger().error(self._appName + " (while interrupting in response to signal " + str(sig) + \
1801
+ "):" + traceback.format_exc())
1802
+
1803
+ self._condVar.acquire()
1804
+ self._callbackInProcess = False
1805
+ self._condVar.notify()
1806
+ self._condVar.release()
1807
+
1808
+ _callbackOnInterruptCallback = classmethod(_callbackOnInterruptCallback)
1809
+
1810
+ HandleSignals = 0
1811
+ NoSignalHandling = 1
1812
+
1813
+ _appName = None
1814
+ _communicator = None
1815
+ _application = None
1816
+ _ctrlCHandler = None
1817
+ _previousCallback = None
1818
+ _interrupted = False
1819
+ _released = False
1820
+ _destroyed = False
1821
+ _callbackInProgress = False
1822
+ _condVar = threading.Condition()
1823
+ _signalPolicy = HandleSignals
1824
+
1825
+ #
1826
+ # Define Ice::Object and Ice::ObjectPrx.
1827
+ #
1828
+ IcePy._t_Object = IcePy.defineClass('::Ice::Object', Object, (), None, ())
1829
+ IcePy._t_Value = IcePy.defineValue('::Ice::Object', Value, -1, (), False, False, None, ())
1830
+ IcePy._t_ObjectPrx = IcePy.defineProxy('::Ice::Object', ObjectPrx)
1831
+ Object._ice_type = IcePy._t_Object
1832
+
1833
+ Object._op_ice_isA = IcePy.Operation('ice_isA', OperationMode.Idempotent, OperationMode.Nonmutating, False, None, (), (((), IcePy._t_string, False, 0),), (), ((), IcePy._t_bool, False, 0), ())
1834
+ Object._op_ice_ping = IcePy.Operation('ice_ping', OperationMode.Idempotent, OperationMode.Nonmutating, False, None, (), (), (), None, ())
1835
+ Object._op_ice_ids = IcePy.Operation('ice_ids', OperationMode.Idempotent, OperationMode.Nonmutating, False, None, (), (), (), ((), _t_StringSeq, False, 0), ())
1836
+ Object._op_ice_id = IcePy.Operation('ice_id', OperationMode.Idempotent, OperationMode.Nonmutating, False, None, (), (), (), ((), IcePy._t_string, False, 0), ())
1837
+
1838
+ IcePy._t_LocalObject = IcePy.defineValue('::Ice::LocalObject', object, -1, (), False, False, None, ())
1839
+
1840
+ IcePy._t_UnknownSlicedValue = IcePy.defineValue('::Ice::UnknownSlicedValue', UnknownSlicedValue, -1, (), True, False, None, ())
1841
+ UnknownSlicedValue._ice_type = IcePy._t_UnknownSlicedValue
1842
+
1843
+ #
1844
+ # Annotate some exceptions.
1845
+ #
1846
+ def SyscallException__str__(self):
1847
+ return "Ice.SyscallException:\n" + os.strerror(self.error)
1848
+ SyscallException.__str__ = SyscallException__str__
1849
+ del SyscallException__str__
1850
+
1851
+ def SocketException__str__(self):
1852
+ return "Ice.SocketException:\n" + os.strerror(self.error)
1853
+ SocketException.__str__ = SocketException__str__
1854
+ del SocketException__str__
1855
+
1856
+ def ConnectFailedException__str__(self):
1857
+ return "Ice.ConnectFailedException:\n" + os.strerror(self.error)
1858
+ ConnectFailedException.__str__ = ConnectFailedException__str__
1859
+ del ConnectFailedException__str__
1860
+
1861
+ def ConnectionRefusedException__str__(self):
1862
+ return "Ice.ConnectionRefusedException:\n" + os.strerror(self.error)
1863
+ ConnectionRefusedException.__str__ = ConnectionRefusedException__str__
1864
+ del ConnectionRefusedException__str__
1865
+
1866
+ def ConnectionLostException__str__(self):
1867
+ if self.error == 0:
1868
+ return "Ice.ConnectionLostException:\nrecv() returned zero"
1869
+ else:
1870
+ return "Ice.ConnectionLostException:\n" + os.strerror(self.error)
1871
+ ConnectionLostException.__str__ = ConnectionLostException__str__
1872
+ del ConnectionLostException__str__
1873
+
1874
+ #
1875
+ # Proxy comparison functions.
1876
+ #
1877
+ def proxyIdentityEqual(lhs, rhs):
1878
+ '''Determines whether the identities of two proxies are equal.'''
1879
+ return proxyIdentityCompare(lhs, rhs) == 0
1880
+
1881
+ def proxyIdentityCompare(lhs, rhs):
1882
+ '''Compares the identities of two proxies.'''
1883
+ if (lhs and not isinstance(lhs, ObjectPrx)) or (rhs and not isinstance(rhs, ObjectPrx)):
1884
+ raise ValueError('argument is not a proxy')
1885
+ if not lhs and not rhs:
1886
+ return 0
1887
+ elif not lhs and rhs:
1888
+ return -1
1889
+ elif lhs and not rhs:
1890
+ return 1
1891
+ else:
1892
+ lid = lhs.ice_getIdentity()
1893
+ rid = rhs.ice_getIdentity()
1894
+ return (lid > rid) - (lid < rid)
1895
+
1896
+ def proxyIdentityAndFacetEqual(lhs, rhs):
1897
+ '''Determines whether the identities and facets of two
1898
+ proxies are equal.'''
1899
+ return proxyIdentityAndFacetCompare(lhs, rhs) == 0
1900
+
1901
+ def proxyIdentityAndFacetCompare(lhs, rhs):
1902
+ '''Compares the identities and facets of two proxies.'''
1903
+ if (lhs and not isinstance(lhs, ObjectPrx)) or (rhs and not isinstance(rhs, ObjectPrx)):
1904
+ raise ValueError('argument is not a proxy')
1905
+ if not lhs and not rhs:
1906
+ return 0
1907
+ elif not lhs and rhs:
1908
+ return -1
1909
+ elif lhs and not rhs:
1910
+ return 1
1911
+ elif lhs.ice_getIdentity() != rhs.ice_getIdentity():
1912
+ lid = lhs.ice_getIdentity()
1913
+ rid = rhs.ice_getIdentity()
1914
+ return (lid > rid) - (lid < rid)
1915
+ else:
1916
+ lf = lhs.ice_getFacet()
1917
+ rf = rhs.ice_getFacet()
1918
+ return (lf > rf) - (lf < rf)
1919
+
1920
+ #
1921
+ # Used by generated code. Defining these in the Ice module means the generated code
1922
+ # can avoid the need to qualify the type() and hash() functions with their module
1923
+ # names. Since the functions are in the __builtin__ module (for Python 2.x) and the
1924
+ # builtins module (for Python 3.x), it's easier to define them here.
1925
+ #
1926
+ def getType(o):
1927
+ return type(o)
1928
+
1929
+ #
1930
+ # Used by generated code. Defining this in the Ice module means the generated code
1931
+ # can avoid the need to qualify the hash() function with its module name. Since
1932
+ # the function is in the __builtin__ module (for Python 2.x) and the builtins
1933
+ # module (for Python 3.x), it's easier to define it here.
1934
+ #
1935
+ def getHash(o):
1936
+ return hash(o)
1937
+
1938
+ Protocol_1_0 = ProtocolVersion(1, 0)
1939
+ Encoding_1_0 = EncodingVersion(1, 0)
1940
+ Encoding_1_1 = EncodingVersion(1, 1)
1941
+
1942
+
1943
+ BuiltinBool = 0
1944
+ BuiltinByte = 1
1945
+ BuiltinShort = 2
1946
+ BuiltinInt = 3
1947
+ BuiltinLong = 4
1948
+ BuiltinFloat = 5
1949
+ BuiltinDouble = 6
1950
+
1951
+ BuiltinTypes = [BuiltinBool, BuiltinByte, BuiltinShort, BuiltinInt, BuiltinLong, BuiltinFloat, BuiltinDouble]
1952
+ BuiltinArrayTypes = ["b", "b", "h", "i", "q", "f", "d"]
1953
+
1954
+ #
1955
+ # The array "q" type specifier is new in Python 3.3
1956
+ #
1957
+ if sys.version_info[:2] >= (3, 3):
1958
+ def createArray(view, t, copy):
1959
+ if t not in BuiltinTypes:
1960
+ raise ValueError("`{0}' is not an array builtin type".format(t))
1961
+ a = array.array(BuiltinArrayTypes[t])
1962
+ a.frombytes(view)
1963
+ return a
1964
+ #
1965
+ # The array.frombytes method is new in Python 3.2
1966
+ #
1967
+ elif sys.version_info[:2] >= (3, 2):
1968
+ def createArray(view, t, copy):
1969
+ if t not in BuiltinTypes:
1970
+ raise ValueError("`{0}' is not an array builtin type".format(t))
1971
+ elif t == BuiltinLong:
1972
+ raise ValueError("array.array 'q' specifier is only supported with Python >= 3.3")
1973
+ a = array.array(BuiltinArrayTypes[t])
1974
+ a.frombytes(view)
1975
+ return a
1976
+ else:
1977
+ def createArray(view, t, copy):
1978
+ if t not in BuiltinTypes:
1979
+ raise ValueError("`{0}' is not an array builtin type".format(t))
1980
+ elif t == BuiltinLong:
1981
+ raise ValueError("array.array 'q' specifier is only supported with Python >= 3.3")
1982
+ a = array.array(BuiltinArrayTypes[t])
1983
+ a.fromstring(str(view.tobytes()))
1984
+ return a
1985
+
1986
+
1987
+ try:
1988
+ import numpy
1989
+
1990
+ BuiltinNumpyTypes = [numpy.bool_, numpy.int8, numpy.int16, numpy.int32, numpy.int64, numpy.float32, numpy.float64]
1991
+
1992
+ #
1993
+ # With Python2.7 we cannot initialize numpy array from memoryview
1994
+ # See: https://github.com/numpy/numpy/issues/5935
1995
+ #
1996
+ if sys.version_info[0] >= 3:
1997
+ def createNumPyArray(view, t, copy):
1998
+ if t not in BuiltinTypes:
1999
+ raise ValueError("`{0}' is not an array builtin type".format(t))
2000
+ return numpy.frombuffer(view.tobytes() if copy else view, BuiltinNumpyTypes[t])
2001
+ else:
2002
+ def createNumPyArray(view, t, copy):
2003
+ if t not in BuiltinTypes:
2004
+ raise ValueError("`{0}' is not an array builtin type".format(t))
2005
+ return numpy.frombuffer(view.tobytes(), BuiltinNumpyTypes[t])
2006
+
2007
+ except ImportError:
2008
+ pass