<s> import json <EOL> from circuits . core import Event <EOL> from circuits . six import bytes_to_str , text_type <EOL> META_EXCLUDE = set ( dir ( Event ( ) ) ) <EOL> META_EXCLUDE . add ( "<STR_LIT>" ) <EOL> META_EXCLUDE . add ( "<STR_LIT>" ) <EOL> META_EXCLUDE . add ( "<STR_LIT>" ) <EOL> META_EXCLUDE . add ( "<STR_LIT>" ) <EOL> def load_event ( s ) : <EOL> data = json . loads ( s ) <EOL> name = bytes_to_str ( data [ "<STR_LIT:name>" ] . encode ( "<STR_LIT:utf-8>" ) ) <EOL> args = [ ] <EOL> for arg in data [ "<STR_LIT:args>" ] : <EOL> if isinstance ( arg , text_type ) : <EOL> arg = arg . encode ( "<STR_LIT:utf-8>" ) <EOL> args . append ( arg ) <EOL> kwargs = { } <EOL> for k , v in data [ "<STR_LIT>" ] . items ( ) : <EOL> if isinstance ( v , text_type ) : <EOL> v = v . encode ( "<STR_LIT:utf-8>" ) <EOL> kwargs [ str ( k ) ] = v <EOL> e = Event . create ( name , * args , ** kwargs ) <EOL> e . success = bool ( data [ "<STR_LIT:success>" ] ) <EOL> e . failure = bool ( data [ "<STR_LIT>" ] ) <EOL> e . notify = bool ( data [ "<STR_LIT>" ] ) <EOL> e . channels = tuple ( data [ "<STR_LIT>" ] ) <EOL> for k , v in dict ( data [ "<STR_LIT>" ] ) . items ( ) : <EOL> setattr ( e , k , v ) <EOL> return e , data [ "<STR_LIT:id>" ] <EOL> def dump_event ( e , id ) : <EOL> meta = { } <EOL> for name in list ( set ( dir ( e ) ) - META_EXCLUDE ) : <EOL> meta [ name ] = getattr ( e , name ) <EOL> data = { <EOL> "<STR_LIT:id>" : id , <EOL> "<STR_LIT:name>" : e . name , <EOL> "<STR_LIT:args>" : e . args , <EOL> "<STR_LIT>" : e . kwargs , <EOL> "<STR_LIT:success>" : e . success , <EOL> "<STR_LIT>" : e . failure , <EOL> "<STR_LIT>" : e . channels , <EOL> "<STR_LIT>" : e . notify , <EOL> "<STR_LIT>" : meta <EOL> } <EOL> return json . dumps ( data ) <EOL> def dump_value ( v ) : <EOL> meta = { } <EOL> e = v . event <EOL> if e : <EOL> for name in list ( set ( dir ( e ) ) - META_EXCLUDE ) : <EOL> meta [ name ] = getattr ( e , name ) <EOL> data = { <EOL> "<STR_LIT:id>" : v . node_call_id , <EOL> "<STR_LIT>" : v . errors , <EOL> "<STR_LIT:value>" : v . _value , <EOL> "<STR_LIT>" : meta <EOL> } <EOL> return json . dumps ( data ) <EOL> def load_value ( v ) : <EOL> data = json . loads ( v ) <EOL> return data [ '<STR_LIT:value>' ] , data [ '<STR_LIT:id>' ] , data [ '<STR_LIT>' ] , data [ '<STR_LIT>' ] </s>
