@darabonba/python-generator 1.2.18 → 2.0.0

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.
Files changed (138) hide show
  1. package/ChangeLog.md +0 -155
  2. package/lib/builtin.js +818 -0
  3. package/lib/generator.js +2704 -0
  4. package/lib/helper.js +422 -0
  5. package/package.json +6 -5
  6. package/src/lib/helper.js +11 -1
  7. package/src/resolver/base.js +3 -1
  8. package/src/resolver/client.js +7 -4
  9. package/src/resolver/model.js +5 -3
  10. package/tests/expected/alias/setup.py +79 -0
  11. package/tests/expected/alias/tea_python_tests/__init__.py +1 -0
  12. package/tests/expected/alias/tea_python_tests/client.py +35 -0
  13. package/tests/expected/annotation/tea_python_tests/__init__.py +1 -0
  14. package/tests/expected/annotation/tea_python_tests/client.py +93 -0
  15. package/tests/expected/annotation/tea_python_tests/models.py +37 -0
  16. package/tests/expected/api/tea_python_tests/__init__.py +1 -0
  17. package/tests/expected/api/tea_python_tests/client.py +106 -0
  18. package/tests/expected/builtin/tea_python_tests/client.py +685 -0
  19. package/tests/expected/comment/tea_python_tests/__init__.py +1 -0
  20. package/tests/expected/comment/tea_python_tests/client.py +288 -0
  21. package/tests/expected/comment/tea_python_tests/models.py +195 -0
  22. package/tests/expected/complex/tea_python_tests/__init__.py +1 -0
  23. package/tests/expected/complex/tea_python_tests/client.py +1168 -0
  24. package/tests/expected/complex/tea_python_tests/exceptions.py +39 -0
  25. package/tests/expected/complex/tea_python_tests/models.py +570 -0
  26. package/tests/expected/const/tea_python_tests/__init__.py +1 -0
  27. package/tests/expected/const/tea_python_tests/client.py +14 -0
  28. package/tests/expected/empty/setup.py +74 -0
  29. package/tests/expected/empty/tea_python_tests/__init__.py +1 -0
  30. package/tests/expected/empty/tea_python_tests/client.py +10 -0
  31. package/tests/expected/exec/tea_python_tests/__init__.py +1 -0
  32. package/tests/expected/exec/tea_python_tests/exec_client.py +21 -0
  33. package/tests/expected/function/tea_python_tests/__init__.py +1 -0
  34. package/tests/expected/function/tea_python_tests/client.py +64 -0
  35. package/tests/expected/import/setup.py +78 -0
  36. package/tests/expected/import/tea_python_tests/__init__.py +1 -0
  37. package/tests/expected/import/tea_python_tests/client.py +29 -0
  38. package/tests/expected/map/tea_python_tests/__init__.py +1 -0
  39. package/tests/expected/map/tea_python_tests/client.py +39 -0
  40. package/tests/expected/model/tea_python_tests/__init__.py +1 -0
  41. package/tests/expected/model/tea_python_tests/client.py +10 -0
  42. package/tests/expected/model/tea_python_tests/exceptions.py +28 -0
  43. package/tests/expected/model/tea_python_tests/models.py +780 -0
  44. package/tests/expected/multi/tea_python_tests/api.py +95 -0
  45. package/tests/expected/multi/tea_python_tests/client.py +40 -0
  46. package/tests/expected/multi/tea_python_tests/lib/util.py +19 -0
  47. package/tests/expected/multi/tea_python_tests/model/user.py +23 -0
  48. package/tests/expected/multi/tea_python_tests/model/user_exceptions.py +83 -0
  49. package/tests/expected/multi/tea_python_tests/model/user_models.py +145 -0
  50. package/tests/expected/python2/function/tea_python_tests/client.py +3 -1
  51. package/tests/expected/python2/model/tea_python_tests/models.py +57 -30
  52. package/tests/expected/python3/function/tea_python_tests/client.py +3 -1
  53. package/tests/expected/python3/model/tea_python_tests/models.py +57 -29
  54. package/tests/expected/statements/tea_python_tests/__init__.py +1 -0
  55. package/tests/expected/statements/tea_python_tests/client.py +86 -0
  56. package/tests/expected/super/tea_python_tests/__init__.py +1 -0
  57. package/tests/expected/super/tea_python_tests/client.py +16 -0
  58. package/tests/expected/typedef/setup.py +77 -0
  59. package/tests/expected/typedef/tea_python_tests/__init__.py +1 -0
  60. package/tests/expected/typedef/tea_python_tests/client.py +74 -0
  61. package/tests/expected/typedef/tea_python_tests/models.py +42 -0
  62. package/tests/fixtures/alias/Darafile +11 -0
  63. package/tests/fixtures/alias/libraries/Alias/Darafile +11 -0
  64. package/tests/fixtures/alias/libraries/Alias-Symbol/Darafile +11 -0
  65. package/tests/fixtures/builtin/Darafile +6 -0
  66. package/tests/fixtures/builtin/main.dara +333 -0
  67. package/tests/fixtures/complex/libraries/import.dara +18 -11
  68. package/tests/fixtures/complex/main.dara +451 -103
  69. package/tests/fixtures/function/main.dara +2 -0
  70. package/tests/fixtures/import/libraries/Darafile +1 -1
  71. package/tests/fixtures/import/pack/Darafile +3 -0
  72. package/tests/fixtures/map/libraries/Darafile +3 -0
  73. package/tests/fixtures/map/libraries/import.dara +4 -0
  74. package/tests/fixtures/map/main.dara +17 -2
  75. package/tests/fixtures/model/.libraries.json +3 -0
  76. package/tests/fixtures/model/Darafile +5 -2
  77. package/tests/fixtures/model/libraries/Darafile +20 -0
  78. package/tests/fixtures/model/libraries/import.dara +27 -0
  79. package/tests/fixtures/model/main.dara +57 -37
  80. package/tests/fixtures/multi/.libraries.json +3 -0
  81. package/tests/fixtures/multi/Darafile +12 -0
  82. package/tests/fixtures/multi/api.dara +20 -0
  83. package/tests/fixtures/multi/lib/util.dara +5 -0
  84. package/tests/fixtures/multi/libraries/darabonba_Util_0.2.11/Teafile +62 -0
  85. package/tests/fixtures/multi/libraries/darabonba_Util_0.2.11/main.tea +244 -0
  86. package/tests/fixtures/multi/main.dara +32 -0
  87. package/tests/fixtures/multi/model/user.dara +33 -0
  88. package/tests/{python3.tests.js → main.tests.js} +107 -65
  89. package/tests/output/alias/setup.py +79 -0
  90. package/tests/output/alias/tea_python_tests/client.py +35 -0
  91. package/tests/output/annotation/setup.py +77 -0
  92. package/tests/output/annotation/tea_python_tests/client.py +93 -0
  93. package/tests/output/annotation/tea_python_tests/models.py +37 -0
  94. package/tests/output/api/setup.py +77 -0
  95. package/tests/output/api/tea_python_tests/client.py +106 -0
  96. package/tests/output/builtin/setup.py +77 -0
  97. package/tests/output/builtin/tea_python_tests/client.py +685 -0
  98. package/tests/output/comment/setup.py +77 -0
  99. package/tests/output/comment/tea_python_tests/client.py +288 -0
  100. package/tests/output/comment/tea_python_tests/models.py +195 -0
  101. package/tests/output/complex/setup.py +77 -0
  102. package/tests/output/complex/tea_python_tests/client.py +1168 -0
  103. package/tests/output/complex/tea_python_tests/exceptions.py +39 -0
  104. package/tests/output/complex/tea_python_tests/models.py +570 -0
  105. package/tests/output/const/setup.py +77 -0
  106. package/tests/output/const/tea_python_tests/client.py +14 -0
  107. package/tests/output/empty/setup.py +77 -0
  108. package/tests/output/empty/tea_python_tests/client.py +10 -0
  109. package/tests/output/exec/setup.py +77 -0
  110. package/tests/output/exec/tea_python_tests/exec_client.py +21 -0
  111. package/tests/output/function/setup.py +77 -0
  112. package/tests/output/function/tea_python_tests/client.py +64 -0
  113. package/tests/output/import/setup.py +78 -0
  114. package/tests/output/import/tea_python_tests/client.py +29 -0
  115. package/tests/output/map/setup.py +77 -0
  116. package/tests/output/map/tea_python_tests/client.py +39 -0
  117. package/tests/output/model/setup.py +77 -0
  118. package/tests/output/model/tea_python_tests/client.py +10 -0
  119. package/tests/output/model/tea_python_tests/exceptions.py +28 -0
  120. package/tests/output/model/tea_python_tests/models.py +780 -0
  121. package/tests/output/multi/setup.py +77 -0
  122. package/tests/output/multi/tea_python_tests/api.py +95 -0
  123. package/tests/output/multi/tea_python_tests/client.py +40 -0
  124. package/tests/output/multi/tea_python_tests/lib/util.py +19 -0
  125. package/tests/output/multi/tea_python_tests/model/user.py +23 -0
  126. package/tests/output/multi/tea_python_tests/model/user_exceptions.py +83 -0
  127. package/tests/output/multi/tea_python_tests/model/user_models.py +145 -0
  128. package/tests/output/statements/setup.py +77 -0
  129. package/tests/output/statements/tea_python_tests/client.py +86 -0
  130. package/tests/output/super/setup.py +77 -0
  131. package/tests/output/super/tea_python_tests/client.py +16 -0
  132. package/tests/output/typedef/setup.py +78 -0
  133. package/tests/output/typedef/tea_python_tests/client.py +74 -0
  134. package/tests/output/typedef/tea_python_tests/models.py +42 -0
  135. package/tests/common.tests.js +0 -244
  136. package/tests/lib.tests.js +0 -269
  137. package/tests/python2.tests.js +0 -283
  138. 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": "1.2.18",
