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
Jérome Perrin
slapos.core
Commits
0abbd362
Commit
0abbd362
authored
May 14, 2012
by
Łukasz Nowak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Encode unicode to UTF-8
Also switch to decorator based logic.
parent
17b2848f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
14 deletions
+23
-14
master/product/Vifib/Tool/VifibRestApiV1Tool.py
master/product/Vifib/Tool/VifibRestApiV1Tool.py
+23
-14
No files found.
master/product/Vifib/Tool/VifibRestApiV1Tool.py
View file @
0abbd362
...
...
@@ -99,6 +99,9 @@ def supportModifiedSince(document_url_id):
return
wrapperSupportModifiedSince
return
outer
def
encode_utf8
(
s
):
return
s
.
encode
(
'utf-8'
)
def
requireJson
(
json_dict
,
optional_key_list
=
None
):
if
optional_key_list
is
None
:
optional_key_list
=
[]
...
...
@@ -118,9 +121,18 @@ def requireJson(json_dict, optional_key_list=None):
if
key
not
in
self
.
jbody
:
if
key
not
in
optional_key_list
:
error_dict
[
key
]
=
'Missing.'
elif
key
in
self
.
jbody
and
not
isinstance
(
self
.
jbody
[
key
],
type_
):
error_dict
[
key
]
=
'%s is not %s.'
%
(
type
(
self
.
jbody
[
key
]).
__name__
,
type_
.
__name__
)
elif
key
in
self
.
jbody
:
method
=
None
if
type
(
type_
)
in
(
tuple
,
list
):
type_
,
method
=
type_
if
not
isinstance
(
self
.
jbody
[
key
],
type_
):
error_dict
[
key
]
=
'%s is not %s.'
%
(
type
(
self
.
jbody
[
key
]
).
__name__
,
type_
.
__name__
)
if
method
is
not
None
:
try
:
self
.
jbody
[
key
]
=
method
(
self
.
jbody
[
key
])
except
Exception
:
error_dict
[
key
]
=
'Malformed value.'
if
error_dict
:
self
.
REQUEST
.
response
.
setStatus
(
400
)
self
.
REQUEST
.
response
.
setBody
(
json
.
dumps
(
error_dict
))
...
...
@@ -220,7 +232,7 @@ class InstancePublisher(GenericPublisher):
@
requireHeader
({
'Accept'
:
'application/json'
,
'Content-Type'
:
'application/json'
})
@
requireJson
(
dict
(
title
=
unicode
,
title
=
(
unicode
,
encode_utf8
)
,
connection
=
dict
),
[
'title'
,
'connection'
])
@
extractInstance
...
...
@@ -275,12 +287,12 @@ class InstancePublisher(GenericPublisher):
'Content-Type'
:
'application/json'
})
@
requireJson
(
dict
(
slave
=
bool
,
software_release
=
unicode
,
title
=
unicode
,
software_type
=
unicode
,
parameter
=
dict
,
sla
=
dict
,
status
=
unicode
software_release
=
(
unicode
,
encode_utf8
)
,
title
=
(
unicode
,
encode_utf8
)
,
software_type
=
(
unicode
,
encode_utf8
)
,
parameter
=
(
dict
,
etreeXml
)
,
sla
=
(
dict
,
etreeXml
)
,
status
=
(
unicode
,
encode_utf8
),
))
def
__request
(
self
):
request_dict
=
{}
...
...
@@ -293,9 +305,6 @@ class InstancePublisher(GenericPublisher):
(
'slave'
,
'shared'
),
(
'status'
,
'state'
)
):
if
k_j
in
(
'sla'
,
'parameter'
):
request_dict
[
k_i
]
=
etreeXml
(
self
.
jbody
[
k_j
])
else
:
request_dict
[
k_i
]
=
self
.
jbody
[
k_j
]
try
:
...
...
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