[issue7560] Various filename-taking posix methods don't like bytes / buffer objects.

Sebastian Hagen report at bugs.python.org
Tue Dec 22 06:07:42 CET 2009


New submission from Sebastian Hagen <sh_pybugs at memespace.net>:

Most of the functions in Python's stdlib that take filename parameters
allow for those parameters to be buffer (such as bytes, bytearray,
memoryview) objects. This is useful for various reasons, among them that
on Posix-likes, file- and pathnames ultimately *are* sequences of bytes.
A number of functions in the posix (and thus, os) module break this
convention:
mkfifo()
mknod()
statvfs()
pathconf()

E.g.:
>>> os.statvfs(b'/')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: statvfs() argument 1 must be string, not bytes

I'm attaching a patch that modifies the abovementioned functions to make
them accept buffer-like objects in addition to string objects; I've
never contributed code to the stdlib, so any general problems with that
patch can be ascribed to my ignorance about established practice (or
inability to program, in the case of downright bugs).

I'm a bit off a loss as what to do about posix.system(). IMO, that one
should also take bytes - at least on posix-like OSes - since it
specifies a commandline, and both the name and the arguments in such
lines are, on posix-likes, sequences of bytes.
I'm not sure how to best reconcile that with the MS Windows version of
that function, however; advice would be welcome.

----------
components: Library (Lib)
files: posix_fn_bytes_01.patch
keywords: patch
messages: 96792
nosy: sh
severity: normal
status: open
title: Various filename-taking posix methods don't like bytes / buffer objects.
versions: Python 3.1, Python 3.2
Added file: http://bugs.python.org/file15659/posix_fn_bytes_01.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7560>
_______________________________________


More information about the Python-bugs-list mailing list