jsonpickle: better support for objects that implement __getstate__() only

When an object implements __getstate__() but not __setstate__()
then jsonpickle was ignoring the __getstate__() implementation.

Change the logic so that we take the result of __getstate__()
regardless of whether __setstate__() is provided.

If __setstate__() is missing when restoring from json then
return the original __getstate__() data as-is rather than
returning an empty object instance.

Closes #73

Signed-off-by: David Aguilar <davvid@gmail.com>
pickler: micro-optimize flattening objects with __slots__

Signed-off-by: David Aguilar <davvid@gmail.com>
unpickler: move dict-key restore code into a function

This will let us reuse this for object instances.

Signed-off-by: David Aguilar <davvid@gmail.com>
unpickler: support defaultdict with int keys

Related-to: #75
Signed-off-by: David Aguilar <davvid@gmail.com>
jsonpickle: better support for defaultdict with custom factories

Add support for common uses of collections.defaultdict by wrapping a
proxy around the default_factory.

The proxy contains an exemplar instance which is used to provide the
original factory's behavior when going round-trip.

Closes #75
Reported-by: Kyle Gorman <kylebgorman@gmail.com>
Signed-off-by: David Aguilar <davvid@gmail.com>
tests: move all datetime tests to datetime_tests.py

Signed-off-by: David Aguilar <davvid@gmail.com>
tests: move advanced object tests to object_test.py

Signed-off-by: David Aguilar <davvid@gmail.com>
picklers: pylint cleanup

Signed-off-by: David Aguilar <davvid@gmail.com>
compat: readability tweaks

Signed-off-by: David Aguilar <davvid@gmail.com>
handlers: update the SimpleReduceHandler docstring

Signed-off-by: David Aguilar <davvid@gmail.com>
picklers: add support for Queue objects

Add a custom handler for serializing Queue objects.

Closes #74

Reported-by: dichotomy <dichotomy@riseup.net>
Signed-off-by: David Aguilar <davvid@gmail.com>
jsonpickle v0.7.2

Signed-off-by: David Aguilar <davvid@gmail.com>
jsonpickle: support serializing references to module-level functions

Add support for objects that hold references to module-level functions.

Closes #77

Suggested-by: Kyle Gorman <kylebgorman@gmail.com>
Signed-off-by: David Aguilar <davvid@gmail.com>
Add ability to use __getnewargs__ from protocol 2
Merge pull request #79 from marcintustin/master

Add ability to use __getnewargs__ from protocol 2

Signed-off-by: David Aguilar <davvid@gmail.com>
tags: alphabetize to minimize potential merge conflicts

Signed-off-by: David Aguilar <davvid@gmail.com>
pickle v2: improve handling for object references

We now allow Pickle Protocol v2 __getnewargs__() to contain
references.

The unpickler uses a new strategy for handling references.
It now places Proxy objects into the referencing machinery
to break dependencies between construction arguments and
parent objects.

A final sweep is done at the end of restore() to swap proxies
for their real instances.  This allows for proper referencing
within objects returned by __getnewargs__().

Related-to: #78
Signed-off-by: David Aguilar <davvid@gmail.com>
tests: add a Pickle v2 cyclical reference test

Related-to: #78
Signed-off-by: David Aguilar <davvid@gmail.com>
tests: fix typos

Signed-off-by: David Aguilar <davvid@gmail.com>
unpickler: more Pickle v2 referencing improvements

We now support cyclical references inside of lists when using
Pickle Protocol v2.

Related-to: #78
Signed-off-by: David Aguilar <davvid@gmail.com>