예제 #1
0
 def _freeze_(self):
     # don't capture the environment in the translated pypy
     self.space.call_method(self.w_environ, 'clear')
     # also reset random_context to a fresh new context (empty so far,
     # to be filled at run-time by rurandom.urandom())
     self.random_context = rurandom.init_urandom()
     return True
예제 #2
0
 def _freeze_(self):
     # don't capture the environment in the translated pypy
     self.space.call_method(self.w_environ, 'clear')
     # also reset random_context to a fresh new context (empty so far,
     # to be filled at run-time by rurandom.urandom())
     self.random_context = rurandom.init_urandom()
     return True
예제 #3
0
def test_rurandom():
    context = rurandom.init_urandom()
    s = rurandom.urandom(context, 5000)
    assert type(s) is str and len(s) == 5000
    for x in [1, 11, 111, 222]:
        assert s.count(chr(x)) >= 1
예제 #4
0
class Seed:
    k0l = k1l = r_uint64(0)


seed = Seed()


def select_random_seed(s):
    """'s' is a string of length 16"""
    seed.k0l = _decode64(s)
    seed.k1l = _decode64(s[8:16])
    _update_prebuilt_hashes()


random_ctx = rurandom.init_urandom()
strtoul = rffi.llexternal("strtoul", [rffi.CCHARP, rffi.CCHARPP, rffi.INT],
                          rffi.ULONG,
                          save_err=rffi.RFFI_SAVE_ERRNO)

env_var_name = "PYTHONHASHSEED"


def initialize_from_env():
    # This uses the same algorithms as CPython 3.5.  The environment
    # variable we read also defaults to "PYTHONHASHSEED".  If needed,
    # a different RPython interpreter can patch the value of the
    # global variable 'env_var_name', or just patch the whole
    # initialize_from_env() function.
    value = os.environ.get(env_var_name)
    if value and value != "random":
예제 #5
0
 def __init__(self, space):
     self.space = space
     self.w_environ = space.newdict()
     self.random_context = rurandom.init_urandom()
예제 #6
0
 def __init__(self, space):
     self.space = space
     self.w_environ = space.newdict()
     self.random_context = rurandom.init_urandom()
예제 #7
0
def test_rurandom():
    context = rurandom.init_urandom()
    s = rurandom.urandom(context, 5000)
    assert type(s) is str and len(s) == 5000
    for x in [1, 11, 111, 222]:
        assert s.count(chr(x)) >= 1