import geopandas
from pyogrio.errors import DataSourceError
from shapely.errors import GEOSException


def is_valid(resource, file):
    """Check if the content is a readable GML file."""

    with open(file.name, "rb") as f:
        try:
            geopandas.read_file(f)
            return True
        except DataSourceError as e:
            resource["error"] = str(e)
            return False
        except GEOSException as e:
            resource["error"] = str(e)
            return False
        except Exception as e:
            resource["error"] = str(e)
            return False