7197: refactor code

replace all copies of logging with a single point at the exception
rethrow point
This commit is contained in:
Vassilii Khachaturov 2013-11-13 22:02:21 +02:00
parent c5f0c7a6f0
commit b3ab87bc5a

View File

@ -1634,35 +1634,34 @@ class Date(object):
# Did the roundtrip change the date value?! # Did the roundtrip change the date value?!
if sanity.dateval != value: if sanity.dateval != value:
if sanity.get_new_year() != self.get_new_year(): try:
# convert_calendar resets the new year, so the date value will differ. if sanity.get_new_year() != self.get_new_year():
# Just check the sort value matches then. # convert_calendar resets the new year, so the date value will differ.
if self.sortval != sanity.sortval: # Just check the sort value matches then.
log.debug("Sanity check failed - self: {}, sanity: {}".format( if self.sortval != sanity.sortval:
self.to_struct(), sanity.to_struct())) raise DateError("Invalid date value {}".format(value))
raise DateError("Invalid date value {}".format(value)) else:
else: # Maybe it is OK because of undetermined value adjustment?
# Maybe it is OK because of undetermined value adjustment? zl = zip(sanity.dateval, value)
zl = zip(sanity.dateval, value) # Loop over all values present, whether compound or not
# Loop over all values present, whether compound or not for d,m,y,sl in zip(*[iter(zl)]*4):
for d,m,y,sl in zip(*[iter(zl)]*4): # each of d,m,y,sl is a pair from dateval and value, to compare
# each of d,m,y,sl is a pair from dateval and value, to compare for adjusted,original in d,m:
for adjusted,original in d,m: if adjusted != original and not(original == 0 and adjusted == 1):
raise DateError("Invalid day/month {} passed in value {}".
format(original, value))
adjusted,original = y
adjusted -= year_delta
if adjusted != original and not(original == 0 and adjusted == 1): if adjusted != original and not(original == 0 and adjusted == 1):
log.debug("Sanity check failed - self: {}, sanity: {}".format( raise DateError("Invalid year {} passed in value {}".
self.to_struct(), sanity.to_struct()))
raise DateError("Invalid day/month {} passed in value {}".
format(original, value)) format(original, value))
adjusted,original = y # ignore slash difference
adjusted -= year_delta except DateError:
if adjusted != original and not(original == 0 and adjusted == 1): log.debug("Sanity check failed - self: {}, sanity: {}".format(
log.debug("Sanity check failed - self: {}, sanity: {}".format( self.to_struct(), sanity.to_struct()))
self.to_struct(), sanity.to_struct())) raise
raise DateError("Invalid year {} passed in value {}".
format(original, value))
# ignore slash difference
def recalc_sort_value(self): def recalc_sort_value(self):
""" """