Author: Matti Picus <matti.pi...@gmail.com> Branch: Changeset: r69715:3fc0ff96d0bc Date: 2014-03-05 11:41 +0200 http://bitbucket.org/pypy/pypy/changeset/3fc0ff96d0bc/
Log: merge heads diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py --- a/rpython/rlib/rposix.py +++ b/rpython/rlib/rposix.py @@ -136,141 +136,92 @@ # - but rpython.rtyper.module.ll_os.py on Windows will replace these functions # with other wrappers that directly handle unicode strings. @specialize.argtype(0) -def open(path, flags, mode): +def _as_bytes(path): assert path is not None if isinstance(path, str): - return os.open(path, flags, mode) + return path else: - return os.open(path.as_bytes(), flags, mode) + return path.as_bytes() + +@specialize.argtype(0) +def open(path, flags, mode): + return os.open(_as_bytes(path), flags, mode) @specialize.argtype(0) def stat(path): - if isinstance(path, str): - return os.stat(path) - else: - return os.stat(path.as_bytes()) + return os.stat(_as_bytes(path)) @specialize.argtype(0) def lstat(path): - if isinstance(path, str): - return os.lstat(path) - else: - return os.lstat(path.as_bytes()) + return os.lstat(_as_bytes(path)) @specialize.argtype(0) def statvfs(path): - if isinstance(path, str): - return os.statvfs(path) - else: - return os.statvfs(path.as_bytes()) + return os.statvfs(_as_bytes(path)) @specialize.argtype(0) def unlink(path): - if isinstance(path, str): - return os.unlink(path) - else: - return os.unlink(path.as_bytes()) + return os.unlink(_as_bytes(path)) @specialize.argtype(0, 1) def rename(path1, path2): - if isinstance(path1, str): - return os.rename(path1, path2) - else: - return os.rename(path1.as_bytes(), path2.as_bytes()) + return os.rename(_as_bytes(path1), _as_bytes(path2)) @specialize.argtype(0) def listdir(dirname): - if isinstance(dirname, str): - return os.listdir(dirname) - else: - return os.listdir(dirname.as_bytes()) + return os.listdir(_as_bytes(dirname)) @specialize.argtype(0) def access(path, mode): - if isinstance(path, str): - return os.access(path, mode) - else: - return os.access(path.as_bytes(), mode) + return os.access(_as_bytes(path), mode) @specialize.argtype(0) def chmod(path, mode): - if isinstance(path, str): - return os.chmod(path, mode) - else: - return os.chmod(path.as_bytes(), mode) + return os.chmod(_as_bytes(path), mode) @specialize.argtype(0, 1) def utime(path, times): - if isinstance(path, str): - return os.utime(path, times) - else: - return os.utime(path.as_bytes(), times) + return os.utime(_as_bytes(path), times) @specialize.argtype(0) def chdir(path): - if isinstance(path, str): - return os.chdir(path) - else: - return os.chdir(path.as_bytes()) + return os.chdir(_as_bytes(path)) @specialize.argtype(0) def mkdir(path, mode=0777): - if isinstance(path, str): - return os.mkdir(path, mode) - else: - return os.mkdir(path.as_bytes(), mode) + return os.mkdir(_as_bytes(path), mode) @specialize.argtype(0) def rmdir(path): - if isinstance(path, str): - return os.rmdir(path) - else: - return os.rmdir(path.as_bytes()) + return os.rmdir(_as_bytes(path)) @specialize.argtype(0) def mkfifo(path, mode): - if isinstance(path, str): - os.mkfifo(path, mode) - else: - os.mkfifo(path.as_bytes(), mode) + os.mkfifo(_as_bytes(path), mode) @specialize.argtype(0) def mknod(path, mode, device): - if isinstance(path, str): - os.mknod(path, mode, device) - else: - os.mknod(path.as_bytes(), mode, device) + os.mknod(_as_bytes(path), mode, device) @specialize.argtype(0, 1) def symlink(src, dest): - if isinstance(src, str): - os.symlink(src, dest) - else: - os.symlink(src.as_bytes(), dest.as_bytes()) + os.symlink(_as_bytes(src), _as_bytes(dest)) if os.name == 'nt': import nt + @specialize.argtype(0) def _getfullpathname(path): - if isinstance(path, str): - return nt._getfullpathname(path) - else: - return nt._getfullpathname(path.as_bytes()) + return nt._getfullpathname(_as_bytes(path)) @specialize.argtype(0, 1) def putenv(name, value): - if isinstance(name, str): - os.environ[name] = value - else: - os.environ[name.as_bytes()] = value.as_bytes() + os.environ[_as_bytes(name)] = _as_bytes(value) @specialize.argtype(0) def unsetenv(name): - if isinstance(name, str): - del os.environ[name] - else: - del os.environ[name.as_bytes()] + del os.environ[_as_bytes(name)] if os.name == 'nt': from rpython.rlib import rwin32 diff --git a/rpython/rlib/test/test_rposix.py b/rpython/rlib/test/test_rposix.py --- a/rpython/rlib/test/test_rposix.py +++ b/rpython/rlib/test/test_rposix.py @@ -25,10 +25,9 @@ def as_unicode(self): return self.unistr -class TestPosixUnicode: +class BasePosixUnicode: def setup_method(self, method): - self.ufilename = (unicode(udir.join('test_open')) + - u'\u65e5\u672c.txt') # "Japan" + self.ufilename = self._get_filename() try: f = file(self.ufilename, 'w') except UnicodeEncodeError: @@ -148,3 +147,13 @@ rposix.unsetenv(self.path) interpret(f, []) # does not crash + + +class TestPosixAscii(BasePosixUnicode): + def _get_filename(self): + return str(udir.join('test_open_ascii')) + +class TestPosixUnicode(BasePosixUnicode): + def _get_filename(self): + return (unicode(udir.join('test_open')) + + u'\u65e5\u672c.txt') # "Japan" _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit