New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
shelve.open/bsddb.hashopen exception with unicode paths #53639
Comments
Windows XP Simple Chinese Version temppath = u"D:\\你好新建文件夹\\a"
import shelve
cache = shelve.open(temppath, 'c')
# when use temppath.encode("utf-8"),it works, but I got a Error with such traceback Traceback (most recent call last):
File "D:\eclipse_workspace\pytest\src\test.py", line 5, in <module>
cache = shelve.open(temppath, 'c')
File "D:\eclipse_workspace\omstarv5r6\linksvn\src\UNPPython\pywindows\Lib\shelve.py", line 225, in open
return DbfilenameShelf(filename, flag, protocol, writeback)
File "D:\eclipse_workspace\omstarv5r6\linksvn\src\UNPPython\pywindows\Lib\shelve.py", line 209, in __init__
Shelf.__init__(self, anydbm.open(filename, flag), protocol, writeback)
File "D:\eclipse_workspace\omstarv5r6\linksvn\src\UNPPython\pywindows\Lib\anydbm.py", line 83, in open
return mod.open(file, flag, mode)
File "D:\eclipse_workspace\omstarv5r6\linksvn\src\UNPPython\pywindows\Lib\dbhash.py", line 16, in open
return bsddb.hashopen(file, flag, mode)
File "D:\eclipse_workspace\omstarv5r6\linksvn\src\UNPPython\pywindows\Lib\bsddb\__init__.py", line 310, in hashopen
d.open(file, db.DB_HASH, flags, mode)
bsddb.db.DBNoSuchFileError: (2, 'No such file or directory') |
I think it is supposed that unicode paths and GBK encoded str objects will be ok in Windows. |
shelve uses anydbm which uses gdbm, dbm or bsddbm. Attached patch fixes gdbm and dbm (replace "s" format by "et" with Py_FileSystemDefaultEncoding). bsddbm is harder to fix: bsdhashopen(), bsdbtopen() and bsdrnopen() have to be fixed, and they accept None for the filename ("z" format). |
sorry I donot know exactly your meaning, do you mean that I can use the attached patch to complie a new Python dll? can you explains more clearly? thank you very much |
Same patch for Python 3.2. |
Victor's comments were addressed to the python development community and concern python internals. Given that only bsddb exists on windows by default, his patches unfortunately don't do you any good. I'm adding jcea as nosy in case he wants to/can deal with the problem in bsddb. |
It looks like bsddb (dbm.bsd) module doesn't exist anymore in Python3: see issue bpo-9397. It's now maintained in the third party module pybsddb. |
New patch for bsddb module: create parse_filename() function, based on Python3 PyUnicode_FSConverter() but it accepts None. I didn't tested the patch because I'm unable to compile the module. It looks like it should use db_185.h instead of db.h, and link to another library, but configure or setup.py doesn't know it. |
dbm_open_unicode-32.patch no longer applied cleanly due to Argument Clinic. I'm not sure about applying patches to 2.7. I support this, but it looks as new feature, and you should ask on Python-Dev mailing list. |
Could you please update the patch Victor? |
You can update this old patch if you want. |
Python 3 is not affected: Python 3.5.0a0 (default:61a045ac0006, Jan 15 2015, 00:05:43)
[GCC 4.9.2 20141101 (Red Hat 4.9.2-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> temppath = u"D:\\你好新建文件夹\\a"
>>> import shelve
>>> cache = shelve.open(temppath, 'c') (no error) |
Oh sorry, dbm_open_unicode-32.patch is still needed. Currently, filenames are encoded to UTF-8 which "works" when the filesystem encoding is UTF-8, but it doesn't work on Windows. |
And needed tests. |
It was fixed in bpo-32922. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: