@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
@@ -0,0 +1,333 @@
1
+ static async function arrayTest(args: [string]): void {
2
+ if((args.length() > 0) && args.contains('cn-hanghzou')) {
3
+ var index = args.index('cn-hanghzou');
4
+ var regionId: string = args.get(index);
5
+ var all = args.join(',');
6
+ var first = args.shift();
7
+ var last = args.pop();
8
+ var length1 = args.unshift(first);
9
+ var length2 = args.push(last);
10
+ var length3:integer = length1 + length2;
11
+ var longStr = 'long' + first + last;
12
+ var fullStr = args.join(',');
13
+ var newArr = ['test'];
14
+ var cArr: [ string ] = newArr.concat(args);
15
+ var acsArr = newArr.sort('acs');
16
+ var descArr = newArr.sort('desc');
17
+ var llArr: [string] = acsArr.concat(descArr);
18
+ llArr.append('test', 10);
19
+ llArr.remove('test');
20
+ }
21
+ }
22
+
23
+ static async function bytesTest(args: [string]): void {
24
+ var fullStr = args.join(',');
25
+ var data = fullStr.toBytes('utf8');
26
+ var newFullStr = data.toString();
27
+ if(fullStr != newFullStr) {
28
+ return;
29
+ }
30
+ var hexStr = data.toHex();
31
+
32
+ var base64Str = data.toBase64();
33
+
34
+ var length: integer = data.length();
35
+
36
+ var obj = data.toJSON();
37
+
38
+ var data2 = $Bytes.from(fullStr, 'base64');
39
+ }
40
+
41
+ static async function dateTest(args: [string]): void {
42
+ var date = new $Date('2023-09-12 17:47:31.916000 +0800 UTC');
43
+ var dateStr = date.format('YYYY-MM-DD HH:mm:ss');
44
+ var timestamp = date.unix();
45
+ var yesterday = date.sub('day', 1);
46
+ var oneDay = date.diff('day', yesterday);
47
+ var tomorrow = date.add('day', 1);
48
+ var twoDay = tomorrow.diff('day', date) + oneDay;
49
+ var hour = date.hour();
50
+ var minute = date.minute();
51
+ var second = date.second();
52
+ var dayOfMonth = date.dayOfMonth();
53
+ var dayOfWeek = date.dayOfWeek();
54
+ var weekOfYear = date.weekOfYear();
55
+ var month = date.month();
56
+ var year = date.year();
57
+ var utcDate = date.UTC();
58
+ }
59
+
60
+ static async function envTest(args: [string]): void {
61
+ var es = $Env.get('TEST');
62
+ var ma = $Env.set('TEST', es + 'test');
63
+ }
64
+
65
+ static async function fileTest(args: [string]): void {
66
+ if($File.exists('/tmp/test')) {
67
+ var file = new $File('/tmp/test');
68
+ var path = file.path();
69
+ var length = file.length() + 10;
70
+ var createTime = file.createTime();
71
+ var modifyTime = file.modifyTime();
72
+ var timeLong = modifyTime.diff('minute', createTime);
73
+ var data = file.read(300);
74
+ file.write($Bytes.from('test', 'utf8'));
75
+ var rs:readable = $File.createReadStream('/tmp/test');
76
+ var ws:writable = $File.createWriteStream('/tmp/test');
77
+ }
78
+ }
79
+
80
+ static async function formTest(args: [string]): void {
81
+ var m = {
82
+ key1 = 'test1',
83
+ key2 = 'test2',
84
+ key3 = 3,
85
+ key4 = {
86
+ key5 = 123,
87
+ key6 = '321'
88
+ }
89
+ };
90
+ var form = $Form.toFormString(m);
91
+ form = form + "&key7=23233&key8=" + $Form.getBoundary();
92
+
93
+ var r:readable = $Form.toFileForm(m, $Form.getBoundary());
94
+ }
95
+
96
+ static async function jsonTest(args: [string]): void {
97
+ var m = {
98
+ key1 = 'test1',
99
+ key2 = 'test2',
100
+ key3 = 3,
101
+ key4 = {
102
+ key5 = 123,
103
+ key6 = '321'
104
+ }
105
+ };
106
+ var ms = $JSON.stringify(m);
107
+ var ma = $JSON.parseJSON(ms);
108
+ var arrStr = '[1,2,3,4]';
109
+ var arr = $JSON.parseJSON(arrStr);
110
+ }
111
+
112
+ static async function logerTest(args: [string]): void {
113
+ $Logger.log("test");
114
+ $Logger.info("test");
115
+ $Logger.warning("test");
116
+ $Logger.debug("test");
117
+ $Logger.error("test");
118
+ }
119
+
120
+ static async function mapTestCase(args: [string]): void {
121
+ var mapTest = {
122
+ key1 = 'value1',
123
+ key2 = 'value2',
124
+ key3 = 'value3',
125
+ };
126
+
127
+ var length = mapTest.length();
128
+ var num = length + 3;
129
+ var keys = mapTest.keySet();
130
+ var allKey = '';
131
+ for(var key : keys) {
132
+ allKey = allKey + key;
133
+ }
134
+ var entries: [ entry[string] ] = mapTest.entries();
135
+ var newKey = '';
136
+ var newValue = '';
137
+ for(var e : entries) {
138
+ newKey = newKey + e.key();
139
+ newValue = newValue + e.value();
140
+ }
141
+
142
+ var json = mapTest.toJSON();
143
+ var mapTest2 = {
144
+ key1 = 'value4',
145
+ key4 = 'value5',
146
+ };
147
+ var mapTest3 = mapTest.merge(mapTest2);
148
+ if(mapTest3['key1'] == 'value4') {
149
+ return;
150
+ }
151
+ }
152
+
153
+ static async function numberTest(args: [string]): void {
154
+ var num = 3.2;
155
+ var inum: integer = num.parseInt();
156
+ var lnum: long = num.parseLong();
157
+ var fnum: float = num.parseFloat();
158
+ var dnum: double = num.parseDouble();
159
+
160
+ inum = inum.parseInt();
161
+ lnum = inum.parseLong();
162
+ fnum = inum.parseFloat();
163
+ dnum = inum.parseDouble();
164
+
165
+ inum = lnum.parseInt();
166
+ lnum = lnum.parseLong();
167
+ fnum = lnum.parseFloat();
168
+ dnum = lnum.parseDouble();
169
+
170
+ inum = fnum.parseInt();
171
+ lnum = fnum.parseLong();
172
+ fnum = fnum.parseFloat();
173
+ dnum = fnum.parseDouble();
174
+
175
+ inum = dnum.parseInt();
176
+ lnum = dnum.parseLong();
177
+ fnum = dnum.parseFloat();
178
+ dnum = dnum.parseDouble();
179
+
180
+ lnum = inum.itol();
181
+ inum = lnum.ltoi();
182
+
183
+ var randomNum = $Number.random();
184
+ inum = $Number.floor(inum);
185
+ inum = $Number.round(inum);
186
+ }
187
+
188
+ static async function streamTest(args: [string]): void {
189
+ if($File.exists('/tmp/test')) {
190
+ var rs:readable = $File.createReadStream('/tmp/test');
191
+ var ws:writable = $File.createWriteStream('/tmp/test');
192
+ var data = rs.read(30);
193
+ ws.write(data);
194
+ rs.pipe(ws);
195
+ data = $Stream.readAsBytes(rs);
196
+ var obj = $Stream.readAsJSON(rs);
197
+ var jsonStr = $Stream.readAsString(rs);
198
+ }
199
+ }
200
+
201
+ static async function stringTest(args: [string]): void {
202
+ var fullStr = args.join(',');
203
+ args = fullStr.split(',');
204
+
205
+ if((fullStr.length() > 0) && fullStr.contains('hangzhou')) {
206
+ var newStr1 = fullStr.replace('/hangzhou/g', 'beijing');
207
+ }
208
+
209
+ if(fullStr.hasPrefix('cn')) {
210
+ var newStr2 = fullStr.replace('/cn/gi', 'zh');
211
+ }
212
+
213
+ if(fullStr.hasPrefix('beijing')) {
214
+ var newStr3 = fullStr.replace('/beijing/', 'chengdu');
215
+ }
216
+
217
+ var start = fullStr.index('beijing');
218
+
219
+ var end = start + 7;
220
+
221
+ var region = fullStr.subString(start, end);
222
+
223
+ var lowerRegion = region.toLower();
224
+ var upperRegion = region.toUpper();
225
+
226
+ if(region.equals('beijing')) {
227
+ region = region + ' ';
228
+ region = region.trim();
229
+ }
230
+
231
+ var tb: bytes = fullStr.toBytes('utf8');
232
+ var em = 'xxx';
233
+ if(em.empty()) {
234
+ return;
235
+ }
236
+ var num = '32.0a';
237
+ var inum = num.parseInt() + 3;
238
+ var lnum:long = num.parseLong();
239
+ var fnum:float = num.parseFloat() + 1.0;
240
+ var dnum:double = num.parseDouble() + 1.0d;
241
+ }
242
+
243
+ static async function urlTest(args: [string]): void {
244
+ var url = new $URL(args[0]);
245
+ var path = url.path();
246
+ var pathname = url.pathname();
247
+ var protocol = url.protocol();
248
+ var hostname = url.hostname();
249
+ var port = url.port();
250
+ var host = url.host();
251
+ var hash = url.hash();
252
+ var search = url.search();
253
+ var href = url.href();
254
+ var auth = url.auth();
255
+ var url2 = $URL.parse(args[1]);
256
+ path = url2.path();
257
+ var newUrl = $URL.urlEncode(args[2]);
258
+ var newSearch = $URL.percentEncode(search);
259
+ var newPath = $URL.pathEncode(pathname);
260
+ var all = 'test' + path + protocol + hostname + hash + search + href + auth + newUrl + newSearch + newPath;
261
+ }
262
+
263
+ static async function xmlTest(args: [string]): void {
264
+ var m = {
265
+ key1 = 'test1',
266
+ key2 = 'test2',
267
+ key3 = 3,
268
+ key4 = {
269
+ key5 = 123,
270
+ key6 = '321'
271
+ }
272
+ };
273
+ var xml = $XML.toXML(m);
274
+ xml = xml + "<key7>132</key7>";
275
+
276
+ var respMap : map[string]any = $XML.parseXml(xml, null);
277
+ }
278
+
279
+ static function returnAny(): any;
280
+
281
+ static async function main(args: [string]):void {
282
+ arrayTest(args);
283
+ bytesTest(args);
284
+ dateTest(args);
285
+ envTest(args);
286
+ fileTest(args);
287
+ formTest(args);
288
+ logerTest(args);
289
+ mapTestCase(args);
290
+ numberTest(args);
291
+ streamTest(args);
292
+ stringTest(args);
293
+ urlTest(args);
294
+ xmlTest(args);
295
+
296
+ var a: integer = $integer(args[0]) + 10;
297
+ var b: string = $string(a) + args[1] + $string(returnAny());
298
+ var c: number = $number(b) + $number(a) + $number(returnAny());
299
+ var d: int8 = $int8(b) + $int8(a) + $int8(returnAny());
300
+ var e: int16 = $int16(b) + $int16(a) + $int16(returnAny());
301
+ var f: int32 = $int32(b) + $int32(a) + $int32(returnAny());
302
+ var g: int64 = $int64(b) + $int64(a) + $int64(returnAny());
303
+ var h: long = $long(b) + $long(a) + $long(returnAny());
304
+ var i: ulong = $ulong(b) + $ulong(a) + $ulong(returnAny());
305
+ var j: uint8 = $uint8(b) + $uint8(a) + $uint8(returnAny());
306
+ var k: uint16 = $uint16(b) + $uint16(a) + $uint16(returnAny());
307
+ var l: uint32 = $uint32(b) + $uint32(a) + $uint32(returnAny());
308
+ var m: uint64 = $uint64(b) + $uint64(a) + $uint64(returnAny());
309
+ var n: float = $float(b) + $float(a) + $float(returnAny());
310
+ var o: double = $double(b) + $double(a) + $double(returnAny());
311
+ if($boolean(args[2])) {
312
+ var data = $bytes(returnAny());
313
+ var length: integer = data.length();
314
+ var test: any = $any(data);
315
+ var maps: map[string]string = {
316
+ key = 'value',
317
+ };
318
+ var obj: object = $object(maps);
319
+ var ws = $writable(obj);
320
+ var rs = $readable(maps);
321
+ data = rs.read(30);
322
+ if(!$isNull(data)) {
323
+ ws.write(data);
324
+ }
325
+ }
326
+
327
+ $sleep(a);
328
+ var defaultVal = $string($default(args[0], args[1]));
329
+
330
+ if($equal(defaultVal, b)) {
331
+ return;
332
+ }
333
+ }
@@ -1,31 +1,38 @@
1
1
  model RuntimeObject = {}