3
+ "version": "2.0.0",
4
4
  "description": "The darabonba generator for Python",
5
- "main": "src/generator.js",
5
+ "main": "lib/generator.js",
6
6
  "directories": {
7
- "src": "src"
7
+ "lib": "lib"
8
8
  },
9
9
  "scripts": {
10
- "lint": "eslint --fix src/",
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.2.10",
33
+ "@darabonba/annotation-parser": "^1.0.1",
34
+ "@darabonba/parser": "^2.1.4",
34
35
  "enum": "^3.0.4"
35
36
  }
36
37
  }
package/src/lib/helper.js CHANGED
@@ -41,7 +41,12 @@ function _subModelName(name) {
41
41
  }
42
42
 
43
43
  function _string(str) {
44
- return str.string;
44
+ if (str.string === '""') {
45
+ return '\\"\\"';
46
+ }
47
+ return str.string.replace(/([^\\])"+|^"/g, function (str) {
48
+ return str.replace(/"/g, '\\"');
49
+ });
45
50
  }
46
51
 
47
52
  function _isBasicType(type) {
@@ -172,9 +177,14 @@ function _toSnakeCase(str) {
172
177
  return res;
173
178
  }
174
179
 
180
+ function _escape(str) {
181
+ return str.includes('-') ? `${str}` : str;
182
+ }
183
+
175
184
 
176
185
  module.exports = {
177
186
  _config,
187
+ _escape,
178
188
  _upperFirst,
179
189
  _camelCase,
180
190
  _string,
@@ -3,6 +3,8 @@
3
3
  const debug = require('../lib/debug');
4
4
 
5
5
  const {
6
+ _string,
7
+ _escape,
6
8
  _isBasicType
7
9
  } = require('../lib/helper');
8
10
 
@@ -176,7 +178,7 @@ class BaseResolver {
176
178
  } else if (typeNode.type === 'modelBody') {
177
179
  // is sub model
178
180
  typeInfo['objectType'] = 'model';
179
- typeInfo['lexeme'] = this.combinator.addModelInclude([this.object.name, sourceNode.fieldName.lexeme].join('.'));
181
+ typeInfo['lexeme'] = this.combinator.addModelInclude([this.object.name, _escape(sourceNode.fieldName.lexeme) || _string(sourceNode.fieldName)].join('.'));
180
182
  return typeInfo;
181
183
  } else if (_isBasicType(typeNode.type)) {
182
184
  return this.resolveType(typeNode.type, typeNode);
@@ -43,7 +43,10 @@ const {
43
43
  } = require('../langs/common/enum');
44
44
 
45
45
  const {
46
- _isBasicType
46
+ _isBasicType,
47
+ _string,
48
+ _escape
49
+
47
50
  } = require('../lib/helper');
48
51
 
49
52
  const systemPackage = ['Util'];
@@ -158,7 +161,7 @@ class ClientResolver extends BaseResolver {
158
161
  ast.params.params.forEach(p => {
159
162
  var param = new GrammerValue();
160
163
  param.type = this.resolveType(p.paramType, p);
161
- param.key = p.paramName.lexeme;
164
+ param.key = _escape(p.paramName.lexeme || _string(p.paramName));
162
165
  if (p.needValidate) {
163
166
  func.addBodyNode(new GrammerCall('method', [
164
167
  { type: 'object', name: param.key },
@@ -450,8 +453,8 @@ class ClientResolver extends BaseResolver {
450
453
  valGrammer.needCast = true;
451
454
  exprChild.isExpand = true;
452
455
  }
453
- if (field.fieldName && field.fieldName.lexeme) {
454
- exprChild.key = field.fieldName.lexeme;
456
+ if (field.fieldName && (field.fieldName.lexeme || field.fieldName.string)) {
457
+ exprChild.key = (field.fieldName.lexeme) || _string(field.fieldName);
455
458
  }
456
459
  this.renderGrammerValue(exprChild, field.expr, expectedType);
457
460
  this.findComments(valGrammer, field);
@@ -6,7 +6,9 @@ const assert = require('assert');
6
6
  const BaseResolver = require('./base');
7
7
 
8
8
  const {
9
- _isBasicType
9
+ _string,
10
+ _escape,
11
+ _isBasicType,
10
12
  } = require('../lib/helper');
11
13
 
12
14
  const {
@@ -95,7 +97,7 @@ class ModelResolver extends BaseResolver {
95
97
 
96
98
  const prop = new PropItem();
97
99
  prop.belong = object.index;
98
- prop.name = node.fieldName.lexeme;
100
+ prop.name = _escape(node.fieldName.lexeme) || _string(node.fieldName);
99
101
  prop.type = this.resolveType(node.fieldValue, node);
100
102
 
101
103
  prop.modify.push(Modify.public());
@@ -141,7 +143,7 @@ class ModelResolver extends BaseResolver {
141
143
  }
142
144
 
143
145
  findSubModelsUsed(node, subModelUsed = [], pre = '') {
144
- let name = node.fieldName.lexeme;
146
+ let name = _escape(node.fieldName.lexeme) || _string(node.fieldName);
145
147
  if (pre !== '') {
146
148
  name = pre + '.' + name;
147
149
  }
@@ -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"