1.1 --- a/EventAggregatorSupport.py Sun Aug 07 00:11:31 2011 +0200
1.2 +++ b/EventAggregatorSupport.py Sun Aug 07 01:23:44 2011 +0200
1.3 @@ -148,6 +148,9 @@
1.4 else:
1.5 return int(x)
1.6
1.7 +def to_list(s, sep):
1.8 + return [x.strip() for x in s.split(sep) if x.strip()]
1.9 +
1.10 def sort_none_first(x, y):
1.11 if x is None:
1.12 return -1
1.13 @@ -613,7 +616,12 @@
1.14 # Convert lists.
1.15
1.16 elif property == "CATEGORIES":
1.17 - value = [v.strip() for v in value.split(",") if v.strip()]
1.18 + value = to_list(value, ",")
1.19 +
1.20 + # Convert positions (using decimal values).
1.21 +
1.22 + elif property == "GEO":
1.23 + value = map(getMapReferenceFromDecimal, to_list(value, ";"))
1.24
1.25 # Accept other textual data as it is.
1.26
1.27 @@ -634,7 +642,7 @@
1.28
1.29 class EventPage:
1.30
1.31 - "An event page."
1.32 + "An event page acting as an event resource."
1.33
1.34 def __init__(self, page):
1.35 self.page = page
1.36 @@ -754,7 +762,12 @@
1.37 # Lists (whose elements may be quoted).
1.38
1.39 elif term in ("topics", "categories"):
1.40 - desc = [getSimpleWikiText(value.strip()) for value in desc.split(",") if value.strip()]
1.41 + desc = map(getSimpleWikiText, to_list(desc, ","))
1.42 +
1.43 + # Position details (using degrees:minutes:seconds).
1.44 +
1.45 + elif term == "geo":
1.46 + desc = map(getMapReference, to_list(desc, ";"))
1.47
1.48 # Labels which may well be quoted.
1.49
1.50 @@ -2422,6 +2435,15 @@
1.51
1.52 return Reference(*map(float, value.split(":")))
1.53
1.54 +def getMapReferenceFromDecimal(value):
1.55 +
1.56 + "Return a map reference by parsing the given 'value' in decimal degrees."
1.57 +
1.58 + value = float(value)
1.59 + degrees, remainder = divmod(abs(value * 3600), 3600)
1.60 + minutes, seconds = divmod(remainder, 60)
1.61 + return Reference(sign(value) * degrees, minutes, seconds)
1.62 +
1.63 # vim: tabstop=4 expandtab shiftwidth=4
1.64
1.65 # User interface functions.