def serialize_trigger(alarm, container):
        if not alarm.trigger:
            raise ValueError("Alarm must have a trigger")

        if isinstance(alarm.trigger, timedelta):
            representation = timedelta_to_duration(alarm.trigger)
            container.append(ContentLine("TRIGGER", value=representation))
        else:
            container.append(
                ContentLine(
                    "TRIGGER",
                    params={"VALUE": ["DATE-TIME"]},
                    value=arrow_to_iso(alarm.trigger),
                ))
    def serialize_uid(todo: "Todo", container: Container):
        if todo.uid:
            uid = todo.uid
        else:
            uid = uid_gen()

        container.append(ContentLine("UID", value=uid))
    def serialize_dtstamp(todo: "Todo", container: Container):
        if todo.dtstamp:
            instant = todo.dtstamp
        else:
            instant = arrow.now()

        container.append(ContentLine("DTSTAMP", value=arrow_to_iso(instant)))
Example #4
0
 def serialize(self) -> ContentLine:
     line = ContentLine(self.Meta.name,
                        params=self.extra,
                        value=escape_string('mailto:%s' % self.email))
     for output in self.Meta.serializer.get_serializers():
         output(self, line)
     return line
Example #5
0
    def serialize_1prodid(calendar,
                          container):  # 1prodid will be sorted second
        if calendar.creator:
            creator = calendar.creator
        else:
            creator = "recurrent_ics.py - http://git.io/lLljaA"

        container.append(ContentLine("PRODID", value=creator))
Example #6
0
    def serialize_recurrent(event, container):
        if event.recurrent:
            params = {
                "FREQ": event.recurrent,
                "BYDAY": ",".join(event.recurrence_weekdays),
                "INTERVAL": str(event.recurrence_interval)
            }
            if event.recurrence_count:
                params["COUNT"] = event.recurrence_count
            if event.recurrence_end:
                params["UNTIL"] = arrow_to_iso(event.recurrence_end)

            container.append(
                ContentLine("RRULE", value=parse_rrule_dict(params)))
Example #7
0
 def serialize_method(calendar, container):
     if calendar.method:
         container.append(
             ContentLine("METHOD", value=calendar.method.upper()))
 def serialize_cn(person: "Person", line: ContentLine):
     if person.common_name:
         line.params["CN"] = [escape_string(person.common_name)]
 def serialize_partstat(attendee: "Attendee", line: ContentLine):
     if attendee.partstat:
         line.params["PARTSTAT"] = [escape_string(attendee.partstat)]
 def serialize_rsvp(attendee: "Attendee", line: ContentLine):
     if attendee.rsvp is not None:
         line.params["RSVP"] = [attendee.rsvp]
Example #11
0
 def serialize_location(todo: "Todo", container: Container):
     if todo.location:
         container.append(
             ContentLine("LOCATION", value=escape_string(todo.location))
         )
Example #12
0
 def serialize_start(todo: "Todo", container: Container):
     if todo.begin:
         container.append(ContentLine("DTSTART", value=arrow_to_iso(todo.begin)))
Example #13
0
 def serialize_description(todo: "Todo", container: Container):
     if todo.description:
         container.append(
             ContentLine("DESCRIPTION", value=escape_string(todo.description))
         )
Example #14
0
 def serialize_created(todo: "Todo", container: Container):
     if todo.created:
         container.append(ContentLine("CREATED", value=arrow_to_iso(todo.created)))
Example #15
0
 def serialize_completed(todo: "Todo", container: Container):
     if todo.completed:
         container.append(
             ContentLine("COMPLETED", value=arrow_to_iso(todo.completed))
         )
 def serialize_dir(person: "Person", line: ContentLine):
     if person.dir:
         line.params["DIR"] = [escape_string(person.dir)]
 def serialize_sent_by(person: "Person", line: ContentLine):
     if person.sent_by:
         line.params["SENT-BY"] = [escape_string(person.sent_by)]
