boto/boto — pull request #1183 by jamesls (2012-12-12 22:03:31+00:00)
Title: Add ability to use Decimal for DynamoDB numeric types

This expands on the work of @disruptek based on the comments in #1060.

The gist of this change is to refactor the
serialization/deserialization of python types to the format
that the dynamodb expects into a single "Dynamizer" interface.

This interface is then plumbed into Layer2 and can be passed in
via the `__init__`. This also allows users to entirely override
this process if they need.

I implemented two types of Dynamizers:

* Dynamizer - Uses Decimals to handle numeric types.
* LossyFloatDynamizer - Uses int/float to handle numeric types.

I made the default dynamizer the LossyFloatDynamizer which will
maintain backwards compatibility (all of the dynamodb tests pass).
I imagine (hope) after some time we can default to Dynamizer
instead.

If a user wants to use decimals, they can either pass in the
appropriate dynamizer:

```python
dynamodb = boto.connect_dynamodb(dynamizer=Dynamizer)
```

or use the `use_decimals` convenience method::

```python
dynamodb = boto.connect_dynamodb()
dynamodb.use_decimals()
```

If a user wants to customize this process, they can subclass
Dynamizer and either override `encode` or `decode`, or they
can override a specific conversion. For example:

```python
class UnicodeDynamizer(Dynamizer):
def decode_s(self, attr):
return unicode(attr)

dynamodb = boto.connect_dynamodb(dynamizer=UnicodeDynamizer)
```

I've added unittests/integration tests for the new functionality.

If this approach looks reasonable I can update the user docs, API docstrings,
etc. for the new changes. Just looking for feedback first.

@garnaat, @disruptek thoughts?