diff --git a/CHANGES.rst b/CHANGES.rst index df402a4e..62880976 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,8 +6,7 @@ Changelog Minor changes: -- Refactored prop.py. Ref: #482 [pronoym99] - +- Refactored cal.py, tools.py and completed remaining minimal refactoring in parser.py. Ref: #481 [pronoym99] - Calendar.from_ical no longer throws long errors Ref: #473 Fixes: #472 diff --git a/docs/credits.rst b/docs/credits.rst index 22952c49..10f269b5 100644 --- a/docs/credits.rst +++ b/docs/credits.rst @@ -64,6 +64,7 @@ icalendar contributors - Mauro Amico - Alexander Pitkin - Michał Górny +- Pronoy Find out who contributed:: diff --git a/src/icalendar/cal.py b/src/icalendar/cal.py index cf7dc9cd..44b1c3fd 100644 --- a/src/icalendar/cal.py +++ b/src/icalendar/cal.py @@ -370,8 +370,7 @@ def from_ical(cls, st, multiple=False): factory = types_factory.for_property(name) component = stack[-1] if stack else None if not component: - raise ValueError('Property "{prop}" does not have ' - 'a parent component.'.format(prop=name)) + raise ValueError(f'Property "{name}" does not have a parent component.') datetime_names = ('DTSTART', 'DTEND', 'RECURRENCE-ID', 'DUE', 'FREEBUSY', 'RDATE', 'EXDATE') try: @@ -434,12 +433,8 @@ def to_ical(self, sorted=True): def __repr__(self): """String representation of class with all of it's subcomponents. """ - subs = ', '.join([str(it) for it in self.subcomponents]) - return '{}({}{})'.format( - self.name or type(self).__name__, - dict(self), - ', %s' % subs if subs else '' - ) + subs = ', '.join(str(it) for it in self.subcomponents) + return f"{self.name or type(self).__name__}({dict(self)}{', ' + subs if subs else ''})" ####################################### @@ -612,12 +607,10 @@ def to_tz(self): tzname = component['TZNAME'].encode('ascii', 'replace') tzname = self._make_unique_tzname(tzname, tznames) except KeyError: - tzname = '{}_{}_{}_{}'.format( - zone, - component['DTSTART'].to_ical().decode('utf-8'), - component['TZOFFSETFROM'].to_ical(), # for whatever reason this is str/unicode - component['TZOFFSETTO'].to_ical(), # for whatever reason this is str/unicode - ) + # for whatever reason this is str/unicode + tzname = f"{zone}_{component['DTSTART'].to_ical().decode('utf-8')}_" + \ + f"{component['TZOFFSETFROM'].to_ical()}_" + \ + f"{component['TZOFFSETTO'].to_ical()}" tzname = self._make_unique_tzname(tzname, tznames) dst[tzname], component_transitions = self._extract_offsets( diff --git a/src/icalendar/parser.py b/src/icalendar/parser.py index 5dd64c65..47f0b684 100644 --- a/src/icalendar/parser.py +++ b/src/icalendar/parser.py @@ -261,7 +261,7 @@ def from_ical(cls, st, strict=False): def escape_string(val): - # '%{:02X}'.format(i) + # f'{i:02X}' return val.replace(r'\,', '%2C').replace(r'\:', '%3A')\ .replace(r'\;', '%3B').replace(r'\\', '%5C') diff --git a/src/icalendar/tools.py b/src/icalendar/tools.py index e641e5bc..b9af20b7 100644 --- a/src/icalendar/tools.py +++ b/src/icalendar/tools.py @@ -30,6 +30,4 @@ def uid(host_name='example.com', unique=''): host_name = to_unicode(host_name) unique = unique or UIDGenerator.rnd_string() today = to_unicode(vDatetime(datetime.today()).to_ical()) - return vText('{}-{}@{}'.format(today, - unique, - host_name)) + return vText(f'{today}-{unique}@{host_name}')