Example #18
0
 def serialize_percent(todo: "Todo", container: Container):
     if todo.percent is not None:
         container.append(ContentLine("PERCENT-COMPLETE", value=str(todo.percent)))
 def serialize_role(attendee: "Attendee", line: ContentLine):
     if attendee.role:
         line.params["ROLE"] = [escape_string(attendee.role)]
Example #20
0
 def serialize_priority(todo: "Todo", container: Container):
     if todo.priority is not None:
         container.append(ContentLine("PRIORITY", value=str(todo.priority)))
 def serialize_cutype(attendee: "Attendee", line: ContentLine):
     if attendee.cutype:
         line.params["CUTYPE"] = [escape_string(attendee.cutype)]
Example #22
0
 def serialize_summary(todo: "Todo", container: Container):
     if todo.name:
         container.append(ContentLine("SUMMARY", value=escape_string(todo.name)))
Example #23
0
 def serialize_calscale(calendar, container):
     if calendar.scale:
         container.append(
             ContentLine("CALSCALE", value=calendar.scale.upper()))
Example #24
0
 def serialize_url(todo: "Todo", container: Container):
     if todo.url:
         container.append(ContentLine("URL", value=escape_string(todo.url)))
Example #25
0
 def serialize_0version(calendar,
                        container):  # 0version will be sorted first
     container.append(ContentLine("VERSION", value="2.0"))
Example #26
0
 def serialize_due(todo: "Todo", container: Container):
     if todo._due_time:
         container.append(ContentLine("DUE", value=arrow_to_iso(todo._due_time)))
class CalendarParser(Parser):
    @option(required=True)
    def parse_prodid(calendar, prodid):
        calendar._creator = prodid.value

    _version_default = [ContentLine(name="VERSION", value="2.0")]

    @option(required=True, default=_version_default)
    def parse_version(calendar, line):
        version = line
        # TODO : should take care of minver/maxver
        if ";" in version.value:
            _, calendar.version = version.value.split(";")
        else:
            calendar.version = version.value

    def parse_calscale(calendar, line):
        calscale = line
        if calscale:
            calendar.scale = calscale.value.lower()
            calendar.scale_params = calscale.params
        else:
            calendar.scale = "georgian"
            calendar.scale_params = {}

    def parse_method(calendar, line):
        method = line
        if method:
            calendar.method = method.value
            calendar.method_params = method.params
        else:
            calendar.method = None
            calendar.method_params = {}

    @option(multiple=True)
    def parse_vtimezone(calendar, vtimezones):
        """Receives a list of VTIMEZONE blocks.

        Parses them and adds them to calendar._timezones.
        """
        for vtimezone in vtimezones:
            remove_x(vtimezone)  # Remove non standard lines from the block
            remove_sequence(
                vtimezone
            )  # Remove SEQUENCE lines because tzical does not understand them
            fake_file = StringIO()
            fake_file.write(str(vtimezone))  # Represent the block as a string
            fake_file.seek(0)
            timezones = tzical(fake_file)  # tzical does not like strings
            # timezones is a tzical object and could contain multiple timezones
            for key in timezones.keys():
                calendar._timezones[key] = timezones.get(key)

    @option(multiple=True)
    def parse_vevent(calendar, lines):
        # tz=calendar._timezones gives access to the event factory to the
        # timezones list
        def event_factory(x):
            return Event._from_container(x, tz=calendar._timezones)

        calendar.events = set(map(event_factory, lines))

    @option(multiple=True)
    def parse_vtodo(calendar, lines):
        # tz=calendar._timezones gives access to the event factory to the
        # timezones list
        def todo_factory(x):
            return Todo._from_container(x, tz=calendar._timezones)

        calendar.todos = set(map(todo_factory, lines))
Example #28
0
 def serialize_duration(todo: "Todo", container: Container):
     if todo._duration:
         representation = timedelta_to_duration(todo._duration)
         container.append(ContentLine("DURATION", value=representation))
Example #29
0
 def serialize_status(todo: "Todo", container: Container):
     if todo.status:
         container.append(ContentLine("STATUS", value=todo.status))
 def serialize_subject(alarm, container):
     container.append(
         ContentLine("SUMMARY", value=escape_string(alarm.subject or "")))