Skip to content

Commit 4497eab

Browse files
Merge branch 'main' into bytes_per_sep-maxsize
2 parents 113cf3a + 42825e6 commit 4497eab

20 files changed

+993
-303
lines changed

Doc/c-api/descriptor.rst

Lines changed: 79 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,31 @@ Descriptor Objects
88
"Descriptors" are objects that describe some attribute of an object. They are
99
found in the dictionary of type objects.
1010

11-
.. XXX document these!
12-
1311
.. c:function:: PyObject* PyDescr_NewGetSet(PyTypeObject *type, struct PyGetSetDef *getset)
1412
13+
Create a new get-set descriptor for extension type *type* from the
14+
:c:type:`PyGetSetDef` structure *getset*.
15+
16+
Get-set descriptors expose attributes implemented by C getter and setter
17+
functions rather than stored directly in the instance. This is the same kind
18+
of descriptor created for entries in :c:member:`~PyTypeObject.tp_getset`, and
19+
it appears in Python as a :class:`types.GetSetDescriptorType` object.
20+
21+
On success, return a :term:`strong reference` to the descriptor. Return
22+
``NULL`` with an exception set on failure.
23+
24+
.. c:function:: PyObject* PyDescr_NewMember(PyTypeObject *type, struct PyMemberDef *member)
1525
16-
.. c:function:: PyObject* PyDescr_NewMember(PyTypeObject *type, struct PyMemberDef *meth)
26+
Create a new member descriptor for extension type *type* from the
27+
:c:type:`PyMemberDef` structure *member*.
1728
29+
Member descriptors expose fields in the type's C struct as Python
30+
attributes. This is the same kind of descriptor created for entries in
31+
:c:member:`~PyTypeObject.tp_members`, and it appears in Python as a
32+
:class:`types.MemberDescriptorType` object.
33+
34+
On success, return a :term:`strong reference` to the descriptor. Return
35+
``NULL`` with an exception set on failure.
1836
1937
.. c:var:: PyTypeObject PyMemberDescr_Type
2038
@@ -30,22 +48,53 @@ found in the dictionary of type objects.
3048
The type object for get/set descriptor objects created from
3149
:c:type:`PyGetSetDef` structures. These descriptors implement attributes
3250
whose value is computed by C getter and setter functions, and are used
33-
for many built-in type attributes.
51+
for many built-in type attributes. They correspond to
52+
:class:`types.GetSetDescriptorType` objects in Python.
3453
3554
3655
.. c:function:: PyObject* PyDescr_NewMethod(PyTypeObject *type, struct PyMethodDef *meth)
3756
57+
Create a new method descriptor for extension type *type* from the
58+
:c:type:`PyMethodDef` structure *meth*.
59+
60+
Method descriptors expose C functions as methods on a type. This is the same
61+
kind of descriptor created for entries in
62+
:c:member:`~PyTypeObject.tp_methods`, and it appears in Python as a
63+
:class:`types.MethodDescriptorType` object.
64+
65+
On success, return a :term:`strong reference` to the descriptor. Return
66+
``NULL`` with an exception set on failure.
3867
3968
.. c:var:: PyTypeObject PyMethodDescr_Type
4069
4170
The type object for method descriptor objects created from
4271
:c:type:`PyMethodDef` structures. These descriptors expose C functions as
43-
methods on a type, and correspond to :class:`types.MemberDescriptorType`
72+
methods on a type, and correspond to :class:`types.MethodDescriptorType`
4473
objects in Python.
4574
4675
47-
.. c:function:: PyObject* PyDescr_NewWrapper(PyTypeObject *type, struct wrapperbase *wrapper, void *wrapped)
76+
.. c:struct:: wrapperbase
77+
78+
Describes a slot wrapper used by :c:func:`PyDescr_NewWrapper`.
4879
80+
Each ``wrapperbase`` record stores the Python-visible name and metadata for a
81+
special method implemented by a type slot, together with the wrapper
82+
function used to adapt that slot to Python's calling convention.
83+
84+
.. c:function:: PyObject* PyDescr_NewWrapper(PyTypeObject *type, struct wrapperbase *base, void *wrapped)
85+
86+
Create a new wrapper descriptor for extension type *type* from the
87+
:c:struct:`wrapperbase` structure *base* and the wrapped slot function
88+
pointer
89+
*wrapped*.
90+
91+
Wrapper descriptors expose special methods implemented by type slots. This
92+
is the same kind of descriptor that CPython creates for slot-based special
93+
methods such as ``__repr__`` or ``__add__``, and it appears in Python as a
94+
:class:`types.WrapperDescriptorType` object.
95+
96+
On success, return a :term:`strong reference` to the descriptor. Return
97+
``NULL`` with an exception set on failure.
4998
5099
.. c:var:: PyTypeObject PyWrapperDescr_Type
51100
@@ -58,6 +107,16 @@ found in the dictionary of type objects.
58107
59108
.. c:function:: PyObject* PyDescr_NewClassMethod(PyTypeObject *type, PyMethodDef *method)
60109
110+
Create a new class method descriptor for extension type *type* from the
111+
:c:type:`PyMethodDef` structure *method*.
112+
113+
Class method descriptors expose C methods that receive the class rather than
114+
an instance when accessed. This is the same kind of descriptor created for
115+
``METH_CLASS`` entries in :c:member:`~PyTypeObject.tp_methods`, and it
116+
appears in Python as a :class:`types.ClassMethodDescriptorType` object.
117+
118+
On success, return a :term:`strong reference` to the descriptor. Return
119+
``NULL`` with an exception set on failure.
61120
62121
.. c:function:: int PyDescr_IsData(PyObject *descr)
63122
@@ -66,8 +125,18 @@ found in the dictionary of type objects.
66125
no error checking.
67126
68127
69-
.. c:function:: PyObject* PyWrapper_New(PyObject *, PyObject *)
128+
.. c:function:: PyObject* PyWrapper_New(PyObject *d, PyObject *self)
129+
130+
Create a new bound wrapper object from the wrapper descriptor *d* and the
131+
instance *self*.
132+
133+
This is the bound form of a wrapper descriptor created by
134+
:c:func:`PyDescr_NewWrapper`. CPython creates these objects when a slot
135+
wrapper is accessed through an instance, and they appear in Python as
136+
:class:`types.MethodWrapperType` objects.
70137
138+
On success, return a :term:`strong reference` to the wrapper object. Return
139+
``NULL`` with an exception set on failure.
71140
72141
.. c:macro:: PyDescr_COMMON
73142
@@ -104,9 +173,9 @@ Built-in descriptors
104173
.. c:var:: PyTypeObject PyClassMethodDescr_Type
105174
106175
The type object for C-level class method descriptor objects.
107-
This is the type of the descriptors created for :func:`classmethod` defined in
108-
C extension types, and is the same object as :class:`classmethod`
109-
in Python.
176+
This is the type of the descriptors created for :func:`classmethod` defined
177+
in C extension types, and corresponds to
178+
:class:`types.ClassMethodDescriptorType` objects in Python.
110179
111180
112181
.. c:function:: PyObject *PyClassMethod_New(PyObject *callable)

