X-Git-Url: http://git.tremily.us/?p=pycalendar.git;a=blobdiff_plain;f=pycalendar%2Fdtype%2Fgeo.py;fp=pycalendar%2Fdtype%2Fgeo.py;h=4a7ac70c1a038c3dd737800524030ed614e3dc97;hp=0000000000000000000000000000000000000000;hb=81ad44f701a889d346fe5e090f3d91871d907034;hpb=b5bb8b30d371978e877e81820c58cd4bda8bba6c diff --git a/pycalendar/dtype/geo.py b/pycalendar/dtype/geo.py new file mode 100644 index 0000000..4a7ac70 --- /dev/null +++ b/pycalendar/dtype/geo.py @@ -0,0 +1,31 @@ +# Copyright + +"""Functions for processing geographic position + +As defined in :RFC:`5545`, section 3.8.1.6 (Geographic Position). +""" + +from . import base as _base + + +class Geo (_base.DataType): + name = 'GEO' + + @classmethod + def decode(cls, property, value): + """Parse geographic position + + As defined in :RFC:`5545`, section 3.8.1.6 (Geographic + Position). + + >>> Geo.decode(property={}, value='37.386013;-122.082932') + (37.386013, -122.082932) + """ + geo = tuple(float(x) for x in value.split(';')) + if len(geo) != 2: + raise ValueError(value) + return geo + + @classmethod + def encode(cls, property, value): + return '{:.6f};{:.6f}'.format(*value)