[pypy-svn] r34224 - in pypy/dist: lib-python/modified-2.4.1/test pypy pypy/config pypy/config/test pypy/lib pypy/lib/test2 pypy/module/__builtin__ pypy/module/_file pypy/module/_file/test pypy/module/posix pypy/module/posix/test pypy/module/sys pypy/objspace/std pypy/rlib pypy/rlib/test pypy/tool

cfbolz at codespeak.net cfbolz at codespeak.net
Sun Nov 5 12:26:18 CET 2006


Author: cfbolz
Date: Sun Nov  5 12:26:15 2006
New Revision: 34224

Added:
   pypy/dist/pypy/module/_file/   (props changed)
      - copied from r34223, pypy/branch/refactor-file/pypy/module/_file/
   pypy/dist/pypy/module/_file/__init__.py
      - copied unchanged from r34223, pypy/branch/refactor-file/pypy/module/_file/__init__.py
   pypy/dist/pypy/module/_file/app_file.py
      - copied unchanged from r34223, pypy/branch/refactor-file/pypy/module/_file/app_file.py
   pypy/dist/pypy/module/_file/interp_file.py
      - copied unchanged from r34223, pypy/branch/refactor-file/pypy/module/_file/interp_file.py
   pypy/dist/pypy/module/_file/test/   (props changed)
      - copied from r34223, pypy/branch/refactor-file/pypy/module/_file/test/
   pypy/dist/pypy/module/_file/test/__init__.py
      - copied unchanged from r34223, pypy/branch/refactor-file/pypy/module/_file/test/__init__.py
   pypy/dist/pypy/module/_file/test/test_file.py
      - copied unchanged from r34223, pypy/branch/refactor-file/pypy/module/_file/test/test_file.py
   pypy/dist/pypy/module/_file/test/test_file_extra.py
      - copied unchanged from r34223, pypy/branch/refactor-file/pypy/module/_file/test/test_file_extra.py
Removed:
   pypy/dist/pypy/lib/_file.py
   pypy/dist/pypy/lib/test2/test_file_extra.py
Modified:
   pypy/dist/lib-python/modified-2.4.1/test/test_file.py
   pypy/dist/pypy/config/pypyoption.py
   pypy/dist/pypy/config/test/test_pypyoption.py
   pypy/dist/pypy/conftest.py
   pypy/dist/pypy/module/__builtin__/__init__.py
   pypy/dist/pypy/module/__builtin__/state.py
   pypy/dist/pypy/module/posix/app_posix.py
   pypy/dist/pypy/module/posix/test/test_posix2.py
   pypy/dist/pypy/module/posix/test/test_posix_libfile.py
   pypy/dist/pypy/module/sys/__init__.py
   pypy/dist/pypy/module/sys/state.py
   pypy/dist/pypy/objspace/std/objspace.py
   pypy/dist/pypy/rlib/streamio.py
   pypy/dist/pypy/rlib/test/test_streamio.py
   pypy/dist/pypy/tool/option.py
Log:
(guido, cfbolz):

new file implementation works!

svn merge -r 34171:HEAD http://codespeak.net/svn/pypy/branch/refactor-file


Modified: pypy/dist/lib-python/modified-2.4.1/test/test_file.py
==============================================================================
--- pypy/dist/lib-python/modified-2.4.1/test/test_file.py	(original)
+++ pypy/dist/lib-python/modified-2.4.1/test/test_file.py	Sun Nov  5 12:26:15 2006
@@ -1,24 +1,26 @@
 import sys
 import os
+import gc
 from array import array
-#from weakref import proxy
+from weakref import proxy
 
 from test.test_support import verify, TESTFN, TestFailed
 from UserList import UserList
 
-# # verify weak references
-# f = file(TESTFN, 'w')
-# p = proxy(f)
-# p.write('teststring')
-# verify(f.tell(), p.tell())
-# f.close()
-# f = None
-# try:
-#     p.tell()
-# except ReferenceError:
-#     pass
-# else:
-#     raise TestFailed('file proxy still exists when the file is gone')
+# verify weak references
+f = file(TESTFN, 'w')
+p = proxy(f)
+p.write('teststring')
+verify(f.tell(), p.tell())
+f.close()
+f = None
+gc.collect()
+try:
+    p.tell()
+except ReferenceError:
+    pass
+else:
+    raise TestFailed('file proxy still exists when the file is gone')
 
 # verify expected attributes exist
 f = file(TESTFN, 'w')

