Skip to content

Commit 6a6b501

Browse files
committed
Do not strip the result
The output of `getComponentModifierValue` is changed so we don't need to strip the result. And the output of `getExtendsModifierValue` is changed in OpenModelica/OpenModelica#13533 Removed `_ask_with_fallback` and moved the fallback code to `sendExpression`
1 parent 6cfe458 commit 6a6b501

File tree

1 file changed

+11
-23
lines changed

1 file changed

+11
-23
lines changed

OMPython/OMCSession.py

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -128,23 +128,6 @@ def ask(self, question, opt=None, parsed=True):
128128

129129
return res
130130

131-
def _ask_with_fallback(self, question: str, opt: str = None):
132-
"""
133-
Version of ask() with OMTypedParser as fallback for OMParser which is used in ask() => sendExpression() if
134-
parsed is set to True.
135-
"""
136-
try:
137-
# FIXME: OMPython exception UnboundLocalError exception for 'Modelica.Fluid.Machines.ControlledPump'
138-
return self.ask(question=question, opt=opt)
139-
except pyparsing.ParseException as ex:
140-
logger.warning('OMTypedParser error: %s', ex.msg)
141-
result = self.ask(question=question, opt=opt, parsed=False)
142-
try:
143-
return om_parser_basic(result)
144-
except (TypeError, UnboundLocalError) as ex:
145-
logger.warning('OMParser error: %s', ex)
146-
return result
147-
148131
# TODO: Open Modelica Compiler API functions. Would be nice to generate these.
149132
def loadFile(self, filename):
150133
return self.ask('loadFile', f'"{filename}"')
@@ -253,15 +236,13 @@ def getComponentModifierNames(self, className, componentName):
253236
return self.ask('getComponentModifierNames', f'{className}, {componentName}')
254237

255238
def getComponentModifierValue(self, className, componentName):
256-
return self._ask_with_fallback(question='getComponentModifierValue',
257-
opt=f'{className}, {componentName}')
239+
return self.ask(question='getComponentModifierValue', opt=f'{className}, {componentName}')
258240

259241
def getExtendsModifierNames(self, className, componentName):
260242
return self.ask('getExtendsModifierNames', f'{className}, {componentName}')
261243

262244
def getExtendsModifierValue(self, className, extendsName, modifierName):
263-
return self._ask_with_fallback(question='getExtendsModifierValue',
264-
opt=f'{className}, {extendsName}, {modifierName}')
245+
return self.ask(question='getExtendsModifierValue', opt=f'{className}, {extendsName}, {modifierName}')
265246

266247
def getNthComponentModification(self, className, comp_id):
267248
# FIXME: OMPython exception Results KeyError exception
@@ -564,7 +545,14 @@ def sendExpression(self, command, parsed=True):
564545
else:
565546
result = self._omc.recv_string()
566547
if parsed is True:
567-
answer = om_parser_typed(result)
568-
return answer
548+
try:
549+
return om_parser_typed(result)
550+
except pyparsing.ParseException as ex:
551+
logger.warning('OMTypedParser error: %s. Returning the basic parser result.', ex.msg)
552+
try:
553+
return om_parser_basic(result)
554+
except (TypeError, UnboundLocalError) as ex:
555+
logger.warning('OMParser error: %s. Returning the unparsed result.', ex)
556+
return result
569557
else:
570558
return result

0 commit comments

Comments
 (0)