summaryrefslogtreecommitdiff
path: root/keystoneclient/base.py
diff options
context:
space:
mode:
authorRoman Bogorodskiy <bogorodskiy@gmail.com>2016-09-22 02:06:53 -0400
committerRoman Bogorodskiy <bogorodskiy@gmail.com>2016-09-24 21:18:22 +0300
commitdc9e4491779c0347f4eb770de03827b967541bf3 (patch)
tree35bc5eec3696c48f6657e6e7c822a1b54fd57d38 /keystoneclient/base.py
parent659ee35babe95cea0bf43e2330681d27608956af (diff)
downloadpython-keystoneclient-dc9e4491779c0347f4eb770de03827b967541bf3.tar.gz
Fix non-ascii attributes
It's possible to set and get custom attributes through the API, and it's also possible to use any Unicode strings, not only ASCII range. It works perfectly fine when accessing the API directly using e.g. curl. However, keystoneclient stumbles on the non-ascii keys because it tries to set this as an attribute for the resource class and fails because Python 2.7 does not support non-ascii identifiers: https://docs.python.org/2.7/reference/lexical_analysis.html#identifiers So change the logic to skip setting non-ascii attributes; they are still available in the dict representation. Closes-Bug: #1626403 Change-Id: I267188cdb1d303e3d0fb6bd3229b606f4fe9b2d8
Diffstat (limited to 'keystoneclient/base.py')
-rw-r--r--keystoneclient/base.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/keystoneclient/base.py b/keystoneclient/base.py
index 3f13a6c..af37222 100644
--- a/keystoneclient/base.py
+++ b/keystoneclient/base.py
@@ -479,7 +479,14 @@ class Resource(object):
def _add_details(self, info):
for (k, v) in six.iteritems(info):
try:
- setattr(self, k, v)
+ try:
+ setattr(self, k, v)
+ except UnicodeEncodeError:
+ # This happens when we're running with Python version that
+ # does not support Unicode identifiers (e.g. Python 2.7).
+ # In that case we can't help but not set this attrubute;
+ # it'll be available in a dict representation though
+ pass
self._info[k] = v
except AttributeError: # nosec(cjschaef): we already defined the
# attribute on the class