Hello, With z3c.extfile, if the path name of the HashDir utility is a unicode string, as configured by the <hashDir> directive in zcml, a unicode digest will be returned. However, loading the file with this digest raises a ValueError, since the getPath function only recognizes StringType as digest:
>>> from z3c.extfile import hashdir >>> import tempfile, os >>> tmp = tempfile.mkdtemp() >>> hdPath = os.path.join(tmp, u'testhashdir') >>> hdPath u'/tmp/tmpapwlBZ/testhashdir' >>> hd = hashdir.HashDir(hdPath) >>> from z3c.extfile.property import ExtBytesProperty >>> from cStringIO import StringIO >>> class Foo(object): ... data = ExtBytesProperty('data') ... ... >>> foo = Foo() >>> from z3c.extfile.interfaces import IHashDir >>> from zope import component >>> component.provideUtility(hd, provides=IHashDir) >>> si = StringIO('hello world') >>> foo.data=si >>> foo.data <ReadFile named u'2aae6c35c94fcfb415dbe95f408b9ce91ee846ed'> >>> foo.data.digest u'2aae6c35c94fcfb415dbe95f408b9ce91ee846ed' >>> [u'2aae6c35c94fcfb415dbe95f408b9ce91ee846ed'] >>> hd.getPath(foo.data.digest) Traceback (most recent call last): File "<console>", line 1, in <module> File "/home/hong/workspace/eggs/z3c.extfile-0.2.0a2-py2.5.egg/z3c/extfile/hashdir.py", line 64, in getPath raise ValueError, repr(digest) ValueError: u'2aae6c35c94fcfb415dbe95f408b9ce91ee846ed' Below is the patch that fixes this. I am not sure if this is the best, since it allows the file digest to be unicode. Can someone have a look? Index: hashdir.py =================================================================== --- hashdir.py (revision 85015) +++ hashdir.py (working copy) @@ -3,7 +3,7 @@ import stat import tempfile import shutil -from types import StringType +from types import StringTypes import interfaces from zope import interface from persistent import Persistent @@ -60,7 +60,7 @@ return os.listdir(self.var) def getPath(self, digest): - if type(digest) != StringType or len(digest) != 40: + if isinstance(digest, StringTypes) or len(digest) != 40: raise ValueError, repr(digest) path = os.path.join(self.var, digest) if not os.path.isfile(path): By the way, do I also use https://launchpad.net/zope3/+bugs for tracking bugs in z3c projects? -- Hong Yuan 大管家网上建材超市 装修装潢建材一站式购物 http://www.homemaster.cn
_______________________________________________ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users