<s> import urllib <EOL> from devserver . modules import DevServerModule <EOL> class SessionInfoModule ( DevServerModule ) : <EOL> """<STR_LIT>""" <EOL> logger_name = '<STR_LIT>' <EOL> def process_request ( self , request ) : <EOL> self . has_session = bool ( getattr ( request , '<STR_LIT>' , False ) ) <EOL> if self . has_session is not None : <EOL> self . _save = request . session . save <EOL> self . session = request . session <EOL> request . session . save = self . handle_session_save <EOL> def process_response ( self , request , response ) : <EOL> if getattr ( self , '<STR_LIT>' , False ) : <EOL> if getattr ( request , '<STR_LIT:user>' , None ) and request . user . is_authenticated ( ) : <EOL> user = '<STR_LIT>' % ( request . user . username , request . user . pk ) <EOL> else : <EOL> user = '<STR_LIT>' <EOL> self . logger . info ( '<STR_LIT>' , request . session . session_key , user ) <EOL> request . session . save = self . _save <EOL> self . _save = None <EOL> self . session = None <EOL> self . has_session = False <EOL> def handle_session_save ( self , * args , ** kwargs ) : <EOL> self . _save ( * args , ** kwargs ) <EOL> self . logger . info ( '<STR_LIT>' , self . session . session_key ) <EOL> class RequestDumpModule ( DevServerModule ) : <EOL> """<STR_LIT>""" <EOL> logger_name = '<STR_LIT>' <EOL> def process_request ( self , request ) : <EOL> req = self . logger . style . SQL_KEYWORD ( '<STR_LIT>' % ( request . method , '<STR_LIT:?>' . join ( ( request . META [ '<STR_LIT>' ] , request . META [ '<STR_LIT>' ] ) ) , request . META [ '<STR_LIT>' ] ) ) <EOL> for var , val in request . META . items ( ) : <EOL> if var . startswith ( '<STR_LIT>' ) : <EOL> var = var [ <NUM_LIT:5> : ] . replace ( '<STR_LIT:_>' , '<STR_LIT:->' ) . title ( ) <EOL> req += '<STR_LIT>' % ( self . logger . style . SQL_KEYWORD ( var ) , val ) <EOL> if request . META [ '<STR_LIT>' ] : <EOL> req += '<STR_LIT>' % ( self . logger . style . SQL_KEYWORD ( '<STR_LIT>' ) , request . META [ '<STR_LIT>' ] ) <EOL> if request . POST : <EOL> req += '<STR_LIT>' % self . logger . style . HTTP_INFO ( urllib . urlencode ( dict ( ( k , v . encode ( '<STR_LIT:utf8>' ) ) for k , v in request . POST . items ( ) ) ) ) <EOL> if request . FILES : <EOL> req += '<STR_LIT>' % self . logger . style . HTTP_NOT_MODIFIED ( urllib . urlencode ( request . FILES ) ) <EOL> self . logger . info ( '<STR_LIT>' , req ) <EOL> class ResponseDumpModule ( DevServerModule ) : <EOL> """<STR_LIT>""" <EOL> logger_name = '<STR_LIT>' <EOL> def process_response ( self , request , response ) : <EOL> res = self . logger . style . SQL_FIELD ( '<STR_LIT>' % response . status_code ) <EOL> res += '<STR_LIT:\n>' . join ( [ '<STR_LIT>' % ( self . logger . style . SQL_FIELD ( k ) , v ) <EOL> for k , v in response . _headers . values ( ) ] ) <EOL> self . logger . info ( '<STR_LIT>' , res ) </s>
