0

comments adjustment in nbt.py

This commit is contained in:
Andrew Brown
2011-11-20 10:52:04 -05:00
parent c6b56030ec
commit cd360c3c60

View File

@@ -16,11 +16,11 @@
import gzip, zlib import gzip, zlib
import struct import struct
import StringIO import StringIO
import os
import numpy import numpy
from functools import wraps from functools import wraps
# decorator to handle filename or object as first parameter # decorator that turns the first argument from a string into an open file
# handle
def _file_loader(func): def _file_loader(func):
@wraps(func) @wraps(func)
def wrapper(fileobj, *args): def wrapper(fileobj, *args):
@@ -32,6 +32,10 @@ def _file_loader(func):
@_file_loader @_file_loader
def load(fileobj): def load(fileobj):
"""Reads in the given file as NBT format, parses it, and returns the
result
"""
return NBTFileReader(fileobj).read_all() return NBTFileReader(fileobj).read_all()
def load_from_region(filename, x, y, north_direction): def load_from_region(filename, x, y, north_direction):
@@ -59,6 +63,9 @@ _unsigned_int = struct.Struct(">I")
_chunk_header = struct.Struct(">I B") _chunk_header = struct.Struct(">I B")
class NBTFileReader(object): class NBTFileReader(object):
"""Low level class that reads the Named Binary Tag format used by Minecraft
"""
def __init__(self, fileobj, is_gzip=True): def __init__(self, fileobj, is_gzip=True):
if is_gzip: if is_gzip:
self._file = gzip.GzipFile(fileobj=fileobj, mode='rb') self._file = gzip.GzipFile(fileobj=fileobj, mode='rb')