Doc/library/base64.rst

Lines changed: 69 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,20 @@ POST request.
146146
Accepting the ``+`` and ``/`` characters is now deprecated.
147147

148148

149-
.. function:: b32encode(s)
149+
.. function:: b32encode(s, *, wrapcol=0)
150150

151151
Encode the :term:`bytes-like object` *s* using Base32 and return the
152152
encoded :class:`bytes`.
153153

154+
If *wrapcol* is non-zero, insert a newline (``b'\n'``) character
155+
after at most every *wrapcol* characters.
156+
If *wrapcol* is zero (default), do not add any newlines.
157+
158+
.. versionchanged:: next
159+
Added the *wrapcol* parameter.
160+
154161

155-
.. function:: b32decode(s, casefold=False, map01=None)
162+
.. function:: b32decode(s, casefold=False, map01=None, *, ignorechars=b'')
156163

157164
Decode the Base32 encoded :term:`bytes-like object` or ASCII string *s* and
158165
return the decoded :class:`bytes`.
@@ -168,20 +175,29 @@ POST request.
168175
digit 0 is always mapped to the letter O). For security purposes the default is
169176
``None``, so that 0 and 1 are not allowed in the input.
170177

178+
*ignorechars* should be a :term:`bytes-like object` containing characters
179+
to ignore from the input.
180+
171181
A :exc:`binascii.Error` is raised if *s* is
172182
incorrectly padded or if there are non-alphabet characters present in the
173183
input.
174184

185+
.. versionchanged:: next
186+
Added the *ignorechars* parameter.
187+
175188

176-
.. function:: b32hexencode(s)
189+
.. function:: b32hexencode(s, *, wrapcol=0)
177190

178191
Similar to :func:`b32encode` but uses the Extended Hex Alphabet, as defined in
179192
:rfc:`4648`.
180193

181194
.. versionadded:: 3.10
182195

196+
.. versionchanged:: next
197+
Added the *wrapcol* parameter.
198+
183199

184-
.. function:: b32hexdecode(s, casefold=False)
200+
.. function:: b32hexdecode(s, casefold=False, *, ignorechars=b'')
185201

186202
Similar to :func:`b32decode` but uses the Extended Hex Alphabet, as defined in
187203
:rfc:`4648`.
@@ -193,14 +209,24 @@ POST request.
193209

194210
.. versionadded:: 3.10
195211

212+
.. versionchanged:: next
213+
Added the *ignorechars* parameter.
214+
196215

197-
.. function:: b16encode(s)
216+
.. function:: b16encode(s, *, wrapcol=0)
198217

199218
Encode the :term:`bytes-like object` *s* using Base16 and return the
200219
encoded :class:`bytes`.
201220

221+
If *wrapcol* is non-zero, insert a newline (``b'\n'``) character
222+
after at most every *wrapcol* characters.
223+
If *wrapcol* is zero (default), do not add any newlines.
224+
225+
.. versionchanged:: next
226+
Added the *wrapcol* parameter.
202227

203-
.. function:: b16decode(s, casefold=False)
228+
229+
.. function:: b16decode(s, casefold=False, *, ignorechars=b'')
204230

205231
Decode the Base16 encoded :term:`bytes-like object` or ASCII string *s* and
206232
return the decoded :class:`bytes`.
@@ -209,10 +235,17 @@ POST request.
209235
lowercase alphabet is acceptable as input. For security purposes, the default
210236
is ``False``.
211237

238+
*ignorechars* should be a :term:`bytes-like object` containing characters
239+
to ignore from the input.
240+
212241
A :exc:`binascii.Error` is raised if *s* is
213242
incorrectly padded or if there are non-alphabet characters present in the
214243
input.
215244

245+
.. versionchanged:: next
246+
Added the *ignorechars* parameter.
247+
248+
216249
.. _base64-base-85:
217250

218251
Base85 Encodings
@@ -277,27 +310,40 @@ Refer to the documentation of the individual functions for more information.
277310
.. versionadded:: 3.4
278311

279312

280-
.. function:: b85encode(b, pad=False)
313+
.. function:: b85encode(b, pad=False, *, wrapcol=0)
281314

282315
Encode the :term:`bytes-like object` *b* using base85 (as used in e.g.
283316
git-style binary diffs) and return the encoded :class:`bytes`.
284317

285318
If *pad* is true, the input is padded with ``b'\0'`` so its length is a
286319
multiple of 4 bytes before encoding.
287320

321+
If *wrapcol* is non-zero, insert a newline (``b'\n'``) character
322+
after at most every *wrapcol* characters.
323+
If *wrapcol* is zero (default), do not add any newlines.
324+
288325
.. versionadded:: 3.4
289326

327+
.. versionchanged:: next
328+
Added the *wrapcol* parameter.
290329

291-
.. function:: b85decode(b)
330+
331+
.. function:: b85decode(b, *, ignorechars=b'')
292332

293333
Decode the base85-encoded :term:`bytes-like object` or ASCII string *b* and
294334
return the decoded :class:`bytes`. Padding is implicitly removed, if
295335
necessary.
296336

337+
*ignorechars* should be a :term:`bytes-like object` containing characters
338+
to ignore from the input.
339+
297340
.. versionadded:: 3.4
298341

342+
.. versionchanged:: next
343+
Added the *ignorechars* parameter.
344+
299345

300-
.. function:: z85encode(s, pad=False)
346+
.. function:: z85encode(s, pad=False, *, wrapcol=0)
301347

302348
Encode the :term:`bytes-like object` *s* using Z85 (as used in ZeroMQ)
303349
and return the encoded :class:`bytes`. See `Z85 specification
@@ -306,20 +352,33 @@ Refer to the documentation of the individual functions for more information.
306352
If *pad* is true, the input is padded with ``b'\0'`` so its length is a
307353
multiple of 4 bytes before encoding.
308354

355+
If *wrapcol* is non-zero, insert a newline (``b'\n'``) character
356+
after at most every *wrapcol* characters.
357+
If *wrapcol* is zero (default), do not add any newlines.
358+
309359
.. versionadded:: 3.13
310360

311361
.. versionchanged:: 3.15
312362
The *pad* parameter was added.
313363

364+
.. versionchanged:: next
365+
Added the *wrapcol* parameter.
366+
314367

315-
.. function:: z85decode(s)
368+
.. function:: z85decode(s, *, ignorechars=b'')
316369

317370
Decode the Z85-encoded :term:`bytes-like object` or ASCII string *s* and
318371
return the decoded :class:`bytes`. See `Z85 specification
319372
<https://rfc.zeromq.org/spec/32/>`_ for more information.
320373

374+
*ignorechars* should be a :term:`bytes-like object` containing characters
375+
to ignore from the input.
376+
321377
.. versionadded:: 3.13
322378

379+
.. versionchanged:: next
380+
Added the *ignorechars* parameter.
381+
323382

324383
.. _base64-legacy:
325384

0 commit comments

Comments
 (0)