Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/reference/api/icalendar.cal.location.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
icalendar.cal.location module
=============================

.. automodule:: icalendar.cal.location
:ignore-module-all:
:members:
:show-inheritance:
:undoc-members:
8 changes: 8 additions & 0 deletions docs/reference/api/icalendar.cal.participant.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
icalendar.cal.participant module
================================

.. automodule:: icalendar.cal.participant
:ignore-module-all:
:members:
:show-inheritance:
:undoc-members:
8 changes: 8 additions & 0 deletions docs/reference/api/icalendar.cal.resource.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
icalendar.cal.resource module
=============================

.. automodule:: icalendar.cal.resource
:ignore-module-all:
:members:
:show-inheritance:
:undoc-members:
3 changes: 3 additions & 0 deletions docs/reference/api/icalendar.cal.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ Submodules
icalendar.cal.free_busy
icalendar.cal.journal
icalendar.cal.lazy
icalendar.cal.location
icalendar.cal.participant
icalendar.cal.resource
icalendar.cal.timezone
icalendar.cal.todo

Expand Down
1 change: 1 addition & 0 deletions news/656.feature.1
Comment thread
SashankBhamidi marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added :class:`~icalendar.cal.participant.Participant`, :class:`~icalendar.cal.location.Location`, and :class:`~icalendar.cal.resource.Resource` components from :rfc:`9073`. :user:`SashankBhamidi`
1 change: 1 addition & 0 deletions news/656.feature.2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added ORDER, SCHEMA, and DERIVED property parameters from :rfc:`9073`. :user:`SashankBhamidi`
1 change: 1 addition & 0 deletions news/656.feature.3
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added PARTICIPANT-TYPE, RESOURCE-TYPE, LOCATION-TYPE, CALENDAR-ADDRESS, STYLED-DESCRIPTION, and STRUCTURED-DATA properties from :rfc:`9073`. :user:`SashankBhamidi`
1 change: 1 addition & 0 deletions news/657.feature.1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Completed :rfc:`9074` support: added PROXIMITY enum, typed Alarm.proximity accessor, RELTYPE.SNOOZE, and registered VLOCATION inside VALARM. :user:`SashankBhamidi`
12 changes: 12 additions & 0 deletions src/icalendar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
FreeBusy,
Journal,
LazyCalendar,
Location,
Participant,
Resource,
Timezone,
TimezoneDaylight,
TimezoneStandard,
Expand All @@ -24,10 +27,13 @@
CLASS,
CUTYPE,
FBTYPE,
PARTICIPANT_TYPE,
PARTSTAT,
PROXIMITY,
RANGE,
RELATED,
RELTYPE,
RESOURCE_TYPE,
ROLE,
STATUS,
TRANSP,
Expand Down Expand Up @@ -109,10 +115,13 @@
"CLASS",
"CUTYPE",
"FBTYPE",
"PARTICIPANT_TYPE",
"PARTSTAT",
"PROXIMITY",
"RANGE",
"RELATED",
"RELTYPE",
"RESOURCE_TYPE",
"ROLE",
"STATUS",
"TRANSP",
Expand Down Expand Up @@ -145,8 +154,11 @@
"Journal",
"LazyCalendar",
"LocalTimezoneMissing",
"Location",
"NFields",
"Parameters",
"Participant",
"Resource",
"Timezone",
"TimezoneDaylight",
"TimezoneStandard",
Expand Down
9 changes: 9 additions & 0 deletions src/icalendar/alarms.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ def attachments(self) -> list[vUri | vBinary]:
"""
return self.alarm.attachments

@property
def proximity(self):
"""The type of location-based trigger for this alarm.

