Ejemplo n.º 1
0
 def check_items(self, *items):
     from ics.utils import check_is_instance
     if len(items) == 1:
         check_is_instance("item", items[0], (ContentLine, Container))
     else:
         for nr, item in enumerate(items):
             check_is_instance("item %s" % nr, item, (ContentLine, Container))
Ejemplo n.º 2
0
 def __init__(self, email, extra=None, **kwargs):
     if extra is None:
         extra = dict()
     else:
         check_is_instance("extra", extra, dict)
     super(Person, self).__init__(email, extra)
     for key, val in kwargs.items():
         setattr(self, key, val)
Ejemplo n.º 3
0
 def serialize_toplevel(self,
                        component: Component,
                        context: Optional[ContextDict] = None):
     check_is_instance("instance", component, self.component_type)
     if not context:
         context = ContextDict(defaultdict(lambda: None))
     container = Container(
         component.extra.name
     )  # allow overwriting the name by setting the name of the extras
     self._serialize_attrs(component, context, container)
     return container
Ejemplo n.º 4
0
    def populate_instance(self,
                          instance: Component,
                          container: Container,
                          context: Optional[ContextDict] = None):
        if container.name != self.component_type.NAME:
            raise ValueError("container {} is no {}".format(
                container.name, self.component_type.NAME))
        check_is_instance("instance", instance,
                          (self.component_type, MutablePseudoComponent))
        if not context:
            context = ContextDict(defaultdict(lambda: None))

        self._populate_attrs(instance, container, context)
Ejemplo n.º 5
0
def validate_utc(inst, attr, value):
    check_is_instance(attr.name, value, datetime)
    if not is_utc(value):
        raise ValueError(
            "'{name}' must be in timezone UTC (got {value!r} which has tzinfo {tzinfo!r})"
            .format(name=attr.name, value=value, tzinfo=value.tzinfo))
Ejemplo n.º 6
0
 def add_recipient(self, recipient: Attendee):
     """ Add an recipient to the recipients list """
     check_is_instance("recipient", recipient, Attendee)
     self.recipients.append(recipient)
Ejemplo n.º 7
0
 def add_attendee(self, attendee: Attendee):
     """ Add an attendee to the attendees set """
     check_is_instance("attendee", attendee, Attendee)
     self.attendees.append(attendee)
Ejemplo n.º 8
0
 def validate_timespan(self, attr, value):
     check_is_instance(attr, value, self._TIMESPAN_TYPE)
     value.validate()