Skip to content

Commit

Permalink
get client context base from utilpack
Browse files Browse the repository at this point in the history
  • Loading branch information
David Erb committed Jun 3, 2023
1 parent 05ee575 commit 3c6d920
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 60 deletions.
35 changes: 0 additions & 35 deletions src/dls_servbase_api/context_base.py

This file was deleted.

34 changes: 14 additions & 20 deletions src/dls_servbase_api/datafaces/context.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import logging

# Base class.
from dls_utilpack.client_context_base import ClientContextBase

# Things created in the context.
from dls_servbase_api.datafaces.datafaces import (
Datafaces,
Expand All @@ -9,48 +12,39 @@
logger = logging.getLogger(__name__)


class Context:
class Context(ClientContextBase):
"""
Client context for a dls_servbase_dataface object.
On entering, it creates the object according to the specification (a dict).
On exiting, it closes client connection.
The aenter and aexit methods are exposed for use by an enclosing context.
The aenter and aexit methods are exposed for use by an enclosing context and the base class.
"""

# ----------------------------------------------------------------------------------------
def __init__(self, specification):
self.__specification = specification
self.__dls_servbase_dataface = None

# ----------------------------------------------------------------------------------------
async def __aenter__(self):
""" """

await self.aenter()

# ----------------------------------------------------------------------------------------
async def __aexit__(self, type, value, traceback):
""" """

await self.aexit()
ClientContextBase.__init__(self, specification)

# ----------------------------------------------------------------------------------------
async def aenter(self):
""" """

# Build the object according to the specification.
self.__dls_servbase_dataface = Datafaces().build_object(self.__specification)
self.interface = Datafaces().build_object(self.specification)

# If there is more than one dataface, the last one defined will be the default.
dls_servbase_datafaces_set_default(self.__dls_servbase_dataface)
dls_servbase_datafaces_set_default(self.interface)

# Open client session to the service or direct connection.
await self.interface.open_client_session()

# ----------------------------------------------------------------------------------------
async def aexit(self):
""" """

if self.__dls_servbase_dataface is not None:
await self.__dls_servbase_dataface.close_client_session()
if self.interface is not None:
# Close client session to the service or direct connection.
await self.interface.close_client_session()

# Clear the global variable. Important between pytests.
dls_servbase_datafaces_set_default(None)
10 changes: 5 additions & 5 deletions src/dls_servbase_api/guis/context.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import logging

# Base class.
from dls_servbase_api.context_base import ContextBase
from dls_utilpack.client_context_base import ClientContextBase

# Things created in the context.
from dls_servbase_api.guis.guis import Guis, dls_servbase_guis_set_default

logger = logging.getLogger(__name__)


class Context(ContextBase):
class Context(ClientContextBase):
"""
Client context for a dls_servbase_gui object.
On entering, it creates the object according to the specification (a dict).
On exiting, it closes client connection.
The aenter and aexit methods are exposed for use by an enclosing context.
The aenter and aexit methods are exposed for use by an enclosing context and the base class.
"""

# ----------------------------------------------------------------------------------------
def __init__(self, specification):
self.__specification = specification
ClientContextBase.__init__(self, specification)

# ----------------------------------------------------------------------------------------
async def aenter(self):
""" """

# Build the object according to the specification.
self.interface = Guis().build_object(self.__specification)
self.interface = Guis().build_object(self.specification)

# If there is more than one gui, the last one defined will be the default.
dls_servbase_guis_set_default(self.interface)
Expand Down

0 comments on commit 3c6d920

Please sign in to comment.