Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
agent
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
7
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
42599971
authored
Aug 19, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check for command args to be supplied in a dict
parent
6faa8044
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
11 deletions
+18
-11
agent.py
+18
-11
No files found.
agent.py
View file @
42599971
...
...
@@ -347,17 +347,11 @@ class SerialLineReceiver(SerialLineReceiverBase):
self
.
send_response
(
response
=
'status'
,
args
=
args
)
def
_get_command
(
self
,
command
,
args
):
if
not
isinstance
(
command
,
basestring
)
or
command
.
startswith
(
'_'
):
raise
AttributeError
(
u'Invalid command:
%
s'
%
command
)
try
:
func
=
getattr
(
Context
,
command
)
except
AttributeError
as
e
:
raise
AttributeError
(
u'Command not found:
%
s (
%
s)'
%
(
command
,
e
))
if
not
isfunction
(
func
):
raise
AttributeError
(
"Command refers to non-static method
%
s."
%
self
.
_pretty_fun
(
func
))
def
_check_args
(
self
,
func
,
args
):
if
not
isinstance
(
args
,
dict
):
raise
TypeError
(
"Arguments should be all keyword-arguments in a "
"dict for command
%
s instead of
%
s."
%
(
self
.
_pretty_fun
(
func
),
type
(
args
)
.
__name__
))
# check for unexpected keyword arguments
argspec
=
getargspec
(
func
)
...
...
@@ -376,6 +370,19 @@ class SerialLineReceiver(SerialLineReceiverBase):
raise
TypeError
(
"Command
%
s missing arguments:
%
s"
%
(
self
.
_pretty_fun
(
func
),
", "
.
join
(
missing_kwargs
)))
def
_get_command
(
self
,
command
,
args
):
if
not
isinstance
(
command
,
basestring
)
or
command
.
startswith
(
'_'
):
raise
AttributeError
(
u'Invalid command:
%
s'
%
command
)
try
:
func
=
getattr
(
Context
,
command
)
except
AttributeError
as
e
:
raise
AttributeError
(
u'Command not found:
%
s (
%
s)'
%
(
command
,
e
))
if
not
isfunction
(
func
):
raise
AttributeError
(
"Command refers to non-static method
%
s."
%
self
.
_pretty_fun
(
func
))
self
.
_check_args
(
func
,
args
)
return
func
@staticmethod
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment