Mercurial > touhou
comparison pytouhou/formats/pbg3.py @ 377:70e2ed71b09c
Add meaningful exceptions in format parsing.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 29 Aug 2012 18:34:28 +0200 |
parents | b5c7369abd7c |
children | 1b532e7dd521 |
comparison
equal
deleted
inserted
replaced
376:69ec72b990a4 | 377:70e2ed71b09c |
---|---|
25 | 25 |
26 from pytouhou.utils.bitstream import BitStream | 26 from pytouhou.utils.bitstream import BitStream |
27 import pytouhou.utils.lzss as lzss | 27 import pytouhou.utils.lzss as lzss |
28 | 28 |
29 from pytouhou.utils.helpers import get_logger | 29 from pytouhou.utils.helpers import get_logger |
30 | |
31 from pytouhou.formats import WrongFormatError | |
30 | 32 |
31 logger = get_logger(__name__) | 33 logger = get_logger(__name__) |
32 | 34 |
33 | 35 |
34 class PBG3BitStream(BitStream): | 36 class PBG3BitStream(BitStream): |
99 Return a PBG3 instance otherwise. | 101 Return a PBG3 instance otherwise. |
100 """ | 102 """ |
101 | 103 |
102 magic = file.read(4) | 104 magic = file.read(4) |
103 if magic != b'PBG3': | 105 if magic != b'PBG3': |
104 raise Exception #TODO | 106 raise WrongFormatError(magic) |
105 | 107 |
106 bitstream = PBG3BitStream(file) | 108 bitstream = PBG3BitStream(file) |
107 entries = {} | 109 entries = {} |
108 | 110 |
109 nb_entries = bitstream.read_int() | 111 nb_entries = bitstream.read_int() |