Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/icalendar/param.py: 52%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

124 statements  

1"""Parameter access for icalendar. 

2 

3Related: 

4 

5- :rfc:`5545`, Section 3.2. Property Parameters 

6- :rfc:`7986`, Section 6. Property Parameters 

7- :rfc:`9253` 

8- https://github.com/collective/icalendar/issues/798 

9""" 

10 

11from __future__ import annotations 

12 

13import functools 

14from typing import TYPE_CHECKING, TypeVar 

15 

16from icalendar import enums 

17 

18if TYPE_CHECKING: 

19 from collections.abc import Callable 

20 from datetime import timedelta 

21 from enum import Enum 

22 

23 

24if TYPE_CHECKING: 

25 from icalendar.prop import VPROPERTY 

26 

27 

28def _default_return_none() -> str | None: 

29 """Return None by default.""" 

30 return None 

31 

32 

33def _default_return_string() -> str: 

34 """Return None by default.""" 

35 return "" 

36 

37 

38T = TypeVar("T") 

39 

40 

41def string_parameter( 

42 name: str, 

43 doc: str, 

44 default: Callable = _default_return_none, 

45 convert: Callable[[str], T] | None = None, 

46 convert_to: Callable[[T], str] | None = None, 

47) -> property: 

48 """Create a property for a string parameter with optional conversion. 

49 

50 This helper function is used to define properties that read from and write to 

51 ``self.params`` while optionally converting values between their stored 

52 string representation and a more convenient Python type. 

53 

54 Parameters: 

55 name: Name of the parameter in the params dictionary. 

56 doc: Documentation for the property. 

57 default: 

58 Function that returns a default value if the parameter is not found. 

59 convert: 

60 Function that converts the stored string value to the desired type. 

61 convert_to: 

62 Function to convert a value back to a string for storage. 

63 

64 Returns: 

65 A property object with a getter, setter, and deleter for the parameter. 

66 

67 Example: 

68 

69 Define a parameter that is stored as a string but used as an integer: 

70 

71 >>> from icalendar.param import string_parameter 

72 

73 >>> class Dummy: 

74 ... def __init__(self): 

75 ... self.params = {} 

76 ... 

77 >>> Dummy.priority = string_parameter( 

78 ... "PRIORITY", 

79 ... "Priority of the component", 

80 ... default=lambda: 0, 

81 ... convert=int, 

82 ... convert_to=str, 

83 ... ) 

84 >>> obj = Dummy() 

85 

86 Accessing the property converts the stored string value to the type 

87 specified by the ``convert`` parameter, in this case, an ``int``. 

88 

89 >>> obj.priority = "5" 

90 >>> obj.priority 

91 5 

92 

93 Setting the property stores the new value. 

94 

95 >>> obj.priority = 10 

96 >>> obj.priority 

97 10 

98 """ 

99 

100 if convert_to is None: 

101 convert_to = convert 

102 

103 @functools.wraps(default) 

104 def fget(self: VPROPERTY) -> str | None: 

105 value = self.params.get(name) 

106 if value is None: 

107 return default() 

108 return convert(value) if convert else value 

109 

110 def fset(self: VPROPERTY, value: str | None): 

111 if value is None: 

112 fdel(self) 

113 else: 

114 self.params[name] = convert_to(value) if convert_to else value 

115 

116 def fdel(self: VPROPERTY): 

117 self.params.pop(name, None) 

118 

119 return property(fget, fset, fdel, doc=doc) 

120 

121 

122ALTREP = string_parameter( 

123 "ALTREP", 

124 """ALTREP - Specify an alternate text representation for the property value. 

125 

126Description: 

127 This parameter specifies a URI that points to an 

128 alternate representation for a textual property value. A property 

129 specifying this parameter MUST also include a value that reflects 

130 the default representation of the text value. The URI parameter 

131 value MUST be specified in a quoted-string. 

132 

133.. note:: 

134 

135 While there is no restriction imposed on the URI schemes 

136 allowed for this parameter, Content Identifier (CID) :rfc:`2392`, 

137 HTTP :rfc:`2616`, and HTTPS :rfc:`2818` are the URI schemes most 

138 commonly used by current implementations. 

139""", 

140) 

141 

