<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def exec(self, container: Container, command: str, context: Optional[str] = None, stdout: bool = True, stderr: bool = False, time_limit: Optional[int] = None ) -> ExecResponse: """ Executes a given command inside a provided container. Parameters: container: the container to which the command should be issued. command: the command that should be executed. context: the working directory that should be used to perform the execution. If no context is provided, then the command will be executed at the root of the container. stdout: specifies whether or not output to the stdout should be included in the execution summary. stderr: specifies whether or not output to the stderr should be included in the execution summary. time_limit: an optional time limit that is applied to the execution. If the command fails to execute within the time limit, the command will be aborted and treated as a failure. Returns: a summary of the outcome of the execution. Raises: KeyError: if the container no longer exists on the server. """

        # FIXME perhaps these should be encoded as path variables?
        payload = {
            'command': command,
            'context': context,
            'stdout': stdout,
            'stderr': stderr,
            'time-limit': time_limit
        }
        path = "containers/{}/exec".format(container.uid)
        r = self.__api.post(path, json=payload)

        if r.status_code == 200:
            return ExecResponse.from_dict(r.json())
        if r.status_code == 404:
            raise KeyError("no container found with given UID: {}".format(container.uid))

        self.__api.handle_erroneous_response(r)