Fixed a bytes/str issue for Python 3.

This commit is contained in:
Jakub Roztocil 2013-09-25 00:00:17 +02:00
parent d5bc564e4f
commit 0bcd4d2fb0
2 changed files with 5 additions and 3 deletions

View File

@ -596,7 +596,7 @@ def parse_items(items, data=None, headers=None, files=None, params=None):
if item.sep in SEP_GROUP_DATA_EMBED_ITEMS:
try:
with open(os.path.expanduser(value), 'rb') as f:
value = f.read()
value = f.read().decode('utf8')
except IOError as e:
raise ParseError('%s": %s' % (item.orig, e))

View File

@ -1242,7 +1242,8 @@ class ItemParsingTest(BaseTestCase):
# Parsed data
raw_json_embed = data.pop('raw-json-embed')
self.assertDictEqual(raw_json_embed, json.loads(JSON_FILE_CONTENT))
self.assertDictEqual(raw_json_embed, json.loads(
JSON_FILE_CONTENT.decode('utf8')))
data['string-embed'] = data['string-embed'].strip()
self.assertDictEqual(dict(data), {
"ed": "",
@ -1260,7 +1261,8 @@ class ItemParsingTest(BaseTestCase):
# Parsed file fields
self.assertIn('file', files)
self.assertEqual(files['file'][1].read().strip(), FILE_CONTENT)
self.assertEqual(files['file'][1].read().strip().decode('utf8'),
FILE_CONTENT)
class ArgumentParserTestCase(unittest.TestCase):