142CN = string_parameter( 

143 "CN", 

144 """Specify the common name to be associated with the calendar user specified. 

145 

146Description: 

147 This parameter can be specified on properties with a 

148 CAL-ADDRESS value type. The parameter specifies the common name 

149 to be associated with the calendar user specified by the property. 

150 The parameter value is text. The parameter value can be used for 

151 display text to be associated with the calendar address specified 

152 by the property. 

153""", 

154 default=_default_return_string, 

155) 

156 

157 

158def _default_return_individual() -> enums.CUTYPE | str: 

159 """Default value.""" 

160 return enums.CUTYPE.INDIVIDUAL 

161 

162 

163def _convert_enum(enum: type[Enum]) -> Callable[[str], Enum]: 

164 def convert(value: str) -> str: 

165 """Convert if possible.""" 

166 try: 

167 return enum(value.upper()) 

168 except ValueError: 

169 return value 

170 

171 return convert 

172 

173 

174CUTYPE = string_parameter( 

175 "CUTYPE", 

176 """Identify the type of calendar user specified by the property. 

177 

178Description: 

179 This parameter can be specified on properties with a 

180 CAL-ADDRESS value type. The parameter identifies the type of 

181 calendar user specified by the property. If not specified on a 

182 property that allows this parameter, the default is INDIVIDUAL. 

183 Applications MUST treat x-name and iana-token values they don't 

184 recognize the same way as they would the UNKNOWN value. 

185""", 

186 default=_default_return_individual, 

187 convert=_convert_enum(enums.CUTYPE), 

188) 

189 

190 

191def quoted_list_parameter(name: str, doc: str) -> property: 

192 """Return a parameter that contains a quoted list.""" 

193 

194 def fget(self: VPROPERTY) -> tuple[str]: 

195 value = self.params.get(name) 

196 if value is None: 

197 return () 

198 if isinstance(value, str): 

199 return tuple(value.split(",")) 

200 return value 

201 

202 def fset(self: VPROPERTY, value: str | tuple[str]): 

203 if value == (): 

204 fdel(self) 

205 else: 

206 self.params[name] = (value,) if isinstance(value, str) else value 

207 

208 def fdel(self: VPROPERTY): 

209 self.params.pop(name, None) 

210 

211 return property(fget, fset, fdel, doc=doc) 

212 

213 

214DELEGATED_FROM = quoted_list_parameter( 

215 "DELEGATED-FROM", 

216 """Specify the calendar users that have delegated their participation to the calendar user specified by the property. 

217 

218Description: 

219 This parameter can be specified on properties with a 

220 CAL-ADDRESS value type. This parameter specifies those calendar 

221 users that have delegated their participation in a group-scheduled 

222 event or to-do to the calendar user specified by the property. 

223 The individual calendar address parameter values MUST each be 

224 specified in a quoted-string. 

225""", # noqa: E501 

226) 

227 

228DELEGATED_TO = quoted_list_parameter( 

229 "DELEGATED-TO", 

230 """Specify the calendar users to whom the calendar user specified by the property has delegated participation. 

231 

232Description: 

233 This parameter can be specified on properties with a 

234 CAL-ADDRESS value type. This parameter specifies those calendar 

235 users whom have been delegated participation in a group-scheduled 

236 event or to-do by the calendar user specified by the property. 

237 The individual calendar address parameter values MUST each be 

238 specified in a quoted-string. 

239 """, # noqa: E501 

240) 

241 

242DIR = string_parameter( 

243 "DIR", 

244 """Specify reference to a directory entry associated with the calendar user specified by the property. 

245 

246Description: 

247 This parameter can be specified on properties with a 

248 CAL-ADDRESS value type. The parameter specifies a reference to 

249 the directory entry associated with the calendar user specified by 

250 the property. The parameter value is a URI. The URI parameter 

251 value MUST be specified in a quoted-string. 

252 

253.. note:: 

254 

255 While there is no restriction imposed on the URI schemes 

256 allowed for this parameter, CID :rfc:`2392`, DATA :rfc:`2397`, FILE 

257 :rfc:`1738`, FTP :rfc:`1738`, HTTP :rfc:`2616`, HTTPS :rfc:`2818`, LDAP 

258 :rfc:`4516`, and MID :rfc:`2392` are the URI schemes most commonly 

259 used by current implementations. 

260""", # noqa: E501 

261) 

