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
b176d403
Commit
b176d403
authored
Jan 20, 2015
by
Zachary Ware
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #23280: Fix docstrings for binascii.(un)hexlify
parent
5a494f6a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
103 additions
and
6 deletions
+103
-6
Lib/test/test_binascii.py
Lib/test/test_binascii.py
+3
-1
Modules/binascii.c
Modules/binascii.c
+31
-4
Modules/clinic/binascii.c.h
Modules/clinic/binascii.c.h
+69
-1
No files found.
Lib/test/test_binascii.py
View file @
b176d403
...
...
@@ -162,7 +162,9 @@ class BinASCIITest(unittest.TestCase):
self
.
assertRaises
(
binascii
.
Error
,
binascii
.
a2b_hex
,
t
[:
-
1
])
self
.
assertRaises
(
binascii
.
Error
,
binascii
.
a2b_hex
,
t
[:
-
1
]
+
b'q'
)
self
.
assertEqual
(
binascii
.
hexlify
(
b'a'
),
b'61'
)
# Confirm that b2a_hex == hexlify and a2b_hex == unhexlify
self
.
assertEqual
(
binascii
.
hexlify
(
self
.
type2test
(
s
)),
t
)
self
.
assertEqual
(
binascii
.
unhexlify
(
self
.
type2test
(
t
)),
u
)
def
test_qp
(
self
):
# A test for SF bug 534347 (segfaults without the proper fix)
...
...
Modules/binascii.c
View file @
b176d403
...
...
@@ -1147,6 +1147,20 @@ binascii_b2a_hex_impl(PyModuleDef *module, Py_buffer *data)
return
retval
;
}
/*[clinic input]
binascii.hexlify = binascii.b2a_hex
Hexadecimal representation of binary data.
The return value is a bytes object.
[clinic start generated code]*/
static
PyObject
*
binascii_hexlify_impl
(
PyModuleDef
*
module
,
Py_buffer
*
data
)
/*[clinic end generated code: output=6098440091fb61dc input=2e3afae7f083f061]*/
{
return
binascii_b2a_hex_impl
(
module
,
data
);
}
static
int
to_int
(
int
c
)
...
...
@@ -1221,6 +1235,21 @@ binascii_a2b_hex_impl(PyModuleDef *module, Py_buffer *hexstr)
return
NULL
;
}
/*[clinic input]
binascii.unhexlify = binascii.a2b_hex
Binary data of hexadecimal representation.
hexstr must contain an even number of hex digits (upper or lower case).
[clinic start generated code]*/
static
PyObject
*
binascii_unhexlify_impl
(
PyModuleDef
*
module
,
Py_buffer
*
hexstr
)
/*[clinic end generated code: output=17cec7544499803e input=dd8c012725f462da]*/
{
return
binascii_a2b_hex_impl
(
module
,
hexstr
);
}
static
int
table_hex
[
128
]
=
{
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
-
1
,
...
...
@@ -1535,10 +1564,8 @@ static struct PyMethodDef binascii_module_methods[] = {
BINASCII_B2A_HQX_METHODDEF
BINASCII_A2B_HEX_METHODDEF
BINASCII_B2A_HEX_METHODDEF
{
"unhexlify"
,
(
PyCFunction
)
binascii_a2b_hex
,
METH_VARARGS
,
binascii_a2b_hex__doc__
},
{
"hexlify"
,
(
PyCFunction
)
binascii_b2a_hex
,
METH_VARARGS
,
binascii_b2a_hex__doc__
},
BINASCII_HEXLIFY_METHODDEF
BINASCII_UNHEXLIFY_METHODDEF
BINASCII_RLECODE_HQX_METHODDEF
BINASCII_RLEDECODE_HQX_METHODDEF
BINASCII_CRC_HQX_METHODDEF
...
...
Modules/clinic/binascii.c.h
View file @
b176d403
...
...
@@ -367,6 +367,40 @@ exit:
return
return_value
;
}
PyDoc_STRVAR
(
binascii_hexlify__doc__
,
"hexlify($module, data, /)
\n
"
"--
\n
"
"
\n
"
"Hexadecimal representation of binary data.
\n
"
"
\n
"
"The return value is a bytes object."
);
#define BINASCII_HEXLIFY_METHODDEF \
{"hexlify", (PyCFunction)binascii_hexlify, METH_VARARGS, binascii_hexlify__doc__},
static
PyObject
*
binascii_hexlify_impl
(
PyModuleDef
*
module
,
Py_buffer
*
data
);
static
PyObject
*
binascii_hexlify
(
PyModuleDef
*
module
,
PyObject
*
args
)
{
PyObject
*
return_value
=
NULL
;
Py_buffer
data
=
{
NULL
,
NULL
};
if
(
!
PyArg_ParseTuple
(
args
,
"y*:hexlify"
,
&
data
))
goto
exit
;
return_value
=
binascii_hexlify_impl
(
module
,
&
data
);
exit:
/* Cleanup for data */
if
(
data
.
obj
)
PyBuffer_Release
(
&
data
);
return
return_value
;
}
PyDoc_STRVAR
(
binascii_a2b_hex__doc__
,
"a2b_hex($module, hexstr, /)
\n
"
"--
\n
"
...
...
@@ -402,6 +436,40 @@ exit:
return
return_value
;
}
PyDoc_STRVAR
(
binascii_unhexlify__doc__
,
"unhexlify($module, hexstr, /)
\n
"
"--
\n
"
"
\n
"
"Binary data of hexadecimal representation.
\n
"
"
\n
"
"hexstr must contain an even number of hex digits (upper or lower case)."
);
#define BINASCII_UNHEXLIFY_METHODDEF \
{"unhexlify", (PyCFunction)binascii_unhexlify, METH_VARARGS, binascii_unhexlify__doc__},
static
PyObject
*
binascii_unhexlify_impl
(
PyModuleDef
*
module
,
Py_buffer
*
hexstr
);
static
PyObject
*
binascii_unhexlify
(
PyModuleDef
*
module
,
PyObject
*
args
)
{
PyObject
*
return_value
=
NULL
;
Py_buffer
hexstr
=
{
NULL
,
NULL
};
if
(
!
PyArg_ParseTuple
(
args
,
"O&:unhexlify"
,
ascii_buffer_converter
,
&
hexstr
))
goto
exit
;
return_value
=
binascii_unhexlify_impl
(
module
,
&
hexstr
);
exit:
/* Cleanup for hexstr */
if
(
hexstr
.
obj
)
PyBuffer_Release
(
&
hexstr
);
return
return_value
;
}
PyDoc_STRVAR
(
binascii_a2b_qp__doc__
,
"a2b_qp($module, /, data, header=False)
\n
"
"--
\n
"
...
...
@@ -475,4 +543,4 @@ exit:
return
return_value
;
}
/*[clinic end generated code: output=
68e2bcc6956b6213
input=a9049054013a1b77]*/
/*[clinic end generated code: output=
e46d29f8c9adae7e
input=a9049054013a1b77]*/
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