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
e6996ed5
Kaydet (Commit)
e6996ed5
authored
Kas 02, 2012
tarafından
Stefan Krah
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #16145: Support legacy strings in the _csv module.
üst
ed71918d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
6 deletions
+50
-6
test_csv.py
Lib/test/test_csv.py
+11
-0
_csv.c
Modules/_csv.c
+15
-6
_testcapimodule.c
Modules/_testcapimodule.c
+24
-0
No files found.
Lib/test/test_csv.py
Dosyayı görüntüle @
e6996ed5
...
...
@@ -197,6 +197,17 @@ class Test_Csv(unittest.TestCase):
fileobj
.
seek
(
0
)
self
.
assertEqual
(
fileobj
.
read
(),
"a,b
\r\n
c,d
\r\n
"
)
@support.cpython_only
def
test_writerows_legacy_strings
(
self
):
import
_testcapi
c
=
_testcapi
.
unicode_legacy_string
(
'a'
)
with
TemporaryFile
(
"w+"
,
newline
=
''
)
as
fileobj
:
writer
=
csv
.
writer
(
fileobj
)
writer
.
writerows
([[
c
]])
fileobj
.
seek
(
0
)
self
.
assertEqual
(
fileobj
.
read
(),
"a
\r\n
"
)
def
_read_test
(
self
,
input
,
expect
,
**
kwargs
):
reader
=
csv
.
reader
(
input
,
**
kwargs
)
result
=
list
(
reader
)
...
...
Modules/_csv.c
Dosyayı görüntüle @
e6996ed5
...
...
@@ -13,8 +13,6 @@ module instead.
#include "Python.h"
#include "structmember.h"
#define IS_BASESTRING(o) \
PyUnicode_Check(o)
typedef
struct
{
PyObject
*
error_obj
;
/* CSV exception */
...
...
@@ -248,6 +246,7 @@ _set_char(const char *name, Py_UCS4 *target, PyObject *src, Py_UCS4 dflt)
name
);
return
-
1
;
}
/* PyUnicode_READY() is called in PyUnicode_GetLength() */
if
(
len
>
0
)
*
target
=
PyUnicode_READ_CHAR
(
src
,
0
);
}
...
...
@@ -263,12 +262,14 @@ _set_str(const char *name, PyObject **target, PyObject *src, const char *dflt)
else
{
if
(
src
==
Py_None
)
*
target
=
NULL
;
else
if
(
!
IS_BASESTRING
(
src
))
{
else
if
(
!
PyUnicode_Check
(
src
))
{
PyErr_Format
(
PyExc_TypeError
,
"
\"
%s
\"
must be a string"
,
name
);
return
-
1
;
}
else
{
if
(
PyUnicode_READY
(
src
)
==
-
1
)
return
-
1
;
Py_XDECREF
(
*
target
);
Py_INCREF
(
src
);
*
target
=
src
;
...
...
@@ -357,7 +358,7 @@ dialect_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
return
NULL
;
if
(
dialect
!=
NULL
)
{
if
(
IS_BASESTRING
(
dialect
))
{
if
(
PyUnicode_Check
(
dialect
))
{
dialect
=
get_dialect_from_registry
(
dialect
);
if
(
dialect
==
NULL
)
return
NULL
;
...
...
@@ -808,6 +809,10 @@ Reader_iternext(ReaderObj *self)
Py_DECREF
(
lineobj
);
return
NULL
;
}
if
(
PyUnicode_READY
(
lineobj
)
==
-
1
)
{
Py_DECREF
(
lineobj
);
return
NULL
;
}
++
self
->
line_num
;
kind
=
PyUnicode_KIND
(
lineobj
);
data
=
PyUnicode_DATA
(
lineobj
);
...
...
@@ -1108,6 +1113,8 @@ join_append(WriterObj *self, PyObject *field, int *quoted, int quote_empty)
Py_ssize_t
rec_len
;
if
(
field
!=
NULL
)
{
if
(
PyUnicode_READY
(
field
)
==
-
1
)
return
0
;
field_kind
=
PyUnicode_KIND
(
field
);
field_data
=
PyUnicode_DATA
(
field
);
field_len
=
PyUnicode_GET_LENGTH
(
field
);
...
...
@@ -1403,11 +1410,13 @@ csv_register_dialect(PyObject *module, PyObject *args, PyObject *kwargs)
if
(
!
PyArg_UnpackTuple
(
args
,
""
,
1
,
2
,
&
name_obj
,
&
dialect_obj
))
return
NULL
;
if
(
!
IS_BASESTRING
(
name_obj
))
{
if
(
!
PyUnicode_Check
(
name_obj
))
{
PyErr_SetString
(
PyExc_TypeError
,
"dialect name must be a string
or unicode
"
);
"dialect name must be a string"
);
return
NULL
;
}
if
(
PyUnicode_READY
(
name_obj
)
==
-
1
)
return
NULL
;
dialect
=
_call_dialect
(
dialect_obj
,
kwargs
);
if
(
dialect
==
NULL
)
return
NULL
;
...
...
Modules/_testcapimodule.c
Dosyayı görüntüle @
e6996ed5
...
...
@@ -1520,6 +1520,29 @@ unicode_transformdecimaltoascii(PyObject *self, PyObject *args)
return
PyUnicode_TransformDecimalToASCII
(
unicode
,
length
);
}
static
PyObject
*
unicode_legacy_string
(
PyObject
*
self
,
PyObject
*
args
)
{
Py_UNICODE
*
data
;
Py_ssize_t
len
;
PyObject
*
u
;
if
(
!
PyArg_ParseTuple
(
args
,
"u#"
,
&
data
,
&
len
))
return
NULL
;
u
=
PyUnicode_FromUnicode
(
NULL
,
len
);
if
(
u
==
NULL
)
return
NULL
;
memcpy
(
PyUnicode_AS_UNICODE
(
u
),
data
,
len
*
sizeof
(
Py_UNICODE
));
if
(
len
>
0
)
{
/* The empty string is always ready. */
assert
(
!
PyUnicode_IS_READY
(
u
));
}
return
u
;
}
static
PyObject
*
getargs_w_star
(
PyObject
*
self
,
PyObject
*
args
)
{
...
...
@@ -2506,6 +2529,7 @@ static PyMethodDef TestMethods[] = {
{
"unicode_aswidecharstring"
,
unicode_aswidecharstring
,
METH_VARARGS
},
{
"unicode_encodedecimal"
,
unicode_encodedecimal
,
METH_VARARGS
},
{
"unicode_transformdecimaltoascii"
,
unicode_transformdecimaltoascii
,
METH_VARARGS
},
{
"unicode_legacy_string"
,
unicode_legacy_string
,
METH_VARARGS
},
#ifdef WITH_THREAD
{
"_test_thread_state"
,
test_thread_state
,
METH_VARARGS
},
{
"_pending_threadfunc"
,
pending_threadfunc
,
METH_VARARGS
},
...
...
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