Modified: pypy/dist/pypy/config/pypyoption.py
==============================================================================
--- pypy/dist/pypy/config/pypyoption.py	(original)
+++ pypy/dist/pypy/config/pypyoption.py	Sun Nov  5 12:26:15 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/dist/pypy/config/test/test_pypyoption.py
==============================================================================
--- pypy/dist/pypy/config/test/test_pypyoption.py	(original)
+++ pypy/dist/pypy/config/test/test_pypyoption.py	Sun Nov  5 12:26:15 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/dist/pypy/conftest.py
==============================================================================
--- pypy/dist/pypy/conftest.py	(original)
+++ pypy/dist/pypy/conftest.py	Sun Nov  5 12:26:15 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/dist/pypy/module/__builtin__/__init__.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/__init__.py	(original)
+++ pypy/dist/pypy/module/__builtin__/__init__.py	Sun Nov  5 12:26:15 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/dist/pypy/module/__builtin__/state.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/state.py	(original)
+++ pypy/dist/pypy/module/__builtin__/state.py	Sun Nov  5 12:26:15 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/dist/pypy/module/posix/app_posix.py
==============================================================================
--- pypy/dist/pypy/module/posix/app_posix.py	(original)
+++ pypy/dist/pypy/module/posix/app_posix.py	Sun Nov  5 12:26:15 2006
@@ -23,13 +23,10 @@
     st_mtime = tuple_item_getter(8)
     st_ctime = tuple_item_getter(9)
 
