<s> """<STR_LIT>""" <EOL> import linecache <EOL> import sys <EOL> import types <EOL> __all__ = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] <EOL> def warnpy3k ( message , category = None , stacklevel = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> if sys . py3kwarning : <EOL> if category is None : <EOL> category = DeprecationWarning <EOL> warn ( message , category , stacklevel + <NUM_LIT:1> ) <EOL> def _show_warning ( message , category , filename , lineno , file = None , line = None ) : <EOL> """<STR_LIT>""" <EOL> if file is None : <EOL> file = sys . stderr <EOL> try : <EOL> file . write ( formatwarning ( message , category , filename , lineno , line ) ) <EOL> except IOError : <EOL> pass <EOL> showwarning = _show_warning <EOL> def formatwarning ( message , category , filename , lineno , line = None ) : <EOL> """<STR_LIT>""" <EOL> s = "<STR_LIT>" % ( filename , lineno , category . __name__ , message ) <EOL> line = linecache . getline ( filename , lineno ) if line is None else line <EOL> if line : <EOL> line = line . strip ( ) <EOL> s += "<STR_LIT>" % line <EOL> return s <EOL> def filterwarnings ( action , message = "<STR_LIT>" , category = Warning , module = "<STR_LIT>" , lineno = <NUM_LIT:0> , <EOL> append = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> import re <EOL> assert action in ( "<STR_LIT:error>" , "<STR_LIT:ignore>" , "<STR_LIT>" , "<STR_LIT:default>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ) , "<STR_LIT>" % ( action , ) <EOL> assert isinstance ( message , basestring ) , "<STR_LIT>" <EOL> assert isinstance ( category , ( type , types . ClassType ) ) , "<STR_LIT>" <EOL> assert issubclass ( category , Warning ) , "<STR_LIT>" <EOL> assert isinstance ( module , basestring ) , "<STR_LIT>" <EOL> assert isinstance ( lineno , int ) and lineno >= <NUM_LIT:0> , "<STR_LIT>" <EOL> item = ( action , re . compile ( message , re . I ) , category , <EOL> re . compile ( module ) , lineno ) <EOL> if append : <EOL> filters . append ( item ) <EOL> else : <EOL> filters . insert ( <NUM_LIT:0> , item ) <EOL> def simplefilter ( action , category = Warning , lineno = <NUM_LIT:0> , append = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> assert action in ( "<STR_LIT:error>" , "<STR_LIT:ignore>" , "<STR_LIT>" , "<STR_LIT:default>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ) , "<STR_LIT>" % ( action , ) <EOL> assert isinstance ( lineno , int ) and lineno >= <NUM_LIT:0> , "<STR_LIT>" <EOL> item = ( action , None , category , None , lineno ) <EOL> if append : <EOL> filters . append ( item ) <EOL> else : <EOL> filters . insert ( <NUM_LIT:0> , item ) <EOL> def resetwarnings ( ) : <EOL> """<STR_LIT>""" <EOL> filters [ : ] = [ ] <EOL> class _OptionError ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def _processoptions ( args ) : <EOL> for arg in args : <EOL> try : <EOL> _setoption ( arg ) <EOL> except _OptionError , msg : <EOL> print >> sys . stderr , "<STR_LIT>" , msg <EOL> def _setoption ( arg ) : <EOL> import re <EOL> parts = arg . split ( '<STR_LIT::>' ) <EOL> if len ( parts ) > <NUM_LIT:5> : <EOL> raise _OptionError ( "<STR_LIT>" % ( arg , ) ) <EOL> while len ( parts ) < <NUM_LIT:5> : <EOL> parts . append ( '<STR_LIT>' ) <EOL> action , message , category , module , lineno = [ s . strip ( ) <EOL> for s in parts ] <EOL> action = _getaction ( action ) <EOL> message = re . escape ( message ) <EOL> category = _getcategory ( category ) <EOL> module = re . escape ( module ) <EOL> if module : <EOL> module = module + '<STR_LIT:$>' <EOL> if lineno : <EOL> try : <EOL> lineno = int ( lineno ) <EOL> if lineno < <NUM_LIT:0> : <EOL> raise ValueError <EOL> except ( ValueError , OverflowError ) : <EOL> raise _OptionError ( "<STR_LIT>" % ( lineno , ) ) <EOL> else : <EOL> lineno = <NUM_LIT:0> <EOL> filterwarnings ( action , message , category , module , lineno ) <EOL> def _getaction ( action ) : <EOL> if not action : <EOL> return "<STR_LIT:default>" <EOL> if action == "<STR_LIT:all>" : return "<STR_LIT>" <EOL> for a in ( '<STR_LIT:default>' , '<STR_LIT>' , '<STR_LIT:ignore>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:error>' ) : <EOL> if a . startswith ( action ) : <EOL> return a <EOL> raise _OptionError ( "<STR_LIT>" % ( action , ) ) <EOL> def _getcategory ( category ) : <EOL> import re <EOL> if not category : <EOL> return Warning <EOL> if re . match ( "<STR_LIT>" , category ) : <EOL> try : <EOL> cat = eval ( category ) <EOL> except NameError : <EOL> raise _OptionError ( "<STR_LIT>" % ( category , ) ) <EOL> else : <EOL> i = category . rfind ( "<STR_LIT:.>" ) <EOL> module = category [ : i ] <EOL> klass = category [ i + <NUM_LIT:1> : ] <EOL> try : <EOL> m = __import__ ( module , None , None , [ klass ] ) <EOL> except ImportError : <EOL> raise _OptionError ( "<STR_LIT>" % ( module , ) ) <EOL> try : <EOL> cat = getattr ( m , klass ) <EOL> except AttributeError : <EOL> raise _OptionError ( "<STR_LIT>" % ( category , ) ) <EOL> if not issubclass ( cat , Warning ) : <EOL> raise _OptionError ( "<STR_LIT>" % ( category , ) ) <EOL> return cat <EOL> def warn ( message , category = None , stacklevel = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( message , Warning ) : <EOL> category = message . __class__ <EOL> if category is None : <EOL> category = UserWarning <EOL> assert issubclass ( category , Warning ) <EOL> try : <EOL> caller = sys . _getframe ( stacklevel ) <EOL> except ValueError : <EOL> globals = sys . __dict__ <EOL> lineno = <NUM_LIT:1> <EOL> else : <EOL> globals = caller . f_globals <EOL> lineno = caller . f_lineno <EOL> if '<STR_LIT>' in globals : <EOL> module = globals [ '<STR_LIT>' ] <EOL> else : <EOL> module = "<STR_LIT>" <EOL> filename = globals . get ( '<STR_LIT>' ) <EOL> if filename : <EOL> fnl = filename . lower ( ) <EOL> if fnl . endswith ( ( "<STR_LIT>" , "<STR_LIT>" ) ) : <EOL> filename = filename [ : - <NUM_LIT:1> ] <EOL> else : <EOL> if module == "<STR_LIT:__main__>" : <EOL> try : <EOL> filename = sys . argv [ <NUM_LIT:0> ] <EOL> except AttributeError : <EOL> filename = '<STR_LIT:__main__>' <EOL> if not filename : <EOL> filename = module <EOL> registry = globals . setdefault ( "<STR_LIT>" , { } ) <EOL> warn_explicit ( message , category , filename , lineno , module , registry , <EOL> globals ) <EOL> def warn_explicit ( message , category , filename , lineno , <EOL> module = None , registry = None , module_globals = None ) : <EOL> lineno = int ( lineno ) <EOL> if module is None : <EOL> module = filename or "<STR_LIT>" <EOL> if module [ - <NUM_LIT:3> : ] . lower ( ) == "<STR_LIT>" : <EOL> module = module [ : - <NUM_LIT:3> ] <EOL> if registry is None : <EOL> registry = { } <EOL> if isinstance ( message , Warning ) : <EOL> text = str ( message ) <EOL> category = message . __class__ <EOL> else : <EOL> text = message <EOL> message = category ( message ) <EOL> key = ( text , category , lineno ) <EOL> if registry . get ( key ) : <EOL> return <EOL> for item in filters : <EOL> action , msg , cat , mod , ln = item <EOL> if ( ( msg is None or msg . match ( text ) ) and <EOL> issubclass ( category , cat ) and <EOL> ( mod is None or mod . match ( module ) ) and <EOL> ( ln == <NUM_LIT:0> or lineno == ln ) ) : <EOL> break <EOL> else : <EOL> action = defaultaction <EOL> if action == "<STR_LIT:ignore>" : <EOL> registry [ key ] = <NUM_LIT:1> <EOL> return <EOL> linecache . getlines ( filename , module_globals ) <EOL> if action == "<STR_LIT:error>" : <EOL> raise message <EOL> if action == "<STR_LIT>" : <EOL> registry [ key ] = <NUM_LIT:1> <EOL> oncekey = ( text , category ) <EOL> if onceregistry . get ( oncekey ) : <EOL> return <EOL> onceregistry [ oncekey ] = <NUM_LIT:1> <EOL> elif action == "<STR_LIT>" : <EOL> pass <EOL> elif action == "<STR_LIT>" : <EOL> registry [ key ] = <NUM_LIT:1> <EOL> altkey = ( text , category , <NUM_LIT:0> ) <EOL> if registry . get ( altkey ) : <EOL> return <EOL> registry [ altkey ] = <NUM_LIT:1> <EOL> elif action == "<STR_LIT:default>" : <EOL> registry [ key ] = <NUM_LIT:1> <EOL> else : <EOL> raise RuntimeError ( <EOL> "<STR_LIT>" % <EOL> ( action , item ) ) <EOL> fxn_code = None <EOL> if hasattr ( showwarning , '<STR_LIT>' ) : <EOL> fxn_code = showwarning . func_code <EOL> elif hasattr ( showwarning , '<STR_LIT>' ) : <EOL> fxn_code = showwarning . __func__ . func_code <EOL> if fxn_code : <EOL> args = fxn_code . co_varnames [ : fxn_code . co_argcount ] <EOL> CO_VARARGS = <NUM_LIT> <EOL> if '<STR_LIT>' not in args and not fxn_code . co_flags & CO_VARARGS : <EOL> showwarning_msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if message == showwarning_msg : <EOL> _show_warning ( message , category , filename , lineno ) <EOL> else : <EOL> warn ( showwarning_msg , DeprecationWarning ) <EOL> showwarning ( message , category , filename , lineno ) <EOL> class WarningMessage ( object ) : <EOL> """<STR_LIT>""" <EOL> _WARNING_DETAILS = ( "<STR_LIT:message>" , "<STR_LIT>" , "<STR_LIT:filename>" , "<STR_LIT>" , "<STR_LIT:file>" , <EOL> "<STR_LIT>" ) <EOL> def __init__ ( self , message , category , filename , lineno , file = None , <EOL> line = None ) : <EOL> local_values = locals ( ) <EOL> for attr in self . _WARNING_DETAILS : <EOL> setattr ( self , attr , local_values [ attr ] ) <EOL> self . _category_name = category . __name__ if category else None <EOL> def __str__ ( self ) : <EOL> return ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( self . message , self . _category_name , <EOL> self . filename , self . lineno , self . line ) ) <EOL> class catch_warnings ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , record = False , module = None ) : <EOL> """<STR_LIT>""" <EOL> self . _record = record <EOL> self . _module = sys . modules [ '<STR_LIT>' ] if module is None else module <EOL> self . _entered = False <EOL> def __repr__ ( self ) : <EOL> args = [ ] <EOL> if self . _record : <EOL> args . append ( "<STR_LIT>" ) <EOL> if self . _module is not sys . modules [ '<STR_LIT>' ] : <EOL> args . append ( "<STR_LIT>" % self . _module ) <EOL> name = type ( self ) . __name__ <EOL> return "<STR_LIT>" % ( name , "<STR_LIT:U+002CU+0020>" . join ( args ) ) <EOL> def __enter__ ( self ) : <EOL> if self . _entered : <EOL> raise RuntimeError ( "<STR_LIT>" % self ) <EOL> self . _entered = True <EOL> self . _filters = self . _module . filters <EOL> self . _module . filters = self . _filters [ : ] <EOL> self . _showwarning = self . _module . showwarning <EOL> if self . _record : <EOL> log = [ ] <EOL> def showwarning ( * args , ** kwargs ) : <EOL> log . append ( WarningMessage ( * args , ** kwargs ) ) <EOL> self . _module . showwarning = showwarning <EOL> return log <EOL> else : <EOL> return None <EOL> def __exit__ ( self , * exc_info ) : <EOL> if not self . _entered : <EOL> raise RuntimeError ( "<STR_LIT>" % self ) <EOL> self . _module . filters = self . _filters <EOL> self . _module . showwarning = self . _showwarning <EOL> _warnings_defaults = False <EOL> try : <EOL> from _warnings import ( filters , default_action , once_registry , <EOL> warn , warn_explicit ) <EOL> defaultaction = default_action <EOL> onceregistry = once_registry <EOL> _warnings_defaults = True <EOL> except ImportError : <EOL> filters = [ ] <EOL> defaultaction = "<STR_LIT:default>" <EOL> onceregistry = { } <EOL> _processoptions ( sys . warnoptions ) <EOL> if not _warnings_defaults : <EOL> simplefilter ( "<STR_LIT:ignore>" , category = PendingDeprecationWarning , append = <NUM_LIT:1> ) <EOL> simplefilter ( "<STR_LIT:ignore>" , category = ImportWarning , append = <NUM_LIT:1> ) <EOL> bytes_warning = sys . flags . bytes_warning <EOL> if bytes_warning > <NUM_LIT:1> : <EOL> bytes_action = "<STR_LIT:error>" <EOL> elif bytes_warning : <EOL> bytes_action = "<STR_LIT:default>" <EOL> else : <EOL> bytes_action = "<STR_LIT:ignore>" <EOL> simplefilter ( bytes_action , category = BytesWarning , append = <NUM_LIT:1> ) <EOL> del _warnings_defaults </s>
