summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hellkamp <marc@gsites.de>2015-07-25 13:39:41 +0200
committerMarcel Hellkamp <marc@gsites.de>2015-07-25 13:39:41 +0200
commitef0623cbbfebfa62993126442969c32668fdcff4 (patch)
tree5934ad32a5d2d437cc471e5e1f578615674c60c4
parent813be605c1429ed8be53f159fa7c7b3c05dda79e (diff)
parent2f6c7811694d33fb5d1cffe8a7cd1c564936120c (diff)
downloadbottle-ef0623cbbfebfa62993126442969c32668fdcff4.tar.gz
Merge pull request #777 from goodmami/bugfix-720-0.12
Fix #720 : Allow unicode keys in ConfigDict.
-rw-r--r--bottle.py6
-rw-r--r--test/test_configdict.py13
2 files changed, 16 insertions, 3 deletions
diff --git a/bottle.py b/bottle.py
index 535ddd3..f99f46a 100644
--- a/bottle.py
+++ b/bottle.py
@@ -2107,7 +2107,7 @@ class ConfigDict(dict):
if not isinstance(source, dict):
raise TypeError('Source is not a dict (r)' % type(key))
for key, value in source.items():
- if not isinstance(key, str):
+ if not isinstance(key, basestring):
raise TypeError('Key is not a string (%r)' % type(key))
full_key = prefix + '.' + key if prefix else key
if isinstance(value, dict):
@@ -2123,7 +2123,7 @@ class ConfigDict(dict):
namespace. Apart from that it works just as the usual dict.update().
Example: ``update('some.namespace', key='value')`` '''
prefix = ''
- if a and isinstance(a[0], str):
+ if a and isinstance(a[0], basestring):
prefix = a[0].strip('.') + '.'
a = a[1:]
for key, value in dict(*a, **ka).items():
@@ -2135,7 +2135,7 @@ class ConfigDict(dict):
return self[key]
def __setitem__(self, key, value):
- if not isinstance(key, str):
+ if not isinstance(key, basestring):
raise TypeError('Key has type %r (not a string)' % type(key))
value = self.meta_get(key, 'filter', lambda x: x)(value)
diff --git a/test/test_configdict.py b/test/test_configdict.py
index 654ad7a..16719ab 100644
--- a/test/test_configdict.py
+++ b/test/test_configdict.py
@@ -75,6 +75,19 @@ class TestConfigDict(unittest.TestCase):
self.assertRaises(TypeError, lambda: setitem(c, 5, 6))
self.assertRaises(TypeError, lambda: c.load_dict({5:6}))
+ def test_issue720(self):
+ """Accept unicode keys."""
+ try:
+ key = unichr(12354)
+ except NameError:
+ key = chr(12354)
+ c = ConfigDict()
+ c.load_dict({key: 'value'})
+ self.assertEqual('value', c[key])
+ c = ConfigDict()
+ c.load_dict({key: {'subkey': 'value'}})
+ self.assertEqual('value', c[key + '.subkey'])
+
if __name__ == '__main__': #pragma: no cover
unittest.main()