Configuration#

Configuration types for anonymization.

class icalendar_anonymizer._config.AnonymizeMode(*values)[source]#

Bases: StrEnum

Anonymization mode for a configurable field.

KEEP = 'keep'#
RANDOMIZE = 'randomize'#
REMOVE = 'remove'#
REPLACE = 'replace'#
icalendar_anonymizer._config.CONFIGURABLE_FIELDS = frozenset({'ATTENDEE', 'CATEGORIES', 'COMMENT', 'CONTACT', 'DESCRIPTION', 'LOCATION', 'ORGANIZER', 'RESOURCES', 'SUMMARY', 'UID'})#

Set of field names that can be configured with field_modes parameter.

Contains 10 fields: SUMMARY, DESCRIPTION, LOCATION, COMMENT, CONTACT, RESOURCES, CATEGORIES, ATTENDEE, ORGANIZER, and UID.

icalendar_anonymizer._config.DEFAULT_PLACEHOLDERS = {'ATTENDEE': 'mailto:redacted@example.local', 'CATEGORIES': 'REDACTED', 'COMMENT': '[Comment removed]', 'CONTACT': '[Contact removed]', 'DESCRIPTION': '[Content removed]', 'LOCATION': '[Location removed]', 'ORGANIZER': 'mailto:redacted@example.local', 'RESOURCES': '[Resources removed]', 'SUMMARY': '[Redacted]'}#

Default placeholder values used in REPLACE mode.

Maps field names to their placeholder strings. UID uses a counter for uniqueness: redacted-1@anonymous.local, redacted-2@anonymous.local, etc.

icalendar_anonymizer._config.validate_field_modes(field_modes: dict[str, str] | None) → dict[str, AnonymizeMode] | None[source]#

Validate and normalize field_modes dict.

Parameters:

field_modes – Dict mapping field name to mode string

Returns:

Normalized dict with uppercase keys and AnonymizeMode values

Raises:
  • ValueError – If invalid field name, invalid mode, or UID set to remove

  • TypeError – If field_modes is not a dict or None

icalendar_anonymizer._config.validate_field_modes_against(field_modes: dict[str, str] | None, allowed_fields: frozenset[str], forbid_remove_fields: frozenset[str] = frozenset({})) → dict[str, AnonymizeMode] | None[source]#

Validate and normalize a field_modes dict against a given field vocabulary.

Shared by validate_field_modes (iCalendar fields) and JSCalendar’s own field-mode validator, since the normalization algorithm is the same, only the allowed field names differ.

Parameters:
  • field_modes – Dict mapping field name to mode string

  • allowed_fields – Set of valid field names (uppercase)

  • forbid_remove_fields – Fields that cannot use REMOVE mode

Returns:

Normalized dict with uppercase keys and AnonymizeMode values

Raises:
  • ValueError – If invalid field name, invalid mode, or a forbidden field/mode combination

  • TypeError – If field_modes is not a dict or None

Usage#

from icalendar_anonymizer import AnonymizeMode, CONFIGURABLE_FIELDS

print(sorted(CONFIGURABLE_FIELDS))
# ['ATTENDEE', 'CATEGORIES', 'COMMENT', 'CONTACT', 'DESCRIPTION',
#  'LOCATION', 'ORGANIZER', 'RESOURCES', 'SUMMARY', 'UID']

print(list(AnonymizeMode))
# [<AnonymizeMode.KEEP: 'keep'>, <AnonymizeMode.REMOVE: 'remove'>,
#  <AnonymizeMode.RANDOMIZE: 'randomize'>, <AnonymizeMode.REPLACE: 'replace'>]

AnonymizeMode is a StrEnum, so its members compare equal to the plain strings field_modes already accepts: AnonymizeMode.KEEP == "keep". See Python API for field_modes in context.