2
2
 
3
- static function array(request: object, str: string): [ any ];
4
-
5
- static function query(q: object): map[string]string;
6
- static function body(): readable;
7
- static function parse(c: class): void;
8
- static async function asyncFunc(): void;
9
-
10
3
  type @protocol = string
11
4
  type @pathname = string
12
5
 
13
6
  init(config: Config);
14
7
  model Config = {}
15
- function print(runtime: object, str: string): void {
8
+ function printData(runtime: object, str: string): void {
16
9
  return;
17
10
  }
18
11
 
19
- async function printAsync(runtime: object, str: string): void {
20
- return;
12
+ static function judgeStr(a: string): boolean {
13
+ return true;
21
14
  }
22
15
 
16
+ static function query(q: object): map[string]string;
17
+ static function body(): readable;
18
+ static function parse(c: class): void;
19
+ static async function asyncFunc(): void;
20
+
23
21
  model Request = {
24
22
  accesskey?: string(name='accesskey', description='accesskey'),
25
23
  region?: string(name='region', description='region'),
24
+ instance: {
25
+ instanceId: string(name='instanceId', description='instanceId'),
26
+ }(name='instance', description='instance'),
26
27
  configs: {
27
28
  key: string,
28
29
  value: [ string ],
29
30
  extra: map[string] string
30
- }
31
+ },
31
32
  }
33
+
34
+ static function array(request: object, str: string): [ any ];
35
+
36
+ exception Err3 = {
37
+ accessErrMessage: string
38
+ }