@darabonba/python-generator 1.2.15 → 1.2.17
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/generator.js +2 -0
- package/src/langs/common/combinator.js +1 -0
- package/src/langs/common/config.js +6 -1
- package/src/langs/python/combinator.js +41 -33
- package/src/langs/python/config.js +44 -38
- package/src/langs/python2/combinator.js +32 -25
- 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/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 +9 -1
- package/tests/lib.tests.js +18 -2
- package/tests/python2.tests.js +4 -2
- package/tests/python3.tests.js +18 -4
- package/tests/resolver.tests.js +3 -3
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# To get started with Dependabot version updates, you'll need to specify which
|
|
2
|
+
# package ecosystems to update and where the package manifests are located.
|
|
3
|
+
# Please see the documentation for all configuration options:
|
|
4
|
+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
|
5
|
+
|
|
6
|
+
version: 2
|
|
7
|
+
updates:
|
|
8
|
+
- package-ecosystem: "npm" # See documentation for possible values
|
|
9
|
+
directory: "/" # Location of package manifests
|
|
10
|
+
schedule:
|
|
11
|
+
interval: "weekly"
|
package/.github/workflows/ci.yml
CHANGED
|
@@ -16,8 +16,7 @@ jobs:
|
|
|
16
16
|
|
|
17
17
|
strategy:
|
|
18
18
|
matrix:
|
|
19
|
-
node-version: [12.x, 14.x, 16.x]
|
|
20
|
-
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
|
19
|
+
node-version: [12.x, 14.x, 16.x, 18.x, 20.x]
|
|
21
20
|
|
|
22
21
|
steps:
|
|
23
22
|
- uses: actions/checkout@v2
|
|
@@ -27,4 +26,5 @@ jobs:
|
|
|
27
26
|
node-version: ${{ matrix.node-version }}
|
|
28
27
|
- run: npm install
|
|
29
28
|
- run: npm run ci
|
|
30
|
-
-
|
|
29
|
+
- name: Upload coverage to Codecov
|
|
30
|
+
uses: codecov/codecov-action@v3
|
package/ChangeLog.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# ChangeLog
|
|
2
2
|
|
|
3
|
+
## 1.2.17 - 2023-12-27
|
|
4
|
+
* Fix: correct model name when first letter is capitalized && and some keywords
|
|
5
|
+
|
|
6
|
+
## 1.2.16 - 2023-09-13
|
|
7
|
+
* Feat: support importing additional package
|
|
8
|
+
|
|
3
9
|
## 1.2.15 - 2022-12-26
|
|
4
10
|
* Fix: array assign and access with variables name
|
|
5
11
|
|
package/README-CN.md
CHANGED
|
@@ -2,17 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
# Darabonba Python 生成器
|
|
4
4
|
|
|
5
|
-
[](https://github.com/aliyun/darabonba-python-generator/actions/workflows/ci.yml)
|
|
6
6
|
[![codecov][cov-image]][cov-url]
|
|
7
|
-
[![
|
|
7
|
+
[![NPM version][npm-image]][npm-url]
|
|
8
8
|
[![npm download][download-image]][download-url]
|
|
9
9
|
|
|
10
10
|
[npm-image]: https://img.shields.io/npm/v/@darabonba/python-generator.svg?style=flat-square
|
|
11
11
|
[npm-url]: https://npmjs.org/package/@darabonba/python-generator
|
|
12
12
|
[cov-image]: https://codecov.io/gh/aliyun/darabonba-python-generator/branch/master/graph/badge.svg
|
|
13
13
|
[cov-url]: https://codecov.io/gh/aliyun/darabonba-python-generator
|
|
14
|
-
[david-image]: https://img.shields.io/david/aliyun/darabonba-python-generator.svg?style=flat-square
|
|
15
|
-
[david-url]: https://david-dm.org/aliyun/darabonba-python-generator
|
|
16
14
|
[download-image]: https://img.shields.io/npm/dm/@darabonba/python-generator.svg?style=flat-square
|
|
17
15
|
[download-url]: https://npmjs.org/package/@darabonba/python-generator
|
|
18
16
|
|
package/README.md
CHANGED
|
@@ -2,17 +2,15 @@ English | [简体中文](/README-CN.md)
|
|
|
2
2
|
|
|
3
3
|
# Darabonba Python Generator
|
|
4
4
|
|
|
5
|
-
[](https://github.com/aliyun/darabonba-python-generator/actions/workflows/ci.yml)
|
|
6
6
|
[![codecov][cov-image]][cov-url]
|
|
7
|
-
[![
|
|
7
|
+
[![NPM version][npm-image]][npm-url]
|
|
8
8
|
[![npm download][download-image]][download-url]
|
|
9
9
|
|
|
10
10
|
[npm-image]: https://img.shields.io/npm/v/@darabonba/python-generator.svg?style=flat-square
|
|
11
11
|
[npm-url]: https://npmjs.org/package/@darabonba/python-generator
|
|
12
12
|
[cov-image]: https://codecov.io/gh/aliyun/darabonba-python-generator/branch/master/graph/badge.svg
|
|
13
13
|
[cov-url]: https://codecov.io/gh/aliyun/darabonba-python-generator
|
|
14
|
-
[david-image]: https://img.shields.io/david/aliyun/darabonba-python-generator.svg?style=flat-square
|
|
15
|
-
[david-url]: https://david-dm.org/aliyun/darabonba-python-generator
|
|
16
14
|
[download-image]: https://img.shields.io/npm/dm/@darabonba/python-generator.svg?style=flat-square
|
|
17
15
|
[download-url]: https://npmjs.org/package/@darabonba/python-generator
|
|
18
16
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darabonba/python-generator",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.17",
|
|
4
4
|
"description": "The darabonba generator for Python",
|
|
5
5
|
"main": "src/generator.js",
|
|
6
6
|
"directories": {
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"lint": "eslint --fix src/",
|
|
11
|
-
"test": "mocha
|
|
12
|
-
"test-cov": "nyc -r=lcov -r=html -r=text -r=json
|
|
13
|
-
"ci": "npm run lint && npm run test-cov
|
|
11
|
+
"test": "mocha -R spec -t 3000 tests/*.tests.js",
|
|
12
|
+
"test-cov": "nyc -r=lcov -r=html -r=text -r=json npm run test",
|
|
13
|
+
"ci": "npm run lint && npm run test-cov"
|
|
14
14
|
},
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
@@ -18,12 +18,11 @@
|
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"chai": "^4.2.0",
|
|
21
|
-
"
|
|
22
|
-
"eslint": "^7.14.0",
|
|
21
|
+
"eslint": "^8.55.0",
|
|
23
22
|
"expect.js": "^0.3.1",
|
|
24
|
-
"has-flag": "^
|
|
23
|
+
"has-flag": "^5.0.1",
|
|
25
24
|
"mm": "^3.2.0",
|
|
26
|
-
"mocha": "^
|
|
25
|
+
"mocha": "^10.2.0",
|
|
27
26
|
"mocha-sinon": "^2.1.2",
|
|
28
27
|
"nyc": "^15.1.0",
|
|
29
28
|
"sinon": "^9.2.1"
|
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);
|
|
@@ -31,7 +31,9 @@ const {
|
|
|
31
31
|
_toSnakeCase,
|
|
32
32
|
_toCamelCase,
|
|
33
33
|
_avoidKeywords,
|
|
34
|
-
|
|
34
|
+
_avoidFuncKeywords,
|
|
35
|
+
_avoidClassKeywords,
|
|
36
|
+
_avoidVarKeywords,
|
|
35
37
|
_exception,
|
|
36
38
|
_symbol,
|
|
37
39
|
_deepClone,
|
|
@@ -46,6 +48,14 @@ function _name(name) {
|
|
|
46
48
|
return _avoidKeywords(_toSnakeCase(name));
|
|
47
49
|
}
|
|
48
50
|
|
|
51
|
+
function _varName(name){
|
|
52
|
+
return _avoidVarKeywords(_toSnakeCase(name));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function _funcName(name){
|
|
56
|
+
return _avoidFuncKeywords(_toSnakeCase(name));
|
|
57
|
+
}
|
|
58
|
+
|
|
49
59
|
function _type(type) {
|
|
50
60
|
const config = _config();
|
|
51
61
|
let t = type instanceof Object ? type.lexeme : type;
|
|
@@ -446,10 +456,7 @@ class Combinator extends CombinatorBase {
|
|
|
446
456
|
} else {
|
|
447
457
|
className = name.split('.').map(item => _upperFirst(item)).join('');
|
|
448
458
|
}
|
|
449
|
-
|
|
450
|
-
className = _avoidKeywords(className);
|
|
451
|
-
}
|
|
452
|
-
return _toCamelCase(className);
|
|
459
|
+
return _toCamelCase(_avoidClassKeywords(className));
|
|
453
460
|
}
|
|
454
461
|
|
|
455
462
|
emitClass(emitter, object) {
|
|
@@ -502,7 +509,7 @@ class Combinator extends CombinatorBase {
|
|
|
502
509
|
} else if (p instanceof PropItem) {
|
|
503
510
|
const type = this.getTypeHints(p.type);
|
|
504
511
|
if (type) {
|
|
505
|
-
emitter.emitln(`${
|
|
512
|
+
emitter.emitln(`${_varName(p.name)}: ${type} = None`, this.level);
|
|
506
513
|
}
|
|
507
514
|
}
|
|
508
515
|
});
|
|
@@ -670,7 +677,7 @@ class Combinator extends CombinatorBase {
|
|
|
670
677
|
type: type.itemType,
|
|
671
678
|
parentType: type.lexeme
|
|
672
679
|
};
|
|
673
|
-
this.emitComplexToMap(emitter, propInfo, `result['${
|
|
680
|
+
this.emitComplexToMap(emitter, propInfo, `result['${fieldName}']`, depth + 1);
|
|
674
681
|
} else {
|
|
675
682
|
if (type.itemType.objectType === 'model') {
|
|
676
683
|
emitter.emitln(`result['${fieldName}'].append(k.to_map() if k else None)`, this.level);
|
|
@@ -714,7 +721,7 @@ class Combinator extends CombinatorBase {
|
|
|
714
721
|
type: type.valType,
|
|
715
722
|
parentType: type.lexeme
|
|
716
723
|
};
|
|
717
|
-
this.emitComplexToMap(emitter, propInfo, `result['${
|
|
724
|
+
this.emitComplexToMap(emitter, propInfo, `result['${fieldName}']`, depth + 1);
|
|
718
725
|
} else {
|
|
719
726
|
if (type.valType.objectType === 'model') {
|
|
720
727
|
emitter.emitln(`result['${fieldName}'][k] = v.to_map()`, this.level);
|
|
@@ -956,9 +963,9 @@ class Combinator extends CombinatorBase {
|
|
|
956
963
|
construct.params.forEach(param => {
|
|
957
964
|
const typeHints = this.getTypeHints(param.type);
|
|
958
965
|
if (param.value !== null && param.value !== 'null') {
|
|
959
|
-
constructParams.push(`${
|
|
966
|
+
constructParams.push(`${_varName(param.key)}: ${typeHints} = ${param.value},`);
|
|
960
967
|
} else {
|
|
961
|
-
constructParams.push(`${
|
|
968
|
+
constructParams.push(`${_varName(param.key)}: ${typeHints},`);
|
|
962
969
|
}
|
|
963
970
|
});
|
|
964
971
|
emitter.emitln('def __init__(', this.level);
|
|
@@ -978,9 +985,9 @@ class Combinator extends CombinatorBase {
|
|
|
978
985
|
if (prop instanceof PropItem) {
|
|
979
986
|
const typeHints = this.getTypeHints(prop.type);
|
|
980
987
|
if (typeHints === this.className) {
|
|
981
|
-
emitter.emitln(`${
|
|
988
|
+
emitter.emitln(`${_varName(prop.name)}: '${typeHints}' = None,`, this.level);
|
|
982
989
|
} else {
|
|
983
|
-
emitter.emitln(`${
|
|
990
|
+
emitter.emitln(`${_varName(prop.name)}: ${typeHints} = None,`, this.level);
|
|
984
991
|
}
|
|
985
992
|
|
|
986
993
|
}
|
|
@@ -1016,7 +1023,7 @@ class Combinator extends CombinatorBase {
|
|
|
1016
1023
|
emitter.emitln(`# ${d}`, this.level);
|
|
1017
1024
|
});
|
|
1018
1025
|
}
|
|
1019
|
-
emitter.emitln(`self.${_name(prop.name)} = ${
|
|
1026
|
+
emitter.emitln(`self.${_name(prop.name)} = ${_varName(prop.name)}`, this.level);
|
|
1020
1027
|
});
|
|
1021
1028
|
if (construct.body.length > 0) {
|
|
1022
1029
|
construct.body.forEach(gram => {
|
|
@@ -1115,19 +1122,19 @@ class Combinator extends CombinatorBase {
|
|
|
1115
1122
|
let selfVar = this.func_static ? '' : 'self';
|
|
1116
1123
|
|
|
1117
1124
|
if (func.params.length > 0) {
|
|
1118
|
-
emitter.emitln(`def ${
|
|
1125
|
+
emitter.emitln(`def ${_funcName(func.name)}_async(`);
|
|
1119
1126
|
this.levelUp();
|
|
1120
1127
|
if (selfVar) {
|
|
1121
1128
|
emitter.emitln(`${selfVar},`, this.level);
|
|
1122
1129
|
}
|
|
1123
1130
|
func.params.forEach(p => {
|
|
1124
1131
|
const type = this.getTypeHints(p.type);
|
|
1125
|
-
emitter.emitln(`${
|
|
1132
|
+
emitter.emitln(`${_varName(p.key)}: ${type},`, this.level);
|
|
1126
1133
|
});
|
|
1127
1134
|
this.levelDown();
|
|
1128
1135
|
emitter.emitln(`) -> ${rtype}:`, this.level);
|
|
1129
1136
|
} else {
|
|
1130
|
-
emitter.emit(`def ${
|
|
1137
|
+
emitter.emit(`def ${_funcName(func.name)}_async(`);
|
|
1131
1138
|
if (selfVar) {
|
|
1132
1139
|
emitter.emit(`${selfVar}`);
|
|
1133
1140
|
}
|
|
@@ -1158,19 +1165,19 @@ class Combinator extends CombinatorBase {
|
|
|
1158
1165
|
let selfVar = this.func_static ? '' : 'self';
|
|
1159
1166
|
|
|
1160
1167
|
if (func.params.length > 0) {
|
|
1161
|
-
emitter.emitln(`def ${
|
|
1168
|
+
emitter.emitln(`def ${_funcName(func.name)}(`);
|
|
1162
1169
|
this.levelUp();
|
|
1163
1170
|
if (selfVar) {
|
|
1164
1171
|
emitter.emitln(`${selfVar},`, this.level);
|
|
1165
1172
|
}
|
|
1166
1173
|
func.params.forEach(p => {
|
|
1167
1174
|
const type = this.getTypeHints(p.type);
|
|
1168
|
-
emitter.emitln(`${
|
|
1175
|
+
emitter.emitln(`${_varName(p.key)}: ${type},`, this.level);
|
|
1169
1176
|
});
|
|
1170
1177
|
this.levelDown();
|
|
1171
1178
|
emitter.emitln(`) -> ${rtype}:`, this.level);
|
|
1172
1179
|
} else {
|
|
1173
|
-
emitter.emit(`def ${
|
|
1180
|
+
emitter.emit(`def ${_funcName(func.name)}(`);
|
|
1174
1181
|
if (selfVar) {
|
|
1175
1182
|
emitter.emit(`${selfVar}`);
|
|
1176
1183
|
}
|
|
@@ -1234,7 +1241,8 @@ class Combinator extends CombinatorBase {
|
|
|
1234
1241
|
let list = this.includeList.filter(node => node.from && !node.alias);
|
|
1235
1242
|
|
|
1236
1243
|
let from = {};
|
|
1237
|
-
let fromList =
|
|
1244
|
+
let fromList = [];
|
|
1245
|
+
fromList = fromList.concat(this.additionalPackage);
|
|
1238
1246
|
|
|
1239
1247
|
list.forEach(item => {
|
|
1240
1248
|
if (!from[item.from]) {
|
|
@@ -1348,12 +1356,12 @@ class Combinator extends CombinatorBase {
|
|
|
1348
1356
|
pre += `.${_name(path.name)}`;
|
|
1349
1357
|
}
|
|
1350
1358
|
} else if (path.type === 'object') {
|
|
1351
|
-
pre += `${
|
|
1359
|
+
pre += `${_varName(_convertStaticParam(pathName))}`;
|
|
1352
1360
|
} else if (path.type === 'object_async') {
|
|
1353
1361
|
if (this.aioMode) {
|
|
1354
|
-
pre += `await ${
|
|
1362
|
+
pre += `await ${_varName(_convertStaticParam(pathName))}`;
|
|
1355
1363
|
} else {
|
|
1356
|
-
pre += `${
|
|
1364
|
+
pre += `${_varName(_convertStaticParam(pathName))}`;
|
|
1357
1365
|
}
|
|
1358
1366
|
} else if (path.type === 'object_static') {
|
|
1359
1367
|
pre += `${_convertStaticParam(pathName)}`;
|
|
@@ -1364,24 +1372,24 @@ class Combinator extends CombinatorBase {
|
|
|
1364
1372
|
pre += `${_convertStaticParam(pathName)}`;
|
|
1365
1373
|
}
|
|
1366
1374
|
} else if (path.type === 'call' || path.type === 'call_static') {
|
|
1367
|
-
pre += `.${
|
|
1375
|
+
pre += `.${_funcName(pathName)}(${params})`;
|
|
1368
1376
|
} else if (path.type === 'call_async' || path.type === 'call_static_async') {
|
|
1369
1377
|
if (this.aioMode) {
|
|
1370
|
-
pre += `.${
|
|
1378
|
+
pre += `.${_funcName(pathName)}_async(${params})`;
|
|
1371
1379
|
} else {
|
|
1372
|
-
pre += `.${
|
|
1380
|
+
pre += `.${_funcName(pathName)}(${params})`;
|
|
1373
1381
|
}
|
|
1374
1382
|
} else if (path.type === 'prop') {
|
|
1375
1383
|
pre += `.${_name(pathName)}`;
|
|
1376
1384
|
} else if (path.type === 'prop_static') {
|
|
1377
1385
|
pre += `.${_name(pathName)}`;
|
|
1378
1386
|
} else if (path.type === 'map') {
|
|
1379
|
-
pre += path.isVar ? `.get(${
|
|
1387
|
+
pre += path.isVar ? `.get(${_varName(pathName)})` : `.get('${pathName}')`;
|
|
1380
1388
|
} else if (path.type === 'map_set') {
|
|
1381
1389
|
const quote = this._adaptedQuotes(pathName, emitter);
|
|
1382
1390
|
pre += `[${quote}${pathName}${quote}]`;
|
|
1383
1391
|
} else if (path.type === 'list') {
|
|
1384
|
-
pre += path.isVar ? `[${
|
|
1392
|
+
pre += path.isVar ? `[${_varName(pathName)}]` : `[${pathName}]`;
|
|
1385
1393
|
} else {
|
|
1386
1394
|
debug.stack(gram);
|
|
1387
1395
|
}
|
|
@@ -1410,7 +1418,7 @@ class Combinator extends CombinatorBase {
|
|
|
1410
1418
|
emitter.emit(`${name}()`);
|
|
1411
1419
|
} else if (gram.varType === 'var' || gram.varType === 'const') {
|
|
1412
1420
|
const name = gram.name ? gram.name : gram.key;
|
|
1413
|
-
emitter.emit(`${_convertStaticParam(
|
|
1421
|
+
emitter.emit(`${_convertStaticParam(_varName(name))}`);
|
|
1414
1422
|
} else {
|
|
1415
1423
|
debug.stack(gram);
|
|
1416
1424
|
}
|
|
@@ -1422,7 +1430,7 @@ class Combinator extends CombinatorBase {
|
|
|
1422
1430
|
const quote = this._adaptedQuotes(gram.key, emitter);
|
|
1423
1431
|
emitter.emit(`${quote}${gram.key}${quote}: `);
|
|
1424
1432
|
} else {
|
|
1425
|
-
emitter.emit(`${
|
|
1433
|
+
emitter.emit(`${_varName(gram.key)}=`, this.level);
|
|
1426
1434
|
}
|
|
1427
1435
|
}
|
|
1428
1436
|
if (gram instanceof GrammerCall) {
|
|
@@ -1538,7 +1546,7 @@ class Combinator extends CombinatorBase {
|
|
|
1538
1546
|
const quote = this._adaptedQuotes(gram.value, emitter);
|
|
1539
1547
|
emitter.emit(`${quote}${gram.value}${quote}`);
|
|
1540
1548
|
} else if (gram.type === 'param') {
|
|
1541
|
-
emitter.emit(`${_convertStaticParam(
|
|
1549
|
+
emitter.emit(`${_convertStaticParam(_varName(gram.value))}`);
|
|
1542
1550
|
} else if (gram.type === 'call') {
|
|
1543
1551
|
this.grammerCall(emitter, gram.value);
|
|
1544
1552
|
} else if (gram.type === 'number') {
|
|
@@ -1758,7 +1766,7 @@ class Combinator extends CombinatorBase {
|
|
|
1758
1766
|
gram.params.forEach(p => {
|
|
1759
1767
|
let emit = new Emitter();
|
|
1760
1768
|
if (p.key) {
|
|
1761
|
-
emit.emit(`${
|
|
1769
|
+
emit.emit(`${_varName(p.key)}`);
|
|
1762
1770
|
emit.emit('=');
|
|
1763
1771
|
}
|
|
1764
1772
|
if (typeof (p.value) === 'string') {
|
|
@@ -1788,7 +1796,7 @@ class Combinator extends CombinatorBase {
|
|
|
1788
1796
|
this.grammerCall(emit, behavior.call);
|
|
1789
1797
|
|
|
1790
1798
|
if (behavior.isVar) {
|
|
1791
|
-
emitter.emit(`${emit.output}[${
|
|
1799
|
+
emitter.emit(`${emit.output}[${_varName(behavior.key)}] = `, this.level);
|
|
1792
1800
|
} else {
|
|
1793
1801
|
const quote = this._adaptedQuotes(behavior.key, emitter);
|
|
1794
1802
|
emitter.emit(`${emit.output}[${quote}${behavior.key}${quote}] = `, this.level);
|
|
@@ -6,44 +6,50 @@ module.exports = {
|
|
|
6
6
|
...defaultConfig,
|
|
7
7
|
indent: ' ',
|
|
8
8
|
ext: '.py',
|
|
9
|
-
keywords:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
9
|
+
keywords: {
|
|
10
|
+
general: [
|
|
11
|
+
'async',
|
|
12
|
+
'await',
|
|
13
|
+
'and',
|
|
14
|
+
'as',
|
|
15
|
+
'assert',
|
|
16
|
+
'break',
|
|
17
|
+
'class',
|
|
18
|
+
'continue',
|
|
19
|
+
'def',
|
|
20
|
+
'del',
|
|
21
|
+
'elif',
|
|
22
|
+
'else',
|
|
23
|
+
'except',
|
|
24
|
+
'finally',
|
|
25
|
+
'for',
|
|
26
|
+
'from',
|
|
27
|
+
'False',
|
|
28
|
+
'global',
|
|
29
|
+
'if',
|
|
30
|
+
'import',
|
|
31
|
+
'in',
|
|
32
|
+
'is',
|
|
33
|
+
'lambda',
|
|
34
|
+
'nonlocal',
|
|
35
|
+
'not',
|
|
36
|
+
'None',
|
|
37
|
+
'or',
|
|
38
|
+
'pass',
|
|
39
|
+
'raise',
|
|
40
|
+
'return',
|
|
41
|
+
'try',
|
|
42
|
+
'True',
|
|
43
|
+
'while',
|
|
44
|
+
'with',
|
|
45
|
+
'yield'
|
|
46
|
+
],
|
|
47
|
+
function: [],
|
|
48
|
+
class: [],
|
|
49
|
+
param_variables: [
|
|
50
|
+
'self'
|
|
51
|
+
]
|
|
52
|
+
},
|
|
47
53
|
symbolMap: {
|
|
48
54
|
'ASSIGN': '=',
|
|
49
55
|
'EQ': '==',
|
|
@@ -31,7 +31,9 @@ const {
|
|
|
31
31
|
_toSnakeCase,
|
|
32
32
|
_toCamelCase,
|
|
33
33
|
_avoidKeywords,
|
|
34
|
-
|
|
34
|
+
_avoidFuncKeywords,
|
|
35
|
+
_avoidClassKeywords,
|
|
36
|
+
_avoidVarKeywords,
|
|
35
37
|
_exception,
|
|
36
38
|
_symbol,
|
|
37
39
|
_deepClone,
|
|
@@ -43,6 +45,14 @@ function _name(name) {
|
|
|
43
45
|
return _avoidKeywords(_toSnakeCase(name));
|
|
44
46
|
}
|
|
45
47
|
|
|
48
|
+
function _varName(name){
|
|
49
|
+
return _avoidVarKeywords(_toSnakeCase(name));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function _funcName(name){
|
|
53
|
+
return _avoidFuncKeywords(_toSnakeCase(name));
|
|
54
|
+
}
|
|
55
|
+
|
|
46
56
|
function _type(type) {
|
|
47
57
|
const config = _config();
|
|
48
58
|
let t = type instanceof Object ? type.lexeme : type;
|
|
@@ -387,10 +397,7 @@ class Combinator extends CombinatorBase {
|
|
|
387
397
|
} else {
|
|
388
398
|
className = name.split('.').map(item => _upperFirst(item)).join('');
|
|
389
399
|
}
|
|
390
|
-
|
|
391
|
-
className = _avoidKeywords(className);
|
|
392
|
-
}
|
|
393
|
-
return _toCamelCase(className);
|
|
400
|
+
return _toCamelCase(_avoidClassKeywords(className));
|
|
394
401
|
}
|
|
395
402
|
|
|
396
403
|
emitClass(emitter, object) {
|
|
@@ -444,7 +451,7 @@ class Combinator extends CombinatorBase {
|
|
|
444
451
|
} else if (p instanceof PropItem) {
|
|
445
452
|
const type = this.typeHint(p.type);
|
|
446
453
|
if (type) {
|
|
447
|
-
emitter.emitln(`${
|
|
454
|
+
emitter.emitln(`${_varName(p.name)} = None # type: ${type}`, this.level);
|
|
448
455
|
}
|
|
449
456
|
}
|
|
450
457
|
});
|
|
@@ -611,7 +618,7 @@ class Combinator extends CombinatorBase {
|
|
|
611
618
|
type: type.itemType,
|
|
612
619
|
parentType: type.lexeme
|
|
613
620
|
};
|
|
614
|
-
this.emitComplexToMap(emitter, propInfo, `result['${
|
|
621
|
+
this.emitComplexToMap(emitter, propInfo, `result['${fieldName}']`, depth + 1);
|
|
615
622
|
} else {
|
|
616
623
|
if (type.itemType.objectType === 'model') {
|
|
617
624
|
emitter.emitln(`result['${fieldName}'].append(k.to_map() if k else None)`, this.level);
|
|
@@ -655,7 +662,7 @@ class Combinator extends CombinatorBase {
|
|
|
655
662
|
type: type.valType,
|
|
656
663
|
parentType: type.lexeme
|
|
657
664
|
};
|
|
658
|
-
this.emitComplexToMap(emitter, propInfo, `result['${
|
|
665
|
+
this.emitComplexToMap(emitter, propInfo, `result['${fieldName}']`, depth + 1);
|
|
659
666
|
} else {
|
|
660
667
|
if (type.valType.objectType === 'model') {
|
|
661
668
|
emitter.emitln(`result['${fieldName}'][k] = v.to_map()`, this.level);
|
|
@@ -896,9 +903,9 @@ class Combinator extends CombinatorBase {
|
|
|
896
903
|
let constructParams = [];
|
|
897
904
|
construct.params.forEach(param => {
|
|
898
905
|
if (param.value !== null && param.value !== 'null') {
|
|
899
|
-
constructParams.push(`${
|
|
906
|
+
constructParams.push(`${_varName(param.key)}=${param.value}`);
|
|
900
907
|
} else {
|
|
901
|
-
constructParams.push(`${
|
|
908
|
+
constructParams.push(`${_varName(param.key)}`);
|
|
902
909
|
}
|
|
903
910
|
});
|
|
904
911
|
emitter.emit('def __init__(self', this.level);
|
|
@@ -914,7 +921,7 @@ class Combinator extends CombinatorBase {
|
|
|
914
921
|
let curr_length = 0;
|
|
915
922
|
props.forEach((prop) => {
|
|
916
923
|
if (prop instanceof PropItem) {
|
|
917
|
-
let str = ` ${
|
|
924
|
+
let str = ` ${_varName(prop.name)}=None`;
|
|
918
925
|
if(curr_length+str.length>=max_length){
|
|
919
926
|
str = emitter.eol + emitter.indent(this.level + 3) + str;
|
|
920
927
|
curr_length = 0;
|
|
@@ -958,7 +965,7 @@ class Combinator extends CombinatorBase {
|
|
|
958
965
|
}
|
|
959
966
|
|
|
960
967
|
const fieldType = this.typeHint(prop.type);
|
|
961
|
-
emitter.emitln(`self.${_name(prop.name)} = ${
|
|
968
|
+
emitter.emitln(`self.${_name(prop.name)} = ${_varName(prop.name)} # type: ${fieldType}`, this.level);
|
|
962
969
|
});
|
|
963
970
|
if (construct.body.length > 0) {
|
|
964
971
|
construct.body.forEach(gram => {
|
|
@@ -1014,17 +1021,17 @@ class Combinator extends CombinatorBase {
|
|
|
1014
1021
|
}
|
|
1015
1022
|
if (func.params.length > 0) {
|
|
1016
1023
|
let selfVar = this.func_static ? '' : 'self, ';
|
|
1017
|
-
emitter.emit(`def ${
|
|
1024
|
+
emitter.emit(`def ${_funcName(func.name)}(${selfVar}`, this.level);
|
|
1018
1025
|
if (func.params.length > 0) {
|
|
1019
1026
|
let params = [];
|
|
1020
1027
|
func.params.forEach(p => {
|
|
1021
|
-
params.push(`${
|
|
1028
|
+
params.push(`${_varName(p.key)}`);
|
|
1022
1029
|
});
|
|
1023
1030
|
emitter.emit(params.join(', '));
|
|
1024
1031
|
}
|
|
1025
1032
|
} else {
|
|
1026
1033
|
let selfVar = this.func_static ? '' : 'self';
|
|
1027
|
-
emitter.emit(`def ${
|
|
1034
|
+
emitter.emit(`def ${_funcName(func.name)}(${selfVar}`, this.level);
|
|
1028
1035
|
}
|
|
1029
1036
|
emitter.emitln('):');
|
|
1030
1037
|
this.levelUp();
|
|
@@ -1216,24 +1223,24 @@ class Combinator extends CombinatorBase {
|
|
|
1216
1223
|
pre += `.${_name(path.name)}`;
|
|
1217
1224
|
}
|
|
1218
1225
|
} else if (path.type === 'object' || path.type === 'object_async') {
|
|
1219
|
-
pre += `${
|
|
1226
|
+
pre += `${_varName(_convertStaticParam(pathName))}`;
|
|
1220
1227
|
} else if (path.type === 'object_static' || path.type === 'object_static_async') {
|
|
1221
1228
|
pre += `${_convertStaticParam(pathName)}`;
|
|
1222
1229
|
} else if (path.type === 'call' || path.type === 'call_static') {
|
|
1223
|
-
pre += `.${
|
|
1230
|
+
pre += `.${_funcName(pathName)}(${params})`;
|
|
1224
1231
|
} else if (path.type === 'call_async' || path.type === 'call_static_async') {
|
|
1225
|
-
pre += `.${
|
|
1232
|
+
pre += `.${_funcName(pathName)}(${params})`;
|
|
1226
1233
|
} else if (path.type === 'prop') {
|
|
1227
1234
|
pre += `.${_name(pathName)}`;
|
|
1228
1235
|
} else if (path.type === 'prop_static') {
|
|
1229
1236
|
pre += `.${_name(pathName)}`;
|
|
1230
1237
|
} else if (path.type === 'map') {
|
|
1231
|
-
pre += path.isVar ? `.get(${
|
|
1238
|
+
pre += path.isVar ? `.get(${_varName(pathName)})` : `.get('${pathName}')`;
|
|
1232
1239
|
} else if (path.type === 'map_set') {
|
|
1233
1240
|
const quote = this._adaptedQuotes(pathName, emitter);
|
|
1234
1241
|
pre += `[${quote}${pathName}${quote}]`;
|
|
1235
1242
|
} else if (path.type === 'list') {
|
|
1236
|
-
pre += path.isVar ? `[${
|
|
1243
|
+
pre += path.isVar ? `[${_varName(pathName)}]` : `[${pathName}]`;
|
|
1237
1244
|
} else {
|
|
1238
1245
|
debug.stack(gram);
|
|
1239
1246
|
}
|
|
@@ -1276,7 +1283,7 @@ class Combinator extends CombinatorBase {
|
|
|
1276
1283
|
emitter.emit(`${name}()`);
|
|
1277
1284
|
} else if (gram.varType === 'var' || gram.varType === 'const') {
|
|
1278
1285
|
const name = gram.name ? gram.name : gram.key;
|
|
1279
|
-
emitter.emit(`${_convertStaticParam(
|
|
1286
|
+
emitter.emit(`${_convertStaticParam(_varName(name))}`);
|
|
1280
1287
|
} else {
|
|
1281
1288
|
debug.stack(gram);
|
|
1282
1289
|
}
|
|
@@ -1288,7 +1295,7 @@ class Combinator extends CombinatorBase {
|
|
|
1288
1295
|
const quote = this._adaptedQuotes(gram.key, emitter);
|
|
1289
1296
|
emitter.emit(`${quote}${gram.key}${quote}: `);
|
|
1290
1297
|
} else {
|
|
1291
|
-
emitter.emit(`${
|
|
1298
|
+
emitter.emit(`${_varName(gram.key)}=`, this.level);
|
|
1292
1299
|
}
|
|
1293
1300
|
}
|
|
1294
1301
|
if (gram instanceof GrammerCall) {
|
|
@@ -1404,7 +1411,7 @@ class Combinator extends CombinatorBase {
|
|
|
1404
1411
|
const quote = this._adaptedQuotes(gram.value, emitter);
|
|
1405
1412
|
emitter.emit(`${quote}${gram.value}${quote}`);
|
|
1406
1413
|
} else if (gram.type === 'param') {
|
|
1407
|
-
emitter.emit(`${_convertStaticParam(
|
|
1414
|
+
emitter.emit(`${_convertStaticParam(_varName(gram.value))}`);
|
|
1408
1415
|
} else if (gram.type === 'call') {
|
|
1409
1416
|
this.grammerCall(emitter, gram.value);
|
|
1410
1417
|
} else if (gram.type === 'number') {
|
|
@@ -1618,7 +1625,7 @@ class Combinator extends CombinatorBase {
|
|
|
1618
1625
|
gram.params.forEach(p => {
|
|
1619
1626
|
let emit = new Emitter();
|
|
1620
1627
|
if (p.key) {
|
|
1621
|
-
emit.emit(`${
|
|
1628
|
+
emit.emit(`${_varName(p.key)}`);
|
|
1622
1629
|
emit.emit('=');
|
|
1623
1630
|
}
|
|
1624
1631
|
if (typeof (p.value) === 'string') {
|
|
@@ -1648,7 +1655,7 @@ class Combinator extends CombinatorBase {
|
|
|
1648
1655
|
this.grammerCall(emit, behavior.call);
|
|
1649
1656
|
|
|
1650
1657
|
if (behavior.isVar) {
|
|
1651
|
-
emitter.emit(`${emit.output}[${
|
|
1658
|
+
emitter.emit(`${emit.output}[${_varName(behavior.key)}] = `, this.level);
|
|
1652
1659
|
} else {
|
|
1653
1660
|
const quote = this._adaptedQuotes(behavior.key, emitter);
|
|
1654
1661
|
emitter.emit(`${emit.output}[${quote}${behavior.key}${quote}] = `, this.level);
|
|
@@ -6,40 +6,49 @@ module.exports = {
|
|
|
6
6
|
...defaultConfig,
|
|
7
7
|
indent: ' ',
|
|
8
8
|
ext: '.py',
|
|
9
|
-
keywords:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
9
|
+
keywords: {
|
|
10
|
+
general: [
|
|
11
|
+
'and',
|
|
12
|
+
'as',
|
|
13
|
+
'assert',
|
|
14
|
+
'break',
|
|
15
|
+
'class',
|
|
16
|
+
'continue',
|
|
17
|
+
'def',
|
|
18
|
+
'del',
|
|
19
|
+
'elif',
|
|
20
|
+
'else',
|
|
21
|
+
'except',
|
|
22
|
+
'finally',
|
|
23
|
+
'for',
|
|
24
|
+
'from',
|
|
25
|
+
'False',
|
|
26
|
+
'global',
|
|
27
|
+
'if',
|
|
28
|
+
'import',
|
|
29
|
+
'in',
|
|
30
|
+
'is',
|
|
31
|
+
'lambda',
|
|
32
|
+
'not',
|
|
33
|
+
'None',
|
|
34
|
+
'or',
|
|
35
|
+
'pass',
|
|
36
|
+
'raise',
|
|
37
|
+
'return',
|
|
38
|
+
'try',
|
|
39
|
+
'True',
|
|
40
|
+
'while',
|
|
41
|
+
'with',
|
|
42
|
+
'yield'
|
|
43
|
+
],
|
|
44
|
+
function: [],
|
|
45
|
+
class: [],
|
|
46
|
+
param_variables: [
|
|
47
|
+
'exec',
|
|
48
|
+
'print',
|
|
49
|
+
'self'
|
|
50
|
+
]
|
|
51
|
+
},
|
|
43
52
|
symbolMap: {
|
|
44
53
|
'ASSIGN': '=',
|
|
45
54
|
'EQ': '==',
|
package/src/lib/helper.js
CHANGED
|
@@ -53,7 +53,31 @@ function _deepClone(obj) {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
function _avoidKeywords(str) {
|
|
56
|
-
if (config.keywords.indexOf(str.toLowerCase()) > -1) {
|
|
56
|
+
if (config.keywords.general.indexOf(str.toLowerCase()) > -1) {
|
|
57
|
+
return str + '_';
|
|
58
|
+
}
|
|
59
|
+
return str;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function _avoidFuncKeywords(str) {
|
|
63
|
+
if (config.keywords.general.indexOf(str.toLowerCase()) > -1
|
|
64
|
+
|| config.keywords.function.indexOf(str.toLowerCase()) > -1) {
|
|
65
|
+
return str + '_';
|
|
66
|
+
}
|
|
67
|
+
return str;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function _avoidClassKeywords(str) {
|
|
71
|
+
if (config.keywords.general.indexOf(str.toLowerCase()) > -1
|
|
72
|
+
|| config.keywords.class.indexOf(str.toLowerCase()) > -1) {
|
|
73
|
+
return str + '_';
|
|
74
|
+
}
|
|
75
|
+
return str;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function _avoidVarKeywords(str) {
|
|
79
|
+
if (config.keywords.general.indexOf(str.toLowerCase()) > -1
|
|
80
|
+
|| config.keywords.param_variables.indexOf(str.toLowerCase()) > -1) {
|
|
57
81
|
return str + '_';
|
|
58
82
|
}
|
|
59
83
|
return str;
|
|
@@ -69,7 +93,7 @@ function _convertStaticParam(param) {
|
|
|
69
93
|
}
|
|
70
94
|
|
|
71
95
|
function _isKeywords(str) {
|
|
72
|
-
return config.keywords.indexOf(str.toLowerCase()) > -1;
|
|
96
|
+
return config.keywords.general.indexOf(str.toLowerCase()) > -1;
|
|
73
97
|
}
|
|
74
98
|
|
|
75
99
|
function _modify(modify) {
|
|
@@ -159,6 +183,9 @@ module.exports = {
|
|
|
159
183
|
_isBasicType,
|
|
160
184
|
_deepClone,
|
|
161
185
|
_avoidKeywords,
|
|
186
|
+
_avoidFuncKeywords,
|
|
187
|
+
_avoidClassKeywords,
|
|
188
|
+
_avoidVarKeywords,
|
|
162
189
|
_convertStaticParam,
|
|
163
190
|
_isKeywords,
|
|
164
191
|
_modify,
|
|
@@ -118,9 +118,33 @@ class ComplexRequestComplexList(TeaModel):
|
|
|
118
118
|
return self
|
|
119
119
|
|
|
120
120
|
|
|
121
|
+
class ComplexRequestComplexList2(TeaModel):
|
|
122
|
+
def __init__(self, any=None):
|
|
123
|
+
self.any = any # type: any
|
|
124
|
+
|
|
125
|
+
def validate(self):
|
|
126
|
+
pass
|
|
127
|
+
|
|
128
|
+
def to_map(self):
|
|
129
|
+
_map = super(ComplexRequestComplexList2, self).to_map()
|
|
130
|
+
if _map is not None:
|
|
131
|
+
return _map
|
|
132
|
+
|
|
133
|
+
result = dict()
|
|
134
|
+
if self.any is not None:
|
|
135
|
+
result['Name'] = self.any
|
|
136
|
+
return result
|
|
137
|
+
|
|
138
|
+
def from_map(self, m=None):
|
|
139
|
+
m = m or dict()
|
|
140
|
+
if m.get('Name') is not None:
|
|
141
|
+
self.any = m.get('Name')
|
|
142
|
+
return self
|
|
143
|
+
|
|
144
|
+
|
|
121
145
|
class ComplexRequest(TeaModel):
|
|
122
146
|
def __init__(self, access_key=None, body=None, strs=None, header=None, num=None, configs=None, part=None,
|
|
123
|
-
complex_list=None, complex_list_1=None, from_=None):
|
|
147
|
+
complex_list=None, complex_list_1=None, complex_list_2=None, from_=None, self_=None, print_=None, exec_=None):
|
|
124
148
|
self.access_key = access_key # type: str
|
|
125
149
|
# Body
|
|
126
150
|
self.body = body # type: READABLE
|
|
@@ -134,8 +158,15 @@ class ComplexRequest(TeaModel):
|
|
|
134
158
|
self.part = part # type: list[ComplexRequestPart]
|
|
135
159
|
self.complex_list = complex_list # type: list[list[list[ComplexRequestComplexList]]]
|
|
136
160
|
self.complex_list_1 = complex_list_1 # type: list[list[dict[str, str]]]
|
|
161
|
+
self.complex_list_2 = complex_list_2 # type: list[list[list[ComplexRequestComplexList2]]]
|
|
137
162
|
# test keywords
|
|
138
163
|
self.from_ = from_ # type: str
|
|
164
|
+
# test keywords
|
|
165
|
+
self.self = self_ # type: str
|
|
166
|
+
# test keywords
|
|
167
|
+
self.print = print_ # type: str
|
|
168
|
+
# test keywords
|
|
169
|
+
self.exec = exec_ # type: str
|
|
139
170
|
|
|
140
171
|
def validate(self):
|
|
141
172
|
self.validate_required(self.access_key, 'access_key')
|
|
@@ -160,7 +191,17 @@ class ComplexRequest(TeaModel):
|
|
|
160
191
|
if k2:
|
|
161
192
|
k2.validate()
|
|
162
193
|
self.validate_required(self.complex_list_1, 'complex_list_1')
|
|
194
|
+
self.validate_required(self.complex_list_2, 'complex_list_2')
|
|
195
|
+
if self.complex_list_2:
|
|
196
|
+
for k in self.complex_list_2:
|
|
197
|
+
for k1 in k:
|
|
198
|
+
for k2 in k1:
|
|
199
|
+
if k2:
|
|
200
|
+
k2.validate()
|
|
163
201
|
self.validate_required(self.from_, 'from_')
|
|
202
|
+
self.validate_required(self.self, 'self')
|
|
203
|
+
self.validate_required(self.print, 'print')
|
|
204
|
+
self.validate_required(self.exec, 'exec')
|
|
164
205
|
|
|
165
206
|
def to_map(self):
|
|
166
207
|
_map = super(ComplexRequest, self).to_map()
|
|
@@ -196,8 +237,24 @@ class ComplexRequest(TeaModel):
|
|
|
196
237
|
result['complexList'].append(l1)
|
|
197
238
|
if self.complex_list_1 is not None:
|
|
198
239
|
result['complexList1'] = self.complex_list_1
|
|
240
|
+
result['ComplexList2'] = []
|
|
241
|
+
if self.complex_list_2 is not None:
|
|
242
|
+
for k in self.complex_list_2:
|
|
243
|
+
l1 = []
|
|
244
|
+
for k1 in k:
|
|
245
|
+
l2 = []
|
|
246
|
+
for k2 in k1:
|
|
247
|
+
l2.append(k2.to_map() if k2 else None)
|
|
248
|
+
l1.append(l2)
|
|
249
|
+
result['ComplexList2'].append(l1)
|
|
199
250
|
if self.from_ is not None:
|
|
200
251
|
result['from'] = self.from_
|
|
252
|
+
if self.self is not None:
|
|
253
|
+
result['self'] = self.self
|
|
254
|
+
if self.print is not None:
|
|
255
|
+
result['print'] = self.print
|
|
256
|
+
if self.exec is not None:
|
|
257
|
+
result['exec'] = self.exec
|
|
201
258
|
return result
|
|
202
259
|
|
|
203
260
|
def from_map(self, m=None):
|
|
@@ -234,8 +291,25 @@ class ComplexRequest(TeaModel):
|
|
|
234
291
|
self.complex_list.append(l1)
|
|
235
292
|
if m.get('complexList1') is not None:
|
|
236
293
|
self.complex_list_1 = m.get('complexList1')
|
|
294
|
+
self.complex_list_2 = []
|
|
295
|
+
if m.get('ComplexList2') is not None:
|
|
296
|
+
for k in m.get('ComplexList2'):
|
|
297
|
+
l1 = []
|
|
298
|
+
for k1 in k:
|
|
299
|
+
l2 = []
|
|
300
|
+
for k2 in k1:
|
|
301
|
+
temp_model = ComplexRequestComplexList2()
|
|
302
|
+
l2.append(temp_model.from_map(k2))
|
|
303
|
+
l1.append(l2)
|
|
304
|
+
self.complex_list_2.append(l1)
|
|
237
305
|
if m.get('from') is not None:
|
|
238
306
|
self.from_ = m.get('from')
|
|
307
|
+
if m.get('self') is not None:
|
|
308
|
+
self.self = m.get('self')
|
|
309
|
+
if m.get('print') is not None:
|
|
310
|
+
self.print = m.get('print')
|
|
311
|
+
if m.get('exec') is not None:
|
|
312
|
+
self.exec = m.get('exec')
|
|
239
313
|
return self
|
|
240
314
|
|
|
241
315
|
|
|
@@ -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: {
|
|
@@ -170,9 +169,18 @@ describe('Python Generator', function () {
|
|
|
170
169
|
github: 'https://github.com/',
|
|
171
170
|
author: 'Alibaba',
|
|
172
171
|
email: 'sdk-team@alibabacloud.com'
|
|
173
|
-
}
|
|
172
|
+
},
|
|
173
|
+
additionalPackage: [
|
|
174
|
+
{
|
|
175
|
+
from: '__future__',
|
|
176
|
+
import: 'annotations'
|
|
177
|
+
}
|
|
178
|
+
]
|
|
174
179
|
}
|
|
175
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);
|
|
176
184
|
});
|
|
177
185
|
|
|
178
186
|
it('map should ok', function () {
|
|
@@ -195,7 +203,13 @@ describe('Python Generator', function () {
|
|
|
195
203
|
{
|
|
196
204
|
python: {
|
|
197
205
|
package: 'tea_python_tests',
|
|
198
|
-
clientName: 'client'
|
|
206
|
+
clientName: 'client',
|
|
207
|
+
additionalPackage: [
|
|
208
|
+
{
|
|
209
|
+
from: '__future__',
|
|
210
|
+
import: 'annotations'
|
|
211
|
+
}
|
|
212
|
+
]
|
|
199
213
|
}
|
|
200
214
|
});
|
|
201
215
|
});
|
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
|
});
|