Author: Amaury Forgeot d'Arc <amaur...@gmail.com> Branch: py3.3 Changeset: r78336:e62a0a0b8520 Date: 2015-06-28 10:25 +0200 http://bitbucket.org/pypy/pypy/changeset/e62a0a0b8520/
Log: os.stat() now accepts fd instead of the path diff --git a/pypy/module/posix/interp_posix.py b/pypy/module/posix/interp_posix.py --- a/pypy/module/posix/interp_posix.py +++ b/pypy/module/posix/interp_posix.py @@ -62,8 +62,15 @@ return self.space.fsdecode_w(self.w_obj) @specialize.memo() -def dispatch_filename(func, tag=0): +def make_dispatch_function(func, tag, allow_fd_fn=None): def dispatch(space, w_fname, *args): + if allow_fd_fn is not None: + try: + fd = space.c_int_w(w_fname) + except OperationError: + pass + else: + return allow_fd_fn(fd, *args) if space.isinstance_w(w_fname, space.w_unicode): fname = FileEncoder(space, w_fname) return func(fname, *args) @@ -72,6 +79,10 @@ return func(fname, *args) return dispatch +@specialize.arg(0, 1) +def dispatch_filename(func, tag=0, allow_fd_fn=None): + return make_dispatch_function(func, tag, allow_fd_fn) + @specialize.memo() def dispatch_filename_2(func): def dispatch(space, w_fname1, w_fname2, *args): @@ -302,7 +313,8 @@ """ try: - st = dispatch_filename(rposix_stat.stat)(space, w_path) + st = dispatch_filename(rposix_stat.stat, 0, + allow_fd_fn=rposix_stat.fstat)(space, w_path) except OSError, e: raise wrap_oserror2(space, e, w_path) else: diff --git a/pypy/module/posix/test/test_posix2.py b/pypy/module/posix/test/test_posix2.py --- a/pypy/module/posix/test/test_posix2.py +++ b/pypy/module/posix/test/test_posix2.py @@ -109,6 +109,7 @@ s = posix.read(fd, 1) assert s == b'i' st = posix.fstat(fd) + assert st == posix.stat(fd) posix.close(fd2) posix.close(fd) _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit