33Definition of an OMC session.
44"""
55
6+ from __future__ import annotations
7+
68__license__ = """
79 This file is part of OpenModelica.
810
3335"""
3436
3537import shutil
36- import abc
3738import getpass
3839import logging
3940import json
@@ -80,9 +81,12 @@ class OMCSessionException(Exception):
8081 pass
8182
8283
83- class OMCSessionBase ( metaclass = abc . ABCMeta ) :
84+ class OMCSessionCmd :
8485
85- def __init__ (self , readonly = False ):
86+ def __init__ (self , session : OMCSessionZMQ , readonly : Optional [bool ] = False ):
87+ if not isinstance (session , OMCSessionZMQ ):
88+ raise OMCSessionException ("Invalid session definition!" )
89+ self ._session = session
8690 self ._readonly = readonly
8791 self ._omc_cache = {}
8892
@@ -92,21 +96,6 @@ def execute(self, command):
9296
9397 return self .sendExpression (command , parsed = False )
9498
95- @abc .abstractmethod
96- def sendExpression (self , command , parsed = True ):
97- """
98- Sends an expression to the OpenModelica. The return type is parsed as if the
99- expression was part of the typed OpenModelica API (see ModelicaBuiltin.mo).
100- * Integer and Real are returned as Python numbers
101- * Strings, enumerations, and typenames are returned as Python strings
102- * Arrays, tuples, and MetaModelica lists are returned as tuples
103- * Records are returned as dicts (the name of the record is lost)
104- * Booleans are returned as True or False
105- * NONE() is returned as None
106- * SOME(value) is returned as value
107- """
108- pass
109-
11099 def _ask (self , question : str , opt : Optional [list [str ]] = None , parsed : Optional [bool ] = True ):
111100
112101 if opt is None :
@@ -126,7 +115,7 @@ def _ask(self, question: str, opt: Optional[list[str]] = None, parsed: Optional[
126115 logger .debug ('OMC ask: %s (parsed=%s)' , expression , parsed )
127116
128117 try :
129- res = self .sendExpression (expression , parsed = parsed )
118+ res = self ._session . sendExpression (expression , parsed = parsed )
130119 except OMCSessionException as ex :
131120 raise OMCSessionException ("OMC _ask() failed: %s (parsed=%s)" , expression , parsed ) from ex
132121
@@ -282,16 +271,14 @@ def getClassNames(self, className=None, recursive=False, qualified=False, sort=F
282271 return value
283272
284273
285- class OMCSessionZMQ ( OMCSessionBase ) :
274+ class OMCSessionZMQ :
286275
287276 def __init__ (self , readonly = False , timeout = 10.00 ,
288277 docker = None , dockerContainer = None , dockerExtraArgs = None , dockerOpenModelicaPath = "omc" ,
289278 dockerNetwork = None , port = None , omhome : str = None ):
290279 if dockerExtraArgs is None :
291280 dockerExtraArgs = []
292281
293- super ().__init__ (readonly = readonly )
294-
295282 self .omhome = self ._get_omhome (omhome = omhome )
296283
297284 self ._omc_process = None
0 commit comments