rapydscript-ng 0.8.3 → 0.8.4

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 (49) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/bin/build.ts +29 -0
  3. package/package.json +1 -1
  4. package/release/baselib-plain-pretty.js +85 -61
  5. package/release/baselib-plain-ugly.js +3 -3
  6. package/release/compiler.js +2543 -2432
  7. package/release/signatures.json +26 -26
  8. package/src/ast.pyj +170 -58
  9. package/src/baselib-builtins.pyj +35 -14
  10. package/src/baselib-containers.pyj +70 -40
  11. package/src/baselib-internal.pyj +20 -8
  12. package/src/baselib-itertools.pyj +6 -2
  13. package/src/baselib-str.pyj +74 -28
  14. package/src/errors.pyj +4 -1
  15. package/src/lib/aes.pyj +664 -35
  16. package/src/lib/elementmaker.pyj +105 -13
  17. package/src/lib/encodings.pyj +31 -7
  18. package/src/lib/gettext.pyj +6 -3
  19. package/src/lib/math.pyj +38 -22
  20. package/src/lib/pythonize.pyj +5 -3
  21. package/src/lib/random.pyj +13 -5
  22. package/src/lib/re.pyj +81 -18
  23. package/src/lib/traceback.pyj +42 -10
  24. package/src/lib/uuid.pyj +2 -1
  25. package/src/output/classes.pyj +70 -26
  26. package/src/output/codegen.pyj +92 -20
  27. package/src/output/comments.pyj +11 -4
  28. package/src/output/exceptions.pyj +17 -4
  29. package/src/output/functions.pyj +34 -13
  30. package/src/output/literals.pyj +7 -2
  31. package/src/output/loops.pyj +50 -16
  32. package/src/output/modules.pyj +41 -12
  33. package/src/output/operators.pyj +154 -31
  34. package/src/output/statements.pyj +38 -10
  35. package/src/output/stream.pyj +43 -12
  36. package/src/output/utils.pyj +10 -3
  37. package/src/parse.pyj +740 -259
  38. package/src/string_interpolation.pyj +4 -1
  39. package/src/tokenizer.pyj +300 -55
  40. package/src/unicode_aliases.pyj +4 -2
  41. package/src/utils.pyj +19 -5
  42. package/test/functions.pyj +8 -0
  43. package/test/generic.pyj +9 -0
  44. package/test/lsp.pyj +16 -0
  45. package/tools/compiler.mjs +0 -6
  46. package/tools/fmt.mjs +41 -2
  47. package/tools/lint-worker.mjs +7 -1
  48. package/tools/lint.mjs +12 -5
  49. package/tools/lsp.mjs +11 -1
@@ -2,7 +2,7 @@
2
2
  # License: BSD
3
3
  # Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
4
4
 
5
- # globals:ρσ_iterator_symbol, ρσ_kwargs_symbol, ρσ_arraylike, ρσ_repr
5
+ # globals: ρσ_iterator_symbol, ρσ_kwargs_symbol, ρσ_arraylike, ρσ_repr
6
6
 
7
7
 
8
8
  def ρσ_equals(a, b):
@@ -19,9 +19,12 @@ def ρσ_equals(a, b):
19
19
  if not (a[i] == b[i]):
20
20
  return False
21
21
  return True
22
- if jstype(a) is 'object' and jstype(b) is 'object' and a is not None and b is not None and (
23
- (a.constructor is Object and b.constructor is Object) or (Object.getPrototypeOf(a) is None and Object.getPrototypeOf(b) is None)
24
- ):
22
+ if (jstype(a) is 'object' and jstype(b) is 'object'
23
+ and a is not None and b is not None
24
+ and ((a.constructor is Object
25
+ and b.constructor is Object)
26
+ or (Object.getPrototypeOf(a) is None
27
+ and Object.getPrototypeOf(b) is None))):
25
28
  # Do a dict like comparison as this is most likely either a JS has
26
29
  # (Object.create(null) or a JS object used as a hash (v"{}"))
27
30
  akeys, bkeys = Object.keys(a), Object.keys(b)
@@ -71,14 +74,19 @@ def ρσ_list_constructor(iterable):
71
74
  for v'var i = 0; i < iterable.length; i++':
72
75
  ans[i] = iterable[i] # noqa:undef
73
76
  elif jstype(iterable[ρσ_iterator_symbol]) is 'function':
74
- iterator = iterable.keys() if jstype(Map) is 'function' and v'iterable instanceof Map' else iterable[ρσ_iterator_symbol]()
77
+ iterator = (
78
+ iterable.keys() if jstype(Map) is 'function'
79
+ and v'iterable instanceof Map'
80
+ else iterable[ρσ_iterator_symbol]()
81
+ )
75
82
  ans = []
76
83
  result = iterator.next()
77
84
  while not result.done:
78
85
  ans.push(result.value)
79
86
  result = iterator.next()
80
87
  elif jstype(iterable) is 'number':
81
- # non-pythonic optimization to allocate all needed memory in a single operation
88
+ # non-pythonic optimization to allocate all needed memory in a
89
+ # single operation
82
90
  ans = new Array(iterable)
83
91
  else:
84
92
  ans = Object.keys(iterable)
@@ -89,7 +97,7 @@ if v'typeof Array.prototype.append' is not 'function':
89
97
  Object.defineProperty(Array.prototype, 'append', {
90
98
  'writable': False, 'configurable': False, 'enumerable': False,
91
99
  'value': Array.prototype.push,
92
- });
100
+ })
93
101
  Object.defineProperty(Array.prototype, 'extend', {
94
102
  'writable': False, 'configurable': False, 'enumerable': False,
95
103
  'value': def (iterable):
@@ -100,12 +108,16 @@ if v'typeof Array.prototype.append' is not 'function':
100
108
  for v'var i = 0; i < iterable.length; i++':
101
109
  this[start + i] = iterable[i] # noqa:undef
102
110
  else:
103
- iterator = iterable.keys() if jstype(Map) is 'function' and v'iterable instanceof Map' else iterable[ρσ_iterator_symbol]()
111
+ iterator = (
112
+ iterable.keys() if jstype(Map) is 'function'
113
+ and v'iterable instanceof Map'
114
+ else iterable[ρσ_iterator_symbol]()
115
+ )
104
116
  result = iterator.next()
105
117
  while not result.done:
106
118
  this.push(result.value)
107
119
  result = iterator.next()
108
- });
120
+ })
109
121
  Object.defineProperty(Array.prototype, 'index', {
110
122
  'writable': False, 'configurable': False, 'enumerable': False,
111
123
  'value': def (val, start, stop):
@@ -122,7 +134,7 @@ if v'typeof Array.prototype.append' is not 'function':
122
134
  if this[i] == val:
123
135
  return i # noqa:undef
124
136
  raise ValueError(val + ' is not in list')
125
- });
137
+ })
126
138
  Object.defineProperty(Array.prototype, 'pypop', {
127
139
  'writable': False, 'configurable': False, 'enumerable': False,
128
140
  'value': def (index):
@@ -134,7 +146,7 @@ if v'typeof Array.prototype.append' is not 'function':
134
146
  if not ans.length:
135
147
  raise IndexError('pop index out of range')
136
148
  return ans[0]
137
- });
149
+ })
138
150
  Object.defineProperty(Array.prototype, 'remove', {
139
151
  'writable': False, 'configurable': False, 'enumerable': False,
140
152
  'value': def (value):
@@ -143,15 +155,15 @@ if v'typeof Array.prototype.append' is not 'function':
143
155
  this.splice(i, 1)
144
156
  return
145
157
  raise ValueError(value + ' not in list')
146
- });
158
+ })
147
159
  Object.defineProperty(Array.prototype, 'toString', {
148
160
  'writable': False, 'configurable': False, 'enumerable': False,
149
161
  'value': def (): return '[' + this.join(', ') + ']'
150
- });
162
+ })
151
163
  Object.defineProperty(Array.prototype, 'inspect', {
152
164
  'writable': False, 'configurable': False, 'enumerable': False,
153
165
  'value': def (): return '[' + this.join(', ') + ']'
154
- });
166
+ })
155
167
  Object.defineProperty(Array.prototype, 'insert', {
156
168
  'writable': False, 'configurable': False, 'enumerable': False,
157
169
  'value': def (index, val):
@@ -164,28 +176,30 @@ if v'typeof Array.prototype.append' is not 'function':
164
176
  for v'var i = this.length; i > index; i--':
165
177
  this[i] = this[i - 1] # noqa:undef
166
178
  this[index] = val
167
- });
179
+ })
168
180
  Object.defineProperty(Array.prototype, 'copy', {
169
181
  'writable': False, 'configurable': False, 'enumerable': False,
170
182
  'value': def (): return ρσ_list_constructor(this)
171
- });
183
+ })
172
184
  Object.defineProperty(Array.prototype, 'clear', {
173
185
  'writable': False, 'configurable': False, 'enumerable': False,
174
186
  'value': def (): this.length = 0
175
- });
187
+ })
176
188
  Object.defineProperty(Array.prototype, 'count', {
177
189
  'writable': False, 'configurable': False, 'enumerable': False,
178
- 'value': def (value): return this.reduce(def (n, val): return n + (val is value);, 0)
179
- });
190
+ 'value': def (value):
191
+ return this.reduce(
192
+ def (n, val): return n + (val is value);, 0)
193
+ })
180
194
  Object.defineProperty(Array.prototype, 'pysort', {
181
195
  'writable': False, 'configurable': False, 'enumerable': False,
182
196
  'value': def (key = None, reverse = False):
183
- def _sort_key(value):
197
+ _sort_key = def (value):
184
198
  t = jstype(value)
185
199
  if t is 'string' or t is 'number':
186
200
  return value
187
201
  return value.toString()
188
- def _sort_cmp(a, b, ap, bp):
202
+ _sort_cmp = def (a, b, ap, bp):
189
203
  if a < b:
190
204
  return -1
191
205
  if a > b:
@@ -196,19 +210,21 @@ if v'typeof Array.prototype.append' is not 'function':
196
210
  keymap = dict()
197
211
  posmap = dict()
198
212
  for v'var i=0; i < this.length; i++':
199
- k = this[i] # noqa:undef
213
+ k = this[i]
200
214
  keymap.set(k, key(k))
201
215
  posmap.set(k, i)
202
- this.sort(def (a, b): return mult * _sort_cmp(keymap.get(a), keymap.get(b), posmap.get(a), posmap.get(b));)
203
- });
216
+ this.sort(def (a, b): return mult * _sort_cmp(
217
+ keymap.get(a), keymap.get(b),
218
+ posmap.get(a), posmap.get(b));)
219
+ })
204
220
  Object.defineProperty(Array.prototype, 'as_array', {
205
221
  'writable': False, 'configurable': False, 'enumerable': False,
206
222
  'value': def (): return Array.from (this)
207
- });
223
+ })
208
224
  Object.defineProperty(Array.prototype, '__len__', {
209
225
  'writable': False, 'configurable': False, 'enumerable': False,
210
226
  'value': def (): return this.length
211
- });
227
+ })
212
228
  Object.defineProperty(Array.prototype, '__contains__', {
213
229
  'writable': False, 'configurable': False, 'enumerable': False,
214
230
  'value': def (val):
@@ -216,7 +232,7 @@ if v'typeof Array.prototype.append' is not 'function':
216
232
  if this[i] == val:
217
233
  return True
218
234
  return False
219
- });
235
+ })
220
236
  Object.defineProperty(Array.prototype, '__eq__', {
221
237
  'writable': False, 'configurable': False, 'enumerable': False,
222
238
  'value': def (other):
@@ -228,11 +244,11 @@ if v'typeof Array.prototype.append' is not 'function':
228
244
  if not (this[i] == other[i]):
229
245
  return False
230
246
  return True
231
- });
247
+ })
232
248
  Object.defineProperty(Array.prototype, 'constructor', {
233
249
  'writable': False, 'configurable': False, 'enumerable': False,
234
250
  'value': ρσ_list_constructor,
235
- });
251
+ })
236
252
 