-def fdopen(fd, mode='r', buffering=None):
+def fdopen(fd, mode='r', buffering=-1):
     """fdopen(fd [, mode='r' [, buffering]]) -> file_object
 
     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/dist/pypy/module/posix/test/test_posix2.py
==============================================================================
--- pypy/dist/pypy/module/posix/test/test_posix2.py	(original)
+++ pypy/dist/pypy/module/posix/test/test_posix2.py	Sun Nov  5 12:26:15 2006
@@ -72,15 +72,11 @@
         ex(self.posix.dup, UNUSEDFD)
 
     def test_fdopen(self):
-        path = self.path 
-        posix = self.posix 
+        path = self.path
+        posix = self.posix
         fd = posix.open(path, posix.O_RDONLY, 0777)
-        try:
-            f = posix.fdopen(fd, "r")
-        except NotImplementedError:
-            pass
-        else:
-            raise "did not raise"
+        f = posix.fdopen(fd, "r")
+        f.close()
 
     def test_listdir(self):
         pdir = self.pdir

Modified: pypy/dist/pypy/module/posix/test/test_posix_libfile.py
==============================================================================
--- pypy/dist/pypy/module/posix/test/test_posix_libfile.py	(original)
+++ pypy/dist/pypy/module/posix/test/test_posix_libfile.py	Sun Nov  5 12:26:15 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/dist/pypy/module/sys/__init__.py
==============================================================================
--- pypy/dist/pypy/module/sys/__init__.py	(original)
+++ pypy/dist/pypy/module/sys/__init__.py	Sun Nov  5 12:26:15 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/dist/pypy/module/sys/state.py
==============================================================================
--- pypy/dist/pypy/module/sys/state.py	(original)
+++ pypy/dist/pypy/module/sys/state.py	Sun Nov  5 12:26:15 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/dist/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objspace.py	(original)
+++ pypy/dist/pypy/objspace/std/objspace.py	Sun Nov  5 12:26:15 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/dist/pypy/rlib/streamio.py
==============================================================================
--- pypy/dist/pypy/rlib/streamio.py	(original)
+++ pypy/dist/pypy/rlib/streamio.py	Sun Nov  5 12:26:15 2006
@@ -29,8 +29,19 @@
 
 import os, sys
 
-# ____________________________________________________________
+from os import O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_TRUNC
+O_BINARY = getattr(os, "O_BINARY", 0)
+
+#          (basemode, plus)
+OS_MODE = {('r', False): O_RDONLY,
+           ('r', True):  O_RDWR,
+           ('w', False): O_WRONLY | O_CREAT | O_TRUNC,
+           ('w', True):  O_RDWR   | O_CREAT | O_TRUNC,
+           ('a', False): O_WRONLY | O_CREAT,
+           ('a', True):  O_RDWR   | O_CREAT,
+           }
 
+# ____________________________________________________________
 
 
 def replace_crlf_with_lf(s):
@@ -49,6 +60,85 @@
     return s.join(string.split(c))
 
 
+def open_file_as_stream(path, mode="r", buffering=-1):
+    os_flags, universal, reading, writing, basemode = decode_mode(mode)
+    stream = open_path_helper(path, os_flags, basemode == "a")
+    return construct_stream_tower(stream, buffering, universal, reading,
+                                  writing)
+
+def fdopen_as_stream(fd, mode, buffering):
+    # XXX XXX XXX you want do check whether the modes are compatible
+    # otherwise you get funny results
+    os_flags, universal, reading, writing, basemode = decode_mode(mode)
+    stream = DiskFile(fd)
+    return construct_stream_tower(stream, buffering, universal, reading,
+                                  writing)
+
+def open_path_helper(path, os_flags, append):
+    # XXX for now always return DiskFile
+    fd = os.open(path, os_flags, 0666)
+    if append:
+        try:
+            os.lseek(fd, 0, 2)
+        except OSError:
+            # XXX does this pass make sense?
+            pass
+    return DiskFile(fd)
+
+def decode_mode(mode):
+    if mode[0] == 'U':
+        mode = 'r' + mode
+
+    basemode  = mode[0]    # 'r', 'w' or 'a'
+    plus      = False
+    universal = False
+    binary    = False
+
+    for c in mode[1:]:
+        if c == '+':
+            plus = True
+        elif c == 'U':
+            universal = True
+        elif c == 'b':
+            binary = True
+        else:
+            break
+
+    flag = OS_MODE[basemode, plus]
+    if binary or universal:
+        flag |= O_BINARY
+
+    reading = basemode == 'r' or plus
+    writing = basemode != 'r' or plus
+
+    return flag, universal, reading, writing, basemode
+
+
+def construct_stream_tower(stream, buffering, universal, reading, writing):
+    if buffering == 0:   # no buffering
+        pass
+    elif buffering == 1:   # line-buffering
+        if writing:
+            stream = LineBufferingOutputStream(stream)
+        if reading:
+            stream = BufferingInputStream(stream)
+
+    else:     # default or explicit buffer sizes
+        if buffering is not None and buffering < 0:
+            buffering = -1
+        if writing:
+            stream = BufferingOutputStream(stream, buffering)
+        if reading:
+            stream = BufferingInputStream(stream, buffering)
+
+    if universal:     # Wants universal newlines
+        if writing and os.linesep != '\n':
+            stream = TextOutputFilter(stream)
+        if reading:
+            stream = TextInputFilter(stream)
+    return stream
+
+
 class StreamError(Exception):
     def __init__(self, message):
         self.message = message
@@ -68,7 +158,7 @@
     def tell(self):
         raise NotImplementedError
 
-    def seek(self, offset, whence=0):
+    def seek(self, offset, whence):
         raise NotImplementedError
 
     def readall(self):
@@ -113,6 +203,9 @@
     def peek(self):
         return ''
 
+    def try_to_find_file_descriptor(self):
+        return -1
+
 
 class DiskFile(Stream):
 
@@ -121,11 +214,12 @@
     def __init__(self, fd):
         self.fd = fd
 
-    def seek(self, offset, whence=0):
+    def seek(self, offset, whence):
         os.lseek(self.fd, offset, whence)
 
     def tell(self):
-        return os.lseek(self.fd, 0, 1)
+        #XXX for running on top of the cpy objspace. later we want r_longlong
+        return int(os.lseek(self.fd, 0, 1))
 
     def read(self, n):
         return os.read(self.fd, n)
@@ -145,6 +239,8 @@
         def truncate(self, size):
             os.ftruncate(self.fd, size)
 
+    def try_to_find_file_descriptor(self):
+        return self.fd
 
 # next class is not RPython
 
@@ -171,7 +267,7 @@
     def tell(self):
         return self.pos
 
-    def seek(self, offset, whence=0):
+    def seek(self, offset, whence):
         if whence == 0:
             self.pos = max(0, offset)
         elif whence == 1:
@@ -239,21 +335,43 @@
     def flush(self):
         self.mm.flush()
 
+    def try_to_find_file_descriptor(self):
+        return self.fd
+
 # ____________________________________________________________
 
+STREAM_METHODS = dict([
+    ("read", [int]),
+    ("write", [str]),
+    ("tell", []),
+    ("seek", [int, int]),
+    ("readall", []),
+    ("readline", []),
+    ("truncate", [int]),
+    ("flush", []),
+    ("close", []),
+    ("peek", []),
+    ("try_to_find_file_descriptor", []),
+    ])
 
 def PassThrough(meth_name, flush_buffers):
+    if meth_name in STREAM_METHODS:
+        signature = STREAM_METHODS[meth_name]
+        args = ", ".join(["v%s" % (i, ) for i in range(len(signature))])
+    else:
+        assert 0, "not a good idea"
+        args = "*args"
     if flush_buffers:
-        code = """def %s(self, *args):
+        code = """def %s(self, %s):
                       self.flush_buffers()
-                      return self.base.%s(*args)
+                      return self.base.%s(%s)
 """
     else:
