Directly import the target module in

oauth2client.client.Credentials.new_from_json.

Reviewed in http://codereview.appspot.com/5085045/.
This commit is contained in:
Joe Gregorio
2011-10-13 10:03:28 -04:00
parent 39defdc33c
commit e9b40f1df9

View File

@@ -143,9 +143,7 @@ class Credentials(object):
data = simplejson.loads(s)
# Find and call the right classmethod from_json() to restore the object.
module = data['_module']
m = __import__(module)
for sub_module in module.split('.')[1:]:
m = getattr(m, sub_module)
m = __import__(module, fromlist=module.split('.')[:-1])
kls = getattr(m, data['_class'])
from_json = getattr(kls, 'from_json')
return from_json(s)