def _parse_resource_usage(cls, action_dict, declarations):
        """Parse out what resources are used, opened and closed in an action step."""

        raw_used = action_dict.pop('use', [])
        opened = [x.strip() for x in action_dict.pop('open_before', [])]
        closed = [x.strip() for x in action_dict.pop('close_after', [])]

        used = {}

        for resource in raw_used:
            if 'as' in resource:
                global_name, _, local_name = resource.partition('as')
                global_name = global_name.strip()
                local_name = local_name.strip()

                if len(global_name) == 0 or len(local_name) == 0:
                    raise RecipeFileInvalid("Resource usage specified in action with invalid name using 'as' statement", global_name=global_name, local_name=local_name, statement=resource)
            else:
                global_name = resource.strip()
                local_name = global_name

            if local_name in used:
                raise RecipeFileInvalid("Resource specified twice for action", args=action_dict, resource=local_name, used_resources=used)

            used[local_name] = global_name

        # Make sure we only use, open and close declared resources
        for name in (x for x in used.values() if x not in declarations):
            raise RecipeFileInvalid("Action makes use of non-declared shared resource", name=name)

        for name in (x for x in opened if x not in declarations):
            raise RecipeFileInvalid("Action specified a non-declared shared resource in open_before", name=name)

        for name in (x for x in closed if x not in declarations):
            raise RecipeFileInvalid("Action specified a non-declared shared resource in close_after", name=name)

        return ResourceUsage(used, opened, closed)
Parse out what resources are used, opened and closed in an action step.