Skip to content

Commit

Permalink
Update cal.py (#481)
Browse files Browse the repository at this point in the history
* Update cal.py

* Update credits.rst pertaining to #482

* Update CHANGES.rst pertaining to #482

* Update CHANGES.rst pertaining to #481

* Update CHANGES.rst pertaining to #483

* Update CHANGES.rst

* Update credits.rst and changes.rst pertaining to #481

* Update CHANGES.rst

* Update CHANGES.rst

* Update CHANGES.rst

* Update CHANGES.rst

* Update cal.py

* Update cal.py

* Update CHANGES.rst

* Update cal.py

* Update cal.py

* Update cal.py

* Update tools.py

* Update parser.py

* Update CHANGES.rst
  • Loading branch information
pronoym99 committed Oct 31, 2022
1 parent cb2ccaa commit 7b1f376
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 20 deletions.
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, 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
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
21 changes: 7 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,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(
Expand Down
2 changes: 1 addition & 1 deletion src/icalendar/parser.py
Expand Up @@ -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')

Expand Down
4 changes: 1 addition & 3 deletions src/icalendar/tools.py
Expand Up @@ -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}')

0 comments on commit 7b1f376

Please sign in to comment.