<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def calc_buffered_bounds( format, bounds, meters_per_pixel_dim, layer_name, geometry_type, buffer_cfg):
 """ Calculate the buffered bounds per format per layer based on config. """


    if not buffer_cfg:
        return bounds

    format_buffer_cfg = buffer_cfg.get(format.extension)
    if format_buffer_cfg is None:
        return bounds

    geometry_type = normalize_geometry_type(geometry_type)

    per_layer_cfg = format_buffer_cfg.get('layer', {}).get(layer_name)
    if per_layer_cfg is not None:
        layer_geom_pixels = per_layer_cfg.get(geometry_type)
        if layer_geom_pixels is not None:
            assert isinstance(layer_geom_pixels, Number)
            result = bounds_buffer(
                bounds, meters_per_pixel_dim * layer_geom_pixels)
            return result

    by_geometry_pixels = format_buffer_cfg.get('geometry', {}).get(
        geometry_type)
    if by_geometry_pixels is not None:
        assert isinstance(by_geometry_pixels, Number)
        result = bounds_buffer(
            bounds, meters_per_pixel_dim * by_geometry_pixels)
        return result

    return bounds