in libs/libcommon/src/libcommon/url_preparator.py [0:0]
def _prepare_asset_url_path_in_place(self, cell: Any, asset_url_path: AssetUrlPath, revision: str) -> Any:
if not cell:
return cell
elif len(asset_url_path.path) == 0:
if not isinstance(cell, dict):
raise InvalidFirstRowsError("Expected the cell to be a dict")
for key, value in cell.items():
if isinstance(value, dict):
# if the value is a dict, we have to prepare the URL in it for nested assets
self._prepare_asset_url_path_in_place(cell=value, asset_url_path=asset_url_path, revision=revision)
elif key == "src":
src = cell.get(key)
if not isinstance(src, str):
raise InvalidFirstRowsError(f'Expected cell["{key}"] to be a string')
cell[key] = self.prepare_url(src, revision=revision)
# ^ prepare the url in place
else:
key = asset_url_path.path[0]
if key == 0:
# it's a list, we have to prepare each element
if not isinstance(cell, list):
raise InvalidFirstRowsError("Expected the cell to be a list")
for cell_item in cell:
self._prepare_asset_url_path_in_place(
cell=cell_item, asset_url_path=asset_url_path.enter(), revision=revision
)
else:
# it's a dict, we have to prepare the value of the key
if not isinstance(cell, dict):
raise InvalidFirstRowsError("Expected the cell to be a dict")
self._prepare_asset_url_path_in_place(
cell=cell[key], asset_url_path=asset_url_path.enter(), revision=revision
)