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
745d54d2
Commit
745d54d2
authored
Nov 16, 2013
by
Ezio Melotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#17806: Added keyword-argument support for "tabsize" to str/bytes.expandtabs().
parent
b41c2547
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
51 additions
and
23 deletions
+51
-23
Doc/library/stdtypes.rst
Doc/library/stdtypes.rst
+1
-1
Lib/test/buffer_tests.py
Lib/test/buffer_tests.py
+11
-5
Lib/test/string_tests.py
Lib/test/string_tests.py
+20
-7
Misc/NEWS
Misc/NEWS
+3
-0
Objects/bytearrayobject.c
Objects/bytearrayobject.c
+1
-1
Objects/bytesobject.c
Objects/bytesobject.c
+1
-1
Objects/stringlib/transmogrify.h
Objects/stringlib/transmogrify.h
+5
-3
Objects/unicodeobject.c
Objects/unicodeobject.c
+9
-5
No files found.
Doc/library/stdtypes.rst
View file @
745d54d2
...
...
@@ -1523,7 +1523,7 @@ expression support in the :mod:`re` module).
at that position.
.. method:: str.expandtabs(
[tabsize]
)
.. method:: str.expandtabs(
tabsize=8
)
Return a copy of the string where all tab characters are replaced by one or
more spaces, depending on the current column and the given tab size. Tab
...
...
Lib/test/buffer_tests.py
View file @
745d54d2
...
...
@@ -160,14 +160,20 @@ class MixinBytesBufferCommonTests(object):
self
.
marshal
(
b'abc
\
r
ab
\
t
def
\
n
g
\
t
hi'
).
expandtabs
(
8
))
self
.
assertEqual
(
b'abc
\
r
ab def
\
n
g hi'
,
self
.
marshal
(
b'abc
\
r
ab
\
t
def
\
n
g
\
t
hi'
).
expandtabs
(
4
))
self
.
assertEqual
(
b'abc
\
r
\
n
ab def
\
n
g hi'
,
self
.
marshal
(
b'abc
\
r
\
n
ab
\
t
def
\
n
g
\
t
hi'
).
expandtabs
())
self
.
assertEqual
(
b'abc
\
r
\
n
ab def
\
n
g hi'
,
self
.
marshal
(
b'abc
\
r
\
n
ab
\
t
def
\
n
g
\
t
hi'
).
expandtabs
(
8
))
self
.
assertEqual
(
b'abc
\
r
\
n
ab def
\
n
g hi'
,
self
.
marshal
(
b'abc
\
r
\
n
ab
\
t
def
\
n
g
\
t
hi'
).
expandtabs
(
4
))
self
.
assertEqual
(
b'abc
\
r
ab def
\
n
g hi'
,
self
.
marshal
(
b'abc
\
r
ab
\
t
def
\
n
g
\
t
hi'
).
expandtabs
())
self
.
assertEqual
(
b'abc
\
r
ab def
\
n
g hi'
,
self
.
marshal
(
b'abc
\
r
ab
\
t
def
\
n
g
\
t
hi'
).
expandtabs
(
8
))
self
.
assertEqual
(
b'abc
\
r
\
n
ab
\
r
\
n
def
\
n
g
\
r
\
n
hi'
,
self
.
marshal
(
b'abc
\
r
\
n
ab
\
r
\
n
def
\
n
g
\
r
\
n
hi'
).
expandtabs
(
4
))
self
.
marshal
(
b'abc
\
r
\
n
ab
\
r
\
n
def
\
n
g
\
r
\
n
hi'
).
expandtabs
(
4
))
# check keyword args
self
.
assertEqual
(
b'abc
\
r
ab def
\
n
g hi'
,
self
.
marshal
(
b'abc
\
r
ab
\
t
def
\
n
g
\
t
hi'
).
expandtabs
(
tabsize
=
8
))
self
.
assertEqual
(
b'abc
\
r
ab def
\
n
g hi'
,
self
.
marshal
(
b'abc
\
r
ab
\
t
def
\
n
g
\
t
hi'
).
expandtabs
(
tabsize
=
4
))
self
.
assertEqual
(
b' a
\
n
b'
,
self
.
marshal
(
b'
\
t
a
\
n
\
t
b'
).
expandtabs
(
1
))
self
.
assertRaises
(
TypeError
,
self
.
marshal
(
b'hello'
).
expandtabs
,
42
,
42
)
...
...
Lib/test/string_tests.py
View file @
745d54d2
...
...
@@ -328,13 +328,26 @@ class BaseTest:
self
.
checkraises
(
TypeError
,
'hello'
,
'upper'
,
42
)
def
test_expandtabs
(
self
):
self
.
checkequal
(
'abc
\
r
ab def
\
n
g hi'
,
'abc
\
r
ab
\
t
def
\
n
g
\
t
hi'
,
'expandtabs'
)
self
.
checkequal
(
'abc
\
r
ab def
\
n
g hi'
,
'abc
\
r
ab
\
t
def
\
n
g
\
t
hi'
,
'expandtabs'
,
8
)
self
.
checkequal
(
'abc
\
r
ab def
\
n
g hi'
,
'abc
\
r
ab
\
t
def
\
n
g
\
t
hi'
,
'expandtabs'
,
4
)
self
.
checkequal
(
'abc
\
r
\
n
ab def
\
n
g hi'
,
'abc
\
r
\
n
ab
\
t
def
\
n
g
\
t
hi'
,
'expandtabs'
,
4
)
self
.
checkequal
(
'abc
\
r
ab def
\
n
g hi'
,
'abc
\
r
ab
\
t
def
\
n
g
\
t
hi'
,
'expandtabs'
)
self
.
checkequal
(
'abc
\
r
ab def
\
n
g hi'
,
'abc
\
r
ab
\
t
def
\
n
g
\
t
hi'
,
'expandtabs'
,
8
)
self
.
checkequal
(
'abc
\
r
\
n
ab
\
r
\
n
def
\
n
g
\
r
\
n
hi'
,
'abc
\
r
\
n
ab
\
r
\
n
def
\
n
g
\
r
\
n
hi'
,
'expandtabs'
,
4
)
self
.
checkequal
(
'abc
\
r
ab def
\
n
g hi'
,
'abc
\
r
ab
\
t
def
\
n
g
\
t
hi'
,
'expandtabs'
)
self
.
checkequal
(
'abc
\
r
ab def
\
n
g hi'
,
'abc
\
r
ab
\
t
def
\
n
g
\
t
hi'
,
'expandtabs'
,
8
)
self
.
checkequal
(
'abc
\
r
ab def
\
n
g hi'
,
'abc
\
r
ab
\
t
def
\
n
g
\
t
hi'
,
'expandtabs'
,
4
)
self
.
checkequal
(
'abc
\
r
\
n
ab def
\
n
g hi'
,
'abc
\
r
\
n
ab
\
t
def
\
n
g
\
t
hi'
,
'expandtabs'
)
self
.
checkequal
(
'abc
\
r
\
n
ab def
\
n
g hi'
,
'abc
\
r
\
n
ab
\
t
def
\
n
g
\
t
hi'
,
'expandtabs'
,
8
)
self
.
checkequal
(
'abc
\
r
\
n
ab def
\
n
g hi'
,
'abc
\
r
\
n
ab
\
t
def
\
n
g
\
t
hi'
,
'expandtabs'
,
4
)
self
.
checkequal
(
'abc
\
r
\
n
ab
\
r
\
n
def
\
n
g
\
r
\
n
hi'
,
'abc
\
r
\
n
ab
\
r
\
n
def
\
n
g
\
r
\
n
hi'
,
'expandtabs'
,
4
)
# check keyword args
self
.
checkequal
(
'abc
\
r
ab def
\
n
g hi'
,
'abc
\
r
ab
\
t
def
\
n
g
\
t
hi'
,
'expandtabs'
,
tabsize
=
8
)
self
.
checkequal
(
'abc
\
r
ab def
\
n
g hi'
,
'abc
\
r
ab
\
t
def
\
n
g
\
t
hi'
,
'expandtabs'
,
tabsize
=
4
)
self
.
checkequal
(
' a
\
n
b'
,
'
\
t
a
\
n
\
t
b'
,
'expandtabs'
,
1
)
self
.
checkraises
(
TypeError
,
'hello'
,
'expandtabs'
,
42
,
42
)
...
...
Misc/NEWS
View file @
745d54d2
...
...
@@ -10,6 +10,9 @@ Projected release date: 2013-11-24
Core and Builtins
-----------------
- Issue #17806: Added keyword-argument support for "tabsize" to
str/bytes.expandtabs().
- Issue #17828: Output type errors in str.encode(), bytes.decode() and
bytearray.decode() now direct users to codecs.encode() or codecs.decode()
as appropriate.
...
...
Objects/bytearrayobject.c
View file @
745d54d2
...
...
@@ -2805,7 +2805,7 @@ bytearray_methods[] = {
{
"count"
,
(
PyCFunction
)
bytearray_count
,
METH_VARARGS
,
count__doc__
},
{
"decode"
,
(
PyCFunction
)
bytearray_decode
,
METH_VARARGS
|
METH_KEYWORDS
,
decode_doc
},
{
"endswith"
,
(
PyCFunction
)
bytearray_endswith
,
METH_VARARGS
,
endswith__doc__
},
{
"expandtabs"
,
(
PyCFunction
)
stringlib_expandtabs
,
METH_VARARGS
,
{
"expandtabs"
,
(
PyCFunction
)
stringlib_expandtabs
,
METH_VARARGS
|
METH_KEYWORDS
,
expandtabs__doc__
},
{
"extend"
,
(
PyCFunction
)
bytearray_extend
,
METH_O
,
extend__doc__
},
{
"find"
,
(
PyCFunction
)
bytearray_find
,
METH_VARARGS
,
find__doc__
},
...
...
Objects/bytesobject.c
View file @
745d54d2
...
...
@@ -2389,7 +2389,7 @@ bytes_methods[] = {
{
"decode"
,
(
PyCFunction
)
bytes_decode
,
METH_VARARGS
|
METH_KEYWORDS
,
decode__doc__
},
{
"endswith"
,
(
PyCFunction
)
bytes_endswith
,
METH_VARARGS
,
endswith__doc__
},
{
"expandtabs"
,
(
PyCFunction
)
stringlib_expandtabs
,
METH_VARARGS
,
{
"expandtabs"
,
(
PyCFunction
)
stringlib_expandtabs
,
METH_VARARGS
|
METH_KEYWORDS
,
expandtabs__doc__
},
{
"find"
,
(
PyCFunction
)
bytes_find
,
METH_VARARGS
,
find__doc__
},
{
"fromhex"
,
(
PyCFunction
)
bytes_fromhex
,
METH_VARARGS
|
METH_CLASS
,
...
...
Objects/stringlib/transmogrify.h
View file @
745d54d2
...
...
@@ -5,21 +5,23 @@
shared code in bytes_methods.c to cut down on duplicate code bloat. */
PyDoc_STRVAR
(
expandtabs__doc__
,
"B.expandtabs(
[tabsize]
) -> copy of B
\n
\
"B.expandtabs(
tabsize=8
) -> copy of B
\n
\
\n
\
Return a copy of B where all tab characters are expanded using spaces.
\n
\
If tabsize is not given, a tab size of 8 characters is assumed."
);
static
PyObject
*
stringlib_expandtabs
(
PyObject
*
self
,
PyObject
*
args
)
stringlib_expandtabs
(
PyObject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
{
const
char
*
e
,
*
p
;
char
*
q
;
size_t
i
,
j
;
PyObject
*
u
;
static
char
*
kwlist
[]
=
{
"tabsize"
,
0
};
int
tabsize
=
8
;
if
(
!
PyArg_ParseTuple
(
args
,
"|i:expandtabs"
,
&
tabsize
))
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"|i:expandtabs"
,
kwlist
,
&
tabsize
))
return
NULL
;
/* First pass: determine size of output string */
...
...
Objects/unicodeobject.c
View file @
745d54d2
...
...
@@ -11010,23 +11010,25 @@ unicode_encode(PyObject *self, PyObject *args, PyObject *kwargs)
}
PyDoc_STRVAR
(
expandtabs__doc__
,
"S.expandtabs(
[tabsize]
) -> str
\n
\
"S.expandtabs(
tabsize=8
) -> str
\n
\
\n
\
Return a copy of S where all tab characters are expanded using spaces.
\n
\
If tabsize is not given, a tab size of 8 characters is assumed."
);
static
PyObject
*
unicode_expandtabs
(
PyObject
*
self
,
PyObject
*
args
)
unicode_expandtabs
(
PyObject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
{
Py_ssize_t
i
,
j
,
line_pos
,
src_len
,
incr
;
Py_UCS4
ch
;
PyObject
*
u
;
void
*
src_data
,
*
dest_data
;
static
char
*
kwlist
[]
=
{
"tabsize"
,
0
};
int
tabsize
=
8
;
int
kind
;
int
found
;
if
(
!
PyArg_ParseTuple
(
args
,
"|i:expandtabs"
,
&
tabsize
))
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"|i:expandtabs"
,
kwlist
,
&
tabsize
))
return
NULL
;
if
(
PyUnicode_READY
(
self
)
==
-
1
)
...
...
@@ -13394,7 +13396,8 @@ static PyMethodDef unicode_methods[] = {
{
"title"
,
(
PyCFunction
)
unicode_title
,
METH_NOARGS
,
title__doc__
},
{
"center"
,
(
PyCFunction
)
unicode_center
,
METH_VARARGS
,
center__doc__
},
{
"count"
,
(
PyCFunction
)
unicode_count
,
METH_VARARGS
,
count__doc__
},
{
"expandtabs"
,
(
PyCFunction
)
unicode_expandtabs
,
METH_VARARGS
,
expandtabs__doc__
},
{
"expandtabs"
,
(
PyCFunction
)
unicode_expandtabs
,
METH_VARARGS
|
METH_KEYWORDS
,
expandtabs__doc__
},
{
"find"
,
(
PyCFunction
)
unicode_find
,
METH_VARARGS
,
find__doc__
},
{
"partition"
,
(
PyCFunction
)
unicode_partition
,
METH_O
,
partition__doc__
},
{
"index"
,
(
PyCFunction
)
unicode_index
,
METH_VARARGS
,
index__doc__
},
...
...
@@ -13406,7 +13409,8 @@ static PyMethodDef unicode_methods[] = {
{
"rjust"
,
(
PyCFunction
)
unicode_rjust
,
METH_VARARGS
,
rjust__doc__
},
{
"rstrip"
,
(
PyCFunction
)
unicode_rstrip
,
METH_VARARGS
,
rstrip__doc__
},
{
"rpartition"
,
(
PyCFunction
)
unicode_rpartition
,
METH_O
,
rpartition__doc__
},
{
"splitlines"
,
(
PyCFunction
)
unicode_splitlines
,
METH_VARARGS
|
METH_KEYWORDS
,
splitlines__doc__
},
{
"splitlines"
,
(
PyCFunction
)
unicode_splitlines
,
METH_VARARGS
|
METH_KEYWORDS
,
splitlines__doc__
},
{
"strip"
,
(
PyCFunction
)
unicode_strip
,
METH_VARARGS
,
strip__doc__
},
{
"swapcase"
,
(
PyCFunction
)
unicode_swapcase
,
METH_NOARGS
,
swapcase__doc__
},
{
"translate"
,
(
PyCFunction
)
unicode_translate
,
METH_O
,
translate__doc__
},
...
...
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