Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
itminedu
synnefo
Commits
2b0a9c6a
Commit
2b0a9c6a
authored
Apr 12, 2013
by
Ilias Tsitsimpis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
astakosclient: Raise BadValue when failing to parse request data
parent
d9258b6d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
6 deletions
+20
-6
astakosclient/astakosclient/__init__.py
astakosclient/astakosclient/__init__.py
+7
-5
astakosclient/astakosclient/utils.py
astakosclient/astakosclient/utils.py
+13
-1
No files found.
astakosclient/astakosclient/__init__.py
View file @
2b0a9c6a
...
...
@@ -38,7 +38,7 @@ import hashlib
from
copy
import
copy
import
simplejson
from
astakosclient.utils
import
retry
,
scheme_to_class
from
astakosclient.utils
import
retry
,
scheme_to_class
,
parse_request
from
astakosclient.errors
import
\
AstakosClientException
,
Unauthorized
,
BadRequest
,
NotFound
,
Forbidden
,
\
NoUserName
,
NoUUID
,
BadValue
,
QuotaLimit
,
InvalidResponse
...
...
@@ -170,6 +170,8 @@ class AstakosClient():
else
:
return
""
except
Exception
as
err
:
self
.
logger
.
error
(
"Cannot parse response
\"
%s
\"
with simplejson: %s"
%
(
data
,
str
(
err
)))
raise
InvalidResponse
(
str
(
err
),
data
)
# ------------------------
...
...
@@ -196,7 +198,7 @@ class AstakosClient():
# with {'uuids': uuids}
def
_uuid_catalog
(
self
,
token
,
uuids
,
req_path
):
req_headers
=
{
'content-type'
:
'application/json'
}
req_body
=
simplejson
.
dumps
({
'uuids'
:
uuids
})
req_body
=
parse_request
({
'uuids'
:
uuids
}
,
self
.
logger
)
data
=
self
.
_call_astakos
(
token
,
req_path
,
req_headers
,
req_body
,
"POST"
)
if
"uuid_catalog"
in
data
:
...
...
@@ -255,7 +257,7 @@ class AstakosClient():
# with {'displaynames': display_names}
def
_displayname_catalog
(
self
,
token
,
display_names
,
req_path
):
req_headers
=
{
'content-type'
:
'application/json'
}
req_body
=
simplejson
.
dumps
({
'displaynames'
:
display_names
})
req_body
=
parse_request
({
'displaynames'
:
display_names
}
,
self
.
logger
)
data
=
self
.
_call_astakos
(
token
,
req_path
,
req_headers
,
req_body
,
"POST"
)
if
"displayname_catalog"
in
data
:
...
...
@@ -349,7 +351,7 @@ class AstakosClient():
"""
req_headers
=
{
'content-type'
:
'application/json'
}
req_body
=
simplejson
.
dumps
(
request
)
req_body
=
parse_request
(
request
,
self
.
logger
)
try
:
response
=
self
.
_call_astakos
(
token
,
"/astakos/api/commissions"
,
req_headers
,
req_body
,
"POST"
)
...
...
@@ -426,7 +428,7 @@ class AstakosClient():
path
=
"/astakos/api/commissions/"
+
str
(
serial
)
+
"/action"
req_headers
=
{
'content-type'
:
'application/json'
}
req_body
=
simplejson
.
dumps
({
str
(
action
):
""
})
req_body
=
parse_request
({
str
(
action
):
""
}
,
self
.
logger
)
self
.
_call_astakos
(
token
,
path
,
req_headers
,
req_body
,
"POST"
)
def
issue_commission_accept
(
self
,
token
,
serial
):
...
...
astakosclient/astakosclient/utils.py
View file @
2b0a9c6a
...
...
@@ -34,8 +34,9 @@
from
httplib
import
HTTPConnection
,
HTTPSConnection
from
contextlib
import
closing
import
simplejson
from
objpool.http
import
PooledHTTPConnection
from
astakosclient.errors
import
AstakosClientException
from
astakosclient.errors
import
AstakosClientException
,
BadValue
def
retry
(
func
):
...
...
@@ -81,3 +82,14 @@ def scheme_to_class(scheme, use_pool, pool_size):
return
_https_connection
else
:
return
None
def
parse_request
(
request
,
logger
):
"""Parse request with simplejson to convert it to string"""
try
:
return
simplejson
.
dumps
(
request
)
except
Exception
as
err
:
m
=
"Cannot parse request
\"
%s
\"
with simplejson: %s"
\
%
(
request
,
str
(
err
))
logger
.
error
(
m
)
raise
BadValue
(
m
)
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