From 9d9337dc4d349825ee45008c440c27add9469399 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 22 Feb 2021 18:14:12 +0100 Subject: [PATCH] dtoolutil: Fix Filename division operator in Python 3 --- dtool/src/dtoolutil/filename.h | 1 + dtool/src/dtoolutil/filename_ext.cxx | 9 +++++++++ dtool/src/dtoolutil/filename_ext.h | 3 +++ 3 files changed, 13 insertions(+) diff --git a/dtool/src/dtoolutil/filename.h b/dtool/src/dtoolutil/filename.h index 66b38356a6..99d94af5a6 100644 --- a/dtool/src/dtoolutil/filename.h +++ b/dtool/src/dtoolutil/filename.h @@ -122,6 +122,7 @@ PUBLISHED: INLINE Filename operator + (const std::string &other) const; INLINE Filename operator / (const Filename &other) const; + EXTENSION(Filename __truediv__(const Filename &other) const); // Or, you can use any of these. INLINE std::string get_fullpath() const; diff --git a/dtool/src/dtoolutil/filename_ext.cxx b/dtool/src/dtoolutil/filename_ext.cxx index e60bf83a90..c7b7e30606 100644 --- a/dtool/src/dtoolutil/filename_ext.cxx +++ b/dtool/src/dtoolutil/filename_ext.cxx @@ -184,6 +184,15 @@ __fspath__() const { return PyUnicode_FromWideChar(filename.data(), (Py_ssize_t)filename.size()); } +/** + * Returns a new Filename that is composed of the other filename added to the + * end of this filename, with an intervening slash added if necessary. + */ +Filename Extension:: +__truediv__(const Filename &other) const { + return Filename(*_this, other); +} + /** * This variant on scan_directory returns a Python list of strings on success, * or None on failure. diff --git a/dtool/src/dtoolutil/filename_ext.h b/dtool/src/dtoolutil/filename_ext.h index 1ebeaacc52..6567d0995f 100644 --- a/dtool/src/dtoolutil/filename_ext.h +++ b/dtool/src/dtoolutil/filename_ext.h @@ -34,6 +34,9 @@ public: PyObject *__reduce__(PyObject *self) const; PyObject *__repr__() const; PyObject *__fspath__() const; + + Filename __truediv__(const Filename &other) const; + PyObject *scan_directory() const; };