Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Correct use of buffers vs. strings for Python 3

  • Loading branch information...
commit b70bc2f23609bc32063c380ad9bf9015686023f5 1 parent c46f66f
Blixt authored
View
4 starbound/btreedb4.py
@@ -122,7 +122,7 @@ def open(self):
class BTreeIndex(sbbf02.Block):
- SIGNATURE = 'II'
+ SIGNATURE = b'II'
__slots__ = ['keys', 'level', 'num_keys', 'values']
@@ -148,7 +148,7 @@ def get_block_for_key(self, key):
class BTreeLeaf(sbbf02.Block):
- SIGNATURE = 'LL'
+ SIGNATURE = b'LL'
__slots__ = ['data', 'next_block']
View
2  starbound/filebase.py
@@ -28,7 +28,7 @@ def is_open(self):
def open(self):
assert self._stream is None, 'File is already open'
- stream = open(self.path)
+ stream = open(self.path, 'rb')
self._stream = stream
def read(self, length):
View
6 starbound/sbbf02.py
@@ -32,7 +32,7 @@ class Block(BlockMeta('Block', (object,), {})):
def read(file):
signature = file.read(2)
- if signature == '\x00\x00':
+ if signature == b'\x00\x00':
return None
if signature not in Block.types:
@@ -43,7 +43,7 @@ def read(file):
class BlockFree(Block):
- SIGNATURE = 'FF'
+ SIGNATURE = b'FF'
__slots__ = ['next_free_block', 'raw_data']
@@ -82,7 +82,7 @@ def open(self):
super(FileSBBF02, self).open()
stream = self._stream
- assert stream.read(6) == 'SBBF02', 'Invalid file format'
+ assert stream.read(6) == b'SBBF02', 'Invalid file format'
# Block header data.
fields = struct.unpack('>ii?i', stream.read(13))
View
4 starbound/sbon.py
@@ -31,7 +31,7 @@ def read_document(stream, repair=False):
name = read_string(stream)
# Not sure what this part is.
- assert stream.read(1) == '\x01'
+ assert stream.read(1) == b'\x01'
version = struct.unpack('>i', stream.read(4))[0]
data = read_dynamic(stream, repair)
@@ -71,7 +71,7 @@ def read_dynamic(stream, repair=False):
return struct.unpack(format, stream.read(struct.calcsize(format)))[0]
def read_fixlen_string(stream, length):
- return stream.read(length).rstrip('\x00').decode('utf-8')
+ return stream.read(length).rstrip(b'\x00').decode('utf-8')
def read_list(stream, repair=False):
length = read_varlen_number(stream)
View
2  starbound/sbvj01.py
@@ -13,7 +13,7 @@ def open(self):
"""
super(FileSBVJ01, self).open()
- assert self.read(6) == 'SBVJ01', 'Invalid file format'
+ assert self.read(6) == b'SBVJ01', 'Invalid file format'
self.identifier, self.version, self.data = sbon.read_document(self._stream)
# Technically, we could already close the file at this point. Need to
Please sign in to comment.
Something went wrong with that request. Please try again.