comparison pytouhou/formats/pbg3.py @ 58:3da4de9decd0

Use logging module
author Thibaut Girka <thib@sitedethib.com>
date Tue, 23 Aug 2011 21:01:50 +0200
parents ab826bc29aa2
children ac2e5e1c2c3c
comparison
equal deleted inserted replaced
57:694f25881d0f 58:3da4de9decd0
1 from pytouhou.utils.bitstream import BitStream
2 import pytouhou.utils.lzss as lzss
3
4
5 # -*- encoding: utf-8 -*- 1 # -*- encoding: utf-8 -*-
6 ## 2 ##
7 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com> 3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com>
8 ## 4 ##
9 ## This program is free software; you can redistribute it and/or modify 5 ## This program is free software; you can redistribute it and/or modify
13 ## This program is distributed in the hope that it will be useful, 9 ## This program is distributed in the hope that it will be useful,
14 ## but WITHOUT ANY WARRANTY; without even the implied warranty of 10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ## GNU General Public License for more details. 12 ## GNU General Public License for more details.
17 ## 13 ##
14
15 from pytouhou.utils.bitstream import BitStream
16 import pytouhou.utils.lzss as lzss
17
18 from pytouhou.utils.helpers import get_logger
19
20 logger = get_logger(__name__)
21
18 22
19 class PBG3BitStream(BitStream): 23 class PBG3BitStream(BitStream):
20 def read_int(self): 24 def read_int(self):
21 size = self.read(2) 25 size = self.read(2)
22 return self.read((size + 1) * 8) 26 return self.read((size + 1) * 8)
78 value = 0 82 value = 0
79 for c in self.bitstream.io.read(compressed_size): 83 for c in self.bitstream.io.read(compressed_size):
80 value += ord(c) 84 value += ord(c)
81 value &= 0xFFFFFFFF 85 value &= 0xFFFFFFFF
82 if value != checksum: 86 if value != checksum:
83 print('Warning: corrupted data') #TODO 87 logger.warn('corrupted data!')
84 return data 88 return data
85 89