Debian Codegraph @

pypy/module/sys/state.py

raw symbols SCIP
1 """
2 Implementation of interpreter-level 'sys' routines.
3 """
4 import os
5 from pypy import pypydir
6 from pypy.interpreter.error import oefmt
7 from pypy.interpreter.gateway import unwrap_spec
8 from pypy.module.sys.system import DEFAULT_MAX_STR_DIGITS
9
10 # ____________________________________________________________
11 #
12
13 class State:
14 def __init__(self, space):
15 self.space = space
16
17 self.w_modules = space.newdict(module=True)
18 self.w_warnoptions = space.newlist([])
19 self.w_argv = space.newlist([])
20 self.w_orig_argv = space.newlist([])
21 self.w_int_max_str_digits = space.newint(DEFAULT_MAX_STR_DIGITS)
22
23 self.setinitialpath(space)
24
25 def setinitialpath(self, space):
26 from pypy.module.sys.initpath import compute_stdlib_path_sourcetree
27 # This initial value for sys.prefix is normally overwritten
28 # at runtime by initpath.py
29 srcdir = os.path.dirname(pypydir)
30 self.w_initial_prefix = space.newtext(srcdir)
31 # Initialize the default path
32 path = compute_stdlib_path_sourcetree(self, space.config.objspace.platlibdir, srcdir)
33 self.w_path = space.newlist([space.newfilename(p) for p in path])
34
35 def get(space):
36 return space.fromcache(State)
37
38 def pypy_getudir(space):
39 """NOT_RPYTHON
40 (should be removed from interpleveldefs before translation)"""
41 from rpython.tool.udir import udir
42 return space.newfilename(str(udir))
43
44 @unwrap_spec(maxdigits=int)
45 def set_int_max_str_digits(space, maxdigits):
46 """Set the maximum string digits limit for non-binary int<->str conversions
47 """
48 from pypy.module.sys.system import MAX_STR_DIGITS_THRESHOLD
49
50 state = get(space)
51 if maxdigits == 0 or maxdigits >= MAX_STR_DIGITS_THRESHOLD:
52 state.w_int_max_str_digits = space.newint(maxdigits)
53 return
54 raise oefmt(space.w_ValueError,
55 "maxdigits %d must be 0 or larger than %d",
56 maxdigits, MAX_STR_DIGITS_THRESHOLD)
57
58 def get_int_max_str_digits(space):
59 state = get(space)
60 return state.w_int_max_str_digits