Skip to content

Commit

Permalink
Merge branch 'master' into refactor_test_unicode_params
Browse files Browse the repository at this point in the history
  • Loading branch information
jacadzaca committed Oct 29, 2022
2 parents 9044270 + 2c93383 commit 8966432
Show file tree
Hide file tree
Showing 14 changed files with 230 additions and 117 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Output:
```

## Expected behavior**
## Expected behavior
<!-- A clear and concise description of what you expected to happen. -->

## Environment
Expand Down
26 changes: 23 additions & 3 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
Changelog
=========

5.0.1 (unreleased)
5.0.2 (unreleased)
------------------

Minor changes:

- fixed setuptools deprecation warnings [mgorny]
- Calendar.from_ical no longer throws long errors
Ref: #473
Fixes: #472
[jacadzaca]

Breaking changes:

Expand All @@ -18,7 +21,24 @@ New features:

Bug fixes:

- ...
- broken properties are not added to the parent component
Ref: #471
Fixes: #464
[jacadzaca]

5.0.1 (2022-10-22)
------------------

Minor changes:

- fixed setuptools deprecation warnings [mgorny]

Bug fixes:

- a well-known timezone timezone prefixed with a `/` is treated as if the slash wasn't present
Ref: #467
Fixes: #466
[jacadzaca]

5.0.0 (2022-10-17)
------------------
Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ ignore =

[zest.releaser]
python-file-with-version = src/icalendar/__init__.py
create-wheel = yes

[bdist_wheel]
universal = 1
universal = 0

[metadata]
license_files = LICENSE.rst
Expand Down
2 changes: 1 addition & 1 deletion src/icalendar/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '5.0.0'
__version__ = '5.0.1'

from icalendar.cal import (
Calendar,
Expand Down
19 changes: 13 additions & 6 deletions src/icalendar/cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,22 +383,29 @@ def from_ical(cls, st, multiple=False):
if not component.ignore_exceptions:
raise
component.errors.append((uname, str(e)))
component.add(name, None, encode=0)
else:
vals.params = params
component.add(name, vals, encode=0)

if multiple:
return comps
if len(comps) > 1:
raise ValueError(f'Found multiple components where '
f'only one is allowed: {st!r}')
raise ValueError(cls._format_error(
'Found multiple components where only one is allowed', st))
if len(comps) < 1:
raise ValueError(f'Found no components where '
f'exactly one is required: '
f'{st!r}')
raise ValueError(cls._format_error(
'Found no components where exactly one is required', st))
return comps[0]

def _format_error(error_description, bad_input, elipsis='[...]'):
# there's three character more in the error, ie. ' ' x2 and a ':'
max_error_length = 100 - 3
if len(error_description) + len(bad_input) + len(elipsis) > max_error_length:
truncate_to = max_error_length - len(error_description) - len(elipsis)
return f'{error_description}: {bad_input[:truncate_to]} {elipsis}'
else:
return f'{error_description}: {bad_input}'

def content_line(self, name, value, sorted=True):
"""Returns property as content line.
"""
Expand Down
4 changes: 2 additions & 2 deletions src/icalendar/prop.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,10 @@ def from_ical(ical, timezone=None):
tzinfo = None
if timezone:
try:
tzinfo = pytz.timezone(timezone)
tzinfo = pytz.timezone(timezone.strip('/'))
except pytz.UnknownTimeZoneError:
if timezone in WINDOWS_TO_OLSON:
tzinfo = pytz.timezone(WINDOWS_TO_OLSON.get(timezone))
tzinfo = pytz.timezone(WINDOWS_TO_OLSON.get(timezone.strip('/')))
else:
tzinfo = _timezone_cache.get(timezone, None)

Expand Down
41 changes: 41 additions & 0 deletions src/icalendar/tests/calendars/big_bad_calendar.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
BEGIN:VCALENDAR
BEGIN:VEVENT
END:VEVENT
BEGIN:VEVENT
END:VEVENT
BEGIN:VEVENT
END:VEVENT
BEGIN:VEVENT
END:VEVENT
BEGIN:VEVENT
END:VEVENT
BEGIN:VEVENT
END:VEVENT
BEGIN:VEVENT
END:VEVENT
BEGIN:VEVENT
END:VEVENT
BEGIN:VEVENT
END:VEVENT
BEGIN:VEVENT
END:VEVENT
BEGIN:VEVENT
END:VEVENT
BEGIN:VEVENT
END:VEVENT
BEGIN:VEVENT
END:VEVENT
BEGIN:VEVENT
END:VEVENT
BEGIN:VEVENT
END:VEVENT
BEGIN:VEVENT
END:VEVENT
BEGIN:VEVENT
END:VEVENT
BEGIN:VEVENT
END:VEVENT
BEGIN:VEVENT
END:VEVENT
BEGIN:VEVENT
END:VEVENT
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
BEGIN:VCALENDAR
BEGIN:VEVENT
UID:0cab49a0-1167-40f0-bfed-ecb4d117047d
DTSTAMP:20221019T102950Z
DTSTART;TZID=/Europe/Stockholm:20221021T200000
DTEND;TZID=/Europe/Stockholm:20221021T210000
SUMMARY:Just chatting
DESCRIPTION:Just Chatting.
CATEGORIES:Just Chatting
RRULE:FREQ=WEEKLY;BYDAY=FR
END:VEVENT
END:VCALENDAR
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
BEGIN:VCALENDAR
BEGIN:VTIMEZONE
TZID:/Europe/CUSTOM
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
TZNAME:CEST
DTSTART:19700329T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
TZNAME:CET
DTSTART:19701025T030000
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
UID:0cab49a0-1167-40f0-bfed-ecb4d117047d
DTSTAMP:20221019T102950Z
DTSTART;TZID=/Europe/CUSTOM:20221021T200000
DTEND;TZID=/Europe/CUSTOM:20221021T210000
SUMMARY:Just chatting
DESCRIPTION:Just Chatting.
CATEGORIES:Just Chatting
RRULE:FREQ=WEEKLY;BYDAY=FR
END:VEVENT
END:VCALENDAR
3 changes: 3 additions & 0 deletions src/icalendar/tests/calendars/small_bad_calendar.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BEGIN:VCALENDAR
BEGIN:VEVENT
END:VEVENT
7 changes: 7 additions & 0 deletions src/icalendar/tests/events/issue_464_invalid_rdate.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
BEGIN:VEVENT
SUMMARY:RDATE period
DTSTART:19961230T020000Z
DTEND:19961230T060000Z
UID:rdate_period
RDATE;VALUE=PERIOD:19970101T180000Z/19970102T070000Z,199709T180000Z/PT5H30M
END:VEVENT
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,22 @@ def test_dont_ignore_exceptions_on_broken_calendars_issue_104(calendars):
'''
with pytest.raises(ValueError):
calendars.issue_104_broken_calendar

def test_rdate_dosent_become_none_on_invalid_input_issue_464(events):
'''Issue #464 - [BUG] RDATE can become None if value is invalid
https://github.com/collective/icalendar/issues/464
'''
assert events.issue_464_invalid_rdate.is_broken
assert ('RDATE', 'Expected period format, got: 199709T180000Z/PT5H30M') in events.issue_464_invalid_rdate.errors
assert not b'RDATE:None' in events.issue_464_invalid_rdate.to_ical()

@pytest.mark.parametrize('calendar_name', [
'big_bad_calendar',
'small_bad_calendar',
'multiple_calendar_components',
])
def test_error_message_doesnt_get_too_big(calendars, calendar_name):
with pytest.raises(ValueError) as exception:
calendars[calendar_name]
assert len(str(exception).split(': ')[1]) <= 100

14 changes: 14 additions & 0 deletions src/icalendar/tests/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,17 @@ def test_creates_event_with_base64_encoded_attachment_issue_82(events):
event = Event()
event.add('ATTACH', b)
assert event.to_ical() == events.issue_82_expected_output.raw_ics

@pytest.mark.parametrize('calendar_name', [
# Issue #466 - [BUG] TZID timezone is ignored when forward-slash is used
# https://github.com/collective/icalendar/issues/466
'issue_466_respect_unique_timezone',
'issue_466_convert_tzid_with_slash'
])
def test_handles_unique_tzid(calendars, in_timezone, calendar_name):
calendar = calendars[calendar_name]
start_dt = calendar.walk('VEVENT')[0]['dtstart'].dt
end_dt = calendar.walk('VEVENT')[0]['dtend'].dt
assert start_dt == in_timezone(datetime(2022, 10, 21, 20, 0, 0), 'Europe/Stockholm')
assert end_dt == in_timezone(datetime(2022, 10, 21, 21, 0, 0), 'Europe/Stockholm')

Loading

0 comments on commit 8966432

Please sign in to comment.