==========
 Adresses
==========

There are several kinds of address types having constraints and titles.

Constraints
===========

The constraints ensure valid values for some address fields.

E-mail address
--------------

    >>> import icemac.addressbook.address
    >>> e = icemac.addressbook.address.EMailAddress()

Some failing examples first:

    >>> e.email = u'asdfg'
    Traceback (most recent call last):
    ConstraintNotSatisfied: asdfg
    >>> e.email = u'ich@'
    Traceback (most recent call last):
    ConstraintNotSatisfied: ich@
    >>> e.email = u'ich@goo@le.de'
    Traceback (most recent call last):
    ConstraintNotSatisfied: ich@goo@le.de
    >>> e.email = u'ich@local'
    Traceback (most recent call last):
    ConstraintNotSatisfied: ich@local
    >>> e.email = u'ich@local..de'
    Traceback (most recent call last):
    ConstraintNotSatisfied: ich@local..de
    >>> e.email = u'ich@local.de.'
    Traceback (most recent call last):
    ConstraintNotSatisfied: ich@local.de.

Now some working examples:

    >>> e.email = u'ich@example.org'
    >>> e.email = u'ich+du@example.org'
    >>> e.email = u'ich=du@example.org'
    >>> e.email = u'ich_du@example.org'
    >>> e.email = u'ich-du@example.org'
    >>> e.email = u'ich+du@a.b.c.d.example.org'
    >>> e.email = u'ich+du@example.museum'
    >>> e.email = u'ich@ex-ample.de'
    >>> e.email = u'ich@ex_ample.de'

Home page address
-----------------

    >>> a = icemac.addressbook.address.HomePageAddress()

Some failing examples first:

    >>> a.url = 'asdfg'
    Traceback (most recent call last):
    InvalidURI: asdfg
    >>> a.url = 'www.example.com'
    Traceback (most recent call last):
    InvalidURI: www.example.com


Now some working examples:

    >>> a.url = 'http://www.example.org'
    >>> a.url = 'http://www2.example.org'
    >>> a.url = 'http://a.b.c.d.example.org'
    >>> a.url = 'http://example.museum'


Titles
======

Each address type has a title adapter. Depending on the values set on
the address the computed title differs.


Postal address
--------------

    >>> import icemac.addressbook.interfaces
    >>> pa = icemac.addressbook.address.PostalAddress()

Germany is the default country, we like to reset it to get a really
empty address:

    >>> germany = pa.country
    >>> pa.country = None
    >>> icemac.addressbook.interfaces.ITitle(pa)
    u'unknown'

Setting attribute values leads to more telling titles:

    >>> pa.kind = 'private'
    >>> icemac.addressbook.interfaces.ITitle(pa)
    u'private'

    >>> pa.street = u'Papa street 3 a'
    >>> icemac.addressbook.interfaces.ITitle(pa)
    u'private: Papa street 3 a'

    >>> pa.address_prefix = u'c/o Mama'
    >>> icemac.addressbook.interfaces.ITitle(pa)
    u'private: c/o Mama, Papa street 3 a'

    >>> pa.zip = u'12345'
    >>> pa.city = u'Dingshausen'
    >>> pa.country = germany
    >>> icemac.addressbook.interfaces.ITitle(pa)
    u'private: c/o Mama, Papa street 3 a, 12345, Dingshausen, Germany'

E-mail address
--------------

    >>> ea = icemac.addressbook.address.EMailAddress()

The title of an empy e-mail address is a bit untelling:

    >>> icemac.addressbook.interfaces.ITitle(ea)
    u'unknown'

Setting attribute values leads to more telling titles:

    >>> ea.kind = 'work'
    >>> icemac.addressbook.interfaces.ITitle(ea)
    u'work'

    >>> ea.email = u'tester@example.org'
    >>> icemac.addressbook.interfaces.ITitle(ea)
    u'work: tester@example.org'

Home page address
-----------------

    >>> hp = icemac.addressbook.address.HomePageAddress()

The title of an empy home page address is a bit untelling:

    >>> icemac.addressbook.interfaces.ITitle(hp)
    u'unknown'

Setting attribute values leads to more telling titles:

    >>> hp.kind = 'other'
    >>> icemac.addressbook.interfaces.ITitle(hp)
    u'other'

    >>> hp.url = 'http://www.example.org'
    >>> icemac.addressbook.interfaces.ITitle(hp)
    u'other: http://www.example.org'

Phone number
------------

    >>> n = icemac.addressbook.address.PhoneNumber()

The title of an empy phone number is a bit untelling:

    >>> icemac.addressbook.interfaces.ITitle(n)
    u'unknown'

Setting attribute values leads to more telling titles:

    >>> n.kind = 'cell phone'
    >>> icemac.addressbook.interfaces.ITitle(n)
    u'cell phone'

    >>> n.number = u'+017912345678'
    >>> icemac.addressbook.interfaces.ITitle(n)
    u'cell phone: +017912345678'


Helper functions
================

There are some helper funtions to convert interfaces, prefixes,
classes and titles around addresses:

    >>> icemac.addressbook.address.object_to_prefix(
    ...     icemac.addressbook.address.PostalAddress())
    'postal_address'
    >>> icemac.addressbook.address.object_to_prefix(object())
    Traceback (most recent call last):
    KeyError: <object object at 0x...>

    >>> icemac.addressbook.address.object_to_title(
    ...     icemac.addressbook.address.PhoneNumber())
    u'phone number'
    >>> icemac.addressbook.address.object_to_title(object())
    Traceback (most recent call last):
    KeyError: <object object at 0x...>

    >>> icemac.addressbook.address.object_to_class(
    ...     icemac.addressbook.address.EMailAddress())
    <class 'icemac.addressbook.address.EMailAddress'>
    >>> icemac.addressbook.address.object_to_class(object())
    Traceback (most recent call last):
    KeyError: <object object at 0...>
