code
stringlengths
1
1.72M
language
stringclasses
1 value
#! /usr/bin/env python import autopath import py import sys mydir = py.magic.autopath().dirpath().realpath() from pypy.tool.pytest import htmlreport from pypy.tool.pytest import confpath if __name__ == '__main__': if len(sys.argv) > 1: testresultdir = py.path.local(sys.argv[1]) assert te...
Python
#empty
Python
#empty
Python
import autopath import re from os import listdir from sys import stdin, stdout, stderr where = autopath.pypydir + '/objspace/std/' quote = '(' + "'" + '|' + '"' + ')' triplequotes = '(' + "'''" + '|' + '"""' + ')' # Note: this will produce erroneous result if you nest triple quotes # in your docstring. def mk_std_fil...
Python
import sys, os, signal import threading def getsignalname(n): for name, value in signal.__dict__.items(): if value == n and name.startswith('SIG'): return name return 'signal %d' % (n,) timeout = float(sys.argv[1]) timedout = False def childkill(): global timedout timedout = True ...
Python
#!/usr/bin/env python # XXX needs to run on codespeak import py import sys import os base = py.path.local('/www/codespeak.net/htdocs') def runpytest(path, outfile): lockfile = base.join(".gendoclock") return os.system("/admin/bin/withlock %s py.test %s >>%s 2>&1" %( lockfile, path, out...
Python
from __future__ import division import autopath import py import math import random import sets exclude_files = ["__init__.py", "autopath.py", "conftest.py"] def include_file(path): if ("test" in str(path) or "tool" in str(path) or "documentation" in str(path) or "pyrex" in str(path) or "_cache" ...
Python
# This is where the options for py.py are defined. import os from pypy.config.pypyoption import get_pypy_config from pypy.config.config import Config, OptionDescription, to_optparse from py.compat import optparse extra_useage = """For detailed descriptions of all the options see http://codespeak.net/pypy/dist/pypy/do...
Python
import exceptions, os from pypy.tool import slaveproc class IsolateException(Exception): pass class IsolateInvoker(object): # to have a nice repr def __init__(self, isolate, name): self.isolate = isolate self.name = name def __call__(self, *args): return self.isolate._inv...
Python
""" A color print. """ import sys from py.__.misc.terminal_helper import ansi_print from pypy.tool.ansi_mandelbrot import Driver class AnsiLog: wrote_dot = False # XXX sharing state with all instances KW_TO_COLOR = { # color supress 'red': ((31,), True), 'bold': ((1,), True), ...
Python
import autopath import py from py.__.misc.cmdline import countloc from py.xml import raw pypydir = py.path.local(autopath.pypydir) def isdocfile(p): return p.ext == '.txt' or p.basename in ('README', 'NOTES', 'LICENSE') def istestfile(p): if not p.check(file=1, ext='.py'): return False pb = p...
Python
import py from os import system, chdir from urllib import urlopen log_URL = 'http://tismerysoft.de/pypy/irc-logs/' archive_FILENAME = 'pypy.tar.gz' tempdir = py.test.ensuretemp("irc-log") # get compressed archive chdir( str(tempdir)) system('wget -q %s%s' % (log_URL, archive_FILENAME)) system('tar xzf %s' % archiv...
Python
import py release_URL = 'http://codespeak.net/svn/pypy/release/' releases = [r[:-2] for r in py.std.os.popen('svn list ' + release_URL).readlines() if 'x' not in r] f = file('release_dates.txt', 'w') print >> f, 'date, release' for release in releases: for s in py.std.os.popen('svn info ' + release_URL + release)...
Python
##"""Thread-local storage.""" ## ##try: ## from thread import _local as tlsobject ##except ImportError: # Python < 2.4 ## ## # XXX needs a real object whose attributes are visible only in ## # the thread that reads/writes them. ## ## import autopath, os ## filename = os.path.join(os.path.dirname(a...
Python
""" Trace object space configuration options - set with __pytrace__=1 in py.py """ from pypy.tool.traceop import ResultPrinter, ResultPrinterVerbose def get_operations_all(): from pypy.interpreter.baseobjspace import ObjSpace operations = dict([(r[0], r[0]) for r in ObjSpace.MethodTable]) for name in ObjS...
Python
# load opcode.py as pythonopcode from our own lib __all__ = ['opmap', 'opname', 'HAVE_ARGUMENT', 'hasconst', 'hasname', 'hasjrel', 'hasjabs', 'haslocal', 'hascompare', 'hasfree', 'cmp_op'] def load_opcode(): import py opcode_path = py.path.local(__file__).dirpath().dirpath().dirpath('lib...
Python
import sys, os # this file runs some benchmarks with a pypy-c that is assumed to be # built using the MeasuringDictImplementation. # it should be run with pypy/translator/goal as the cwd, and you'll # need to hack a copy of rst2html for yourself (svn docutils # required). try: os.unlink("dictinfo.txt") except os...
Python
# # Common entry point to access a temporary directory (for testing, etc.) # This uses the py lib's logic to create numbered directories. The last # three temporary directories are kept. # import autopath import os from py.path import local udir = local.make_numbered_dir(prefix='usession-', keep=3)
Python
#!/usr/bin/env python import Image import ImageDraw import urllib import StringIO import math import sys import colorsys import py pyhtml = py.xml.html from result import ( PerfResult, PerfResultDelta, PerfResultCollection, PerfTable ) class Page: """generates a benchmark summary page The gener...
Python
import py class PerfResult: """Holds information about a benchmark run of a particular test run.""" def __init__(self, date=0.0, test_id="", revision=0.0, revision_id="NONE", timestamp=0.0, revision_date=0.0, elapsed_time=-1, committer="", message="", ...
Python
#!/usr/bin/env python import Image import ImageDraw import urllib import StringIO import math import sys import colorsys import py pyhtml = py.xml.html from result import ( PerfResult, PerfResultDelta, PerfResultCollection, PerfTable ) class Page: """generates a benchmark summary page The gener...
Python
import py class ResultDB(object): def __init__(self): self.benchmarks = [] def parsepickle(self, path): f = path.open("rb") id2numrun = py.std.pickle.load(f) id2bestspeed = py.std.pickle.load(f) f.close() for id in id2numrun: besttime = id2bestspeed[...
Python
#
Python
#!/usr/bin/env python # XXX needs to run on codespeak import py import sys import os base = py.path.local('/www/codespeak.net/htdocs') def runpytest(path, outfile): lockfile = base.join(".gendoclock") return os.system("/admin/bin/withlock %s py.test %s >>%s 2>&1" %( lockfile, path, out...
Python
#! /usr/bin/env python """ This script walks over the files and subdirs of the specified directories ('.' by default), and changes the svn properties to match the PyPy guidelines: svn:ignore includes '*.pyc' and '*.pyo' for all directories svn:eol-style is 'native' for *.py and *.txt files """ import sys, o...
Python
import pypy import py def pypyrev(cache=[]): """ return subversion revision number for current pypy package. """ try: return cache[0] except IndexError: pypydir = py.path.svnwc(pypy.__file__).dirpath() rev = pypydir.info().rev cache.append(rev) return rev ...
Python
import struct, sys # This is temporary hack to run PyPy on PyPy # until PyPy's struct module handle P format character. try: HUGEVAL_FMT = 'P' HUGEVAL_BYTES = struct.calcsize('P') except struct.error: if sys.maxint <= 2147483647: HUGEVAL_FMT = 'l' HUGEVAL_BYTES = 4 else: HUG...
Python
import autopath import sys, imp from pypy.tool import slaveproc class IsolateSlave(slaveproc.Slave): mod = None def do_cmd(self, cmd): cmd, data = cmd if cmd == 'load': assert self.mod is None mod = data if isinstance(mod, str): mod = __impor...
Python
#! /usr/bin/env python """ This script walks over the files and subdirs of the specified directories ('.' by default), and changes the svn properties to match the PyPy guidelines: svn:ignore includes '*.pyc' and '*.pyo' for all directories svn:eol-style is 'native' for *.py and *.txt files """ import sys, o...
Python
""" self cloning, automatic path configuration copy this into any subdirectory of pypy from which scripts need to be run, typically all of the test subdirs. The idea is that any such script simply issues import autopath and this will make sure that the parent directory containing "pypy" is in sys.path. If y...
Python
# load __future__.py constants def load_module(): import py module_path = py.path.local(__file__).dirpath().dirpath().dirpath('lib-python/modified-2.4.1/__future__.py') execfile(str(module_path), globals()) load_module() del load_module # this could be generalized, it's also in opcode.py
Python
# this is for use with a pypy-c build with multidicts and using the # MeasuringDictImplementation -- it will create a file called # 'dictinfo.txt' in the local directory and this file will turn the # contents back into DictInfo objects. # run with python -i ! import sys infile = open(sys.argv[1]) curr = None slots ...
Python
# # support code for the trace object space # import autopath import sys class Stack(list): push = list.append def pop(self): return super(Stack, self).pop(-1) def top(self): try: return self[-1] except IndexError: return None class ResultPrinter(object)...
Python
import os, struct, marshal, sys class Exchange(object): def __init__(self, inp, out): self.out = out self.inp = inp def send(self, data): s = marshal.dumps(data) h = struct.pack('L', len(s)) self.out.write(h+s) self.out.flush() def recv(self): HSIZE...
Python
# some analysis of global imports """ The idea: compile a module's source text and walk recursively through the code objects. Find out which globals are used. Then examine each 'import *' by importing that module and looking for those globals. Replace the 'import *' by the list found. More advanced: If the new import ...
Python
#empty
Python
# a couple of support functions which # help with generating Python source. # XXX This module provides a similar, but subtly different, functionality # XXX several times over, which used to be scattered over four modules. # XXX We should try to generalize and single out one approach to dynamic # XXX code compilation. ...
Python
class InstanceMethod(object): "Like types.InstanceMethod, but with a reasonable (structural) equality." def __init__(self, im_func, im_self, im_class): self.im_func = im_func self.im_self = im_self self.im_class = im_class def __call__(self, *args, **kwds): firstarg = self...
Python
import autopath import py log = py.log.Producer("log") logexec = py.log.Producer("exec") import os BASEURL = "file:///svn/pypy/release/1.0.x" DDIR = py.path.local('/www/codespeak.net/htdocs/download/pypy') def usage(): print "usage: %s [-tag .<micro>] versionbasename" %(py.std.sys.argv[0]) raise SystemExit...
Python
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer import threading import sys server_thread = None server_port = None class TBRequestHandler(BaseHTTPRequestHandler): views = {} def do_GET(self): if self.path == '/quit': global server_thread server_thread = None ...
Python
from pypy.tool.tb_server.server import TBRequestHandler import py html = py.xml.html import traceback import cgi import urllib views = TBRequestHandler.views class URL(object): attrs='scm','netloc','path','params','query','fragment' attrindex = dict(zip(attrs, range(len(attrs)))) # XXX authentication p...
Python
# Lazy import def start(): global start, stop, publish_exc, wait_until_interrupt from server import start, stop, publish_exc, wait_until_interrupt return start() def stop(): pass def wait_until_interrupt(): pass def publish_exc(exc): pass
Python
""" ref = UnionRef(x) -> creates a reference to x, such that ref() is x. Two references can be merged: ref.merge(ref2) make ref and ref2 interchangeable. After a merge, ref() is ref2(). This is done by asking the two older objects that ref and ref2 pointed to how they should be merged. The point is that large equiva...
Python
# This is a general algorithm used by the annotator. # union-find impl, a info object is attached to the roots class UnionFind(object): def __init__(self, info_factory=None): self.link_to_parent = {} self.weight = {} self.info_factory = info_factory self.root_info = {} # mapp...
Python
""" Utilities to manipulate graphs (vertices and edges, not control flow graphs). Convention: 'vertices' is a set of vertices (or a dict with vertices as keys); 'edges' is a dict mapping vertices to a list of edges with its source. Note that we can usually use 'edges' as the set of 'vertices' too. """ class Edg...
Python
import weakref import UserDict class MultiWeakKeyDictionary(UserDict.DictMixin): def __init__(self): self._bylength = {} def __getitem__(self, key): key = (len(key),) + key d = self._bylength for step in key: d = d[step] return d def __setitem__(self,...
Python
from __future__ import division EPSILON = 1E-12 class SparseMatrix: def __init__(self, height): self.lines = [{} for row in range(height)] def __getitem__(self, (row, col)): return self.lines[row].get(col, 0) def __setitem__(self, (row, col), value): if abs(value) > EPSILON: ...
Python
__all__ = ['FSet', 'emptyset'] # Reference: # "Implementing sets efficiently in a functional language" # http://swiss.csail.mit.edu/~adams/BB/ # See BB.sml in the current directory. class FSet(object): """Functional Set. Behaves like a frozenset from Python 2.4 (incomplete, though). This version is...
Python
#empty
Python
""" self cloning, automatic path configuration copy this into any subdirectory of pypy from which scripts need to be run, typically all of the test subdirs. The idea is that any such script simply issues import autopath and this will make sure that the parent directory containing "pypy" is in sys.path. If y...
Python
#empty
Python
import sys import opcode import dis import imp import os import __builtin__ import time """ so design goal: i want to take a pile of source code and analyze each module for the names it defines and the modules it imports and the names it uses from them. then i can find things like: - things which are just plain not...
Python
import py from py.__.misc.cmdline.countloc import get_loccount import datetime import time URL = "http://codespeak.net/svn/pypy/dist" tempdir = py.path.svnwc(py.test.ensuretemp("pypy-dist")) print "checking out" tempdir.checkout(URL) print "done" pypy = tempdir.join('pypy') statistic = [] curr_rev = tempdir.info()....
Python
def test_something(space): assert space.w_None is space.w_None def app_test_something(): assert 42 == 42 class AppTestSomething: def test_method_app(self): assert 23 == 23 class TestSomething: def test_method(self): assert self.space
Python
def f(a,b): return a+b def g(): raise ValueError, "booh" class FancyException(Exception): pass def h(): raise FancyException, "booh" def bomb(): raise KeyboardInterrupt
Python
""" self cloning, automatic path configuration copy this into any subdirectory of pypy from which scripts need to be run, typically all of the test subdirs. The idea is that any such script simply issues import autopath and this will make sure that the parent directory containing "pypy" is in sys.path. If y...
Python
""" Caches that can freeze when the annotator needs it. """ # # _freeze_() protocol: # user-defined classes can define a method _freeze_(), which # is called when a prebuilt instance is found. If the method # returns True, the instance is considered immutable and becomes # a SomePBC(). Otherwise it's...
Python
# NOT_RPYTHON """ A pure Python reimplementation of the _sre module from CPython 2.4 Copyright 2005 Nik Haldimann, licensed under the MIT license This code is based on material licensed under CNRI's Python 1.6 license and copyrighted by: Copyright (c) 1997-2001 by Secret Labs AB """ import sys import _sre def compi...
Python
from pypy.interpreter.baseobjspace import Wrappable from pypy.interpreter.typedef import GetSetProperty, TypeDef from pypy.interpreter.typedef import interp_attrproperty, interp_attrproperty_w from pypy.interpreter.gateway import interp2app, ObjSpace, W_Root from pypy.interpreter.error import OperationError from pypy.r...
Python
from pypy.interpreter.mixedmodule import MixedModule class Module(MixedModule): """A pure Python reimplementation of the _sre module from CPython 2.4 Copyright 2005 Nik Haldimann, licensed under the MIT license This code is based on material licensed under CNRI's Python 1.6 license and copyrighted by: Copyright ...
Python
""" self cloning, automatic path configuration copy this into any subdirectory of pypy from which scripts need to be run, typically all of the test subdirs. The idea is that any such script simply issues import autopath and this will make sure that the parent directory containing "pypy" is in sys.path. If y...
Python
"""Support functions for app-level _sre tests.""" import locale, _sre from sre_constants import OPCODES, ATCODES, CHCODES def encode_literal(string): opcodes = [] for character in string: opcodes.extend([OPCODES["literal"], ord(character)]) return opcodes def assert_match(opcodes, strings): as...
Python
from pypy.rpython.rctypes.tool import ctypes_platform from pypy.rpython.rctypes.tool.libc import libc import pypy.rpython.rctypes.implementation # this defines rctypes magic from pypy.rpython.rctypes.aerrno import geterrno from pypy.interpreter.error import OperationError from pypy.interpreter.baseobjspace import W_Roo...
Python
# NOT_RPYTHON import os from _structseq import structseqtype, structseqfield _POSIX = os.name == "posix" class struct_time: __metaclass__ = structseqtype __module__ = 'time' tm_year = structseqfield(0) tm_mon = structseqfield(1) tm_mday = structseqfield(2) tm_hour = structseqfield(3...
Python
from pypy.interpreter.mixedmodule import MixedModule class Module(MixedModule): applevel_name = 'time' interpleveldefs = { 'accept2dyear': 'interp_time.accept2dyear', 'timezone': 'interp_time.timezone', 'daylight': 'interp_time.daylight', 'tzname': 'interp_time.tzname', ...
Python
from pypy.interpreter.error import OperationError from pypy.interpreter.baseobjspace import ObjSpace, W_Root from pypy.rpython.rctypes.tool import ctypes_platform from pypy.rpython.rctypes.tool.util import find_library, load_library import sys from ctypes import * class CConfig: _includes_ = ('unistd.h',) if...
Python
from pypy.interpreter.mixedmodule import MixedModule class Module(MixedModule): """A demo built-in module based on ctypes.""" interpleveldefs = { 'crypt' : 'interp_crypt.crypt', } appleveldefs = { }
Python
#
Python
class DemoError(Exception): pass
Python
from pypy.interpreter.mixedmodule import MixedModule class Module(MixedModule): """A demo built-in module based on ctypes.""" interpleveldefs = { 'measuretime' : 'demo.measuretime', 'sieve' : 'demo.sieve', 'MyType' : 'demo.W_MyType', } appleveldefs =...
Python
from pypy.interpreter.error import OperationError from pypy.interpreter.baseobjspace import ObjSpace, W_Root, Wrappable from pypy.interpreter.gateway import interp2app from pypy.interpreter.typedef import TypeDef, GetSetProperty from pypy.rpython.rctypes.tool import ctypes_platform from pypy.rpython.rctypes.tool.libc i...
Python
def index(space, w_a): return space.index(w_a) def abs(space, w_obj): 'abs(a) -- Same as abs(a).' return space.abs(w_obj) def add(space, w_obj1, w_obj2): 'add(a, b) -- Same as a a + b' return space.add(w_obj1, w_obj2) def and_(space, w_obj1, w_obj2): 'and_(a, b) -- Same as a a & b' return...
Python
'''NOT_RPYTHON: because of attrgetter and itemgetter Operator interface. This module exports a set of operators as functions. E.g. operator.add(x,y) is equivalent to x+y. ''' def attrgetter(attr): def f(obj): return getattr(obj, attr) return f def countOf(a,b): 'countOf(a, b) -- Return the numbe...
Python
from pypy.interpreter.mixedmodule import MixedModule from pypy.interpreter.error import OperationError class Module(MixedModule): """Operator Builtin Module. """ # HACK! override loaders to be able to access different operations # under same name. I.e., operator.eq == operator.__eq__ def __init__(s...
Python
"""NOT_RPYTHON""" import sys import _file class file(object): """file(name[, mode[, buffering]]) -> file object Open a file. The mode can be 'r', 'w' or 'a' for reading (default), writing or appending. The file will be created if it doesn't exist when opened for writing or appending; it will be truncated when...
Python
import py from pypy.rlib import streamio from errno import EINTR from pypy.interpreter.error import OperationError from pypy.interpreter.gateway import ObjSpace, W_Root, NoneNotWrapped, applevel from pypy.interpreter.baseobjspace import Wrappable from pypy.interpreter.typedef import TypeDef from pypy.interpreter.gatew...
Python
# Package initialisation from pypy.interpreter.mixedmodule import MixedModule class Module(MixedModule): appleveldefs = { "file": "app_file.file", } interpleveldefs = { "open_file_as_stream": "interp_file.open_file_as_stream", "fdopen_as_stream": "interp_file.fdopen_as_stream", ...
Python
# Note: # This *is* now explicitly RPython. # Please make sure not to break this. """ _codecs -- Provides access to the codec registry and the builtin codecs. This module should never be imported directly. The standard library module "codecs" wraps this builtin module for use within Python. ...
Python
from pypy.interpreter.mixedmodule import MixedModule class Module(MixedModule): appleveldefs = { '__doc__' : 'app_codecs.__doc__', '__name__' : 'app_codecs.__name__', 'ascii_decode' : 'app_codecs.ascii_decode', 'ascii_encode' : 'app_codecs.ascii_encode', 'charbu...
Python
""" self cloning, automatic path configuration copy this into any subdirectory of pypy from which scripts need to be run, typically all of the test subdirs. The idea is that any such script simply issues import autopath and this will make sure that the parent directory containing "pypy" is in sys.path. If y...
Python
# empty
Python
from pypy.interpreter.baseobjspace import Wrappable from pypy.interpreter import baseobjspace, typedef, gateway from pypy.interpreter.gateway import interp2app from pypy.interpreter.function import Function from pypy.interpreter.error import OperationError from pypy.objspace.std.listobject import W_ListObject from pyp...
Python
from pypy.rlib.cslib.rpropagation import Repository, Solver import pypy.rlib.cslib.rdistributor as rd from pypy.module._cslib import fd from pypy.module._cslib.constraint import W_AbstractConstraint from pypy.interpreter.error import OperationError from pypy.interpreter import typedef, gateway, baseobjspace from pyp...
Python
from pypy.interpreter.error import OperationError from pypy.interpreter import typedef, gateway, baseobjspace from pypy.interpreter.gateway import interp2app from pypy.objspace.std.listobject import W_ListObject, W_TupleObject from pypy.objspace.std.intobject import W_IntObject from pypy.rlib.cslib import rdomain as...
Python
# Package initialisation from pypy.interpreter.mixedmodule import MixedModule #print '_csp module' class Module(MixedModule): appleveldefs = { } interpleveldefs = { 'FiniteDomain' : 'fd.make_fd', 'AllDistinct' : 'constraint.make_alldistinct', '_make_expression': 'constraint...
Python
from pypy.interpreter.error import OperationError from pypy.interpreter.typedef import TypeDef from pypy.interpreter.gateway import ObjSpace, W_Root, NoneNotWrapped, interp2app from pypy.interpreter.baseobjspace import Wrappable from pypy.rlib.rarithmetic import r_uint, intmask from pypy.rlib import rrandom import tim...
Python
import py from pypy.interpreter.mixedmodule import MixedModule class Module(MixedModule): appleveldefs = {} interpleveldefs = { 'Random' : 'interp_random.W_Random', }
Python
# this is a sketch of how one might one day be able to define a pretty simple # ctypes-using module, suitable for feeding to the ext-compiler from pypy.interpreter.baseobjspace import ObjSpace from pypy.module.readline import c_readline #------------------------------------------------------------ # exported API (...
Python
from ctypes import * from pypy.rpython.rctypes.tool.ctypes_platform import configure, Library from pypy.interpreter.error import OperationError from pypy.interpreter.gateway import ObjSpace, interp2app #------------------------------------------------------------ # configuration for binding to external readline librar...
Python
# NOT_RPYTHON def stub(*args, **kwds): import warnings warnings.warn("the 'readline' module is only a stub so far") def stub_str(*args, **kwds): stub() return '' def stub_int(*args, **kwds): stub() return 0
Python
# this is a sketch of how one might one day be able to define a pretty simple # ctypes-using module, suitable for feeding to the ext-compiler from pypy.interpreter.mixedmodule import MixedModule # XXX raw_input needs to check for space.readline_func and use # it if its there class Module(MixedModule): """Import...
Python
#
Python
import py class Directory(py.test.collect.Directory): def run(self): try: import ctypes except ImportError: py.test.skip("these tests need ctypes installed") return super(Directory, self).run()
Python
class error(Exception): pass def as_fd(f): if not isinstance(f, (int, long)): try: fileno = f.fileno except AttributeError: raise TypeError("argument must be an int, or have a fileno() method.") f = f.fileno() if not isinstance(f, (int, long)): ...
Python
from pypy.interpreter.typedef import TypeDef from pypy.interpreter.baseobjspace import Wrappable from pypy.interpreter.gateway import W_Root, ObjSpace, interp2app from pypy.rlib import _rsocket_ctypes as _c from ctypes import POINTER, byref from pypy.rpython.rctypes.aerrno import geterrno from pypy.interpreter.error im...
Python
# Package initialisation from pypy.interpreter.mixedmodule import MixedModule import sys class Module(MixedModule): appleveldefs = { 'error': 'app_select.error', 'select': 'app_select.select', } interpleveldefs = { 'poll' : 'interp_select.poll', } def buildloaders(cls): ...
Python
import math from pypy.interpreter.error import OperationError from pypy.interpreter.gateway import ObjSpace, W_Root, NoneNotWrapped class State: def __init__(self, space): self.w_e = space.wrap(math.e) self.w_pi = space.wrap(math.pi) def get(space): return space.fromcache(State) def math1...
Python
# Package initialisation from pypy.interpreter.mixedmodule import MixedModule class Module(MixedModule): appleveldefs = { } interpleveldefs = { 'e' : 'interp_math.get(space).w_e', 'pi' : 'interp_math.get(space).w_pi', 'pow' : 'interp_math.pow', ...
Python
# ONESHOT SCRIPT (probably can go away soon) # to generate the mixed module 'math' (see same directory) import py import math import re import sys rex_arg = re.compile(".*\((.*)\).*") if __name__ == '__main__': print py.code.Source(""" import math from pypy.interpreter.gateway import ObjSpace ...
Python
# NOT_RPYTHON -- flowing results in # AttributeError: << 'FlowObjSpace' object has no attribute 'w_AttributeError' # XXX investigate! """ The 'sys' module. """ import sys def excepthook(exctype, value, traceback): """Handle an exception by displaying it with a traceback on sys.stderr.""" from traceback i...
Python