Skip to content

Commit ff263df

Browse files
committed
Merge pull request #91 from msgpack/reduce-six
Reduce six usage
2 parents 96d7d0e + 0c22e77 commit ff263df

File tree

5 files changed

+29
-33
lines changed

5 files changed

+29
-33
lines changed

test/test_pack.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
# coding: utf-8
3+
from __future__ import absolute_import, division, print_function, unicode_literals
34

4-
import six
55
import struct
66
from pytest import raises, xfail
77

@@ -28,24 +28,22 @@ def testPack():
2828
check(td)
2929

3030
def testPackUnicode():
31-
test_data = [
32-
six.u(""), six.u("abcd"), [six.u("defgh")], six.u("Русский текст"),
33-
]
31+
test_data = ["", "abcd", ["defgh"], "Русский текст"]
3432
for td in test_data:
3533
re = unpackb(packb(td, encoding='utf-8'), use_list=1, encoding='utf-8')
3634
assert re == td
3735
packer = Packer(encoding='utf-8')
3836
data = packer.pack(td)
39-
re = Unpacker(BytesIO(data), encoding='utf-8', use_list=1).unpack()
37+
re = Unpacker(BytesIO(data), encoding=str('utf-8'), use_list=1).unpack()
4038
assert re == td
4139

4240
def testPackUTF32():
4341
try:
4442
test_data = [
45-
six.u(""),
46-
six.u("abcd"),
47-
[six.u("defgh")],
48-
six.u("Русский текст"),
43+
"",
44+
"abcd",
45+
["defgh"],
46+
"Русский текст",
4947
]
5048
for td in test_data:
5149
re = unpackb(packb(td, encoding='utf-32'), use_list=1, encoding='utf-32')
@@ -70,26 +68,26 @@ def testStrictUnicodeUnpack():
7068

7169
def testStrictUnicodePack():
7270
with raises(UnicodeEncodeError):
73-
packb(six.u("abc\xeddef"), encoding='ascii', unicode_errors='strict')
71+
packb("abc\xeddef", encoding='ascii', unicode_errors='strict')
7472

7573
def testIgnoreErrorsPack():
76-
re = unpackb(packb(six.u("abcФФФdef"), encoding='ascii', unicode_errors='ignore'), encoding='utf-8', use_list=1)
77-
assert re == six.u("abcdef")
74+
re = unpackb(packb("abcФФФdef", encoding='ascii', unicode_errors='ignore'), encoding='utf-8', use_list=1)
75+
assert re == "abcdef"
7876

7977
def testNoEncoding():
8078
with raises(TypeError):
81-
packb(six.u("abc"), encoding=None)
79+
packb("abc", encoding=None)
8280

8381
def testDecodeBinary():
84-
re = unpackb(packb("abc"), encoding=None, use_list=1)
82+
re = unpackb(packb(b"abc"), encoding=None, use_list=1)
8583
assert re == b"abc"
8684

8785
def testPackFloat():
88-
assert packb(1.0, use_single_float=True) == b'\xca' + struct.pack('>f', 1.0)
89-
assert packb(1.0, use_single_float=False) == b'\xcb' + struct.pack('>d', 1.0)
86+
assert packb(1.0, use_single_float=True) == b'\xca' + struct.pack(str('>f'), 1.0)
87+
assert packb(1.0, use_single_float=False) == b'\xcb' + struct.pack(str('>d'), 1.0)
9088

9189
def testArraySize(sizes=[0, 5, 50, 1000]):
92-
bio = six.BytesIO()
90+
bio = BytesIO()
9391
packer = Packer()
9492
for size in sizes:
9593
bio.write(packer.pack_array_header(size))
@@ -108,7 +106,7 @@ def test_manualreset(sizes=[0, 5, 50, 1000]):
108106
for i in range(size):
109107
packer.pack(i)
110108

111-
bio = six.BytesIO(packer.bytes())
109+
bio = BytesIO(packer.bytes())
112110
unpacker = Unpacker(bio, use_list=1)
113111
for size in sizes:
114112
assert unpacker.unpack() == list(range(size))
@@ -117,7 +115,7 @@ def test_manualreset(sizes=[0, 5, 50, 1000]):
117115
assert packer.bytes() == b''
118116

119117
def testMapSize(sizes=[0, 5, 50, 1000]):
120-
bio = six.BytesIO()
118+
bio = BytesIO()
121119
packer = Packer()
122120
for size in sizes:
123121
bio.write(packer.pack_map_header(size))

test/test_seq.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
#!/usr/bin/env python
22
# coding: utf-8
33

4-
import six
54
import io
65
import msgpack
76

8-
binarydata = [chr(i) for i in range(256)]
9-
binarydata = six.b("".join(binarydata))
7+
8+
binarydata = bytes(bytearray(range(256)))
109

1110
def gen_binary_data(idx):
12-
data = binarydata[:idx % 300]
13-
return data
11+
return binarydata[:idx % 300]
12+
1413

1514
def test_exceeding_unpacker_read_size():
1615
dumpf = io.BytesIO()

test/test_sequnpack.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
# coding: utf-8
33

4-
import six
4+
import io
55
from msgpack import Unpacker, BufferFull
66
from msgpack.exceptions import OutOfData
77
from pytest import raises
@@ -79,7 +79,7 @@ def test_readbytes():
7979
assert unpacker.unpack() == ord(b'r')
8080

8181
# Test buffer refill
82-
unpacker = Unpacker(six.BytesIO(b'foobar'), read_size=3)
82+
unpacker = Unpacker(io.BytesIO(b'foobar'), read_size=3)
8383
assert unpacker.unpack() == ord(b'f')
8484
assert unpacker.read_bytes(3) == b'oob'
8585
assert unpacker.unpack() == ord(b'a')

test/test_unpack_raw.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
"""Tests for cases where the user seeks to obtain packed msgpack objects"""
22

3-
import six
3+
import io
44
from msgpack import Unpacker, packb
55

66

77
def test_write_bytes():
88
unpacker = Unpacker()
99
unpacker.feed(b'abc')
10-
f = six.BytesIO()
10+
f = io.BytesIO()
1111
assert unpacker.unpack(f.write) == ord('a')
1212
assert f.getvalue() == b'a'
13-
f = six.BytesIO()
13+
f = io.BytesIO()
1414
assert unpacker.skip(f.write) is None
1515
assert f.getvalue() == b'b'
16-
f = six.BytesIO()
16+
f = io.BytesIO()
1717
assert unpacker.skip() is None
1818
assert f.getvalue() == b''
1919

2020

2121
def test_write_bytes_multi_buffer():
2222
long_val = (5) * 100
2323
expected = packb(long_val)
24-
unpacker = Unpacker(six.BytesIO(expected), read_size=3, max_buffer_size=3)
24+
unpacker = Unpacker(io.BytesIO(expected), read_size=3, max_buffer_size=3)
2525

26-
f = six.BytesIO()
26+
f = io.BytesIO()
2727
unpacked = unpacker.unpack(f.write)
2828
assert unpacked == long_val
2929
assert f.getvalue() == expected

tox.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ envlist = py26,py27,py32,py33,pypy
44
[testenv]
55
deps=
66
pytest
7-
six
87

98
commands=py.test test

0 commit comments

Comments
 (0)