Update RapydScript

This commit is contained in:
Kovid Goyal 2016-04-04 21:50:57 +05:30
parent 05c637cba7
commit 1f0143fe62
4 changed files with 17 additions and 17 deletions

Binary file not shown.

View File

@ -1,6 +1,6 @@
# vim:fileencoding=utf-8
# License: BSD Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
# globals: _$rapyd$_str
# globals: ρσ_str
def strings():
string_funcs = set((
@ -17,4 +17,4 @@ def strings():
if exclude:
string_funcs = string_funcs.difference(set(exclude))
for name in string_funcs:
String.prototype[name] = _$rapyd$_str.prototype[name]
String.prototype[name] = ρσ_str.prototype[name]

View File

@ -15,19 +15,19 @@
# please don't mess with this from the outside
_$rapyd$_seed_state = {
ρσ_seed_state = {
'key': [],
'key_i': 0,
'key_j': 0
}
_$rapyd$_get_random_byte = def():
_$rapyd$_seed_state.key_i = (_$rapyd$_seed_state.key_i + 1) % 256
_$rapyd$_seed_state.key_j = (_$rapyd$_seed_state.key_j + _$rapyd$_seed_state.key[_$rapyd$_seed_state.key_i]) % 256
_$rapyd$_seed_state.key[_$rapyd$_seed_state.key_i], _$rapyd$_seed_state.key[_$rapyd$_seed_state.key_j] = \
_$rapyd$_seed_state.key[_$rapyd$_seed_state.key_j], _$rapyd$_seed_state.key[_$rapyd$_seed_state.key_i]
return _$rapyd$_seed_state.key[(_$rapyd$_seed_state.key[_$rapyd$_seed_state.key_i] + \
_$rapyd$_seed_state.key[_$rapyd$_seed_state.key_j]) % 256]
ρσ_get_random_byte = def():
ρσ_seed_state.key_i = (ρσ_seed_state.key_i + 1) % 256
ρσ_seed_state.key_j = (ρσ_seed_state.key_j + ρσ_seed_state.key[ρσ_seed_state.key_i]) % 256
ρσ_seed_state.key[ρσ_seed_state.key_i], ρσ_seed_state.key[ρσ_seed_state.key_j] = \
ρσ_seed_state.key[ρσ_seed_state.key_j], ρσ_seed_state.key[ρσ_seed_state.key_i]
return ρσ_seed_state.key[(ρσ_seed_state.key[ρσ_seed_state.key_i] + \
ρσ_seed_state.key[ρσ_seed_state.key_j]) % 256]
def seed(x=Date().getTime()):
if type(x) is 'number':
@ -35,18 +35,18 @@ def seed(x=Date().getTime()):
elif type(x) is not 'string':
raise TypeError("unhashable type: '" + type(x) + "'")
for i in range(256):
_$rapyd$_seed_state.key[i] = i
ρσ_seed_state.key[i] = i
j = 0
for i in range(256):
j = (j + _$rapyd$_seed_state.key[i] + x.charCodeAt(i % x.length)) % 256
_$rapyd$_seed_state.key[i], _$rapyd$_seed_state.key[j] = _$rapyd$_seed_state.key[j], _$rapyd$_seed_state.key[i]
j = (j + ρσ_seed_state.key[i] + x.charCodeAt(i % x.length)) % 256
ρσ_seed_state.key[i], ρσ_seed_state.key[j] = ρσ_seed_state.key[j], ρσ_seed_state.key[i]
seed()
def random():
n = 0
m = 1
for i in range(8):
n += _$rapyd$_get_random_byte() * m
n += ρσ_get_random_byte() * m
m *= 256
return n / 18446744073709551616

View File

@ -3,7 +3,7 @@
# Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
# Copyright: 2013, Alexander Tsepkov
# globals: _$rapyd$_iterator_symbol, _$rapyd$_list_decorate
# globals: ρσ_iterator_symbol, ρσ_list_decorate
# basic implementation of Python's 're' library
@ -381,7 +381,7 @@ class RegexObject:
def findall(self, string):
self._pattern.lastIndex = 0
return _$rapyd$_list_decorate(string.match(self._pattern) or v'[]')
return ρσ_list_decorate(string.match(self._pattern) or v'[]')
def finditer(self, string):
pat = RegExp(this._pattern.source, this._modifiers) # We have to do this since lastIndex is mutable
@ -389,7 +389,7 @@ class RegexObject:
'_string':string,
'_r': pat,
'_self': self,
_$rapyd$_iterator_symbol: def (): return this;,
ρσ_iterator_symbol: def (): return this;,
'next': def ():
m = this._r.exec(this._string)
if m is None: