khard.helpers.typing

Helper code for type annotations and runtime type conversion.

Module Contents

Classes

ObjectType

Generic enumeration.

Functions

convert_to_vcard(→ StrList)

converts user input into vcard compatible data structures

list_to_string(→ str)

converts list to string recursively so that nested lists are supported

string_to_list(→ List[str])

string_to_date(→ datetime.datetime)

Convert a date string into a date object.

Attributes

Date

StrList

class khard.helpers.typing.ObjectType

Bases: enum.Enum

Generic enumeration.

Derive from this class to define new enumerations.

str = 1
list = 2
both = 3
khard.helpers.typing.Date
khard.helpers.typing.StrList
khard.helpers.typing.convert_to_vcard(name: str, value: StrList, constraint: ObjectType) StrList

converts user input into vcard compatible data structures

Parameters
  • name – object name, only required for error messages

  • value – user input

  • constraint – set the accepted return type for vcard attribute

Returns

cleaned user input, ready for vcard or a ValueError

khard.helpers.typing.list_to_string(input: Union[str, List], delimiter: str) str

converts list to string recursively so that nested lists are supported

Parameters
  • input – a list of strings and lists of strings (and so on recursive)

  • delimiter – the deimiter to use when joining the items

Returns

the recursively joined list

khard.helpers.typing.string_to_list(input: Union[str, List[str]], delimiter: str) List[str]
khard.helpers.typing.string_to_date(string: str) datetime.datetime

Convert a date string into a date object.

Parameters

string – the date string to parse

Returns

the parsed datetime object