Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1eb79cf

Browse files
committed
Move xdrlib over to the bytes type.
1 parent d24fffe commit 1eb79cf

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

Lib/test/test_xdrlib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class XDRTest(unittest.TestCase):
88
def test_xdr(self):
99
p = xdrlib.Packer()
1010

11-
s = 'hello world'
12-
a = ['what', 'is', 'hapnin', 'doctor']
11+
s = b'hello world'
12+
a = [b'what', b'is', b'hapnin', b'doctor']
1313

1414
p.pack_int(42)
1515
p.pack_uint(9)

Lib/xdrlib.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""
66

77
import struct
8-
from io import StringIO as _StringIO
8+
from io import BytesIO
99

1010
__all__ = ["Error", "Packer", "Unpacker", "ConversionError"]
1111

@@ -40,7 +40,7 @@ def __init__(self):
4040
self.reset()
4141

4242
def reset(self):
43-
self.__buf = _StringIO()
43+
self.__buf = BytesIO()
4444

4545
def get_buffer(self):
4646
return self.__buf.getvalue()
@@ -54,8 +54,8 @@ def pack_uint(self, x):
5454
pack_enum = pack_int
5555

5656
def pack_bool(self, x):
57-
if x: self.__buf.write('\0\0\0\1')
58-
else: self.__buf.write('\0\0\0\0')
57+
if x: self.__buf.write(b'\0\0\0\1')
58+
else: self.__buf.write(b'\0\0\0\0')
5959

6060
def pack_uhyper(self, x):
6161
self.pack_uint(x>>32 & 0xffffffff)
@@ -78,7 +78,7 @@ def pack_fstring(self, n, s):
7878
raise ValueError, 'fstring size must be nonnegative'
7979
data = s[:n]
8080
n = ((n+3)//4)*4
81-
data = data + (n - len(data)) * '\0'
81+
data = data + (n - len(data)) * b'\0'
8282
self.__buf.write(data)
8383

8484
pack_fopaque = pack_fstring

0 commit comments

Comments
 (0)