[pypy-svn] r34192 - in pypy/branch/refactor-file/pypy: . config config/test module/__builtin__ module/posix module/posix/test module/sys objspace/std tool

cfbolz at codespeak.net cfbolz at codespeak.net
Sat Nov 4 17:18:18 CET 2006


Author: cfbolz
Date: Sat Nov  4 17:18:17 2006
New Revision: 34192

Modified:
   pypy/branch/refactor-file/pypy/config/pypyoption.py
   pypy/branch/refactor-file/pypy/config/test/test_pypyoption.py
   pypy/branch/refactor-file/pypy/conftest.py
   pypy/branch/refactor-file/pypy/module/__builtin__/__init__.py
   pypy/branch/refactor-file/pypy/module/__builtin__/state.py
   pypy/branch/refactor-file/pypy/module/posix/app_posix.py
   pypy/branch/refactor-file/pypy/module/posix/test/test_posix_libfile.py
   pypy/branch/refactor-file/pypy/module/sys/__init__.py
   pypy/branch/refactor-file/pypy/module/sys/state.py
   pypy/branch/refactor-file/pypy/objspace/std/objspace.py
   pypy/branch/refactor-file/pypy/tool/option.py
Log:
(guido, cfbolz):

remove config.objspace.uselibfile options because we can now always use our own
file implementation! good!! progress! less code, less faking, happyness.


