@darabonba/python-generator 1.2.16 → 1.2.18
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/.github/dependabot.yml +11 -0
- package/.github/workflows/ci.yml +3 -3
- package/ChangeLog.md +6 -0
- package/README-CN.md +2 -4
- package/README.md +2 -4
- package/package.json +7 -8
- package/src/langs/common/config.js +6 -1
- package/src/langs/python/combinator.js +69 -62
- package/src/langs/python/config.js +44 -38
- package/src/langs/python2/combinator.js +62 -55
- package/src/langs/python2/config.js +43 -34
- package/src/lib/helper.js +29 -2
- package/tests/expected/python2/complex/tea_python_tests/models.py +75 -1
- package/tests/expected/python2/import/setup.py +1 -1
- package/tests/expected/python3/complex/tea_python_tests/models.py +82 -1
- package/tests/expected/python3/import/setup.py +1 -1
- package/tests/fixtures/complex/main.dara +9 -1
- package/tests/lib.tests.js +18 -2
- package/tests/python2.tests.js +4 -2
- package/tests/python3.tests.js +4 -2
- package/tests/resolver.tests.js +3 -3
- package/tests/expected/python2/import/tea_python_tests/__pycache__/__init__.cpython-39.pyc +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
# This file is auto-generated, don't edit it. Thanks.
|
|
3
3
|
from Tea.model import TeaModel
|
|
4
|
-
from typing import List, Dict, BinaryIO
|
|
4
|
+
from typing import List, Dict, Any, BinaryIO
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
class ComplexRequestHeader(TeaModel):
|
|
@@ -134,6 +134,33 @@ class ComplexRequestComplexList(TeaModel):
|
|
|
134
134
|
return self
|
|
135
135
|
|
|
136
136
|
|
|
137
|
+
class ComplexRequestComplexList2(TeaModel):
|
|
138
|
+
def __init__(
|
|
139
|
+
self,
|
|
140
|
+
any: Any = None,
|
|
141
|
+
):
|
|
142
|
+
self.any = any
|
|
143
|
+
|
|
144
|
+
def validate(self):
|
|
145
|
+
pass
|
|
146
|
+
|
|
147
|
+
def to_map(self):
|
|
148
|
+
_map = super().to_map()
|
|
149
|
+
if _map is not None:
|
|
150
|
+
return _map
|
|
151
|
+
|
|
152
|
+
result = dict()
|
|
153
|
+
if self.any is not None:
|
|
154
|
+
result['Name'] = self.any
|
|
155
|
+
return result
|
|
156
|
+
|
|
157
|
+
def from_map(self, m: dict = None):
|
|
158
|
+
m = m or dict()
|
|
159
|
+
if m.get('Name') is not None:
|
|
160
|
+
self.any = m.get('Name')
|
|
161
|
+
return self
|
|
162
|
+
|
|
163
|
+
|
|
137
164
|
class ComplexRequest(TeaModel):
|
|
138
165
|
def __init__(
|
|
139
166
|
self,
|
|
@@ -146,7 +173,11 @@ class ComplexRequest(TeaModel):
|
|
|
146
173
|
part: List[ComplexRequestPart] = None,
|
|
147
174
|
complex_list: List[List[List[ComplexRequestComplexList]]] = None,
|
|
148
175
|
complex_list_1: List[List[Dict[str, str]]] = None,
|
|
176
|
+
complex_list_2: List[List[List[ComplexRequestComplexList2]]] = None,
|
|
149
177
|
from_: str = None,
|
|
178
|
+
self_: str = None,
|
|
179
|
+
print: str = None,
|
|
180
|
+
exec: str = None,
|
|
150
181
|
):
|
|
151
182
|
self.access_key = access_key
|
|
152
183
|
# Body
|
|
@@ -161,8 +192,15 @@ class ComplexRequest(TeaModel):
|
|
|
161
192
|
self.part = part
|
|
162
193
|
self.complex_list = complex_list
|
|
163
194
|
self.complex_list_1 = complex_list_1
|
|
195
|
+
self.complex_list_2 = complex_list_2
|
|
164
196
|
# test keywords
|
|
165
197
|
self.from_ = from_
|
|
198
|
+
# test keywords
|
|
199
|
+
self.self_ = self_
|
|
200
|
+
# test keywords
|
|
201
|
+
self.print = print
|
|
202
|
+
# test keywords
|
|
203
|
+
self.exec = exec
|
|
166
204
|
|
|
167
205
|
def validate(self):
|
|
168
206
|
self.validate_required(self.access_key, 'access_key')
|
|
@@ -187,7 +225,17 @@ class ComplexRequest(TeaModel):
|
|
|
187
225
|
if k2:
|
|
188
226
|
k2.validate()
|
|
189
227
|
self.validate_required(self.complex_list_1, 'complex_list_1')
|
|
228
|
+
self.validate_required(self.complex_list_2, 'complex_list_2')
|
|
229
|
+
if self.complex_list_2:
|
|
230
|
+
for k in self.complex_list_2:
|
|
231
|
+
for k1 in k:
|
|
232
|
+
for k2 in k1:
|
|
233
|
+
if k2:
|
|
234
|
+
k2.validate()
|
|
190
235
|
self.validate_required(self.from_, 'from_')
|
|
236
|
+
self.validate_required(self.self_, 'self_')
|
|
237
|
+
self.validate_required(self.print, 'print')
|
|
238
|
+
self.validate_required(self.exec, 'exec')
|
|
191
239
|
|
|
192
240
|
def to_map(self):
|
|
193
241
|
_map = super().to_map()
|
|
@@ -223,8 +271,24 @@ class ComplexRequest(TeaModel):
|
|
|
223
271
|
result['complexList'].append(l1)
|
|
224
272
|
if self.complex_list_1 is not None:
|
|
225
273
|
result['complexList1'] = self.complex_list_1
|
|
274
|
+
result['ComplexList2'] = []
|
|
275
|
+
if self.complex_list_2 is not None:
|
|
276
|
+
for k in self.complex_list_2:
|
|
277
|
+
l1 = []
|
|
278
|
+
for k1 in k:
|
|
279
|
+
l2 = []
|
|
280
|
+
for k2 in k1:
|
|
281
|
+
l2.append(k2.to_map() if k2 else None)
|
|
282
|
+
l1.append(l2)
|
|
283
|
+
result['ComplexList2'].append(l1)
|
|
226
284
|
if self.from_ is not None:
|
|
227
285
|
result['from'] = self.from_
|
|
286
|
+
if self.self_ is not None:
|
|
287
|
+
result['self'] = self.self_
|
|
288
|
+
if self.print is not None:
|
|
289
|
+
result['print'] = self.print
|
|
290
|
+
if self.exec is not None:
|
|
291
|
+
result['exec'] = self.exec
|
|
228
292
|
return result
|
|
229
293
|
|
|
230
294
|
def from_map(self, m: dict = None):
|
|
@@ -261,8 +325,25 @@ class ComplexRequest(TeaModel):
|
|
|
261
325
|
self.complex_list.append(l1)
|
|
262
326
|
if m.get('complexList1') is not None:
|
|
263
327
|
self.complex_list_1 = m.get('complexList1')
|
|
328
|
+
self.complex_list_2 = []
|
|
329
|
+
if m.get('ComplexList2') is not None:
|
|
330
|
+
for k in m.get('ComplexList2'):
|
|
331
|
+
l1 = []
|
|
332
|
+
for k1 in k:
|
|
333
|
+
l2 = []
|
|
334
|
+
for k2 in k1:
|
|
335
|
+
temp_model = ComplexRequestComplexList2()
|
|
336
|
+
l2.append(temp_model.from_map(k2))
|
|
337
|
+
l1.append(l2)
|
|
338
|
+
self.complex_list_2.append(l1)
|
|
264
339
|
if m.get('from') is not None:
|
|
265
340
|
self.from_ = m.get('from')
|
|
341
|
+
if m.get('self') is not None:
|
|
342
|
+
self.self_ = m.get('self')
|
|
343
|
+
if m.get('print') is not None:
|
|
344
|
+
self.print = m.get('print')
|
|
345
|
+
if m.get('exec') is not None:
|
|
346
|
+
self.exec = m.get('exec')
|
|
266
347
|
return self
|
|
267
348
|
|
|
268
349
|
|
|
@@ -36,7 +36,15 @@ model ComplexRequest = {
|
|
|
36
36
|
}
|
|
37
37
|
]]](name='complexList'),
|
|
38
38
|
complexList1: [[map[string]string]],
|
|
39
|
-
|
|
39
|
+
complexList2: [[[
|
|
40
|
+
{
|
|
41
|
+
any?: any(name='Name'),
|
|
42
|
+
}
|
|
43
|
+
]]](name='ComplexList2'),
|
|
44
|
+
from: string(name='from', description='test keywords'),
|
|
45
|
+
self: string(name='self', description='test keywords'),
|
|
46
|
+
print: string(name='print', description='test keywords'),
|
|
47
|
+
exec: string(name='exec', description='test keywords'),
|
|
40
48
|
}
|
|
41
49
|
|
|
42
50
|
async function hello(request: object, strs: [ string ]): [ string ] {
|
package/tests/lib.tests.js
CHANGED
|
@@ -14,6 +14,9 @@ const {
|
|
|
14
14
|
_upperFirst,
|
|
15
15
|
_config,
|
|
16
16
|
_avoidKeywords,
|
|
17
|
+
_avoidFuncKeywords,
|
|
18
|
+
_avoidClassKeywords,
|
|
19
|
+
_avoidVarKeywords,
|
|
17
20
|
_modify,
|
|
18
21
|
_symbol,
|
|
19
22
|
_toSnakeCase,
|
|
@@ -193,8 +196,21 @@ describe('helper tests', function () {
|
|
|
193
196
|
});
|
|
194
197
|
|
|
195
198
|
it('_avoidKeywords should be ok', function () {
|
|
196
|
-
_config({
|
|
199
|
+
_config({
|
|
200
|
+
keywords: {
|
|
201
|
+
general: 'key',
|
|
202
|
+
function: ['function'],
|
|
203
|
+
class: ['class'],
|
|
204
|
+
param_variables: ['var']
|
|
205
|
+
}
|
|
206
|
+
});
|
|
197
207
|
expect(_avoidKeywords('key')).to.be.eql('key_');
|
|
208
|
+
expect(_avoidFuncKeywords('key')).to.be.eql('key_');
|
|
209
|
+
expect(_avoidFuncKeywords('function')).to.be.eql('function_');
|
|
210
|
+
expect(_avoidClassKeywords('key')).to.be.eql('key_');
|
|
211
|
+
expect(_avoidClassKeywords('class')).to.be.eql('class_');
|
|
212
|
+
expect(_avoidVarKeywords('key')).to.be.eql('key_');
|
|
213
|
+
expect(_avoidVarKeywords('var')).to.be.eql('var_');
|
|
198
214
|
});
|
|
199
215
|
|
|
200
216
|
it('_modify should be ok', function () {
|
|
@@ -220,7 +236,7 @@ describe('helper tests', function () {
|
|
|
220
236
|
expect(_symbol('ASSIGN')).to.be.eql('=');
|
|
221
237
|
});
|
|
222
238
|
|
|
223
|
-
it('_isSnakeCase should be ok', function() {
|
|
239
|
+
it('_isSnakeCase should be ok', function () {
|
|
224
240
|
expect(_isSnakeCase('tea_rpc')).to.be.eql(true);
|
|
225
241
|
expect(_isSnakeCase('tea')).to.be.eql(true);
|
|
226
242
|
expect(_isSnakeCase('tearpc')).to.be.eql(true);
|
package/tests/python2.tests.js
CHANGED
|
@@ -157,8 +157,7 @@ describe('Python Generator', function () {
|
|
|
157
157
|
|
|
158
158
|
it('import should ok', function () {
|
|
159
159
|
check('import', [
|
|
160
|
-
'tea_python_tests/client.py'
|
|
161
|
-
'setup.py'
|
|
160
|
+
'tea_python_tests/client.py'
|
|
162
161
|
],
|
|
163
162
|
{
|
|
164
163
|
python2: {
|
|
@@ -173,6 +172,9 @@ describe('Python Generator', function () {
|
|
|
173
172
|
}
|
|
174
173
|
}
|
|
175
174
|
});
|
|
175
|
+
const expected = fs.readFileSync(path.join(expectedDir, 'import', 'setup.py'), 'utf8');
|
|
176
|
+
const output = fs.readFileSync(path.join(outputDir, 'import', 'setup.py'), 'utf8');
|
|
177
|
+
assert.deepStrictEqual(output.replace(new RegExp('\\d{2}\\/\\d{2}\\/\\d{4}'), '*'), expected);
|
|
176
178
|
});
|
|
177
179
|
|
|
178
180
|
it('map should ok', function () {
|
package/tests/python3.tests.js
CHANGED
|
@@ -157,8 +157,7 @@ describe('Python Generator', function () {
|
|
|
157
157
|
|
|
158
158
|
it('import should ok', function () {
|
|
159
159
|
check('import', [
|
|
160
|
-
'tea_python_tests/client.py'
|
|
161
|
-
'setup.py'
|
|
160
|
+
'tea_python_tests/client.py'
|
|
162
161
|
],
|
|
163
162
|
{
|
|
164
163
|
python: {
|
|
@@ -179,6 +178,9 @@ describe('Python Generator', function () {
|
|
|
179
178
|
]
|
|
180
179
|
}
|
|
181
180
|
});
|
|
181
|
+
const expected = fs.readFileSync(path.join(expectedDir, 'import', 'setup.py'), 'utf8');
|
|
182
|
+
const output = fs.readFileSync(path.join(outputDir, 'import', 'setup.py'), 'utf8');
|
|
183
|
+
assert.deepStrictEqual(output.replace(new RegExp('\\d{2}\\/\\d{2}\\/\\d{4}'), '*'), expected);
|
|
182
184
|
});
|
|
183
185
|
|
|
184
186
|
it('map should ok', function () {
|
package/tests/resolver.tests.js
CHANGED
|
@@ -28,8 +28,8 @@ describe('client resolver should be ok', function () {
|
|
|
28
28
|
it('resolve should be ok', function () {
|
|
29
29
|
const combinator = new Combinator(Object.assign(_deepClone(config), {
|
|
30
30
|
package: 'test', model: { dir: 'Models' }
|
|
31
|
-
}), {
|
|
32
|
-
const code = new ClientResolver({moduleBody: { nodes: [] }}, combinator, {});
|
|
31
|
+
}), {});
|
|
32
|
+
const code = new ClientResolver({ moduleBody: { nodes: [] } }, combinator, {});
|
|
33
33
|
mm(code, 'initAnnotation', function () { return; });
|
|
34
34
|
mm(code, 'resolveProps', function () { return; });
|
|
35
35
|
mm(code.combinator, 'addInclude', function (className) { return className; });
|
|
@@ -83,7 +83,7 @@ describe('client resolver should be ok', function () {
|
|
|
83
83
|
}), {});
|
|
84
84
|
const code = new ClientResolver({}, combinator, {});
|
|
85
85
|
const funcItem = new FuncItem();
|
|
86
|
-
|
|
86
|
+
|
|
87
87
|
mm(code.combinator, 'addInclude', function (className) {
|
|
88
88
|
return className;
|
|
89
89
|
});
|