diff --git a/CHANGES.rst b/CHANGES.rst index 14eec50e..ece8fbbc 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -117,6 +117,14 @@ Changes in this release include the following: * Moved the wxpy_api.h file into the wx package at wx/include/wxPython so it will be included in the wheel file. (#961) +* Fixed how string data is added to a virtual file-like object in + wx.MemoryFSHandler. All strings are now added to the file as utf-8 encoded data, + in both Python2 and Python3, and will be read from the virtual file the same + way. If you need to use some other encoding for some reason you can first + convert the text to a bytesarray or other buffer protocol compatible object and + then create the virtual file from that data. (#969) + + diff --git a/etg/filesys.py b/etg/filesys.py index 0f042965..19b32668 100644 --- a/etg/filesys.py +++ b/etg/filesys.py @@ -83,10 +83,17 @@ def run(): _fixHandlerClass(c) c.addPrivateCopyCtor() - # Make some more python-friendly versions of the AddFile methods accepting raw data - c.find('AddFile').findOverload('binarydata').ignore() - c.find('AddFileWithMimeType').findOverload('binarydata').ignore() + # Make some more python-friendly versions of the AddFile methods accepting text or raw data + c.find('AddFile').findOverload('textdata').ignore() + c.addCppMethod('void', 'AddFile', '(const wxString& filename, const wxString& textdata)', + isStatic=True, + doc="Add a file from text data, which will first be converted to utf-8 encoded bytes.", + body="""\ + wxScopedCharBuffer buf = textdata->utf8_str(); + wxMemoryFSHandler::AddFile(*filename, (const char*)buf, strlen(buf)); + """) + c.find('AddFile').findOverload('binarydata').ignore() c.addCppMethod('void', 'AddFile', '(const wxString& filename, wxPyBuffer* binarydata)', isStatic=True, doc="Add a file from raw data in a python buffer compatible object.", @@ -94,6 +101,17 @@ def run(): wxMemoryFSHandler::AddFile(*filename, binarydata->m_ptr, binarydata->m_len); """) + c.find('AddFileWithMimeType').findOverload('textdata').ignore() + c.addCppMethod('void', 'AddFileWithMimeType', + '(const wxString& filename, const wxString& textdata, const wxString& mimetype)', + isStatic=True, + doc="Add a file from text data, which will first be converted to utf-8 encoded bytes.", + body="""\ + wxScopedCharBuffer buf = textdata->utf8_str(); + wxMemoryFSHandler::AddFileWithMimeType(*filename, (const char*)buf, strlen(buf), *mimetype); + """) + + c.find('AddFileWithMimeType').findOverload('binarydata').ignore() c.addCppMethod('void', 'AddFileWithMimeType', '(const wxString& filename, wxPyBuffer* binarydata, const wxString& mimetype)', isStatic=True,