237
253
 
238
254
  def ρσ_list_decorate(ans):
@@ -301,7 +317,8 @@ def ρσ_set_polyfill():
301
317
  return v"{'done':false, 'value':this._s[this._keys[this._i]]}"
302
318
  return ans
303
319
 
304
- if jstype(Set) is not 'function' or jstype(Set.prototype.delete) is not 'function':
320
+ if (jstype(Set) is not 'function'
321
+ or jstype(Set.prototype.delete) is not 'function'):
305
322
  v'ρσ_set_implementation = ρσ_set_polyfill'
306
323
  else:
307
324
  v'ρσ_set_implementation = Set'
@@ -318,7 +335,11 @@ def ρσ_set(iterable):
318
335
  for v'var i = 0; i < iterable.length; i++':
319
336
  s.add(iterable[i])
320
337
  elif jstype(iterable[ρσ_iterator_symbol]) is 'function':
321
- iterator = iterable.keys() if jstype(Map) is 'function' and v'iterable instanceof Map' else iterable[ρσ_iterator_symbol]()
338
+ iterator = (
339
+ iterable.keys() if jstype(Map) is 'function'
340
+ and v'iterable instanceof Map'
341
+ else iterable[ρσ_iterator_symbol]()
342
+ )
322
343
  result = iterator.next()
323
344
  while not result.done:
324
345
  s.add(result.value)
@@ -339,7 +360,8 @@ Object.defineProperties(ρσ_set.prototype, {
339
360
  })
340
361
 
341
362
  ρσ_set.prototype.__len__ = def (): return this.jsset.size
342
- ρσ_set.prototype.has = ρσ_set.prototype.__contains__ = def (x): return this.jsset.has(x)
363
+ ρσ_set.prototype.has = ρσ_set.prototype.__contains__ = def (x):
364
+ return this.jsset.has(x)
343
365
  ρσ_set.prototype.add = def (x): this.jsset.add(x)
344
366
  ρσ_set.prototype.clear = def (): this.jsset.clear()
345
367
  ρσ_set.prototype.copy = def (): return ρσ_set(this)
