==========
 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'none'

Setting attribute values leads to more telling titles:

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

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

    >>> pa.zip = u'12345'
    >>> pa.city = u'Dingshausen'
    >>> pa.country = germany
    >>> icemac.addressbook.interfaces.ITitle(pa)
    u'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'none'

Setting attribute values leads to more telling titles:

    >>> ea.email = u'tester@example.org'
    >>> icemac.addressbook.interfaces.ITitle(ea)
    u'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'none'

Setting attribute values leads to more telling titles:

   >>> hp.url = 'http://www.example.org'
    >>> icemac.addressbook.interfaces.ITitle(hp)
    u'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'none'

Setting attribute values leads to more telling titles:

    >>> n.number = u'+017912345678'
    >>> icemac.addressbook.interfaces.ITitle(n)
    u'+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...>

    >>> icemac.addressbook.address.prefix_to_class('postal_address')
    <class 'icemac.addressbook.address.PostalAddress'>
    >>> icemac.addressbook.address.object_to_class('asdf')
    Traceback (most recent call last):
    KeyError: 'asdf'
