| 
						
						
							
								
							
						
						
					 | 
					 | 
					@ -3,13 +3,44 @@ This file will describe how a site is loaded
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					"""
 | 
					 | 
					 | 
					 | 
					"""
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					from cms.engine.config.structure import Layout, System
 | 
					 | 
					 | 
					 | 
					from cms.engine.config.structure import Layout, System
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					from cms import disk, cloud
 | 
					 | 
					 | 
					 | 
					from cms import disk, cloud
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					import cms
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import copy
 | 
					 | 
					 | 
					 | 
					import copy
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import json
 | 
					 | 
					 | 
					 | 
					import json
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import io
 | 
					 | 
					 | 
					 | 
					import io
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					import os
 | 
					 | 
					 | 
					 | 
					import os
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					from jinja2 import Environment, BaseLoader, FileSystemLoader
 | 
					 | 
					 | 
					 | 
					from jinja2 import Environment, BaseLoader, FileSystemLoader
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					from datetime import datetime
 | 
					 | 
					 | 
					 | 
					from datetime import datetime
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					import mistune
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					from mistune import markdown
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					from flask import make_response, render_template
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					import numpy as np
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					import pandas as pd
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					class RequestController :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    def __init__(self,_route):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        self._routes = _route
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    def isfile(self,request):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        #
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # call self.exists to determin if this is an actual file or not
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        return '.' in request.path
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    def isroute(self,request):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # return '/'.join(request.path[1:].split('/')[:2])  in self._routes
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        return self.get_route(request) in self._routes
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        return False
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    def isapi(self,request):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        return 'api' in request.path
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    def get_route(self,request):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _items = request.path[1:].split('/')
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _items = _items if _items[-1] != '' else _items[:-1]
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        N = len(_items) + 1
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _names = []
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        for i in range(1, len(_items) + 1):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            _names.append('/'.join(_items[:i]))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _names=[_item for _item in _names if _item in self._routes]
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        return _names[-1] if _names else None
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					class IOConfig:
 | 
					 | 
					 | 
					 | 
					class IOConfig:
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    """
 | 
					 | 
					 | 
					 | 
					    """
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -19,8 +50,11 @@ class IOConfig:
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        self._config = {'system':{},'layout':{},'plugins':{}}
 | 
					 | 
					 | 
					 | 
					        self._config = {'system':{},'layout':{},'plugins':{}}
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        self._caller = None
 | 
					 | 
					 | 
					 | 
					        self._caller = None
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        self._location= _args['location'] if 'location' in _args else None   
 | 
					 | 
					 | 
					 | 
					        self._location= _args['location'] if 'location' in _args else None   
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        self._logs = []
 | 
					 | 
					 | 
					 | 
					        self._logs = []
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    def get(self,_key) :
 | 
					 | 
					 | 
					 | 
					    def get(self,_key) :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        #
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # @TODO: Include elements to be skipped (just in case & for security reasons)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if not _key :
 | 
					 | 
					 | 
					 | 
					        if not _key :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            return self._config
 | 
					 | 
					 | 
					 | 
					            return self._config
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        _keys = _key.split('.') if '.' in _key else [_key]
 | 
					 | 
					 | 
					 | 
					        _keys = _key.split('.') if '.' in _key else [_key]
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -34,6 +68,11 @@ class IOConfig:
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            
 | 
					 | 
					 | 
					 | 
					            
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        return _object
 | 
					 | 
					 | 
					 | 
					        return _object
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    def set(self,_expr,value):
 | 
					 | 
					 | 
					 | 
					    def set(self,_expr,value):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        """
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        Set the value of an attribute given the path with dot of the attribute
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _expr   expression of the attribute e.g: person.age
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        value   value to be set for the attribute
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        """
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if len(_expr.split('.')) == 1 :
 | 
					 | 
					 | 
					 | 
					        if len(_expr.split('.')) == 1 :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            self._config[_expr] = value
 | 
					 | 
					 | 
					 | 
					            self._config[_expr] = value
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        else:
 | 
					 | 
					 | 
					 | 
					        else:
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -62,7 +101,16 @@ class Initialization (IOConfig):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        #
 | 
					 | 
					 | 
					 | 
					        #
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        # Invoke initialization
 | 
					 | 
					 | 
					 | 
					        # Invoke initialization
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        self.reload()
 | 
					 | 
					 | 
					 | 
					        self.reload()
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        #
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if self._caller and self._caller.secure :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            self.secure = self._caller.secure
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        else: 
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            self.secure = cms.secure.Manager(config = self._config)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        
 | 
					 | 
					 | 
					 | 
					        
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        #
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # Log initializaton ...
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        #
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        self.log(action='init.security',module='site.init',input= self.secure._permissions.to_dict(orient='records'))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    def reload (self):
 | 
					 | 
					 | 
					 | 
					    def reload (self):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        _args  = self._args
 | 
					 | 
					 | 
					 | 
					        _args  = self._args
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        self._config = self.read_config(**_args)
 | 
					 | 
					 | 
					 | 
					        self._config = self.read_config(**_args)
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -80,6 +128,8 @@ class Initialization (IOConfig):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        
 | 
					 | 
					 | 
					 | 
					        
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        self.menu()
 | 
					 | 
					 | 
					 | 
					        self.menu()
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        self.plugins()    
 | 
					 | 
					 | 
					 | 
					        self.plugins()    
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					   
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    def read_config(self,**_args) :
 | 
					 | 
					 | 
					 | 
					    def read_config(self,**_args) :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        _config = {}
 | 
					 | 
					 | 
					 | 
					        _config = {}
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if 'path' in _args :
 | 
					 | 
					 | 
					 | 
					        if 'path' in _args :
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -104,7 +154,9 @@ class Initialization (IOConfig):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            
 | 
					 | 
					 | 
					 | 
					            
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            pass
 | 
					 | 
					 | 
					 | 
					            pass
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        _context = self.get('system.context')
 | 
					 | 
					 | 
					 | 
					        _context = self.get('system.context')
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					        _context = _context[:-1] if _context.endswith('/') else _context
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # _context = f'{_context}/' if _context != "" and not _context.endswith("/") else _context
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # _context = f'{_context}/files'
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if self._caller :
 | 
					 | 
					 | 
					 | 
					        if self._caller :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            #
 | 
					 | 
					 | 
					 | 
					            #
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            # There is a parent context we need to account and we are updating the current context to reflect the caller context
 | 
					 | 
					 | 
					 | 
					            # There is a parent context we need to account and we are updating the current context to reflect the caller context
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -114,7 +166,6 @@ class Initialization (IOConfig):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            # updating the configuratioin
 | 
					 | 
					 | 
					 | 
					            # updating the configuratioin
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            _iconURI = '/'.join(["",_parentContext,self._caller.get('system.icon')])
 | 
					 | 
					 | 
					 | 
					            _iconURI = '/'.join(["",_parentContext,self._caller.get('system.icon')])
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            
 | 
					 | 
					 | 
					 | 
					            
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            # print ([self._caller.get('system.context'), _parentContext,_context])
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            if self._caller.get('system.context') != '':
 | 
					 | 
					 | 
					 | 
					            if self._caller.get('system.context') != '':
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                _parentContext = "/"+_parentContext
 | 
					 | 
					 | 
					 | 
					                _parentContext = "/"+_parentContext
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                _context = "/"+_context
 | 
					 | 
					 | 
					 | 
					                _context = "/"+_context
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -162,13 +213,14 @@ class Initialization (IOConfig):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        _context = self.get('system.context')
 | 
					 | 
					 | 
					 | 
					        _context = self.get('system.context')
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        _logo = self.get('system.logo')
 | 
					 | 
					 | 
					 | 
					        _logo = self.get('system.logo')
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        _root = self.get('layout.root')
 | 
					 | 
					 | 
					 | 
					        _root = self.get('layout.root')
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if self.get('system.source.id') == 'cloud' :
 | 
					 | 
					 | 
					 | 
					        # if self.get('system.source.id') == 'cloud' :
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            _icon = f'{_context}/api/cloud/download?doc={_logo}'
 | 
					 | 
					 | 
					 | 
					        #     _icon = f'{_context}/api/cloud/download?doc={_logo}'
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        else:
 | 
					 | 
					 | 
					 | 
					        # else:
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            _icon = f'{_context}/api/disk/read?uri={_logo}'
 | 
					 | 
					 | 
					 | 
					        #     _icon = f'{_context}/api/disk/read?uri={_logo}'
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            # _root = f'{_context}/api/disk/read?uri={_root}'
 | 
					 | 
					 | 
					 | 
					        _icon = f'{_context}/{_logo}'.replace(_root,'')       
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        
 | 
					 | 
					 | 
					 | 
					        
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        # self.set('layout.root',_root)
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        self.set('system.icon',_icon)
 | 
					 | 
					 | 
					 | 
					        self.set('system.icon',_icon)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        self.set('system.logo',_icon)
 | 
					 | 
					 | 
					 | 
					        self.set('system.logo',_icon)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        #
 | 
					 | 
					 | 
					 | 
					        #
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -215,10 +267,6 @@ class Initialization (IOConfig):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        #
 | 
					 | 
					 | 
					 | 
					        #
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        # At this point the entire menu is build and we need to have it sorted
 | 
					 | 
					 | 
					 | 
					        # At this point the entire menu is build and we need to have it sorted
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        self.order()
 | 
					 | 
					 | 
					 | 
					        self.order()
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        # _labels = list(self.get('layout.menu').keys())
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        # self.log(action='init.menu',module='menu',input=_labels)
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        # print (self.get('layout.menu'))
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        # print (_object)
 | 
					 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    def order(self,**_args):
 | 
					 | 
					 | 
					 | 
					    def order(self,**_args):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if self.get('layout.order.menu') :
 | 
					 | 
					 | 
					 | 
					        if self.get('layout.order.menu') :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            _sorted = {}
 | 
					 | 
					 | 
					 | 
					            _sorted = {}
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					 | 
					@ -269,12 +317,14 @@ class Initialization (IOConfig):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        _parentContext = self.get('system.parentContext')
 | 
					 | 
					 | 
					 | 
					        _parentContext = self.get('system.parentContext')
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        _map        = {}
 | 
					 | 
					 | 
					 | 
					        _map        = {}
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        _plugins = {}
 | 
					 | 
					 | 
					 | 
					        _plugins = {}
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if self.get('system.source.id') == 'cloud' :
 | 
					 | 
					 | 
					 | 
					        # if self.get('system.source.id') == 'cloud' :
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            _plugins = cloud.plugins(_context)
 | 
					 | 
					 | 
					 | 
					        #     _plugins = cloud.plugins(_context)
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        else:
 | 
					 | 
					 | 
					 | 
					        # else:
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            _plugins = disk.plugins(context=_context)
 | 
					 | 
					 | 
					 | 
					        #     _plugins = disk.plugins(context=_context)
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        _uri = 'api/system/debug'
 | 
					 | 
					 | 
					 | 
					        _uri = f'{_context}/api/system/debug'
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        _uri = _uri if not _context else f'{_context}/{_uri}'
 | 
					 | 
					 | 
					 | 
					        if _uri.startswith('/') :
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            _uri = _uri[1:]
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # _uri = _uri if not _context else f'{_context}/{_uri}'
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        _plugins[_uri] = self.debug
 | 
					 | 
					 | 
					 | 
					        _plugins[_uri] = self.debug
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if os.path.exists(_folder) and self.get('plugins'):
 | 
					 | 
					 | 
					 | 
					        if os.path.exists(_folder) and self.get('plugins'):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            
 | 
					 | 
					 | 
					 | 
					            
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -289,6 +339,9 @@ class Initialization (IOConfig):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                        if _pointer :
 | 
					 | 
					 | 
					 | 
					                        if _pointer :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                            _uri = f"api/{_filename}/{_module}"
 | 
					 | 
					 | 
					 | 
					                            _uri = f"api/{_filename}/{_module}"
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                            _uri = f"{_context}/{_uri}" if _context else _uri
 | 
					 | 
					 | 
					 | 
					                            _uri = f"{_context}/{_uri}" if _context else _uri
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                            if (_uri.startswith("/")) :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                                _uri = _uri[1:]
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                            
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                            _map[_uri] = _pointer
 | 
					 | 
					 | 
					 | 
					                            _map[_uri] = _pointer
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                            if _parentContext :
 | 
					 | 
					 | 
					 | 
					                            if _parentContext :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                                # _uri = f"{_parentContext}/{_context}"
 | 
					 | 
					 | 
					 | 
					                                # _uri = f"{_parentContext}/{_context}"
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -306,7 +359,9 @@ class Initialization (IOConfig):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            # Updating plugins from disk/cloud
 | 
					 | 
					 | 
					 | 
					            # Updating plugins from disk/cloud
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            _plugins = _map if not _plugins else dict(_plugins,**_map)
 | 
					 | 
					 | 
					 | 
					            _plugins = _map if not _plugins else dict(_plugins,**_map)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        #
 | 
					 | 
					 | 
					 | 
					        #
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # if we have login enabled we should add them as a plugins
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        #
 | 
					 | 
					 | 
					 | 
					        #
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        self.set('plugins',_plugins)
 | 
					 | 
					 | 
					 | 
					        self.set('plugins',_plugins)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        self.log(action='init.plugins',module='plugins',input=list(_plugins.keys()))
 | 
					 | 
					 | 
					 | 
					        self.log(action='init.plugins',module='plugins',input=list(_plugins.keys()))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					 | 
					@ -314,39 +369,274 @@ class Site(Initialization) :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    def __init__(self,**_args):
 | 
					 | 
					 | 
					 | 
					    def __init__(self,**_args):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        super().__init__(**_args)
 | 
					 | 
					 | 
					 | 
					        super().__init__(**_args)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        self._config['system']['portal'] = (self.get('system.routes')) == None
 | 
					 | 
					 | 
					 | 
					        self._config['system']['portal'] = (self.get('system.routes')) == None
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    def html(self,_uri,_id) :
 | 
					 | 
					 | 
					 | 
					        self._routes = []
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        _handler = cloud if self.get('system.source.id') == 'cloud' else disk
 | 
					 | 
					 | 
					 | 
					        if self.get('system.routes') :
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        _html = _handler.html(_uri, self.get(None))
 | 
					 | 
					 | 
					 | 
					            self._routes = list(self.get('system.routes').keys())
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        return " ".join([f'<div id="{_id}"> ',_html,"</div>"])
 | 
					 | 
					 | 
					 | 
					        if self._caller :
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    def read(self,_uri) :
 | 
					 | 
					 | 
					 | 
					            self._routes = self._caller._routes
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        self.inspect = RequestController(self._routes)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        #
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # let's update the plugins
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        #
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if self.secure.method() in ['oauth2.0','oauth20','oauth2'] :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            _plugins = self.get('plugins')
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            _plugins['api/oauth2/authorize'] = cms.authorizationURL
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            _plugins['api/oauth2/final'] = cms.oauthFinalize
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            self.set('plugins',_plugins)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    def exists (self,uri):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        path = []
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if self.get('layout.location'):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            path.append(self.get('layout.location'))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if self.get('layout.root') not in uri :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            path.append(self.get('layout.root'))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        path.append(uri)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        return os.path.exists( os.sep.join(path))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    # def _html(self,_uri,_id,request) :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    #     if self.secure.allow(request=request):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    #         _handler = cloud if self.get('system.source.id') == 'cloud' else disk
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    #         _html = _handler.html(_uri, self.get(None))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    #         #
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    #         # maybe apply the environment here ??
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    #         return " ".join([f'<div id="{_id}"> ',_html,"</div>"])
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    #     else:
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    #         None
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    def mimeType(self,uri):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _extension = uri.split('.')[-1].strip().lower()
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _mimeType = 'application/octet-stream'
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if _extension in ['css','js','csv','html','md'] :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            _mimeType = f'text/{_extension}'.replace('md','html')
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            if _extension == 'js' :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                _mimeType = 'text/javascript'
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        elif _extension in ['png','jpg','jpeg'] :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            _mimeType = f'image/{_extension}'
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        return _mimeType
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    def path(self,_uri):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        path = []
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if self.get('layout.location'):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            path.append(self.get('layout.location'))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if self.get('layout.root') not in _uri :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            path.append(self.get('layout.root'))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        path.append(_uri)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        return os.sep.join(path)  
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    def html (self,_request):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _uri = self.uri(_request)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _mimeType = self.mimeType(_uri)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        f = open(self.path(_uri),'r')
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _content =  f.read() #_handler.html(_uri, self.get(None))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        f.close()
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if 'md' in _mimeType or 'html' in _mimeType :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            # _content = f'<div>{_content}</div>'
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            if _uri.split('.')[-1].strip().lower() == 'md':
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                _content = mistune.html(_content).replace(""",'"').replace("<","<").replace(">",">") if _uri[-2:] in ['md','MD','Md','mD'] else _content
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                _content = f"<div>{_content}</div>" #if 'dom' not in _request.headers else f'<div id="{_request.headers['dom']}">{_content}</div>'
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            else:
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                _env = Environment(loader=BaseLoader()).from_string(_content)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                _content = str(_env.render(**self.get(None)))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            pass
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        return _content,_mimeType
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    def uri(self,request):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if 'uri' in request.headers or 'uri' in request.args :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            return request.headers['uri'] if 'uri' in request.headers else request.args.get('uri',None)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        else:
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            _route  =  self.inspect.get_route(request)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            #
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            # The route doesn't have any forward slashes nor slash at the end
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            #
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            file    =  request.path.replace(f'{_route}','')
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            #
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            if file.startswith('//') or file.startswith('/') :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                # NOTE: false positive if file.startswith('/') is used
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                file = file[2:] if file.startswith('//') else file[1:]
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            return file if file.strip() not in ['',None,'/'] else self.get('layout.index')
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # # file = '/'.join(request.path[1:].split('/')[1:])
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # file = request.path[1:]
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # _isapi = 'api' in request.path
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # _isroute = '/'.join(request.path[1:].split('/')[:2])  in self._routes
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # _isfile  = '.' in request.path
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # return file if _isfile and not _isroute else self.get('layout.index')
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    def read(self,request) :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _kwargs = {'allow':0}
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # if self.secure.allow(request=request):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _uri = self.uri(request)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        _handler = cloud if self.get('system.source.id') == 'cloud' else disk
 | 
					 | 
					 | 
					 | 
					        _handler = cloud if self.get('system.source.id') == 'cloud' else disk
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        return _handler.read(uri=_uri, config=self.get(None))
 | 
					 | 
					 | 
					 | 
					        _extension = _uri.split('.')[1].lower()
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _mimeType = self.mimeType(_uri)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if _extension.strip() in ['md','txt','html','js','css'] :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            _content,_mimeType = self.html(request)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        else:
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            #
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            # Opening a binary file
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            f = open(self.path(_uri),'rb')
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            _content = io.BytesIO(f.read())
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            f.close()
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            # _content,_ =  _handler.read(uri=_uri, config=self.get(None))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _kwargs = {'allow':1,'mimeType':_mimeType,'extension':_extension,
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                    'path':self.path(_uri),
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                    'uri':_uri,'request':request.path}
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        self.log(action='file.read',module='site.read',input=_kwargs)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if _content :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            return _content, _mimeType 
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        return None, 'plain/html'
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # if 'html' in _mimetype :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            #     _args = {'layout':self.get('layout'),'system':self.get('system')}
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            #     _content = _content.decode('utf-8') if type(_content) == bytes else _content
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            #     _env = Environment(loader=BaseLoader()).from_string(_content)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            #     _content = _env.render(**_args)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            # return _content,_mimetype
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # return None,'plain/html'
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    def render (self,**_args):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        """
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        :id target of the dom or jinja
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        :request    incoming request
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        :uri        uri to read from disk ...
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        """
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # _site = self._sites[_appid] if _appid else self._sites[self._id]
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _id = _args.get('id')
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # _uri= _args['uri']
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _request = _args['request']
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _uri = self.uri(_request)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _kwargs = {'layout':self.get('layout')}
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _system = self.get('system')
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        for k in ['source','app'] :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            if k in _system :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                del _system[k]
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _kwargs['system'] = _system
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _cookies = json.loads(_request.cookies.get(self.secure._authContext ,"{}"))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if _cookies :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            _kwargs['username'] = _cookies['username']
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _html,_mimeType = self.html(_request) 
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # _kwargs[_id] = f'<div id="{_id}">{_html}</div>'
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # return _kwargs
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # _html = f'<div id="{_id}">{_html}</div>'
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if _html :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            _env = Environment(loader=BaseLoader()).from_string(f'<div id="{_id}">{_html}</div>')
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            _kwargs[_id] = str(_env.render(**_kwargs))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            return _kwargs
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        return None
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    def apply_tags (self,_html):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _kwargs = {'layout':self.get('layout'),'system':self.get('system')}
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _env = Environment(loader=BaseLoader()).from_string(f'<div>{_html}</div>')
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        return _env.render(**_kwargs)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    def run(self,_request) :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _plugins = self.get('plugins')
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _data = "<div align='center'><h2>404</h2></div>"
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _mimeType = 'plain/html'
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _code = 404
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _key = _request.path[1:] #if self.get('system.context') != '' else _request.path[1:]
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # print ([_key,_key in list(_plugins.keys())])
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # print (list (_plugins.keys()))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if _plugins and _key in _plugins:
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            _mimeType = 'application/octet-stream'
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            _pointer = _plugins.get(_key) 
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            if hasattr(_pointer,'mimetype'):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                _mimeType = _pointer.mimetype
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                _data = _pointer(request=_request,config=self.get(None))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                if hasattr(_pointer,'method') and  _request.method not in _pointer.method :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                    _data = "<div align='center'><h2>404</h2></div>"
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                    
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            elif not hasattr(_pointer,'mimetype'):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                _data,_mimeType = _pointer(request=_request,config=self.get(None))
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                if 'html' in _mimeType  :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                    _data = self.apply_tags(_data)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            if type(_data) == pd.DataFrame :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                _data = _data.to_json(orient='records')
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            elif type(_data)  in [dict,list] :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                _data = json.dumps(_data)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        #     #
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        #     # return the ata
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        _code = _code if not _data else 200
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # resp = make_response(_data)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # resp.status_code = _code
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # resp.headers['Content-Type'] = _mimeType
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # resp.headers['Content-Disposition'] = 'inline'
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        return _data,_code,{"Content-Type":_mimeType}
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					class QCMS:
 | 
					 | 
					 | 
					 | 
					class QCMS:
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    def __init__(self,**_args):
 | 
					 | 
					 | 
					 | 
					    def __init__(self,**_args):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        _app = Site(**_args)
 | 
					 | 
					 | 
					 | 
					        _app = Site(**_args)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        self._id = _app.get('system.context') #if _app.get('system.context') else 'main'
 | 
					 | 
					 | 
					 | 
					        self._id = _app.get('system.context') #if _app.get('system.context') else 'main'
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        self._sites = {self._id:_app}
 | 
					 | 
					 | 
					 | 
					        # if self._id == '' :
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        #     self._id = '/'
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        self._sites = {self._id:_app, '/':_app}
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        self._routes = []
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        if _app.get('system.routes') :
 | 
					 | 
					 | 
					 | 
					        if _app.get('system.routes') :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            _routes = _app.get('system.routes')
 | 
					 | 
					 | 
					 | 
					            _routes = _app.get('system.routes')
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            
 | 
					 | 
					 | 
					 | 
					            
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            for _name in _routes :
 | 
					 | 
					 | 
					 | 
					            for _name in _routes :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                self._routes.append(_name)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                _path = _routes[_name]['path']
 | 
					 | 
					 | 
					 | 
					                _path = _routes[_name]['path']
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                self._sites[_name] = Site(context=_name,path=_path,caller=_app)
 | 
					 | 
					 | 
					 | 
					                self._sites[_name] = Site(context=_name,path=_path,caller=_app)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    def render(self,_uri,_id,_appid=None):
 | 
					 | 
					 | 
					 | 
					                # self._sites[f'{_name}/']  = self._sites[_name]
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        _site = self._sites[_appid] if _appid else self._sites[self._id]
 | 
					 | 
					 | 
					 | 
					        
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        _args = {'layout':_site.get('layout')}
 | 
					 | 
					 | 
					 | 
					        
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        _system = _site.get('system')
 | 
					 | 
					 | 
					 | 
					        self.inspect = RequestController(self._routes)
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        for k in ['source','app'] :
 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					            if k in _system :
 | 
					 | 
					 | 
					 | 
					    def _render(self,request):
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					                del _system[k]
 | 
					 | 
					 | 
					 | 
					        _site = self.get(request)
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        _args['system'] = _system
 | 
					 | 
					 | 
					 | 
					        _args =  _site.render(request=request,id='index')
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        _html = _site.html(_uri,_id)
 | 
					 | 
					 | 
					 | 
					        return render_template('index.html',**_args)
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        
 | 
					 | 
					 | 
					 | 
					    def _read(self,request):
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        _env = Environment(loader=BaseLoader()).from_string(_html)
 | 
					 | 
					 | 
					 | 
					        _site = self.get(request)
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        _args[_id] = str(_env.render(**_args))
 | 
					 | 
					 | 
					 | 
					        return _site.read(request)
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        return _args
 | 
					 | 
					 | 
					 | 
					    def delegate(self,request):
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        isfile = self.inspect.isfile(request)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        isapi  = self.inspect.isapi(request)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        isroute= self.inspect.isroute(request)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if not isapi and not isfile:
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            return self._render(request)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        #
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # # let's check on files to be services (assumption is that they should have an extension)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        # The following propositional logic is as such
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        #   (isfile and isroute) or (isfile and not isroute) -> isfile (isroute is optional)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if isfile  :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            _content,_mimeType = self._read(request)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            return _content,200,{'Content-Type':_mimeType}
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if isapi :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            _site = self.get(request)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            return _site.run(request)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    def get(self,request=None) :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        if request :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            if self.inspect.isroute(request) :
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                self._id = self.inspect.get_route(request)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            else:
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					                self._id = ''
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        else:
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					            self._id = ''
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        return self._sites[self._id]
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    def set(self,_id):
 | 
					 | 
					 | 
					 | 
					    def set(self,_id):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        self._id = _id
 | 
					 | 
					 | 
					 | 
					        self._id = _id
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					    def get(self,_id=None):
 | 
					 | 
					 | 
					 | 
					    def allow(self,id, request) :
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					        return self._sites[self._id] if not _id else self._sites[_id]
 | 
					 | 
					 | 
					 | 
					        _site = self.get(id)
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        return _site.secure.allow(request=request)
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					    def has(self,_id):
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					        return _id in self._sites
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					   
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					 | 
					   
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
					 | 
					 | 
					
 
 |