iris-pex-embedded-python 2.3.16__py3-none-any.whl → 2.3.18__py3-none-any.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.

Potentially problematic release.


This version of iris-pex-embedded-python might be problematic. Click here for more details.

Files changed (120) hide show
  1. grongier/iris/Grongier/PEX/BusinessOperation.cls +33 -0
  2. grongier/iris/Grongier/PEX/BusinessProcess.cls +100 -0
  3. grongier/iris/Grongier/PEX/BusinessService.cls +33 -0
  4. grongier/iris/Grongier/PEX/Common.cls +133 -0
  5. grongier/iris/Grongier/PEX/Director.cls +15 -0
  6. grongier/iris/Grongier/PEX/Duplex/Operation.cls +27 -0
  7. grongier/iris/Grongier/PEX/Duplex/Process.cls +211 -0
  8. grongier/iris/Grongier/PEX/Duplex/Service.cls +9 -0
  9. grongier/iris/Grongier/PEX/InboundAdapter.cls +22 -0
  10. grongier/iris/Grongier/PEX/Message.cls +126 -0
  11. grongier/iris/Grongier/PEX/OutboundAdapter.cls +34 -0
  12. grongier/iris/Grongier/PEX/PickleMessage.cls +58 -0
  13. grongier/iris/Grongier/PEX/PrivateSession/Duplex.cls +247 -0
  14. grongier/iris/Grongier/PEX/PrivateSession/Message/Ack.cls +32 -0
  15. grongier/iris/Grongier/PEX/PrivateSession/Message/Poll.cls +32 -0
  16. grongier/iris/Grongier/PEX/PrivateSession/Message/Start.cls +32 -0
  17. grongier/iris/Grongier/PEX/PrivateSession/Message/Stop.cls +48 -0
  18. grongier/iris/Grongier/PEX/Python.cls +27 -0
  19. grongier/iris/Grongier/PEX/Test.cls +62 -0
  20. grongier/iris/Grongier/PEX/Utils.cls +312 -0
  21. grongier/iris/__init__.py +0 -0
  22. grongier/pex/_business_host.py +9 -1
  23. grongier/pex/_cli.py +8 -2
  24. grongier/pex/data/PEX/BusinessOperation.cls +35 -0
  25. grongier/pex/data/PEX/BusinessProcess.cls +113 -0
  26. grongier/pex/data/PEX/BusinessService.cls +35 -0
  27. grongier/pex/data/PEX/Common.cls +146 -0
  28. grongier/pex/data/PEX/Director.cls +57 -0
  29. grongier/pex/data/PEX/Duplex/Operation.cls +29 -0
  30. grongier/pex/data/PEX/Duplex/Process.cls +229 -0
  31. grongier/pex/data/PEX/Duplex/Service.cls +9 -0
  32. grongier/pex/data/PEX/InboundAdapter.cls +22 -0
  33. grongier/pex/data/PEX/Message.cls +128 -0
  34. grongier/pex/data/PEX/OutboundAdapter.cls +36 -0
  35. grongier/pex/data/PEX/PickleMessage.cls +58 -0
  36. grongier/pex/data/PEX/PrivateSession/Duplex.cls +260 -0
  37. grongier/pex/data/PEX/PrivateSession/Message/Ack.cls +32 -0
  38. grongier/pex/data/PEX/PrivateSession/Message/Poll.cls +32 -0
  39. grongier/pex/data/PEX/PrivateSession/Message/Start.cls +32 -0
  40. grongier/pex/data/PEX/PrivateSession/Message/Stop.cls +48 -0
  41. grongier/pex/data/PEX/Test.cls +62 -0
  42. grongier/pex/data/PEX/Utils.cls +413 -0
  43. intersystems_iris/_BufferReader.py +10 -0
  44. intersystems_iris/_BufferWriter.py +32 -0
  45. intersystems_iris/_ConnectionInformation.py +54 -0
  46. intersystems_iris/_ConnectionParameters.py +18 -0
  47. intersystems_iris/_Constant.py +38 -0
  48. intersystems_iris/_DBList.py +500 -0
  49. intersystems_iris/_Device.py +69 -0
  50. intersystems_iris/_GatewayContext.py +25 -0
  51. intersystems_iris/_GatewayException.py +4 -0
  52. intersystems_iris/_GatewayUtility.py +74 -0
  53. intersystems_iris/_IRIS.py +1294 -0
  54. intersystems_iris/_IRISConnection.py +516 -0
  55. intersystems_iris/_IRISEmbedded.py +85 -0
  56. intersystems_iris/_IRISGlobalNode.py +273 -0
  57. intersystems_iris/_IRISGlobalNodeView.py +25 -0
  58. intersystems_iris/_IRISIterator.py +143 -0
  59. intersystems_iris/_IRISList.py +360 -0
  60. intersystems_iris/_IRISNative.py +208 -0
  61. intersystems_iris/_IRISOREF.py +4 -0
  62. intersystems_iris/_IRISObject.py +424 -0
  63. intersystems_iris/_IRISReference.py +133 -0
  64. intersystems_iris/_InStream.py +149 -0
  65. intersystems_iris/_LegacyIterator.py +135 -0
  66. intersystems_iris/_ListItem.py +15 -0
  67. intersystems_iris/_ListReader.py +84 -0
  68. intersystems_iris/_ListWriter.py +157 -0
  69. intersystems_iris/_LogFileStream.py +115 -0
  70. intersystems_iris/_MessageHeader.py +51 -0
  71. intersystems_iris/_OutStream.py +25 -0
  72. intersystems_iris/_PrintStream.py +65 -0
  73. intersystems_iris/_PythonGateway.py +850 -0
  74. intersystems_iris/_SharedMemorySocket.py +87 -0
  75. intersystems_iris/__init__.py +79 -0
  76. intersystems_iris/__main__.py +7 -0
  77. intersystems_iris/dbapi/_Column.py +56 -0
  78. intersystems_iris/dbapi/_DBAPI.py +2587 -0
  79. intersystems_iris/dbapi/_Descriptor.py +46 -0
  80. intersystems_iris/dbapi/_IRISStream.py +65 -0
  81. intersystems_iris/dbapi/_Message.py +158 -0
  82. intersystems_iris/dbapi/_Parameter.py +169 -0
  83. intersystems_iris/dbapi/_ParameterCollection.py +141 -0
  84. intersystems_iris/dbapi/_ResultSetRow.py +338 -0
  85. intersystems_iris/dbapi/_SQLType.py +32 -0
  86. intersystems_iris/dbapi/__init__.py +0 -0
  87. intersystems_iris/dbapi/preparser/_PreParser.py +1671 -0
  88. intersystems_iris/dbapi/preparser/_Scanner.py +391 -0
  89. intersystems_iris/dbapi/preparser/_Token.py +81 -0
  90. intersystems_iris/dbapi/preparser/_TokenList.py +251 -0
  91. intersystems_iris/dbapi/preparser/__init__.py +0 -0
  92. intersystems_iris/pex/_BusinessHost.py +101 -0
  93. intersystems_iris/pex/_BusinessOperation.py +105 -0
  94. intersystems_iris/pex/_BusinessProcess.py +214 -0
  95. intersystems_iris/pex/_BusinessService.py +95 -0
  96. intersystems_iris/pex/_Common.py +228 -0
  97. intersystems_iris/pex/_Director.py +24 -0
  98. intersystems_iris/pex/_IRISBusinessOperation.py +5 -0
  99. intersystems_iris/pex/_IRISBusinessService.py +18 -0
  100. intersystems_iris/pex/_IRISInboundAdapter.py +5 -0
  101. intersystems_iris/pex/_IRISOutboundAdapter.py +17 -0
  102. intersystems_iris/pex/_InboundAdapter.py +57 -0
  103. intersystems_iris/pex/_Message.py +6 -0
  104. intersystems_iris/pex/_OutboundAdapter.py +46 -0
  105. intersystems_iris/pex/__init__.py +25 -0
  106. iris/__init__.py +33 -0
  107. iris/iris_ipm.py +40 -0
  108. iris/iris_site.py +13 -0
  109. iris/irisbuiltins.py +97 -0
  110. iris/irisloader.py +199 -0
  111. {iris_pex_embedded_python-2.3.16.dist-info → iris_pex_embedded_python-2.3.18.dist-info}/METADATA +3 -4
  112. iris_pex_embedded_python-2.3.18.dist-info/RECORD +153 -0
  113. {iris_pex_embedded_python-2.3.16.dist-info → iris_pex_embedded_python-2.3.18.dist-info}/WHEEL +1 -1
  114. iris_pex_embedded_python-2.3.18.dist-info/top_level.txt +4 -0
  115. irisnative/_IRISNative.py +9 -0
  116. irisnative/__init__.py +10 -0
  117. iris_pex_embedded_python-2.3.16.dist-info/RECORD +0 -43
  118. iris_pex_embedded_python-2.3.16.dist-info/top_level.txt +0 -1
  119. {iris_pex_embedded_python-2.3.16.dist-info → iris_pex_embedded_python-2.3.18.dist-info}/LICENSE +0 -0
  120. {iris_pex_embedded_python-2.3.16.dist-info → iris_pex_embedded_python-2.3.18.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,500 @@
1
+ import struct
2
+ import decimal
3
+ import functools
4
+ import math
5
+ import intersystems_iris._IRISOREF
6
+ import datetime
7
+
8
+ class _DBList(object):
9
+
10
+ ITEM_UNDEF = -1;
11
+ ITEM_PLACEHOLDER = 0;
12
+ ITEM_ASCII = 1;
13
+ ITEM_UNICODE = 2;
14
+ ITEM_POSINT = 4;
15
+ ITEM_NEGINT = 5;
16
+ ITEM_POSNUM = 6;
17
+ ITEM_NEGNUM = 7;
18
+ ITEM_DOUBLE = 8;
19
+ ITEM_COMPACT_DOUBLE = 9;
20
+ ITEM_OREF_ASCII = 25;
21
+ ITEM_OREF_UNICODE = 26;
22
+
23
+ @classmethod
24
+ def _get_list_element(cls, item):
25
+ buffer = item.buffer
26
+ offset = item.next_offset
27
+ item.by_reference = False
28
+ # if first byte is 0, then length is next 2 bytes
29
+ if buffer[offset] == 0:
30
+ length = buffer[offset + 1] | (buffer[offset + 2] << 8);
31
+ offset += 3
32
+ # if the length is still 0, then the length is the next 4 bytes
33
+ if length == 0:
34
+ length = buffer[offset] | (buffer[offset + 1] << 8) | (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24);
35
+ offset += 4
36
+ item.type = buffer[offset]
37
+ if item.type >= 32 and item.type < 64:
38
+ item.type = item.type-32
39
+ item.by_reference = True
40
+ item.data_offset = offset + 1
41
+ item.data_length = length - 1
42
+ item.next_offset = item.data_offset + item.data_length
43
+ item.is_null = False
44
+ item.is_undefined = False
45
+ elif buffer[offset] == 1:
46
+ item.type = cls.ITEM_UNDEF
47
+ if item.type >= 32 and item.type < 64:
48
+ item.type = item.type-32
49
+ item.by_reference = True
50
+ item.data_offset = offset + 1
51
+ item.data_length = 0
52
+ item.next_offset = item.data_offset
53
+ item.is_null = True
54
+ item.is_undefined = True
55
+ else:
56
+ item.type = buffer[offset + 1]
57
+ if item.type >= 32 and item.type < 64:
58
+ item.type = item.type-32
59
+ item.by_reference = True
60
+ item.data_offset = offset + 2
61
+ item.data_length = buffer[offset] - 2
62
+ item.next_offset = item.data_offset + item.data_length
63
+ item.is_null = (item.type == cls.ITEM_PLACEHOLDER) or ((item.type == cls.ITEM_ASCII) and (item.data_length == 0))
64
+ item.is_undefined = False
65
+ return
66
+
67
+ @classmethod
68
+ def _get_data_offset(cls, buffer, offset):
69
+ if buffer[offset] != 0:
70
+ next_offset = offset + buffer[offset]
71
+ elif buffer[offset + 1] == 0 and buffer[offset + 2] == 0:
72
+ if offset + 6 < len(buffer):
73
+ next_offset = offset + (buffer[offset + 3] | (buffer[offset + 4] << 8) | (buffer[offset + 5] << 16)) + 7
74
+ elif offset + 2 < len(buffer):
75
+ next_offset = offset + (buffer[offset + 1] | (buffer[offset + 2] << 8)) + 3
76
+ return next_offset
77
+
78
+ @classmethod
79
+ def _get(cls, item, locale, asBytes = False, retainAsciiZero = False):
80
+ if item.is_null:
81
+ return None
82
+ func = cls._get_switcher.get(item.type, None)
83
+ if func is None:
84
+ raise Exception("Incorrect list format, unknown type: " + item.type)
85
+ else:
86
+ return func(item.buffer, item.data_offset, item.data_length, locale, asBytes, retainAsciiZero)
87
+
88
+ @classmethod
89
+ def _grab_ascii_string(cls, buffer, offset, length, locale, asBytes = False, retainAsciiZero = False):
90
+ byte_array = buffer[offset:offset+length]
91
+ if not retainAsciiZero and byte_array == b'\x00':
92
+ return ""
93
+ if asBytes:
94
+ return bytes(byte_array)
95
+ else:
96
+ try:
97
+ return byte_array.decode(locale)
98
+ except:
99
+ return byte_array.decode('latin-1')
100
+
101
+ @classmethod
102
+ def _grab_unicode_string(cls, buffer, offset, length, *args):
103
+ return buffer[offset:offset+length].decode("utf-16LE")
104
+
105
+ @classmethod
106
+ def _grab_pos_integer(cls, buffer, offset, length, *args):
107
+ number = 0
108
+ for i in range(length):
109
+ number = number*256 + buffer[offset+length-i-1]
110
+ return number
111
+
112
+ @classmethod
113
+ def _grab_neg_integer(cls, buffer, offset, length, *args):
114
+ if length == 0:
115
+ return -1
116
+ if length == 1:
117
+ return (buffer[offset]) - 0x100
118
+ if length == 2:
119
+ return (buffer[offset] | buffer[offset+1]<<8) - 0x10000
120
+ if length == 3:
121
+ return (buffer[offset] | buffer[offset+1]<<8 | buffer[offset+2]<<16) - 0x1000000
122
+ if length == 4:
123
+ return (buffer[offset] | buffer[offset+1]<<8 | buffer[offset+2]<<16 | buffer[offset+3]<<24) - 0x100000000
124
+ if length == 5:
125
+ return (buffer[offset] | buffer[offset+1]<<8 | buffer[offset+2]<<16 | buffer[offset+3]<<24 | buffer[offset+4]<<32) - 0x10000000000
126
+ if length == 6:
127
+ return (buffer[offset] | buffer[offset+1]<<8 | buffer[offset+2]<<16 | buffer[offset+3]<<24 | buffer[offset+4]<<32 | buffer[offset+5]<<40) - 0x1000000000000
128
+ if length == 7:
129
+ return (buffer[offset] | buffer[offset+1]<<8 | buffer[offset+2]<<16 | buffer[offset+3]<<24 | buffer[offset+4]<<32 | buffer[offset+5]<<40 | buffer[offset+6]<<48) - 0x100000000000000
130
+ if length == 8:
131
+ return (buffer[offset] | buffer[offset+1]<<8 | buffer[offset+2]<<16 | buffer[offset+3]<<24 | buffer[offset+4]<<32 | buffer[offset+5]<<40 | buffer[offset+6]<<48 | buffer[offset+7]<<56) - 0x10000000000000000
132
+ raise Exception("Integer out of range")
133
+
134
+ @classmethod
135
+ def _grab_pos_number(cls, buffer, offset, length, *args):
136
+ num = cls._grab_pos_integer(buffer, offset + 1, length - 1)
137
+ scale = buffer[offset]
138
+ if scale > 127:
139
+ scale -= 256
140
+ return cls.__parse_decimal(scale, num)
141
+
142
+ @classmethod
143
+ def _grab_neg_number(cls, buffer, offset, length, *args):
144
+ num = cls._grab_neg_integer(buffer, offset + 1, length - 1)
145
+ scale = buffer[offset]
146
+ if scale > 127:
147
+ scale -= 256
148
+ return cls.__parse_decimal(scale, num)
149
+
150
+ @classmethod
151
+ def _grab_double(cls, buffer, offset, length, *args):
152
+ if length != 8: return cls.__grab_compact_float(buffer, offset, length)
153
+ return struct.unpack('d', buffer[offset:offset+length])[0]
154
+
155
+ @classmethod
156
+ def _grab_compact_double(cls, buffer, offset, length, *args):
157
+ return struct.unpack('d',b'\x00\x00\x00\x00\x00\x00\x00\x00'[length:]+buffer[offset:offset+length])[0]
158
+
159
+ @classmethod
160
+ def __grab_compact_float(cls, buffer, offset, length):
161
+ return struct.unpack('f',b'\x00\x00\x00\x00'[length:]+buffer[offset:offset+length])[0]
162
+
163
+ @classmethod
164
+ def _grab_oref_ascii(cls, buffer, offset, length, locale, *args):
165
+ return intersystems_iris._IRISOREF._IRISOREF(cls._grab_ascii_string(buffer, offset, length, locale, False))
166
+
167
+ @classmethod
168
+ def _grab_oref_unicode(cls, buffer, offset, length, *args):
169
+ return intersystems_iris._IRISOREF._IRISOREF(cls._grab_unicode_string(buffer, offset, length))
170
+
171
+ @classmethod
172
+ def _set(cls, buffer, offset, data, locale, is_unicode, compact_double):
173
+ func = cls._set_switcher.get(type(data), None)
174
+ if func is None:
175
+ # raise Exception("Unsupported argument type: " + str(type(data)))
176
+ return cls._stuff_str(buffer, offset, str(data), locale, is_unicode, compact_double)
177
+ else:
178
+ return func(buffer, offset, data, locale, is_unicode, compact_double)
179
+
180
+ @classmethod
181
+ def _set_undefined(cls, buffer, offset):
182
+ buffer[offset] = 1
183
+ return offset + 1
184
+
185
+ @classmethod
186
+ def _set_null(cls, buffer, offset):
187
+ return cls._stuff_null(buffer, offset)
188
+
189
+ @classmethod
190
+ def _stuff_null(cls, buffer, offset, data = None, *args):
191
+ buffer[offset] = 2
192
+ buffer[offset+1] = cls.ITEM_ASCII
193
+ return offset+2
194
+
195
+ @classmethod
196
+ def _stuff_bytes(cls, buffer, offset, data, *args):
197
+ length = len(data)
198
+ offset = cls.__set_list_length_type(buffer, offset, length, cls.ITEM_ASCII)
199
+ buffer[offset:offset+length] = data[0:length]
200
+ offset += length
201
+ return offset
202
+
203
+ @classmethod
204
+ def _stuff_int(cls, buffer, offset, data, locale, is_unicode, *args):
205
+ if data > 0x7fffffffffffffff or data < -0x8000000000000000:
206
+ return cls._stuff_str(buffer, offset, str(data), locale=locale, is_unicode=is_unicode)
207
+ if data == 0:
208
+ return cls.__set_list_length_type(buffer, offset, 0, cls.ITEM_POSINT)
209
+ elif data > 0:
210
+ length = cls.__get_pos_int_length(data)
211
+ offset = cls.__set_list_length_type(buffer, offset, length, cls.ITEM_POSINT)
212
+ offset = cls.__stuff_raw_int(buffer, offset, data, length)
213
+ return offset
214
+ else:
215
+ length = cls.__get_neg_int_length(data)
216
+ offset = cls.__set_list_length_type(buffer, offset, length, cls.ITEM_NEGINT)
217
+ offset = cls.__stuff_raw_int(buffer, offset, data, length)
218
+ return offset
219
+
220
+ @classmethod
221
+ def _stuff_double(cls, buffer, offset, data, locale, is_unicode, compact_double):
222
+ if compact_double:
223
+ if data == 0 and math.copysign(1,data) > 0:
224
+ return cls.__set_list_length_type(buffer, offset, 0, cls.ITEM_DOUBLE)
225
+ # check if value can be corced to a single-precision value
226
+ # pack('<f') can throw OverFlowError
227
+ if struct.unpack('f', struct.pack('f', data))[0] == data:
228
+ lt = cls.ITEM_DOUBLE
229
+ data_bytes = struct.pack('<f',data)
230
+ else:
231
+ lt = cls.ITEM_COMPACT_DOUBLE
232
+ data_bytes = struct.pack('<d',data)
233
+ length = len(data_bytes)
234
+ #skip zeros
235
+ for i in range(length):
236
+ if data_bytes[i] != 0:
237
+ break
238
+ offset = cls.__set_list_length_type(buffer, offset, length-i, lt)
239
+ for j in range(i,length):
240
+ buffer[offset] = data_bytes[j]
241
+ offset += 1
242
+ return offset
243
+ else: # not compact_double
244
+ data_bytes = struct.pack('<d', data)
245
+ length = len(data_bytes)
246
+ offset = cls.__set_list_length_type(buffer, offset, length, cls.ITEM_DOUBLE)
247
+ for i in range(length):
248
+ buffer[offset] = data_bytes[i]
249
+ offset += 1
250
+ return offset
251
+
252
+ @classmethod
253
+ def _stuff_decimal(cls, buffer, offset, data, *args):
254
+ try:
255
+ if math.isnan(data) or math.isinf(data):
256
+ return cls._stuff_double(buffer, offset, data, *args)
257
+ except ValueError as e:
258
+ if str(data).lower() == "snan":
259
+ return cls._stuff_double(buffer, offset, decimal.Decimal('nan'), *args)
260
+ elif str(data).lower() == "-snan":
261
+ return cls._stuff_double(buffer, offset, decimal.Decimal('-nan'), *args)
262
+ else:
263
+ raise e
264
+ bd = data
265
+ scale = -bd.as_tuple()[2]
266
+ unscaled_value = int(bd.scaleb(scale))
267
+ # Truncate the magnitude if it does not fit into a 63 bit value
268
+ if cls.__get_bitlength(unscaled_value) > 63:
269
+ bd_rnd = decimal.Context(prec=19, rounding=decimal.ROUND_HALF_UP).create_decimal(bd)
270
+ scale = -bd_rnd.as_tuple()[2]
271
+ unscaled_value = int(bd_rnd.scaleb(scale))
272
+ if cls.__get_bitlength(unscaled_value) > 63:
273
+ bd_rnd = decimal.Context(prec=18, rounding=decimal.ROUND_HALF_UP).create_decimal(bd)
274
+ scale = -bd_rnd.as_tuple()[2]
275
+ unscaled_value = int(bd_rnd.scaleb(scale))
276
+ if unscaled_value < 922337203685477581 and unscaled_value > -922337203685477581:
277
+ unscaled_value = int((decimal.Decimal(unscaled_value)*10).to_integral_exact(rounding=decimal.ROUND_HALF_UP))
278
+ scale += 1
279
+ if cls.__get_bitlength(unscaled_value) > 63:
280
+ raise Exception("Decimal out of range")
281
+ # Round the extend scale values in the 128-145 range
282
+ if scale < -127 or scale > 128:
283
+ if scale > 128:
284
+ prec_adj = -scale + 128
285
+ else:
286
+ prec_adj = -scale - 127
287
+ unscaled_value = int(decimal.Decimal(unscaled_value).scaleb(prec_adj).to_integral(rounding=decimal.ROUND_HALF_UP))
288
+ scale += prec_adj
289
+ if unscaled_value == 0:
290
+ scale = 0
291
+ if cls.__get_bitlength(unscaled_value) > 63:
292
+ raise Exception("Decimal out of range")
293
+ # If can store in type 6, 7
294
+ if scale < 129 and scale > -128:
295
+ if unscaled_value >= 0:
296
+ length = cls.__get_pos_int_length(unscaled_value)
297
+ offset = cls.__set_list_length_type(buffer, offset, length + 1, cls.ITEM_POSNUM)
298
+ else:
299
+ length = cls.__get_neg_int_length(unscaled_value)
300
+ offset = cls.__set_list_length_type(buffer, offset, length + 1, cls.ITEM_NEGNUM)
301
+ scale = -scale
302
+ if scale < 0:
303
+ scale += 256
304
+ buffer[offset] = scale
305
+ offset += 1
306
+ offset = cls.__stuff_raw_int(buffer, offset, unscaled_value, length)
307
+ return offset
308
+ # Out of range for IRIS Numeric SQLType
309
+ return cls._stuff_double(buffer, offset, data, *args)
310
+
311
+ @classmethod
312
+ def _stuff_str(cls, buffer, offset, data, locale, is_unicode, *args):
313
+ if type(data)==str and len(data) == 0:
314
+ return cls.__stuff_empty_string(buffer, offset)
315
+ is_oref = False
316
+ if type(data) == intersystems_iris._IRISOREF._IRISOREF:
317
+ data = data._oref
318
+ is_oref = True
319
+ offset_saved = offset
320
+ offset = cls.__stuff_8bit_ascii(buffer, offset, data, is_oref)
321
+ if offset == -1:
322
+ offset = offset_saved
323
+ if is_unicode:
324
+ offset = cls.__stuff_unicode(buffer, offset, data, is_oref)
325
+ else:
326
+ offset = cls.__stuff_multibyte(buffer, offset, data, is_oref, locale)
327
+ return offset
328
+
329
+ @classmethod
330
+ def _stuff_datetime(cls, buffer, offset, data, locale, is_unicode, *args):
331
+ return cls._stuff_str(buffer, offset, data.strftime('%Y-%m-%d %H:%M:%S.%f'), locale=locale, is_unicode=is_unicode)
332
+
333
+ @classmethod
334
+ def _stuff_date(cls, buffer, offset, data, locale, is_unicode, *args):
335
+ return cls._stuff_str(buffer, offset, data.strftime('%Y-%m-%d'), locale=locale, is_unicode=is_unicode)
336
+
337
+ @classmethod
338
+ def _stuff_time(cls, buffer, offset, data, locale, is_unicode, *args):
339
+ return cls._stuff_str(buffer, offset, data.strftime('%H:%M:%S.%f'), locale=locale, is_unicode=is_unicode)
340
+
341
+ @classmethod
342
+ def __set_list_length_type(cls, buffer, offset, length, type):
343
+ length += 1
344
+ if length < 0xFF:
345
+ length += 1;
346
+ buffer[offset] = length
347
+ buffer[offset + 1] = type
348
+ return offset + 2
349
+ if length <= 0xFFFF:
350
+ buffer[offset] = 0
351
+ buffer[offset + 1] = length & 0xFF
352
+ buffer[offset + 2] = (length >> 8) & 0xFF
353
+ buffer[offset + 3] = type
354
+ return offset + 4
355
+ buffer[offset] = 0;
356
+ buffer[offset + 1] = 0;
357
+ buffer[offset + 2] = 0;
358
+ buffer[offset + 3] = length & 0xFF
359
+ buffer[offset + 4] = (length >> 8) & 0xFF
360
+ buffer[offset + 5] = (length >> 16) & 0xFF
361
+ buffer[offset + 6] = (length >> 24) & 0xFF
362
+ buffer[offset + 7] = type
363
+ return offset + 8
364
+
365
+ @classmethod
366
+ def __get_pos_int_length(cls, data):
367
+ if data <= 0xFF:
368
+ return 1
369
+ if data <= 0xFFFF:
370
+ return 2
371
+ if data <= 0xFFFFFF:
372
+ return 3
373
+ if data <= 0xFFFFFFFF:
374
+ return 4
375
+ if data <= 0xFFFFFFFFFF:
376
+ return 5
377
+ if data <= 0xFFFFFFFFFFFF:
378
+ return 6
379
+ if data <= 0xFFFFFFFFFFFFFF:
380
+ return 7
381
+ if data <= 0xFFFFFFFFFFFFFFFF:
382
+ return 8
383
+ raise Exception("Integer out of range")
384
+
385
+ @classmethod
386
+ def __get_neg_int_length(cls, data):
387
+ if data == -1:
388
+ return 0
389
+ if data >= -0x100:
390
+ return 1
391
+ if data >= -0x10000:
392
+ return 2
393
+ if data >= -0x1000000:
394
+ return 3
395
+ if data >= -0x100000000:
396
+ return 4
397
+ if data >= -0x10000000000:
398
+ return 5
399
+ if data >= -0x1000000000000:
400
+ return 6
401
+ if data >= -0x100000000000000:
402
+ return 7
403
+ if data >= -0x10000000000000000:
404
+ return 8
405
+ raise Exception("Integer out of range")
406
+
407
+ @classmethod
408
+ def __stuff_raw_int(cls, buffer, offset, data, length):
409
+ for i in range(length):
410
+ one_byte = data & 255
411
+ data = data >> 8
412
+ buffer[offset+i] = one_byte
413
+ return offset+length
414
+
415
+ @classmethod
416
+ def __stuff_empty_string(cls, buffer, offset):
417
+ buffer[offset] = 3
418
+ buffer[offset+1] = cls.ITEM_ASCII
419
+ buffer[offset+2] = 0
420
+ return offset+3
421
+
422
+ @classmethod
423
+ def __stuff_8bit_ascii(cls, buffer, offset, data, is_oref):
424
+ try:
425
+ list_type = cls.ITEM_OREF_ASCII if is_oref else cls.ITEM_ASCII
426
+ length = len(data)
427
+ offset = cls.__set_list_length_type(buffer, offset, length, list_type)
428
+ buffer[offset:offset+length] = data.encode("latin-1")
429
+ return offset+length
430
+ except Exception as e:
431
+ return -1
432
+
433
+ @classmethod
434
+ def __stuff_unicode(cls, buffer, offset, data, is_oref):
435
+ list_type = cls.ITEM_OREF_UNICODE if is_oref else cls.ITEM_UNICODE
436
+ byte_array = bytearray(data,"utf-16LE")
437
+ length = len(byte_array)
438
+ offset = cls.__set_list_length_type(buffer, offset, length, list_type)
439
+ buffer[offset:offset+length] = byte_array[0:length]
440
+ return offset+length
441
+
442
+ @classmethod
443
+ def __stuff_multibyte(cls, buffer, offset, data, is_oref, locale):
444
+ list_type = cls.ITEM_OREF_ASCII if is_oref else cls.ITEM_ASCII
445
+ ascii = data.encode(locale)
446
+ length = len(ascii)
447
+ offset = cls.__set_list_length_type(buffer, offset, length, list_type)
448
+ buffer[offset:offset+length] = ascii
449
+ return offset + length
450
+
451
+ @classmethod
452
+ def __parse_decimal(cls, scale, num):
453
+ decstr = str(num) + "E" + str(scale)
454
+ dec = decimal.Decimal(decstr)
455
+ return dec
456
+
457
+ @classmethod
458
+ def __get_bitlength(cls, value):
459
+ if value < 0:
460
+ return (value + 1).bit_length()
461
+ else:
462
+ return value.bit_length()
463
+
464
+ @classmethod
465
+ def _set_type_as_pass_by_reference(cls, buffer, offset):
466
+ if buffer[offset] == 0:
467
+ buffer[offset+3] = buffer[offset+3]+32
468
+ elif buffer[offset] == 1:
469
+ pass
470
+ else:
471
+ buffer[offset+1] = buffer[offset+1]+32
472
+ return
473
+
474
+ _DBList._get_switcher = {
475
+ _DBList.ITEM_ASCII: _DBList._grab_ascii_string,
476
+ _DBList.ITEM_UNICODE: _DBList._grab_unicode_string,
477
+ _DBList.ITEM_POSINT: _DBList._grab_pos_integer,
478
+ _DBList.ITEM_NEGINT: _DBList._grab_neg_integer,
479
+ _DBList.ITEM_POSNUM: _DBList._grab_pos_number,
480
+ _DBList.ITEM_NEGNUM: _DBList._grab_neg_number,
481
+ _DBList.ITEM_DOUBLE: _DBList._grab_double,
482
+ _DBList.ITEM_COMPACT_DOUBLE: _DBList._grab_compact_double,
483
+ _DBList.ITEM_OREF_ASCII: _DBList._grab_oref_ascii,
484
+ _DBList.ITEM_OREF_UNICODE: _DBList._grab_oref_unicode
485
+ }
486
+
487
+ _DBList._set_switcher = {
488
+ type(None): _DBList._stuff_null,
489
+ datetime.time: _DBList._stuff_time,
490
+ datetime.date: _DBList._stuff_date,
491
+ datetime.datetime: _DBList._stuff_datetime,
492
+ bytes: _DBList._stuff_bytes,
493
+ bytearray: _DBList._stuff_bytes,
494
+ bool: _DBList._stuff_int,
495
+ int: _DBList._stuff_int,
496
+ float: _DBList._stuff_double,
497
+ decimal.Decimal: _DBList._stuff_decimal,
498
+ str: _DBList._stuff_str,
499
+ intersystems_iris._IRISOREF._IRISOREF: _DBList._stuff_str,
500
+ }
@@ -0,0 +1,69 @@
1
+ import base64
2
+ import getpass
3
+ import os
4
+ import platform
5
+ import socket
6
+ import struct
7
+ import sys
8
+ import threading
9
+ import intersystems_iris._SharedMemorySocket
10
+ import ssl
11
+
12
+ class _Device(object):
13
+
14
+ def __init__(self, _connection, _socket, _sslcontext = None):
15
+ _connection._device = self
16
+ self._connection = _connection
17
+ self._sslcontext = _sslcontext
18
+ if _socket is None:
19
+ self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
20
+ else:
21
+ self._socket = _socket
22
+
23
+ def close(self):
24
+ return self._socket.close()
25
+
26
+ def settimeout(self,time):
27
+ return self._socket.settimeout(time)
28
+
29
+ def connect(self, server_address):
30
+ if self._sslcontext is None:
31
+ return self._socket.connect(server_address)
32
+ else:
33
+ self._socket = self._sslcontext.wrap_socket(self._socket, server_hostname = server_address[0])
34
+ return self._socket.connect(server_address)
35
+
36
+ def sendall(self, buffer):
37
+ return self._socket.sendall(buffer)
38
+
39
+ def recv(self, len):
40
+ return self._socket.recv(len)
41
+
42
+ def gethostname(self):
43
+ return socket.gethostname()
44
+
45
+ def gethostbyname(self, hostname):
46
+ return socket.gethostbyname(hostname)
47
+
48
+ def is_sharedmemory(self):
49
+ return isinstance(self._socket, intersystems_iris._SharedMemorySocket._SharedMemorySocket)
50
+
51
+ def establishSHMSocket(self):
52
+ try:
53
+ iris_bin_dir = self._connection._connection_info._iris_install_dir
54
+ server_job_number = self._connection._connection_info._server_job_number
55
+ filename = b''
56
+ if self._connection._connection_params.hostname != None:
57
+ array = self._connection._connection_params.hostname.split("|")
58
+ filename = array[3] if len(array)>=4 else ""
59
+ filename = filename.upper()
60
+ filename = bytes(filename, "latin-1")
61
+ shmSocket = intersystems_iris._SharedMemorySocket._SharedMemorySocket(iris_bin_dir, server_job_number, filename)
62
+ shmSocket.connect()
63
+ self._socket.close()
64
+ self._socket = shmSocket
65
+ except BaseException as e:
66
+ try:
67
+ shmSocket.close()
68
+ except BaseException as e:
69
+ pass
@@ -0,0 +1,25 @@
1
+ import threading
2
+ import intersystems_iris._IRIS
3
+
4
+ class _GatewayContext(object):
5
+
6
+ __thread_local_connection = {}
7
+
8
+ @classmethod
9
+ def _set_connection(cls, connection):
10
+ thread_id = threading.get_ident()
11
+ cls.__thread_local_connection[thread_id] = connection
12
+
13
+ @classmethod
14
+ def _get_connection(cls):
15
+ thread_id = threading.get_ident()
16
+ return cls.__thread_local_connection.get(thread_id)
17
+
18
+ @classmethod
19
+ def getConnection(cls):
20
+ return cls._get_connection()
21
+
22
+ @classmethod
23
+ def getIRIS(cls):
24
+ return intersystems_iris.IRIS(cls._get_connection())
25
+
@@ -0,0 +1,4 @@
1
+ class _GatewayException(Exception):
2
+
3
+ def __init__(self, msg):
4
+ super().__init__(msg)
@@ -0,0 +1,74 @@
1
+ import inspect
2
+ import platform
3
+ import sys
4
+ import intersystems_iris._GatewayContext
5
+
6
+ class _GatewayUtility(object):
7
+
8
+ @staticmethod
9
+ def getLanguageName():
10
+ return "Python"
11
+
12
+ @staticmethod
13
+ def getLanguageVersion():
14
+ return platform.python_version()
15
+
16
+ @staticmethod
17
+ def writeOutput(data):
18
+ connection = intersystems_iris.GatewayContext.getConnection()
19
+ method_object = connection._output_redirect_handler
20
+ if method_object is None:
21
+ print(data, end="", flush=True)
22
+ else:
23
+ args = [ data ]
24
+ method_object(*args)
25
+
26
+ @classmethod
27
+ def dumpAllModules(cls, startswith = None):
28
+ if startswith is None: startswith = ""
29
+ lines = {}
30
+ gateway = intersystems_iris.GatewayContext.getConnection()._get_gateway()
31
+ cls._dumpOneModuleCollection(startswith, lines, sys.modules.copy())
32
+ cls._dumpOneModuleCollection(startswith, lines, gateway._thread_modules)
33
+ return "\r\n".join(sorted(lines.keys()))
34
+
35
+ @classmethod
36
+ def dumpSysModules(cls, startswith = None):
37
+ if startswith is None: startswith = ""
38
+ lines = {}
39
+ gateway = intersystems_iris.GatewayContext.getConnection()._get_gateway()
40
+ cls._dumpOneModuleCollection(startswith, lines, sys.modules.copy())
41
+ return "\r\n".join(sorted(lines.keys()))
42
+
43
+ @classmethod
44
+ def dumpThreadModules(cls, startswith = None):
45
+ if startswith is None: startswith = ""
46
+ lines = {}
47
+ gateway = intersystems_iris.GatewayContext.getConnection()._get_gateway()
48
+ cls._dumpOneModuleCollection(startswith, lines, gateway._thread_modules)
49
+ return "\r\n".join(sorted(lines.keys()))
50
+
51
+ @classmethod
52
+ def dumpMethods(cls, class_name = None):
53
+ lines = {}
54
+ gateway = intersystems_iris.GatewayContext.getConnection()._get_gateway()
55
+ class_object = gateway._load_class(class_name)
56
+ methods = inspect.getmembers(class_object, inspect.isfunction)
57
+ for m in range(len(methods)):
58
+ lines[methods[m][0]] = ""
59
+ return "\r\n".join(sorted(lines.keys()))
60
+
61
+ @classmethod
62
+ def _dumpOneModuleCollection(cls, startswith, lines, collection):
63
+ for module in collection.values():
64
+ module_name = module.__name__ + "."
65
+ if module_name.startswith(startswith): lines[module_name] = ""
66
+ try:
67
+ classes = inspect.getmembers(module, inspect.isclass)
68
+ for clazz in range(len(classes)):
69
+ class_name = module_name + classes[clazz][0]
70
+ if class_name.startswith(startswith): lines[class_name] = ""
71
+ except Exception as ex:
72
+ pass
73
+ return
74
+