Mercurial > p > roundup > code
changeset 5445:46317fe544ec
Python 3 preparation: convert string content to bytes for file storage.
When FileClass content comes from a text field in a form rather than
an uploaded file (e.g. creating a msg object in the classic template),
this reaches the blobfiles code as a str object, which thus needs
converting to bytes for storage.
Note that given this fix, while msg objects can be created, they
appear with spurious b'' on the issue pages. Something needs to
handle the conversion in the other direction as well; I'm not entirely
sure what, but probably the hyperdb property wrapper for any String
content property that is actually stored in a file like this.
(As previously discussed, ideally there might be a distinction between
String and Bytes fields, and then there might be separate text and
binary variants of FileClass. I haven't attempted to implement any of
that and it should be possible to get Roundup working with Python 3
without needing to do that.)
| author | Joseph Myers <jsm@polyomino.org.uk> |
|---|---|
| date | Wed, 25 Jul 2018 12:32:26 +0000 |
| parents | 167f0d25ea8e |
| children | 214f34e18678 |
| files | roundup/backends/blobfiles.py |
| diffstat | 1 files changed, 4 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/roundup/backends/blobfiles.py Wed Jul 25 12:31:32 2018 +0000 +++ b/roundup/backends/blobfiles.py Wed Jul 25 12:32:26 2018 +0000 @@ -22,6 +22,8 @@ import os +from roundup.anypy.strings import s2b + def files_in_dir(dir): if not os.path.exists(dir): return 0 @@ -332,6 +334,8 @@ # in multi-tracker (i.e. multi-umask) or modpython scenarios # the umask may have changed since last we set it. os.umask(self.umask) + if isinstance(content, str): + content = s2b(content) open(name, 'wb').write(content) def getfile(self, classname, nodeid, property):
