| 96 | } |
| 97 | |
| 98 | PyObject* Has(PyObject* self[[maybe_unused]], PyObject *const* args, Py_ssize_t nargs) noexcept { |
| 99 | if (nargs != 1) { |
| 100 | PyErr_Format(PyExc_TypeError, "__res.has takes 1 positional arguments but %z were given", nargs); |
| 101 | return nullptr; |
| 102 | } |
| 103 | |
| 104 | TStringBuf key; |
| 105 | if (PyUnicode_Check(args[0])) { |
| 106 | Py_ssize_t sz; |
| 107 | const char* data = PyUnicode_AsUTF8AndSize(args[0], &sz); |
| 108 | if (sz < 0) { |
| 109 | return nullptr; |
| 110 | } |
| 111 | key = {data, static_cast<size_t>(sz)}; |
| 112 | } else { |
| 113 | char* data = nullptr; |
| 114 | Py_ssize_t sz; |
| 115 | if (PyBytes_AsStringAndSize(args[0], &data, &sz) != 0) { |
| 116 | return nullptr; |
| 117 | } |
| 118 | key = {data, static_cast<size_t>(sz)}; |
| 119 | } |
| 120 | |
| 121 | return CallWithErrorTranslation([&]{ |
| 122 | int res = NResource::Has(key); |
| 123 | return PyBool_FromLong(res); |
| 124 | }); |
| 125 | } |
| 126 | |
| 127 | } |
| 128 |
no test coverage detected