mirror of
https://github.com/python/cpython
synced 2026-09-28 03:33:18 +03:00
bpo-40563: Support pathlike objects on dbm/shelve (GH-21849)
Co-authored-by: Hakan Çelik <hakancelik96@outlook.com>
This commit is contained in:
parent
62fa613f6a
commit
707137b863
14 changed files with 124 additions and 68 deletions
|
|
@ -590,7 +590,7 @@ static PyType_Spec gdbmtype_spec = {
|
|||
/*[clinic input]
|
||||
_gdbm.open as dbmopen
|
||||
|
||||
filename: unicode
|
||||
filename: object
|
||||
flags: str="r"
|
||||
mode: int(py_default="0o666") = 0o666
|
||||
/
|
||||
|
|
@ -622,7 +622,7 @@ when the database has to be created. It defaults to octal 0o666.
|
|||
static PyObject *
|
||||
dbmopen_impl(PyObject *module, PyObject *filename, const char *flags,
|
||||
int mode)
|
||||
/*[clinic end generated code: output=9527750f5df90764 input=812b7d74399ceb0e]*/
|
||||
/*[clinic end generated code: output=9527750f5df90764 input=bca6ec81dc49292c]*/
|
||||
{
|
||||
int iflags;
|
||||
_gdbm_state *state = get_gdbm_state(module);
|
||||
|
|
@ -672,10 +672,11 @@ dbmopen_impl(PyObject *module, PyObject *filename, const char *flags,
|
|||
}
|
||||
}
|
||||
|
||||
PyObject *filenamebytes = PyUnicode_EncodeFSDefault(filename);
|
||||
if (filenamebytes == NULL) {
|
||||
PyObject *filenamebytes;
|
||||
if (!PyUnicode_FSConverter(filename, &filenamebytes)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *name = PyBytes_AS_STRING(filenamebytes);
|
||||
if (strlen(name) != (size_t)PyBytes_GET_SIZE(filenamebytes)) {
|
||||
Py_DECREF(filenamebytes);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue