Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Klaus Wölfel
slapos.core
Commits
0594e893
Commit
0594e893
authored
May 15, 2012
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Format json during response.
parent
46af2489
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
14 deletions
+17
-14
master/product/Vifib/Tool/VifibRestApiV1Tool.py
master/product/Vifib/Tool/VifibRestApiV1Tool.py
+17
-14
No files found.
master/product/Vifib/Tool/VifibRestApiV1Tool.py
View file @
0594e893
...
@@ -52,6 +52,9 @@ def etreeXml(d):
...
@@ -52,6 +52,9 @@ def etreeXml(d):
return
etree
.
tostring
(
r
,
pretty_print
=
True
,
xml_declaration
=
True
,
return
etree
.
tostring
(
r
,
pretty_print
=
True
,
xml_declaration
=
True
,
encoding
=
'utf-8'
)
encoding
=
'utf-8'
)
def
jsonify
(
d
):
return
json
.
dumps
(
d
,
indent
=
2
)
def
requireHeader
(
header_dict
):
def
requireHeader
(
header_dict
):
def
outer
(
fn
):
def
outer
(
fn
):
def
wrapperRequireHeader
(
self
,
*
args
,
**
kwargs
):
def
wrapperRequireHeader
(
self
,
*
args
,
**
kwargs
):
...
@@ -63,7 +66,7 @@ def requireHeader(header_dict):
...
@@ -63,7 +66,7 @@ def requireHeader(header_dict):
return
fn
(
self
,
*
args
,
**
kwargs
)
return
fn
(
self
,
*
args
,
**
kwargs
)
else
:
else
:
self
.
REQUEST
.
response
.
setStatus
(
400
)
self
.
REQUEST
.
response
.
setStatus
(
400
)
self
.
REQUEST
.
response
.
setBody
(
json
.
dumps
(
problem_dict
))
self
.
REQUEST
.
response
.
setBody
(
json
ify
(
problem_dict
))
return
self
.
REQUEST
.
response
return
self
.
REQUEST
.
response
wrapperRequireHeader
.
__doc__
=
fn
.
__doc__
wrapperRequireHeader
.
__doc__
=
fn
.
__doc__
...
@@ -116,7 +119,7 @@ def requireJson(json_dict, optional_key_list=None):
...
@@ -116,7 +119,7 @@ def requireJson(json_dict, optional_key_list=None):
self
.
jbody
=
json
.
load
(
self
.
REQUEST
.
stdin
)
self
.
jbody
=
json
.
load
(
self
.
REQUEST
.
stdin
)
except
Exception
:
except
Exception
:
self
.
REQUEST
.
response
.
setStatus
(
400
)
self
.
REQUEST
.
response
.
setStatus
(
400
)
self
.
REQUEST
.
response
.
setBody
(
json
.
dumps
(
self
.
REQUEST
.
response
.
setBody
(
json
ify
(
{
'error'
:
'Data is not json object.'
}))
{
'error'
:
'Data is not json object.'
}))
return
self
.
REQUEST
.
response
return
self
.
REQUEST
.
response
else
:
else
:
...
@@ -139,7 +142,7 @@ def requireJson(json_dict, optional_key_list=None):
...
@@ -139,7 +142,7 @@ def requireJson(json_dict, optional_key_list=None):
error_dict
[
key
]
=
'Malformed value.'
error_dict
[
key
]
=
'Malformed value.'
if
error_dict
:
if
error_dict
:
self
.
REQUEST
.
response
.
setStatus
(
400
)
self
.
REQUEST
.
response
.
setStatus
(
400
)
self
.
REQUEST
.
response
.
setBody
(
json
.
dumps
(
error_dict
))
self
.
REQUEST
.
response
.
setBody
(
json
ify
(
error_dict
))
return
self
.
REQUEST
.
response
return
self
.
REQUEST
.
response
return
fn
(
self
,
*
args
,
**
kwargs
)
return
fn
(
self
,
*
args
,
**
kwargs
)
wrapperRequireJson
.
__doc__
=
fn
.
__doc__
wrapperRequireJson
.
__doc__
=
fn
.
__doc__
...
@@ -174,7 +177,7 @@ def responseSupport(anonymous=False):
...
@@ -174,7 +177,7 @@ def responseSupport(anonymous=False):
'Currenty logged in user %r has no Person document.'
%
'Currenty logged in user %r has no Person document.'
%
self
.
getPortalObject
().
getAuthenticatedMember
())
self
.
getPortalObject
().
getAuthenticatedMember
())
self
.
REQUEST
.
response
.
setStatus
(
500
)
self
.
REQUEST
.
response
.
setStatus
(
500
)
self
.
REQUEST
.
response
.
setBody
(
json
.
dumps
({
'error'
:
self
.
REQUEST
.
response
.
setBody
(
json
ify
({
'error'
:
'There is system issue, please try again later.'
}))
'There is system issue, please try again later.'
}))
return
self
.
REQUEST
.
response
return
self
.
REQUEST
.
response
self
.
person_url
=
person
.
getRelativeUrl
()
self
.
person_url
=
person
.
getRelativeUrl
()
...
@@ -206,7 +209,7 @@ def extractInstance(fn):
...
@@ -206,7 +209,7 @@ def extractInstance(fn):
LOG
(
'VifibRestApiV1Tool'
,
ERROR
,
LOG
(
'VifibRestApiV1Tool'
,
ERROR
,
'Problem while trying to find instance:'
,
error
=
True
)
'Problem while trying to find instance:'
,
error
=
True
)
self
.
REQUEST
.
response
.
setStatus
(
500
)
self
.
REQUEST
.
response
.
setStatus
(
500
)
self
.
REQUEST
.
response
.
setBody
(
json
.
dumps
({
'error'
:
self
.
REQUEST
.
response
.
setBody
(
json
ify
({
'error'
:
'There is system issue, please try again later.'
}))
'There is system issue, please try again later.'
}))
else
:
else
:
self
.
REQUEST
[
'traverse_subpath'
]
=
self
.
REQUEST
[
'traverse_subpath'
][
2
:]
self
.
REQUEST
[
'traverse_subpath'
]
=
self
.
REQUEST
[
'traverse_subpath'
][
2
:]
...
@@ -262,11 +265,11 @@ class InstancePublisher(GenericPublisher):
...
@@ -262,11 +265,11 @@ class InstancePublisher(GenericPublisher):
LOG
(
'VifibRestApiV1Tool'
,
ERROR
,
LOG
(
'VifibRestApiV1Tool'
,
ERROR
,
'Problem while modifying:'
,
error
=
True
)
'Problem while modifying:'
,
error
=
True
)
self
.
REQUEST
.
response
.
setStatus
(
500
)
self
.
REQUEST
.
response
.
setStatus
(
500
)
self
.
REQUEST
.
response
.
setBody
(
json
.
dumps
({
'error'
:
self
.
REQUEST
.
response
.
setBody
(
json
ify
({
'error'
:
'There is system issue, please try again later.'
}))
'There is system issue, please try again later.'
}))
else
:
else
:
if
d
:
if
d
:
self
.
REQUEST
.
response
.
setBody
(
json
.
dumps
(
d
))
self
.
REQUEST
.
response
.
setBody
(
json
ify
(
d
))
return
self
.
REQUEST
.
response
return
self
.
REQUEST
.
response
@
requireHeader
({
'Accept'
:
'application/json'
,
@
requireHeader
({
'Accept'
:
'application/json'
,
...
@@ -281,7 +284,7 @@ class InstancePublisher(GenericPublisher):
...
@@ -281,7 +284,7 @@ class InstancePublisher(GenericPublisher):
LOG
(
'VifibRestApiV1Tool'
,
ERROR
,
LOG
(
'VifibRestApiV1Tool'
,
ERROR
,
'Problem while trying to generate instance dict:'
,
error
=
True
)
'Problem while trying to generate instance dict:'
,
error
=
True
)
self
.
REQUEST
.
response
.
setStatus
(
500
)
self
.
REQUEST
.
response
.
setStatus
(
500
)
self
.
REQUEST
.
response
.
setBody
(
json
.
dumps
({
'error'
:
self
.
REQUEST
.
response
.
setBody
(
json
ify
({
'error'
:
'There is system issue, please try again later.'
}))
'There is system issue, please try again later.'
}))
else
:
else
:
self
.
REQUEST
.
response
.
setStatus
(
204
)
self
.
REQUEST
.
response
.
setStatus
(
204
)
...
@@ -319,12 +322,12 @@ class InstancePublisher(GenericPublisher):
...
@@ -319,12 +322,12 @@ class InstancePublisher(GenericPublisher):
LOG
(
'VifibRestApiV1Tool'
,
ERROR
,
LOG
(
'VifibRestApiV1Tool'
,
ERROR
,
'Problem with person.requestSoftwareInstance:'
,
error
=
True
)
'Problem with person.requestSoftwareInstance:'
,
error
=
True
)
self
.
REQUEST
.
response
.
setStatus
(
500
)
self
.
REQUEST
.
response
.
setStatus
(
500
)
self
.
REQUEST
.
response
.
setBody
(
json
.
dumps
({
'error'
:
self
.
REQUEST
.
response
.
setBody
(
json
ify
({
'error'
:
'There is system issue, please try again later.'
}))
'There is system issue, please try again later.'
}))
return
self
.
REQUEST
.
response
return
self
.
REQUEST
.
response
self
.
REQUEST
.
response
.
setStatus
(
202
)
self
.
REQUEST
.
response
.
setStatus
(
202
)
self
.
REQUEST
.
response
.
setBody
(
json
.
dumps
({
'status'
:
'processing'
}))
self
.
REQUEST
.
response
.
setBody
(
json
ify
({
'status'
:
'processing'
}))
return
self
.
REQUEST
.
response
return
self
.
REQUEST
.
response
@
requireHeader
({
'Accept'
:
'application/json'
})
@
requireHeader
({
'Accept'
:
'application/json'
})
...
@@ -364,7 +367,7 @@ class InstancePublisher(GenericPublisher):
...
@@ -364,7 +367,7 @@ class InstancePublisher(GenericPublisher):
LOG
(
'VifibRestApiV1Tool'
,
ERROR
,
LOG
(
'VifibRestApiV1Tool'
,
ERROR
,
'Problem while trying to generate instance dict:'
,
error
=
True
)
'Problem while trying to generate instance dict:'
,
error
=
True
)
self
.
REQUEST
.
response
.
setStatus
(
500
)
self
.
REQUEST
.
response
.
setStatus
(
500
)
self
.
REQUEST
.
response
.
setBody
(
json
.
dumps
({
'error'
:
self
.
REQUEST
.
response
.
setBody
(
json
ify
({
'error'
:
'There is system issue, please try again later.'
}))
'There is system issue, please try again later.'
}))
else
:
else
:
self
.
REQUEST
.
response
.
setStatus
(
200
)
self
.
REQUEST
.
response
.
setStatus
(
200
)
...
@@ -377,7 +380,7 @@ class InstancePublisher(GenericPublisher):
...
@@ -377,7 +380,7 @@ class InstancePublisher(GenericPublisher):
# Say that content is publicly cacheable. It is only required in order to
# Say that content is publicly cacheable. It is only required in order to
# *force* storing content on clients' disk in case of using HTTPS
# *force* storing content on clients' disk in case of using HTTPS
self
.
REQUEST
.
response
.
setHeader
(
'Cache-Control'
,
'public'
)
self
.
REQUEST
.
response
.
setHeader
(
'Cache-Control'
,
'public'
)
self
.
REQUEST
.
response
.
setBody
(
json
.
dumps
(
d
))
self
.
REQUEST
.
response
.
setBody
(
json
ify
(
d
))
return
self
.
REQUEST
.
response
return
self
.
REQUEST
.
response
@
requireHeader
({
'Accept'
:
'application/json'
})
@
requireHeader
({
'Accept'
:
'application/json'
})
...
@@ -396,7 +399,7 @@ class InstancePublisher(GenericPublisher):
...
@@ -396,7 +399,7 @@ class InstancePublisher(GenericPublisher):
self
.
REQUEST
.
response
.
setStatus
(
204
)
self
.
REQUEST
.
response
.
setStatus
(
204
)
else
:
else
:
self
.
REQUEST
.
response
.
setStatus
(
200
)
self
.
REQUEST
.
response
.
setStatus
(
200
)
self
.
REQUEST
.
response
.
setBody
(
json
.
dumps
(
d
))
self
.
REQUEST
.
response
.
setBody
(
json
ify
(
d
))
return
self
.
REQUEST
.
response
return
self
.
REQUEST
.
response
@
responseSupport
()
@
responseSupport
()
...
@@ -518,7 +521,7 @@ class VifibRestApiV1Tool(BaseTool):
...
@@ -518,7 +521,7 @@ class VifibRestApiV1Tool(BaseTool):
'optional'
:
{}
'optional'
:
{}
}
}
}]}
}]}
self
.
REQUEST
.
response
.
setBody
(
json
.
dumps
(
d
))
self
.
REQUEST
.
response
.
setBody
(
json
ify
(
d
))
return
self
.
REQUEST
.
response
return
self
.
REQUEST
.
response
@
responseSupport
(
True
)
@
responseSupport
(
True
)
...
...
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