<s> from __future__ import ( absolute_import , division , <EOL> print_function , unicode_literals ) <EOL> from pylint . checkers import BaseChecker <EOL> from pylint . interfaces import IAstroidChecker <EOL> from astroid import Name , CallFunc , AssName , Getattr , Tuple , Subscript <EOL> from . . __pkginfo__ import BASE_ID <EOL> class ViewsChecker ( BaseChecker ) : <EOL> __implements__ = IAstroidChecker <EOL> name = '<STR_LIT>' <EOL> msgs = { <EOL> '<STR_LIT>' % BASE_ID : ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> '<STR_LIT>' % BASE_ID : ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> '<STR_LIT>' % BASE_ID : ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> '<STR_LIT>' % BASE_ID : ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> } <EOL> _is_view_function = False <EOL> _is_view_class = False <EOL> _is_inside_try_except = False <EOL> _try_except_node = None <EOL> _is_len = False <EOL> @ staticmethod <EOL> def _is_does_not_exist ( node ) : <EOL> if ( isinstance ( node , ( Name , Getattr ) ) and <EOL> '<STR_LIT>' in node . as_string ( ) ) : <EOL> return True <EOL> return False <EOL> @ staticmethod <EOL> def _is_getattr_or_name ( node , name ) : <EOL> if ( ( isinstance ( node , Name ) and node . name == name ) or <EOL> ( isinstance ( node , Getattr ) and node . attrname == name ) ) : <EOL> return True <EOL> return False <EOL> def visit_attribute ( self , node ) : <EOL> parent = node . parent <EOL> expr = node . expr <EOL> if self . _is_getattr_or_name ( expr , '<STR_LIT:user>' ) : <EOL> if ( node . attrname == '<STR_LIT>' and <EOL> not isinstance ( parent , CallFunc ) ) : <EOL> self . add_message ( '<STR_LIT>' , node = node ) <EOL> elif self . _is_getattr_or_name ( expr , '<STR_LIT>' ) : <EOL> if node . attrname in ( '<STR_LIT:GET>' , '<STR_LIT:POST>' ) : <EOL> if ( isinstance ( parent , Subscript ) or <EOL> isinstance ( parent , Getattr ) and <EOL> parent . attrname == '<STR_LIT>' ) : <EOL> self . add_message ( '<STR_LIT>' , node = node ) <EOL> elif isinstance ( parent , Getattr ) and node . attrname == '<STR_LIT>' : <EOL> if parent . attrname == '<STR_LIT>' : <EOL> if self . _is_view_function or self . _is_view_class : <EOL> if not self . _is_inside_try_except : <EOL> self . add_message ( <EOL> '<STR_LIT>' , node = node ) <EOL> else : <EOL> for h in self . _try_except_node . handlers : <EOL> if self . _is_does_not_exist ( h . type ) : <EOL> break <EOL> elif isinstance ( h . type , Tuple ) : <EOL> _does_not_exist_found = False <EOL> for exc_cls in h . type . elts : <EOL> if self . _is_does_not_exist ( exc_cls ) : <EOL> _does_not_exist_found = True <EOL> break <EOL> if _does_not_exist_found : <EOL> break <EOL> else : <EOL> self . add_message ( <EOL> '<STR_LIT>' , node = node ) <EOL> elif parent . attrname in ( '<STR_LIT:all>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> if self . _is_len : <EOL> self . add_message ( '<STR_LIT>' , node = node ) <EOL> def visit_functiondef ( self , node ) : <EOL> if '<STR_LIT>' in node . root ( ) . file : <EOL> args = node . args . args <EOL> if ( args and isinstance ( args [ <NUM_LIT:0> ] , AssName ) and <EOL> args [ <NUM_LIT:0> ] . name == '<STR_LIT>' ) : <EOL> self . _is_view_function = True <EOL> def leave_functiondef ( self , node ) : <EOL> self . _is_view_function = False <EOL> def visit_tryexcept ( self , node ) : <EOL> self . _is_inside_try_except = True <EOL> self . _try_except_node = node <EOL> def leave_tryexcept ( self , node ) : <EOL> self . _is_inside_try_except = False <EOL> self . _try_except_node = None <EOL> def visit_call ( self , node ) : <EOL> if isinstance ( node . func , Name ) and node . func . name == '<STR_LIT>' : <EOL> self . _is_len = True <EOL> def leave_call ( self , node ) : <EOL> self . _is_len = False <EOL> def visit_classdef ( self , node ) : <EOL> if node . is_subtype_of ( '<STR_LIT>' ) : <EOL> self . _is_view_class = True <EOL> def leave_classdef ( self , node ) : <EOL> self . _is_view_class = False </s>
