<s> from uliweb import Middleware <EOL> from uliweb . utils . common import request_url <EOL> from logging import getLogger <EOL> log = getLogger ( __name__ . rsplit ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] ) <EOL> class RecorderrMiddle ( Middleware ) : <EOL> ORDER = <NUM_LIT> <EOL> def process_response ( self , request , response ) : <EOL> from uliweb import settings , functions , json_dumps <EOL> import base64 <EOL> if not settings . get_var ( '<STR_LIT>' ) : <EOL> return response <EOL> S = functions . get_model ( '<STR_LIT>' ) <EOL> s = S . all ( ) . one ( ) <EOL> if not s or s . status == '<STR_LIT:E>' : <EOL> return response <EOL> if settings . get_var ( '<STR_LIT>' ) : <EOL> try : <EOL> text = response . data <EOL> except Exception as e : <EOL> text = str ( e ) <EOL> else : <EOL> text = '<STR_LIT>' <EOL> if not request . content_type : <EOL> post_data_is_text = True <EOL> else : <EOL> post_data_is_text = self . test_text ( request . content_type ) <EOL> if not post_data_is_text : <EOL> post_data = base64 . encodestring ( request . data ) <EOL> else : <EOL> post_data = json_dumps ( request . POST . to_dict ( ) ) <EOL> response_data_is_text = self . test_text ( response . content_type ) <EOL> if not response_data_is_text : <EOL> response_data = base64 . encodestring ( text ) <EOL> else : <EOL> response_data = text <EOL> R = functions . get_model ( '<STR_LIT>' ) <EOL> if request . user : <EOL> user_id = request . user . id <EOL> else : <EOL> user_id = None <EOL> max_content_length = settings . get_var ( '<STR_LIT>' ) <EOL> if len ( response_data ) > max_content_length : <EOL> msg = "<STR_LIT>" % max_content_length <EOL> log . info ( msg ) <EOL> response_data = msg <EOL> response_data_is_text = True <EOL> recorder = R ( method = request . method , <EOL> url = request_url ( request ) , <EOL> post_data_is_text = post_data_is_text , <EOL> post_data = post_data , user = user_id , <EOL> response_data = response_data , <EOL> response_data_is_text = response_data_is_text , <EOL> status_code = response . status_code , <EOL> ) <EOL> recorder . save ( ) <EOL> return response <EOL> def test_text ( self , content_type ) : <EOL> from uliweb . utils . common import match <EOL> from uliweb import settings <EOL> m = content_type . split ( '<STR_LIT:;>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> r = match ( m , settings . get_var ( '<STR_LIT>' ) ) <EOL> return r </s>
