Description
After adding an attachment, I get the following on that page
AttributeError : 'unicode' object has no attribute 'decode'
/usr/lib/python2.3/site-packages/MoinMoin/action/AttachFile.py in (a=u'test.png') 1. 284 attach_dir = getAttachDir(request, pagename) 2. 285 if os.path.isdir(attach_dir): 3. 286 files = map(lambda a: a.decode(config.charset), os.listdir(attach_dir)) 4. 287 files.sort() 5. 288 return files
This is because os.listdir is returning unicode strings, since attach_dir was passed to it as a unicode string.
Steps to reproduce
Python 2.3.5 (#2, Mar 6 2006, 10:12:24) [GCC 4.0.3 20060304 (prerelease) (Debian 4.0.2-10)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> map(lambda a: a.decode('utf-8'), os.listdir(u'/')) Traceback (most recent call last): File "<stdin>", line 1, in ? File "<stdin>", line 1, in <lambda> AttributeError: 'unicode' object has no attribute 'decode' >>>
Workaround
Force the strings to be !unicode
--- AttachFile.py 2006-04-05 18:58:07.000000000 +0000 +++ AttachFile-new.py 2006-07-11 07:06:50.000000000 +0000 @@ -283,7 +283,7 @@ def _get_files(request, pagename): attach_dir = getAttachDir(request, pagename) if os.path.isdir(attach_dir): - files = map(lambda a: a.decode(config.charset), os.listdir(attach_dir)) + files = map(lambda a: a.decode(config.charset), os.listdir(type(str())(attach_dir))) files.sort() return files return []
Discussion
The system encoding is
>>> import sys >>> sys.getfilesystemencoding() 'ANSI_X3.4-1968'
It's an otherwise standard Debian system
- Please specify which moin version you are using.
- This systemencoding looks somewhat strange, for what is this used?
- Please explain the new code from your patch, it looks a bit strange to me.
Plan
- Priority:
- Assigned to:
- Status: Please do not use unicode strings for data_dir.