262 

263 

264def _default_return_busy() -> enums.FBTYPE | str: 

265 """Default value.""" 

266 return enums.FBTYPE.BUSY 

267 

268 

269FBTYPE = string_parameter( 

270 "FBTYPE", 

271 """Specify the free or busy time type. 

272 

273Description: 

274 This parameter specifies the free or busy time type. 

275 The value FREE indicates that the time interval is free for 

276 scheduling. The value BUSY indicates that the time interval is 

277 busy because one or more events have been scheduled for that 

278 interval. The value BUSY-UNAVAILABLE indicates that the time 

279 interval is busy and that the interval can not be scheduled. The 

280 value BUSY-TENTATIVE indicates that the time interval is busy 

281 because one or more events have been tentatively scheduled for 

282 that interval. If not specified on a property that allows this 

283 parameter, the default is BUSY. Applications MUST treat x-name 

284 and iana-token values they don't recognize the same way as they 

285 would the BUSY value. 

286""", 

287 default=_default_return_busy, 

288 convert=_convert_enum(enums.FBTYPE), 

289) 

290 

291LANGUAGE = string_parameter( 

292 "LANGUAGE", 

293 """Specify the language for text values in a property or property parameter. 

294 

295Description: 

296 This parameter identifies the language of the text in 

297 the property value and of all property parameter values of the 

298 property. The value of the "LANGUAGE" property parameter is that 

299 defined in :rfc:`5646`. 

300 

301 For transport in a MIME entity, the Content-Language header field 

302 can be used to set the default language for the entire body part. 

303 Otherwise, no default language is assumed. 

304""", 

305) 

306 

307MEMBER = quoted_list_parameter( 

308 "MEMBER", 

309 """Specify the group or list membership of the calendar user specified by the property. 

310 

311Description: 

312 This parameter can be specified on properties with a 

313 CAL-ADDRESS value type. The parameter identifies the groups or 

314 list membership for the calendar user specified by the property. 

315 The parameter value is either a single calendar address in a 

316 quoted-string or a COMMA-separated list of calendar addresses, 

317 each in a quoted-string. The individual calendar address 

318 parameter values MUST each be specified in a quoted-string. 

319""", # noqa: E501 

320) 

321 

322 

323def _default_return_needs_action() -> enums.PARTSTAT | str: 

324 """Default value.""" 

325 return enums.PARTSTAT.NEEDS_ACTION 

326 

327 

328PARTSTAT = string_parameter( 

329 "PARTSTAT", 

330 """Specify the participation status for the calendar user specified by the property. 

331 

332Description: 

333 This parameter can be specified on properties with a 

334 CAL-ADDRESS value type. The parameter identifies the 

335 participation status for the calendar user specified by the 

336 property value. The parameter values differ depending on whether 

337 they are associated with a group-scheduled "VEVENT", "VTODO", or 

338 "VJOURNAL". The values MUST match one of the values allowed for 

339 the given calendar component. If not specified on a property that 

340 allows this parameter, the default value is NEEDS-ACTION. 

341 Applications MUST treat x-name and iana-token values they don't 

342 recognize the same way as they would the NEEDS-ACTION value. 

343""", 

344 default=_default_return_needs_action, 

345 convert=_convert_enum(enums.PARTSTAT), 

346) 

347 

348 

349def _default_range_none() -> enums.RANGE | str | None: 

350 return None 

351 

352 

353RANGE = string_parameter( 

354 "RANGE", 

355 """Specify the effective range of recurrence instances from the instance specified by the recurrence identifier specified by the property. 

356 

357Description: 

358 This parameter can be specified on a property that 

359 specifies a recurrence identifier. The parameter specifies the 

360 effective range of recurrence instances that is specified by the 

361 property. The effective range is from the recurrence identifier 

362 specified by the property. If this parameter is not specified on 

363 an allowed property, then the default range is the single instance 

364 specified by the recurrence identifier value of the property. The 

365 parameter value can only be "THISANDFUTURE" to indicate a range 

366 defined by the recurrence identifier and all subsequent instances. 

367 The value "THISANDPRIOR" is deprecated by this revision of 

368 iCalendar and MUST NOT be generated by applications. 

369""", # noqa: E501 

370 default=_default_range_none, 

371 convert=_convert_enum(enums.RANGE), 

372) 

