Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions gvm/protocols/gmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"""
from typing import Any, Optional, Callable, Union

from gvm.errors import GvmError
from gvm.errors import GvmClientError, GvmError

from gvm.protocols.base import GvmProtocol, GvmConnection

Expand All @@ -48,7 +48,7 @@ class Gmp(GvmProtocol):

from gvm.protocols.gmp import Gmp

with Gmp(connection) as gmp:
with Gmp(connection).supported_gmp as gmp:
# gmp can be an instance of gvm.protocols.gmpv208.Gmp,
# gvm.protocols.gmpv214.Gmp depending
# on the supported GMP version of the remote manager daemon
Expand Down Expand Up @@ -113,9 +113,12 @@ def determine_supported_gmp(self) -> SUPPORTED_GMP_VERSIONS:

return gmp_class(self._connection, transform=self._gmp_transform)

def __enter__(self):
gmp = self.determine_supported_gmp()

gmp.connect()
@property
def supported_gmp(self):
return self.determine_supported_gmp()

return gmp
def __enter__(self):
raise GvmClientError(
'You may not use Gmp for context directly. Please use property '
'supported_gmp instead.'
)