#NEWLINE# def process_all( self , function ) : #NEWLINE# #INDENT# self . log . debug ( ( 'get: %s' % function ) ) #NEWLINE# static_file = re . match ( '^/*res\\/(.*)$' , function ) #NEWLINE# attr_call = re . match ( '^\\/*(\\w+)\\/(\\w+)\\?{0,1}(\\w*\\={1}\\w+\\${0,1})*$' , function ) #NEWLINE# if ( ( function == '/' ) or ( not function ) ) : #NEWLINE# #INDENT# should_call_main = ( not hasattr ( self . client , 'root' ) ) #NEWLINE# if should_call_main : #NEWLINE# #INDENT# self . client . root = self . main ( * self . server . userdata ) #NEWLINE# #UNINDENT# self . send_response ( 200 ) #NEWLINE# self . send_header ( 'Content-type' , 'text/html' ) #NEWLINE# self . end_headers ( ) #NEWLINE# self . wfile . write ( encode_text ( '<!DOCTYPE html>\n' ) ) #NEWLINE# self . wfile . write ( encode_text ( '<html>\n<head>\n' ) ) #NEWLINE# self . wfile . write ( encode_text ( '<meta content=\'text/html;charset=utf-8\' http-equiv=\'Content-Type\'>\n                <meta content=\'utf-8\' http-equiv=\'encoding\'>\n                <meta name="viewport" content="width=device-width, initial-scale=1.0">' ) ) #NEWLINE# self . wfile . write ( encode_text ( self . client . css_header ) ) #NEWLINE# self . wfile . write ( encode_text ( self . client . html_header ) ) #NEWLINE# self . wfile . write ( encode_text ( self . client . script_header ) ) #NEWLINE# self . wfile . write ( encode_text ( '\n</head>\n<body>\n' ) ) #NEWLINE# html = self . client . root . repr ( self . client ) #NEWLINE# self . wfile . write ( encode_text ( html ) ) #NEWLINE# self . wfile . write ( encode_text ( self . client . html_footer ) ) #NEWLINE# self . wfile . write ( encode_text ( '</body>\n</html>' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if static_file : #NEWLINE# #INDENT# static_paths = [ os . path . join ( os . path . dirname ( __file__ ) , 'res' ) ] #NEWLINE# static_paths . extend ( self . _app_args . get ( 'static_paths' , ( ) ) ) #NEWLINE# filename = None #NEWLINE# found = False #NEWLINE# for s in reversed ( static_paths ) : #NEWLINE# #INDENT# filename = os . path . join ( s , static_file . groups ( ) [ 0 ] ) #NEWLINE# if os . path . exists ( filename ) : #NEWLINE# #INDENT# found = True #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# if ( not found ) : #NEWLINE# #INDENT# self . send_response ( 404 ) #NEWLINE# return #NEWLINE# #UNINDENT# ( mimetype , encoding ) = mimetypes . guess_type ( filename ) #NEWLINE# self . send_response ( 200 ) #NEWLINE# self . send_header ( 'Content-type' , ( mimetype if mimetype else 'application/octet-stream' ) ) #NEWLINE# if self . server . enable_file_cache : #NEWLINE# #INDENT# self . send_header ( 'Cache-Control' , 'public, max-age=86400' ) #NEWLINE# #UNINDENT# self . end_headers ( ) #NEWLINE# with open ( filename , 'rb' ) as f : #NEWLINE# #INDENT# content = f . read ( ) #NEWLINE# self . wfile . write ( content ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if attr_call : #NEWLINE# #INDENT# params = list ( ) #NEWLINE# param_dict = parse_qs ( urlparse ( function ) . query ) #NEWLINE# for k in param_dict : #NEWLINE# #INDENT# params . append ( param_dict [ k ] ) #NEWLINE# #UNINDENT# ( widget , function ) = attr_call . group ( 1 , 2 ) #NEWLINE# try : #NEWLINE# #INDENT# ( content , headers ) = get_method_by ( get_method_by ( self . client . root , widget ) , function ) ( * params ) #NEWLINE# if ( content is None ) : #NEWLINE# #INDENT# self . send_response ( 503 ) #NEWLINE# return #NEWLINE# #UNINDENT# self . send_response ( 200 ) #NEWLINE# #UNINDENT# except IOError : #NEWLINE# #INDENT# self . log . error ( ( 'attr %s/%s call error' % ( widget , function ) ) , exc_info = True ) #NEWLINE# self . send_response ( 404 ) #NEWLINE# return #NEWLINE# #UNINDENT# except ( TypeError , AttributeError ) : #NEWLINE# #INDENT# self . log . error ( ( 'attr %s/%s not available' % ( widget , function ) ) ) #NEWLINE# self . send_response ( 503 ) #NEWLINE# return #NEWLINE# #UNINDENT# for k in headers . keys ( ) : #NEWLINE# #INDENT# self . send_header ( k , headers [ k ] ) #NEWLINE# #UNINDENT# self . end_headers ( ) #NEWLINE# self . wfile . write ( content )