@darabonba/python-generator 1.2.14 → 1.2.16
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 +6 -0
- package/package.json +1 -1
- package/src/generator.js +2 -0
- package/src/langs/common/combinator.js +1 -0
- package/src/langs/python/combinator.js +3 -2
- package/src/langs/python2/combinator.js +1 -1
- package/tests/expected/python2/complex/tea_python_tests/client.py +8 -0
- package/tests/expected/python2/import/setup.py +1 -1
- package/tests/expected/python2/import/tea_python_tests/__pycache__/__init__.cpython-39.pyc +0 -0
- package/tests/expected/python3/complex/tea_python_tests/client.py +8 -0
- package/tests/expected/python3/import/setup.py +1 -1
- package/tests/expected/python3/import/tea_python_tests/client.py +1 -0
- package/tests/expected/python3/model/tea_python_tests/client.py +3 -0
- package/tests/expected/python3/model/tea_python_tests/models.py +1 -0
- package/tests/fixtures/complex/main.dara +8 -0
- package/tests/python3.tests.js +14 -2
package/ChangeLog.md
CHANGED
package/package.json
CHANGED
package/src/generator.js
CHANGED
|
@@ -15,12 +15,14 @@ class Generator {
|
|
|
15
15
|
}
|
|
16
16
|
this.lang = lang;
|
|
17
17
|
this.typedef = meta[lang] && meta[lang].typedef ? meta[lang].typedef : {};
|
|
18
|
+
this.additionalPackage = meta[lang] && meta[lang].additionalPackage ? meta[lang].additionalPackage : [];
|
|
18
19
|
this.initConfig(meta);
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
visit(ast) {
|
|
22
23
|
this.imports = this.resolveImports(ast);
|
|
23
24
|
this.imports.typedef = this.typedef;
|
|
25
|
+
this.imports.additionalPackage = this.additionalPackage;
|
|
24
26
|
Object.keys(this.typedef).forEach((def) => {
|
|
25
27
|
if (this.typedef[def].package && !this.imports.requirePackage.includes(this.typedef[def].package)) {
|
|
26
28
|
this.imports.requirePackage.push(this.typedef[def].package);
|
|
@@ -1234,7 +1234,8 @@ class Combinator extends CombinatorBase {
|
|
|
1234
1234
|
let list = this.includeList.filter(node => node.from && !node.alias);
|
|
1235
1235
|
|
|
1236
1236
|
let from = {};
|
|
1237
|
-
let fromList =
|
|
1237
|
+
let fromList = [];
|
|
1238
|
+
fromList = fromList.concat(this.additionalPackage);
|
|
1238
1239
|
|
|
1239
1240
|
list.forEach(item => {
|
|
1240
1241
|
if (!from[item.from]) {
|
|
@@ -1381,7 +1382,7 @@ class Combinator extends CombinatorBase {
|
|
|
1381
1382
|
const quote = this._adaptedQuotes(pathName, emitter);
|
|
1382
1383
|
pre += `[${quote}${pathName}${quote}]`;
|
|
1383
1384
|
} else if (path.type === 'list') {
|
|
1384
|
-
pre += `[${pathName}]`;
|
|
1385
|
+
pre += path.isVar ? `[${_name(pathName)}]` : `[${pathName}]`;
|
|
1385
1386
|
} else {
|
|
1386
1387
|
debug.stack(gram);
|
|
1387
1388
|
}
|
|
@@ -1233,7 +1233,7 @@ class Combinator extends CombinatorBase {
|
|
|
1233
1233
|
const quote = this._adaptedQuotes(pathName, emitter);
|
|
1234
1234
|
pre += `[${quote}${pathName}${quote}]`;
|
|
1235
1235
|
} else if (path.type === 'list') {
|
|
1236
|
-
pre += `[${pathName}]`;
|
|
1236
|
+
pre += path.isVar ? `[${_name(pathName)}]` : `[${pathName}]`;
|
|
1237
1237
|
} else {
|
|
1238
1238
|
debug.stack(gram);
|
|
1239
1239
|
}
|
|
@@ -220,6 +220,8 @@ class Client(SourceClient):
|
|
|
220
220
|
def array_access_3(request, index):
|
|
221
221
|
config_val = request.configs.value[0]
|
|
222
222
|
val = request.configs.value[index]
|
|
223
|
+
i_0 = 0
|
|
224
|
+
val = request.configs.value[i_0]
|
|
223
225
|
return config_val
|
|
224
226
|
|
|
225
227
|
@staticmethod
|
|
@@ -247,6 +249,8 @@ class Client(SourceClient):
|
|
|
247
249
|
@staticmethod
|
|
248
250
|
def array_assign_3(request, config):
|
|
249
251
|
request.configs.value[0] = config
|
|
252
|
+
i_0 = 0
|
|
253
|
+
request.configs.value[i_0] = config
|
|
250
254
|
|
|
251
255
|
@staticmethod
|
|
252
256
|
def map_access(request):
|
|
@@ -257,6 +261,8 @@ class Client(SourceClient):
|
|
|
257
261
|
def map_access_2(request, key):
|
|
258
262
|
config_info = request.configs.extra.get('name')
|
|
259
263
|
config_value = request.configs.extra.get(key)
|
|
264
|
+
i_0 = key
|
|
265
|
+
config_value = request.configs.extra.get(i_0)
|
|
260
266
|
return config_info
|
|
261
267
|
|
|
262
268
|
@staticmethod
|
|
@@ -271,6 +277,8 @@ class Client(SourceClient):
|
|
|
271
277
|
@staticmethod
|
|
272
278
|
def map_assign(request, name):
|
|
273
279
|
request.configs.extra['name'] = name
|
|
280
|
+
i_0 = 'name'
|
|
281
|
+
request.configs.extra[i_0] = name
|
|
274
282
|
|
|
275
283
|
@staticmethod
|
|
276
284
|
def str_fmt():
|
|
Binary file
|
|
@@ -416,6 +416,8 @@ class Client(SourceClient):
|
|
|
416
416
|
) -> str:
|
|
417
417
|
config_val = request.configs.value[0]
|
|
418
418
|
val = request.configs.value[index]
|
|
419
|
+
i_0 = 0
|
|
420
|
+
val = request.configs.value[i_0]
|
|
419
421
|
return config_val
|
|
420
422
|
|
|
421
423
|
@staticmethod
|
|
@@ -450,6 +452,8 @@ class Client(SourceClient):
|
|
|
450
452
|
config: str,
|
|
451
453
|
) -> None:
|
|
452
454
|
request.configs.value[0] = config
|
|
455
|
+
i_0 = 0
|
|
456
|
+
request.configs.value[i_0] = config
|
|
453
457
|
|
|
454
458
|
@staticmethod
|
|
455
459
|
def map_access(
|
|
@@ -465,6 +469,8 @@ class Client(SourceClient):
|
|
|
465
469
|
) -> str:
|
|
466
470
|
config_info = request.configs.extra.get('name')
|
|
467
471
|
config_value = request.configs.extra.get(key)
|
|
472
|
+
i_0 = key
|
|
473
|
+
config_value = request.configs.extra.get(i_0)
|
|
468
474
|
return config_info
|
|
469
475
|
|
|
470
476
|
@staticmethod
|
|
@@ -482,6 +488,8 @@ class Client(SourceClient):
|
|
|
482
488
|
name: str,
|
|
483
489
|
) -> None:
|
|
484
490
|
request.configs.extra['name'] = name
|
|
491
|
+
i_0 = 'name'
|
|
492
|
+
request.configs.extra[i_0] = name
|
|
485
493
|
|
|
486
494
|
@staticmethod
|
|
487
495
|
def str_fmt() -> None:
|
|
@@ -191,6 +191,8 @@ static function arrayAccess2(): string {
|
|
|
191
191
|
static function arrayAccess3(request: ComplexRequest, index: number): string {
|
|
192
192
|
var configVal = request.configs.value[0];
|
|
193
193
|
var val = request.configs.value[index];
|
|
194
|
+
var i0 = 0;
|
|
195
|
+
val = request.configs.value[i0];
|
|
194
196
|
return configVal;
|
|
195
197
|
}
|
|
196
198
|
|
|
@@ -210,6 +212,8 @@ static function arrayAssign2(config: string): [ string ] {
|
|
|
210
212
|
|
|
211
213
|
static function arrayAssign3(request: ComplexRequest, config: string): void {
|
|
212
214
|
request.configs.value[0] = config;
|
|
215
|
+
var i0 = 0;
|
|
216
|
+
request.configs.value[i0] = config;
|
|
213
217
|
}
|
|
214
218
|
|
|
215
219
|
static function mapAccess(request: ComplexRequest): string {
|
|
@@ -220,6 +224,8 @@ static function mapAccess(request: ComplexRequest): string {
|
|
|
220
224
|
static function mapAccess2(request: Source.Request, key: string): string {
|
|
221
225
|
var configInfo = request.configs.extra['name'];
|
|
222
226
|
var configValue = request.configs.extra[key];
|
|
227
|
+
var i0 = key;
|
|
228
|
+
configValue = request.configs.extra[i0];
|
|
223
229
|
return configInfo;
|
|
224
230
|
}
|
|
225
231
|
|
|
@@ -234,6 +240,8 @@ static function mapAccess3(): string {
|
|
|
234
240
|
|
|
235
241
|
static function mapAssign(request: ComplexRequest, name: string): void {
|
|
236
242
|
request.configs.extra['name'] = name;
|
|
243
|
+
var i0 = 'name';
|
|
244
|
+
request.configs.extra[i0] = name;
|
|
237
245
|
}
|
|
238
246
|
|
|
239
247
|
static function strFmt(): void {
|
package/tests/python3.tests.js
CHANGED
|
@@ -170,7 +170,13 @@ describe('Python Generator', function () {
|
|
|
170
170
|
github: 'https://github.com/',
|
|
171
171
|
author: 'Alibaba',
|
|
172
172
|
email: 'sdk-team@alibabacloud.com'
|
|
173
|
-
}
|
|
173
|
+
},
|
|
174
|
+
additionalPackage: [
|
|
175
|
+
{
|
|
176
|
+
from: '__future__',
|
|
177
|
+
import: 'annotations'
|
|
178
|
+
}
|
|
179
|
+
]
|
|
174
180
|
}
|
|
175
181
|
});
|
|
176
182
|
});
|
|
@@ -195,7 +201,13 @@ describe('Python Generator', function () {
|
|
|
195
201
|
{
|
|
196
202
|
python: {
|
|
197
203
|
package: 'tea_python_tests',
|
|
198
|
-
clientName: 'client'
|
|
204
|
+
clientName: 'client',
|
|
205
|
+
additionalPackage: [
|
|
206
|
+
{
|
|
207
|
+
from: '__future__',
|
|
208
|
+
import: 'annotations'
|
|
209
|
+
}
|
|
210
|
+
]
|
|
199
211
|
}
|
|
200
212
|
});
|
|
201
213
|
});
|