Skip to content

Commit

Permalink
Correct use of buffers vs. strings for Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Blixt committed Feb 28, 2014
1 parent c46f66f commit b70bc2f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions starbound/btreedb4.py
Expand Up @@ -122,7 +122,7 @@ def open(self):


class BTreeIndex(sbbf02.Block):
SIGNATURE = 'II'
SIGNATURE = b'II'

__slots__ = ['keys', 'level', 'num_keys', 'values']

Expand All @@ -148,7 +148,7 @@ def get_block_for_key(self, key):


class BTreeLeaf(sbbf02.Block):
SIGNATURE = 'LL'
SIGNATURE = b'LL'

__slots__ = ['data', 'next_block']

Expand Down
2 changes: 1 addition & 1 deletion starbound/filebase.py
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions starbound/sbbf02.py
Expand Up @@ -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:
Expand All @@ -43,7 +43,7 @@ def read(file):


class BlockFree(Block):
SIGNATURE = 'FF'
SIGNATURE = b'FF'

__slots__ = ['next_free_block', 'raw_data']

Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions starbound/sbon.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion starbound/sbvj01.py
Expand Up @@ -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
Expand Down

0 comments on commit b70bc2f

Please sign in to comment.