tdrpa.tdworker 1.2.13.2__py312-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.
- tdrpa/_tdxlwings/__init__.py +193 -0
- tdrpa/_tdxlwings/__pycache__/__init__.cpython-311.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/__init__.cpython-38.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/_win32patch.cpython-311.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/_win32patch.cpython-38.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/_xlwindows.cpython-311.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/_xlwindows.cpython-38.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/apps.cpython-311.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/apps.cpython-38.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/base_classes.cpython-311.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/base_classes.cpython-38.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/com_server.cpython-311.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/com_server.cpython-38.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/constants.cpython-311.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/constants.cpython-38.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/expansion.cpython-311.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/expansion.cpython-38.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/main.cpython-311.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/main.cpython-38.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/udfs.cpython-311.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/udfs.cpython-38.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/utils.cpython-311.pyc +0 -0
- tdrpa/_tdxlwings/__pycache__/utils.cpython-38.pyc +0 -0
- tdrpa/_tdxlwings/_win32patch.py +90 -0
- tdrpa/_tdxlwings/_xlmac.py +2240 -0
- tdrpa/_tdxlwings/_xlwindows.py +2518 -0
- tdrpa/_tdxlwings/addin/Dictionary.cls +474 -0
- tdrpa/_tdxlwings/addin/IWebAuthenticator.cls +71 -0
- tdrpa/_tdxlwings/addin/WebClient.cls +772 -0
- tdrpa/_tdxlwings/addin/WebHelpers.bas +3203 -0
- tdrpa/_tdxlwings/addin/WebRequest.cls +875 -0
- tdrpa/_tdxlwings/addin/WebResponse.cls +453 -0
- tdrpa/_tdxlwings/addin/xlwings.xlam +0 -0
- tdrpa/_tdxlwings/apps.py +35 -0
- tdrpa/_tdxlwings/base_classes.py +1092 -0
- tdrpa/_tdxlwings/cli.py +1306 -0
- tdrpa/_tdxlwings/com_server.py +385 -0
- tdrpa/_tdxlwings/constants.py +3080 -0
- tdrpa/_tdxlwings/conversion/__init__.py +103 -0
- tdrpa/_tdxlwings/conversion/framework.py +147 -0
- tdrpa/_tdxlwings/conversion/numpy_conv.py +34 -0
- tdrpa/_tdxlwings/conversion/pandas_conv.py +184 -0
- tdrpa/_tdxlwings/conversion/standard.py +321 -0
- tdrpa/_tdxlwings/expansion.py +83 -0
- tdrpa/_tdxlwings/ext/__init__.py +3 -0
- tdrpa/_tdxlwings/ext/sql.py +73 -0
- tdrpa/_tdxlwings/html/xlwings-alert.html +71 -0
- tdrpa/_tdxlwings/js/xlwings.js +577 -0
- tdrpa/_tdxlwings/js/xlwings.ts +729 -0
- tdrpa/_tdxlwings/mac_dict.py +6399 -0
- tdrpa/_tdxlwings/main.py +5205 -0
- tdrpa/_tdxlwings/mistune/__init__.py +63 -0
- tdrpa/_tdxlwings/mistune/block_parser.py +366 -0
- tdrpa/_tdxlwings/mistune/inline_parser.py +216 -0
- tdrpa/_tdxlwings/mistune/markdown.py +84 -0
- tdrpa/_tdxlwings/mistune/renderers.py +220 -0
- tdrpa/_tdxlwings/mistune/scanner.py +121 -0
- tdrpa/_tdxlwings/mistune/util.py +41 -0
- tdrpa/_tdxlwings/pro/__init__.py +40 -0
- tdrpa/_tdxlwings/pro/_xlcalamine.py +536 -0
- tdrpa/_tdxlwings/pro/_xlofficejs.py +146 -0
- tdrpa/_tdxlwings/pro/_xlremote.py +1293 -0
- tdrpa/_tdxlwings/pro/custom_functions_code.js +150 -0
- tdrpa/_tdxlwings/pro/embedded_code.py +60 -0
- tdrpa/_tdxlwings/pro/udfs_officejs.py +549 -0
- tdrpa/_tdxlwings/pro/utils.py +199 -0
- tdrpa/_tdxlwings/quickstart.xlsm +0 -0
- tdrpa/_tdxlwings/quickstart_addin.xlam +0 -0
- tdrpa/_tdxlwings/quickstart_addin_ribbon.xlam +0 -0
- tdrpa/_tdxlwings/quickstart_fastapi/main.py +47 -0
- tdrpa/_tdxlwings/quickstart_fastapi/requirements.txt +3 -0
- tdrpa/_tdxlwings/quickstart_standalone.xlsm +0 -0
- tdrpa/_tdxlwings/reports.py +12 -0
- tdrpa/_tdxlwings/rest/__init__.py +1 -0
- tdrpa/_tdxlwings/rest/api.py +368 -0
- tdrpa/_tdxlwings/rest/serializers.py +103 -0
- tdrpa/_tdxlwings/server.py +14 -0
- tdrpa/_tdxlwings/udfs.py +775 -0
- tdrpa/_tdxlwings/utils.py +777 -0
- tdrpa/_tdxlwings/xlwings-0.31.6.applescript +30 -0
- tdrpa/_tdxlwings/xlwings.bas +2061 -0
- tdrpa/_tdxlwings/xlwings_custom_addin.bas +2042 -0
- tdrpa/_tdxlwings/xlwingslib.cp38-win_amd64.pyd +0 -0
- tdrpa/tdworker/__init__.pyi +12 -0
- tdrpa/tdworker/_clip.pyi +50 -0
- tdrpa/tdworker/_excel.pyi +743 -0
- tdrpa/tdworker/_file.pyi +77 -0
- tdrpa/tdworker/_img.pyi +226 -0
- tdrpa/tdworker/_network.pyi +94 -0
- tdrpa/tdworker/_os.pyi +47 -0
- tdrpa/tdworker/_sp.pyi +21 -0
- tdrpa/tdworker/_w.pyi +129 -0
- tdrpa/tdworker/_web.pyi +995 -0
- tdrpa/tdworker/_winE.pyi +228 -0
- tdrpa/tdworker/_winK.pyi +74 -0
- tdrpa/tdworker/_winM.pyi +117 -0
- tdrpa/tdworker.cp312-win_amd64.pyd +0 -0
- tdrpa_tdworker-1.2.13.2.dist-info/METADATA +38 -0
- tdrpa_tdworker-1.2.13.2.dist-info/RECORD +101 -0
- tdrpa_tdworker-1.2.13.2.dist-info/WHEEL +5 -0
- tdrpa_tdworker-1.2.13.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,453 @@
|
|
1
|
+
VERSION 1.0 CLASS
|
2
|
+
BEGIN
|
3
|
+
MultiUse = -1 'True
|
4
|
+
END
|
5
|
+
Attribute VB_Name = "WebResponse"
|
6
|
+
Attribute VB_GlobalNameSpace = False
|
7
|
+
Attribute VB_Creatable = False
|
8
|
+
Attribute VB_PredeclaredId = False
|
9
|
+
Attribute VB_Exposed = True
|
10
|
+
''
|
11
|
+
' CHANGED:
|
12
|
+
' This version includes support for unicode handling on Windows
|
13
|
+
' by incorporating https://github.com/VBA-tools/VBA-Web/pull/305/files
|
14
|
+
' but enhanced so it's ignored by macOS and works with both 64 and 32bit Excel
|
15
|
+
'
|
16
|
+
' WebResponse v4.1.6
|
17
|
+
' (c) Tim Hall - https://github.com/VBA-tools/VBA-Web
|
18
|
+
'
|
19
|
+
' Wrapper for http/cURL responses that includes parsed Data based on WebRequest.ResponseFormat.
|
20
|
+
'
|
21
|
+
' Usage:
|
22
|
+
' ```VB.net
|
23
|
+
' Dim Response As WebResponse
|
24
|
+
' Set Response = Client.Execute(Request)
|
25
|
+
'
|
26
|
+
' If Response.StatusCode = WebStatusCode.Ok Then
|
27
|
+
' ' Response.Headers, Response.Cookies
|
28
|
+
' ' Response.Data -> Parsed Response.Content based on Request.ResponseFormat
|
29
|
+
' ' Response.Body -> Raw response bytes
|
30
|
+
' Else
|
31
|
+
' Debug.Print "Error: " & Response.StatusCode & " - " & Response.Content
|
32
|
+
' End If
|
33
|
+
' ```
|
34
|
+
'
|
35
|
+
' Errors:
|
36
|
+
' 11030 / 80042b16 / -2147210474 - Error creating from http
|
37
|
+
' 11031 / 80042b17 / -2147210473 - Error creating from cURL
|
38
|
+
' 11032 / 80042b18 / -2147210472 - Error extracting headers
|
39
|
+
'
|
40
|
+
' @class WebResponse
|
41
|
+
' @author tim.hall.engr@gmail.com
|
42
|
+
' @license MIT (http://www.opensource.org/licenses/mit-license.php)
|
43
|
+
'' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '
|
44
|
+
Option Explicit
|
45
|
+
|
46
|
+
Private Const CP_UTF8 = 65001
|
47
|
+
|
48
|
+
#If Mac Then
|
49
|
+
#ElseIf VBA7 Then
|
50
|
+
Private Declare PtrSafe Function MultiByteToWideChar Lib "KERNEL32" ( _
|
51
|
+
ByVal CodePage As Long, ByVal dwFlags As Long, _
|
52
|
+
ByVal lpMultiByteStr As LongPtr, ByVal cchMultiByte As Long, _
|
53
|
+
ByVal lpWideCharStr As LongPtr, ByVal cchWideChar As Long) As Long
|
54
|
+
#Else
|
55
|
+
Private Declare Function MultiByteToWideChar Lib "KERNEL32" ( _
|
56
|
+
ByVal CodePage As Long, ByVal dwFlags As Long, _
|
57
|
+
ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, _
|
58
|
+
ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long
|
59
|
+
#End If
|
60
|
+
Private web_CrLf As String
|
61
|
+
|
62
|
+
' --------------------------------------------- '
|
63
|
+
' Properties
|
64
|
+
' --------------------------------------------- '
|
65
|
+
|
66
|
+
''
|
67
|
+
' Status code that the server returned (e.g. 200).
|
68
|
+
'
|
69
|
+
' @property StatusCode
|
70
|
+
' @type WebStatusCode
|
71
|
+
''
|
72
|
+
Public StatusCode As WebStatusCode
|
73
|
+
|
74
|
+
''
|
75
|
+
' Status string that the server returned (e.g. `404 -> "Not Found"`)
|
76
|
+
'
|
77
|
+
' @property StatusDescription
|
78
|
+
' @type String
|
79
|
+
''
|
80
|
+
Public StatusDescription As String
|
81
|
+
|
82
|
+
''
|
83
|
+
' Content string that the server returned.
|
84
|
+
'
|
85
|
+
' @property Content
|
86
|
+
' @type String
|
87
|
+
''
|
88
|
+
Public Content As String
|
89
|
+
|
90
|
+
''
|
91
|
+
' Raw bytes for the response.
|
92
|
+
'
|
93
|
+
' @property Body
|
94
|
+
' @type Byte()
|
95
|
+
''
|
96
|
+
Public Body As Variant
|
97
|
+
|
98
|
+
''
|
99
|
+
' Parsed `Content` or `Body` based on the `WebRequest.ResponseFormat`.
|
100
|
+
'
|
101
|
+
' @property Data
|
102
|
+
' @type Dictionary|Collection
|
103
|
+
''
|
104
|
+
Public Data As Object
|
105
|
+
|
106
|
+
''
|
107
|
+
' Headers that were included with the response.
|
108
|
+
' (`Collection` of `KeyValue`)
|
109
|
+
'
|
110
|
+
' @property Headers
|
111
|
+
' @type Collection
|
112
|
+
''
|
113
|
+
Public headers As Collection
|
114
|
+
|
115
|
+
''
|
116
|
+
' Cookies that were included with the response.
|
117
|
+
' (`Collection` of `KeyValue`)
|
118
|
+
'
|
119
|
+
' @property Cookies
|
120
|
+
' @type Collection
|
121
|
+
''
|
122
|
+
Public Cookies As Collection
|
123
|
+
|
124
|
+
' ============================================= '
|
125
|
+
' Public Methods
|
126
|
+
' ============================================= '
|
127
|
+
|
128
|
+
''
|
129
|
+
' Helper for updating the response with the given updated response values.
|
130
|
+
' Useful for `ByRef` cases to update response in place.
|
131
|
+
'
|
132
|
+
' @method Update
|
133
|
+
' @param Updated {WebResponse} Updated `WebResponse` to pull updated values from
|
134
|
+
''
|
135
|
+
Public Sub Update(Updated As WebResponse)
|
136
|
+
Me.StatusCode = Updated.StatusCode
|
137
|
+
Me.StatusDescription = Updated.StatusDescription
|
138
|
+
Me.Content = Updated.Content
|
139
|
+
Me.Body = Updated.Body
|
140
|
+
Set Me.headers = Updated.headers
|
141
|
+
Set Me.Cookies = Updated.Cookies
|
142
|
+
Set Me.Data = Updated.Data
|
143
|
+
End Sub
|
144
|
+
|
145
|
+
''
|
146
|
+
' Create response from http
|
147
|
+
'
|
148
|
+
' @internal
|
149
|
+
' @method CreateFromHttp
|
150
|
+
' @param {WebClient} Client
|
151
|
+
' @param {WebRequest} Request
|
152
|
+
' @param {WinHttpRequest} Http
|
153
|
+
' @throws 11030 / 80042b16 / -2147210474 - Error creating from http
|
154
|
+
''
|
155
|
+
Public Sub CreateFromHttp(Client As WebClient, Request As WebRequest, Http As Object)
|
156
|
+
Dim bodyBytes() As Byte
|
157
|
+
On Error GoTo web_ErrorHandling
|
158
|
+
|
159
|
+
Me.StatusCode = Http.Status
|
160
|
+
Me.StatusDescription = Http.StatusText
|
161
|
+
' WinHttpRequest.ResponseText has been decoded with the users code page (CP_ACP)
|
162
|
+
' This is completely useless. Assume UTF8 here.
|
163
|
+
' TODO: detect from response headers, allow override by caller
|
164
|
+
bodyBytes = Http.ResponseBody
|
165
|
+
Me.Content = web_UTF8ToUni(bodyBytes)
|
166
|
+
Me.Body = Http.ResponseBody
|
167
|
+
|
168
|
+
web_LoadValues Http.GetAllResponseHeaders, Me.Content, Me.Body, Request
|
169
|
+
|
170
|
+
Exit Sub
|
171
|
+
|
172
|
+
web_ErrorHandling:
|
173
|
+
|
174
|
+
Dim web_ErrorDescription As String
|
175
|
+
web_ErrorDescription = "An error occurred while creating response from http" & vbNewLine & _
|
176
|
+
Err.Number & VBA.IIf(Err.Number < 0, " (" & VBA.LCase$(VBA.Hex$(Err.Number)) & ")", "") & ": " & Err.Description
|
177
|
+
|
178
|
+
WebHelpers.LogError web_ErrorDescription, "WebResponse.CreateFromHttp", 11030 + vbObjectError
|
179
|
+
Err.Raise 11030 + vbObjectError, "WebResponse.CreateFromHttp", web_ErrorDescription
|
180
|
+
End Sub
|
181
|
+
|
182
|
+
''
|
183
|
+
' Create response from cURL
|
184
|
+
'
|
185
|
+
' @internal
|
186
|
+
' @method CreateFromCurl
|
187
|
+
' @param {WebClient} Client
|
188
|
+
' @param {WebRequest} Request
|
189
|
+
' @param {String} Result
|
190
|
+
' @throws 11031 / 80042b17 / -2147210473 - Error creating from cURL
|
191
|
+
''
|
192
|
+
Public Sub CreateFromCurl(Client As WebClient, Request As WebRequest, Result As String)
|
193
|
+
On Error GoTo web_ErrorHandling
|
194
|
+
|
195
|
+
Dim web_Lines() As String
|
196
|
+
|
197
|
+
web_Lines = VBA.Split(Result, web_CrLf)
|
198
|
+
|
199
|
+
Me.StatusCode = web_ExtractStatusFromCurlResponse(web_Lines)
|
200
|
+
Me.StatusDescription = web_ExtractStatusTextFromCurlResponse(web_Lines)
|
201
|
+
Me.Content = web_ExtractResponseTextFromCurlResponse(web_Lines)
|
202
|
+
Me.Body = WebHelpers.StringToAnsiBytes(Me.Content)
|
203
|
+
|
204
|
+
web_LoadValues web_ExtractHeadersFromCurlResponse(web_Lines), Me.Content, Me.Body, Request
|
205
|
+
|
206
|
+
Exit Sub
|
207
|
+
|
208
|
+
web_ErrorHandling:
|
209
|
+
|
210
|
+
Dim web_ErrorDescription As String
|
211
|
+
web_ErrorDescription = "An error occurred while creating response from cURL" & vbNewLine & _
|
212
|
+
Err.Number & VBA.IIf(Err.Number < 0, " (" & VBA.LCase$(VBA.Hex$(Err.Number)) & ")", "") & ": " & Err.Description
|
213
|
+
|
214
|
+
WebHelpers.LogError web_ErrorDescription, "WebResponse.CreateFromCurl", 11031 + vbObjectError
|
215
|
+
Err.Raise 11031 + vbObjectError, "WebResponse.CreateFromCurl", web_ErrorDescription
|
216
|
+
End Sub
|
217
|
+
|
218
|
+
''
|
219
|
+
' Extract headers from response headers
|
220
|
+
'
|
221
|
+
' @internal
|
222
|
+
' @method ExtractHeaders
|
223
|
+
' @param {String} ResponseHeaders
|
224
|
+
' @return {Collection} Headers
|
225
|
+
' @throws 11032 / 80042b18 / -2147210472 - Error extracting headers
|
226
|
+
''
|
227
|
+
Public Function ExtractHeaders(ResponseHeaders As String) As Collection
|
228
|
+
On Error GoTo web_ErrorHandling
|
229
|
+
|
230
|
+
Dim web_Lines As Variant
|
231
|
+
Dim web_i As Integer
|
232
|
+
Dim web_Headers As New Collection
|
233
|
+
Dim web_Header As Dictionary
|
234
|
+
Dim web_ColonPosition As Long
|
235
|
+
Dim web_Multiline As Boolean
|
236
|
+
|
237
|
+
web_Lines = VBA.Split(ResponseHeaders, web_CrLf)
|
238
|
+
|
239
|
+
For web_i = LBound(web_Lines) To (UBound(web_Lines) + 1)
|
240
|
+
If web_i > UBound(web_Lines) Then
|
241
|
+
web_Headers.Add web_Header
|
242
|
+
ElseIf web_Lines(web_i) <> "" Then
|
243
|
+
web_ColonPosition = VBA.InStr(1, web_Lines(web_i), ":")
|
244
|
+
If web_ColonPosition = 0 And Not web_Header Is Nothing Then
|
245
|
+
' Assume part of multi-line header
|
246
|
+
web_Multiline = True
|
247
|
+
ElseIf web_Multiline Then
|
248
|
+
' Close out multi-line string
|
249
|
+
web_Multiline = False
|
250
|
+
web_Headers.Add web_Header
|
251
|
+
ElseIf Not web_Header Is Nothing Then
|
252
|
+
' Add previous header
|
253
|
+
web_Headers.Add web_Header
|
254
|
+
End If
|
255
|
+
|
256
|
+
If Not web_Multiline Then
|
257
|
+
Set web_Header = WebHelpers.CreateKeyValue( _
|
258
|
+
Key:=VBA.Trim(VBA.Mid$(web_Lines(web_i), 1, web_ColonPosition - 1)), _
|
259
|
+
Value:=VBA.Trim(VBA.Mid$(web_Lines(web_i), web_ColonPosition + 1, VBA.Len(web_Lines(web_i)))) _
|
260
|
+
)
|
261
|
+
Else
|
262
|
+
web_Header("Value") = web_Header("Value") & web_CrLf & web_Lines(web_i)
|
263
|
+
End If
|
264
|
+
End If
|
265
|
+
Next web_i
|
266
|
+
|
267
|
+
Set ExtractHeaders = web_Headers
|
268
|
+
Exit Function
|
269
|
+
|
270
|
+
web_ErrorHandling:
|
271
|
+
|
272
|
+
Dim web_ErrorDescription As String
|
273
|
+
web_ErrorDescription = "An error occurred while extracting headers" & vbNewLine & _
|
274
|
+
Err.Number & VBA.IIf(Err.Number < 0, " (" & VBA.LCase$(VBA.Hex$(Err.Number)) & ")", "") & ": " & Err.Description
|
275
|
+
|
276
|
+
WebHelpers.LogError web_ErrorDescription, "WebResponse.CreateFromCurl", 11032 + vbObjectError
|
277
|
+
Err.Raise 11032 + vbObjectError, "WebResponse.CreateFromCurl", web_ErrorDescription
|
278
|
+
End Function
|
279
|
+
|
280
|
+
''
|
281
|
+
' Extract cookies from response headers
|
282
|
+
'
|
283
|
+
' @internal
|
284
|
+
' @method ExtractCookies
|
285
|
+
' @param {Collection} Headers
|
286
|
+
' @return {Collection} Cookies
|
287
|
+
''
|
288
|
+
Public Function ExtractCookies(headers As Collection) As Collection
|
289
|
+
Dim web_Header As Dictionary
|
290
|
+
Dim web_Cookie As String
|
291
|
+
Dim web_Key As String
|
292
|
+
Dim web_Value As String
|
293
|
+
Dim web_Cookies As New Collection
|
294
|
+
|
295
|
+
For Each web_Header In headers
|
296
|
+
If web_Header("Key") = "Set-Cookie" Then
|
297
|
+
web_Cookie = web_Header("Value")
|
298
|
+
If VBA.InStr(1, web_Cookie, "=") > 0 Then
|
299
|
+
web_Key = VBA.Mid$(web_Cookie, 1, VBA.InStr(1, web_Cookie, "=") - 1)
|
300
|
+
web_Value = VBA.Mid$(web_Cookie, VBA.InStr(1, web_Cookie, "=") + 1, VBA.Len(web_Cookie))
|
301
|
+
|
302
|
+
' Ignore text after semi-colon
|
303
|
+
If VBA.InStr(1, web_Value, ";") > 0 Then
|
304
|
+
web_Value = VBA.Mid$(web_Value, 1, VBA.InStr(1, web_Value, ";") - 1)
|
305
|
+
End If
|
306
|
+
|
307
|
+
' Ignore surrounding quotes
|
308
|
+
If VBA.Left$(web_Value, 1) = """" Then
|
309
|
+
web_Value = VBA.Mid$(web_Value, 2, VBA.Len(web_Value) - 2)
|
310
|
+
End If
|
311
|
+
|
312
|
+
web_Cookies.Add WebHelpers.CreateKeyValue(web_Key, WebHelpers.UrlDecode(web_Value, PlusAsSpace:=False, EncodingMode:=UrlEncodingMode.CookieUrlEncoding))
|
313
|
+
Else
|
314
|
+
WebHelpers.LogWarning _
|
315
|
+
"Unrecognized cookie format: " & web_Cookie, "WebResponse.ExtractCookies"
|
316
|
+
End If
|
317
|
+
End If
|
318
|
+
Next web_Header
|
319
|
+
|
320
|
+
Set ExtractCookies = web_Cookies
|
321
|
+
End Function
|
322
|
+
|
323
|
+
' ============================================= '
|
324
|
+
' Private Functions
|
325
|
+
' ============================================= '
|
326
|
+
|
327
|
+
Private Sub web_LoadValues(web_Headers As String, web_Content As String, web_Body As Variant, web_Request As WebRequest)
|
328
|
+
' Convert content to data by format
|
329
|
+
If web_Request.ResponseFormat <> WebFormat.PlainText Then
|
330
|
+
On Error Resume Next
|
331
|
+
Set Me.Data = _
|
332
|
+
WebHelpers.ParseByFormat(web_Content, web_Request.ResponseFormat, web_Request.CustomResponseFormat, web_Body)
|
333
|
+
|
334
|
+
If Err.Number <> 0 Then
|
335
|
+
WebHelpers.LogError Err.Description, Err.source, Err.Number
|
336
|
+
Err.Clear
|
337
|
+
End If
|
338
|
+
On Error GoTo 0
|
339
|
+
End If
|
340
|
+
|
341
|
+
' Extract headers
|
342
|
+
Set Me.headers = ExtractHeaders(web_Headers)
|
343
|
+
|
344
|
+
' Extract cookies
|
345
|
+
Set Me.Cookies = ExtractCookies(Me.headers)
|
346
|
+
End Sub
|
347
|
+
|
348
|
+
Private Function web_ExtractStatusFromCurlResponse(web_CurlResponseLines() As String) As Long
|
349
|
+
Dim web_StatusLineParts() As String
|
350
|
+
|
351
|
+
web_StatusLineParts = VBA.Split(web_CurlResponseLines(web_FindStatusLine(web_CurlResponseLines)), " ")
|
352
|
+
web_ExtractStatusFromCurlResponse = VBA.CLng(web_StatusLineParts(1))
|
353
|
+
End Function
|
354
|
+
|
355
|
+
Private Function web_ExtractStatusTextFromCurlResponse(web_CurlResponseLines() As String) As String
|
356
|
+
Dim web_StatusLineParts() As String
|
357
|
+
Dim web_i As Long
|
358
|
+
Dim web_StatusText As String
|
359
|
+
|
360
|
+
web_StatusLineParts = VBA.Split(web_CurlResponseLines(web_FindStatusLine(web_CurlResponseLines)), " ", 3)
|
361
|
+
web_ExtractStatusTextFromCurlResponse = web_StatusLineParts(2)
|
362
|
+
End Function
|
363
|
+
|
364
|
+
Private Function web_ExtractHeadersFromCurlResponse(web_CurlResponseLines() As String) As String
|
365
|
+
Dim web_StatusLineIndex As Long
|
366
|
+
Dim web_BlankLineIndex As Long
|
367
|
+
Dim web_HeaderLines() As String
|
368
|
+
Dim web_WriteIndex As Long
|
369
|
+
Dim web_ReadIndex As Long
|
370
|
+
|
371
|
+
' Find status line and blank line before body
|
372
|
+
web_StatusLineIndex = web_FindStatusLine(web_CurlResponseLines)
|
373
|
+
web_BlankLineIndex = web_FindBlankLine(web_CurlResponseLines)
|
374
|
+
|
375
|
+
' Extract headers string
|
376
|
+
ReDim web_HeaderLines(0 To web_BlankLineIndex - 2 - web_StatusLineIndex)
|
377
|
+
|
378
|
+
web_WriteIndex = 0
|
379
|
+
For web_ReadIndex = (web_StatusLineIndex + 1) To web_BlankLineIndex - 1
|
380
|
+
web_HeaderLines(web_WriteIndex) = web_CurlResponseLines(web_ReadIndex)
|
381
|
+
web_WriteIndex = web_WriteIndex + 1
|
382
|
+
Next web_ReadIndex
|
383
|
+
|
384
|
+
web_ExtractHeadersFromCurlResponse = VBA.Join$(web_HeaderLines, web_CrLf)
|
385
|
+
End Function
|
386
|
+
|
387
|
+
Private Function web_ExtractResponseTextFromCurlResponse(web_CurlResponseLines() As String) As String
|
388
|
+
Dim web_BlankLineIndex As Long
|
389
|
+
Dim web_BodyLines() As String
|
390
|
+
Dim web_WriteIndex As Long
|
391
|
+
Dim web_ReadIndex As Long
|
392
|
+
|
393
|
+
' Find blank line before body
|
394
|
+
web_BlankLineIndex = web_FindBlankLine(web_CurlResponseLines)
|
395
|
+
|
396
|
+
' Extract body string
|
397
|
+
ReDim web_BodyLines(0 To UBound(web_CurlResponseLines) - web_BlankLineIndex - 1)
|
398
|
+
|
399
|
+
web_WriteIndex = 0
|
400
|
+
For web_ReadIndex = web_BlankLineIndex + 1 To UBound(web_CurlResponseLines)
|
401
|
+
web_BodyLines(web_WriteIndex) = web_CurlResponseLines(web_ReadIndex)
|
402
|
+
web_WriteIndex = web_WriteIndex + 1
|
403
|
+
Next web_ReadIndex
|
404
|
+
|
405
|
+
web_ExtractResponseTextFromCurlResponse = VBA.Join$(web_BodyLines, web_CrLf)
|
406
|
+
End Function
|
407
|
+
|
408
|
+
Private Function web_FindStatusLine(web_CurlResponseLines() As String) As Long
|
409
|
+
' Special case for cURL: 100 Continue is included before final status code
|
410
|
+
' -> ignore 100 and find final status code (next non-100 status code)
|
411
|
+
For web_FindStatusLine = LBound(web_CurlResponseLines) To UBound(web_CurlResponseLines)
|
412
|
+
If VBA.Trim$(web_CurlResponseLines(web_FindStatusLine)) <> "" Then
|
413
|
+
If VBA.Split(web_CurlResponseLines(web_FindStatusLine), " ")(1) <> "100" Then
|
414
|
+
Exit Function
|
415
|
+
End If
|
416
|
+
End If
|
417
|
+
Next web_FindStatusLine
|
418
|
+
End Function
|
419
|
+
|
420
|
+
Private Function web_FindBlankLine(web_CurlResponseLines() As String) As Long
|
421
|
+
For web_FindBlankLine = (web_FindStatusLine(web_CurlResponseLines) + 1) To UBound(web_CurlResponseLines)
|
422
|
+
If VBA.Trim$(web_CurlResponseLines(web_FindBlankLine)) = "" Then
|
423
|
+
Exit Function
|
424
|
+
End If
|
425
|
+
Next web_FindBlankLine
|
426
|
+
End Function
|
427
|
+
|
428
|
+
Private Function web_UTF8ToUni(bySrc() As Byte) As String
|
429
|
+
' Converts a UTF-8 byte array to a Unicode string
|
430
|
+
#If Mac Then
|
431
|
+
#Else
|
432
|
+
Dim lBytes As Long, lNC As Long, lRet As Long
|
433
|
+
|
434
|
+
' Size of bytes array, return null string if less than 2
|
435
|
+
lBytes = UBound(bySrc) - LBound(bySrc) + 1
|
436
|
+
If lBytes < 2 Then
|
437
|
+
web_UTF8ToUni = vbNullString
|
438
|
+
Exit Function
|
439
|
+
End If
|
440
|
+
|
441
|
+
' Get the length of the data, create array big enough, and convert
|
442
|
+
lRet = MultiByteToWideChar(CP_UTF8, 0, VarPtr(bySrc(0)), lBytes, 0, 0)
|
443
|
+
web_UTF8ToUni = String$(lRet, 0)
|
444
|
+
MultiByteToWideChar CP_UTF8, 0, VarPtr(bySrc(0)), lBytes, StrPtr(web_UTF8ToUni), lRet
|
445
|
+
#End If
|
446
|
+
End Function
|
447
|
+
|
448
|
+
Private Sub Class_Initialize()
|
449
|
+
web_CrLf = VBA.Chr$(13) & VBA.Chr$(10)
|
450
|
+
|
451
|
+
Set headers = New Collection
|
452
|
+
Set Cookies = New Collection
|
453
|
+
End Sub
|
Binary file
|
tdrpa/_tdxlwings/apps.py
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
from .main import Apps, Books, App
|
2
|
+
from . import _xlwindows
|
3
|
+
|
4
|
+
class AppsEx(Apps):
|
5
|
+
_name = 'AppsEx'
|
6
|
+
|
7
|
+
@property
|
8
|
+
def activeapps(self):
|
9
|
+
applist = []
|
10
|
+
for app in self.impl:
|
11
|
+
tmp = App(impl=app)
|
12
|
+
if tmp not in applist:
|
13
|
+
applist.append(App(impl=app))
|
14
|
+
return applist
|
15
|
+
|
16
|
+
appsex = AppsEx(impl=_xlwindows.Apps())
|
17
|
+
|
18
|
+
class ActiveApps(Books):
|
19
|
+
|
20
|
+
def __init__(self):
|
21
|
+
pass
|
22
|
+
|
23
|
+
_name = 'Apps'
|
24
|
+
|
25
|
+
@property
|
26
|
+
def impl(self):
|
27
|
+
impllist = []
|
28
|
+
for appbooks in appsex.activeapps:
|
29
|
+
for impl in appbooks.books.impl:
|
30
|
+
impllist.append(impl)
|
31
|
+
|
32
|
+
for impl in impllist:
|
33
|
+
yield impl
|
34
|
+
|
35
|
+
AppsBooks = ActiveApps()
|