0

Remove windows-style newlines

This commit is contained in:
Andrew Chin
2011-03-24 19:51:33 -04:00
parent d84af9fa4b
commit df6124b425

42
nbt.py
View File

@@ -34,16 +34,16 @@ def _file_loader(func):
def load(fileobj): def load(fileobj):
return NBTFileReader(fileobj).read_all() return NBTFileReader(fileobj).read_all()
def load_from_region(filename, x, y): def load_from_region(filename, x, y):
nbt = load_region(filename).load_chunk(x, y) nbt = load_region(filename).load_chunk(x, y)
if nbt is None: if nbt is None:
return None ## return none. I think this is who we should indicate missing chunks return None ## return none. I think this is who we should indicate missing chunks
#raise IOError("No such chunk in region: (%i, %i)" % (x, y)) #raise IOError("No such chunk in region: (%i, %i)" % (x, y))
return nbt.read_all() return nbt.read_all()
def load_region(filename): def load_region(filename):
return MCRFileReader(filename) return MCRFileReader(filename)
class NBTFileReader(object): class NBTFileReader(object):
def __init__(self, fileobj, is_gzip=True): def __init__(self, fileobj, is_gzip=True):
if is_gzip: if is_gzip:
@@ -180,9 +180,9 @@ class MCRFileReader(object):
chunks (as instances of NBTFileReader), getting chunk timestamps, chunks (as instances of NBTFileReader), getting chunk timestamps,
and for listing chunks contained in the file.""" and for listing chunks contained in the file."""
def __init__(self, filename): def __init__(self, filename):
self._file = None self._file = None
self._filename = filename self._filename = filename
# cache used when the entire header tables are read in get_chunks() # cache used when the entire header tables are read in get_chunks()
self._locations = None self._locations = None
self._timestamps = None self._timestamps = None
@@ -252,7 +252,7 @@ class MCRFileReader(object):
return timestamp return timestamp
def get_chunk_info(self,closeFile = True): def get_chunk_info(self,closeFile = True):
"""Return a list of all chunks contained in this region file, """Return a list of all chunks contained in this region file,
as a list of (x, y) coordinate tuples. To load these chunks, as a list of (x, y) coordinate tuples. To load these chunks,
provide these coordinates to load_chunk().""" provide these coordinates to load_chunk()."""
@@ -260,7 +260,7 @@ class MCRFileReader(object):
if self._chunks: if self._chunks:
return self._chunks return self._chunks
if self._file is None: if self._file is None:
self._file = open(self._filename,'rb'); self._file = open(self._filename,'rb');
self._chunks = [] self._chunks = []
@@ -283,11 +283,11 @@ class MCRFileReader(object):
for x in xrange(32): for x in xrange(32):
timestamp = self._read_chunk_timestamp() timestamp = self._read_chunk_timestamp()
self._timestamps.append(timestamp) self._timestamps.append(timestamp)
if closeFile: if closeFile:
#free the file object since it isn't safe to be reused in child processes (seek point goes wonky!) #free the file object since it isn't safe to be reused in child processes (seek point goes wonky!)
self._file.close() self._file.close()
self._file = None self._file = None
return self._chunks return self._chunks
def get_chunk_timestamp(self, x, y): def get_chunk_timestamp(self, x, y):
@@ -320,13 +320,13 @@ class MCRFileReader(object):
x = x % 32 x = x % 32
y = y % 32 y = y % 32
if self._locations is None: if self._locations is None:
self.get_chunk_info() self.get_chunk_info()
location = self._locations[x + y * 32] location = self._locations[x + y * 32]
if location is None: if location is None:
return None return None
if self._file is None: if self._file is None:
self._file = open(self._filename,'rb'); self._file = open(self._filename,'rb');
# seek to the data # seek to the data
self._file.seek(location[0]) self._file.seek(location[0])