-        code = """def %s(self, *args):
-                      return self.base.%s(*args)
+        code = """def %s(self, %s):
+                      return self.base.%s(%s)
 """
     d = {}
-    exec code % (meth_name, meth_name) in d
+    exec code % (meth_name, args, meth_name, args) in d
     return d[meth_name]
 
 
@@ -285,7 +403,7 @@
     def flush_buffers(self):
         if self.lines or self.buf:
             try:
-                self.do_seek(self.tell())
+                self.do_seek(self.tell(), 0)
             except NotImplementedError:
                 pass
             else:
@@ -300,7 +418,7 @@
         assert bytes >= offset #, (locals(), self.__dict__)
         return bytes - offset
 
-    def seek(self, offset, whence=0):
+    def seek(self, offset, whence):
         # This may fail on the do_seek() or do_tell() call.
         # But it won't call either on a relative forward seek.
         # Nor on a seek to the very end.
@@ -493,6 +611,9 @@
     flush      = PassThrough("flush",     flush_buffers=True)
     close      = PassThrough("close",     flush_buffers=False)
 
+    def try_to_find_file_descriptor(self):
+        return self.base.try_to_find_file_descriptor()
+
 
 class BufferingOutputStream(Stream):
 
@@ -545,6 +666,9 @@
     flush      = PassThrough("flush",    flush_buffers=True)
     close      = PassThrough("close",    flush_buffers=True)
 
+    def try_to_find_file_descriptor(self):
+        return self.base.try_to_find_file_descriptor()
+
 
 class LineBufferingOutputStream(BufferingOutputStream):
 
@@ -560,6 +684,10 @@
             self.do_write(self.buf[:p])
             self.buf = self.buf[p:]
 
+    def try_to_find_file_descriptor(self):
+        return self.base.try_to_find_file_descriptor()
+
+
 # ____________________________________________________________
 
 
@@ -590,6 +718,8 @@
     flush    = PassThrough("flush", flush_buffers=False)
     close    = PassThrough("close", flush_buffers=False)
 
+    def try_to_find_file_descriptor(self):
+        return self.base.try_to_find_file_descriptor()
 
 class TextInputFilter(Stream):
 
@@ -688,7 +818,7 @@
                 break
         return ''.join(result)
 
-    def seek(self, offset, whence=0):
+    def seek(self, offset, whence):
         """Seeks based on knowledge that does not come from a tell()
            may go to the wrong place, since the number of
            characters seen may not match the number of characters
@@ -739,6 +869,9 @@
     flush      = PassThrough("flush",     flush_buffers=True)
     close      = PassThrough("close",     flush_buffers=False)
 
+    def try_to_find_file_descriptor(self):
+        return self.base.try_to_find_file_descriptor()
+
 
 class TextOutputFilter(Stream):
 
@@ -762,6 +895,8 @@
     flush      = PassThrough("flush",     flush_buffers=False)
     close      = PassThrough("close",     flush_buffers=False)
 
+    def try_to_find_file_descriptor(self):
+        return self.base.try_to_find_file_descriptor()
 
 
 # _________________________________________________
@@ -811,6 +946,8 @@
     flush      = PassThrough("flush",     flush_buffers=False)
     close      = PassThrough("close",     flush_buffers=False)
 
+    def try_to_find_file_descriptor(self):
+        return self.base.try_to_find_file_descriptor()
 
 class EncodingOutputFilter(Stream):
 
@@ -836,3 +973,7 @@
     truncate   = PassThrough("truncate",  flush_buffers=False)
     flush      = PassThrough("flush",     flush_buffers=False)
     close      = PassThrough("close",     flush_buffers=False)
+
+    def try_to_find_file_descriptor(self):
+        return self.base.try_to_find_file_descriptor()
+

Modified: pypy/dist/pypy/rlib/test/test_streamio.py
==============================================================================
--- pypy/dist/pypy/rlib/test/test_streamio.py	(original)
+++ pypy/dist/pypy/rlib/test/test_streamio.py	Sun Nov  5 12:26:15 2006
@@ -188,18 +188,13 @@
         def f():
             assert file.readline() == "ab\n"
             assert file.readline() == "def\n"
-            os.write(1, "3\n")
             blocks = []
             while 1:
                 block = file.read(1)