This delegates to :attr:`Alarm.proximity
<icalendar.cal.alarm.Alarm.proximity>`.
"""
return self.alarm.proximity

@property
def parent(self) -> Parent | None:
"""The component that contains the alarm.
Expand Down
9 changes: 5 additions & 4 deletions src/icalendar/attr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1385,17 +1385,18 @@ def _del_organizer(self: Component):
def single_string_enum_property(
name: str,
enum: type[StrEnum],
default: StrEnum | str,
default: StrEnum | str | None,
docs: str,
preserve_unknown: bool = False,
) -> property:
"""Create a property to access a single string value and convert it to an enum."""
prop = single_string_property(name, docs, default=default)
_str_default = "" if default is None else default
prop = single_string_property(name, docs, default=_str_default)

def fget(self: Component) -> StrEnum | str:
def fget(self: Component) -> StrEnum | str | None:
"""Get the value."""
value = prop.fget(self)
if value == default:
if value == _str_default:
return default
try:
return enum(str(value))
Expand Down
6 changes: 6 additions & 0 deletions src/icalendar/cal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
from .free_busy import FreeBusy
from .journal import Journal
from .lazy import LazyCalendar
from .location import Location
from .participant import Participant
from .resource import Resource
from .timezone import Timezone, TimezoneDaylight, TimezoneStandard
from .todo import Todo

Expand All @@ -28,6 +31,9 @@
"FreeBusy",
"Journal",
"LazyCalendar",
"Location",
"Participant",
"Resource",
"Timezone",
"TimezoneDaylight",
"TimezoneStandard",
Expand Down
19 changes: 19 additions & 0 deletions src/icalendar/cal/alarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from icalendar.cal.component import Component
from icalendar.cal.examples import get_example
from icalendar.enums import ACTION as AlarmAction # noqa: N811
from icalendar.enums import PROXIMITY
from icalendar.error import InvalidCalendar
from icalendar.prop import vCalAddress

Expand Down Expand Up @@ -204,6 +205,24 @@ class Alarm(Component):
""",
)

proximity = single_string_enum_property(
"PROXIMITY",
PROXIMITY,
None,
"""The type of location-based trigger for this alarm per :rfc:`9074#section-8.1`.

Although the RFC says that when this sub-component is set, a VLOCATION
sub-component MUST also be present to identify the location that
triggers the alarm, icalendar does not enforce this requirement.

Returns:
Either a :class:`~icalendar.enums.PROXIMITY` member for known values
(``ARRIVE``, ``DEPART``, ``CONNECT``, or ``DISCONNECT``), a plain
:class:`str` for unknown values, or ``None`` when absent.
""",
preserve_unknown=True,
)

TRIGGER = create_single_property(
"TRIGGER",
"dt",
Expand Down
6 changes: 6 additions & 0 deletions src/icalendar/cal/component_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
from icalendar.cal.event import Event
from icalendar.cal.free_busy import FreeBusy
from icalendar.cal.journal import Journal
from icalendar.cal.location import Location
from icalendar.cal.participant import Participant
from icalendar.cal.resource import Resource
from icalendar.cal.timezone import (
Timezone,
TimezoneDaylight,
Expand All @@ -70,6 +73,9 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
self.add_component_class(Alarm)
self.add_component_class(Available)
self.add_component_class(Availability)
self.add_component_class(Participant)
self.add_component_class(Location)
self.add_component_class(Resource)

def add_component_class(self, cls: type[Component]) -> None:
"""Add a component class to the factory.
Expand Down
21 changes: 21 additions & 0 deletions src/icalendar/cal/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,27 @@ class Event(Component):
)
ignore_exceptions = True

@property
def participants(self):
"""All PARTICIPANT sub-components of this event per :rfc:`9073#section-7.1`."""
from icalendar.cal.participant import Participant

return self.walk(Participant.name)

@property
def locations(self):
"""All VLOCATION sub-components of this event per :rfc:`9073#section-7.2`."""
from icalendar.cal.location import Location

return self.walk(Location.name)

@property
def resources(self):
"""All VRESOURCE sub-components of this event per :rfc:`9073#section-7.3`."""
from icalendar.cal.resource import Resource

return self.walk(Resource.name)