@@ -475,7 +497,8 @@ Object.defineProperties(ρσ_set.prototype, {
475
497
  s.add(r.value)
476
498
  r = iterator.next()
477
499
 
478
- ρσ_set.prototype.toString = ρσ_set.prototype.__repr__ = ρσ_set.prototype.__str__ = ρσ_set.prototype.inspect = def ():
500
+ ρσ_set.prototype.toString = ρσ_set.prototype.__repr__ \
501
+ = ρσ_set.prototype.__str__ = ρσ_set.prototype.inspect = def ():
479
502
  return '{' + list(this).join(', ') + '}'
480
503
 
481
504
  ρσ_set.prototype.__eq__ = def (other):
@@ -571,7 +594,8 @@ def ρσ_dict_polyfill():
571
594
  return v"{'done':false, 'value':this._s[this._keys[this._i]]}"
572
595
  return ans
573
596
 
574
- if jstype(Map) is not 'function' or jstype(Map.prototype.delete) is not 'function':
597
+ if (jstype(Map) is not 'function'
598
+ or jstype(Map.prototype.delete) is not 'function'):
575
599
  v'ρσ_dict_implementation = ρσ_dict_polyfill'
576
600
  else:
577
601
  v'ρσ_dict_implementation = Map'
@@ -596,14 +620,17 @@ Object.defineProperties(ρσ_dict.prototype, {
596
620
  })
597
621
 
598
622
  ρσ_dict.prototype.__len__ = def (): return this.jsmap.size
599
- ρσ_dict.prototype.has = ρσ_dict.prototype.__contains__ = def (x): return this.jsmap.has(x)
600
- ρσ_dict.prototype.set = ρσ_dict.prototype.__setitem__ = def (key, value): this.jsmap.set(key, value)
623
+ ρσ_dict.prototype.has = ρσ_dict.prototype.__contains__ = def (x):
624
+ return this.jsmap.has(x)
625
+ ρσ_dict.prototype.set = ρσ_dict.prototype.__setitem__ = def (key, value):
626
+ this.jsmap.set(key, value)
601
627
  ρσ_dict.prototype.__delitem__ = def (key): this.jsmap.delete(key)
602
628
  ρσ_dict.prototype.clear = def (): this.jsmap.clear()
603
629
  ρσ_dict.prototype.copy = def (): return ρσ_dict(this)
604
630
  ρσ_dict.prototype.keys = def (): return this.jsmap.keys()
605
631
  ρσ_dict.prototype.values = def (): return this.jsmap.values()
606
- ρσ_dict.prototype.items = ρσ_dict.prototype.entries = def (): return this.jsmap.entries()
632
+ ρσ_dict.prototype.items = ρσ_dict.prototype.entries = def ():
633
+ return this.jsmap.entries()
607
634
  ρσ_dict.prototype[ρσ_iterator_symbol] = def (): return this.jsmap.keys()
608
635
 
609
636
  ρσ_dict.prototype.__getitem__ = def (key):
@@ -618,7 +645,8 @@ Object.defineProperties(ρσ_dict.prototype, {
618
645
  return None if defval is undefined else defval
619
646
  return ans
620
647
 
621
- ρσ_dict.prototype.set_default = ρσ_dict.prototype.setdefault = def (key, defval):
648
+ ρσ_dict.prototype.set_default = ρσ_dict.prototype.setdefault \
649
+ = def (key, defval):
622
650
  j = this.jsmap
623
651
  if not j.has(key):
624
652
  j.set(key, defval)
@@ -689,7 +717,8 @@ Object.defineProperties(ρσ_dict.prototype, {
689
717
  if arguments.length > 1:
690
718
  ρσ_dict.prototype.update.call(this, arguments[1])
691
719
 
692
- ρσ_dict.prototype.toString = ρσ_dict.prototype.inspect = ρσ_dict.prototype.__str__ = ρσ_dict.prototype.__repr__ = def ():
720
+ ρσ_dict.prototype.toString = ρσ_dict.prototype.inspect \
721
+ = ρσ_dict.prototype.__str__ = ρσ_dict.prototype.__repr__ = def ():
693
722
  entries = v'[]'
694
723
  iterator = this.jsmap.entries()
695
724
  r = iterator.next()
@@ -709,7 +738,8 @@ Object.defineProperties(ρσ_dict.prototype, {
709
738
  r = iterator.next()
710
739
  while not r.done:
711
740
  x = this.jsmap.get(r.value[0])
712
- if (x is undefined and not this.jsmap.has(r.value[0])) or x is not r.value[1]:
741
+ if ((x is undefined and not this.jsmap.has(r.value[0]))
742
+ or x is not r.value[1]):
713
743
  return False
714
744
  r = iterator.next()
715
745
  return True
@@ -1,7 +1,8 @@
1
1
  # vim:fileencoding=utf-8
2
2
  # License: BSD
3
3
 
4
- # globals: exports, console, ρσ_iterator_symbol, ρσ_kwargs_symbol, ρσ_arraylike, ρσ_list_constructor, ρσ_str, ρσ_int, ρσ_float
4
+ # globals: exports, console, ρσ_iterator_symbol, ρσ_kwargs_symbol,
5
+ # globals: ρσ_arraylike, ρσ_list_constructor, ρσ_str, ρσ_int, ρσ_float
5
6
 
6
7
 
7
8
  def ρσ_eslice(arr, step, start, end):
@@ -65,7 +66,9 @@ def ρσ_unpack_asarray(num, iterable):
65
66
  return iterable
66
67
  ans = v'[]'
67
68
  if jstype(iterable[ρσ_iterator_symbol]) is 'function':
68
- iterator = iterable.keys() if jstype(Map) is 'function' and v'iterable instanceof Map' else iterable[ρσ_iterator_symbol]()
69
+ iterator = iterable.keys() \
70
+ if jstype(Map) is 'function' and v'iterable instanceof Map' \
71
+ else iterable[ρσ_iterator_symbol]()
69
72
  result = iterator.next()
70
73
  while not result.done and ans.length < num:
71
74
  ans.push(result.value)
@@ -106,14 +109,17 @@ def ρσ_Iterable(iterable):
106
109
  if ρσ_arraylike(iterable):
107
110
  return iterable
108
111
  if jstype(iterable[ρσ_iterator_symbol]) is 'function':
109
- iterator = iterable.keys() if jstype(Map) is 'function' and v'iterable instanceof Map' else iterable[ρσ_iterator_symbol]()
112
+ iterator = iterable.keys() \
113
+ if jstype(Map) is 'function' and v'iterable instanceof Map' \
114
+ else iterable[ρσ_iterator_symbol]()
110
115
  ans = []
111
116
  result = iterator.next()
112
117
  while not result.done:
113
118
  ans.push(result.value)
114
119
  result = iterator.next()
115
120
  return ans
116
- # so we can use 'for ... in' syntax with objects, as we would with dicts in python
121
+ # so we can use 'for ... in' syntax with objects, as we would
122
+ # with dicts in python
117
123
  return Object.keys(iterable)
118
124
 
119
125
  ρσ_desugar_kwargs = (def ():
@@ -228,7 +234,8 @@ def ρσ_splice(arr, val, start, end):
228
234
  return def ():
229
235
  return undefined
230
236
  , 'g': def (expr):
231
- if expr is undefined or expr is None or jstype(expr.__getitem__) is not 'function':
237
+ if (expr is undefined or expr is None or
238
+ jstype(expr.__getitem__) is not 'function'):
232
239
  return {'__getitem__': def (): return undefined;}
233
240
  , 'e': def (expr, alt):
234
241
  return alt if expr is undefined or expr is None else expr
@@ -242,7 +249,10 @@ def ρσ_mixin():
242
249
  # inheritance.
243
250
  seen = Object.create(None)
244
251
  # Ensure the following special properties are never copied
245
- seen.__argnames__ = seen.__handles_kwarg_interpolation__ = seen.__init__ = seen.__annotations__ = seen.__doc__ = seen.__bind_methods__ = seen.__bases__ = seen.constructor = seen.__class__ = True
252
+ seen.__argnames__ = seen.__handles_kwarg_interpolation__ = \
253
+ seen.__init__ = seen.__annotations__ = seen.__doc__ = \
254
+ seen.__bind_methods__ = seen.__bases__ = \
255
+ seen.constructor = seen.__class__ = True
246
256
  resolved_props = {}
247
257
  p = target = arguments[0].prototype
248
258
  while p and p is not Object.prototype:
@@ -275,11 +285,13 @@ def ρσ_instanceof():
275
285
  return True
276
286
  if (q is Array or q is ρσ_list_constructor) and Array.isArray(obj):
277
287
  return True
278
- if q is ρσ_str and (jstype(obj) is 'string' or v'obj instanceof String'):
288
+ if q is ρσ_str and (
289
+ jstype(obj) is 'string' or v'obj instanceof String'):
279
290
  return True
280
291
  if q is ρσ_int and (jstype(obj) is 'number' and Number.isInteger(obj)):
281
292
  return True
282
- if q is ρσ_float and (jstype(obj) is 'number' and not Number.isInteger(obj)):
293
+ if q is ρσ_float and (
294
+ jstype(obj) is 'number' and not Number.isInteger(obj)):
283
295
  return True
284
296
  if bases.length > 1:
285
297
  for v'var c = 1; c < bases.length; c++':
@@ -36,12 +36,16 @@ def map():
36
36
  if r.done:
37
37
  return v"{'done':true}"
38
38
  this._args[i] = r.value # noqa:undef
39
- return v"{'done':false, 'value':this._func.apply(undefined, this._args)}"
39
+ return (
40
+ v"{'done':false, 'value':this._func.apply(undefined, this._args)}"
41
+ )
40
42
  return ans
41
43
 
42
44
 
43
45
  def filter(func_or_none, iterable):
44
- func = ρσ_bool if func_or_none is None else func_or_none # noqa: unused-local
46
+ func = ( # noqa: unused-local
47
+ ρσ_bool if func_or_none is None else func_or_none
48
+ )
45
49
  ans = v"{'_func':func, '_iterator':ρσ_iter(iterable)}"
46
50
  ans[ρσ_iterator_symbol] = def ():
47
51
  return this
@@ -61,9 +61,13 @@ def ρσ_repr(x):
61
61
  ans = ρσ_repr_js_builtin(x)
62
62
  else:
63
63
  name = Object.prototype.toString.call(x).slice(8, -1)
64
- if 'Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array'.indexOf(name) != -1:
65
- return name + '([' + x.map(def (i): return str.format('0x{:02x}', i);).join(', ') + '])'
66
- if jstype(HTMLElement) is not 'undefined' and v'x instanceof HTMLElement':
64
+ if ('Int8Array Uint8Array Uint8ClampedArray Int16Array'
65
+ + ' Uint16Array Int32Array Uint32Array'
66
+ + ' Float32Array Float64Array').indexOf(name) != -1:
67
+ mapped = x.map(def (i): return str.format('0x{:02x}', i);)
68
+ return name + '([' + mapped.join(', ') + '])'
69
+ if (jstype(HTMLElement) is not 'undefined' and
70
+ v'x instanceof HTMLElement'):
67
71
  ans = ρσ_html_element_to_string(x)
68
72
  else:
69
73
  ans = x.toString() if v'typeof x.toString === "function"' else x
@@ -74,7 +78,9 @@ def ρσ_repr(x):
74
78
  ans = JSON.stringify(x)
75
79
  except:
76
80
  pass
77
- return ans + '' # Ensures we return an object of type string (i.e. primitive value) rather than a String object
81
+ # Ensures we return an object of type string (i.e. primitive value)
82
+ # rather than a String object
83
+ return ans + ''
78
84
 
79
85
 
80
86
  def ρσ_str(x):
@@ -93,9 +99,13 @@ def ρσ_str(x):
93
99
  ans = ρσ_repr_js_builtin(x, True)
94
100
  elif v'typeof x.toString === "function"':
95
101
  name = Object.prototype.toString.call(x).slice(8, -1)
96
- if 'Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array'.indexOf(name) != -1:
97
- return name + '([' + x.map(def (i): return str.format('0x{:02x}', i);).join(', ') + '])'
98
- if jstype(HTMLElement) is not 'undefined' and v'x instanceof HTMLElement':
102
+ if ('Int8Array Uint8Array Uint8ClampedArray Int16Array'
103
+ + ' Uint16Array Int32Array Uint32Array'
104
+ + ' Float32Array Float64Array').indexOf(name) != -1:
105
+ mapped = x.map(def (i): return str.format('0x{:02x}', i);)
106
+ return name + '([' + mapped.join(', ') + '])'
107
+ if (jstype(HTMLElement) is not 'undefined' and
108
+ v'x instanceof HTMLElement'):
99
109
  ans = ρσ_html_element_to_string(x)
100
110
  else:
101
111
  ans = x.toString()
@@ -105,15 +115,22 @@ def ρσ_str(x):
105
115
  elif jstype(x) is 'object' and not x.toString:
106
116
  # Assume this is a dictionary
107
117
  ans = ρσ_repr_js_builtin(x)
108
- return ans + '' # Ensures we return an object of type string (i.e. primitive value) rather than a String object
118
+ # Ensures we return an object of type string (i.e. primitive value)
119
+ # rather than a String object
120
+ return ans + ''
109
121
 
110
122
  define_str_func = def (name, func):
111
123
  ρσ_str.prototype[name] = func
112
124
  ρσ_str[name] = f = func.call.bind(func)
113
125
  if func.__argnames__:
114
- Object.defineProperty(f, '__argnames__', {'value': v"['string']".concat(func.__argnames__)})
126
+ Object.defineProperty(
127
+ f,
128
+ '__argnames__',
129
+ {'value': v"['string']".concat(func.__argnames__)}
130
+ )
115
131
 
116
- ρσ_orig_split, ρσ_orig_replace = String.prototype.split.call.bind(String.prototype.split), String.prototype.replace.call.bind(String.prototype.replace)
132
+ ρσ_orig_split = String.prototype.split.call.bind(String.prototype.split)
133
+ ρσ_orig_replace = String.prototype.replace.call.bind(String.prototype.replace)
117
134
 
118
135
  # format() {{{
119
136
  define_str_func('format', def ():
@@ -143,7 +160,8 @@ define_str_func('format', def ():
143
160
  def resolve_format_spec(format_spec):
144
161
  if ρσ_str.format._template_resolve_fs_pat is undefined:
145
162
  ρσ_str.format._template_resolve_fs_pat = /[{]([a-zA-Z0-9_]+)[}]/g
146
- return format_spec.replace(ρσ_str.format._template_resolve_fs_pat, def (match, key):
163
+ pat = ρσ_str.format._template_resolve_fs_pat
164
+ return format_spec.replace(pat, def (match, key):
147
165
  if not Object.prototype.hasOwnProperty.call(kwargs, key):
148
166
  return ''
149
167
  return '' + kwargs[key]
@@ -156,14 +174,19 @@ define_str_func('format', def ():
156
174
  return ans
157
175
  def safe_comma(value, comma):
158
176
  try:
159
- return set_comma(value.toLocaleString(undefined, v'{useGrouping: true}'), comma)
177
+ return set_comma(
178
+ value.toLocaleString(undefined, v'{useGrouping: true}'),
179
+ comma)
160
180
  except:
161
181
  return value.toString(10)
162
182
  def safe_fixed(value, precision, comma):
163
183
  if not comma:
164
184
  return value.toFixed(precision)
165
185
  try:
166
- return set_comma(value.toLocaleString(undefined, v'{useGrouping: true, minimumFractionDigits: precision, maximumFractionDigits: precision}'), comma)
186
+ ufmt = {'useGrouping': True,
187
+ 'minimumFractionDigits': precision,
188
+ 'maximumFractionDigits': precision}
189
+ return set_comma(value.toLocaleString(undefined, ufmt), comma)
167
190
  except:
168
191
  return value.toFixed(precision)
169
192
  def apply_formatting(value, format_spec):
@@ -181,7 +204,9 @@ define_str_func('format', def ():
181
204
  ([bcdeEfFgGnosxX%])? # type
182
205
  ///
183
206
  try:
184
- fill, align, sign, fhash, zeropad, width, comma, precision, ftype = format_spec.match(ρσ_str.format._template_format_pat)[1:]
207
+ m = format_spec.match(ρσ_str.format._template_format_pat)
208
+ fill, align, sign, fhash, zeropad = m[1], m[2], m[3], m[4], m[5]
209
+ width, comma, precision, ftype = m[6], m[7], m[8], m[9]
185
210
  except TypeError:
186
211
  return value
187
212
  if zeropad:
@@ -213,7 +238,9 @@ define_str_func('format', def ():
213
238
  elif ftype is 'c':
214
239
  if value > 0xFFFF:
215
240
  code = value - 0x10000
216
- value = String.fromCharCode(0xD800 + (code >> 10), 0xDC00 + (code & 0x3FF))
241
+ value = String.fromCharCode(
242
+ 0xD800 + (code >> 10),
243
+ 0xDC00 + (code & 0x3FF))
217
244
  else:
218
245
  value = String.fromCharCode(value)
219
246
  elif ftype is 'd':
@@ -227,7 +254,8 @@ define_str_func('format', def ():
227
254
  value = '0o' + value
228
255
  elif lftype is 'x':
229
256
  value = value.toString(16)
230
- value = value.toLowerCase() if ftype is 'x' else value.toUpperCase()
257
+ value = (value.toLowerCase() if ftype is 'x'
258
+ else value.toUpperCase())
231
259
  if fhash:
232
260
  value = '0x' + value
233
261
  elif v"['e','f','g','%']".indexOf(lftype) is not -1:
@@ -236,16 +264,20 @@ define_str_func('format', def ():
236
264
  prec = 6 if isNaN(precision) else precision
237
265
  if lftype is 'e':
238
266
  value = value.toExponential(prec)
239
- value = value.toUpperCase() if ftype is 'E' else value.toLowerCase()
267
+ value = (value.toUpperCase() if ftype is 'E'
268
+ else value.toLowerCase())
240
269
  elif lftype is 'f':
241
270
  value = safe_fixed(value, prec, comma)
242
- value = value.toUpperCase() if ftype is 'F' else value.toLowerCase()
271
+ value = (value.toUpperCase() if ftype is 'F'
272
+ else value.toLowerCase())
243
273
  elif lftype is '%':
244
274
  value *= 100
245
275
  value = safe_fixed(value, prec, comma) + '%'
246
276
  elif lftype is 'g':
247
277
  prec = max(1, prec)
248
- exp = parseInt(split(value.toExponential(prec - 1).toLowerCase(), 'e')[1], 10)
278
+ exp = parseInt(
279
+ split(value.toExponential(prec - 1).toLowerCase(),
280
+ 'e')[1], 10)
249
281
  if -4 <= exp < prec:
250
282
  value = safe_fixed(value, prec - 1 - exp, comma)
251
283
  else:
@@ -289,7 +321,9 @@ define_str_func('format', def ():
289
321
  value = repeat(fill, left) + value + repeat(fill, right)
290
322
  elif align is '=':
291
323
  if value[0] in '+- ':
292
- value = value[0] + repeat(fill, width - value.length) + value[1:]
324
+ value = (value[0] +
325
+ repeat(fill, width - value.length) +
326
+ value[1:])
293
327
  else:
294
328
  value = repeat(fill, width - value.length) + value
295
329
  else:
@@ -329,7 +363,9 @@ define_str_func('format', def ():
329
363
  if lkey:
330
364
  explicit = True
331
365
  if implicit:
332
- raise ValueError('cannot switch from automatic field numbering to manual field specification')
366
+ raise ValueError(
367
+ 'cannot switch from automatic field numbering'
368
+ + ' to manual field specification')
333
369
  nvalue = parseInt(lkey)
334
370
  object = kwargs[lkey] if isNaN(nvalue) else args[nvalue]
335
371
  if object is undefined:
@@ -340,9 +376,12 @@ define_str_func('format', def ():
340
376
  else:
341
377
  implicit = True
342
378
  if explicit:
343
- raise ValueError('cannot switch from manual field specification to automatic field numbering')
379
+ raise ValueError(
380
+ 'cannot switch from manual field specification'
381
+ + ' to automatic field numbering')
344
382
  if idx >= args.length:
345
- raise IndexError('Not enough arguments to match template: ' + template)
383
+ raise IndexError(
384
+ 'Not enough arguments to match template: ' + template)
346
385
  object = args[idx]
347
386
  idx += 1
348
387
  if jstype(object) is 'function':
@@ -401,7 +440,9 @@ define_str_func('center', def (width, fill):
401
440
  left = (width - this.length) // 2
402
441
  right = width - left - this.length # noqa:unused-local
403
442
  fill = fill or ' '
404
- return v'new Array(left+1).join(fill)' + this + v'new Array(right+1).join(fill)'
443
+ left_pad = v'new Array(left+1).join(fill)'
444
+ right_pad = v'new Array(right+1).join(fill)'
445
+ return left_pad + this + right_pad
405
446
  )
406
447
 
407
448
  define_str_func('count', def (needle, start, end):
@@ -433,7 +474,8 @@ define_str_func('endswith', def (suffixes, start, end):
433
474
  string = string[:end]
434
475
  for v'var i = 0; i < suffixes.length; i++':
435
476
  q = suffixes[i] # noqa:undef
436
- if string.indexOf(q, Math.max(start, string.length - q.length)) is not -1:
477
+ if (string.indexOf(q, Math.max(start, string.length - q.length))
478
+ is not -1):
437
479
  return True
438
480
  return False
439
481
  )
@@ -445,7 +487,8 @@ define_str_func('startswith', def (prefixes, start, end):
445
487
  for v'var i = 0; i < prefixes.length; i++':
446
488
  prefix = prefixes[i] # noqa:undef
447
489
  end = this.length if end is undefined else end
448
- if end - start >= prefix.length and prefix is this[start:start + prefix.length]:
490
+ if (end - start >= prefix.length and
491
+ prefix is this[start:start + prefix.length]):
449
492
  return True
450
493
  return False
451
494
  )
@@ -560,7 +603,8 @@ define_str_func('rstrip', def (chars):
560
603
  )
561
604
 
562
605
  define_str_func('strip', def (chars):
563
- return ρσ_str.prototype.lstrip.call(ρσ_str.prototype.rstrip.call(this, chars), chars)
606
+ return ρσ_str.prototype.lstrip.call(
607
+ ρσ_str.prototype.rstrip.call(this, chars), chars)
564
608
  )
565
609
 
566
610
  define_str_func('partition', def (sep):
@@ -755,7 +799,9 @@ define_str_func('zfill', def (width):
755
799
  ρσ_str.ascii_letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
756
800
  ρσ_str.digits = '0123456789'
757
801
  ρσ_str.punctuation = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
758
- ρσ_str.printable = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'
802
+ ρσ_str.printable = ('0123456789abcdefghijklmnopqrstuvwxyz'
803
+ + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
804
+ + '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c')
759
805
  ρσ_str.whitespace = ' \t\n\r\x0b\x0c'
760
806
 
761
807
  v'define_str_func = undefined'
package/src/errors.pyj CHANGED
@@ -17,7 +17,10 @@ class SyntaxError(Error):
17
17
  self.fileName = filename
18
18
 
19
19
  def toString(self):
20
- ans = self.message + ' (line: ' + self.line + ', col: ' + self.col + ', pos: ' + self.pos + ')'
20
+ ans = (
21
+ self.message + ' (line: ' + self.line + ', col: ' +
22
+ self.col + ', pos: ' + self.pos + ')'
23
+ )
21
24
  if self.filename:
22
25
  ans = self.filename + ':' + ans
23
26
  if self.stack: