blob: f62461223673714ba8cd472bbc6de0d80e2a1572 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import warnings
from . import DealFormat
from .rzd import RZDFormat
from .. import dto
class CDSFormat(DealFormat):
@property
def suffix(self):
return '.cds'
def __init__(self):
self.rzd_format = RZDFormat()
def parse_content(self, content):
dealset = []
while True:
data = content.read(14)
if len(data) < 14:
if len(data) != 0:
warnings.warn('.cds data truncated: %s' % (data))
break
deal = dto.Deal()
deal.number = ord(data[0])
deal.dealer = deal.get_dealer(deal.number)
deal.vulnerable = deal.get_vulnerability(deal.number)
deal.hands = self.rzd_format.parse_deal(data[1:], offset=1)
dealset.append(deal)
return dealset
def output_content(self, out_file, dealset):
for deal in dealset:
out_file.write(chr(deal.number))
out_file.write(self.rzd_format.dump_deal(deal, offset=1))
|