Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit 0a0b492

Browse files
committed
python keywords not handled correctly at command level
1 parent 08a02ef commit 0a0b492

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

cli4/cli4.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import sys
55
import re
66
import getopt
7+
import keyword
78
import json
89

910
my_yaml = None
@@ -237,13 +238,16 @@ def run_command(cf, method, command, params=None, content=None, files=None):
237238
raise e
238239
else:
239240
try:
240-
# dashes (vs underscores) cause issues in Python and other languages
241-
if '-' in element:
241+
if keyword.iskeyword(element):
242+
# a keyword is appended with an extra underscore so it can used with Python code
243+
m = getattr(m, element + '_')
244+
elif '-' in element:
245+
# dashes (vs underscores) cause issues in Python and other languages
242246
m = getattr(m, element.replace('-','_'))
243247
else:
244248
m = getattr(m, element)
245249
cmd.append(element)
246-
except AttributeError:
250+
except AttributeError as e:
247251
# the verb/element was not found
248252
sys.stderr.write('cli4: /%s - not found\n' % (command))
249253
raise e

0 commit comments

Comments
 (0)