373 

374 

375def _default_related() -> enums.RELATED | str: 

376 return enums.RELATED.START 

377 

378 

379RELATED = string_parameter( 

380 "RELATED", 

381 """Specify the relationship of the alarm trigger with respect to the start or end of the calendar component. 

382 

383Description: 

384 This parameter can be specified on properties that 

385 specify an alarm trigger with a "DURATION" value type. The 

386 parameter specifies whether the alarm will trigger relative to the 

387 start or end of the calendar component. The parameter value START 

388 will set the alarm to trigger off the start of the calendar 

389 component; the parameter value END will set the alarm to trigger 

390 off the end of the calendar component. If the parameter is not 

391 specified on an allowable property, then the default is START. 

392 

393""", # noqa: E501 

394 default=_default_related, 

395 convert=_convert_enum(enums.RELATED), 

396) 

397 

398 

399def _default_req_participant() -> enums.ROLE | str: 

400 return enums.ROLE.REQ_PARTICIPANT 

401 

402 

403ROLE = string_parameter( 

404 "ROLE", 

405 """Specify the participation role for the calendar user specified by the property. 

406 

407Description: 

408 This parameter can be specified on properties with a 

409 CAL-ADDRESS value type. The parameter specifies the participation 

410 role for the calendar user specified by the property in the group 

411 schedule calendar component. If not specified on a property that 

412 allows this parameter, the default value is REQ-PARTICIPANT. 

413 Applications MUST treat x-name and iana-token values they don't 

414 recognize the same way as they would the REQ-PARTICIPANT value. 

415""", 

416 default=_default_req_participant, 

417 convert=_convert_enum(enums.ROLE), 

418) 

419 

420 

421def boolean_parameter(name: str, default: bool, doc: str) -> property: 

422 def _default() -> bool: 

423 return default 

424 

425 return string_parameter( 

426 name, 

427 doc, 

428 default=_default, 

429 convert=lambda x: x.upper() == "TRUE", 

430 convert_to=lambda x: "TRUE" if x else "FALSE", 

431 ) 

432 

433 

434RSVP = boolean_parameter( 

435 "RSVP", 

436 False, 

437 """Specify whether there is an expectation of a favor of anreply from the calendar user specified by the property value. 

438 

439Description: 

440 This parameter can be specified on properties with a 

441 CAL-ADDRESS value type. The parameter identifies the expectation 

442 of a reply from the calendar user specified by the property value. 

443 This parameter is used by the "Organizer" to request a 

444 participation status reply from an "Attendee" of a group-scheduled 

445 event or to-do. If not specified on a property that allows this 

446 parameter, the default value is ``False``. 

447""", # noqa: E501 

448) 

449 

450SENT_BY = string_parameter( 

451 "SENT-BY", 

452 """Specify the calendar user that is acting on behalf of the calendar user specified by the property. 

453 

454Description: 

455 This parameter can be specified on properties with a 

456 CAL-ADDRESS value type. The parameter specifies the calendar user 

457 that is acting on behalf of the calendar user specified by the 

458 property. The parameter value MUST be a mailto URI as defined in 

459 :rfc:`2368`. The individual calendar address parameter values MUST 

460 each be specified in a quoted-string. 

461""", # noqa: E501 

462) 

463 

