summaryrefslogtreecommitdiff
path: root/dealconvert/formats/bhg.py
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2019-05-23 01:42:08 +0200
committeremkael <emkael@tlen.pl>2019-05-23 01:42:08 +0200
commitc5608c4cdb67aca4d154541a09d5ebb88bf232ec (patch)
treea3f9ecba1206c3bfe6aa936ce43f238b34d4c315 /dealconvert/formats/bhg.py
parent3e2102f3038be32c85e98c2bd6a6023c63fae070 (diff)
Proper error/warning handling
Diffstat (limited to 'dealconvert/formats/bhg.py')
-rw-r--r--dealconvert/formats/bhg.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/dealconvert/formats/bhg.py b/dealconvert/formats/bhg.py
index 7ff0704..23a1673 100644
--- a/dealconvert/formats/bhg.py
+++ b/dealconvert/formats/bhg.py
@@ -1,4 +1,4 @@
-import sys
+import warnings
from . import DealFormat
from .. import dto
@@ -14,9 +14,12 @@ class BHGFormat(DealFormat):
for board_no, line in enumerate(board_lines):
if board_no > 0:
if len(line) != 52:
- print 'WARNING: malformed .bhg line #%d: %s' % (board_no, line)
+ warnings.warn(
+ 'malformed .bhg line #%d: %s' % (board_no, line))
elif not line.isalpha():
- print 'WARNING: invalid characters in .bhg line #%d: %s' % (board_no, line)
+ warnings.warn(
+ 'invalid characters in .bhg line #%d: %s' % (
+ board_no, line))
else:
deal = dto.Deal()
deal.number = board_no
@@ -47,7 +50,8 @@ class BHGFormat(DealFormat):
for card in cards:
line += chr((65 if card < 26 else 71)+card)
except ValueError:
- print 'ERROR: invalid suit %s in board #%d' % (''.join(suit), deal.number)
- sys.exit()
+ raise RuntimeError(
+ 'invalid suit %s in board #%d' % (
+ ''.join(suit), deal.number))
lines[deal.number] = line
out_file.write('\r\n'.join(lines))