switchs2.py: don't crash si chbre inexistante

This commit is contained in:
Daniel STAN 2014-12-09 21:22:21 +01:00
parent 7c4d8dcbb0
commit e5f7930bd9
2 changed files with 10 additions and 2 deletions

View file

@ -44,6 +44,10 @@ def _need_conn(f):
bat_switchs = ["a", "b", "c", "g", "h", "i", "j", "m", "o", "p"]
class ChbreNotFound(ValueError):
"""Lorsqu'une chambre n'existe pas"""
pass
@_need_conn
def chbre_prises(batiment, chambre = None):
"""Correspondance chambre -> prise"""
@ -55,7 +59,7 @@ def chbre_prises(batiment, chambre = None):
try:
return "%03d" % cur.fetchone()[0]
except TypeError:
raise ValueError("Chambre inexistante bat %r, chbre %r" % (batiment, chambre))
raise ChbreNotFound("Chambre inexistante bat %r, chbre %r" % (batiment, chambre))
else:
cur = conn.cursor()
cur.execute("SELECT chambre, prise_crans FROM prises WHERE batiment = %s", batiment)