464TZID = string_parameter( 

465 "TZID", 

466 """Specify the identifier for the time zone definition for a time component in the property value. 

467 

468Description: 

469 This parameter MUST be specified on the "DTSTART", 

470 "DTEND", "DUE", "EXDATE", and "RDATE" properties when either a 

471 DATE-TIME or TIME value type is specified and when the value is 

472 neither a UTC or a "floating" time. Refer to the DATE-TIME or 

473 TIME value type definition for a description of UTC and "floating 

474 time" formats. This property parameter specifies a text value 

475 that uniquely identifies the "VTIMEZONE" calendar component to be 

476 used when evaluating the time portion of the property. The value 

477 of the "TZID" property parameter will be equal to the value of the 

478 "TZID" property for the matching time zone definition. An 

479 individual "VTIMEZONE" calendar component MUST be specified for 

480 each unique "TZID" parameter value specified in the iCalendar 

481 object. 

482 

483 The parameter MUST be specified on properties with a DATE-TIME 

484 value if the DATE-TIME is not either a UTC or a "floating" time. 

485 Failure to include and follow VTIMEZONE definitions in iCalendar 

486 objects may lead to inconsistent understanding of the local time 

487 at any given location. 

488 

489 The presence of the SOLIDUS character as a prefix, indicates that 

490 this "TZID" represents a unique ID in a globally defined time zone 

491 registry (when such registry is defined). 

492 

493.. note:: 

494 

495 This document does not define a naming convention for 

496 time zone identifiers. Implementers may want to use the naming 

497 conventions defined in existing time zone specifications such 

498 as the public-domain TZ database (TZDB). The specification of 

499 globally unique time zone identifiers is not addressed by this 

500 document and is left for future study. 

501""", # noqa: E501 

502) 

503 

504 

505def _default_return_parent() -> enums.RELTYPE: 

506 return enums.RELTYPE.PARENT 

507 

508 

509RELTYPE = string_parameter( 

510 "RELTYPE", 

511 """Specify the type of hierarchical relationship associated with a component. 

512 

513Conformance: 

514 :rfc:`5545` introduces the RELTYPE property parameter. 

515 :rfc:`9253` adds new values. 

516 

517Description: 

518 This parameter can be specified on a property that 

519 references another related calendar. The parameter specifies the 

520 hierarchical relationship type of the calendar component 

521 referenced by the property. The parameter value can be PARENT, to 

522 indicate that the referenced calendar component is a superior of 

523 calendar component; CHILD to indicate that the referenced calendar 

524 component is a subordinate of the calendar component; or SIBLING 

525 to indicate that the referenced calendar component is a peer of 

526 the calendar component. If this parameter is not specified on an 

527 allowable property, the default relationship type is PARENT. 

528 Applications MUST treat x-name and iana-token values they don't 

529 recognize the same way as they would the PARENT value. 

530""", 

531 default=_default_return_parent, 

532 convert=_convert_enum(enums.RELTYPE), 

533) 

534 

535 

536def _get_value(self: VPROPERTY) -> str: 

537 """The VALUE parameter or the default. 

538 

539 Purpose: 

540 VALUE explicitly specify the value type format for a property value. 

541 

542 Description: 

543 This parameter specifies the value type and format of 

544 the property value. The property values MUST be of a single value 

545 type. For example, a "RDATE" property cannot have a combination 

546 of DATE-TIME and TIME value types. 

547 

548 If the property's value is the default value type, then this 

549 parameter need not be specified. However, if the property's 

550 default value type is overridden by some other allowable value 

551 type, then this parameter MUST be specified. 

552 

553 Applications MUST preserve the value data for ``x-name`` and 

554 ``iana-token`` values that they don't recognize without attempting 

555 to interpret or parse the value data. 

556 

557 Returns: 

558 The VALUE parameter or the default. 

559 

560 Examples: 

561 The VALUE defaults to the name of the property. 

562 Note that it is case-insensitive but always uppercase. 

563 

564 .. code-block:: pycon 

565 

566 >>> from icalendar import vBoolean 

567 >>> b = vBoolean(True) 

568 >>> b.VALUE 

569 'BOOLEAN' 

570 

571 Setting the VALUE parameter of a typed property usually does not make sense. 

572 For convenience, using this property, the value will be converted to 

573 an uppercase string. 

574 If you have some custom property, you might use it like this: 

575 

576 .. code-block:: pycon 

577 

578 >>> from icalendar import vUnknown, Event 

579 >>> v = vUnknown("Some property text.") 

580 >>> v.VALUE = "x-type" # lower case 

581 >>> v.VALUE 

582 'X-TYPE' 

583 >>> event = Event() 

584 >>> event.add("x-prop", v) 

585 >>> print(event.to_ical()) 

586 BEGIN:VEVENT 

587 X-PROP;VALUE=X-TYPE:Some property text. 

588 END:VEVENT 

589 

590 """ 

591 value = self.params.value 

592 if value is None: 

593 _get_default_value = getattr(self, "_get_value", None) 

