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
b0428159
Kaydet (Commit)
b0428159
authored
Nis 08, 2007
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Make it possible to instantiate a _FileIO() with an integer file descriptor
instead of a filename. Add a 'closed' attribute.
üst
b8551ae6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
18 deletions
+50
-18
_fileio.c
Modules/_fileio.c
+50
-18
No files found.
Modules/_fileio.c
Dosyayı görüntüle @
b0428159
...
@@ -22,9 +22,8 @@
...
@@ -22,9 +22,8 @@
*
*
* Unanswered questions:
* Unanswered questions:
*
*
* - Add mode, name, and closed properties a la Python 2 file objects?
* - Add mode and name properties a la Python 2 file objects?
* - Do we need a (*close)() in the struct like Python 2 file objects,
* - Check for readable/writable before attempting to read/write?
* for not-quite-ordinary-file objects?
*/
*/
#ifdef MS_WINDOWS
#ifdef MS_WINDOWS
...
@@ -55,15 +54,16 @@ static PyObject *
...
@@ -55,15 +54,16 @@ static PyObject *
fileio_close
(
PyFileIOObject
*
self
)
fileio_close
(
PyFileIOObject
*
self
)
{
{
if
(
self
->
fd
>=
0
)
{
if
(
self
->
fd
>=
0
)
{
int
fd
=
self
->
fd
;
self
->
fd
=
-
1
;
Py_BEGIN_ALLOW_THREADS
Py_BEGIN_ALLOW_THREADS
errno
=
0
;
errno
=
0
;
close
(
self
->
fd
);
close
(
fd
);
Py_END_ALLOW_THREADS
Py_END_ALLOW_THREADS
if
(
errno
<
0
)
{
if
(
errno
<
0
)
{
PyErr_SetFromErrno
(
PyExc_IOError
);
PyErr_SetFromErrno
(
PyExc_IOError
);
return
NULL
;
return
NULL
;
}
}
self
->
fd
=
-
1
;
}
}
Py_RETURN_NONE
;
Py_RETURN_NONE
;
...
@@ -123,7 +123,7 @@ static int
...
@@ -123,7 +123,7 @@ static int
fileio_init
(
PyObject
*
oself
,
PyObject
*
args
,
PyObject
*
kwds
)
fileio_init
(
PyObject
*
oself
,
PyObject
*
args
,
PyObject
*
kwds
)
{
{
PyFileIOObject
*
self
=
(
PyFileIOObject
*
)
oself
;
PyFileIOObject
*
self
=
(
PyFileIOObject
*
)
oself
;
static
char
*
kwlist
[]
=
{
"file
name
"
,
"mode"
,
NULL
};
static
char
*
kwlist
[]
=
{
"file"
,
"mode"
,
NULL
};
char
*
name
=
NULL
;
char
*
name
=
NULL
;
char
*
mode
=
"r"
;
char
*
mode
=
"r"
;
char
*
s
;
char
*
s
;
...
@@ -131,6 +131,7 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
...
@@ -131,6 +131,7 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
int
ret
=
0
;
int
ret
=
0
;
int
rwa
=
0
,
plus
=
0
,
append
=
0
;
int
rwa
=
0
,
plus
=
0
,
append
=
0
;
int
flags
=
0
;
int
flags
=
0
;
int
fd
=
-
1
;
assert
(
PyFileIO_Check
(
oself
));
assert
(
PyFileIO_Check
(
oself
));
if
(
self
->
fd
>=
0
)
if
(
self
->
fd
>=
0
)
...
@@ -142,8 +143,20 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
...
@@ -142,8 +143,20 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
Py_DECREF
(
closeresult
);
Py_DECREF
(
closeresult
);
}
}
if
(
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"i|s:fileio"
,
kwlist
,
&
fd
,
&
mode
))
{
if
(
fd
<
0
)
{
PyErr_SetString
(
PyExc_ValueError
,
"Negative filedescriptor"
);
return
-
1
;
}
}
else
{
PyErr_Clear
();
#ifdef Py_WIN_WIDE_FILENAMES
#ifdef Py_WIN_WIDE_FILENAMES
if
(
GetVersion
()
<
0x80000000
)
{
/* On NT, so wide API available */
if
(
GetVersion
()
<
0x80000000
)
{
/* On NT, so wide API available */
PyObject
*
po
;
PyObject
*
po
;
if
(
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"U|s:fileio"
,
if
(
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"U|s:fileio"
,
kwlist
,
&
po
,
&
mode
))
{
kwlist
,
&
po
,
&
mode
))
{
...
@@ -155,17 +168,18 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
...
@@ -155,17 +168,18 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
}
}
PyErr_SetString
(
PyExc_NotImplementedError
,
PyErr_SetString
(
PyExc_NotImplementedError
,
"Windows wide filenames are not yet supported"
);
"Windows wide filenames are not yet supported"
);
goto
error
;
goto
error
;
}
}
#endif
#endif
if
(
!
wideargument
)
{
if
(
!
wideargument
)
{
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"et|s:fileio"
,
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"et|s:fileio"
,
kwlist
,
kwlist
,
Py_FileSystemDefaultEncoding
,
Py_FileSystemDefaultEncoding
,
&
name
,
&
mode
))
&
name
,
&
mode
))
goto
error
;
goto
error
;
}
}
}
self
->
readable
=
self
->
writable
=
0
;
self
->
readable
=
self
->
writable
=
0
;
...
@@ -224,13 +238,19 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
...
@@ -224,13 +238,19 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
flags
|=
O_BINARY
;
flags
|=
O_BINARY
;
#endif
#endif
Py_BEGIN_ALLOW_THREADS
if
(
fd
>=
0
)
{
errno
=
0
;
self
->
fd
=
fd
;
self
->
fd
=
open
(
name
,
flags
,
0666
);
/* XXX Should we set self->own_fd = 0 ??? */
Py_END_ALLOW_THREADS
}
if
(
self
->
fd
<
0
||
dircheck
(
self
)
<
0
)
{
else
{
PyErr_SetFromErrnoWithFilename
(
PyExc_IOError
,
name
);
Py_BEGIN_ALLOW_THREADS
goto
error
;
errno
=
0
;
self
->
fd
=
open
(
name
,
flags
,
0666
);
Py_END_ALLOW_THREADS
if
(
self
->
fd
<
0
||
dircheck
(
self
)
<
0
)
{
PyErr_SetFromErrnoWithFilename
(
PyExc_IOError
,
name
);
goto
error
;
}
}
}
goto
done
;
goto
done
;
...
@@ -652,6 +672,18 @@ static PyMethodDef fileio_methods[] = {
...
@@ -652,6 +672,18 @@ static PyMethodDef fileio_methods[] = {
{
NULL
,
NULL
}
/* sentinel */
{
NULL
,
NULL
}
/* sentinel */
};
};
/* 'closed' is an attribute for backwards compatibility reasons. */
static
PyObject
*
get_closed
(
PyFileIOObject
*
f
,
void
*
closure
)
{
return
PyBool_FromLong
((
long
)(
f
->
fd
<
0
));
}
static
PyGetSetDef
fileio_getsetlist
[]
=
{
{
"closed"
,
(
getter
)
get_closed
,
NULL
,
"True if the file is closed"
},
{
0
},
};
PyTypeObject
PyFileIO_Type
=
{
PyTypeObject
PyFileIO_Type
=
{
PyObject_HEAD_INIT
(
&
PyType_Type
)
PyObject_HEAD_INIT
(
&
PyType_Type
)
0
,
0
,
...
@@ -683,7 +715,7 @@ PyTypeObject PyFileIO_Type = {
...
@@ -683,7 +715,7 @@ PyTypeObject PyFileIO_Type = {
0
,
/* tp_iternext */
0
,
/* tp_iternext */
fileio_methods
,
/* tp_methods */
fileio_methods
,
/* tp_methods */
0
,
/* tp_members */
0
,
/* tp_members */
0
,
/* tp_getset */
fileio_getsetlist
,
/* tp_getset */
0
,
/* tp_base */
0
,
/* tp_base */
0
,
/* tp_dict */
0
,
/* tp_dict */
0
,
/* tp_descr_get */
0
,
/* tp_descr_get */
...
...
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