/src/Python-3.8.3/Objects/clinic/memoryobject.c.h
Line  | Count  | Source  | 
1  |  | /*[clinic input]  | 
2  |  | preserve  | 
3  |  | [clinic start generated code]*/  | 
4  |  |  | 
5  |  | PyDoc_STRVAR(memoryview_hex__doc__,  | 
6  |  | "hex($self, /, sep=<unrepresentable>, bytes_per_sep=1)\n"  | 
7  |  | "--\n"  | 
8  |  | "\n"  | 
9  |  | "Return the data in the buffer as a str of hexadecimal numbers.\n"  | 
10  |  | "\n"  | 
11  |  | "  sep\n"  | 
12  |  | "    An optional single character or byte to separate hex bytes.\n"  | 
13  |  | "  bytes_per_sep\n"  | 
14  |  | "    How many bytes between separators.  Positive values count from the\n"  | 
15  |  | "    right, negative values count from the left.\n"  | 
16  |  | "\n"  | 
17  |  | "Example:\n"  | 
18  |  | ">>> value = memoryview(b\'\\xb9\\x01\\xef\')\n"  | 
19  |  | ">>> value.hex()\n"  | 
20  |  | "\'b901ef\'\n"  | 
21  |  | ">>> value.hex(\':\')\n"  | 
22  |  | "\'b9:01:ef\'\n"  | 
23  |  | ">>> value.hex(\':\', 2)\n"  | 
24  |  | "\'b9:01ef\'\n"  | 
25  |  | ">>> value.hex(\':\', -2)\n"  | 
26  |  | "\'b901:ef\'");  | 
27  |  |  | 
28  |  | #define MEMORYVIEW_HEX_METHODDEF    \  | 
29  |  |     {"hex", (PyCFunction)(void(*)(void))memoryview_hex, METH_FASTCALL|METH_KEYWORDS, memoryview_hex__doc__}, | 
30  |  |  | 
31  |  | static PyObject *  | 
32  |  | memoryview_hex_impl(PyMemoryViewObject *self, PyObject *sep,  | 
33  |  |                     int bytes_per_sep);  | 
34  |  |  | 
35  |  | static PyObject *  | 
36  |  | memoryview_hex(PyMemoryViewObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)  | 
37  | 0  | { | 
38  | 0  |     PyObject *return_value = NULL;  | 
39  | 0  |     static const char * const _keywords[] = {"sep", "bytes_per_sep", NULL}; | 
40  | 0  |     static _PyArg_Parser _parser = {NULL, _keywords, "hex", 0}; | 
41  | 0  |     PyObject *argsbuf[2];  | 
42  | 0  |     Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;  | 
43  | 0  |     PyObject *sep = NULL;  | 
44  | 0  |     int bytes_per_sep = 1;  | 
45  |  | 
  | 
46  | 0  |     args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 2, 0, argsbuf);  | 
47  | 0  |     if (!args) { | 
48  | 0  |         goto exit;  | 
49  | 0  |     }  | 
50  | 0  |     if (!noptargs) { | 
51  | 0  |         goto skip_optional_pos;  | 
52  | 0  |     }  | 
53  | 0  |     if (args[0]) { | 
54  | 0  |         sep = args[0];  | 
55  | 0  |         if (!--noptargs) { | 
56  | 0  |             goto skip_optional_pos;  | 
57  | 0  |         }  | 
58  | 0  |     }  | 
59  | 0  |     if (PyFloat_Check(args[1])) { | 
60  | 0  |         PyErr_SetString(PyExc_TypeError,  | 
61  | 0  |                         "integer argument expected, got float" );  | 
62  | 0  |         goto exit;  | 
63  | 0  |     }  | 
64  | 0  |     bytes_per_sep = _PyLong_AsInt(args[1]);  | 
65  | 0  |     if (bytes_per_sep == -1 && PyErr_Occurred()) { | 
66  | 0  |         goto exit;  | 
67  | 0  |     }  | 
68  | 0  | skip_optional_pos:  | 
69  | 0  |     return_value = memoryview_hex_impl(self, sep, bytes_per_sep);  | 
70  |  | 
  | 
71  | 0  | exit:  | 
72  | 0  |     return return_value;  | 
73  | 0  | }  | 
74  |  | /*[clinic end generated code: output=ee265a73f68b0077 input=a9049054013a1b77]*/  |