594 if _get_default_value is not None: 

595 value = _get_default_value() 

596 return self.default_value if value is None else value 

597 

598 

599def _set_value(self: VPROPERTY, value: str | None): 

600 """Set the VALUE parameter.""" 

601 self.params.value = value 

602 

603 

604def _del_value(self: VPROPERTY): 

605 """Delete the VALUE parameter.""" 

606 del self.params.value 

607 

608 

609VALUE = property(_get_value, _set_value, _del_value) 

610 

611LABEL = string_parameter( 

612 "LABEL", 

613 """LABEL provides a human-readable label. 

614 

615Conformance: 

616 This property parameter is specified in :rfc:`7986`, 

617 iCalendar Property Extensions. 

618 

619 :rfc:`9253` makes use of this for the LINK property. 

620 This parameter maps to the "title" 

621 attribute defined in Section 3.4.1 of :rfc:`8288`. 

622 LABEL is used to label the destination 

623 of a link such that it can be used as a human-readable identifier 

624 (e.g., a menu entry) in the language indicated by the LANGUAGE 

625 (if present). The LABEL MUST NOT 

626 appear more than once in a given link; occurrences after the first 

627 MUST be ignored by parsers. 

628 

629Description: 

630 This property parameter MAY be specified on the 

631 "CONFERENCE" property. It is anticipated that other extensions to 

632 iCalendar will reuse this property parameter on new properties 

633 that they define. As a result, clients MUST expect to find this 

634 property parameter present on many different properties. It 

635 provides a human-readable label that can be presented to calendar 

636 users to allow them to discriminate between properties that might 

637 be similar or provide additional information for properties that 

638 are not self-describing. The "LANGUAGE" property parameter can be 

639 used to specify the language of the text in the parameter value 

640 (as per Section 3.2.10 of :rfc:`5545`). 

641 

642Examples: 

643 This is a label of a chat. 

644 

645 .. code-block:: ics 

646 

647 CONFERENCE;VALUE=URI;FEATURE=VIDEO; 

648 LABEL="Web video chat, access code=76543"; 

649 :https://video-chat.example.com/;group-id=1234 

650 

651""", 

652) 

653 

654FMTTYPE = string_parameter( 

655 "FMTTYPE", 

656 """FMTTYPE specfies the content type of a referenced object. 

657 

658Conformance: 

659 :rfc:`5545` specifies the FMTTYPE. 

660 :rfc:`9253` adds FMTTYPE to LINK properties. In a LINK, 

661 FMTTYPE maps to the "type" 

662 attribute defined in Section 3.4.1 of :rfc:`8288`. 

663 See :rfc:`6838`. 

664 

665Description: 

666 This parameter can be specified on properties that are 

667 used to reference an object. The parameter specifies the media 

668 type :rfc:`4288` of the referenced object. For example, on the 

669 "ATTACH" property, an FTP type URI value does not, by itself, 

670 necessarily convey the type of content associated with the 

671 resource. The parameter value MUST be the text for either an 

672 IANA-registered media type or a non-standard media type. 

673 

674Example: 

675 A Microsoft Word document: 

676 

677 .. code-block:: ics 

678 

679 ATTACH;FMTTYPE=application/msword:ftp://example.com/pub/docs/ 

680 agenda.doc 

681 

682 A website: 

683 

684 .. code-block:: ics 

685 

686 LINK;FMTTYPE=text/html;LINKREL=SOURCE;LABEL=Venue;VALUE=URI: 

687 https://example.com/venue 

688 

689 """, 

690) 

691 

