import yaml


def get_time_limit(cwl_content: bytes) -> int:
    """Takes a CWL file contents and extracts cwl1.1-dev1 time limit.

    Supports only two of three possible ways of writing this. Returns
    0 if no value was specified, in which case the default should be
    used.

    Args:
        cwl_content: The contents of a CWL file.

    Returns:
        Time to reserve in seconds.
    """
    workflow = yaml.safe_load(cwl_content.decode())
    hints = workflow.get('hints')
    if hints is None:
        return 0

    time_limit = hints.get('TimeLimit')
    if time_limit is None:
        return 0

    if isinstance(time_limit, int):
        return time_limit
    elif isinstance(time_limit, dict):
        limit = time_limit.get('timeLimit')
        if limit is None:
            raise ValueError('Invalid TimeLimit specification in CWL file,'
                             ' expected timeLimit attribute')
        return limit
    else:
        raise ValueError('Invalid TimeLimit specification in CWL file,'
                         ' expected int or timeLimit attribute')