def walk_metadata(metadata_url, headers=None, expect_json=False):
 metadata = dict()
 for line in query_metadata(metadata_url, headers, expect_json):
  if (line.endswith('/') and (not (line == 'public-keys/'))):
   key = line[:(-1)]
   metadata[key] = walk_metadata((metadata_url + line), headers, expect_json)
  else:
   results = query_metadata((metadata_url + line), headers, expect_json)
   if (len(results) == 1):
    metadata[line] = results.pop()
   else:
    metadata[line] = results
 return metadata

def walk_metadata ( metadata_url , headers = None , expect_json = False ) : metadata = dict ( ) for line in query_metadata ( metadata_url , headers , expect_json ) : if ( line . endswith ( '/' ) and ( not ( line == 'public-keys/' ) ) ) : key = line [ : ( - 1 ) ] metadata [ key ] = walk_metadata ( ( metadata_url + line ) , headers , expect_json ) else : results = query_metadata ( ( metadata_url + line ) , headers , expect_json ) if ( len ( results ) == 1 ) : metadata [ line ] = results . pop ( ) else : metadata [ line ] = results return metadata
walk the metadata tree and return a dictionary of the entire tree args: metadata_url : metadata url headers : headers to set for metadata request expect_json : does the metadata_url return json returns: dict: the result of walking the metadata tree .