<s> import os <EOL> import warnings <EOL> import cherrypy <EOL> from cherrypy . _cpcompat import iteritems , copykeys , builtins <EOL> class Checker ( object ) : <EOL> """<STR_LIT>""" <EOL> on = True <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . _populate_known_types ( ) <EOL> def __call__ ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . on : <EOL> oldformatwarning = warnings . formatwarning <EOL> warnings . formatwarning = self . formatwarning <EOL> try : <EOL> for name in dir ( self ) : <EOL> if name . startswith ( "<STR_LIT>" ) : <EOL> method = getattr ( self , name ) <EOL> if method and hasattr ( method , '<STR_LIT>' ) : <EOL> method ( ) <EOL> finally : <EOL> warnings . formatwarning = oldformatwarning <EOL> def formatwarning ( self , message , category , filename , lineno , line = None ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % message <EOL> global_config_contained_paths = False <EOL> def check_app_config_entries_dont_start_with_script_name ( self ) : <EOL> """<STR_LIT>""" <EOL> for sn , app in cherrypy . tree . apps . items ( ) : <EOL> if not isinstance ( app , cherrypy . Application ) : <EOL> continue <EOL> if not app . config : <EOL> continue <EOL> if sn == '<STR_LIT>' : <EOL> continue <EOL> sn_atoms = sn . strip ( "<STR_LIT:/>" ) . split ( "<STR_LIT:/>" ) <EOL> for key in app . config . keys ( ) : <EOL> key_atoms = key . strip ( "<STR_LIT:/>" ) . split ( "<STR_LIT:/>" ) <EOL> if key_atoms [ : len ( sn_atoms ) ] == sn_atoms : <EOL> warnings . warn ( <EOL> "<STR_LIT>" "<STR_LIT>" % ( sn , key ) ) <EOL> def check_site_config_entries_in_app_config ( self ) : <EOL> """<STR_LIT>""" <EOL> for sn , app in iteritems ( cherrypy . tree . apps ) : <EOL> if not isinstance ( app , cherrypy . Application ) : <EOL> continue <EOL> msg = [ ] <EOL> for section , entries in iteritems ( app . config ) : <EOL> if section . startswith ( '<STR_LIT:/>' ) : <EOL> for key , value in iteritems ( entries ) : <EOL> for n in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> if key . startswith ( n ) : <EOL> msg . append ( "<STR_LIT>" % ( section , key , value ) ) <EOL> if msg : <EOL> msg . insert ( <NUM_LIT:0> , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % sn ) <EOL> warnings . warn ( os . linesep . join ( msg ) ) <EOL> def check_skipped_app_config ( self ) : <EOL> """<STR_LIT>""" <EOL> for sn , app in cherrypy . tree . apps . items ( ) : <EOL> if not isinstance ( app , cherrypy . Application ) : <EOL> continue <EOL> if not app . config : <EOL> msg = "<STR_LIT>" % sn <EOL> if self . global_config_contained_paths : <EOL> msg += ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> warnings . warn ( msg ) <EOL> return <EOL> def check_app_config_brackets ( self ) : <EOL> """<STR_LIT>""" <EOL> for sn , app in cherrypy . tree . apps . items ( ) : <EOL> if not isinstance ( app , cherrypy . Application ) : <EOL> continue <EOL> if not app . config : <EOL> continue <EOL> for key in app . config . keys ( ) : <EOL> if key . startswith ( "<STR_LIT:[>" ) or key . endswith ( "<STR_LIT:]>" ) : <EOL> warnings . warn ( <EOL> "<STR_LIT>" "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( sn , key ) ) <EOL> def check_static_paths ( self ) : <EOL> """<STR_LIT>""" <EOL> request = cherrypy . request <EOL> for sn , app in cherrypy . tree . apps . items ( ) : <EOL> if not isinstance ( app , cherrypy . Application ) : <EOL> continue <EOL> request . app = app <EOL> for section in app . config : <EOL> request . get_resource ( section + "<STR_LIT>" ) <EOL> conf = request . config . get <EOL> if conf ( "<STR_LIT>" , False ) : <EOL> msg = "<STR_LIT>" <EOL> root = conf ( "<STR_LIT>" ) <EOL> dir = conf ( "<STR_LIT>" ) <EOL> if dir is None : <EOL> msg = "<STR_LIT>" <EOL> else : <EOL> fulldir = "<STR_LIT>" <EOL> if os . path . isabs ( dir ) : <EOL> fulldir = dir <EOL> if root : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> testdir = os . path . join ( root , dir [ <NUM_LIT:1> : ] ) <EOL> if os . path . exists ( testdir ) : <EOL> msg += ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % testdir ) <EOL> else : <EOL> if not root : <EOL> msg = "<STR_LIT>" <EOL> else : <EOL> fulldir = os . path . join ( root , dir ) <EOL> if not os . path . isabs ( fulldir ) : <EOL> msg = "<STR_LIT>" % fulldir <EOL> if fulldir and not os . path . exists ( fulldir ) : <EOL> if msg : <EOL> msg += "<STR_LIT:\n>" <EOL> msg += ( "<STR_LIT>" <EOL> "<STR_LIT>" % fulldir ) <EOL> if msg : <EOL> warnings . warn ( "<STR_LIT>" <EOL> % ( msg , section , root , dir ) ) <EOL> obsolete = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : ( '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> } <EOL> deprecated = { } <EOL> def _compat ( self , config ) : <EOL> """<STR_LIT>""" <EOL> for section , conf in config . items ( ) : <EOL> if isinstance ( conf , dict ) : <EOL> for k , v in conf . items ( ) : <EOL> if k in self . obsolete : <EOL> warnings . warn ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( k , self . obsolete [ k ] , section ) ) <EOL> elif k in self . deprecated : <EOL> warnings . warn ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> ( k , self . deprecated [ k ] , section ) ) <EOL> else : <EOL> if section in self . obsolete : <EOL> warnings . warn ( "<STR_LIT>" <EOL> % ( section , self . obsolete [ section ] ) ) <EOL> elif section in self . deprecated : <EOL> warnings . warn ( "<STR_LIT>" <EOL> % ( section , self . deprecated [ section ] ) ) <EOL> def check_compatibility ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _compat ( cherrypy . config ) <EOL> for sn , app in cherrypy . tree . apps . items ( ) : <EOL> if not isinstance ( app , cherrypy . Application ) : <EOL> continue <EOL> self . _compat ( app . config ) <EOL> extra_config_namespaces = [ ] <EOL> def _known_ns ( self , app ) : <EOL> ns = [ "<STR_LIT>" ] <EOL> ns . extend ( copykeys ( app . toolboxes ) ) <EOL> ns . extend ( copykeys ( app . namespaces ) ) <EOL> ns . extend ( copykeys ( app . request_class . namespaces ) ) <EOL> ns . extend ( copykeys ( cherrypy . config . namespaces ) ) <EOL> ns += self . extra_config_namespaces <EOL> for section , conf in app . config . items ( ) : <EOL> is_path_section = section . startswith ( "<STR_LIT:/>" ) <EOL> if is_path_section and isinstance ( conf , dict ) : <EOL> for k , v in conf . items ( ) : <EOL> atoms = k . split ( "<STR_LIT:.>" ) <EOL> if len ( atoms ) > <NUM_LIT:1> : <EOL> if atoms [ <NUM_LIT:0> ] not in ns : <EOL> if ( atoms [ <NUM_LIT:0> ] == "<STR_LIT>" and atoms [ <NUM_LIT:1> ] in ns ) : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( k , "<STR_LIT:.>" . join ( atoms [ <NUM_LIT:1> : ] ) , section ) ) <EOL> else : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( k , atoms [ <NUM_LIT:0> ] , section ) ) <EOL> warnings . warn ( msg ) <EOL> elif atoms [ <NUM_LIT:0> ] == "<STR_LIT>" : <EOL> if atoms [ <NUM_LIT:1> ] not in dir ( cherrypy . tools ) : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( k , atoms [ <NUM_LIT:1> ] , section ) ) <EOL> warnings . warn ( msg ) <EOL> def check_config_namespaces ( self ) : <EOL> """<STR_LIT>""" <EOL> for sn , app in cherrypy . tree . apps . items ( ) : <EOL> if not isinstance ( app , cherrypy . Application ) : <EOL> continue <EOL> self . _known_ns ( app ) <EOL> known_config_types = { } <EOL> def _populate_known_types ( self ) : <EOL> b = [ x for x in vars ( builtins ) . values ( ) <EOL> if type ( x ) is type ( str ) ] <EOL> def traverse ( obj , namespace ) : <EOL> for name in dir ( obj ) : <EOL> if name == '<STR_LIT>' : <EOL> continue <EOL> vtype = type ( getattr ( obj , name , None ) ) <EOL> if vtype in b : <EOL> self . known_config_types [ namespace + "<STR_LIT:.>" + name ] = vtype <EOL> traverse ( cherrypy . request , "<STR_LIT>" ) <EOL> traverse ( cherrypy . response , "<STR_LIT>" ) <EOL> traverse ( cherrypy . server , "<STR_LIT>" ) <EOL> traverse ( cherrypy . engine , "<STR_LIT>" ) <EOL> traverse ( cherrypy . log , "<STR_LIT>" ) <EOL> def _known_types ( self , config ) : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> for section , conf in config . items ( ) : <EOL> if isinstance ( conf , dict ) : <EOL> for k , v in conf . items ( ) : <EOL> if v is not None : <EOL> expected_type = self . known_config_types . get ( k , None ) <EOL> vtype = type ( v ) <EOL> if expected_type and vtype != expected_type : <EOL> warnings . warn ( msg % ( k , section , vtype . __name__ , <EOL> expected_type . __name__ ) ) <EOL> else : <EOL> k , v = section , conf <EOL> if v is not None : <EOL> expected_type = self . known_config_types . get ( k , None ) <EOL> vtype = type ( v ) <EOL> if expected_type and vtype != expected_type : <EOL> warnings . warn ( msg % ( k , section , vtype . __name__ , <EOL> expected_type . __name__ ) ) <EOL> def check_config_types ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _known_types ( cherrypy . config ) <EOL> for sn , app in cherrypy . tree . apps . items ( ) : <EOL> if not isinstance ( app , cherrypy . Application ) : <EOL> continue <EOL> self . _known_types ( app . config ) <EOL> def check_localhost ( self ) : <EOL> """<STR_LIT>""" <EOL> for k , v in cherrypy . config . items ( ) : <EOL> if k == '<STR_LIT>' and v == '<STR_LIT:localhost>' : <EOL> warnings . warn ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) </s>
