blob: c7eeb5a6a98e3f138854152bdec90a59d327030b (
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, interactive=True):
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))
|