<s> from django . apps import apps <EOL> from django . dispatch import Signal <EOL> from django . utils import six <EOL> class_prepared = Signal ( providing_args = [ "<STR_LIT:class>" ] ) <EOL> class ModelSignal ( Signal ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( ModelSignal , self ) . __init__ ( * args , ** kwargs ) <EOL> self . unresolved_references = { } <EOL> class_prepared . connect ( self . _resolve_references ) <EOL> def _resolve_references ( self , sender , ** kwargs ) : <EOL> opts = sender . _meta <EOL> reference = ( opts . app_label , opts . object_name ) <EOL> try : <EOL> receivers = self . unresolved_references . pop ( reference ) <EOL> except KeyError : <EOL> pass <EOL> else : <EOL> for receiver , weak , dispatch_uid in receivers : <EOL> super ( ModelSignal , self ) . connect ( <EOL> receiver , sender = sender , weak = weak , dispatch_uid = dispatch_uid <EOL> ) <EOL> def connect ( self , receiver , sender = None , weak = True , dispatch_uid = None ) : <EOL> if isinstance ( sender , six . string_types ) : <EOL> try : <EOL> app_label , model_name = sender . split ( '<STR_LIT:.>' ) <EOL> except ValueError : <EOL> raise ValueError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> try : <EOL> sender = apps . get_registered_model ( app_label , model_name ) <EOL> except LookupError : <EOL> ref = ( app_label , model_name ) <EOL> refs = self . unresolved_references . setdefault ( ref , [ ] ) <EOL> refs . append ( ( receiver , weak , dispatch_uid ) ) <EOL> return <EOL> super ( ModelSignal , self ) . connect ( <EOL> receiver , sender = sender , weak = weak , dispatch_uid = dispatch_uid <EOL> ) <EOL> pre_init = ModelSignal ( providing_args = [ "<STR_LIT>" , "<STR_LIT:args>" , "<STR_LIT>" ] , use_caching = True ) <EOL> post_init = ModelSignal ( providing_args = [ "<STR_LIT>" ] , use_caching = True ) <EOL> pre_save = ModelSignal ( providing_args = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> use_caching = True ) <EOL> post_save = ModelSignal ( providing_args = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , use_caching = True ) <EOL> pre_delete = ModelSignal ( providing_args = [ "<STR_LIT>" , "<STR_LIT>" ] , use_caching = True ) <EOL> post_delete = ModelSignal ( providing_args = [ "<STR_LIT>" , "<STR_LIT>" ] , use_caching = True ) <EOL> m2m_changed = ModelSignal ( <EOL> providing_args = [ "<STR_LIT:action>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> use_caching = True , <EOL> ) <EOL> pre_migrate = Signal ( providing_args = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> post_migrate = Signal ( providing_args = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) </s>
