Python 3 compatibility
This commit is contained in:
parent
02551de6de
commit
b33177ab70
wsme
@ -192,10 +192,12 @@ def datetime_fromjson(datatype, value):
|
||||
return datetime.datetime.strptime(value, '%Y-%m-%dT%H:%M:%S')
|
||||
|
||||
|
||||
def parse(s, datatypes, bodyarg):
|
||||
def parse(s, datatypes, bodyarg, encoding='utf8'):
|
||||
if hasattr(s, 'read'):
|
||||
jdata = json.load(s)
|
||||
else:
|
||||
if six.PY3 and isinstance(s, six.binary_type):
|
||||
s = s.decode(encoding)
|
||||
jdata = json.loads(s)
|
||||
if bodyarg:
|
||||
argname = list(datatypes.keys())[0]
|
||||
|
@ -208,19 +208,19 @@ class TestController(unittest.TestCase):
|
||||
'Accept': 'application/json'
|
||||
})
|
||||
|
||||
self.assertEquals(res.body, '10')
|
||||
self.assertEquals(res.body, b('10'))
|
||||
|
||||
res = app.get('/mul_float?a=2.2&b=4', headers={
|
||||
'Accept': 'application/json'
|
||||
})
|
||||
|
||||
self.assertEquals(res.body, '8.8')
|
||||
self.assertEquals(res.body, b('8.8'))
|
||||
|
||||
res = app.get('/mul_string?a=hello&b=2', headers={
|
||||
'Accept': 'application/json'
|
||||
})
|
||||
|
||||
self.assertEquals(res.body, '"hellohello"')
|
||||
self.assertEquals(res.body, b('"hellohello"'))
|
||||
|
||||
|
||||
class TestFunctionDefinition(unittest.TestCase):
|
||||
|
Loading…
x
Reference in New Issue
Block a user