[pypy-svn] r15128 - in pypy/dist/pypy: annotation rpython rpython/module rpython/test translator/c/test
cfbolz at codespeak.net
cfbolz at codespeak.net
Tue Jul 26 16:38:04 CEST 2005
Author: cfbolz
Date: Tue Jul 26 16:38:02 2005
New Revision: 15128
Modified:
pypy/dist/pypy/annotation/builtin.py
pypy/dist/pypy/rpython/extfunctable.py
pypy/dist/pypy/rpython/module/ll_os_path.py
pypy/dist/pypy/rpython/test/test_rbuiltin.py
pypy/dist/pypy/translator/c/test/test_extfunc.py
Log:
implemented isdir
Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py (original)
+++ pypy/dist/pypy/annotation/builtin.py Tue Jul 26 16:38:02 2005
@@ -284,8 +284,6 @@
#BUILTIN_ANALYZERS[os.path.dirname] = pathpart
#BUILTIN_ANALYZERS[os.path.normpath] = pathpart
#BUILTIN_ANALYZERS[os.path.join] = pathpart
-BUILTIN_ANALYZERS[os.path.exists] = test
-BUILTIN_ANALYZERS[os.path.isdir] = test
# import
BUILTIN_ANALYZERS[__import__] = import_func
Modified: pypy/dist/pypy/rpython/extfunctable.py
==============================================================================
--- pypy/dist/pypy/rpython/extfunctable.py (original)
+++ pypy/dist/pypy/rpython/extfunctable.py Tue Jul 26 16:38:02 2005
@@ -79,6 +79,7 @@
declare(os.fstat , statannotation, 'll_os/fstat')
declare(os.stat , statannotation, 'll_os/stat')
declare(os.path.exists, bool , 'll_os_path/exists')
+declare(os.path.isdir, bool , 'll_os_path/isdir')
declare(time.time , float , 'll_time/time')
declare(time.clock , float , 'll_time/clock')
declare(time.sleep , noneannotation, 'll_time/sleep')
Modified: pypy/dist/pypy/rpython/module/ll_os_path.py
==============================================================================
--- pypy/dist/pypy/rpython/module/ll_os_path.py (original)
+++ pypy/dist/pypy/rpython/module/ll_os_path.py Tue Jul 26 16:38:02 2005
@@ -5,6 +5,7 @@
# see ll_os.py for comments
import os
+import stat
from pypy.rpython.rstr import STR
from pypy.rpython.module.support import to_rstr, from_rstr, ll_strcpy
from pypy.rpython.module.ll_os import ll_os_stat
@@ -12,15 +13,6 @@
# Does a path exist?
# This is false for dangling symbolic links.
-## This version produces nonsense, keeping it for reference
-## def ll_os_path_exists(path):
-## """Test whether a path exists"""
-## try:
-## st = os.stat(from_rstr(path))
-## except OSError:
-## return False
-## return True
-
def ll_os_path_exists(path):
"""Test whether a path exists"""
try:
@@ -29,3 +21,10 @@
return False
return True
+def ll_os_path_isdir(path):
+ try:
+ st = ll_os_stat(path)
+ except OSError:
+ return False
+ return stat.S_ISDIR(st.item0)
+
Modified: pypy/dist/pypy/rpython/test/test_rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rbuiltin.py (original)
+++ pypy/dist/pypy/rpython/test/test_rbuiltin.py Tue Jul 26 16:38:02 2005
@@ -129,6 +129,14 @@
assert interpret(f, [
to_rstr("strange_filename_that_looks_improbable.sde")]) == False
+def test_os_isdir():
+ import os
+ def f(fn):
+ return os.path.isdir(fn)
+ assert interpret(f, [to_rstr("/")]) == True
+ assert interpret(f, [to_rstr(str(py.magic.autopath()))]) == False
+ assert interpret(f, [to_rstr("another/unlikely/directory/name")]) == False
+
def test_pbc_isTrue():
class C:
Modified: pypy/dist/pypy/translator/c/test/test_extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_extfunc.py (original)
+++ pypy/dist/pypy/translator/c/test/test_extfunc.py Tue Jul 26 16:38:02 2005
@@ -114,6 +114,18 @@
return os.path.exists(tmpfile)
f = compile(fn, [])
open(tmpfile, 'w').close()
- assert f() is True
+ assert f() == True
os.unlink(tmpfile)
- assert f() is False
+ assert f() == False
+
+def test_os_path_isdir():
+ directory = "./."
+ def fn():
+ return os.path.isdir(directory)
+ f = compile(fn, [])
+ assert f() == True
+ directory = "some/random/name"
+ def fn():
+ return os.path.isdir(directory)
+ f = compile(fn, [])
+ assert f() == False
More information about the Pypy-commit
mailing list