Skip to content

Commit 3c6d920

Browse files
author
David Erb
committed
get client context base from utilpack
1 parent 05ee575 commit 3c6d920

File tree

3 files changed

+19
-60
lines changed

3 files changed

+19
-60
lines changed

src/dls_servbase_api/context_base.py

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import logging
22

3+
# Base class.
4+
from dls_utilpack.client_context_base import ClientContextBase
5+
36
# Things created in the context.
47
from dls_servbase_api.datafaces.datafaces import (
58
Datafaces,
@@ -9,48 +12,39 @@
912
logger = logging.getLogger(__name__)
1013

1114

12-
class Context:
15+
class Context(ClientContextBase):
1316
"""
1417
Client context for a dls_servbase_dataface object.
1518
On entering, it creates the object according to the specification (a dict).
1619
On exiting, it closes client connection.
1720
18-
The aenter and aexit methods are exposed for use by an enclosing context.
21+
The aenter and aexit methods are exposed for use by an enclosing context and the base class.
1922
"""
2023

2124
# ----------------------------------------------------------------------------------------
2225
def __init__(self, specification):
23-
self.__specification = specification
24-
self.__dls_servbase_dataface = None
25-
26-
# ----------------------------------------------------------------------------------------
27-
async def __aenter__(self):
28-
""" """
29-
30-
await self.aenter()
31-
32-
# ----------------------------------------------------------------------------------------
33-
async def __aexit__(self, type, value, traceback):
34-
""" """
35-
36-
await self.aexit()
26+
ClientContextBase.__init__(self, specification)
3727

3828
# ----------------------------------------------------------------------------------------
3929
async def aenter(self):
4030
""" """
4131

4232
# Build the object according to the specification.
43-
self.__dls_servbase_dataface = Datafaces().build_object(self.__specification)
33+
self.interface = Datafaces().build_object(self.specification)
4434

4535
# If there is more than one dataface, the last one defined will be the default.
46-
dls_servbase_datafaces_set_default(self.__dls_servbase_dataface)
36+
dls_servbase_datafaces_set_default(self.interface)
37+
38+
# Open client session to the service or direct connection.
39+
await self.interface.open_client_session()
4740

4841
# ----------------------------------------------------------------------------------------
4942
async def aexit(self):
5043
""" """
5144

52-
if self.__dls_servbase_dataface is not None:
53-
await self.__dls_servbase_dataface.close_client_session()
45+
if self.interface is not None:
46+
# Close client session to the service or direct connection.
47+
await self.interface.close_client_session()
5448

5549
# Clear the global variable. Important between pytests.
5650
dls_servbase_datafaces_set_default(None)

src/dls_servbase_api/guis/context.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
import logging
22

33
# Base class.
4-
from dls_servbase_api.context_base import ContextBase
4+
from dls_utilpack.client_context_base import ClientContextBase
55

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

99
logger = logging.getLogger(__name__)
1010

1111

12-
class Context(ContextBase):
12+
class Context(ClientContextBase):
1313
"""
1414
Client context for a dls_servbase_gui object.
1515
On entering, it creates the object according to the specification (a dict).
1616
On exiting, it closes client connection.
1717
18-
The aenter and aexit methods are exposed for use by an enclosing context.
18+
The aenter and aexit methods are exposed for use by an enclosing context and the base class.
1919
"""
2020

2121
# ----------------------------------------------------------------------------------------
2222
def __init__(self, specification):
23-
self.__specification = specification
23+
ClientContextBase.__init__(self, specification)
2424

2525
# ----------------------------------------------------------------------------------------
2626
async def aenter(self):
2727
""" """
2828

2929
# Build the object according to the specification.
30-
self.interface = Guis().build_object(self.__specification)
30+
self.interface = Guis().build_object(self.specification)
3131

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

0 commit comments

Comments
 (0)