khard.helpers.typing
====================

.. py:module:: khard.helpers.typing

.. autoapi-nested-parse::

   Helper code for type annotations and runtime type conversion.



Attributes
----------

.. autoapisummary::

   khard.helpers.typing.Date
   khard.helpers.typing.StrList
   khard.helpers.typing.PostAddress


Classes
-------

.. autoapisummary::

   khard.helpers.typing.ObjectType


Functions
---------

.. autoapisummary::

   khard.helpers.typing.convert_to_vcard
   khard.helpers.typing.list_to_string
   khard.helpers.typing.string_to_list
   khard.helpers.typing.string_to_date


Module Contents
---------------

.. py:class:: ObjectType(*args, **kwds)

   Bases: :py:obj:`enum.Enum`


   Create a collection of name/value pairs.

   Example enumeration:

   >>> class Color(Enum):
   ...     RED = 1
   ...     BLUE = 2
   ...     GREEN = 3

   Access them by:

   - attribute access:

     >>> Color.RED
     <Color.RED: 1>

   - value lookup:

     >>> Color(1)
     <Color.RED: 1>

   - name lookup:

     >>> Color['RED']
     <Color.RED: 1>

   Enumerations can be iterated over, and know how many members they have:

   >>> len(Color)
   3

   >>> list(Color)
   [<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

   Methods can be added to enumerations, and members can have their own
   attributes -- see the documentation for details.


   .. py:attribute:: str
      :value: 1



   .. py:attribute:: list
      :value: 2



   .. py:attribute:: both
      :value: 3



.. py:data:: Date

.. py:data:: StrList

.. py:data:: PostAddress

.. py:function:: convert_to_vcard(name: str, value: StrList, constraint: ObjectType) -> StrList

   converts user input into vCard compatible data structures

   :param name: object name, only required for error messages
   :param value: user input
   :param constraint: set the accepted return type for vCard attribute
   :returns: cleaned user input, ready for vCard or a ValueError


.. py:function:: list_to_string(input: Union[str, List], delimiter: str) -> str

   converts list to string recursively so that nested lists are supported

   :param input: a list of strings and lists of strings (and so on recursive)
   :param delimiter: the delimiter to use when joining the items
   :returns: the recursively joined list


.. py:function:: string_to_list(input: Union[str, List[str]], delimiter: str) -> List[str]

.. py:function:: string_to_date(string: str) -> datetime.datetime

   Convert a date string into a date object.

   :param string: the date string to parse
   :returns: the parsed datetime object


