def retrieve_descriptor(descriptor):
the_descriptor = descriptor<EOL>if the_descriptor is None:<EOL><INDENT>the_descriptor = {}<EOL><DEDENT>if isinstance(the_descriptor, six.string_types):<EOL><INDENT>try:<EOL><INDENT>if os.path.isfile(the_descriptor):<EOL><INDENT>with open(the_descriptor, '<STR_LIT:r>') as f:<EOL><INDENT>the_descriptor = json.load(f)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>req = requests.get(the_descriptor)<EOL>req.raise_for_status()<EOL>req.encoding = '<STR_LIT:utf8>'<EOL>the_descriptor = req.json()<EOL><DEDENT><DEDENT>except (IOError, requests.exceptions.RequestException) as error:<EOL><INDENT>message = '<STR_LIT>' % descriptor<EOL>six.raise_from(exceptions.DataPackageException(message), error)<EOL><DEDENT>except ValueError as error:<EOL><INDENT>message = '<STR_LIT>' % (descriptor, error)<EOL>six.raise_from(exceptions.DataPackageException(message), error)<EOL><DEDENT><DEDENT>if hasattr(the_descriptor, '<STR_LIT>'):<EOL><INDENT>try:<EOL><INDENT>the_descriptor = json.load(the_descriptor)<EOL><DEDENT>except ValueError as e:<EOL><INDENT>six.raise_from(exceptions.DataPackageException(str(e)), e)<EOL><DEDENT><DEDENT>if not isinstance(the_descriptor, dict):<EOL><INDENT>msg = '<STR_LIT>'<EOL>raise exceptions.DataPackageException(msg.format(type(the_descriptor).__name__))<EOL><DEDENT>return the_descriptor<EOL>
Retrieve descriptor.