@darabonba/python-generator 1.2.19 → 2.0.1
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.
- package/ChangeLog.md +0 -158
- package/lib/builtin.js +818 -0
- package/lib/generator.js +2708 -0
- package/lib/helper.js +422 -0
- package/package.json +6 -5
- package/tests/expected/alias/setup.py +79 -0
- package/tests/expected/alias/tea_python_tests/__init__.py +1 -0
- package/tests/expected/alias/tea_python_tests/client.py +35 -0
- package/tests/expected/annotation/tea_python_tests/__init__.py +1 -0
- package/tests/expected/annotation/tea_python_tests/client.py +93 -0
- package/tests/expected/annotation/tea_python_tests/models.py +37 -0
- package/tests/expected/api/tea_python_tests/__init__.py +1 -0
- package/tests/expected/api/tea_python_tests/client.py +106 -0
- package/tests/expected/builtin/tea_python_tests/client.py +685 -0
- package/tests/expected/comment/tea_python_tests/__init__.py +1 -0
- package/tests/expected/comment/tea_python_tests/client.py +288 -0
- package/tests/expected/comment/tea_python_tests/models.py +195 -0
- package/tests/expected/complex/tea_python_tests/__init__.py +1 -0
- package/tests/expected/complex/tea_python_tests/client.py +1169 -0
- package/tests/expected/complex/tea_python_tests/exceptions.py +39 -0
- package/tests/expected/complex/tea_python_tests/models.py +570 -0
- package/tests/expected/const/tea_python_tests/__init__.py +1 -0
- package/tests/expected/const/tea_python_tests/client.py +14 -0
- package/{src/langs/python/files/setup.py.tmpl → tests/expected/empty/setup.py} +11 -11
- package/tests/expected/empty/tea_python_tests/__init__.py +1 -0
- package/tests/expected/empty/tea_python_tests/client.py +10 -0
- package/tests/expected/exec/tea_python_tests/__init__.py +1 -0
- package/tests/expected/exec/tea_python_tests/exec_client.py +21 -0
- package/tests/expected/function/tea_python_tests/__init__.py +1 -0
- package/tests/expected/function/tea_python_tests/client.py +64 -0
- package/tests/expected/import/setup.py +78 -0
- package/tests/expected/import/tea_python_tests/__init__.py +1 -0
- package/tests/expected/import/tea_python_tests/client.py +29 -0
- package/tests/expected/map/tea_python_tests/__init__.py +1 -0
- package/tests/expected/map/tea_python_tests/client.py +39 -0
- package/tests/expected/model/tea_python_tests/__init__.py +1 -0
- package/tests/expected/model/tea_python_tests/client.py +10 -0
- package/tests/expected/model/tea_python_tests/exceptions.py +28 -0
- package/tests/expected/model/tea_python_tests/models.py +780 -0
- package/tests/expected/multi/tea_python_tests/api.py +95 -0
- package/tests/expected/multi/tea_python_tests/client.py +40 -0
- package/tests/expected/multi/tea_python_tests/lib/util.py +19 -0
- package/tests/expected/multi/tea_python_tests/model/user.py +26 -0
- package/tests/expected/multi/tea_python_tests/model/user_exceptions.py +83 -0
- package/tests/expected/multi/tea_python_tests/model/user_models.py +145 -0
- package/tests/expected/statements/tea_python_tests/__init__.py +1 -0
- package/tests/expected/statements/tea_python_tests/client.py +86 -0
- package/tests/expected/super/tea_python_tests/__init__.py +1 -0
- package/tests/expected/super/tea_python_tests/client.py +16 -0
- package/tests/expected/typedef/setup.py +77 -0
- package/tests/expected/typedef/tea_python_tests/__init__.py +1 -0
- package/tests/expected/typedef/tea_python_tests/client.py +74 -0
- package/tests/expected/typedef/tea_python_tests/models.py +42 -0
- package/tests/fixtures/alias/Darafile +11 -0
- package/tests/fixtures/alias/libraries/Alias/Darafile +11 -0
- package/tests/fixtures/alias/libraries/Alias-Symbol/Darafile +11 -0
- package/tests/fixtures/builtin/Darafile +6 -0
- package/tests/fixtures/builtin/main.dara +333 -0
- package/tests/fixtures/complex/libraries/import.dara +18 -11
- package/tests/fixtures/complex/main.dara +452 -103
- package/tests/fixtures/import/libraries/Darafile +1 -1
- package/tests/fixtures/import/pack/Darafile +3 -0
- package/tests/fixtures/map/libraries/Darafile +3 -0
- package/tests/fixtures/map/libraries/import.dara +4 -0
- package/tests/fixtures/map/main.dara +17 -2
- package/tests/fixtures/model/.libraries.json +3 -0
- package/tests/fixtures/model/Darafile +5 -2
- package/tests/fixtures/model/libraries/Darafile +20 -0
- package/tests/fixtures/model/libraries/import.dara +27 -0
- package/tests/fixtures/model/main.dara +60 -42
- package/tests/fixtures/multi/.libraries.json +3 -0
- package/tests/fixtures/multi/Darafile +12 -0
- package/tests/fixtures/multi/api.dara +20 -0
- package/tests/fixtures/multi/lib/util.dara +5 -0
- package/tests/fixtures/multi/libraries/darabonba_Util_0.2.11/Teafile +68 -0
- package/tests/fixtures/multi/libraries/darabonba_Util_0.2.11/main.tea +244 -0
- package/tests/fixtures/multi/libraries/darabonba_Util_0.2.11/util.tea +2 -0
- package/tests/fixtures/multi/main.dara +32 -0
- package/tests/fixtures/multi/model/user.dara +35 -0
- package/tests/{python3.tests.js → main.tests.js} +107 -65
- package/tests/output/alias/setup.py +79 -0
- package/tests/output/alias/tea_python_tests/client.py +35 -0
- package/{src/langs/python2/files/setup.py.tmpl → tests/output/annotation/setup.py} +19 -24
- package/tests/output/annotation/tea_python_tests/client.py +93 -0
- package/tests/output/annotation/tea_python_tests/models.py +37 -0
- package/tests/output/api/setup.py +77 -0
- package/tests/output/api/tea_python_tests/client.py +106 -0
- package/tests/output/builtin/setup.py +77 -0
- package/tests/output/builtin/tea_python_tests/client.py +685 -0
- package/tests/output/comment/setup.py +77 -0
- package/tests/output/comment/tea_python_tests/client.py +288 -0
- package/tests/output/comment/tea_python_tests/models.py +195 -0
- package/tests/output/complex/setup.py +77 -0
- package/tests/output/complex/tea_python_tests/client.py +1169 -0
- package/tests/output/complex/tea_python_tests/exceptions.py +39 -0
- package/tests/output/complex/tea_python_tests/models.py +570 -0
- package/tests/output/const/setup.py +77 -0
- package/tests/output/const/tea_python_tests/client.py +14 -0
- package/tests/output/empty/setup.py +77 -0
- package/tests/output/empty/tea_python_tests/client.py +10 -0
- package/tests/output/exec/setup.py +77 -0
- package/tests/output/exec/tea_python_tests/exec_client.py +21 -0
- package/tests/output/function/setup.py +77 -0
- package/tests/output/function/tea_python_tests/client.py +64 -0
- package/tests/output/import/setup.py +78 -0
- package/tests/output/import/tea_python_tests/client.py +29 -0
- package/tests/output/map/setup.py +77 -0
- package/tests/output/map/tea_python_tests/client.py +39 -0
- package/tests/output/model/setup.py +77 -0
- package/tests/output/model/tea_python_tests/client.py +10 -0
- package/tests/output/model/tea_python_tests/exceptions.py +28 -0
- package/tests/output/model/tea_python_tests/models.py +780 -0
- package/tests/output/multi/setup.py +77 -0
- package/tests/output/multi/tea_python_tests/api.py +95 -0
- package/tests/output/multi/tea_python_tests/client.py +40 -0
- package/tests/output/multi/tea_python_tests/lib/util.py +19 -0
- package/tests/output/multi/tea_python_tests/model/user.py +26 -0
- package/tests/output/multi/tea_python_tests/model/user_exceptions.py +83 -0
- package/tests/output/multi/tea_python_tests/model/user_models.py +145 -0
- package/tests/output/statements/setup.py +77 -0
- package/tests/output/statements/tea_python_tests/client.py +86 -0
- package/tests/output/super/setup.py +77 -0
- package/tests/output/super/tea_python_tests/client.py +16 -0
- package/tests/output/typedef/setup.py +78 -0
- package/tests/output/typedef/tea_python_tests/client.py +74 -0
- package/tests/output/typedef/tea_python_tests/models.py +42 -0
- package/src/generator.js +0 -231
- package/src/langs/common/combinator.js +0 -193
- package/src/langs/common/config.js +0 -60
- package/src/langs/common/enum.js +0 -179
- package/src/langs/common/items.js +0 -551
- package/src/langs/common/package_info.js +0 -53
- package/src/langs/python/combinator.js +0 -1898
- package/src/langs/python/config.js +0 -169
- package/src/langs/python/files/.gitignore.tmpl +0 -5
- package/src/langs/python/files/__init__.py.tmpl +0 -1
- package/src/langs/python/package_info.js +0 -78
- package/src/langs/python2/combinator.js +0 -1770
- package/src/langs/python2/config.js +0 -162
- package/src/langs/python2/files/.gitignore.tmpl +0 -5
- package/src/langs/python2/files/__init__.py.tmpl +0 -1
- package/src/langs/python2/package_info.js +0 -78
- package/src/lib/debug.js +0 -55
- package/src/lib/emitter.js +0 -95
- package/src/lib/helper.js +0 -207
- package/src/resolver/base.js +0 -282
- package/src/resolver/client.js +0 -1013
- package/src/resolver/model.js +0 -159
- package/tests/common.tests.js +0 -244
- package/tests/lib.tests.js +0 -269
- package/tests/python2.tests.js +0 -283
- package/tests/resolver.tests.js +0 -434
package/lib/helper.js
ADDED
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const DSL = require('@darabonba/parser');
|
|
3
|
+
|
|
4
|
+
const keywords = [
|
|
5
|
+
'False', 'None', 'True', '__peg_parser__', 'and',
|
|
6
|
+
'as', 'assert', 'async', 'await', 'break',
|
|
7
|
+
'class', 'continue', 'def', 'del', 'elif',
|
|
8
|
+
'else', 'except', 'finally', 'for', 'from',
|
|
9
|
+
'global', 'if', 'import', 'in', 'is',
|
|
10
|
+
'lambda', 'nonlocal', 'not', 'or', 'pass',
|
|
11
|
+
'raise', 'return', 'try', 'while', 'with', 'yield'
|
|
12
|
+
];
|
|
13
|
+
|
|
14
|
+
const builtinModels = [
|
|
15
|
+
'$Request', '$Response', '$Error', '$SSEEvent', '$Model',
|
|
16
|
+
'$RuntimeOptions', '$ExtendsParameters', '$RetryOptions',
|
|
17
|
+
'$ResponseError', '$FileField'
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
const CORE = 'Dara';
|
|
21
|
+
const REQUEST = '_request';
|
|
22
|
+
const RESPONSE = '_response';
|
|
23
|
+
const EXCEPTION = 'darabonba.exceptions.DaraException';
|
|
24
|
+
const RESP_EXCEPTION = 'darabonba.exceptions.ResponseException';
|
|
25
|
+
const MODEL = 'darabonba.model';
|
|
26
|
+
|
|
27
|
+
const builtinImports = {
|
|
28
|
+
DaraStream: {
|
|
29
|
+
packageName: 'darabonba.utils.stream',
|
|
30
|
+
className: 'Stream',
|
|
31
|
+
aliasName: 'DaraStream'
|
|
32
|
+
},
|
|
33
|
+
DaraConsole: {
|
|
34
|
+
packageName: 'darabonba.utils.console',
|
|
35
|
+
className: 'Logger',
|
|
36
|
+
aliasName: 'DaraConsole'
|
|
37
|
+
},
|
|
38
|
+
DaraXML: {
|
|
39
|
+
packageName: 'darabonba.utils.xml',
|
|
40
|
+
className: 'XML',
|
|
41
|
+
aliasName: 'DaraXML'
|
|
42
|
+
},
|
|
43
|
+
DaraURL: {
|
|
44
|
+
packageName: 'darabonba.url',
|
|
45
|
+
className: 'Url',
|
|
46
|
+
aliasName: 'DaraURL'
|
|
47
|
+
},
|
|
48
|
+
DaraForm: {
|
|
49
|
+
packageName: 'darabonba.utils.form',
|
|
50
|
+
className: 'Form',
|
|
51
|
+
aliasName: 'DaraForm'
|
|
52
|
+
},
|
|
53
|
+
DaraFile: {
|
|
54
|
+
packageName: 'darabonba.file',
|
|
55
|
+
className: 'File',
|
|
56
|
+
aliasName: 'DaraFile'
|
|
57
|
+
},
|
|
58
|
+
DaraBytes: {
|
|
59
|
+
packageName: 'darabonba.utils.bytes',
|
|
60
|
+
className: 'Bytes',
|
|
61
|
+
aliasName: 'DaraBytes'
|
|
62
|
+
},
|
|
63
|
+
DaraDate: {
|
|
64
|
+
packageName: 'darabonba.date',
|
|
65
|
+
className: 'Date',
|
|
66
|
+
aliasName: 'DaraDate'
|
|
67
|
+
},
|
|
68
|
+
DaraCore: {
|
|
69
|
+
packageName: 'darabonba.core',
|
|
70
|
+
className: 'DaraCore',
|
|
71
|
+
},
|
|
72
|
+
DaraRequest: {
|
|
73
|
+
packageName: 'darabonba.request',
|
|
74
|
+
className: 'DaraRequest',
|
|
75
|
+
},
|
|
76
|
+
DaraResponse: {
|
|
77
|
+
packageName: 'darabonba.response',
|
|
78
|
+
className: 'DaraResponse',
|
|
79
|
+
},
|
|
80
|
+
DaraModel: {
|
|
81
|
+
packageName: 'darabonba.model',
|
|
82
|
+
className: 'DaraModel',
|
|
83
|
+
},
|
|
84
|
+
RuntimeOptions: {
|
|
85
|
+
packageName: 'darabonba.runtime',
|
|
86
|
+
className: 'RuntimeOptions',
|
|
87
|
+
},
|
|
88
|
+
DaraException: {
|
|
89
|
+
packageName: 'darabonba.exceptions',
|
|
90
|
+
className: 'DaraException',
|
|
91
|
+
},
|
|
92
|
+
UnretryableException: {
|
|
93
|
+
packageName: 'darabonba.exceptions',
|
|
94
|
+
className: 'UnretryableException',
|
|
95
|
+
},
|
|
96
|
+
ResponseException: {
|
|
97
|
+
packageName: 'darabonba.exceptions',
|
|
98
|
+
className: 'ResponseException',
|
|
99
|
+
},
|
|
100
|
+
RetryPolicyContext: {
|
|
101
|
+
packageName: 'darabonba.policy.retry',
|
|
102
|
+
className: 'RetryPolicyContext',
|
|
103
|
+
},
|
|
104
|
+
RetryOptions: {
|
|
105
|
+
packageName: 'darabonba.policy.retry',
|
|
106
|
+
className: 'RetryOptions',
|
|
107
|
+
},
|
|
108
|
+
SSEEvent: {
|
|
109
|
+
packageName: 'darabonba.event',
|
|
110
|
+
className: 'Event',
|
|
111
|
+
aliasName: 'SSEEvent'
|
|
112
|
+
},
|
|
113
|
+
FileField: {
|
|
114
|
+
packageName: 'darabonba.form',
|
|
115
|
+
className: 'FileField',
|
|
116
|
+
},
|
|
117
|
+
ExtendsParameters: {
|
|
118
|
+
packageName: 'darabonba.runtime',
|
|
119
|
+
className: 'ExtendsParameters',
|
|
120
|
+
},
|
|
121
|
+
DaraEnv: {
|
|
122
|
+
className: 'os',
|
|
123
|
+
},
|
|
124
|
+
DaraLogger: {
|
|
125
|
+
className: 'logging',
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
function _name(str) {
|
|
130
|
+
if (str.lexeme === '__request') {
|
|
131
|
+
return REQUEST;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (str.lexeme === '__response') {
|
|
135
|
+
return RESPONSE;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (str.lexeme === 'from') {
|
|
139
|
+
return 'from_';
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (str.lexeme === 'self') {
|
|
143
|
+
return 'self_';
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return str.lexeme || str.name;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function _vid(vid) {
|
|
150
|
+
return `_${_name(vid).substr(1)}`;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function _string(str) {
|
|
154
|
+
if (str.string === '\'\'') {
|
|
155
|
+
return '\\\'\\\'';
|
|
156
|
+
}
|
|
157
|
+
return str.string.replace(/([^\\])'+|^'/g, function (str) {
|
|
158
|
+
return str.replace(/'/g, '\\\'');
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function _upperFirst(str) {
|
|
163
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
164
|
+
}
|
|
165
|
+
function _lowerFirst(str) {
|
|
166
|
+
return str[0].toLowerCase() + str.substring(1);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function _subModelName(name) {
|
|
170
|
+
return name.split('.').map((name) => _upperFirst(name)).join('');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function _avoidKeywords(str) {
|
|
174
|
+
// 区分大小写
|
|
175
|
+
if (keywords.indexOf(str) > -1) {
|
|
176
|
+
return str + '_';
|
|
177
|
+
}
|
|
178
|
+
return str;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function _camelCase(str, split = '_') {
|
|
182
|
+
// 先将字符串中的下划线拆分
|
|
183
|
+
if (str.indexOf(split) > -1) {
|
|
184
|
+
let tmp = str.split(split);
|
|
185
|
+
tmp = tmp.map((s, i) => {
|
|
186
|
+
// 如果是第一个单词则不处理,其他单词首字母大写
|
|
187
|
+
return _upperFirst(s);
|
|
188
|
+
});
|
|
189
|
+
str = tmp.join('');
|
|
190
|
+
} else {
|
|
191
|
+
// 如果没有下划线,对整个字符串首字母大写
|
|
192
|
+
str = _upperFirst(str);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return str;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function _snakeCase(str) {
|
|
199
|
+
if (!str) {
|
|
200
|
+
return '';
|
|
201
|
+
}
|
|
202
|
+
let res = '';
|
|
203
|
+
let tmp = '';
|
|
204
|
+
for (const c of str) {
|
|
205
|
+
if (/[A-Z|0-9]/.test(c)) {
|
|
206
|
+
tmp += c;
|
|
207
|
+
} else {
|
|
208
|
+
if (tmp.length > 0) {
|
|
209
|
+
res += res === '' ? tmp.toLowerCase() : '_' + tmp.toLowerCase();
|
|
210
|
+
tmp = '';
|
|
211
|
+
}
|
|
212
|
+
res += c;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (tmp.length > 0) {
|
|
216
|
+
res += '_' + tmp.toLowerCase();
|
|
217
|
+
}
|
|
218
|
+
res = res.replace(/-/g, '_');
|
|
219
|
+
if (res[0] === '_' && str[0] !== '_') {
|
|
220
|
+
res = res.substring(1);
|
|
221
|
+
}
|
|
222
|
+
return res;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function _deepClone(obj) {
|
|
226
|
+
return JSON.parse(JSON.stringify(obj));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function _isSnakeCase(str) {
|
|
230
|
+
if (/[^\da-z_]/.test(str)) {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (/\d/.test(str[0])) {
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return true;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function _isBasicType(type) {
|
|
242
|
+
return DSL.util.isBasicType(type);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function _isBinaryOp(type) {
|
|
246
|
+
const op = [
|
|
247
|
+
'or', 'eq', 'neq',
|
|
248
|
+
'gt', 'gte', 'lt',
|
|
249
|
+
'lte', 'add', 'subtract',
|
|
250
|
+
'div', 'multi', 'and'
|
|
251
|
+
];
|
|
252
|
+
return op.includes(type);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function _isBuiltinModel(name) {
|
|
256
|
+
return builtinModels.includes(name);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function _isDefault(expr) {
|
|
260
|
+
if(expr.type !== 'call' || expr.left.type !== 'method_call') {
|
|
261
|
+
return false;
|
|
262
|
+
}
|
|
263
|
+
const name = _name(expr.left.id);
|
|
264
|
+
|
|
265
|
+
if(name !== '$default') {
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return true;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function _type(name) {
|
|
273
|
+
if (name === 'string') {
|
|
274
|
+
return 'str';
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (name === 'boolean') {
|
|
278
|
+
return 'bool';
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (name === 'any') {
|
|
282
|
+
return 'Any';
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (name === 'void') {
|
|
286
|
+
return 'None';
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (name === 'integer' || name === 'number' ||
|
|
290
|
+
name === 'int8' || name === 'uint8' ||
|
|
291
|
+
name === 'int16' || name === 'uint16' ||
|
|
292
|
+
name === 'int32' || name === 'uint32' ||
|
|
293
|
+
name === 'int64' || name === 'uint64' ||
|
|
294
|
+
name === 'long' || name === 'ulong') {
|
|
295
|
+
return 'int';
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if(name === 'float' || name === 'double') {
|
|
299
|
+
return 'float';
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (name === 'readable') {
|
|
303
|
+
return 'BinaryIO';
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (name === 'writable') {
|
|
307
|
+
return 'BinaryIO';
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (name === '$Request') {
|
|
311
|
+
return `${CORE}Request`;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (name === '$Response') {
|
|
315
|
+
return `${CORE}Response`;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (name === '$Model') {
|
|
319
|
+
return `${CORE}Model`;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (name === '$Error') {
|
|
323
|
+
return `${CORE}Exception`;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
if (name === '$SSEEvent') {
|
|
327
|
+
return 'SSEEvent';
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (name === '$RetryOptions') {
|
|
331
|
+
return 'RetryOptions';
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (name === '$RuntimeOptions') {
|
|
335
|
+
return 'RuntimeOptions';
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (name === '$ResponseError') {
|
|
339
|
+
return 'ResponseError';
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
if (name === '$FileField') {
|
|
343
|
+
return 'FileField';
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (name === '$ExtendsParameters') {
|
|
347
|
+
return 'ExtendsParameters';
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if (name === '$Date') {
|
|
351
|
+
return `${CORE}Date`;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (name === '$File') {
|
|
355
|
+
return `${CORE}File`;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (name === '$URL') {
|
|
359
|
+
return `${CORE}URL`;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
if (name === '$Stream') {
|
|
363
|
+
return `${CORE}Stream`;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (name === 'object') {
|
|
367
|
+
return 'dict';
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (name === 'bytes') {
|
|
371
|
+
return 'bytes';
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
return name;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
function _adaptedQuotes(str) {
|
|
378
|
+
const line = str.split('\n');
|
|
379
|
+
let quote = '\'';
|
|
380
|
+
if (str.indexOf('\'') !== -1 && str.indexOf('"') !== -1 || line.length > 1) {
|
|
381
|
+
quote = '\'\'\'';
|
|
382
|
+
} else if (str.indexOf('\'') !== -1) {
|
|
383
|
+
quote = '"';
|
|
384
|
+
}
|
|
385
|
+
return quote;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function _getImport(type) {
|
|
389
|
+
return builtinImports[type];
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function _escape(str) {
|
|
393
|
+
return str.includes('-') ? `'${str}'` : str;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
module.exports = {
|
|
397
|
+
_name,
|
|
398
|
+
_escape,
|
|
399
|
+
_vid,
|
|
400
|
+
_string,
|
|
401
|
+
_upperFirst,
|
|
402
|
+
_lowerFirst,
|
|
403
|
+
_subModelName,
|
|
404
|
+
_avoidKeywords,
|
|
405
|
+
_camelCase,
|
|
406
|
+
_snakeCase,
|
|
407
|
+
_deepClone,
|
|
408
|
+
_isSnakeCase,
|
|
409
|
+
_isBasicType,
|
|
410
|
+
_isBinaryOp,
|
|
411
|
+
_isBuiltinModel,
|
|
412
|
+
_isDefault,
|
|
413
|
+
_type,
|
|
414
|
+
_getImport,
|
|
415
|
+
_adaptedQuotes,
|
|
416
|
+
CORE,
|
|
417
|
+
REQUEST,
|
|
418
|
+
RESPONSE,
|
|
419
|
+
EXCEPTION,
|
|
420
|
+
RESP_EXCEPTION,
|
|
421
|
+
MODEL,
|
|
422
|
+
};
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darabonba/python-generator",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "The darabonba generator for Python",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "lib/generator.js",
|
|
6
6
|
"directories": {
|
|
7
|
-
"
|
|
7
|
+
"lib": "lib"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
-
"lint": "eslint --fix
|
|
10
|
+
"lint": "eslint --fix lib/ tests/",
|
|
11
11
|
"test": "mocha -R spec -t 3000 tests/*.tests.js",
|
|
12
12
|
"test-cov": "nyc -r=lcov -r=html -r=text -r=json npm run test",
|
|
13
13
|
"ci": "npm run lint && npm run test-cov"
|
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
"author": "Alibaba Cloud OpenAPI Team",
|
|
31
31
|
"license": "Apache-2.0",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@darabonba/parser": "^1.
|
|
33
|
+
"@darabonba/annotation-parser": "^1.0.1",
|
|
34
|
+
"@darabonba/parser": "^2.1.4",
|
|
34
35
|
"enum": "^3.0.4"
|
|
35
36
|
}
|
|
36
37
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Licensed to the Apache Software Foundation (ASF) under one
|
|
4
|
+
or more contributor license agreements. See the NOTICE file
|
|
5
|
+
distributed with this work for additional information
|
|
6
|
+
regarding copyright ownership. The ASF licenses this file
|
|
7
|
+
to you under the Apache License, Version 2.0 (the
|
|
8
|
+
"License"); you may not use this file except in compliance
|
|
9
|
+
with the License. You may obtain a copy of the License at
|
|
10
|
+
|
|
11
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
|
|
13
|
+
Unless required by applicable law or agreed to in writing,
|
|
14
|
+
software distributed under the License is distributed on an
|
|
15
|
+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
16
|
+
KIND, either express or implied. See the License for the
|
|
17
|
+
specific language governing permissions and limitations
|
|
18
|
+
under the License.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
import os
|
|
22
|
+
from setuptools import setup, find_packages
|
|
23
|
+
|
|
24
|
+
"""
|
|
25
|
+
setup module for tea_python_tests.
|
|
26
|
+
|
|
27
|
+
Created on *
|
|
28
|
+
|
|
29
|
+
@author: Alibaba
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
PACKAGE = "tea_python_tests"
|
|
33
|
+
NAME = "tea_python_tests"
|
|
34
|
+
DESCRIPTION = ""
|
|
35
|
+
AUTHOR = "Alibaba"
|
|
36
|
+
AUTHOR_EMAIL = "sdk-team@alibabacloud.com"
|
|
37
|
+
URL = "https://github.com/"
|
|
38
|
+
VERSION = __import__(PACKAGE).__version__
|
|
39
|
+
REQUIRES = [
|
|
40
|
+
"alibabacloud-tea>=1.0.0",
|
|
41
|
+
"source==0.0.1",
|
|
42
|
+
"import==1.1.2",
|
|
43
|
+
"alibabacloud_tea_util==0.3.11"
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
LONG_DESCRIPTION = ''
|
|
47
|
+
if os.path.exists('./README.md'):
|
|
48
|
+
with open("README.md", encoding='utf-8') as fp:
|
|
49
|
+
LONG_DESCRIPTION = fp.read()
|
|
50
|
+
|
|
51
|
+
setup(
|
|
52
|
+
name=NAME,
|
|
53
|
+
version=VERSION,
|
|
54
|
+
description=DESCRIPTION,
|
|
55
|
+
long_description=LONG_DESCRIPTION,
|
|
56
|
+
long_description_content_type='text/markdown',
|
|
57
|
+
author=AUTHOR,
|
|
58
|
+
author_email=AUTHOR_EMAIL,
|
|
59
|
+
license="Apache License 2.0",
|
|
60
|
+
url=URL,
|
|
61
|
+
keywords=["tea","python","tests"],
|
|
62
|
+
packages=find_packages(exclude=["tests*"]),
|
|
63
|
+
include_package_data=True,
|
|
64
|
+
platforms="any",
|
|
65
|
+
install_requires=REQUIRES,
|
|
66
|
+
python_requires=">=3.6",
|
|
67
|
+
classifiers=(
|
|
68
|
+
"Development Status :: 4 - Beta",
|
|
69
|
+
"Intended Audience :: Developers",
|
|
70
|
+
"License :: OSI Approved :: Apache Software License",
|
|
71
|
+
"Programming Language :: Python",
|
|
72
|
+
"Programming Language :: Python :: 3",
|
|
73
|
+
"Programming Language :: Python :: 3.6",
|
|
74
|
+
"Programming Language :: Python :: 3.7",
|
|
75
|
+
"Programming Language :: Python :: 3.8",
|
|
76
|
+
"Programming Language :: Python :: 3.9",
|
|
77
|
+
"Topic :: Software Development"
|
|
78
|
+
)
|
|
79
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.0.0"
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# This file is auto-generated, don't edit it. Thanks.
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
from Import.client import Client as ImportClient
|
|
5
|
+
from Source.client import Client as SourceClient
|
|
6
|
+
from Alias.alias_client import AliasClient
|
|
7
|
+
from alias_source.source_client import SourceClient as AliasSourceSourceClient
|
|
8
|
+
from alias_symbol.client import Client as AliasSymbolClient
|
|
9
|
+
from alias_symbol import models as alias_symbol_models
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Client:
|
|
15
|
+
|
|
16
|
+
def __init__(self):
|
|
17
|
+
pass
|
|
18
|
+
|
|
19
|
+
@staticmethod
|
|
20
|
+
def empty_model() -> None:
|
|
21
|
+
ImportClient.test()
|
|
22
|
+
SourceClient.test()
|
|
23
|
+
AliasClient.test()
|
|
24
|
+
AliasSourceSourceClient.test()
|
|
25
|
+
AliasSymbolClient.test()
|
|
26
|
+
model = alias_symbol_models.TestModel()
|
|
27
|
+
|
|
28
|
+
@staticmethod
|
|
29
|
+
async def empty_model_async() -> None:
|
|
30
|
+
ImportClient.test()
|
|
31
|
+
await SourceClient.test_async()
|
|
32
|
+
AliasClient.test()
|
|
33
|
+
AliasSourceSourceClient.test()
|
|
34
|
+
AliasSymbolClient.test()
|
|
35
|
+
model = alias_symbol_models.TestModel()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.0.0"
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# This file is auto-generated, don't edit it. Thanks.
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
from darabonba.core import DaraCore
|
|
5
|
+
from darabonba.exceptions import UnretryableException
|
|
6
|
+
from darabonba.policy.retry import RetryPolicyContext
|
|
7
|
+
from darabonba.request import DaraRequest
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
"""
|
|
11
|
+
* @remarks
|
|
12
|
+
* top annotation
|
|
13
|
+
"""
|
|
14
|
+
class Client:
|
|
15
|
+
_a: str = None
|
|
16
|
+
def __init__(self):
|
|
17
|
+
pass
|
|
18
|
+
|
|
19
|
+
"""
|
|
20
|
+
* @remarks
|
|
21
|
+
* testAPI
|
|
22
|
+
"""
|
|
23
|
+
def test_api(self) -> None:
|
|
24
|
+
_runtime = {
|
|
25
|
+
}
|
|
26
|
+
_last_request = None
|
|
27
|
+
_last_response = None
|
|
28
|
+
_retries_attempted = 0
|
|
29
|
+
_context = RetryPolicyContext(
|
|
30
|
+
retries_attempted= _retries_attempted
|
|
31
|
+
)
|
|
32
|
+
while DaraCore.should_retry(_runtime.get('retryOptions'), _context):
|
|
33
|
+
if _retries_attempted > 0:
|
|
34
|
+
_backoff_time = DaraCore.get_backoff_time(_runtime.get('retryOptions'), _context)
|
|
35
|
+
if _backoff_time > 0:
|
|
36
|
+
DaraCore.sleep(_backoff_time)
|
|
37
|
+
_retries_attempted = _retries_attempted + 1
|
|
38
|
+
try:
|
|
39
|
+
_request = DaraRequest()
|
|
40
|
+
pass
|
|
41
|
+
_last_request = _request
|
|
42
|
+
_response = DaraCore.do_action(_request, _runtime)
|
|
43
|
+
_last_response = _response
|
|
44
|
+
return
|
|
45
|
+
except Exception as e:
|
|
46
|
+
_context = RetryPolicyContext(
|
|
47
|
+
retries_attempted= _retries_attempted,
|
|
48
|
+
http_request = _last_request,
|
|
49
|
+
http_response = _last_response,
|
|
50
|
+
exception = e
|
|
51
|
+
)
|
|
52
|
+
continue
|
|
53
|
+
raise UnretryableException(_context)
|
|
54
|
+
|
|
55
|
+
async def test_api_async(self) -> None:
|
|
56
|
+
_runtime = {
|
|
57
|
+
}
|
|
58
|
+
_last_request = None
|
|
59
|
+
_last_response = None
|
|
60
|
+
_retries_attempted = 0
|
|
61
|
+
_context = RetryPolicyContext(
|
|
62
|
+
retries_attempted= _retries_attempted
|
|
63
|
+
)
|
|
64
|
+
while DaraCore.should_retry(_runtime.get('retryOptions'), _context):
|
|
65
|
+
if _retries_attempted > 0:
|
|
66
|
+
_backoff_time = DaraCore.get_backoff_time(_runtime.get('retryOptions'), _context)
|
|
67
|
+
if _backoff_time > 0:
|
|
68
|
+
DaraCore.sleep(_backoff_time)
|
|
69
|
+
_retries_attempted = _retries_attempted + 1
|
|
70
|
+
try:
|
|
71
|
+
_request = DaraRequest()
|
|
72
|
+
pass
|
|
73
|
+
_last_request = _request
|
|
74
|
+
_response = await DaraCore.async_do_action(_request, _runtime)
|
|
75
|
+
_last_response = _response
|
|
76
|
+
return
|
|
77
|
+
except Exception as e:
|
|
78
|
+
_context = RetryPolicyContext(
|
|
79
|
+
retries_attempted= _retries_attempted,
|
|
80
|
+
http_request = _last_request,
|
|
81
|
+
http_response = _last_response,
|
|
82
|
+
exception = e
|
|
83
|
+
)
|
|
84
|
+
continue
|
|
85
|
+
raise UnretryableException(_context)
|
|
86
|
+
|
|
87
|
+
@staticmethod
|
|
88
|
+
def test_func() -> None:
|
|
89
|
+
pass
|
|
90
|
+
|
|
91
|
+
@staticmethod
|
|
92
|
+
async def test_func_async() -> None:
|
|
93
|
+
pass
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# This file is auto-generated, don't edit it. Thanks.
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
from darabonba.model import DaraModel
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
"""
|
|
8
|
+
* @remarks
|
|
9
|
+
* TestModel
|
|
10
|
+
"""
|
|
11
|
+
class Test(DaraModel):
|
|
12
|
+
def __init__(
|
|
13
|
+
self,
|
|
14
|
+
test: str = None,
|
|
15
|
+
):
|
|
16
|
+
# Alichange app id
|
|
17
|
+
self.test = test
|
|
18
|
+
|
|
19
|
+
def validate(self):
|
|
20
|
+
self.validate_required(self.test, 'test')
|
|
21
|
+
|
|
22
|
+
def to_map(self):
|
|
23
|
+
_map = super().to_map()
|
|
24
|
+
if _map is not None:
|
|
25
|
+
return _map
|
|
26
|
+
|
|
27
|
+
result = dict()
|
|
28
|
+
if self.test is not None:
|
|
29
|
+
result['test'] = self.test
|
|
30
|
+
return result
|
|
31
|
+
|
|
32
|
+
def from_map(self, m: dict = None):
|
|
33
|
+
m = m or dict()
|
|
34
|
+
if m.get('test') is not None:
|
|
35
|
+
self.test = m.get('test')
|
|
36
|
+
return self
|
|
37
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.0.0"
|