<s> """<STR_LIT>""" <EOL> from datetime import date , datetime , time , timedelta <EOL> import os <EOL> import icalendar <EOL> import pytz <EOL> from . . aux import generate_random_uid <EOL> from . aux import to_naive_utc , to_unix_time , invalid_timezone , delete_instance <EOL> from . . log import logger <EOL> class Event ( object ) : <EOL> """<STR_LIT>""" <EOL> allday = False <EOL> def __init__ ( self , vevents , ref = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if self . __class__ . __name__ == '<STR_LIT>' : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> self . _vevents = vevents <EOL> self . _locale = kwargs . pop ( '<STR_LIT>' , None ) <EOL> self . readonly = kwargs . pop ( '<STR_LIT>' , None ) <EOL> self . href = kwargs . pop ( '<STR_LIT>' , None ) <EOL> self . etag = kwargs . pop ( '<STR_LIT>' , None ) <EOL> self . calendar = kwargs . pop ( '<STR_LIT>' , None ) <EOL> self . ref = ref <EOL> start = kwargs . pop ( '<STR_LIT:start>' , None ) <EOL> end = kwargs . pop ( '<STR_LIT:end>' , None ) <EOL> if start is None : <EOL> self . _start = self . _vevents [ self . ref ] [ '<STR_LIT>' ] . dt <EOL> else : <EOL> self . _start = start <EOL> if end is None : <EOL> try : <EOL> self . _end = self . _vevents [ self . ref ] [ '<STR_LIT>' ] . dt <EOL> except KeyError : <EOL> self . _end = self . _start + self . _vevents [ self . ref ] [ '<STR_LIT>' ] . dt <EOL> else : <EOL> self . _end = end <EOL> if kwargs : <EOL> raise TypeError ( '<STR_LIT>' % kwargs . keys ( ) ) <EOL> @ classmethod <EOL> def _get_type_from_vDDD ( cls , start ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( start . dt , datetime ) : <EOL> return AllDayEvent <EOL> if '<STR_LIT>' in start . params or start . dt . tzinfo is not None : <EOL> return LocalizedEvent <EOL> return FloatingEvent <EOL> @ classmethod <EOL> def _get_type_from_date ( cls , start ) : <EOL> if hasattr ( start , '<STR_LIT>' ) and start . tzinfo is not None : <EOL> cls = LocalizedEvent <EOL> elif isinstance ( start , datetime ) : <EOL> cls = FloatingEvent <EOL> elif isinstance ( start , date ) : <EOL> cls = AllDayEvent <EOL> return cls <EOL> @ classmethod <EOL> def fromVEvents ( cls , events_list , ref = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> assert isinstance ( events_list , list ) <EOL> vevents = dict ( ) <EOL> if len ( events_list ) == <NUM_LIT:1> : <EOL> vevents [ '<STR_LIT>' ] = events_list [ <NUM_LIT:0> ] <EOL> else : <EOL> for event in events_list : <EOL> if '<STR_LIT>' in event : <EOL> if invalid_timezone ( event [ '<STR_LIT>' ] ) : <EOL> default_timezone = kwargs [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> recur_id = default_timezone . localize ( event [ '<STR_LIT>' ] . dt ) <EOL> ident = str ( to_unix_time ( recur_id ) ) <EOL> else : <EOL> ident = str ( to_unix_time ( event [ '<STR_LIT>' ] . dt ) ) <EOL> vevents [ ident ] = event <EOL> else : <EOL> vevents [ '<STR_LIT>' ] = event <EOL> if ref is None : <EOL> ref = '<STR_LIT>' <EOL> try : <EOL> if type ( vevents [ ref ] [ '<STR_LIT>' ] . dt ) != type ( vevents [ ref ] [ '<STR_LIT>' ] . dt ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> except KeyError : <EOL> pass <EOL> if kwargs . get ( '<STR_LIT:start>' ) : <EOL> instcls = cls . _get_type_from_date ( kwargs . get ( '<STR_LIT:start>' ) ) <EOL> else : <EOL> instcls = cls . _get_type_from_vDDD ( vevents [ ref ] [ '<STR_LIT>' ] ) <EOL> return instcls ( vevents , ref = ref , ** kwargs ) <EOL> @ classmethod <EOL> def fromString ( cls , event_str , ref = None , ** kwargs ) : <EOL> calendar_collection = icalendar . Calendar . from_ical ( event_str ) <EOL> events = [ item for item in calendar_collection . walk ( ) if item . name == '<STR_LIT>' ] <EOL> return cls . fromVEvents ( events , ref , ** kwargs ) <EOL> def __lt__ ( self , other ) : <EOL> try : <EOL> return self . start_local <= other . start_local <EOL> except TypeError : <EOL> if not isinstance ( other . start_local , datetime ) : <EOL> return <NUM_LIT:0> <EOL> elif not isinstance ( self . start_local , datetime ) : <EOL> return <NUM_LIT:1> <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' . format ( self , other ) ) <EOL> def update_start_end ( self , start , end ) : <EOL> """<STR_LIT>""" <EOL> if type ( start ) != type ( end ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> self . __class__ = self . _get_type_from_date ( start ) <EOL> self . _vevents [ self . ref ] . pop ( '<STR_LIT>' ) <EOL> self . _vevents [ self . ref ] . add ( '<STR_LIT>' , start ) <EOL> self . _start = start <EOL> if not isinstance ( end , datetime ) : <EOL> end = end + timedelta ( days = <NUM_LIT:1> ) <EOL> self . _end = end <EOL> if '<STR_LIT>' in self . _vevents [ self . ref ] : <EOL> self . _vevents [ self . ref ] . pop ( '<STR_LIT>' ) <EOL> self . _vevents [ self . ref ] . add ( '<STR_LIT>' , end ) <EOL> else : <EOL> self . _vevents [ self . ref ] . pop ( '<STR_LIT>' ) <EOL> self . _vevents [ self . ref ] . add ( '<STR_LIT>' , end - start ) <EOL> @ property <EOL> def recurring ( self ) : <EOL> return '<STR_LIT>' in self . _vevents [ self . ref ] or '<STR_LIT>' in self . _vevents [ self . ref ] or '<STR_LIT>' in self . _vevents [ self . ref ] <EOL> @ property <EOL> def recurpattern ( self ) : <EOL> if '<STR_LIT>' in self . _vevents [ self . ref ] : <EOL> return self . _vevents [ self . ref ] [ '<STR_LIT>' ] . to_ical ( ) . decode ( '<STR_LIT:utf-8>' ) <EOL> else : <EOL> return '<STR_LIT>' <EOL> @ property <EOL> def recurobject ( self ) : <EOL> if '<STR_LIT>' in self . _vevents [ self . ref ] : <EOL> return self . _vevents [ self . ref ] [ '<STR_LIT>' ] <EOL> else : <EOL> return icalendar . vRecur ( ) <EOL> def update_rrule ( self , rrule ) : <EOL> self . _vevents [ '<STR_LIT>' ] . pop ( '<STR_LIT>' ) <EOL> if rrule is not None : <EOL> self . _vevents [ '<STR_LIT>' ] . add ( '<STR_LIT>' , rrule ) <EOL> @ property <EOL> def recurrence_id ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . ref == '<STR_LIT>' : <EOL> return self . start <EOL> else : <EOL> return pytz . UTC . localize ( datetime . utcfromtimestamp ( int ( self . ref ) ) ) <EOL> def increment_sequence ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . _vevents [ self . ref ] [ '<STR_LIT>' ] += <NUM_LIT:1> <EOL> except KeyError : <EOL> self . _vevents [ self . ref ] [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> @ property <EOL> def symbol_strings ( self ) : <EOL> if self . _locale [ '<STR_LIT>' ] : <EOL> return dict ( <EOL> recurring = '<STR_LIT>' , <EOL> range = '<STR_LIT>' , <EOL> range_end = '<STR_LIT>' , <EOL> range_start = '<STR_LIT>' , <EOL> right_arrow = '<STR_LIT>' <EOL> ) <EOL> else : <EOL> return dict ( <EOL> recurring = '<STR_LIT:R>' , <EOL> range = '<STR_LIT>' , <EOL> range_end = '<STR_LIT>' , <EOL> range_start = '<STR_LIT>' , <EOL> right_arrow = '<STR_LIT>' <EOL> ) <EOL> @ property <EOL> def start_local ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . start <EOL> @ property <EOL> def end_local ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . end <EOL> @ property <EOL> def start ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _start <EOL> @ property <EOL> def end ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _end <EOL> @ property <EOL> def duration ( self ) : <EOL> try : <EOL> return self . _vevents [ self . ref ] [ '<STR_LIT>' ] . dt <EOL> except KeyError : <EOL> return self . end - self . start <EOL> @ property <EOL> def uid ( self ) : <EOL> return self . _vevents [ self . ref ] [ '<STR_LIT>' ] <EOL> @ property <EOL> def organizer ( self ) : <EOL> if '<STR_LIT>' not in self . _vevents [ self . ref ] : <EOL> return '<STR_LIT>' <EOL> organizer = self . _vevents [ self . ref ] [ '<STR_LIT>' ] <EOL> cn = organizer . params . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> email = organizer . split ( '<STR_LIT::>' ) [ - <NUM_LIT:1> ] <EOL> if cn : <EOL> return '<STR_LIT>' . format ( cn , email ) <EOL> else : <EOL> return email <EOL> @ staticmethod <EOL> def _create_calendar ( ) : <EOL> """<STR_LIT>""" <EOL> calendar = icalendar . Calendar ( ) <EOL> calendar . add ( '<STR_LIT:version>' , '<STR_LIT>' ) <EOL> calendar . add ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return calendar <EOL> @ property <EOL> def raw ( self ) : <EOL> """<STR_LIT>""" <EOL> calendar = self . _create_calendar ( ) <EOL> tzs = list ( ) <EOL> for vevent in self . _vevents . values ( ) : <EOL> if hasattr ( vevent [ '<STR_LIT>' ] . dt , '<STR_LIT>' ) and vevent [ '<STR_LIT>' ] . dt . tzinfo is not None : <EOL> tzs . append ( vevent [ '<STR_LIT>' ] . dt . tzinfo ) <EOL> if '<STR_LIT>' in vevent and hasattr ( vevent [ '<STR_LIT>' ] . dt , '<STR_LIT>' ) and vevent [ '<STR_LIT>' ] . dt . tzinfo is not None and vevent [ '<STR_LIT>' ] . dt . tzinfo not in tzs : <EOL> tzs . append ( vevent [ '<STR_LIT>' ] . dt . tzinfo ) <EOL> for tzinfo in tzs : <EOL> if tzinfo == pytz . UTC : <EOL> continue <EOL> timezone = create_timezone ( tzinfo , self . start ) <EOL> calendar . add_component ( timezone ) <EOL> for vevent in self . _vevents . values ( ) : <EOL> calendar . add_component ( vevent ) <EOL> return calendar . to_ical ( ) . decode ( '<STR_LIT:utf-8>' ) <EOL> def export_ics ( self , path ) : <EOL> """<STR_LIT>""" <EOL> export_path = os . path . expanduser ( path ) <EOL> with open ( export_path , '<STR_LIT:w>' ) as fh : <EOL> fh . write ( self . raw ) <EOL> @ property <EOL> def ident ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _vevents [ self . ref ] [ '<STR_LIT>' ] <EOL> @ property <EOL> def summary ( self ) : <EOL> bday = self . _vevents [ self . ref ] . get ( '<STR_LIT>' , None ) <EOL> if bday : <EOL> number = self . start_local . year - int ( bday [ : <NUM_LIT:4> ] ) <EOL> name = self . _vevents [ self . ref ] . get ( '<STR_LIT>' , None ) <EOL> return '<STR_LIT>' . format ( name = name , number = number ) <EOL> else : <EOL> return self . _vevents [ self . ref ] . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def update_summary ( self , summary ) : <EOL> self . _vevents [ self . ref ] [ '<STR_LIT>' ] = summary <EOL> @ staticmethod <EOL> def _can_handle_alarm ( alarm ) : <EOL> """<STR_LIT>""" <EOL> return alarm . get ( '<STR_LIT>' ) == '<STR_LIT>' and isinstance ( alarm . get ( '<STR_LIT>' ) . dt , timedelta ) <EOL> @ property <EOL> def alarms ( self ) : <EOL> """<STR_LIT>""" <EOL> return [ ( a . get ( '<STR_LIT>' ) . dt , a . get ( '<STR_LIT>' ) ) <EOL> for a in self . _vevents [ self . ref ] . subcomponents <EOL> if a . name == '<STR_LIT>' and self . _can_handle_alarm ( a ) ] <EOL> def update_alarms ( self , alarms ) : <EOL> """<STR_LIT>""" <EOL> components = self . _vevents [ self . ref ] . subcomponents <EOL> components = [ c for c in components <EOL> if not ( c . name == '<STR_LIT>' and self . _can_handle_alarm ( c ) ) ] <EOL> for alarm in alarms : <EOL> new = icalendar . Alarm ( ) <EOL> new . add ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> new . add ( '<STR_LIT>' , alarm [ <NUM_LIT:0> ] ) <EOL> new . add ( '<STR_LIT>' , alarm [ <NUM_LIT:1> ] ) <EOL> components . append ( new ) <EOL> self . _vevents [ self . ref ] . subcomponents = components <EOL> @ property <EOL> def location ( self ) : <EOL> return self . _vevents [ self . ref ] . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def update_location ( self , location ) : <EOL> self . _vevents [ self . ref ] [ '<STR_LIT>' ] = location <EOL> @ property <EOL> def description ( self ) : <EOL> return self . _vevents [ self . ref ] . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def update_description ( self , description ) : <EOL> self . _vevents [ self . ref ] [ '<STR_LIT>' ] = description <EOL> @ property <EOL> def _recur_str ( self ) : <EOL> if self . recurring : <EOL> recurstr = self . symbol_strings [ '<STR_LIT>' ] <EOL> else : <EOL> recurstr = '<STR_LIT>' <EOL> return recurstr <EOL> def relative_to ( self , day , full = False ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( day , datetime ) or not isinstance ( day , date ) : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( type ( day ) ) ) <EOL> day_start = self . _locale [ '<STR_LIT>' ] . localize ( datetime . combine ( day , time . min ) ) <EOL> day_end = self . _locale [ '<STR_LIT>' ] . localize ( datetime . combine ( day , time . max ) ) <EOL> tostr = '<STR_LIT:->' <EOL> if self . start_local < day_start : <EOL> startstr = self . symbol_strings [ '<STR_LIT>' ] + '<STR_LIT:U+0020>' <EOL> tostr = '<STR_LIT>' <EOL> else : <EOL> startstr = self . start_local . strftime ( self . _locale [ '<STR_LIT>' ] ) <EOL> start_of_next_day = day_start + timedelta ( days = <NUM_LIT:1> ) <EOL> if ( self . end_local == start_of_next_day and self . _locale [ '<STR_LIT>' ] == '<STR_LIT>' ) : <EOL> endstr = '<STR_LIT>' <EOL> elif self . end_local > day_end : <EOL> endstr = self . symbol_strings [ '<STR_LIT>' ] + '<STR_LIT:U+0020>' <EOL> tostr = '<STR_LIT>' <EOL> else : <EOL> endstr = self . end_local . strftime ( self . _locale [ '<STR_LIT>' ] ) <EOL> body = self . summary <EOL> if full : <EOL> if self . description . strip ( ) != '<STR_LIT>' : <EOL> body += '<STR_LIT:U+002CU+0020>' + self . description . strip ( ) <EOL> if self . location . strip ( ) != '<STR_LIT>' : <EOL> body += '<STR_LIT:U+002CU+0020>' + self . location . strip ( ) <EOL> comps = [ startstr + tostr + endstr + '<STR_LIT::>' , body , self . _recur_str ] <EOL> return '<STR_LIT:U+0020>' . join ( filter ( bool , comps ) ) <EOL> @ property <EOL> def event_description ( self ) : <EOL> """<STR_LIT>""" <EOL> location = '<STR_LIT>' + self . location if self . location != '<STR_LIT>' else '<STR_LIT>' <EOL> description = '<STR_LIT>' + self . description if self . description != '<STR_LIT>' else '<STR_LIT>' <EOL> repitition = '<STR_LIT>' + self . recurpattern if self . recurpattern != '<STR_LIT>' else '<STR_LIT>' <EOL> return '<STR_LIT>' . format ( <EOL> self . _rangestr , self . summary , location , repitition , description ) <EOL> def duplicate ( self ) : <EOL> """<STR_LIT>""" <EOL> new_uid = generate_random_uid ( ) <EOL> vevent = self . _vevents [ '<STR_LIT>' ] . copy ( ) <EOL> vevent [ '<STR_LIT>' ] = <NUM_LIT:0> <EOL> vevent [ '<STR_LIT>' ] = icalendar . vText ( new_uid ) <EOL> vevent [ '<STR_LIT>' ] = icalendar . vText ( vevent [ '<STR_LIT>' ] + '<STR_LIT>' ) <EOL> event = self . fromVEvents ( [ vevent ] ) <EOL> event . calendar = self . calendar <EOL> return event <EOL> def delete_instance ( self , instance ) : <EOL> """<STR_LIT>""" <EOL> assert self . recurring <EOL> delete_instance ( self . _vevents [ '<STR_LIT>' ] , instance ) <EOL> to_pop = list ( ) <EOL> for key in self . _vevents : <EOL> if key == '<STR_LIT>' : <EOL> continue <EOL> try : <EOL> if self . _vevents [ key ] . get ( '<STR_LIT>' ) . dt == instance : <EOL> to_pop . append ( key ) <EOL> except TypeError : <EOL> continue <EOL> for key in to_pop : <EOL> self . _vevents . pop ( key ) <EOL> class DatetimeEvent ( Event ) : <EOL> @ property <EOL> def _rangestr ( self ) : <EOL> if self . start_local . utctimetuple ( ) [ : <NUM_LIT:3> ] == self . end_local . utctimetuple ( ) [ : <NUM_LIT:3> ] : <EOL> starttime = self . start_local . strftime ( self . _locale [ '<STR_LIT>' ] ) <EOL> endtime = self . end_local . strftime ( self . _locale [ '<STR_LIT>' ] ) <EOL> datestr = self . end_local . strftime ( self . _locale [ '<STR_LIT>' ] ) <EOL> rangestr = starttime + '<STR_LIT:->' + endtime + '<STR_LIT:U+0020>' + datestr <EOL> else : <EOL> startstr = self . start_local . strftime ( self . _locale [ '<STR_LIT>' ] ) <EOL> endstr = self . end_local . strftime ( self . _locale [ '<STR_LIT>' ] ) <EOL> rangestr = startstr + '<STR_LIT>' + endstr <EOL> return rangestr <EOL> class LocalizedEvent ( DatetimeEvent ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( ) . __init__ ( * args , ** kwargs ) <EOL> starttz = getattr ( self . _vevents [ self . ref ] [ '<STR_LIT>' ] . dt , '<STR_LIT>' , None ) <EOL> if starttz is None : <EOL> starttz = self . _locale [ '<STR_LIT>' ] <EOL> try : <EOL> endtz = getattr ( self . _vevents [ self . ref ] [ '<STR_LIT>' ] . dt , '<STR_LIT>' , None ) <EOL> except KeyError : <EOL> endtz = starttz <EOL> if endtz is None : <EOL> endtz = self . _locale [ '<STR_LIT>' ] <EOL> try : <EOL> self . _start = self . _start . astimezone ( starttz ) <EOL> self . _end = self . _end . astimezone ( endtz ) <EOL> except ValueError : <EOL> self . _start = starttz . localize ( self . _start ) <EOL> self . _end = endtz . localize ( self . _end ) <EOL> @ property <EOL> def start_local ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . start . astimezone ( self . _locale [ '<STR_LIT>' ] ) <EOL> @ property <EOL> def end_local ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . end . astimezone ( self . _locale [ '<STR_LIT>' ] ) <EOL> class FloatingEvent ( DatetimeEvent ) : <EOL> """<STR_LIT:U+0020>""" <EOL> allday = False <EOL> @ property <EOL> def start_local ( self ) : <EOL> return self . _locale [ '<STR_LIT>' ] . localize ( self . start ) <EOL> @ property <EOL> def end_local ( self ) : <EOL> return self . _locale [ '<STR_LIT>' ] . localize ( self . end ) <EOL> class AllDayEvent ( Event ) : <EOL> allday = True <EOL> @ property <EOL> def end ( self ) : <EOL> end = super ( AllDayEvent , self ) . end <EOL> if end == self . start : <EOL> logger . warning ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( self . href , self . summary , self . start ) ) <EOL> end += timedelta ( days = <NUM_LIT:1> ) <EOL> return end - timedelta ( days = <NUM_LIT:1> ) <EOL> def relative_to ( self , day , full = False ) : <EOL> if self . start > day or self . end < day : <EOL> raise ValueError ( '<STR_LIT>' <EOL> . format ( dict ( day = day , start = self . start , <EOL> end = self . end ) ) ) <EOL> elif self . start < day and self . end > day : <EOL> rangestr = self . symbol_strings [ '<STR_LIT>' ] <EOL> elif self . start < day : <EOL> rangestr = self . symbol_strings [ '<STR_LIT>' ] <EOL> elif self . end > day : <EOL> rangestr = self . symbol_strings [ '<STR_LIT>' ] <EOL> elif self . start == self . end == day : <EOL> rangestr = '<STR_LIT>' <EOL> body = self . summary <EOL> if full : <EOL> if self . description . strip ( ) != '<STR_LIT>' : <EOL> body += '<STR_LIT:U+002CU+0020>' + self . description . strip ( ) <EOL> if self . location . strip ( ) != '<STR_LIT>' : <EOL> body += '<STR_LIT:U+002CU+0020>' + self . location . strip ( ) <EOL> return '<STR_LIT:U+0020>' . join ( filter ( bool , ( rangestr , body , self . _recur_str ) ) ) <EOL> @ property <EOL> def _rangestr ( self ) : <EOL> if self . start_local == self . end_local : <EOL> rangestr = self . start_local . strftime ( self . _locale [ '<STR_LIT>' ] ) <EOL> else : <EOL> if self . start_local . year == self . end_local . year : <EOL> startstr = self . start_local . strftime ( self . _locale [ '<STR_LIT>' ] ) <EOL> else : <EOL> startstr = self . start_local . strftime ( self . _locale [ '<STR_LIT>' ] ) <EOL> endstr = self . end_local . strftime ( self . _locale [ '<STR_LIT>' ] ) <EOL> rangestr = startstr + '<STR_LIT>' + endstr <EOL> return rangestr <EOL> def create_timezone ( tz , first_date = None , last_date = None ) : <EOL> """<STR_LIT>""" <EOL> first_date = datetime . today ( ) if not first_date else to_naive_utc ( first_date ) <EOL> last_date = datetime . today ( ) if not last_date else to_naive_utc ( last_date ) <EOL> timezone = icalendar . Timezone ( ) <EOL> timezone . add ( '<STR_LIT>' , tz ) <EOL> dst = { <EOL> one [ <NUM_LIT:2> ] : '<STR_LIT>' in two . __repr__ ( ) <EOL> for one , two in iter ( tz . _tzinfos . items ( ) ) <EOL> } <EOL> bst = { <EOL> one [ <NUM_LIT:2> ] : '<STR_LIT>' in two . __repr__ ( ) <EOL> for one , two in iter ( tz . _tzinfos . items ( ) ) <EOL> } <EOL> first_num , last_num = <NUM_LIT:0> , len ( tz . _utc_transition_times ) - <NUM_LIT:1> <EOL> first_tt = tz . _utc_transition_times [ <NUM_LIT:0> ] <EOL> last_tt = tz . _utc_transition_times [ - <NUM_LIT:1> ] <EOL> for num , dt in enumerate ( tz . _utc_transition_times ) : <EOL> if dt > first_tt and dt < first_date : <EOL> first_num = num <EOL> first_tt = dt <EOL> if dt < last_tt and dt > last_date : <EOL> last_num = num <EOL> last_tt = dt <EOL> timezones = dict ( ) <EOL> for num in range ( first_num , last_num + <NUM_LIT:1> ) : <EOL> name = tz . _transition_info [ num ] [ <NUM_LIT:2> ] <EOL> if name in timezones : <EOL> ttime = tz . fromutc ( tz . _utc_transition_times [ num ] ) . replace ( tzinfo = None ) <EOL> if '<STR_LIT>' in timezones [ name ] : <EOL> timezones [ name ] [ '<STR_LIT>' ] . dts . append ( <EOL> icalendar . prop . vDDDTypes ( ttime ) ) <EOL> else : <EOL> timezones [ name ] . add ( '<STR_LIT>' , ttime ) <EOL> continue <EOL> if dst [ name ] or bst [ name ] : <EOL> subcomp = icalendar . TimezoneDaylight ( ) <EOL> else : <EOL> subcomp = icalendar . TimezoneStandard ( ) <EOL> subcomp . add ( '<STR_LIT>' , tz . _transition_info [ num ] [ <NUM_LIT:2> ] ) <EOL> subcomp . add ( <EOL> '<STR_LIT>' , <EOL> tz . fromutc ( tz . _utc_transition_times [ num ] ) . replace ( tzinfo = None ) ) <EOL> subcomp . add ( '<STR_LIT>' , tz . _transition_info [ num ] [ <NUM_LIT:0> ] ) <EOL> subcomp . add ( '<STR_LIT>' , tz . _transition_info [ num - <NUM_LIT:1> ] [ <NUM_LIT:0> ] ) <EOL> timezones [ name ] = subcomp <EOL> for subcomp in timezones . values ( ) : <EOL> timezone . add_component ( subcomp ) <EOL> return timezone <EOL> class EventStandIn ( ) : <EOL> def __init__ ( self , calendar ) : <EOL> self . calendar = calendar <EOL> self . color = None <EOL> self . unicode_symbols = None <EOL> self . readonly = None </s>
