Skip to content

Commit 80afa32

Browse files
committed
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.)
1 parent 566f319 commit 80afa32

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

roundup/backends/blobfiles.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
import os
2424

25+
from roundup.anypy.strings import s2b
26+
2527
def files_in_dir(dir):
2628
if not os.path.exists(dir):
2729
return 0
@@ -332,6 +334,8 @@ def storefile(self, classname, nodeid, property, content):
332334
# in multi-tracker (i.e. multi-umask) or modpython scenarios
333335
# the umask may have changed since last we set it.
334336
os.umask(self.umask)
337+
if isinstance(content, str):
338+
content = s2b(content)
335339
open(name, 'wb').write(content)
336340

337341
def getfile(self, classname, nodeid, property):

0 commit comments

Comments
 (0)