-                os.write(1, "XXXX" + block + "YYYY")
-                os.write(1, "4\n")
                 if not block:
                     break
-                os.write(1, "5\n")
                 blocks.append(block)
                 assert file.read(0) == ""
-            os.write(1, "6\n")
             return "".join(blocks) == "".join(self.lines)[7:]
         res = self.interpret(f, [])
         assert res
@@ -250,23 +245,16 @@
     def test_read_4_after_readline(self):
         file = self.makeStream()
         def f():
-            os.write(1, "1\n")
             res = file.readline()
             assert res == "ab\n"
-            os.write(1, "2\n")
             assert file.readline() == "def\n"
-            os.write(1, "3\n")
             blocks = [file.read(4)]
             while 1:
                 block = file.read(4)
                 if not block:
                     break
                 blocks.append(block)
-                os.write(1, "4\n")
                 assert file.read(0) == ""
-            os.write(1, "5\n")
-            for element in blocks:
-                os.write(1, element + "XXX\n")
             return blocks == ["xy\np", "q\nuv", "wx"]
         res = self.interpret(f, [])
         assert res
@@ -361,7 +349,7 @@
     def test_seek(self):
         file = self.makeStream(tell=True, seek=True)
         end = len(file.readall())
-        file.seek(0)
+        file.seek(0, 0)
         cases = [(readto, seekto, whence) for readto in range(0, end+1)
                                           for seekto in range(0, end+1)
                                           for whence in [0, 1, 2]]
@@ -372,7 +360,7 @@
             all = file.readall()
             assert end == len(all)
             for readto, seekto, whence in cases:
-                file.seek(0)
+                file.seek(0, 0)
                 assert file.tell() == 0
                 head = file.read(readto)
                 assert head == all[:readto]
@@ -473,7 +461,7 @@
             base = TWriter()
             filter = streamio.BufferingOutputStream(base, 4)
             filter.write("x"*6)
-            filter.seek(3)
+            filter.seek(3, 0)
             filter.write("y"*2)
             filter.close()
             assert base.buf == "x"*3 + "y"*2 + "x"*1
@@ -484,7 +472,7 @@
         def f():
             base = TWriter()
             filter = streamio.BufferingOutputStream(base, 4)
-            filter.seek(3)
+            filter.seek(3, 0)
             filter.write("y"*2)
             filter.close()
             assert base.buf == "\0"*3 + "y"*2
@@ -549,7 +537,7 @@
         filter = streamio.BufferingOutputStream(base, 4)
         def f():
             filter.write("x"*6)
-            filter.seek(3)
+            filter.seek(3, 0)
             filter.write("y"*2)
             filter.close()
             assert base.buf == "x"*3 + "y"*2 + "x"*1
@@ -632,9 +620,9 @@
         file.write("Barf\n")
         file.writelines(["a\n", "b\n", "c\n"])
         assert file.tell() == len("BooHoo\nBarf\na\nb\nc\n")
-        file.seek(0)
+        file.seek(0, 0)
         assert file.read() == "BooHoo\nBarf\na\nb\nc\n"
-        file.seek(0)
+        file.seek(0, 0)
         assert file.readlines() == (
                          ["BooHoo\n", "Barf\n", "a\n", "b\n", "c\n"])
         assert file.tell() == len("BooHoo\nBarf\na\nb\nc\n")
@@ -675,7 +663,7 @@
         filter = streamio.BufferingInputStream(
             streamio.BufferingOutputStream(base, 4), 4)
         def f():
-            filter.seek(3)
+            filter.seek(3, 0)
             filter.write("y"*2)
             filter.close()
             assert base.buf == "\0"*3 + "y"*2
@@ -774,7 +762,7 @@
             all = sofar
             for i in range(len(pairs)):
                 sofar, pos = pairs[i]
-                filter.seek(pos)
+                filter.seek(pos, 0)
                 assert filter.tell() == pos
                 assert filter.tell() == pos
                 bufs = [sofar]
@@ -862,7 +850,7 @@
             base = TWriter()
             filter = streamio.TextOutputFilter(base, linesep="\n")
             filter.write("x"*100)
-            filter.seek(50)
+            filter.seek(50, 0)
             filter.write("y"*10)
             assert base.buf == "x"*50 + "y"*10 + "x"*40
         self.interpret(f, [])

Modified: pypy/dist/pypy/tool/option.py
==============================================================================
--- pypy/dist/pypy/tool/option.py	(original)
+++ pypy/dist/pypy/tool/option.py	Sun Nov  5 12:26:15 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