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
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
978084f7
authored
Aug 18, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
properly check command arguments
fixes
#6
parent
50c7b745
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
15 deletions
+21
-15
agent.py
+21
-15
No files found.
agent.py
View file @
978084f7
...
...
@@ -15,6 +15,7 @@ import tarfile
from
os.path
import
expanduser
,
join
,
exists
from
os
import
mkdir
,
environ
from
glob
import
glob
from
inspect
import
getargspec
from
StringIO
import
StringIO
from
base64
import
decodestring
from
shutil
import
rmtree
,
move
...
...
@@ -346,24 +347,29 @@ class SerialLineReceiver(SerialLineReceiverBase):
self
.
send_response
(
response
=
'status'
,
args
=
args
)
def
handle
_command
(
self
,
command
,
args
):
def
_get
_command
(
self
,
command
,
args
):
if
not
isinstance
(
command
,
basestring
)
or
command
.
startswith
(
'_'
):
raise
Exception
(
u'Invalid command:
%
s'
%
command
)
for
k
,
v
in
args
.
iteritems
():
if
not
(
isinstance
(
v
,
int
)
or
isinstance
(
v
,
float
)
or
isinstance
(
v
,
basestring
)):
raise
Exception
(
u'Invalid argument:
%
s'
%
k
)
raise
AttributeError
(
u'Invalid command:
%
s'
%
command
)
try
:
func
=
getattr
(
Context
,
command
)
retval
=
func
(
**
args
)
except
(
AttributeError
,
TypeError
)
as
e
:
raise
Exception
(
u'Command not found:
%
s (
%
s)'
%
(
command
,
e
))
else
:
self
.
send_response
(
response
=
func
.
__name__
,
args
=
{
'retval'
:
retval
,
'uuid'
:
args
.
get
(
'uuid'
,
None
)})
except
AttributeError
as
e
:
raise
AttributeError
(
u'Command not found:
%
s (
%
s)'
%
(
command
,
e
))
# check for unexpected keyword arguments
argspec
=
getargspec
(
func
)
if
argspec
.
keywords
is
None
:
# _operation doesn't take ** args
unexpected_kwargs
=
set
(
args
)
-
set
(
argspec
.
args
)
if
unexpected_kwargs
:
raise
TypeError
(
"Command got unexpected keyword arguments: "
"
%
s"
%
", "
.
join
(
unexpected_kwargs
))
return
func
def
handle_command
(
self
,
command
,
args
):
func
=
self
.
_get_command
(
command
,
args
)
retval
=
func
(
**
args
)
self
.
send_response
(
response
=
func
.
__name__
,
args
=
{
'retval'
:
retval
,
'uuid'
:
args
.
get
(
'uuid'
,
None
)})
def
handle_response
(
self
,
response
,
args
):
pass
...
...
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