def url(path="", lang=False): from pytonik.Router import Router from pytonik.util.Variable import Variable ront = Router() env_os = Variable() DS, p, url = "", "", "" seturl = ront.out("HTTP_HOST")+str(":")+str(env_os.out("SERVER_PORT", '')) if env_os.out( "HTTP_HOST") == "localhost" or env_os.out("HTTP_HOST") == "127.0.0.1" else env_os.out("HTTP_HOST") if ront.out("HTTPS", "") == 'on': url = str("https://") + seturl.replace(":80", "") + "/" + ront.alllanguages.get(ront.getLanguages(), ront.getLanguages()) if lang == True else str( "https://") + seturl.replace(":80", "") else: url = str("http://") + seturl.replace(":80", "") + "/" + ront.alllanguages.get(ront.getLanguages(), ront.getLanguages()) if lang == True else str("http://") + seturl.replace(":80", "") if path == "": DS = "" else: if path[:1] == "/": p = path[1:] DS = "/" else: p = path DS = "/" return url + DS + p
def url(self): osv = Variable() url = osv.out('REQUEST_URI', "") http_s = osv.out("HTTP_HOST") uri = "" if osv.out("SERVER_SOFTWARE", "") == AUTHOR: uri = url.split('/')[2:] else: if http_s == "127.0.0.1" or http_s == "localhost": uri = url.split('/')[2:] else: uri = url.split('/')[1:] return uri
except Exception as err: from http.server import BaseHTTPRequestHandler, HTTPServer try: import socket except Exception as err: from socket import socket try: import http.client as htp from http import client import urllib as urllib except Exception as err: import httplib as htp import urllib2 as urllib varb = Variable() vpath = "" def run(host="", path="", port=6060, server_pro="HTTP/1.1", ssl_ip="", ssl_port="", pr=False): server = HTTPServer path = str(path).replace("\\", "/") if path != "" else str( os.getcwd()).replace("\\", "/")
def __init__(self): osv = Variable() url = osv.out('REQUEST_URI', "") http_s = osv.out("HTTP_HOST") if osv.out("SERVER_SOFTWARE", "") == Version.AUTHOR: self.uri = url.split('/')[2:] else: if http_s == "127.0.0.1" or http_s == "localhost": self.uri = url.split('/')[2:] else: self.uri = url.split('/')[1:] self.add(self._e()) self.controllers = self.get('default_controllers') self.actions = self.get('default_actions') self.default_controllers = self.get('default_controllers') self.default_actions = self.get('default_actions') self.languages = self.get('default_languages') self.all_languages = self.get('languages', '') self.routes = self.get('default_routes', "") self.methodprefix = "" self.parameter = "" path_parts = self.uri # Get parameter from Query String pathparts_paramarray = os.environ.get("QUERY_STRING", '') pathparts_paramarrayOut = dict() if pathparts_paramarray != '': pairs = pathparts_paramarray.split('&') pathparts_paramarray = pairs for i in pairs: name, value = i.split('=', 2) pathparts_paramarray = {name: value} if name in pathparts_paramarray: pathparts_paramarray[name] = value else: pathparts_paramarray[name] = [ pathparts_paramarray[name], value ] pathparts_paramarrayOut.setdefault(name, value) else: pathparts_paramarrayOut = "" if len(path_parts): if Version.PYVERSION_MA < 3: path_parts = filter(None, path_parts) else: path_parts = list(filter(None, path_parts)) routes = self.get('route', '') if list(set(path_parts).intersection(routes.keys())): for s in path_parts: if s in routes: self.routes = s if self.routes in routes: self.methodprefix = routes[self.routes] else: self.methodprefix = "" # path_parts.append(path_parts.pop(-1)) if list(set(path_parts).intersection(self.all_languages.keys())): for s in path_parts: if s in self.all_languages: self.languages = s path_parts.append(path_parts.pop(-1)) controllers = self.get('default_controllers', '') if controllers: i = 0 path_parts = list(filter(None, path_parts)) for s in path_parts: if s is not self.languages: i += 1 if i == 1: self.controllers = s path_parts.append(path_parts.pop(-1)) ++i action = self.get('default_actions', '') if action: i = 0 for s in path_parts: if s is not self.controllers and s is not self.languages: i += 1 if i == 1: self.actions = s path_parts.append(path_parts.pop(-1)) ++i # Get Path from URI / convert it to parameter list_params = [] if pathparts_paramarray == None or pathparts_paramarray == "": if Version.PYVERSION_MA <= 2: lroutes = routes.iteritems() else: lroutes = routes.items() for k, getRouter in lroutes: if self.controllers == k: paraUri = getRouter.split('@') else: paraUri = [] if len(paraUri) > 0: if ':' not in paraUri[1]: getMapPara = [] else: getMapPara = paraUri[1].split(':') if self.controllers in routes: if len(getMapPara[1:]) > 0: new_para = path_parts[1:] if len(new_para) > 0: param_m = [] for i, para in enumerate(getMapPara[1:]): param_n = para if (len(new_para) - i) > 0: v_para = new_para[i] else: v_para = "" list_params.append(param_n) list_params.append(v_para) self.parameter = Helpers.covert_list_dict( list_params) else: for s in path_parts: if s is not self.controllers and s is not self.actions and s is not self.languages: list_params.append(s) path_parts.append(path_parts.pop(-1)) self.parameter = Helpers.covert_list_dict(list_params) else: self.parameter = pathparts_paramarrayOut path_parts.append(path_parts.pop(-1)) return None
### # Author : Betacodings # Author : [email protected] # Maintainer By: Emmanuel Martins # Maintainer Email: [email protected] # Created by Betacodings on 2029. ### from pytonik.Session import Session from pytonik.util.Variable import Variable from pytonik.Controllers import Controllers FSession = Session() FVariable = Variable() FControllers = Controllers() class Flash: def __getattr__(self, item): return item def __init__(self): return @staticmethod def message(message, showin="", key='flash'): option = { 'msg': message, 'controller': showin if showin != "" else "/".join( str(FVariable.out('HTTP_REFERER')).split('/')[3:])