<s> """<STR_LIT>""" <EOL> import warnings <EOL> import inspect <EOL> from ants . utils . exceptions import ScrapyDeprecationWarning <EOL> def attribute ( obj , oldattr , newattr , version = '<STR_LIT>' ) : <EOL> cname = obj . __class__ . __name__ <EOL> warnings . warn ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( cname , oldattr , version , cname , newattr ) , ScrapyDeprecationWarning , stacklevel = <NUM_LIT:3> ) <EOL> def create_deprecated_class ( name , new_class , clsdict = None , <EOL> warn_category = ScrapyDeprecationWarning , <EOL> warn_once = True , <EOL> old_class_path = None , <EOL> new_class_path = None , <EOL> subclass_warn_message = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" , <EOL> instance_warn_message = "<STR_LIT>" "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> class DeprecatedClass ( new_class . __class__ ) : <EOL> deprecated_class = None <EOL> warned_on_subclass = False <EOL> def __new__ ( metacls , name , bases , clsdict_ ) : <EOL> cls = super ( DeprecatedClass , metacls ) . __new__ ( metacls , name , bases , clsdict_ ) <EOL> if metacls . deprecated_class is None : <EOL> metacls . deprecated_class = cls <EOL> return cls <EOL> def __init__ ( cls , name , bases , clsdict_ ) : <EOL> meta = cls . __class__ <EOL> old = meta . deprecated_class <EOL> if old in bases and not ( warn_once and meta . warned_on_subclass ) : <EOL> meta . warned_on_subclass = True <EOL> msg = subclass_warn_message . format ( cls = _clspath ( cls ) , <EOL> old = _clspath ( old , old_class_path ) , <EOL> new = _clspath ( new_class , new_class_path ) ) <EOL> if warn_once : <EOL> msg += '<STR_LIT>' <EOL> warnings . warn ( msg , warn_category , stacklevel = <NUM_LIT:2> ) <EOL> super ( DeprecatedClass , cls ) . __init__ ( name , bases , clsdict_ ) <EOL> def __instancecheck__ ( cls , inst ) : <EOL> return any ( cls . __subclasscheck__ ( c ) <EOL> for c in { type ( inst ) , inst . __class__ } ) <EOL> def __subclasscheck__ ( cls , sub ) : <EOL> if cls is not DeprecatedClass . deprecated_class : <EOL> return super ( DeprecatedClass , cls ) . __subclasscheck__ ( sub ) <EOL> if not inspect . isclass ( sub ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> mro = getattr ( sub , '<STR_LIT>' , ( ) ) <EOL> return any ( c in { cls , new_class } for c in mro ) <EOL> def __call__ ( cls , * args , ** kwargs ) : <EOL> old = DeprecatedClass . deprecated_class <EOL> if cls is old : <EOL> msg = instance_warn_message . format ( cls = _clspath ( cls , old_class_path ) , <EOL> new = _clspath ( new_class , new_class_path ) ) <EOL> warnings . warn ( msg , warn_category , stacklevel = <NUM_LIT:2> ) <EOL> return super ( DeprecatedClass , cls ) . __call__ ( * args , ** kwargs ) <EOL> deprecated_cls = DeprecatedClass ( name , ( new_class , ) , clsdict or { } ) <EOL> try : <EOL> frm = inspect . stack ( ) [ <NUM_LIT:1> ] <EOL> parent_module = inspect . getmodule ( frm [ <NUM_LIT:0> ] ) <EOL> if parent_module is not None : <EOL> deprecated_cls . __module__ = parent_module . __name__ <EOL> except Exception as e : <EOL> warnings . warn ( "<STR_LIT>" % e ) <EOL> return deprecated_cls <EOL> def _clspath ( cls , forced = None ) : <EOL> if forced is not None : <EOL> return forced <EOL> return '<STR_LIT>' . format ( cls . __module__ , cls . __name__ ) </s>
