tdrpa.tdworker 1.1.9.3__py310-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. tdrpa/_tdxlwings/__init__.py +193 -0
  2. tdrpa/_tdxlwings/__pycache__/__init__.cpython-311.pyc +0 -0
  3. tdrpa/_tdxlwings/__pycache__/__init__.cpython-38.pyc +0 -0
  4. tdrpa/_tdxlwings/__pycache__/_win32patch.cpython-311.pyc +0 -0
  5. tdrpa/_tdxlwings/__pycache__/_win32patch.cpython-38.pyc +0 -0
  6. tdrpa/_tdxlwings/__pycache__/_xlwindows.cpython-311.pyc +0 -0
  7. tdrpa/_tdxlwings/__pycache__/_xlwindows.cpython-38.pyc +0 -0
  8. tdrpa/_tdxlwings/__pycache__/apps.cpython-311.pyc +0 -0
  9. tdrpa/_tdxlwings/__pycache__/apps.cpython-38.pyc +0 -0
  10. tdrpa/_tdxlwings/__pycache__/base_classes.cpython-311.pyc +0 -0
  11. tdrpa/_tdxlwings/__pycache__/base_classes.cpython-38.pyc +0 -0
  12. tdrpa/_tdxlwings/__pycache__/com_server.cpython-311.pyc +0 -0
  13. tdrpa/_tdxlwings/__pycache__/com_server.cpython-38.pyc +0 -0
  14. tdrpa/_tdxlwings/__pycache__/constants.cpython-311.pyc +0 -0
  15. tdrpa/_tdxlwings/__pycache__/constants.cpython-38.pyc +0 -0
  16. tdrpa/_tdxlwings/__pycache__/expansion.cpython-311.pyc +0 -0
  17. tdrpa/_tdxlwings/__pycache__/expansion.cpython-38.pyc +0 -0
  18. tdrpa/_tdxlwings/__pycache__/main.cpython-311.pyc +0 -0
  19. tdrpa/_tdxlwings/__pycache__/main.cpython-38.pyc +0 -0
  20. tdrpa/_tdxlwings/__pycache__/udfs.cpython-311.pyc +0 -0
  21. tdrpa/_tdxlwings/__pycache__/udfs.cpython-38.pyc +0 -0
  22. tdrpa/_tdxlwings/__pycache__/utils.cpython-311.pyc +0 -0
  23. tdrpa/_tdxlwings/__pycache__/utils.cpython-38.pyc +0 -0
  24. tdrpa/_tdxlwings/_win32patch.py +90 -0
  25. tdrpa/_tdxlwings/_xlmac.py +2240 -0
  26. tdrpa/_tdxlwings/_xlwindows.py +2518 -0
  27. tdrpa/_tdxlwings/addin/Dictionary.cls +474 -0
  28. tdrpa/_tdxlwings/addin/IWebAuthenticator.cls +71 -0
  29. tdrpa/_tdxlwings/addin/WebClient.cls +772 -0
  30. tdrpa/_tdxlwings/addin/WebHelpers.bas +3203 -0
  31. tdrpa/_tdxlwings/addin/WebRequest.cls +875 -0
  32. tdrpa/_tdxlwings/addin/WebResponse.cls +453 -0
  33. tdrpa/_tdxlwings/addin/xlwings.xlam +0 -0
  34. tdrpa/_tdxlwings/apps.py +35 -0
  35. tdrpa/_tdxlwings/base_classes.py +1092 -0
  36. tdrpa/_tdxlwings/cli.py +1306 -0
  37. tdrpa/_tdxlwings/com_server.py +385 -0
  38. tdrpa/_tdxlwings/constants.py +3080 -0
  39. tdrpa/_tdxlwings/conversion/__init__.py +103 -0
  40. tdrpa/_tdxlwings/conversion/framework.py +147 -0
  41. tdrpa/_tdxlwings/conversion/numpy_conv.py +34 -0
  42. tdrpa/_tdxlwings/conversion/pandas_conv.py +184 -0
  43. tdrpa/_tdxlwings/conversion/standard.py +321 -0
  44. tdrpa/_tdxlwings/expansion.py +83 -0
  45. tdrpa/_tdxlwings/ext/__init__.py +3 -0
  46. tdrpa/_tdxlwings/ext/sql.py +73 -0
  47. tdrpa/_tdxlwings/html/xlwings-alert.html +71 -0
  48. tdrpa/_tdxlwings/js/xlwings.js +577 -0
  49. tdrpa/_tdxlwings/js/xlwings.ts +729 -0
  50. tdrpa/_tdxlwings/mac_dict.py +6399 -0
  51. tdrpa/_tdxlwings/main.py +5205 -0
  52. tdrpa/_tdxlwings/mistune/__init__.py +63 -0
  53. tdrpa/_tdxlwings/mistune/block_parser.py +366 -0
  54. tdrpa/_tdxlwings/mistune/inline_parser.py +216 -0
  55. tdrpa/_tdxlwings/mistune/markdown.py +84 -0
  56. tdrpa/_tdxlwings/mistune/renderers.py +220 -0
  57. tdrpa/_tdxlwings/mistune/scanner.py +121 -0
  58. tdrpa/_tdxlwings/mistune/util.py +41 -0
  59. tdrpa/_tdxlwings/pro/__init__.py +40 -0
  60. tdrpa/_tdxlwings/pro/_xlcalamine.py +536 -0
  61. tdrpa/_tdxlwings/pro/_xlofficejs.py +146 -0
  62. tdrpa/_tdxlwings/pro/_xlremote.py +1293 -0
  63. tdrpa/_tdxlwings/pro/custom_functions_code.js +150 -0
  64. tdrpa/_tdxlwings/pro/embedded_code.py +60 -0
  65. tdrpa/_tdxlwings/pro/udfs_officejs.py +549 -0
  66. tdrpa/_tdxlwings/pro/utils.py +199 -0
  67. tdrpa/_tdxlwings/quickstart.xlsm +0 -0
  68. tdrpa/_tdxlwings/quickstart_addin.xlam +0 -0
  69. tdrpa/_tdxlwings/quickstart_addin_ribbon.xlam +0 -0
  70. tdrpa/_tdxlwings/quickstart_fastapi/main.py +47 -0
  71. tdrpa/_tdxlwings/quickstart_fastapi/requirements.txt +3 -0
  72. tdrpa/_tdxlwings/quickstart_standalone.xlsm +0 -0
  73. tdrpa/_tdxlwings/reports.py +12 -0
  74. tdrpa/_tdxlwings/rest/__init__.py +1 -0
  75. tdrpa/_tdxlwings/rest/api.py +368 -0
  76. tdrpa/_tdxlwings/rest/serializers.py +103 -0
  77. tdrpa/_tdxlwings/server.py +14 -0
  78. tdrpa/_tdxlwings/udfs.py +775 -0
  79. tdrpa/_tdxlwings/utils.py +777 -0
  80. tdrpa/_tdxlwings/xlwings-0.31.6.applescript +30 -0
  81. tdrpa/_tdxlwings/xlwings.bas +2061 -0
  82. tdrpa/_tdxlwings/xlwings_custom_addin.bas +2042 -0
  83. tdrpa/_tdxlwings/xlwingslib.cp38-win_amd64.pyd +0 -0
  84. tdrpa/tdworker/__init__.pyi +8 -0
  85. tdrpa/tdworker/_excel.pyi +703 -0
  86. tdrpa/tdworker/_img.pyi +173 -0
  87. tdrpa/tdworker/_os.pyi +46 -0
  88. tdrpa/tdworker/_w.pyi +129 -0
  89. tdrpa/tdworker/_web.pyi +248 -0
  90. tdrpa/tdworker/_winE.pyi +246 -0
  91. tdrpa/tdworker/_winK.pyi +74 -0
  92. tdrpa/tdworker/_winM.pyi +117 -0
  93. tdrpa/tdworker.cp310-win_amd64.pyd +0 -0
  94. tdrpa.tdworker-1.1.9.3.dist-info/METADATA +25 -0
  95. tdrpa.tdworker-1.1.9.3.dist-info/RECORD +97 -0
  96. tdrpa.tdworker-1.1.9.3.dist-info/WHEEL +5 -0
  97. tdrpa.tdworker-1.1.9.3.dist-info/top_level.txt +1 -0
