def create_event(client, calendar, data, id=None): path = None if id is None: id = str(uuid.uuid1()) path = url.join(calendar.url.path, id + ".ics") r = client.put(path, data, {"Content-Type": "text/calendar; charset=\"utf-8\""}) if r.status == 204 or r.status == 201: path = url.make(calendar.url, path) else: raise error.PutError(r.raw) return (id, path)
def _create(self, data, id=None, path=None): if id is None and path is not None and str(path).endswith('.ics'): id = re.search('(/|^)([^/]*).ics',str(path)).group(2) elif id is None: id = self.instance.vevent.uid.value if path is None: path = id + ".ics" path = self.parent.url.join(path) r = self.client.put(path, data, {"Content-Type": 'text/calendar; charset="utf-8"'}) if r.status == 302: path = [x[1] for x in r.headers if x[0]=='location'][0] elif not (r.status in (204, 201)): raise error.PutError(r.raw) self.url = URL.objectify(path) self.id = id
def _create(self, data, id=None, path=None): if id is None and path is not None and str(path).endswith('.ics'): id = re.search('(/|^)([^/]*).ics', str(path)).group(2) elif id is None: for obj_type in ('vevent', 'vtodo', 'vjournal', 'vfreebusy'): obj = None if hasattr(self.vobject_instance, obj_type): obj = getattr(self.vobject_instance, obj_type) elif self.vobject_instance.name.lower() == obj_type: obj = self.vobject_instance if obj is not None: try: id = obj.uid.value except AttributeError: id = str(uuid.uuid1()) obj.add('uid') obj.uid.value = id break else: for obj_type in ('vevent', 'vtodo', 'vjournal', 'vfreebusy'): obj = None if hasattr(self.vobject_instance, obj_type): obj = getattr(self.vobject_instance, obj_type) elif self.vobject_instance.name.lower() == obj_type: obj = self.vobject_instance if obj is not None: if not hasattr(obj, 'uid'): obj.add('uid') obj.uid.value = id break if path is None: path = quote(id) + ".ics" path = self.parent.url.join(path) r = self.client.put(path, data, {"Content-Type": 'text/calendar; charset="utf-8"'}) if r.status == 302: path = [x[1] for x in r.headers if x[0] == 'location'][0] elif not (r.status in (204, 201)): raise error.PutError(errmsg(r)) self.url = URL.objectify(path) self.id = id
def _create(self, data, id=None, path=None): if id is None and path is not None and str(path).endswith('.ics'): id = re.search('(/|^)([^/]*).ics', str(path)).group(2) elif id is None: for obj_type in ('vevent', 'vtodo', 'vjournal', 'vfreebusy'): obj = None for subcomp in self.instance.subcomponents: if subcomp.name.lower() == obj_type: obj = subcomp break if obj is None and self.instance.name.lower == obj_type: obj = self.instance if obj is not None: id = obj["uid"] break else: for obj_type in ('vevent', 'vtodo', 'vjournal', 'vfreebusy'): obj = None for subcomp in self.instance.subcomponents: if subcomp.name.lower() == obj_type: obj = subcomp break if obj is None and self.instance.name.lower == obj_type: obj = self.instance if obj is not None: obj.add("uid", id) break if path is None: path = id + ".ics" path = self.parent.url.join(path) r = self.client.put(path, data, {"Content-Type": 'text/calendar; charset="utf-8"'}) if r.status == 302: path = [x[1] for x in r.headers if x[0] == 'location'][0] elif not (r.status in (204, 201)): raise error.PutError(errmsg(r)) self.url = URL.objectify(path) self.id = id