Modified: pypy/branch/refactor-file/pypy/config/pypyoption.py
==============================================================================
--- pypy/branch/refactor-file/pypy/config/pypyoption.py	(original)
+++ pypy/branch/refactor-file/pypy/config/pypyoption.py	Sat Nov  4 17:18:17 2006
@@ -11,7 +11,7 @@
     [#"unicodedata",
      "_codecs", "gc", "_weakref", "array", "marshal", "errno",
      "math", "_sre", "_pickle_support", "sys", "exceptions", "__builtins__",
-     "recparser", "symbol", "_random"])
+     "recparser", "symbol", "_random", "_file"])
                               
 pypy_optiondescription = OptionDescription("pypy", "All PyPy Options", [
     OptionDescription("objspace", "Object Space Option", [
@@ -34,16 +34,11 @@
         BoolOption("nofaking", "disallow faking in the object space",
                    default=False,
                    requires=[
-                       ("objspace.uselibfile", True),
                        ("objspace.usemodules.posix", True),
                        ("objspace.usemodules.time", True),
                        ("objspace.usemodules.errno", True)],
                    cmdline='--nofaking'),
 
-        BoolOption("uselibfile", "use the applevel file implementation",
-                   default=False,
-                   cmdline='--uselibfile'),
-
         OptionDescription("usemodules", "Which Modules should be used", [
             BoolOption(modname, "use module %s" % (modname, ),
                        default=modname in default_modules,

Modified: pypy/branch/refactor-file/pypy/config/test/test_pypyoption.py
==============================================================================
--- pypy/branch/refactor-file/pypy/config/test/test_pypyoption.py	(original)
+++ pypy/branch/refactor-file/pypy/config/test/test_pypyoption.py	Sat Nov  4 17:18:17 2006
@@ -6,10 +6,6 @@
     conf = Config(pypy_optiondescription)
     assert not conf.translating
 
-    conf.objspace.nofaking = True
-    assert conf.objspace.uselibfile
-    py.test.raises(ValueError, "conf.objspace.uselibfile = False")
-    
     assert conf.objspace.usemodules.gc
 
     conf.objspace.std.withsmallint = True

Modified: pypy/branch/refactor-file/pypy/conftest.py
==============================================================================
--- pypy/branch/refactor-file/pypy/conftest.py	(original)
+++ pypy/branch/refactor-file/pypy/conftest.py	Sat Nov  4 17:18:17 2006
@@ -28,9 +28,6 @@
                help="object space to run tests on."),
         Option('--oldstyle', action="store_true",dest="oldstyle", default=False,
                help="enable oldstyle classes as default metaclass"),
-        Option('--uselibfile', action="store_true", 
-               dest="uselibfile", default=False,
-               help="enable our applevel file implementation"),
         Option('--nofaking', action="store_true", 
                dest="nofaking", default=False,
                help="avoid faking of modules and objects completely."),

Modified: pypy/branch/refactor-file/pypy/module/__builtin__/__init__.py
==============================================================================
--- pypy/branch/refactor-file/pypy/module/__builtin__/__init__.py	(original)
+++ pypy/branch/refactor-file/pypy/module/__builtin__/__init__.py	Sat Nov  4 17:18:17 2006
@@ -72,8 +72,8 @@
         'object'        : '(space.w_object)',
         'unicode'       : '(space.w_unicode)',
 
-        'file'          : 'state.get(space).w_file', 
-        'open'          : 'state.get(space).w_file', 
+        'file'          : 'state.get(space).w_file',
+        'open'          : 'state.get(space).w_file',
 
         # old-style classes dummy support
         '_classobj'     : 'space.w_classobj',

Modified: pypy/branch/refactor-file/pypy/module/__builtin__/state.py
==============================================================================
--- pypy/branch/refactor-file/pypy/module/__builtin__/state.py	(original)
+++ pypy/branch/refactor-file/pypy/module/__builtin__/state.py	Sat Nov  4 17:18:17 2006
@@ -1,10 +1,9 @@
 
-class State: 
-    def __init__(self, space): 
-        if space.config.objspace.uselibfile:
-            self.w_file = space.builtin.get('__filestub')
-        else: 
-            self.w_file = space.wrap(file) 
+class State:
+    def __init__(self, space):
+        self.w_file = space.appexec([], """():
+                import _file;
+                return _file.file""")
         
-def get(space): 
+def get(space):
     return space.fromcache(State)

Modified: pypy/branch/refactor-file/pypy/module/posix/app_posix.py
==============================================================================
--- pypy/branch/refactor-file/pypy/module/posix/app_posix.py	(original)
+++ pypy/branch/refactor-file/pypy/module/posix/app_posix.py	Sat Nov  4 17:18:17 2006
@@ -28,8 +28,5 @@
 
     Return an open file object connected to a file descriptor."""
 
-    try:
-        return file.fdopen(fd, mode, buffering)
-    except AttributeError:
-        raise NotImplementedError, "fdopen only works if you use PyPy's file implementation."
+    return file.fdopen(fd, mode, buffering)
 

Modified: pypy/branch/refactor-file/pypy/module/posix/test/test_posix_libfile.py
==============================================================================
--- pypy/branch/refactor-file/pypy/module/posix/test/test_posix_libfile.py	(original)
+++ pypy/branch/refactor-file/pypy/module/posix/test/test_posix_libfile.py	Sat Nov  4 17:18:17 2006
@@ -2,9 +2,9 @@
 from pypy.tool.udir import udir
 import os
 
-def setup_module(mod): 
-    mod.space = gettestobjspace(usemodules=['posix'], uselibfile=True)
-    mod.path = udir.join('posixtestfile.txt') 
+def setup_module(mod):
+    mod.space = gettestobjspace(usemodules=['posix'])
+    mod.path = udir.join('posixtestfile.txt')
     mod.path.write("this is a test")
 
 class AppTestPosix: 

Modified: pypy/branch/refactor-file/pypy/module/sys/__init__.py
==============================================================================
--- pypy/branch/refactor-file/pypy/module/sys/__init__.py	(original)
+++ pypy/branch/refactor-file/pypy/module/sys/__init__.py	Sat Nov  4 17:18:17 2006
@@ -20,12 +20,12 @@
         'prefix'                : 'space.wrap(sys.prefix)', 
         'maxunicode'            : 'space.wrap(sys.maxunicode)',
         'maxint'                : 'space.wrap(sys.maxint)',
-        'stdin'                 : 'state.getio(space).w_stdin', 
-        '__stdin__'             : 'state.getio(space).w_stdin', 
-        'stdout'                : 'state.getio(space).w_stdout', 
-        '__stdout__'            : 'state.getio(space).w_stdout', 
-        'stderr'                : 'state.getio(space).w_stderr', 
-        '__stderr__'            : 'state.getio(space).w_stderr', 
+        'stdin'                 : 'state.getio(space).w_stdin',
+        '__stdin__'             : 'state.getio(space).w_stdin',
+        'stdout'                : 'state.getio(space).w_stdout',
+        '__stdout__'            : 'state.getio(space).w_stdout',
+        'stderr'                : 'state.getio(space).w_stderr',
+        '__stderr__'            : 'state.getio(space).w_stderr',
         'pypy_objspaceclass'    : 'space.wrap(repr(space))',
 
         'path'                  : 'state.get(space).w_path', 

Modified: pypy/branch/refactor-file/pypy/module/sys/state.py
==============================================================================
--- pypy/branch/refactor-file/pypy/module/sys/state.py	(original)
+++ pypy/branch/refactor-file/pypy/module/sys/state.py	Sat Nov  4 17:18:17 2006
@@ -72,23 +72,33 @@
 
 pypy_initial_path.unwrap_spec = [ObjSpace, str]
 
-def get(space): 
+def get(space):
     return space.fromcache(State)
 
-class IOState: 
-    def __init__(self, space): 
+class IOState:
+    def __init__(self, space):
         self.space = space
-        if space.config.objspace.uselibfile: 
-            self.w_stdout = space.call_function(space.builtin.get('file'))
-            self.w_stderr = space.call_function(space.builtin.get('file'))
-            self.w_stdin = space.call_function(space.builtin.get('file'))
-        else: 
-            self.w_stdout = space.wrap(sys.__stdout__) 
-            self.w_stderr = space.wrap(sys.__stderr__) 
-            self.w_stdin = space.wrap(sys.__stdin__) 
 
-def getio(space): 
-    return space.fromcache(IOState) 
+        w_fdopen = space.getattr(space.builtin.get('file'),
+                                 space.wrap("fdopen"))
+        self.w_stdin = space.call_function(
+            w_fdopen, space.wrap(0), space.wrap("r"),
+            space.wrap(1))
+        space.setattr(self.w_stdin, space.wrap("_name"),
+                      space.wrap("<stdin>"))
+        self.w_stdout = space.call_function(
+            w_fdopen, space.wrap(1), space.wrap("w"),
+            space.wrap(1))
+        space.setattr(self.w_stdout, space.wrap("_name"),
+                      space.wrap("<stdout>"))
+        self.w_stderr = space.call_function(
+            w_fdopen, space.wrap(2), space.wrap("w"),
+            space.wrap(0))
+        space.setattr(self.w_stderr, space.wrap("_name"),
+                      space.wrap("<hahahaha>"))
+
+def getio(space):
+    return space.fromcache(IOState)
 
 def _pypy_getudir(space):
     """NOT_RPYTHON"""

Modified: pypy/branch/refactor-file/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/branch/refactor-file/pypy/objspace/std/objspace.py	(original)
+++ pypy/branch/refactor-file/pypy/objspace/std/objspace.py	Sat Nov  4 17:18:17 2006
@@ -125,12 +125,9 @@
                         r[s] = value
                     return r
                 dict.fromkeys = classmethod(fromkeys)
-        """) 
+        """)
 
-        if self.config.objspace.uselibfile:
-            self.inituselibfile() 
-
-        if self.config.objspace.std.oldstyle: 
+        if self.config.objspace.std.oldstyle:
             self.enable_old_style_classes_as_default_metaclass()
 
         # final setup
@@ -178,36 +175,6 @@
         w_mod = self.wrap(mod)
         return w_mod, w_dic
 
-    def inituselibfile(self): 
-        """ NOT_RPYTHON use our application level file implementation
-            including re-wrapping sys.stdout/err/in
-        """ 
-        assert self.config.objspace.uselibfile 
-        space = self
-        # nice print helper if the below does not work 
-        # (we dont have prints working at applevel before
-        # inituselibfile is complete)
-        #from pypy.interpreter import gateway 
-        #def printit(space, w_msg): 
-        #    s = space.str_w(w_msg) 
-        #    print "$", s, 
-        #w_p = space.wrap(gateway.interp2app(printit))
-        #self.appexec([w_p], '''(p):
-        self.appexec([], '''():
-            import sys 
-            sys.stdin
-            sys.stdout
-            sys.stderr    # force unlazifying from mixedmodule 
-            from _file import file as libfile 
-            for name, value in libfile.__dict__.items(): 
-                if (name != '__dict__' and name != '__doc__'
-                    and name != '__module__' and name != '__weakref__'):
-                    setattr(file, name, value) 
-            sys.stdin._fdopen(0, "r", 1, '<stdin>') 
-            sys.stdout._fdopen(1, "w", 1, '<stdout>') 
-            sys.stderr._fdopen(2, "w", 0, '<stderr>') 
-        ''')
-
     def setup_exceptions(self):
         """NOT_RPYTHON"""
         ## hacking things in

Modified: pypy/branch/refactor-file/pypy/tool/option.py
==============================================================================
--- pypy/branch/refactor-file/pypy/tool/option.py	(original)
+++ pypy/branch/refactor-file/pypy/tool/option.py	Sat Nov  4 17:18:17 2006
@@ -10,7 +10,6 @@
 class Options:
     objspace = "std" 
     oldstyle = 0
-    uselibfile = 0
     nofaking = 0
     parser = "pypy" # "cpython" / "pypy" 
     compiler = "ast" 
@@ -71,9 +70,6 @@
         setattr(conf.objspace.usemodules, modname, True)
     if getattr(cmdlineopt, "nofaking", False) or kwds.get("nofaking", False):
         conf.objspace.nofaking = True
-    if (getattr(cmdlineopt, "uselibfile", False) or
-        kwds.get("uselibfile", False)):
-        conf.objspace.uselibfile = True
     if getattr(cmdlineopt, "oldstyle", False) or kwds.get("oldstyle", False):
         conf.objspace.std.oldstyle = True
     if hasattr(cmdlineopt, "parser") and cmdlineopt.parser is not None:



More information about the Pypy-commit mailing list