Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
c9e1c7d9
Commit
c9e1c7d9
authored
Jul 23, 2010
by
Martin v. Löwis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #6095: Make directory argument to os.listdir optional.
Patch by Virgil Dupras.
parent
e186e384
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
14 deletions
+35
-14
Doc/library/os.rst
Doc/library/os.rst
+4
-2
Lib/test/test_posix.py
Lib/test/test_posix.py
+8
-3
Misc/NEWS
Misc/NEWS
+2
-0
Modules/posixmodule.c
Modules/posixmodule.c
+21
-9
No files found.
Doc/library/os.rst
View file @
c9e1c7d9
...
...
@@ -1049,10 +1049,10 @@ Files and Directories
Availability: Unix.
.. function:: listdir(
path
)
.. function:: listdir(
[path]
)
Return a list containing the names of the entries in the directory given by
*path*. The list is in arbitrary order. It does not include the special
*path*
(default: '.')
. The list is in arbitrary order. It does not include the special
entries ``'.'`` and ``'..'`` even if they are present in the directory.
This function can be called with a bytes or string argument, and returns
...
...
@@ -1060,6 +1060,8 @@ Files and Directories
Availability: Unix, Windows.
.. versionchanged:: 3.2
The *path* parameter became optional.
.. function:: lstat(path)
...
...
Lib/test/test_posix.py
View file @
c9e1c7d9
...
...
@@ -252,9 +252,14 @@ class PosixTester(unittest.TestCase):
posix
.
chdir
(
os
.
curdir
)
self
.
assertRaises
(
OSError
,
posix
.
chdir
,
support
.
TESTFN
)
def
test_lsdir
(
self
):
if
hasattr
(
posix
,
'lsdir'
):
self
.
assertIn
(
support
.
TESTFN
,
posix
.
lsdir
(
os
.
curdir
))
def
test_listdir
(
self
):
if
hasattr
(
posix
,
'listdir'
):
self
.
assertTrue
(
support
.
TESTFN
in
posix
.
listdir
(
os
.
curdir
))
def
test_listdir_default
(
self
):
# When listdir is called without argument, it's the same as listdir(os.curdir)
if
hasattr
(
posix
,
'listdir'
):
self
.
assertTrue
(
support
.
TESTFN
in
posix
.
listdir
())
def
test_access
(
self
):
if
hasattr
(
posix
,
'access'
):
...
...
Misc/NEWS
View file @
c9e1c7d9
...
...
@@ -1440,6 +1440,8 @@ Library
Extension Modules
-----------------
- Issue #6095: Make directory argument to os.listdir optional.
- Issue #9277: Fix bug in struct.pack for bools in standard mode
(e.g., struct.pack('>?')): if conversion to bool raised an exception
then that exception wasn't properly propagated on machines where
...
...
Modules/posixmodule.c
View file @
c9e1c7d9
...
...
@@ -2291,10 +2291,10 @@ posix_link(PyObject *self, PyObject *args)
PyDoc_STRVAR
(
posix_listdir__doc__
,
"listdir(
path
) -> list_of_strings
\n\n
\
"listdir(
[path]
) -> list_of_strings
\n\n
\
Return a list containing the names of the entries in the directory.
\n
\
\n
\
path: path of directory to list
\n
\
path: path of directory to list
(default: '.')
\n
\
\n
\
The list is in arbitrary order. It does not include the special
\n
\
entries '.' and '..' even if they are present in the directory."
);
...
...
@@ -2315,18 +2315,25 @@ posix_listdir(PyObject *self, PyObject *args)
char
*
bufptr
=
namebuf
;
Py_ssize_t
len
=
sizeof
(
namebuf
)
-
5
;
/* only claim to have space for MAX_PATH */
PyObject
*
po
;
if
(
PyArg_ParseTuple
(
args
,
"U:listdir"
,
&
po
))
{
PyObject
*
po
=
NULL
;
if
(
PyArg_ParseTuple
(
args
,
"
|
U:listdir"
,
&
po
))
{
WIN32_FIND_DATAW
wFileData
;
Py_UNICODE
*
wnamebuf
;
Py_UNICODE
*
wnamebuf
,
*
po_wchars
;
if
(
po
==
NULL
)
{
// Default arg: "."
po_wchars
=
L"."
;
len
=
1
;
}
else
{
po_wchars
=
PyUnicode_AS_UNICODE
(
po
);
len
=
PyUnicode_GET_SIZE
(
po
);
}
/* Overallocate for \\*.*\0 */
len
=
PyUnicode_GET_SIZE
(
po
);
wnamebuf
=
malloc
((
len
+
5
)
*
sizeof
(
wchar_t
));
if
(
!
wnamebuf
)
{
PyErr_NoMemory
();
return
NULL
;
}
wcscpy
(
wnamebuf
,
PyUnicode_AS_UNICODE
(
po
)
);
wcscpy
(
wnamebuf
,
po_wchars
);
if
(
len
>
0
)
{
Py_UNICODE
wch
=
wnamebuf
[
len
-
1
];
if
(
wch
!=
L'/'
&&
wch
!=
L'\\'
&&
wch
!=
L':'
)
...
...
@@ -2548,12 +2555,17 @@ posix_listdir(PyObject *self, PyObject *args)
int
arg_is_unicode
=
1
;
errno
=
0
;
if
(
!
PyArg_ParseTuple
(
args
,
"U:listdir"
,
&
v
))
{
/* v is never read, so it does not need to be initialized yet. */
if
(
!
PyArg_ParseTuple
(
args
,
"|U:listdir"
,
&
v
))
{
arg_is_unicode
=
0
;
PyErr_Clear
();
}
if
(
!
PyArg_ParseTuple
(
args
,
"O&:listdir"
,
PyUnicode_FSConverter
,
&
oname
))
oname
=
NULL
;
if
(
!
PyArg_ParseTuple
(
args
,
"|O&:listdir"
,
PyUnicode_FSConverter
,
&
oname
))
return
NULL
;
if
(
oname
==
NULL
)
{
// Default arg: "."
oname
=
PyBytes_FromString
(
"."
);
}
name
=
PyBytes_AsString
(
oname
);
if
((
dirp
=
opendir
(
name
))
==
NULL
)
{
return
posix_error_with_allocated_filename
(
oname
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment