Feature Requests item #1712419, was opened at 2007-05-03 22:49 Message generated for change (Comment added) made by gbrandl You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1712419&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Unicode Group: None >Status: Closed >Resolution: Wont Fix Priority: 5 Private: No Submitted By: Viktor Ferenczi (complex) Assigned to: Nobody/Anonymous (nobody) Summary: Cannot use dict with unicode keys as keyword arguments Initial Comment: Unicode strings cannot be used as keys in dictionaries passed as keyword argument to a function. For example: Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> def fn(**kw): ... print repr(kw) ... >>> fn(**{u'x':1}) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: fn() keywords must be strings >>> Unicode strings should be converted to str automatically using the site specific default encoding or something similar solution. This bug caused problems when decoding dictionaries from data formats such as XML or JSON. Usually unicode strings are returned from such modules, such as simplejson. Manual encoding from unicode to str causes performance loss if this cannot be done by Python automatically. ---------------------------------------------------------------------- >Comment By: Georg Brandl (gbrandl) Date: 2007-05-19 18:14 Message: Logged In: YES user_id=849994 Originator: NO Yeah, should be uncontroversial. ---------------------------------------------------------------------- Comment By: Raymond Hettinger (rhettinger) Date: 2007-05-18 23:53 Message: Logged In: YES user_id=80475 Originator: NO Recommend closing this as not-a-bug. ---------------------------------------------------------------------- Comment By: M.-A. Lemburg (lemburg) Date: 2007-05-04 10:27 Message: Logged In: YES user_id=38388 Originator: NO Python (currently) does not allow non-ASCII identifiers, so it's not surprising that Unicode parameter names don't work. It's also a really bad idea to pass data from an AJAX XML or JSON request directly to a function without doing at least some post-processing of the data in order to prevent DOS attacks, code injection, etc. dict((str(key), value) for key, value in kw.iteritems()) is all that's needed for the above. BTW, I don't think those few micro-seconds really matter in the face of XML or JSON decoding, network latency, etc. ;-) ---------------------------------------------------------------------- Comment By: Georg Brandl (gbrandl) Date: 2007-05-04 04:10 Message: Logged In: YES user_id=849994 Originator: NO In any case, this is a feature request. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=355470&aid=1712419&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com