LCOV - code coverage report
Current view: top level - Objects/clinic - bytesobject.c.h (source / functions) Hit Total Coverage
Test: CPython 3.12 LCOV report [commit 5e6661bce9] Lines: 78 339 23.0 %
Date: 2023-03-20 08:15:36 Functions: 5 18 27.8 %
Branches: 44 260 16.9 %

           Branch data     Line data    Source code
       1                 :            : /*[clinic input]
       2                 :            : preserve
       3                 :            : [clinic start generated code]*/
       4                 :            : 
       5                 :            : #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
       6                 :            : #  include "pycore_gc.h"            // PyGC_Head
       7                 :            : #  include "pycore_runtime.h"       // _Py_ID()
       8                 :            : #endif
       9                 :            : 
      10                 :            : 
      11                 :            : PyDoc_STRVAR(bytes___bytes____doc__,
      12                 :            : "__bytes__($self, /)\n"
      13                 :            : "--\n"
      14                 :            : "\n"
      15                 :            : "Convert this value to exact type bytes.");
      16                 :            : 
      17                 :            : #define BYTES___BYTES___METHODDEF    \
      18                 :            :     {"__bytes__", (PyCFunction)bytes___bytes__, METH_NOARGS, bytes___bytes____doc__},
      19                 :            : 
      20                 :            : static PyObject *
      21                 :            : bytes___bytes___impl(PyBytesObject *self);
      22                 :            : 
      23                 :            : static PyObject *
      24                 :          1 : bytes___bytes__(PyBytesObject *self, PyObject *Py_UNUSED(ignored))
      25                 :            : {
      26                 :          1 :     return bytes___bytes___impl(self);
      27                 :            : }
      28                 :            : 
      29                 :            : PyDoc_STRVAR(bytes_split__doc__,
      30                 :            : "split($self, /, sep=None, maxsplit=-1)\n"
      31                 :            : "--\n"
      32                 :            : "\n"
      33                 :            : "Return a list of the sections in the bytes, using sep as the delimiter.\n"
      34                 :            : "\n"
      35                 :            : "  sep\n"
      36                 :            : "    The delimiter according which to split the bytes.\n"
      37                 :            : "    None (the default value) means split on ASCII whitespace characters\n"
      38                 :            : "    (space, tab, return, newline, formfeed, vertical tab).\n"
      39                 :            : "  maxsplit\n"
      40                 :            : "    Maximum number of splits to do.\n"
      41                 :            : "    -1 (the default value) means no limit.");
      42                 :            : 
      43                 :            : #define BYTES_SPLIT_METHODDEF    \
      44                 :            :     {"split", _PyCFunction_CAST(bytes_split), METH_FASTCALL|METH_KEYWORDS, bytes_split__doc__},
      45                 :            : 
      46                 :            : static PyObject *
      47                 :            : bytes_split_impl(PyBytesObject *self, PyObject *sep, Py_ssize_t maxsplit);
      48                 :            : 
      49                 :            : static PyObject *
      50                 :          0 : bytes_split(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
      51                 :            : {
      52                 :          0 :     PyObject *return_value = NULL;
      53                 :            :     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
      54                 :            : 
      55                 :            :     #define NUM_KEYWORDS 2
      56                 :            :     static struct {
      57                 :            :         PyGC_Head _this_is_not_used;
      58                 :            :         PyObject_VAR_HEAD
      59                 :            :         PyObject *ob_item[NUM_KEYWORDS];
      60                 :            :     } _kwtuple = {
      61                 :            :         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
      62                 :            :         .ob_item = { &_Py_ID(sep), &_Py_ID(maxsplit), },
      63                 :            :     };
      64                 :            :     #undef NUM_KEYWORDS
      65                 :            :     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
      66                 :            : 
      67                 :            :     #else  // !Py_BUILD_CORE
      68                 :            :     #  define KWTUPLE NULL
      69                 :            :     #endif  // !Py_BUILD_CORE
      70                 :            : 
      71                 :            :     static const char * const _keywords[] = {"sep", "maxsplit", NULL};
      72                 :            :     static _PyArg_Parser _parser = {
      73                 :            :         .keywords = _keywords,
      74                 :            :         .fname = "split",
      75                 :            :         .kwtuple = KWTUPLE,
      76                 :            :     };
      77                 :            :     #undef KWTUPLE
      78                 :            :     PyObject *argsbuf[2];
      79         [ #  # ]:          0 :     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
      80                 :          0 :     PyObject *sep = Py_None;
      81                 :          0 :     Py_ssize_t maxsplit = -1;
      82                 :            : 
      83   [ #  #  #  #  :          0 :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
             #  #  #  # ]
      84         [ #  # ]:          0 :     if (!args) {
      85                 :          0 :         goto exit;
      86                 :            :     }
      87         [ #  # ]:          0 :     if (!noptargs) {
      88                 :          0 :         goto skip_optional_pos;
      89                 :            :     }
      90         [ #  # ]:          0 :     if (args[0]) {
      91                 :          0 :         sep = args[0];
      92         [ #  # ]:          0 :         if (!--noptargs) {
      93                 :          0 :             goto skip_optional_pos;
      94                 :            :         }
      95                 :            :     }
      96                 :            :     {
      97                 :          0 :         Py_ssize_t ival = -1;
      98                 :          0 :         PyObject *iobj = _PyNumber_Index(args[1]);
      99         [ #  # ]:          0 :         if (iobj != NULL) {
     100                 :          0 :             ival = PyLong_AsSsize_t(iobj);
     101                 :          0 :             Py_DECREF(iobj);
     102                 :            :         }
     103   [ #  #  #  # ]:          0 :         if (ival == -1 && PyErr_Occurred()) {
     104                 :          0 :             goto exit;
     105                 :            :         }
     106                 :          0 :         maxsplit = ival;
     107                 :            :     }
     108                 :          0 : skip_optional_pos:
     109                 :          0 :     return_value = bytes_split_impl(self, sep, maxsplit);
     110                 :            : 
     111                 :          0 : exit:
     112                 :          0 :     return return_value;
     113                 :            : }
     114                 :            : 
     115                 :            : PyDoc_STRVAR(bytes_partition__doc__,
     116                 :            : "partition($self, sep, /)\n"
     117                 :            : "--\n"
     118                 :            : "\n"
     119                 :            : "Partition the bytes into three parts using the given separator.\n"
     120                 :            : "\n"
     121                 :            : "This will search for the separator sep in the bytes. If the separator is found,\n"
     122                 :            : "returns a 3-tuple containing the part before the separator, the separator\n"
     123                 :            : "itself, and the part after it.\n"
     124                 :            : "\n"
     125                 :            : "If the separator is not found, returns a 3-tuple containing the original bytes\n"
     126                 :            : "object and two empty bytes objects.");
     127                 :            : 
     128                 :            : #define BYTES_PARTITION_METHODDEF    \
     129                 :            :     {"partition", (PyCFunction)bytes_partition, METH_O, bytes_partition__doc__},
     130                 :            : 
     131                 :            : static PyObject *
     132                 :            : bytes_partition_impl(PyBytesObject *self, Py_buffer *sep);
     133                 :            : 
     134                 :            : static PyObject *
     135                 :          0 : bytes_partition(PyBytesObject *self, PyObject *arg)
     136                 :            : {
     137                 :          0 :     PyObject *return_value = NULL;
     138                 :          0 :     Py_buffer sep = {NULL, NULL};
     139                 :            : 
     140         [ #  # ]:          0 :     if (PyObject_GetBuffer(arg, &sep, PyBUF_SIMPLE) != 0) {
     141                 :          0 :         goto exit;
     142                 :            :     }
     143         [ #  # ]:          0 :     if (!PyBuffer_IsContiguous(&sep, 'C')) {
     144                 :          0 :         _PyArg_BadArgument("partition", "argument", "contiguous buffer", arg);
     145                 :          0 :         goto exit;
     146                 :            :     }
     147                 :          0 :     return_value = bytes_partition_impl(self, &sep);
     148                 :            : 
     149                 :          0 : exit:
     150                 :            :     /* Cleanup for sep */
     151         [ #  # ]:          0 :     if (sep.obj) {
     152                 :          0 :        PyBuffer_Release(&sep);
     153                 :            :     }
     154                 :            : 
     155                 :          0 :     return return_value;
     156                 :            : }
     157                 :            : 
     158                 :            : PyDoc_STRVAR(bytes_rpartition__doc__,
     159                 :            : "rpartition($self, sep, /)\n"
     160                 :            : "--\n"
     161                 :            : "\n"
     162                 :            : "Partition the bytes into three parts using the given separator.\n"
     163                 :            : "\n"
     164                 :            : "This will search for the separator sep in the bytes, starting at the end. If\n"
     165                 :            : "the separator is found, returns a 3-tuple containing the part before the\n"
     166                 :            : "separator, the separator itself, and the part after it.\n"
     167                 :            : "\n"
     168                 :            : "If the separator is not found, returns a 3-tuple containing two empty bytes\n"
     169                 :            : "objects and the original bytes object.");
     170                 :            : 
     171                 :            : #define BYTES_RPARTITION_METHODDEF    \
     172                 :            :     {"rpartition", (PyCFunction)bytes_rpartition, METH_O, bytes_rpartition__doc__},
     173                 :            : 
     174                 :            : static PyObject *
     175                 :            : bytes_rpartition_impl(PyBytesObject *self, Py_buffer *sep);
     176                 :            : 
     177                 :            : static PyObject *
     178                 :          0 : bytes_rpartition(PyBytesObject *self, PyObject *arg)
     179                 :            : {
     180                 :          0 :     PyObject *return_value = NULL;
     181                 :          0 :     Py_buffer sep = {NULL, NULL};
     182                 :            : 
     183         [ #  # ]:          0 :     if (PyObject_GetBuffer(arg, &sep, PyBUF_SIMPLE) != 0) {
     184                 :          0 :         goto exit;
     185                 :            :     }
     186         [ #  # ]:          0 :     if (!PyBuffer_IsContiguous(&sep, 'C')) {
     187                 :          0 :         _PyArg_BadArgument("rpartition", "argument", "contiguous buffer", arg);
     188                 :          0 :         goto exit;
     189                 :            :     }
     190                 :          0 :     return_value = bytes_rpartition_impl(self, &sep);
     191                 :            : 
     192                 :          0 : exit:
     193                 :            :     /* Cleanup for sep */
     194         [ #  # ]:          0 :     if (sep.obj) {
     195                 :          0 :        PyBuffer_Release(&sep);
     196                 :            :     }
     197                 :            : 
     198                 :          0 :     return return_value;
     199                 :            : }
     200                 :            : 
     201                 :            : PyDoc_STRVAR(bytes_rsplit__doc__,
     202                 :            : "rsplit($self, /, sep=None, maxsplit=-1)\n"
     203                 :            : "--\n"
     204                 :            : "\n"
     205                 :            : "Return a list of the sections in the bytes, using sep as the delimiter.\n"
     206                 :            : "\n"
     207                 :            : "  sep\n"
     208                 :            : "    The delimiter according which to split the bytes.\n"
     209                 :            : "    None (the default value) means split on ASCII whitespace characters\n"
     210                 :            : "    (space, tab, return, newline, formfeed, vertical tab).\n"
     211                 :            : "  maxsplit\n"
     212                 :            : "    Maximum number of splits to do.\n"
     213                 :            : "    -1 (the default value) means no limit.\n"
     214                 :            : "\n"
     215                 :            : "Splitting is done starting at the end of the bytes and working to the front.");
     216                 :            : 
     217                 :            : #define BYTES_RSPLIT_METHODDEF    \
     218                 :            :     {"rsplit", _PyCFunction_CAST(bytes_rsplit), METH_FASTCALL|METH_KEYWORDS, bytes_rsplit__doc__},
     219                 :            : 
     220                 :            : static PyObject *
     221                 :            : bytes_rsplit_impl(PyBytesObject *self, PyObject *sep, Py_ssize_t maxsplit);
     222                 :            : 
     223                 :            : static PyObject *
     224                 :          0 : bytes_rsplit(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     225                 :            : {
     226                 :          0 :     PyObject *return_value = NULL;
     227                 :            :     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     228                 :            : 
     229                 :            :     #define NUM_KEYWORDS 2
     230                 :            :     static struct {
     231                 :            :         PyGC_Head _this_is_not_used;
     232                 :            :         PyObject_VAR_HEAD
     233                 :            :         PyObject *ob_item[NUM_KEYWORDS];
     234                 :            :     } _kwtuple = {
     235                 :            :         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     236                 :            :         .ob_item = { &_Py_ID(sep), &_Py_ID(maxsplit), },
     237                 :            :     };
     238                 :            :     #undef NUM_KEYWORDS
     239                 :            :     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     240                 :            : 
     241                 :            :     #else  // !Py_BUILD_CORE
     242                 :            :     #  define KWTUPLE NULL
     243                 :            :     #endif  // !Py_BUILD_CORE
     244                 :            : 
     245                 :            :     static const char * const _keywords[] = {"sep", "maxsplit", NULL};
     246                 :            :     static _PyArg_Parser _parser = {
     247                 :            :         .keywords = _keywords,
     248                 :            :         .fname = "rsplit",
     249                 :            :         .kwtuple = KWTUPLE,
     250                 :            :     };
     251                 :            :     #undef KWTUPLE
     252                 :            :     PyObject *argsbuf[2];
     253         [ #  # ]:          0 :     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
     254                 :          0 :     PyObject *sep = Py_None;
     255                 :          0 :     Py_ssize_t maxsplit = -1;
     256                 :            : 
     257   [ #  #  #  #  :          0 :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
             #  #  #  # ]
     258         [ #  # ]:          0 :     if (!args) {
     259                 :          0 :         goto exit;
     260                 :            :     }
     261         [ #  # ]:          0 :     if (!noptargs) {
     262                 :          0 :         goto skip_optional_pos;
     263                 :            :     }
     264         [ #  # ]:          0 :     if (args[0]) {
     265                 :          0 :         sep = args[0];
     266         [ #  # ]:          0 :         if (!--noptargs) {
     267                 :          0 :             goto skip_optional_pos;
     268                 :            :         }
     269                 :            :     }
     270                 :            :     {
     271                 :          0 :         Py_ssize_t ival = -1;
     272                 :          0 :         PyObject *iobj = _PyNumber_Index(args[1]);
     273         [ #  # ]:          0 :         if (iobj != NULL) {
     274                 :          0 :             ival = PyLong_AsSsize_t(iobj);
     275                 :          0 :             Py_DECREF(iobj);
     276                 :            :         }
     277   [ #  #  #  # ]:          0 :         if (ival == -1 && PyErr_Occurred()) {
     278                 :          0 :             goto exit;
     279                 :            :         }
     280                 :          0 :         maxsplit = ival;
     281                 :            :     }
     282                 :          0 : skip_optional_pos:
     283                 :          0 :     return_value = bytes_rsplit_impl(self, sep, maxsplit);
     284                 :            : 
     285                 :          0 : exit:
     286                 :          0 :     return return_value;
     287                 :            : }
     288                 :            : 
     289                 :            : PyDoc_STRVAR(bytes_join__doc__,
     290                 :            : "join($self, iterable_of_bytes, /)\n"
     291                 :            : "--\n"
     292                 :            : "\n"
     293                 :            : "Concatenate any number of bytes objects.\n"
     294                 :            : "\n"
     295                 :            : "The bytes whose method is called is inserted in between each pair.\n"
     296                 :            : "\n"
     297                 :            : "The result is returned as a new bytes object.\n"
     298                 :            : "\n"
     299                 :            : "Example: b\'.\'.join([b\'ab\', b\'pq\', b\'rs\']) -> b\'ab.pq.rs\'.");
     300                 :            : 
     301                 :            : #define BYTES_JOIN_METHODDEF    \
     302                 :            :     {"join", (PyCFunction)bytes_join, METH_O, bytes_join__doc__},
     303                 :            : 
     304                 :            : PyDoc_STRVAR(bytes_strip__doc__,
     305                 :            : "strip($self, bytes=None, /)\n"
     306                 :            : "--\n"
     307                 :            : "\n"
     308                 :            : "Strip leading and trailing bytes contained in the argument.\n"
     309                 :            : "\n"
     310                 :            : "If the argument is omitted or None, strip leading and trailing ASCII whitespace.");
     311                 :            : 
     312                 :            : #define BYTES_STRIP_METHODDEF    \
     313                 :            :     {"strip", _PyCFunction_CAST(bytes_strip), METH_FASTCALL, bytes_strip__doc__},
     314                 :            : 
     315                 :            : static PyObject *
     316                 :            : bytes_strip_impl(PyBytesObject *self, PyObject *bytes);
     317                 :            : 
     318                 :            : static PyObject *
     319                 :          0 : bytes_strip(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
     320                 :            : {
     321                 :          0 :     PyObject *return_value = NULL;
     322                 :          0 :     PyObject *bytes = Py_None;
     323                 :            : 
     324   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("strip", nargs, 0, 1)) {
                   #  # ]
     325                 :          0 :         goto exit;
     326                 :            :     }
     327         [ #  # ]:          0 :     if (nargs < 1) {
     328                 :          0 :         goto skip_optional;
     329                 :            :     }
     330                 :          0 :     bytes = args[0];
     331                 :          0 : skip_optional:
     332                 :          0 :     return_value = bytes_strip_impl(self, bytes);
     333                 :            : 
     334                 :          0 : exit:
     335                 :          0 :     return return_value;
     336                 :            : }
     337                 :            : 
     338                 :            : PyDoc_STRVAR(bytes_lstrip__doc__,
     339                 :            : "lstrip($self, bytes=None, /)\n"
     340                 :            : "--\n"
     341                 :            : "\n"
     342                 :            : "Strip leading bytes contained in the argument.\n"
     343                 :            : "\n"
     344                 :            : "If the argument is omitted or None, strip leading  ASCII whitespace.");
     345                 :            : 
     346                 :            : #define BYTES_LSTRIP_METHODDEF    \
     347                 :            :     {"lstrip", _PyCFunction_CAST(bytes_lstrip), METH_FASTCALL, bytes_lstrip__doc__},
     348                 :            : 
     349                 :            : static PyObject *
     350                 :            : bytes_lstrip_impl(PyBytesObject *self, PyObject *bytes);
     351                 :            : 
     352                 :            : static PyObject *
     353                 :          0 : bytes_lstrip(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
     354                 :            : {
     355                 :          0 :     PyObject *return_value = NULL;
     356                 :          0 :     PyObject *bytes = Py_None;
     357                 :            : 
     358   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("lstrip", nargs, 0, 1)) {
                   #  # ]
     359                 :          0 :         goto exit;
     360                 :            :     }
     361         [ #  # ]:          0 :     if (nargs < 1) {
     362                 :          0 :         goto skip_optional;
     363                 :            :     }
     364                 :          0 :     bytes = args[0];
     365                 :          0 : skip_optional:
     366                 :          0 :     return_value = bytes_lstrip_impl(self, bytes);
     367                 :            : 
     368                 :          0 : exit:
     369                 :          0 :     return return_value;
     370                 :            : }
     371                 :            : 
     372                 :            : PyDoc_STRVAR(bytes_rstrip__doc__,
     373                 :            : "rstrip($self, bytes=None, /)\n"
     374                 :            : "--\n"
     375                 :            : "\n"
     376                 :            : "Strip trailing bytes contained in the argument.\n"
     377                 :            : "\n"
     378                 :            : "If the argument is omitted or None, strip trailing ASCII whitespace.");
     379                 :            : 
     380                 :            : #define BYTES_RSTRIP_METHODDEF    \
     381                 :            :     {"rstrip", _PyCFunction_CAST(bytes_rstrip), METH_FASTCALL, bytes_rstrip__doc__},
     382                 :            : 
     383                 :            : static PyObject *
     384                 :            : bytes_rstrip_impl(PyBytesObject *self, PyObject *bytes);
     385                 :            : 
     386                 :            : static PyObject *
     387                 :          0 : bytes_rstrip(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
     388                 :            : {
     389                 :          0 :     PyObject *return_value = NULL;
     390                 :          0 :     PyObject *bytes = Py_None;
     391                 :            : 
     392   [ #  #  #  #  :          0 :     if (!_PyArg_CheckPositional("rstrip", nargs, 0, 1)) {
                   #  # ]
     393                 :          0 :         goto exit;
     394                 :            :     }
     395         [ #  # ]:          0 :     if (nargs < 1) {
     396                 :          0 :         goto skip_optional;
     397                 :            :     }
     398                 :          0 :     bytes = args[0];
     399                 :          0 : skip_optional:
     400                 :          0 :     return_value = bytes_rstrip_impl(self, bytes);
     401                 :            : 
     402                 :          0 : exit:
     403                 :          0 :     return return_value;
     404                 :            : }
     405                 :            : 
     406                 :            : PyDoc_STRVAR(bytes_translate__doc__,
     407                 :            : "translate($self, table, /, delete=b\'\')\n"
     408                 :            : "--\n"
     409                 :            : "\n"
     410                 :            : "Return a copy with each character mapped by the given translation table.\n"
     411                 :            : "\n"
     412                 :            : "  table\n"
     413                 :            : "    Translation table, which must be a bytes object of length 256.\n"
     414                 :            : "\n"
     415                 :            : "All characters occurring in the optional argument delete are removed.\n"
     416                 :            : "The remaining characters are mapped through the given translation table.");
     417                 :            : 
     418                 :            : #define BYTES_TRANSLATE_METHODDEF    \
     419                 :            :     {"translate", _PyCFunction_CAST(bytes_translate), METH_FASTCALL|METH_KEYWORDS, bytes_translate__doc__},
     420                 :            : 
     421                 :            : static PyObject *
     422                 :            : bytes_translate_impl(PyBytesObject *self, PyObject *table,
     423                 :            :                      PyObject *deletechars);
     424                 :            : 
     425                 :            : static PyObject *
     426                 :          0 : bytes_translate(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     427                 :            : {
     428                 :          0 :     PyObject *return_value = NULL;
     429                 :            :     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     430                 :            : 
     431                 :            :     #define NUM_KEYWORDS 1
     432                 :            :     static struct {
     433                 :            :         PyGC_Head _this_is_not_used;
     434                 :            :         PyObject_VAR_HEAD
     435                 :            :         PyObject *ob_item[NUM_KEYWORDS];
     436                 :            :     } _kwtuple = {
     437                 :            :         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     438                 :            :         .ob_item = { &_Py_ID(delete), },
     439                 :            :     };
     440                 :            :     #undef NUM_KEYWORDS
     441                 :            :     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     442                 :            : 
     443                 :            :     #else  // !Py_BUILD_CORE
     444                 :            :     #  define KWTUPLE NULL
     445                 :            :     #endif  // !Py_BUILD_CORE
     446                 :            : 
     447                 :            :     static const char * const _keywords[] = {"", "delete", NULL};
     448                 :            :     static _PyArg_Parser _parser = {
     449                 :            :         .keywords = _keywords,
     450                 :            :         .fname = "translate",
     451                 :            :         .kwtuple = KWTUPLE,
     452                 :            :     };
     453                 :            :     #undef KWTUPLE
     454                 :            :     PyObject *argsbuf[2];
     455         [ #  # ]:          0 :     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
     456                 :            :     PyObject *table;
     457                 :          0 :     PyObject *deletechars = NULL;
     458                 :            : 
     459   [ #  #  #  #  :          0 :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
             #  #  #  # ]
     460         [ #  # ]:          0 :     if (!args) {
     461                 :          0 :         goto exit;
     462                 :            :     }
     463                 :          0 :     table = args[0];
     464         [ #  # ]:          0 :     if (!noptargs) {
     465                 :          0 :         goto skip_optional_pos;
     466                 :            :     }
     467                 :          0 :     deletechars = args[1];
     468                 :          0 : skip_optional_pos:
     469                 :          0 :     return_value = bytes_translate_impl(self, table, deletechars);
     470                 :            : 
     471                 :          0 : exit:
     472                 :          0 :     return return_value;
     473                 :            : }
     474                 :            : 
     475                 :            : PyDoc_STRVAR(bytes_maketrans__doc__,
     476                 :            : "maketrans(frm, to, /)\n"
     477                 :            : "--\n"
     478                 :            : "\n"
     479                 :            : "Return a translation table useable for the bytes or bytearray translate method.\n"
     480                 :            : "\n"
     481                 :            : "The returned table will be one where each byte in frm is mapped to the byte at\n"
     482                 :            : "the same position in to.\n"
     483                 :            : "\n"
     484                 :            : "The bytes objects frm and to must be of the same length.");
     485                 :            : 
     486                 :            : #define BYTES_MAKETRANS_METHODDEF    \
     487                 :            :     {"maketrans", _PyCFunction_CAST(bytes_maketrans), METH_FASTCALL|METH_STATIC, bytes_maketrans__doc__},
     488                 :            : 
     489                 :            : static PyObject *
     490                 :            : bytes_maketrans_impl(Py_buffer *frm, Py_buffer *to);
     491                 :            : 
     492                 :            : static PyObject *
     493                 :          2 : bytes_maketrans(void *null, PyObject *const *args, Py_ssize_t nargs)
     494                 :            : {
     495                 :          2 :     PyObject *return_value = NULL;
     496                 :          2 :     Py_buffer frm = {NULL, NULL};
     497                 :          2 :     Py_buffer to = {NULL, NULL};
     498                 :            : 
     499   [ +  -  -  +  :          2 :     if (!_PyArg_CheckPositional("maketrans", nargs, 2, 2)) {
                   -  - ]
     500                 :          0 :         goto exit;
     501                 :            :     }
     502         [ -  + ]:          2 :     if (PyObject_GetBuffer(args[0], &frm, PyBUF_SIMPLE) != 0) {
     503                 :          0 :         goto exit;
     504                 :            :     }
     505         [ -  + ]:          2 :     if (!PyBuffer_IsContiguous(&frm, 'C')) {
     506                 :          0 :         _PyArg_BadArgument("maketrans", "argument 1", "contiguous buffer", args[0]);
     507                 :          0 :         goto exit;
     508                 :            :     }
     509         [ -  + ]:          2 :     if (PyObject_GetBuffer(args[1], &to, PyBUF_SIMPLE) != 0) {
     510                 :          0 :         goto exit;
     511                 :            :     }
     512         [ -  + ]:          2 :     if (!PyBuffer_IsContiguous(&to, 'C')) {
     513                 :          0 :         _PyArg_BadArgument("maketrans", "argument 2", "contiguous buffer", args[1]);
     514                 :          0 :         goto exit;
     515                 :            :     }
     516                 :          2 :     return_value = bytes_maketrans_impl(&frm, &to);
     517                 :            : 
     518                 :          2 : exit:
     519                 :            :     /* Cleanup for frm */
     520         [ +  - ]:          2 :     if (frm.obj) {
     521                 :          2 :        PyBuffer_Release(&frm);
     522                 :            :     }
     523                 :            :     /* Cleanup for to */
     524         [ +  - ]:          2 :     if (to.obj) {
     525                 :          2 :        PyBuffer_Release(&to);
     526                 :            :     }
     527                 :            : 
     528                 :          2 :     return return_value;
     529                 :            : }
     530                 :            : 
     531                 :            : PyDoc_STRVAR(bytes_replace__doc__,
     532                 :            : "replace($self, old, new, count=-1, /)\n"
     533                 :            : "--\n"
     534                 :            : "\n"
     535                 :            : "Return a copy with all occurrences of substring old replaced by new.\n"
     536                 :            : "\n"
     537                 :            : "  count\n"
     538                 :            : "    Maximum number of occurrences to replace.\n"
     539                 :            : "    -1 (the default value) means replace all occurrences.\n"
     540                 :            : "\n"
     541                 :            : "If the optional argument count is given, only the first count occurrences are\n"
     542                 :            : "replaced.");
     543                 :            : 
     544                 :            : #define BYTES_REPLACE_METHODDEF    \
     545                 :            :     {"replace", _PyCFunction_CAST(bytes_replace), METH_FASTCALL, bytes_replace__doc__},
     546                 :            : 
     547                 :            : static PyObject *
     548                 :            : bytes_replace_impl(PyBytesObject *self, Py_buffer *old, Py_buffer *new,
     549                 :            :                    Py_ssize_t count);
     550                 :            : 
     551                 :            : static PyObject *
     552                 :        114 : bytes_replace(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs)
     553                 :            : {
     554                 :        114 :     PyObject *return_value = NULL;
     555                 :        114 :     Py_buffer old = {NULL, NULL};
     556                 :        114 :     Py_buffer new = {NULL, NULL};
     557                 :        114 :     Py_ssize_t count = -1;
     558                 :            : 
     559   [ +  -  -  +  :        114 :     if (!_PyArg_CheckPositional("replace", nargs, 2, 3)) {
                   -  - ]
     560                 :          0 :         goto exit;
     561                 :            :     }
     562         [ -  + ]:        114 :     if (PyObject_GetBuffer(args[0], &old, PyBUF_SIMPLE) != 0) {
     563                 :          0 :         goto exit;
     564                 :            :     }
     565         [ -  + ]:        114 :     if (!PyBuffer_IsContiguous(&old, 'C')) {
     566                 :          0 :         _PyArg_BadArgument("replace", "argument 1", "contiguous buffer", args[0]);
     567                 :          0 :         goto exit;
     568                 :            :     }
     569         [ -  + ]:        114 :     if (PyObject_GetBuffer(args[1], &new, PyBUF_SIMPLE) != 0) {
     570                 :          0 :         goto exit;
     571                 :            :     }
     572         [ -  + ]:        114 :     if (!PyBuffer_IsContiguous(&new, 'C')) {
     573                 :          0 :         _PyArg_BadArgument("replace", "argument 2", "contiguous buffer", args[1]);
     574                 :          0 :         goto exit;
     575                 :            :     }
     576         [ +  - ]:        114 :     if (nargs < 3) {
     577                 :        114 :         goto skip_optional;
     578                 :            :     }
     579                 :            :     {
     580                 :          0 :         Py_ssize_t ival = -1;
     581                 :          0 :         PyObject *iobj = _PyNumber_Index(args[2]);
     582         [ #  # ]:          0 :         if (iobj != NULL) {
     583                 :          0 :             ival = PyLong_AsSsize_t(iobj);
     584                 :          0 :             Py_DECREF(iobj);
     585                 :            :         }
     586   [ #  #  #  # ]:          0 :         if (ival == -1 && PyErr_Occurred()) {
     587                 :          0 :             goto exit;
     588                 :            :         }
     589                 :          0 :         count = ival;
     590                 :            :     }
     591                 :        114 : skip_optional:
     592                 :        114 :     return_value = bytes_replace_impl(self, &old, &new, count);
     593                 :            : 
     594                 :        114 : exit:
     595                 :            :     /* Cleanup for old */
     596         [ +  - ]:        114 :     if (old.obj) {
     597                 :        114 :        PyBuffer_Release(&old);
     598                 :            :     }
     599                 :            :     /* Cleanup for new */
     600         [ +  - ]:        114 :     if (new.obj) {
     601                 :        114 :        PyBuffer_Release(&new);
     602                 :            :     }
     603                 :            : 
     604                 :        114 :     return return_value;
     605                 :            : }
     606                 :            : 
     607                 :            : PyDoc_STRVAR(bytes_removeprefix__doc__,
     608                 :            : "removeprefix($self, prefix, /)\n"
     609                 :            : "--\n"
     610                 :            : "\n"
     611                 :            : "Return a bytes object with the given prefix string removed if present.\n"
     612                 :            : "\n"
     613                 :            : "If the bytes starts with the prefix string, return bytes[len(prefix):].\n"
     614                 :            : "Otherwise, return a copy of the original bytes.");
     615                 :            : 
     616                 :            : #define BYTES_REMOVEPREFIX_METHODDEF    \
     617                 :            :     {"removeprefix", (PyCFunction)bytes_removeprefix, METH_O, bytes_removeprefix__doc__},
     618                 :            : 
     619                 :            : static PyObject *
     620                 :            : bytes_removeprefix_impl(PyBytesObject *self, Py_buffer *prefix);
     621                 :            : 
     622                 :            : static PyObject *
     623                 :          0 : bytes_removeprefix(PyBytesObject *self, PyObject *arg)
     624                 :            : {
     625                 :          0 :     PyObject *return_value = NULL;
     626                 :          0 :     Py_buffer prefix = {NULL, NULL};
     627                 :            : 
     628         [ #  # ]:          0 :     if (PyObject_GetBuffer(arg, &prefix, PyBUF_SIMPLE) != 0) {
     629                 :          0 :         goto exit;
     630                 :            :     }
     631         [ #  # ]:          0 :     if (!PyBuffer_IsContiguous(&prefix, 'C')) {
     632                 :          0 :         _PyArg_BadArgument("removeprefix", "argument", "contiguous buffer", arg);
     633                 :          0 :         goto exit;
     634                 :            :     }
     635                 :          0 :     return_value = bytes_removeprefix_impl(self, &prefix);
     636                 :            : 
     637                 :          0 : exit:
     638                 :            :     /* Cleanup for prefix */
     639         [ #  # ]:          0 :     if (prefix.obj) {
     640                 :          0 :        PyBuffer_Release(&prefix);
     641                 :            :     }
     642                 :            : 
     643                 :          0 :     return return_value;
     644                 :            : }
     645                 :            : 
     646                 :            : PyDoc_STRVAR(bytes_removesuffix__doc__,
     647                 :            : "removesuffix($self, suffix, /)\n"
     648                 :            : "--\n"
     649                 :            : "\n"
     650                 :            : "Return a bytes object with the given suffix string removed if present.\n"
     651                 :            : "\n"
     652                 :            : "If the bytes ends with the suffix string and that suffix is not empty,\n"
     653                 :            : "return bytes[:-len(prefix)].  Otherwise, return a copy of the original\n"
     654                 :            : "bytes.");
     655                 :            : 
     656                 :            : #define BYTES_REMOVESUFFIX_METHODDEF    \
     657                 :            :     {"removesuffix", (PyCFunction)bytes_removesuffix, METH_O, bytes_removesuffix__doc__},
     658                 :            : 
     659                 :            : static PyObject *
     660                 :            : bytes_removesuffix_impl(PyBytesObject *self, Py_buffer *suffix);
     661                 :            : 
     662                 :            : static PyObject *
     663                 :          0 : bytes_removesuffix(PyBytesObject *self, PyObject *arg)
     664                 :            : {
     665                 :          0 :     PyObject *return_value = NULL;
     666                 :          0 :     Py_buffer suffix = {NULL, NULL};
     667                 :            : 
     668         [ #  # ]:          0 :     if (PyObject_GetBuffer(arg, &suffix, PyBUF_SIMPLE) != 0) {
     669                 :          0 :         goto exit;
     670                 :            :     }
     671         [ #  # ]:          0 :     if (!PyBuffer_IsContiguous(&suffix, 'C')) {
     672                 :          0 :         _PyArg_BadArgument("removesuffix", "argument", "contiguous buffer", arg);
     673                 :          0 :         goto exit;
     674                 :            :     }
     675                 :          0 :     return_value = bytes_removesuffix_impl(self, &suffix);
     676                 :            : 
     677                 :          0 : exit:
     678                 :            :     /* Cleanup for suffix */
     679         [ #  # ]:          0 :     if (suffix.obj) {
     680                 :          0 :        PyBuffer_Release(&suffix);
     681                 :            :     }
     682                 :            : 
     683                 :          0 :     return return_value;
     684                 :            : }
     685                 :            : 
     686                 :            : PyDoc_STRVAR(bytes_decode__doc__,
     687                 :            : "decode($self, /, encoding=\'utf-8\', errors=\'strict\')\n"
     688                 :            : "--\n"
     689                 :            : "\n"
     690                 :            : "Decode the bytes using the codec registered for encoding.\n"
     691                 :            : "\n"
     692                 :            : "  encoding\n"
     693                 :            : "    The encoding with which to decode the bytes.\n"
     694                 :            : "  errors\n"
     695                 :            : "    The error handling scheme to use for the handling of decoding errors.\n"
     696                 :            : "    The default is \'strict\' meaning that decoding errors raise a\n"
     697                 :            : "    UnicodeDecodeError. Other possible values are \'ignore\' and \'replace\'\n"
     698                 :            : "    as well as any other name registered with codecs.register_error that\n"
     699                 :            : "    can handle UnicodeDecodeErrors.");
     700                 :            : 
     701                 :            : #define BYTES_DECODE_METHODDEF    \
     702                 :            :     {"decode", _PyCFunction_CAST(bytes_decode), METH_FASTCALL|METH_KEYWORDS, bytes_decode__doc__},
     703                 :            : 
     704                 :            : static PyObject *
     705                 :            : bytes_decode_impl(PyBytesObject *self, const char *encoding,
     706                 :            :                   const char *errors);
     707                 :            : 
     708                 :            : static PyObject *
     709                 :       7065 : bytes_decode(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     710                 :            : {
     711                 :       7065 :     PyObject *return_value = NULL;
     712                 :            :     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     713                 :            : 
     714                 :            :     #define NUM_KEYWORDS 2
     715                 :            :     static struct {
     716                 :            :         PyGC_Head _this_is_not_used;
     717                 :            :         PyObject_VAR_HEAD
     718                 :            :         PyObject *ob_item[NUM_KEYWORDS];
     719                 :            :     } _kwtuple = {
     720                 :            :         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     721                 :            :         .ob_item = { &_Py_ID(encoding), &_Py_ID(errors), },
     722                 :            :     };
     723                 :            :     #undef NUM_KEYWORDS
     724                 :            :     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     725                 :            : 
     726                 :            :     #else  // !Py_BUILD_CORE
     727                 :            :     #  define KWTUPLE NULL
     728                 :            :     #endif  // !Py_BUILD_CORE
     729                 :            : 
     730                 :            :     static const char * const _keywords[] = {"encoding", "errors", NULL};
     731                 :            :     static _PyArg_Parser _parser = {
     732                 :            :         .keywords = _keywords,
     733                 :            :         .fname = "decode",
     734                 :            :         .kwtuple = KWTUPLE,
     735                 :            :     };
     736                 :            :     #undef KWTUPLE
     737                 :            :     PyObject *argsbuf[2];
     738         [ +  + ]:       7065 :     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
     739                 :       7065 :     const char *encoding = NULL;
     740                 :       7065 :     const char *errors = NULL;
     741                 :            : 
     742   [ +  +  +  -  :       7065 :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
             +  -  -  + ]
     743         [ -  + ]:       7065 :     if (!args) {
     744                 :          0 :         goto exit;
     745                 :            :     }
     746         [ -  + ]:       7065 :     if (!noptargs) {
     747                 :          0 :         goto skip_optional_pos;
     748                 :            :     }
     749         [ +  - ]:       7065 :     if (args[0]) {
     750         [ -  + ]:       7065 :         if (!PyUnicode_Check(args[0])) {
     751                 :          0 :             _PyArg_BadArgument("decode", "argument 'encoding'", "str", args[0]);
     752                 :          0 :             goto exit;
     753                 :            :         }
     754                 :            :         Py_ssize_t encoding_length;
     755                 :       7065 :         encoding = PyUnicode_AsUTF8AndSize(args[0], &encoding_length);
     756         [ -  + ]:       7065 :         if (encoding == NULL) {
     757                 :          0 :             goto exit;
     758                 :            :         }
     759         [ -  + ]:       7065 :         if (strlen(encoding) != (size_t)encoding_length) {
     760                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
     761                 :          0 :             goto exit;
     762                 :            :         }
     763         [ +  + ]:       7065 :         if (!--noptargs) {
     764                 :       6366 :             goto skip_optional_pos;
     765                 :            :         }
     766                 :            :     }
     767         [ -  + ]:        699 :     if (!PyUnicode_Check(args[1])) {
     768                 :          0 :         _PyArg_BadArgument("decode", "argument 'errors'", "str", args[1]);
     769                 :          0 :         goto exit;
     770                 :            :     }
     771                 :            :     Py_ssize_t errors_length;
     772                 :        699 :     errors = PyUnicode_AsUTF8AndSize(args[1], &errors_length);
     773         [ -  + ]:        699 :     if (errors == NULL) {
     774                 :          0 :         goto exit;
     775                 :            :     }
     776         [ -  + ]:        699 :     if (strlen(errors) != (size_t)errors_length) {
     777                 :          0 :         PyErr_SetString(PyExc_ValueError, "embedded null character");
     778                 :          0 :         goto exit;
     779                 :            :     }
     780                 :        699 : skip_optional_pos:
     781                 :       7065 :     return_value = bytes_decode_impl(self, encoding, errors);
     782                 :            : 
     783                 :       7065 : exit:
     784                 :       7065 :     return return_value;
     785                 :            : }
     786                 :            : 
     787                 :            : PyDoc_STRVAR(bytes_splitlines__doc__,
     788                 :            : "splitlines($self, /, keepends=False)\n"
     789                 :            : "--\n"
     790                 :            : "\n"
     791                 :            : "Return a list of the lines in the bytes, breaking at line boundaries.\n"
     792                 :            : "\n"
     793                 :            : "Line breaks are not included in the resulting list unless keepends is given and\n"
     794                 :            : "true.");
     795                 :            : 
     796                 :            : #define BYTES_SPLITLINES_METHODDEF    \
     797                 :            :     {"splitlines", _PyCFunction_CAST(bytes_splitlines), METH_FASTCALL|METH_KEYWORDS, bytes_splitlines__doc__},
     798                 :            : 
     799                 :            : static PyObject *
     800                 :            : bytes_splitlines_impl(PyBytesObject *self, int keepends);
     801                 :            : 
     802                 :            : static PyObject *
     803                 :          0 : bytes_splitlines(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     804                 :            : {
     805                 :          0 :     PyObject *return_value = NULL;
     806                 :            :     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     807                 :            : 
     808                 :            :     #define NUM_KEYWORDS 1
     809                 :            :     static struct {
     810                 :            :         PyGC_Head _this_is_not_used;
     811                 :            :         PyObject_VAR_HEAD
     812                 :            :         PyObject *ob_item[NUM_KEYWORDS];
     813                 :            :     } _kwtuple = {
     814                 :            :         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     815                 :            :         .ob_item = { &_Py_ID(keepends), },
     816                 :            :     };
     817                 :            :     #undef NUM_KEYWORDS
     818                 :            :     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     819                 :            : 
     820                 :            :     #else  // !Py_BUILD_CORE
     821                 :            :     #  define KWTUPLE NULL
     822                 :            :     #endif  // !Py_BUILD_CORE
     823                 :            : 
     824                 :            :     static const char * const _keywords[] = {"keepends", NULL};
     825                 :            :     static _PyArg_Parser _parser = {
     826                 :            :         .keywords = _keywords,
     827                 :            :         .fname = "splitlines",
     828                 :            :         .kwtuple = KWTUPLE,
     829                 :            :     };
     830                 :            :     #undef KWTUPLE
     831                 :            :     PyObject *argsbuf[1];
     832         [ #  # ]:          0 :     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
     833                 :          0 :     int keepends = 0;
     834                 :            : 
     835   [ #  #  #  #  :          0 :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
             #  #  #  # ]
     836         [ #  # ]:          0 :     if (!args) {
     837                 :          0 :         goto exit;
     838                 :            :     }
     839         [ #  # ]:          0 :     if (!noptargs) {
     840                 :          0 :         goto skip_optional_pos;
     841                 :            :     }
     842                 :          0 :     keepends = PyObject_IsTrue(args[0]);
     843         [ #  # ]:          0 :     if (keepends < 0) {
     844                 :          0 :         goto exit;
     845                 :            :     }
     846                 :          0 : skip_optional_pos:
     847                 :          0 :     return_value = bytes_splitlines_impl(self, keepends);
     848                 :            : 
     849                 :          0 : exit:
     850                 :          0 :     return return_value;
     851                 :            : }
     852                 :            : 
     853                 :            : PyDoc_STRVAR(bytes_fromhex__doc__,
     854                 :            : "fromhex($type, string, /)\n"
     855                 :            : "--\n"
     856                 :            : "\n"
     857                 :            : "Create a bytes object from a string of hexadecimal numbers.\n"
     858                 :            : "\n"
     859                 :            : "Spaces between two numbers are accepted.\n"
     860                 :            : "Example: bytes.fromhex(\'B9 01EF\') -> b\'\\\\xb9\\\\x01\\\\xef\'.");
     861                 :            : 
     862                 :            : #define BYTES_FROMHEX_METHODDEF    \
     863                 :            :     {"fromhex", (PyCFunction)bytes_fromhex, METH_O|METH_CLASS, bytes_fromhex__doc__},
     864                 :            : 
     865                 :            : static PyObject *
     866                 :            : bytes_fromhex_impl(PyTypeObject *type, PyObject *string);
     867                 :            : 
     868                 :            : static PyObject *
     869                 :          0 : bytes_fromhex(PyTypeObject *type, PyObject *arg)
     870                 :            : {
     871                 :          0 :     PyObject *return_value = NULL;
     872                 :            :     PyObject *string;
     873                 :            : 
     874         [ #  # ]:          0 :     if (!PyUnicode_Check(arg)) {
     875                 :          0 :         _PyArg_BadArgument("fromhex", "argument", "str", arg);
     876                 :          0 :         goto exit;
     877                 :            :     }
     878         [ #  # ]:          0 :     if (PyUnicode_READY(arg) == -1) {
     879                 :          0 :         goto exit;
     880                 :            :     }
     881                 :          0 :     string = arg;
     882                 :          0 :     return_value = bytes_fromhex_impl(type, string);
     883                 :            : 
     884                 :          0 : exit:
     885                 :          0 :     return return_value;
     886                 :            : }
     887                 :            : 
     888                 :            : PyDoc_STRVAR(bytes_hex__doc__,
     889                 :            : "hex($self, /, sep=<unrepresentable>, bytes_per_sep=1)\n"
     890                 :            : "--\n"
     891                 :            : "\n"
     892                 :            : "Create a string of hexadecimal numbers from a bytes object.\n"
     893                 :            : "\n"
     894                 :            : "  sep\n"
     895                 :            : "    An optional single character or byte to separate hex bytes.\n"
     896                 :            : "  bytes_per_sep\n"
     897                 :            : "    How many bytes between separators.  Positive values count from the\n"
     898                 :            : "    right, negative values count from the left.\n"
     899                 :            : "\n"
     900                 :            : "Example:\n"
     901                 :            : ">>> value = b\'\\xb9\\x01\\xef\'\n"
     902                 :            : ">>> value.hex()\n"
     903                 :            : "\'b901ef\'\n"
     904                 :            : ">>> value.hex(\':\')\n"
     905                 :            : "\'b9:01:ef\'\n"
     906                 :            : ">>> value.hex(\':\', 2)\n"
     907                 :            : "\'b9:01ef\'\n"
     908                 :            : ">>> value.hex(\':\', -2)\n"
     909                 :            : "\'b901:ef\'");
     910                 :            : 
     911                 :            : #define BYTES_HEX_METHODDEF    \
     912                 :            :     {"hex", _PyCFunction_CAST(bytes_hex), METH_FASTCALL|METH_KEYWORDS, bytes_hex__doc__},
     913                 :            : 
     914                 :            : static PyObject *
     915                 :            : bytes_hex_impl(PyBytesObject *self, PyObject *sep, int bytes_per_sep);
     916                 :            : 
     917                 :            : static PyObject *
     918                 :          0 : bytes_hex(PyBytesObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     919                 :            : {
     920                 :          0 :     PyObject *return_value = NULL;
     921                 :            :     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     922                 :            : 
     923                 :            :     #define NUM_KEYWORDS 2
     924                 :            :     static struct {
     925                 :            :         PyGC_Head _this_is_not_used;
     926                 :            :         PyObject_VAR_HEAD
     927                 :            :         PyObject *ob_item[NUM_KEYWORDS];
     928                 :            :     } _kwtuple = {
     929                 :            :         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     930                 :            :         .ob_item = { &_Py_ID(sep), &_Py_ID(bytes_per_sep), },
     931                 :            :     };
     932                 :            :     #undef NUM_KEYWORDS
     933                 :            :     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     934                 :            : 
     935                 :            :     #else  // !Py_BUILD_CORE
     936                 :            :     #  define KWTUPLE NULL
     937                 :            :     #endif  // !Py_BUILD_CORE
     938                 :            : 
     939                 :            :     static const char * const _keywords[] = {"sep", "bytes_per_sep", NULL};
     940                 :            :     static _PyArg_Parser _parser = {
     941                 :            :         .keywords = _keywords,
     942                 :            :         .fname = "hex",
     943                 :            :         .kwtuple = KWTUPLE,
     944                 :            :     };
     945                 :            :     #undef KWTUPLE
     946                 :            :     PyObject *argsbuf[2];
     947         [ #  # ]:          0 :     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
     948                 :          0 :     PyObject *sep = NULL;
     949                 :          0 :     int bytes_per_sep = 1;
     950                 :            : 
     951   [ #  #  #  #  :          0 :     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);
             #  #  #  # ]
     952         [ #  # ]:          0 :     if (!args) {
     953                 :          0 :         goto exit;
     954                 :            :     }
     955         [ #  # ]:          0 :     if (!noptargs) {
     956                 :          0 :         goto skip_optional_pos;
     957                 :            :     }
     958         [ #  # ]:          0 :     if (args[0]) {
     959                 :          0 :         sep = args[0];
     960         [ #  # ]:          0 :         if (!--noptargs) {
     961                 :          0 :             goto skip_optional_pos;
     962                 :            :         }
     963                 :            :     }
     964                 :          0 :     bytes_per_sep = _PyLong_AsInt(args[1]);
     965   [ #  #  #  # ]:          0 :     if (bytes_per_sep == -1 && PyErr_Occurred()) {
     966                 :          0 :         goto exit;
     967                 :            :     }
     968                 :          0 : skip_optional_pos:
     969                 :          0 :     return_value = bytes_hex_impl(self, sep, bytes_per_sep);
     970                 :            : 
     971                 :          0 : exit:
     972                 :          0 :     return return_value;
     973                 :            : }
     974                 :            : 
     975                 :            : static PyObject *
     976                 :            : bytes_new_impl(PyTypeObject *type, PyObject *x, const char *encoding,
     977                 :            :                const char *errors);
     978                 :            : 
     979                 :            : static PyObject *
     980                 :        800 : bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
     981                 :            : {
     982                 :        800 :     PyObject *return_value = NULL;
     983                 :            :     #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
     984                 :            : 
     985                 :            :     #define NUM_KEYWORDS 3
     986                 :            :     static struct {
     987                 :            :         PyGC_Head _this_is_not_used;
     988                 :            :         PyObject_VAR_HEAD
     989                 :            :         PyObject *ob_item[NUM_KEYWORDS];
     990                 :            :     } _kwtuple = {
     991                 :            :         .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
     992                 :            :         .ob_item = { &_Py_ID(source), &_Py_ID(encoding), &_Py_ID(errors), },
     993                 :            :     };
     994                 :            :     #undef NUM_KEYWORDS
     995                 :            :     #define KWTUPLE (&_kwtuple.ob_base.ob_base)
     996                 :            : 
     997                 :            :     #else  // !Py_BUILD_CORE
     998                 :            :     #  define KWTUPLE NULL
     999                 :            :     #endif  // !Py_BUILD_CORE
    1000                 :            : 
    1001                 :            :     static const char * const _keywords[] = {"source", "encoding", "errors", NULL};
    1002                 :            :     static _PyArg_Parser _parser = {
    1003                 :            :         .keywords = _keywords,
    1004                 :            :         .fname = "bytes",
    1005                 :            :         .kwtuple = KWTUPLE,
    1006                 :            :     };
    1007                 :            :     #undef KWTUPLE
    1008                 :            :     PyObject *argsbuf[3];
    1009                 :            :     PyObject * const *fastargs;
    1010                 :        800 :     Py_ssize_t nargs = PyTuple_GET_SIZE(args);
    1011         [ -  + ]:        800 :     Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
    1012                 :        800 :     PyObject *x = NULL;
    1013                 :        800 :     const char *encoding = NULL;
    1014                 :        800 :     const char *errors = NULL;
    1015                 :            : 
    1016   [ +  -  +  -  :        800 :     fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 0, 3, 0, argsbuf);
             +  -  +  - ]
    1017         [ -  + ]:        800 :     if (!fastargs) {
    1018                 :          0 :         goto exit;
    1019                 :            :     }
    1020         [ -  + ]:        800 :     if (!noptargs) {
    1021                 :          0 :         goto skip_optional_pos;
    1022                 :            :     }
    1023         [ +  - ]:        800 :     if (fastargs[0]) {
    1024                 :        800 :         x = fastargs[0];
    1025         [ +  - ]:        800 :         if (!--noptargs) {
    1026                 :        800 :             goto skip_optional_pos;
    1027                 :            :         }
    1028                 :            :     }
    1029         [ #  # ]:          0 :     if (fastargs[1]) {
    1030         [ #  # ]:          0 :         if (!PyUnicode_Check(fastargs[1])) {
    1031                 :          0 :             _PyArg_BadArgument("bytes", "argument 'encoding'", "str", fastargs[1]);
    1032                 :          0 :             goto exit;
    1033                 :            :         }
    1034                 :            :         Py_ssize_t encoding_length;
    1035                 :          0 :         encoding = PyUnicode_AsUTF8AndSize(fastargs[1], &encoding_length);
    1036         [ #  # ]:          0 :         if (encoding == NULL) {
    1037                 :          0 :             goto exit;
    1038                 :            :         }
    1039         [ #  # ]:          0 :         if (strlen(encoding) != (size_t)encoding_length) {
    1040                 :          0 :             PyErr_SetString(PyExc_ValueError, "embedded null character");
    1041                 :          0 :             goto exit;
    1042                 :            :         }
    1043         [ #  # ]:          0 :         if (!--noptargs) {
    1044                 :          0 :             goto skip_optional_pos;
    1045                 :            :         }
    1046                 :            :     }
    1047         [ #  # ]:          0 :     if (!PyUnicode_Check(fastargs[2])) {
    1048                 :          0 :         _PyArg_BadArgument("bytes", "argument 'errors'", "str", fastargs[2]);
    1049                 :          0 :         goto exit;
    1050                 :            :     }
    1051                 :            :     Py_ssize_t errors_length;
    1052                 :          0 :     errors = PyUnicode_AsUTF8AndSize(fastargs[2], &errors_length);
    1053         [ #  # ]:          0 :     if (errors == NULL) {
    1054                 :          0 :         goto exit;
    1055                 :            :     }
    1056         [ #  # ]:          0 :     if (strlen(errors) != (size_t)errors_length) {
    1057                 :          0 :         PyErr_SetString(PyExc_ValueError, "embedded null character");
    1058                 :          0 :         goto exit;
    1059                 :            :     }
    1060                 :          0 : skip_optional_pos:
    1061                 :        800 :     return_value = bytes_new_impl(type, x, encoding, errors);
    1062                 :            : 
    1063                 :        800 : exit:
    1064                 :        800 :     return return_value;
    1065                 :            : }
    1066                 :            : /*[clinic end generated code: output=31a9e4af85562612 input=a9049054013a1b77]*/

Generated by: LCOV version 1.14