Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
7fb111bb
Kaydet (Commit)
7fb111bb
authored
Mar 04, 2009
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fix failures introduced by buggy merge (1)
üst
abaf78e6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
15 deletions
+29
-15
test_fileio.py
Lib/test/test_fileio.py
+2
-2
_fileio.c
Modules/_fileio.c
+27
-13
No files found.
Lib/test/test_fileio.py
Dosyayı görüntüle @
7fb111bb
...
@@ -193,8 +193,8 @@ class OtherFileTests(unittest.TestCase):
...
@@ -193,8 +193,8 @@ class OtherFileTests(unittest.TestCase):
os
.
unlink
(
TESTFN
)
os
.
unlink
(
TESTFN
)
def
testInvalidFd
(
self
):
def
testInvalidFd
(
self
):
self
.
assertRaises
(
ValueError
,
_
fileio
.
_
FileIO
,
-
10
)
self
.
assertRaises
(
ValueError
,
_FileIO
,
-
10
)
self
.
assertRaises
(
OSError
,
_
fileio
.
_
FileIO
,
make_bad_fd
())
self
.
assertRaises
(
OSError
,
_FileIO
,
make_bad_fd
())
def
testBadModeArgument
(
self
):
def
testBadModeArgument
(
self
):
# verify that we get a sensible error message for bad mode argument
# verify that we get a sensible error message for bad mode argument
...
...
Modules/_fileio.c
Dosyayı görüntüle @
7fb111bb
...
@@ -57,13 +57,15 @@ PyTypeObject PyFileIO_Type;
...
@@ -57,13 +57,15 @@ PyTypeObject PyFileIO_Type;
#define PyFileIO_Check(op) (PyObject_TypeCheck((op), &PyFileIO_Type))
#define PyFileIO_Check(op) (PyObject_TypeCheck((op), &PyFileIO_Type))
int
int
_PyFileIO_closed
(
PyObject
*
self
)
_PyFileIO_closed
(
PyObject
*
self
)
{
{
return
((
PyFileIOObject
*
)
self
)
->
fd
<
0
;
return
((
PyFileIOObject
*
)
self
)
->
fd
<
0
;
}
}
static
PyObject
*
portable_lseek
(
int
fd
,
PyObject
*
posobj
,
int
whence
);
/* Returns 0 on success, -1 with exception set on failure. */
/* Returns 0 on success, -1 with exception set on failure. */
static
int
static
int
internal_close
(
PyFileIOObject
*
self
)
internal_close
(
PyFileIOObject
*
self
)
...
@@ -156,7 +158,7 @@ check_fd(int fd)
...
@@ -156,7 +158,7 @@ check_fd(int fd)
{
{
#if defined(HAVE_FSTAT)
#if defined(HAVE_FSTAT)
struct
stat
buf
;
struct
stat
buf
;
if
(
fstat
(
fd
,
&
buf
)
<
0
&&
errno
==
EBADF
)
{
if
(
!
_PyVerify_fd
(
fd
)
||
(
fstat
(
fd
,
&
buf
)
<
0
&&
errno
==
EBADF
)
)
{
PyObject
*
exc
;
PyObject
*
exc
;
char
*
msg
=
strerror
(
EBADF
);
char
*
msg
=
strerror
(
EBADF
);
exc
=
PyObject_CallFunction
(
PyExc_OSError
,
"(is)"
,
exc
=
PyObject_CallFunction
(
PyExc_OSError
,
"(is)"
,
...
@@ -176,7 +178,7 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
...
@@ -176,7 +178,7 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
PyFileIOObject
*
self
=
(
PyFileIOObject
*
)
oself
;
PyFileIOObject
*
self
=
(
PyFileIOObject
*
)
oself
;
static
char
*
kwlist
[]
=
{
"file"
,
"mode"
,
"closefd"
,
NULL
};
static
char
*
kwlist
[]
=
{
"file"
,
"mode"
,
"closefd"
,
NULL
};
const
char
*
name
=
NULL
;
const
char
*
name
=
NULL
;
PyObject
*
nameobj
;
PyObject
*
nameobj
,
*
stringobj
=
NULL
;
char
*
mode
=
"r"
;
char
*
mode
=
"r"
;
char
*
s
;
char
*
s
;
#ifdef MS_WINDOWS
#ifdef MS_WINDOWS
...
@@ -226,26 +228,27 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
...
@@ -226,26 +228,27 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
if
(
fd
<
0
)
if
(
fd
<
0
)
{
{
if
(
PyBytes_Check
(
nameobj
)
||
PyByteArray_Check
(
nameobj
))
{
if
(
PyBytes_Check
(
nameobj
)
||
PyByteArray_Check
(
nameobj
))
{
if
(
PyObject_AsCharBuffer
(
nameobj
,
&
name
,
NULL
)
<
0
)
Py_ssize_t
namelen
;
if
(
PyObject_AsCharBuffer
(
nameobj
,
&
name
,
&
namelen
)
<
0
)
return
-
1
;
return
-
1
;
}
}
else
{
else
{
PyObject
*
s
;
PyObject
*
u
=
PyUnicode_FromObject
(
nameobj
);
PyObject
*
u
=
PyUnicode_FromObject
(
nameobj
);
if
(
u
==
NULL
)
if
(
u
==
NULL
)
return
-
1
;
return
-
1
;
s
=
PyUnicode_AsEncodedString
(
s
tringobj
=
PyUnicode_AsEncodedString
(
u
,
Py_FileSystemDefaultEncoding
,
NULL
);
u
,
Py_FileSystemDefaultEncoding
,
NULL
);
Py_DECREF
(
u
);
Py_DECREF
(
u
);
if
(
s
==
NULL
)
if
(
s
tringobj
==
NULL
)
return
-
1
;
return
-
1
;
if
(
!
PyBytes_Check
(
s
))
{
if
(
!
PyBytes_Check
(
s
tringobj
))
{
PyErr_SetString
(
PyExc_TypeError
,
PyErr_SetString
(
PyExc_TypeError
,
"encoder failed to return bytes"
);
"encoder failed to return bytes"
);
goto
error
;
}
}
name
=
PyBytes_AS_STRING
(
s
);
name
=
PyBytes_AS_STRING
(
s
tringobj
);
}
}
}
}
...
@@ -312,10 +315,10 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
...
@@ -312,10 +315,10 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
#endif
#endif
if
(
fd
>=
0
)
{
if
(
fd
>=
0
)
{
self
->
fd
=
fd
;
self
->
closefd
=
closefd
;
if
(
check_fd
(
fd
))
if
(
check_fd
(
fd
))
goto
error
;
goto
error
;
self
->
fd
=
fd
;
self
->
closefd
=
closefd
;
}
}
else
{
else
{
self
->
closefd
=
1
;
self
->
closefd
=
1
;
...
@@ -350,12 +353,23 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
...
@@ -350,12 +353,23 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
if
(
PyObject_SetAttrString
((
PyObject
*
)
self
,
"name"
,
nameobj
)
<
0
)
if
(
PyObject_SetAttrString
((
PyObject
*
)
self
,
"name"
,
nameobj
)
<
0
)
goto
error
;
goto
error
;
if
(
append
)
{
/* For consistent behaviour, we explicitly seek to the
end of file (otherwise, it might be done only on the
first write()). */
PyObject
*
pos
=
portable_lseek
(
self
->
fd
,
NULL
,
2
);
if
(
pos
==
NULL
)
goto
error
;
Py_DECREF
(
pos
);
}
goto
done
;
goto
done
;
error:
error:
ret
=
-
1
;
ret
=
-
1
;
done:
done:
Py_CLEAR
(
stringobj
);
return
ret
;
return
ret
;
}
}
...
@@ -942,14 +956,14 @@ static PyGetSetDef fileio_getsetlist[] = {
...
@@ -942,14 +956,14 @@ static PyGetSetDef fileio_getsetlist[] = {
PyTypeObject
PyFileIO_Type
=
{
PyTypeObject
PyFileIO_Type
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"FileIO"
,
"
_io.
FileIO"
,
sizeof
(
PyFileIOObject
),
sizeof
(
PyFileIOObject
),
0
,
0
,
(
destructor
)
fileio_dealloc
,
/* tp_dealloc */
(
destructor
)
fileio_dealloc
,
/* tp_dealloc */
0
,
/* tp_print */
0
,
/* tp_print */
0
,
/* tp_getattr */
0
,
/* tp_getattr */
0
,
/* tp_setattr */
0
,
/* tp_setattr */
0
,
/* tp_
compare
*/
0
,
/* tp_
reserved
*/
(
reprfunc
)
fileio_repr
,
/* tp_repr */
(
reprfunc
)
fileio_repr
,
/* tp_repr */
0
,
/* tp_as_number */
0
,
/* tp_as_number */
0
,
/* tp_as_sequence */
0
,
/* tp_as_sequence */
...
...
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