Repository: djrobstep/sqlakeyset

Issue:
bookmark_ serializer does not support uuid.UUID objects

Discussion:

Patch:
diff --git a/sqlakeyset/serial/serial.py b/sqlakeyset/serial/serial.py
index 2b708f5..0b751e2 100644
--- a/sqlakeyset/serial/serial.py
+++ b/sqlakeyset/serial/serial.py
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
 import decimal
 import datetime
 import base64
+import uuid
 import dateutil.parser
 
 from .compat import csvreader, csvwriter, sio, text_type, binary_type
@@ -19,6 +20,7 @@ DECIMAL = 'n'
 DATE = 'd'
 DATETIME = 'dt'
 TIME = 't'
+UUID = 'uuid'
 
 
 class Serial(object):
@@ -79,6 +81,8 @@ class Serial(object):
             c = DATETIME
         elif t == datetime.time:
             c = TIME
+        elif t == uuid.UUID:
+            c = UUID
         else:
             raise NotImplementedError(
                 "don't know how to serialize type of {} ({})".format(x, type(x)))
@@ -115,6 +119,8 @@ class Serial(object):
             v = v.date()
         elif c == DATETIME:
             v = dateutil.parser.parse(v)
+        elif c == UUID:
+            v = uuid.UUID(v)
         else:
             raise ValueError('unrecognized value {}'.format(x))
 


Test patch:
diff --git a/tests/test_ser.py b/tests/test_ser.py
index f47e165..1b46e9b 100644
--- a/tests/test_ser.py
+++ b/tests/test_ser.py
@@ -1,13 +1,15 @@
 from __future__ import unicode_literals
 
-from sqlakeyset.serial import Serial
-
 import csv
 import io
-from pytest import raises
+import uuid
 import decimal
 import datetime
 import pytz
+
+from pytest import raises
+from sqlakeyset.serial import Serial
+
 utc = pytz.utc
 
 DEFAULTS = dict(
@@ -67,6 +69,8 @@ def test_serial():
     assert s.serialize_value(datetime.datetime(2007, 12, 5, 12, 30, 30, tzinfo=utc)) \
         == 'dt:2007-12-05 12:30:30+00:00'
     assert s.serialize_value(datetime.time(12, 34, 56)) == 't:12:34:56'
+    assert s.serialize_value(uuid.UUID('939d4cc9-830d-4cca-bd74-3ec3d541a9b3')) \
+        == 'uuid:939d4cc9-830d-4cca-bd74-3ec3d541a9b3'
     with raises(NotImplementedError):
         s.serialize_value(csv.reader)
 
@@ -87,6 +91,7 @@ def test_unserial():
     twoway(datetime.date(2007, 12, 5))
     twoway(datetime.datetime(2007, 12, 5, 12, 30, 30, tzinfo=utc))
     twoway(Z('abc'))
+    twoway(uuid.UUID('939d4cc9-830d-4cca-bd74-3ec3d541a9b3'))
 
     with raises(ValueError):
         s.unserialize_value('zzzz:abc')