<s> from __future__ import absolute_import <EOL> import json <EOL> from ... sql import elements <EOL> from ... import types as sqltypes <EOL> from ... import util <EOL> class JSON ( sqltypes . JSON ) : <EOL> """<STR_LIT>""" <EOL> @ util . memoized_property <EOL> def _str_impl ( self ) : <EOL> return sqltypes . String ( convert_unicode = True ) <EOL> def bind_processor ( self , dialect ) : <EOL> string_process = self . _str_impl . bind_processor ( dialect ) <EOL> json_serializer = dialect . _json_serializer or json . dumps <EOL> def process ( value ) : <EOL> if value is self . NULL : <EOL> value = None <EOL> elif isinstance ( value , elements . Null ) or ( <EOL> value is None and self . none_as_null <EOL> ) : <EOL> return None <EOL> serialized = json_serializer ( value ) <EOL> if string_process : <EOL> serialized = string_process ( serialized ) <EOL> return serialized <EOL> return process <EOL> def result_processor ( self , dialect , coltype ) : <EOL> string_process = self . _str_impl . result_processor ( dialect , coltype ) <EOL> json_deserializer = dialect . _json_deserializer or json . loads <EOL> def process ( value ) : <EOL> if value is None : <EOL> return None <EOL> if string_process : <EOL> value = string_process ( value ) <EOL> return json_deserializer ( value ) <EOL> return process <EOL> class JSONIndexType ( sqltypes . JSON . JSONIndexType ) : <EOL> def bind_processor ( self , dialect ) : <EOL> def process ( value ) : <EOL> if isinstance ( value , int ) : <EOL> return "<STR_LIT>" % value <EOL> else : <EOL> return '<STR_LIT>' % value <EOL> return process <EOL> class JSONPathType ( sqltypes . JSON . JSONPathType ) : <EOL> def bind_processor ( self , dialect ) : <EOL> def process ( value ) : <EOL> return "<STR_LIT>" % ( <EOL> "<STR_LIT>" . join ( [ <EOL> "<STR_LIT>" % elem if isinstance ( elem , int ) <EOL> else '<STR_LIT>' % elem for elem in value <EOL> ] ) <EOL> ) <EOL> return process </s>
