@@ -0,0 +1,1112 @@
+from sqlalchemy.types import TypeDecorator, BINARY%0Afrom sqlalchemy.dialects.postgresql import UUID%0Aimport uuid%0A%0A%0Aclass UUID(TypeDecorator):%0A    %22%22%22Platform-independent UUID type.%0A%0A    Uses Postgresql's UUID type, otherwise uses%0A    BINARY(16).%0A    Based on http://docs.sqlalchemy.org/en/rel_0_9/core/custom_types.html?highlight=guid#backend-agnostic-guid-type%0A    %22%22%22%0A    impl = BINARY%0A%0A    def load_dialect_impl(self, dialect):%0A        if dialect.name == 'postgresql':%0A            return dialect.type_descriptor(UUID())%0A        else:%0A            return dialect.type_descriptor(BINARY)%0A%0A    def process_bind_param(self, value, dialect):%0A        if value is None:%0A            return value%0A        elif dialect.name == 'postgresql':%0A            return str(value)%0A        else:%0A            if not isinstance(value, uuid.UUID):%0A                return uuid.UUID(value).bytes%0A            else:%0A                # hex string%0A                return value.bytes%0A%0A    def process_result_value(self, value, dialect):%0A        if value is None:%0A            return value%0A        else:%0A            return uuid.UUID(bytes=value)%0A

Create a custom UUID column type