Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update cal.py #481

Merged
merged 22 commits into from Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions CHANGES.rst
Expand Up @@ -6,8 +6,7 @@ Changelog

Minor changes:

- Refactored prop.py. Ref: #482 [pronoym99]

- Refactored cal.py. Ref: #481 [pronoym99]
- Calendar.from_ical no longer throws long errors
Ref: #473
Fixes: #472
Expand Down
1 change: 1 addition & 0 deletions docs/credits.rst
Expand Up @@ -64,6 +64,7 @@ icalendar contributors
- Mauro Amico <mauro.amico@gmail.com>
- Alexander Pitkin <peleccom@gmail.com>
- Michał Górny <mgorny@gentoo.org>
- Pronoy <lukex9442@gmail.com>

Find out who contributed::

Expand Down
19 changes: 5 additions & 14 deletions src/icalendar/cal.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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 ''})"


#######################################
Expand Down Expand Up @@ -612,12 +607,8 @@ 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')}_{component['TZOFFSETFROM'].to_ical()}_{component['TZOFFSETTO'].to_ical()}"
pronoym99 marked this conversation as resolved.
Show resolved Hide resolved
tzname = self._make_unique_tzname(tzname, tznames)

dst[tzname], component_transitions = self._extract_offsets(
Expand Down