@property
def alarms(self) -> Alarms:
"""Compute the alarm times for this component.
Expand Down
21 changes: 21 additions & 0 deletions src/icalendar/cal/free_busy.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,27 @@ def new(
cls._validate_start_and_end(start, end)
return free_busy

@property
def participants(self):
"""All PARTICIPANT sub-components of this component per :rfc:`9073#section-7.1`."""
from icalendar.cal.participant import Participant

return self.walk(Participant.name)

@property
def locations(self):
"""All VLOCATION sub-components of this component per :rfc:`9073#section-7.2`."""
from icalendar.cal.location import Location

return self.walk(Location.name)

@property
def resources(self):
"""All VRESOURCE sub-components of this component per :rfc:`9073#section-7.3`."""
from icalendar.cal.resource import Resource

return self.walk(Resource.name)

@classmethod
def example(cls, name: str = "example") -> FreeBusy:
"""Return the FreeBusy example with the given name."""
Expand Down
21 changes: 21 additions & 0 deletions src/icalendar/cal/journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,27 @@ def new(

return journal

@property
def participants(self):
"""All PARTICIPANT sub-components of this journal per :rfc:`9073#section-7.1`."""
from icalendar.cal.participant import Participant

return self.walk(Participant.name)

@property
def locations(self):
"""All VLOCATION sub-components of this journal per :rfc:`9073#section-7.2`."""
from icalendar.cal.location import Location

return self.walk(Location.name)

@property
def resources(self):
"""All VRESOURCE sub-components of this journal per :rfc:`9073#section-7.3`."""
from icalendar.cal.resource import Resource

return self.walk(Resource.name)

@classmethod
def example(cls, name: str = "example") -> Journal:
"""Return the journal example with the given name."""
Expand Down
87 changes: 87 additions & 0 deletions src/icalendar/cal/location.py
Comment thread
SashankBhamidi marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
""":rfc:`9073` Location component."""

from __future__ import annotations

from typing import TYPE_CHECKING

from icalendar.attr import (
description_property,
single_string_property,
uid_property,
)
from icalendar.cal.component import Component

if TYPE_CHECKING:
from icalendar.prop import vGeo


class Location(Component):
"""A VLOCATION calendar component from :rfc:`9073#section-7.2`.

This component provides structured location information for a calendar
component.

It may appear inside :class:`~icalendar.cal.alarm.Alarm`,
:class:`~icalendar.cal.event.Event`,
:class:`~icalendar.cal.free_busy.FreeBusy`,
:class:`~icalendar.cal.journal.Journal`,
:class:`~icalendar.cal.participant.Participant`, or
:class:`~icalendar.cal.todo.Todo` per :rfc:`9074#section-8`. Multiple
instances are allowed.

Example:

.. code-block:: pycon

>>> from icalendar import Location
>>> loc = Location()
>>> loc.location_name = "Conference Room A"
>>> loc.uid = "room-a-uid@example.com"
>>> str(loc.location_name)
'Conference Room A'
"""

name = "VLOCATION"
singletons = ("NAME", "DESCRIPTION", "GEO", "LOCATION-TYPE", "UID")

location_name = single_string_property(
"NAME",
"""The display name of this location per :rfc:`7986#section-5.1`.

Returns:
The value of the NAME property when set, or the empty string when
no NAME property is set.
""",
)

description = description_property

uid = uid_property

location_type = single_string_property(
"LOCATION-TYPE",
"""The raw LOCATION-TYPE value per :rfc:`9073#section-6.1`.

The property value is a comma-separated list of location type tokens
from the IANA registry defined in :rfc:`4589#section-3`,
for example, ``"office,airport"``. This accessor returns the raw
string. Split on commas to work with individual tokens.

Returns:
The value of the LOCATION-TYPE property if set, or the empty string
when not set.
""",
)

@property
def geo(self) -> vGeo | None:
"""The geographic position of this location per :rfc:`5545#section-3.8.1.6`.

Returns:
A :class:`~icalendar.prop.geo.vGeo` instance, or ``None`` when
no GEO property is set.
"""
return self.get("GEO")


__all__ = ["Location"]
Loading