mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update RapydScript
This commit is contained in:
parent
05c637cba7
commit
1f0143fe62
Binary file not shown.
@ -1,6 +1,6 @@
|
|||||||
# vim:fileencoding=utf-8
|
# vim:fileencoding=utf-8
|
||||||
# License: BSD Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: BSD Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
# globals: _$rapyd$_str
|
# globals: ρσ_str
|
||||||
|
|
||||||
def strings():
|
def strings():
|
||||||
string_funcs = set((
|
string_funcs = set((
|
||||||
@ -17,4 +17,4 @@ def strings():
|
|||||||
if exclude:
|
if exclude:
|
||||||
string_funcs = string_funcs.difference(set(exclude))
|
string_funcs = string_funcs.difference(set(exclude))
|
||||||
for name in string_funcs:
|
for name in string_funcs:
|
||||||
String.prototype[name] = _$rapyd$_str.prototype[name]
|
String.prototype[name] = ρσ_str.prototype[name]
|
||||||
|
@ -15,19 +15,19 @@
|
|||||||
|
|
||||||
# please don't mess with this from the outside
|
# please don't mess with this from the outside
|
||||||
|
|
||||||
_$rapyd$_seed_state = {
|
ρσ_seed_state = {
|
||||||
'key': [],
|
'key': [],
|
||||||
'key_i': 0,
|
'key_i': 0,
|
||||||
'key_j': 0
|
'key_j': 0
|
||||||
}
|
}
|
||||||
|
|
||||||
_$rapyd$_get_random_byte = def():
|
ρσ_get_random_byte = def():
|
||||||
_$rapyd$_seed_state.key_i = (_$rapyd$_seed_state.key_i + 1) % 256
|
ρσ_seed_state.key_i = (ρσ_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
|
ρσ_seed_state.key_j = (ρσ_seed_state.key_j + ρσ_seed_state.key[ρσ_seed_state.key_i]) % 256
|
||||||
_$rapyd$_seed_state.key[_$rapyd$_seed_state.key_i], _$rapyd$_seed_state.key[_$rapyd$_seed_state.key_j] = \
|
ρσ_seed_state.key[ρσ_seed_state.key_i], ρσ_seed_state.key[ρσ_seed_state.key_j] = \
|
||||||
_$rapyd$_seed_state.key[_$rapyd$_seed_state.key_j], _$rapyd$_seed_state.key[_$rapyd$_seed_state.key_i]
|
ρσ_seed_state.key[ρσ_seed_state.key_j], ρσ_seed_state.key[ρσ_seed_state.key_i]
|
||||||
return _$rapyd$_seed_state.key[(_$rapyd$_seed_state.key[_$rapyd$_seed_state.key_i] + \
|
return ρσ_seed_state.key[(ρσ_seed_state.key[ρσ_seed_state.key_i] + \
|
||||||
_$rapyd$_seed_state.key[_$rapyd$_seed_state.key_j]) % 256]
|
ρσ_seed_state.key[ρσ_seed_state.key_j]) % 256]
|
||||||
|
|
||||||
def seed(x=Date().getTime()):
|
def seed(x=Date().getTime()):
|
||||||
if type(x) is 'number':
|
if type(x) is 'number':
|
||||||
@ -35,18 +35,18 @@ def seed(x=Date().getTime()):
|
|||||||
elif type(x) is not 'string':
|
elif type(x) is not 'string':
|
||||||
raise TypeError("unhashable type: '" + type(x) + "'")
|
raise TypeError("unhashable type: '" + type(x) + "'")
|
||||||
for i in range(256):
|
for i in range(256):
|
||||||
_$rapyd$_seed_state.key[i] = i
|
ρσ_seed_state.key[i] = i
|
||||||
j = 0
|
j = 0
|
||||||
for i in range(256):
|
for i in range(256):
|
||||||
j = (j + _$rapyd$_seed_state.key[i] + x.charCodeAt(i % x.length)) % 256
|
j = (j + ρσ_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]
|
ρσ_seed_state.key[i], ρσ_seed_state.key[j] = ρσ_seed_state.key[j], ρσ_seed_state.key[i]
|
||||||
seed()
|
seed()
|
||||||
|
|
||||||
def random():
|
def random():
|
||||||
n = 0
|
n = 0
|
||||||
m = 1
|
m = 1
|
||||||
for i in range(8):
|
for i in range(8):
|
||||||
n += _$rapyd$_get_random_byte() * m
|
n += ρσ_get_random_byte() * m
|
||||||
m *= 256
|
m *= 256
|
||||||
return n / 18446744073709551616
|
return n / 18446744073709551616
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
# Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
# Copyright: 2015, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
# Copyright: 2013, Alexander Tsepkov
|
# Copyright: 2013, Alexander Tsepkov
|
||||||
|
|
||||||
# globals: _$rapyd$_iterator_symbol, _$rapyd$_list_decorate
|
# globals: ρσ_iterator_symbol, ρσ_list_decorate
|
||||||
|
|
||||||
# basic implementation of Python's 're' library
|
# basic implementation of Python's 're' library
|
||||||
|
|
||||||
@ -381,7 +381,7 @@ class RegexObject:
|
|||||||
|
|
||||||
def findall(self, string):
|
def findall(self, string):
|
||||||
self._pattern.lastIndex = 0
|
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):
|
def finditer(self, string):
|
||||||
pat = RegExp(this._pattern.source, this._modifiers) # We have to do this since lastIndex is mutable
|
pat = RegExp(this._pattern.source, this._modifiers) # We have to do this since lastIndex is mutable
|
||||||
@ -389,7 +389,7 @@ class RegexObject:
|
|||||||
'_string':string,
|
'_string':string,
|
||||||
'_r': pat,
|
'_r': pat,
|
||||||
'_self': self,
|
'_self': self,
|
||||||
_$rapyd$_iterator_symbol: def (): return this;,
|
ρσ_iterator_symbol: def (): return this;,
|
||||||
'next': def ():
|
'next': def ():
|
||||||
m = this._r.exec(this._string)
|
m = this._r.exec(this._string)
|
||||||
if m is None:
|
if m is None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user