diff options
author | emkael <emkael@tlen.pl> | 2019-05-23 01:42:08 +0200 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2019-05-23 01:42:08 +0200 |
commit | c5608c4cdb67aca4d154541a09d5ebb88bf232ec (patch) | |
tree | a3f9ecba1206c3bfe6aa936ce43f238b34d4c315 /dealconvert/formats/dge.py | |
parent | 3e2102f3038be32c85e98c2bd6a6023c63fae070 (diff) |
Proper error/warning handling
Diffstat (limited to 'dealconvert/formats/dge.py')
-rw-r--r-- | dealconvert/formats/dge.py | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/dealconvert/formats/dge.py b/dealconvert/formats/dge.py index 93eb971..d0a4c46 100644 --- a/dealconvert/formats/dge.py +++ b/dealconvert/formats/dge.py @@ -1,10 +1,10 @@ -import sys +import warnings from . import DealFormat from .. import dto class DGEFormat(DealFormat): - number_warning = 'WARNING: .dge file format assumes consequent deal numbers from 1' + number_warning = '.dge file format assumes consequent deal numbers from 1' suits = { chr(6): dto.SUIT_SPADES, chr(3): dto.SUIT_HEARTS, @@ -23,14 +23,14 @@ class DGEFormat(DealFormat): return '.dge' def parse_content(self, content): - print self.number_warning + warnings.warn(self.number_warning) dealset = [] number = 1 while True: deal_str = content.read(128).strip() if len(deal_str) > 0: if len(deal_str) < 68: - print 'WARNING: truncated .dge input: %s' % (deal_str) + warnings.warn('truncated .dge input: %s' % (deal_str)) break else: deal = dto.Deal() @@ -58,14 +58,13 @@ class DGEFormat(DealFormat): hand += 1 else: if suit is None: - print 'ERROR: invalid .dge line: %s' % (deal_str) - sys.exit() + raise RuntimeError('invalid .dge line: %s' % (deal_str)) else: deal.hands[hand][suit].append(char) return deal.hands def output_content(self, out_file, dealset): - print self.number_warning + warnings.warn(self.number_warning) for deal in dealset: deal_str = self.single_deal_output(deal) deal_str += chr(0) * 60 |