kopia lustrzana https://github.com/ctjacobs/pyqso
Validation for the "L", "S", "I", "M" and "G" ADIF data types.
rodzic
ff025a0ce0
commit
6b59e67495
|
@ -157,7 +157,7 @@ class RecordDialog(Gtk.Dialog):
|
|||
if(data_type == "N"):
|
||||
# Allow a decimal point before and/or after any numbers,
|
||||
# but don't allow a decimal point on its own.
|
||||
m = re.match("-?(([0-9]+\.?[0-9]*)|([0-9]*\.?[0-9]+))", data)
|
||||
m = re.match(r"-?(([0-9]+\.?[0-9]*)|([0-9]*\.?[0-9]+))", data)
|
||||
if(m is None):
|
||||
# Did not match anything.
|
||||
return False
|
||||
|
@ -168,7 +168,7 @@ class RecordDialog(Gtk.Dialog):
|
|||
|
||||
elif(data_type == "B"):
|
||||
# Boolean
|
||||
m = re.match("(Y|N)", data)
|
||||
m = re.match(r"(Y|N)", data)
|
||||
if(m is None):
|
||||
return False
|
||||
else:
|
||||
|
@ -176,19 +176,19 @@ class RecordDialog(Gtk.Dialog):
|
|||
|
||||
elif(data_type == "D"):
|
||||
# Date
|
||||
pattern = re.compile("([0-9]){4}")
|
||||
pattern = re.compile(r"([0-9]{4})")
|
||||
m_year = pattern.match(data, 0)
|
||||
if((m_year is None) or (int(m_year.group(0)) < 1930)):
|
||||
# Did not match anything.
|
||||
return False
|
||||
else:
|
||||
pattern = re.compile("([0-9]){2}")
|
||||
pattern = re.compile(r"([0-9]{2})")
|
||||
m_month = pattern.match(data, 4)
|
||||
if((m_month is None) or int(m_month.group(0)) > 12 or int(m_month.group(0)) < 1):
|
||||
# Did not match anything.
|
||||
return False
|
||||
else:
|
||||
pattern = re.compile("([0-9]){2}")
|
||||
pattern = re.compile(r"([0-9]{2})")
|
||||
m_day = pattern.match(data, 6)
|
||||
days_in_month = calendar.monthrange(int(m_year.group(0)), int(m_month.group(0)))
|
||||
if((m_day is None) or int(m_day.group(0)) > days_in_month[1] or int(m_day.group(0)) < 1):
|
||||
|
@ -201,13 +201,13 @@ class RecordDialog(Gtk.Dialog):
|
|||
|
||||
elif(data_type == "T"):
|
||||
# Time
|
||||
pattern = re.compile("([0-9]){2}")
|
||||
pattern = re.compile(r"([0-9]{2})")
|
||||
m_hour = pattern.match(data, 0)
|
||||
if((m_hour is None) or (int(m_hour.group(0)) < 0) or (int(m_hour.group(0)) > 23)):
|
||||
# Did not match anything.
|
||||
return False
|
||||
else:
|
||||
pattern = re.compile("([0-9]){2}")
|
||||
pattern = re.compile(r"([0-9]{2})")
|
||||
m_minutes = pattern.match(data, 2)
|
||||
if((m_minutes is None) or int(m_minutes.group(0)) < 0 or int(m_minutes.group(0)) > 59):
|
||||
# Did not match anything.
|
||||
|
@ -216,7 +216,7 @@ class RecordDialog(Gtk.Dialog):
|
|||
if(len(data) == 4):
|
||||
# HHMM format
|
||||
return True
|
||||
pattern = re.compile("([0-9]){2}")
|
||||
pattern = re.compile(r"([0-9]{2})")
|
||||
m_seconds = pattern.match(data, 4)
|
||||
if((m_seconds is None) or int(m_seconds.group(0)) < 0 or int(m_seconds.group(0)) > 59):
|
||||
# Did not match anything.
|
||||
|
@ -226,8 +226,67 @@ class RecordDialog(Gtk.Dialog):
|
|||
# otherwise there may be an invalid character after the match.
|
||||
return (len(data) == 6) # HHMMSS format
|
||||
|
||||
elif(data_type == "E"):
|
||||
# Enumeration.
|
||||
#FIXME: Need to make sure that the "S" and "M" data types accept ASCII-only characters
|
||||
# in the range 32-126 inclusive.
|
||||
elif(data_type == "S"):
|
||||
# String
|
||||
m = re.match(r"(.+)", data)
|
||||
if(m is None):
|
||||
return False
|
||||
else:
|
||||
return (m.group(0) == data)
|
||||
|
||||
elif(data_type == "I"):
|
||||
# IntlString
|
||||
m = re.match(ur"(.+)", data, re.UNICODE)
|
||||
if(m is None):
|
||||
return False
|
||||
else:
|
||||
return (m.group(0) == data)
|
||||
|
||||
elif(data_type == "G"):
|
||||
# IntlMultilineString
|
||||
m = re.match(ur"(.+(\r\n)*.*)", data, re.UNICODE)
|
||||
if(m is None):
|
||||
return False
|
||||
else:
|
||||
return (m.group(0) == data)
|
||||
|
||||
elif(data_type == "M"):
|
||||
# MultilineString
|
||||
m = re.match(r"(.+(\r\n)*.*)", data)
|
||||
if(m is None):
|
||||
return False
|
||||
else:
|
||||
return (m.group(0) == data)
|
||||
|
||||
elif(data_type == "L"):
|
||||
# Location
|
||||
pattern = re.compile(r"([EWNS]{1})", re.IGNORECASE)
|
||||
m_directional = pattern.match(data, 0)
|
||||
if(m_directional is None):
|
||||
# Did not match anything.
|
||||
return False
|
||||
else:
|
||||
pattern = re.compile(r"([0-9]{3})")
|
||||
m_degrees = pattern.match(data, 1)
|
||||
if((m_degrees is None) or int(m_degrees.group(0)) < 0 or int(m_degrees.group(0)) > 180):
|
||||
# Did not match anything.
|
||||
return False
|
||||
else:
|
||||
pattern = re.compile(r"([0-9]{2}\.[0-9]{3})")
|
||||
m_minutes = pattern.match(data, 4)
|
||||
if((m_minutes is None) or float(m_minutes.group(0)) < 0 or float(m_minutes.group(0)) > 59.999):
|
||||
# Did not match anything.
|
||||
return False
|
||||
else:
|
||||
# Make sure we match the whole string,
|
||||
# otherwise there may be an invalid character after the match.
|
||||
return (len(data) == 10)
|
||||
|
||||
|
||||
elif(data_type == "E" or data_type == "A"):
|
||||
# Enumeration, AwardList.
|
||||
# We'll assume that this data is valid already,
|
||||
# since the user can only select from a pre-defined (valid) list.
|
||||
return True
|
||||
|
|
Ładowanie…
Reference in New Issue