icalendar.caselessdict module#
- class icalendar.caselessdict.CaselessDict(*args, **kwargs)[source]#
Bases:
OrderedDictA case-insensitive dictionary that uses strings as keys.
All keys are stored in uppercase internally, but values retain their original case. Keys can be provided as
strorbytes. They are converted to Unicode viato_unicode(), then uppercased before storage.- Parameters:
*args (
Any) – Positional arguments passed toOrderedDict.**kwargs (
Any) – Keyword arguments passed toOrderedDict.
Example
Create a new
CaselessDictand normalize existing keys to uppercase.>>> from icalendar.caselessdict import CaselessDict >>> d = CaselessDict(summary="Meeting") >>> d["SUMMARY"] 'Meeting' >>> "summary" in d True
- canonical_order = None#
- copy()[source]#
Return a shallow copy of the dictionary.
- Return type:
Self- Returns:
A new instance of the same type with the same contents.
- has_key(key)[source]#
Check whether a key exists, case-insensitively.
This is a legacy method. Use
key in dictinstead.
- setdefault(key, value=None)[source]#
Create the (key, value) pair, optionally with a
value.Once set, to change default value use
update().
- sorted_items()[source]#
Sort items according to the canonical order for this class.
Items whose keys are listed in
canonical_orderappear first in that order. Remaining items appear alphabetically by key.
- sorted_keys()[source]#
Sort keys according to the canonical order for this class.
Keys listed in
canonical_orderappear first in that order. Remaining keys appear alphabetically at the end.
- icalendar.caselessdict.canonsort_items(dict1, canonical_order=None)[source]#
Sort items from a mapping according to a canonical key order.
- Parameters:
- Return type:
- Returns:
A list of
(key, value)tuples sorted by canonical order.
Example
>>> from icalendar.caselessdict import canonsort_items >>> canonsort_items({"C": 3, "A": 1, "B": 2}, ["B", "C"]) [('B', 2), ('C', 3), ('A', 1)]
- icalendar.caselessdict.canonsort_keys(keys, canonical_order=None)[source]#
Sort leading keys according to a canonical order.
Keys specified in
canonical_orderappear first in that order. Remaining keys appear alphabetically at the end.- Parameters:
- Return type:
- Returns:
A new list of keys sorted by canonical order first, then alphabetically.
Example
>>> from icalendar.caselessdict import canonsort_keys >>> canonsort_keys(["C", "A", "B"], ["B", "C"]) ['B', 'C', 'A']