692LINKREL = string_parameter( 

693 "LINKREL", 

694 """LINKREL 

695 

696Purpose: 

697 LINKREL specifies the relationship of data referenced 

698 by a LINK property. 

699 

700Conformance: 

701 LINKREL is specified in :rfc:`9253`. 

702 This parameter maps to the link relation type defined in 

703 Section 2.1 of :rfc:`8288`. 

704 It is always quoted. 

705 

706Description: 

707 This parameter MUST be specified on all LINK properties and define 

708 the type of reference. 

709 This allows programs consuming this data to automatically scan 

710 for references they support. 

711 There is no default relation type. Any link relation in the 

712 link registry established by :rfc:`8288`, or new link relations, 

713 may be used. 

714 It is expected that link relation types seeing significant usage 

715 in calendaring will have the calendaring usage described in an RFC. 

716 

717 In the simplest case, a link relation type identifies the semantics 

718 of a link. For example, a link with the relation type "copyright" 

719 indicates that the current link context has a copyright resource at 

720 the link target. 

721 

722 Link relation types can also be used to indicate that the target 

723 resource has particular attributes, or exhibits particular 

724 behaviours; for example, a "service" link implies that the link 

725 target can be used as part of a defined protocol (in this case, a 

726 service description). 

727 

728Registration: 

729 There are two kinds of relation types: registered and extension. 

730 These relation types are registered in :rfc:`8288`. 

731 

732.. seealso:: 

733 

734 `Registered Link Relation Types 

735 <https://www.iana.org/assignments/link-relations/link-relations.xhtml>`_. 

736 

737 

738Examples: 

739 This identifies the latest version of the event information. 

740 

741 .. code-block:: ics 

742 

743 LINKREL=latest-version 

744 

745""", 

746) 

747 

748 

749def _get_GAP(prop) -> timedelta | None: # noqa: N802 

750 """GAP 

751 

752 Purpose: 

753 GAP specifies the length of the gap, positive or negative, 

754 between two components with a temporal relationship. 

755 

756 Format Definition: 

757 Same as the DURATION value type defined in :rfc:`5545`, Section 3.3.6. 

758 

759 Description: 

760 This parameter MAY be specified on the RELATED-TO property and defines 

761 the duration of time between the predecessor and successor in an interval. 

762 When positive, it defines the lag time between a task and its logical successor. 

763 When negative, it defines the lead time. 

764 

765 Examples: 

766 An example of lag time might be if Task-A is "paint the room" and Task-B is 

767 "lay the carpets". Then, Task-A may be related to Task-B with 

768 RELTYPE=FINISHTOSTART with a gap of 1 day -- long enough for the paint to dry. 

769 

770 .. code-block:: text 

771 

772 ==================== 

773 | paint the room |--+ 

774 ==================== | 

775 |(lag of one day) 

776 | 

777 | =================== 

778 +->| lay the carpet | 

779 =================== 

780 

781 For an example of lead time, in constructing a two-story building, 

782 the electrical work must be done before painting. However, 

783 the painter can move in to the first floor as the electricians move upstairs. 

784 

785 .. code-block:: text 

786 

787 ===================== 

788 | electrical work |--+ 

789 ===================== | 

790 +-------------+ 

791 |(lead of estimated time) 

792 | ================== 

793 +->| painting | 

794 ================== 

795 """ 

796 value = prop.params.get("GAP") 

797 if value is None: 

798 return None 

799 from icalendar.prop import vDuration 

800 

801 if isinstance(value, str): 

802 return vDuration.from_ical(value) 

803 if not isinstance(value, vDuration): 

804 raise TypeError("Value MUST be a vDuration instance") 

805 return value.td 

806 

807 

808def _set_GAP(prop, value: timedelta | str | None): # noqa: N802 

809 """Set the GAP parameter as a timedelta.""" 

810 if value is None: 

811 prop.params.pop("GAP", None) 

812 return 

813 from icalendar.prop import vDuration 

814 

815 prop.params["GAP"] = vDuration(value) 

816 

817 

818def _del_GAP(prop): # noqa: N802 

819 """Delete the GAP parameter.""" 

820 prop.params.pop("GAP", None) 

821 

822 

823GAP = property(_get_GAP, _set_GAP, _del_GAP) 

824 

825__all__ = [ 

826 "ALTREP", 

827 "CN", 

828 "CUTYPE", 

829 "DELEGATED_FROM", 

830 "DELEGATED_TO", 

831 "DIR", 

832 "FBTYPE", 

833 "FMTTYPE", 

834 "GAP", 

835 "LABEL", 

836 "LANGUAGE", 

837 "LINKREL", 

838 "MEMBER", 

839 "PARTSTAT", 

840 "RANGE", 

841 "RELATED", 

842 "ROLE", 

843 "RSVP", 

844 "SENT_BY", 

845 "TZID", 

846 "VALUE", 

847 "quoted_list_parameter", 

848 "string_parameter", 

849]