snf_django: Handle unicode errors in JSON bodies

Catch unicode errors when doing JSON de-serialization of the body of a request.
Also, rename 'get_request_dict' function to 'get_json_body', as it is a
more representative name for what the function is doing.
snf_django: Explicitly set encoding of requests

Explicitly set the request encoding to UTF-8 instead of relying to
the DEFAULT_CHARSET setting. See:
https://docs.djangoproject.com/en/1.4/ref/unicode/#form-submission
cyclades: Remove use of the 'uenc' and 'udec'

Replace use of 'uenc' and 'udec' functions from 'synnefo.util.text'
module with the 'smart_decode' and 'smart_unicode' functions from
'django.utils.encoding' module.

The uenc/udec functions depend on the locale category LC_CTYPE, which is not
appropriate for the Synenefo API. We explicitly use the
smart_unicode/smart_str functions to decode to unicode and encode to
bytestring objects, always using the utf-8 encoding.
cyclades: Make all DB models return unicode repr

Add __str__ method to all DB models, that simply calls __unicode__
method. Because __str__ will return a unicode string it will be ignored,
and the result from __unicode__ will be used. Also, make all __unicode__
methods to return unicode strings.
plankton: Fix handling of HTTP headers

Improve the handling of all the image parameters that are
requested/returned as HTTP headers. All parameters must be 'utf-8'
encoded. User provided values like the image name and image properties
must also be properly quoted. Lower all image properties(HTTP header
keys) and replace all punctuation characters with underscore.

Finally, add section in the image API guide, explaining the required
format for the image metadata.
snf_django: Add functions to handle unicodes

Add helper functions to handle unicode objects from 'snf-manage' using
the user's preferred encoding. Also add a 'safe_string' function to
escape control characters from strings and unicode objects.
snf_django: Handle unicodes in SynnefoCommand

Extend the SynnefoCommand to override the 'run_from_argv' function in
order to decode command line arguments and options, using the user's
preferred encoding.

Some options of snf-manage commands may be list or tuples. Applying
'smart_unicode' to them will convert them to unicode object. Instead
of recursively converting data, we convert the arguments to unicodes
before being parsed.
plankton: Handle error while decoding image names

* Catch a potential 500 error, when registering a file as an Image, while
trying to decode "Image name" into unicode.
* Add corresponding test case
webproject: Wrap stderr in an EncodedStream object

'snf-manage' command wraps the 'stdout' in an EncodedStream objects,
which encodes all unicode objects to bytestrings using the user's
preferred encoding. This commit wraps 'stderr' as well.
astakos: Remove unused lazy_string
astakos: Replace str with unicode

Define __unicode__ in astakos models rather than __str__.
astakos: Include unicode strings in tests
astakos: Use pprint_table for expired projects
snf_django: Fix csv unicode writer

Use recipe from http://docs.python.org/2/library/csv.html to write unicode
in csv format.
snf_django: Handle unicode in CommandError

Define a custom CommandError, which applies smart_locale_str() in its
__str__ method. Use this custom CommandError in Astakos management
commands.
cyclades: Replace str with smart_unicode
astakos: Use common JSON util in API

Use the 'get_json_body' function, which takes care of encoding errors.
Also, check that the POST body is a dictionary, where needed.
Update copyright to changed files
Fix pep8 errors
Merge pull request #28 from cstavr/feature-unicode-handling

This patch-set fixes a number of issues relative with handling unicode strings.
These commits try to avoid mixing bytestrings and unicode objects, by decoding
bytestrings as early as possible (Input) and encoding unicodes as late as
possible (Ouput). In the API the encoding that is used is always 'UTF-8'. In
the CLI the encoding that is used is the user's preferred encoding.

Besides unicode issues, this patch-set fixes handling of image metadata
(Plankton) which are views as HTTP headers. Since, image metadata must be valid
HTTP headers, metadata keys and values which contain user defined values must
be properly quoted and unquoted where needed.