[ python-Feature Requests-1036490 ] Extend Shelf to support unicode keys

SourceForge.net noreply at sourceforge.net
Sat Nov 13 12:26:34 CET 2004


Feature Requests item #1036490, was opened at 2004-09-28 21:50
Message generated for change (Comment added) made by loewis
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1036490&group_id=5470

Category: Unicode
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Morten Kjeldgaard (mok0)
Assigned to: Nobody/Anonymous (nobody)
Summary: Extend Shelf to support unicode keys

Initial Comment:
Lots of modules return unicode strings, for example the
xml parser. There is no reason why you shouldn't be
able to use a unicode string as key in a dictionary,
shelve or database lookup. I think this is more a bug
than a feature, since having to make sure what type
your keys are makes the code bloated and ugly.



----------------------------------------------------------------------

>Comment By: Martin v. Löwis (loewis)
Date: 2004-11-13 12:26

Message:
Logged In: YES 
user_id=21627

It would be possible to add a unicode argument to the shelve
constructors; this would .encode all keys being passed in,
and .decode all keys being passed out. Canonically, keys
should be encoded as UTF-8.

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2004-09-28 23:53

Message:
Logged In: YES 
user_id=31435

Reset the Category to Unicode; SF lost it on the way to the 
Feature tracker.

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2004-09-28 23:48

Message:
Logged In: YES 
user_id=31435

Moved to the Feature Request tracker, and changed the 
summary to something more accurate.

The restriction to string keys is documented, and the code is 
functioning as documented.  The restriction is hard to lift 
because the underlying database technologies (gdbm, bsddb) 
require string keys.

I suppose Shelf could encode all incoming keys via utf-8, in 
every method taking a key argument, and decode again in all 
ways of getting keys out, but that wouldn't be backward 
compatible.

Unassigned Marc-Andre since I doubt he's going to do 
something about this.

----------------------------------------------------------------------

Comment By: Morten Kjeldgaard (mok0)
Date: 2004-09-28 22:58

Message:
Logged In: YES 
user_id=42755

You are right, unicode strings work in dictionaries. I
should have checked, sorry. However, they don't work in
shelves, as the attached script will demonstrate. You get a
type error:

Traceback (most recent call last):
  File "fail.py", line 7, in ?
    x[a] = "arrrghhh"
  File "/usr/lib/python2.3/shelve.py", line 130, in __setitem__
    self.dict[key] = f.getvalue()
  File "/usr/lib/python2.3/site-packages/__init__.py", line
120, in __setitem__

TypeError: String or Integer object expected for key,
unicode found

I am using Python 2.3.3 on Linux

----------------------------------------------------------------------

Comment By: David Goodger (goodger)
Date: 2004-09-28 22:35

Message:
Logged In: YES 
user_id=7733

Unicode strings work as dictionary keys for me, in both
Python 2.3.3 and 2.4a3.  Are you sure of your assertion? 
Please provide some evidence.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1036490&group_id=5470


More information about the Python-bugs-list mailing list