Browse Source

dtoolutil: Fix Filename division operator in Python 3

rdb 4 years ago
parent
commit
9d9337dc4d

+ 1 - 0
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;

+ 9 - 0
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<Filename>::
+__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.

+ 3 - 0
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;
 };