Skip to content
This repository has been archived by the owner on May 7, 2024. It is now read-only.

Commit

Permalink
python keywords not handled correctly at command level
Browse files Browse the repository at this point in the history
  • Loading branch information
mahtin committed May 19, 2023
1 parent 08a02ef commit 0a0b492
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions cli4/cli4.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
import re
import getopt
import keyword
import json

my_yaml = None
Expand Down Expand Up @@ -237,13 +238,16 @@ def run_command(cf, method, command, params=None, content=None, files=None):
raise e
else:
try:
# dashes (vs underscores) cause issues in Python and other languages
if '-' in element:
if keyword.iskeyword(element):
# a keyword is appended with an extra underscore so it can used with Python code
m = getattr(m, element + '_')
elif '-' in element:
# dashes (vs underscores) cause issues in Python and other languages
m = getattr(m, element.replace('-','_'))
else:
m = getattr(m, element)
cmd.append(element)
except AttributeError:
except AttributeError as e:
# the verb/element was not found
sys.stderr.write('cli4: /%s - not found\n' % (command))
raise e
Expand Down

0 comments on commit 0a0b492

Please sign in to comment.