@@ -0,0 +1,385 @@
1
+ import importlib
2
+ import logging
3
+ import os
4
+ import sys
5
+
6
+ # Hack to find pythoncom.dll - needed for some distribution/setups
7
+ # E.g., if python is started with the full path outside of the python path,
8
+ # then it almost certainly fails
9
+ cwd = os.getcwd()
10
+ if not hasattr(sys, "frozen"):
11
+ # cx_Freeze etc. will fail here otherwise
12
+ os.chdir(sys.exec_prefix)
13
+ try:
14
+ import win32api
15
+ except ImportError:
16
+ raise ImportError(
17
+ "Couldn't find 'pywin32'. Install it via"
18
+ "'pip install pywin32' or 'conda install pywin32'."
19
+ ) from None
20
+ import win32event
21
+
22
+ os.chdir(cwd)
23
+
24
+ try:
25
+ import pythoncom
26
+ except ImportError:
27
+ raise ImportError(
28
+ "Couldn't find 'pywin32'. Install it via"
29
+ "'pip install pywin32' or 'conda install pywin32'."
30
+ ) from None
31
+ import asyncio
32
+ import threading
33
+
34
+ import pywintypes
35
+ import win32com.client
36
+ import win32com.server.dispatcher
37
+ import win32com.server.policy
38
+ import win32com.server.util as serverutil
39
+
40
+ from .udfs import call_udf
41
+
42
+ # If no handler is configured, print is used to make the statements show up in the
43
+ # console that opens when using 'python' instead of 'pythonw' as the interpreter
44
+ logger = logging.getLogger(__name__)
45
+
46
+
47
+ class XLPythonOption:
48
+ """The XLPython class itself"""
49
+
50
+ def __init__(self, option, value):
51
+ self.option = option
52
+ self.value = value
53
+
54
+
55
+ class XLPythonObject:
56
+ _public_methods_ = ["Item", "Count"]
57
+ _public_attrs_ = ["_NewEnum"]
58
+
59
+ def __init__(self, obj):
60
+ self.obj = obj
61
+
62
+ def _NewEnum(self):
63
+ return win32com.server.util.wrap(
64
+ XLPythonEnumerator(self.obj), iid=pythoncom.IID_IEnumVARIANT
65
+ )
66
+
67
+ def Item(self, key):
68
+ return ToVariant(self.obj[key])
69
+
70
+ def Count(self):
71
+ return len(self.obj)
72
+
73
+
74
+ class XLPythonEnumerator:
75
+ _public_methods_ = ["Next", "Skip", "Reset", "Clone"]
76
+
77
+ def __init__(self, gen):
78
+ self.iter = gen.__iter__()
79
+
80
+ def _query_interface_(self, iid):
81
+ if iid == pythoncom.IID_IEnumVARIANT:
82
+ return 1
83
+
84
+ def Next(self, count):
85
+ r = []
86
+ try:
87
+ r.append(ToVariant(next(self.iter)))
88
+ except StopIteration:
89
+ pass
90
+ return r
91
+
92
+ def Skip(self, count):
93
+ raise win32com.server.exception.COMException(scode=0x80004001) # E_NOTIMPL
94
+
95
+ def Reset(self):
96
+ raise win32com.server.exception.COMException(scode=0x80004001) # E_NOTIMPL
97
+
98
+ def Clone(self):
99
+ raise win32com.server.exception.COMException(scode=0x80004001) # E_NOTIMPL
100
+
101
+
102
+ PyIDispatch = pythoncom.TypeIIDs[pythoncom.IID_IDispatch]
103
+
104
+
105
+ def FromVariant(var):
106
+ try:
107
+ obj = win32com.server.util.unwrap(var).obj
108
+ except: # noqa: E722
109
+ obj = var
110
+ if type(obj) is PyIDispatch:
111
+ obj = win32com.client.Dispatch(
112
+ obj, userName=obj.GetTypeInfo().GetDocumentation(-1)[0]
113
+ )
114
+ return obj
115
+
116
+
117
+ def ToVariant(obj):
118
+ return win32com.server.util.wrap(XLPythonObject(obj))
119
+
120
+
121
+ class XLPython:
122
+ _public_methods_ = [
123
+ "Module",
124
+ "Tuple",
125
+ "TupleFromArray",
126
+ "Dict",
127
+ "DictFromArray",
128
+ "List",
129
+ "ListFromArray",
130
+ "Obj",
131
+ "Str",
132
+ "Var",
133
+ "Call",
134
+ "GetItem",
135
+ "SetItem",
136
+ "DelItem",
137
+ "Contains",
138
+ "GetAttr",
139
+ "SetAttr",
140
+ "DelAttr",
141
+ "HasAttr",
142
+ "Eval",
143
+ "Exec",
144
+ "ShowConsole",
145
+ "Builtin",
146
+ "Len",
147
+ "Bool",
148
+ "CallUDF",
149
+ ]
150
+
151
+ def ShowConsole(self):
152
+ import ctypes
153
+ import sys
154
+
155
+ ctypes.windll.kernel32.AllocConsole()
156
+ sys.stdout = open("CONOUT$", "a", 0)
157
+ sys.stderr = open("CONOUT$", "a", 0)
158
+
159
+ def Module(self, module, reload=False):
160
+ vars = {}
161
+ exec("import " + module + " as the_module", vars)
162
+ m = vars["the_module"]
163
+ if reload:
164
+ m = importlib.reload(m)
165
+ return ToVariant(m)
166
+
167
+ def TupleFromArray(self, elements):
168
+ return self.Tuple(*elements)
169
+
170
+ def Tuple(self, *elements):
171
+ return ToVariant(tuple((FromVariant(e) for e in elements)))
172
+
173
+ def DictFromArray(self, kvpairs):
174
+ return self.Dict(*kvpairs)
175
+
176
+ def Dict(self, *kvpairs):
177
+ if len(kvpairs) % 2 != 0:
178
+ raise Exception("Arguments must be alternating keys and values.")
179
+ n = int(len(kvpairs) / 2)
180
+ d = {}
181
+ for k in range(n):
182
+ key = FromVariant(kvpairs[2 * k])
183
+ value = FromVariant(kvpairs[2 * k + 1])
184
+ d[key] = value
185
+ return ToVariant(d)
186
+
187
+ def ListFromArray(self, elements):
188
+ return self.List(*elements)
189
+
190
+ def List(self, *elements):
191
+ return ToVariant(list((FromVariant(e) for e in elements)))
192
+
193
+ def Obj(self, var, dispatch=True):
194
+ return ToVariant(FromVariant(var, dispatch))
195
+
196
+ def Str(self, obj):
197
+ return str(FromVariant(obj))
198
+
199
+ def Var(self, obj, lax=False):
200
+ value = FromVariant(obj)
201
+ if lax:
202
+ t = type(value)
203
+ if t is dict:
204
+ value = tuple(value.items())
205
+ elif t.__name__ == "ndarray" and t.__module__ == "numpy":
206
+ value = value.tolist()
207
+ if type(value) is tuple:
208
+ return (value,)
209
+ # elif isinstance(value, types.InstanceType) and value.__class__ is win32com.client.CDispatch:
210
+ # return value._oleobj_
211
+ else:
212
+ return value
213
+
214
+ def Call(self, obj, *args):
215
+ obj = FromVariant(obj)
216
+ method = None
217
+ pargs = ()
218
+ kwargs = {}
219
+ for arg in args:
220
+ arg = FromVariant(arg)
221
+ if isinstance(arg, tuple):
222
+ pargs = arg
223
+ elif isinstance(arg, dict):
224
+ kwargs = arg
225
+ else:
226
+ # assume string
227
+ method = arg
228
+ if method is None:
229
+ return ToVariant(obj(*pargs, **kwargs))
230
+ else:
231
+ return ToVariant(getattr(obj, method)(*pargs, **kwargs))
232
+
233
+ def CallUDF(self, script, fname, args, this_workbook=None, caller=None):
234
+ args = tuple(FromVariant(arg) for arg in args)
235
+ res = call_udf(script, fname, args, this_workbook, FromVariant(caller))
236
+ if len(res) == 1 and len(res[0]) == 1:
237
+ res = res[0][0]
238
+ elif len(res) == 1 and len(res[0]) > 1:
239
+ res = res[0]
240
+ return res
241
+
242
+ def Len(self, obj):
243
+ obj = FromVariant(obj)
244
+ return len(obj)
245
+
246
+ def Bool(self, obj):
247
+ obj = FromVariant(obj)
248
+ if obj:
249
+ return True
250
+ else:
251
+ return False
252
+
253
+ def Builtin(self):
254
+ import builtins
255
+
256
+ return ToVariant(builtins)
257
+
258
+ def GetItem(self, obj, key):
259
+ obj = FromVariant(obj)
260
+ key = FromVariant(key)
261
+ return ToVariant(obj[key])
262
+
263
+ def SetItem(self, obj, key, value):
264
+ obj = FromVariant(obj)
265
+ key = FromVariant(key)
266
+ value = FromVariant(value)
267
+ obj[key] = value
268
+
269
+ def DelItem(self, obj, key):
270
+ del obj[key]
271
+
272
+ def Contains(self, obj, key):
273
+ return key in obj
274
+
275
+ def GetAttr(self, obj, attr):
276
+ obj = FromVariant(obj)
277
+ attr = FromVariant(attr)
278
+ return ToVariant(getattr(obj, attr))
279
+
280
+ def SetAttr(self, obj, attr, value):
281
+ obj = FromVariant(obj)
282
+ attr = FromVariant(attr)
283
+ value = FromVariant(value)
284
+ setattr(obj, attr, value)
285
+
286
+ def HasAttr(self, obj, attr):
287
+ obj = FromVariant(obj)
288
+ attr = FromVariant(attr)
289
+ return hasattr(obj, attr)
290
+
291
+ def DelAttr(self, obj, attr):
292
+ delattr(obj, attr)
293
+
294
+ def Eval(self, expr, *args):
295
+ globals = None
296
+ locals = None
297
+ for arg in args:
298
+ arg = FromVariant(arg)
299
+ if type(arg) is dict:
300
+ if globals is None:
301
+ globals = arg
302
+ elif locals is None:
303
+ locals = arg
304
+ else:
305
+ raise Exception(
306
+ "Eval can be called with at most 2 dictionary arguments"
307
+ )
308
+ else:
309
+ pass
310
+ return ToVariant(eval(expr, globals, locals))
311
+
312
+ def Exec(self, stmt, *args):
313
+ globals = None
314
+ locals = None
315
+ for arg in args:
316
+ arg = FromVariant(arg)
317
+ if type(arg) is dict:
318
+ if globals is None:
319
+ globals = arg
320
+ elif locals is None:
321
+ locals = arg
322
+ else:
323
+ raise Exception(
324
+ "Exec can be called with at most 2 dictionary arguments"
325
+ )
326
+ else:
327
+ pass
328
+ exec(stmt, globals, locals)
329
+
330
+
331
+ loop = asyncio.new_event_loop()
332
+
333
+
334
+ def _start_background_loop():
335
+ pythoncom.CoInitialize()
336
+ asyncio.set_event_loop(loop)
337
+ loop.run_forever()
338
+
339
+
340
+ def serve(clsid="{506e67c3-55b5-48c3-a035-eed5deea7d6d}"):
341
+ """Launch the COM server, clsid is the XLPython object class id"""
342
+ clsid = pywintypes.IID(clsid)
343
+
344
+ # Override CreateInstance in default policy to instantiate the XLPython object ---
345
+ BaseDefaultPolicy = win32com.server.policy.DefaultPolicy
346
+
347
+ class MyPolicy(BaseDefaultPolicy):
348
+ def _CreateInstance_(self, reqClsid, reqIID):
349
+ if reqClsid == clsid:
350
+ return serverutil.wrap(XLPython(), reqIID)
351
+ else:
352
+ return BaseDefaultPolicy._CreateInstance_(self, clsid, reqIID)
353
+
354
+ win32com.server.policy.DefaultPolicy = MyPolicy
355
+
356
+ # Create the class factory and register it
357
+ factory = pythoncom.MakePyFactory(clsid)
358
+
359
+ clsctx = pythoncom.CLSCTX_LOCAL_SERVER
360
+ flags = pythoncom.REGCLS_MULTIPLEUSE | pythoncom.REGCLS_SUSPENDED
361
+ revokeId = pythoncom.CoRegisterClassObject(clsid, factory, clsctx, flags)
362
+
363
+ pythoncom.EnableQuitMessage(win32api.GetCurrentThreadId())
364
+ pythoncom.CoResumeClassObjects()
365
+
366
+ if not loop.is_running():
367
+ t = threading.Thread(target=_start_background_loop, daemon=True)
368
+ t.start()
369
+ tid = t.ident
370
+ else:
371
+ tid = None
372
+
373
+ msg = "xlwings server running, clsid=%s, event loop on %s"
374
+ logger.info(msg, clsid, tid) if logger.hasHandlers() else print(msg % (clsid, tid))
375
+
376
+ while True:
377
+ rc = win32event.MsgWaitForMultipleObjects(
378
+ (), 0, win32event.INFINITE, win32event.QS_ALLEVENTS
379
+ )
380
+ if rc == win32event.WAIT_OBJECT_0:
381
+ if pythoncom.PumpWaitingMessages():
382
+ break # wm_quit
383
+
384
+ pythoncom.CoRevokeClassObject(revokeId)
385
+ pythoncom.CoUninitialize()