Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, obj):
self.obj = to_unicode(obj)
self.params = Parameters(encoding='BASE64', value="BINARY")
def __init__(self, dt):
if not isinstance(dt, (datetime, date, timedelta, time, tuple)):
raise ValueError('You must use datetime, date, timedelta, '
'time or tuple (for periods)')
if isinstance(dt, datetime):
self.params = Parameters({'value': 'DATE-TIME'})
elif isinstance(dt, date):
self.params = Parameters({'value': 'DATE'})
elif isinstance(dt, time):
self.params = Parameters({'value': 'TIME'})
elif isinstance(dt, tuple):
self.params = Parameters({'value': 'PERIOD'})
if (isinstance(dt, datetime) or isinstance(dt, time))\
and getattr(dt, 'tzinfo', False):
tzinfo = dt.tzinfo
if tzinfo is not pytz.utc and\
(tzutc is None or not isinstance(tzinfo, tzutc)):
# set the timezone as a parameter to the property
tzid = tzid_from_dt(dt)
if tzid:
self.params.update({'TZID': tzid})
self.dt = dt
def __init__(self, *args, **kwargs):
super(vRecur, self).__init__(*args, **kwargs)
self.params = Parameters()
def content_line(self, name, value, sorted=True):
"""Returns property as content line.
"""
params = getattr(value, 'params', Parameters())
return Contentline.from_parts(name, params, value, sorted=sorted)
def content_lines(self):
"Converts the Component and subcomponents into content lines"
contentlines = Contentlines()
for name, values in self.property_items():
params = getattr(values, 'params', Parameters())
contentlines.append(Contentline.from_parts((name, params, values)))
contentlines.append('') # remember the empty string in the end
return contentlines
icalendar's own property types (Fallback is "vText")
or False, if not.
:type encode: Boolean
:returns: icalendar property value
"""
if not encode:
return value
if isinstance(value, types_factory.all_types):
# Don't encode already encoded values.
return value
klass = types_factory.for_property(name)
obj = klass(value)
if parameters:
if isinstance(parameters, dict):
params = Parameters()
for key, item in parameters.items():
params[key] = item
parameters = params
assert isinstance(parameters, Parameters)
obj.params = parameters
return obj
cnode: typically from Erebus2ICSVisitor
return: icalendar.Calendar
"""
comp = Component()
comp.name = cnode.name.upper()
for k,v in cnode.attr.iteritems():
# If an attribute is a CNode, say n, we must add all the
# attributes of n as parameters to the iCalendar element. We
# first encode the value to the corresponding iCalendar value
# (with types_factory, like icalendar.Component does
# internally), and then add the parameters.
if v.__class__ == CNode:
target_class = types_factory.for_property(k)
val = target_class(v.content)
val.params = Parameters()
for p,pv in v.attr.iteritems():
val.params[p] = pv
comp.add(k, val, encode=0)
else:
comp.add(k, v, encode=1)
for c in cnode.children:
comp.add_component(cnode2ical(c))
return comp
def content_lines(self):
"Converts the Component and subcomponents into content lines"
contentlines = Contentlines()
for name, values in self.property_items():
params = getattr(values, 'params', Parameters())
contentlines.append(Contentline.from_parts((name, params, values)))
contentlines.append('') # remember the empty string in the end
return contentlines