parameters: (resource, name)
docstring: Load a resource that could be a file, URL, or json string.
docstring_summary: Load a resource that could be a file, URL, or json string.
docstring_tokens: Load a resource that could be a file URL or json string .
function: def _load_resource(resource, name):
      """Load a resource that could be a file, URL, or json string."""
      # if it's a url, download it
      if resource.startswith('http://') or resource.startswith('https://'):
          try:
              download = urlopen(resource)
          except URLError as err:
              raise err
          else:
              return _decode_response(download)
      # If it's a filepath, load it
      try:
          is_file = isfile(resource)
      except ValueError:
          # check for error with long filepath (or URL) on Windows
          is_file = False
      if is_file:
          try:
              with open(resource, 'rb') as f:
                  loaded_resource = f.read().decode('utf-8')
              _ = json.loads(loaded_resource)
          except ValueError as err:
              raise ValueError('%s not a valid json file' % name)
          else:
              return loaded_resource
      # try to validate the json
      try:
          _ = json.loads(resource)
      except ValueError as err:
          raise ValueError('Could not load %s. Not valid json, url, or filepath'
                           % name)
      else:
          return resource
      raise Exception('Could not load %s.' % name)
function_tokens: def _load_resource ( resource , name ) : # if it's a url, download it if resource . startswith ( 'http://' ) or resource . startswith ( 'https://' ) : try : download = urlopen ( resource ) except URLError as err : raise err else : return _decode_response ( download ) # If it's a filepath, load it try : is_file = isfile ( resource ) except ValueError : # check for error with long filepath (or URL) on Windows is_file = False if is_file : try : with open ( resource , 'rb' ) as f : loaded_resource = f . read ( ) . decode ( 'utf-8' ) _ = json . loads ( loaded_resource ) except ValueError as err : raise ValueError ( '%s not a valid json file' % name ) else : return loaded_resource # try to validate the json try : _ = json . loads ( resource ) except ValueError as err : raise ValueError ( 'Could not load %s. Not valid json, url, or filepath' % name ) else : return resource raise Exception ( 'Could not load %s.' % name )