def __init__(self, fileName): # Python script : read, normalize line separator self.fileName = fileName source = open(fileName).readlines() source = [elt.rstrip() for elt in source] source = '\n'.join(source) source = source + '\n' BaseScript.__init__(self, fileName, source, None)
def __init__(self, fileName): # Python script : read, normalize line separator self.fileName = fileName source = open(fileName).readlines() source = [ elt.rstrip() for elt in source ] source = '\n'.join(source) source = source+'\n' BaseScript.__init__(self, fileName, source, None)
class Script(BaseScript): """Python inside HTML""" def __init__(self, fileName): # pih (PythonInsideHTML) scripts : parse try: pih = PythonInsideHTML.PIH(fileName) except PythonInsideHTML.PIH_ParseError, msg: raise ParseError, msg pc = pih.pythonCode() BaseScript.__init__(self, fileName, pc, pih.getLineMapping())
class Script(BaseScript): """HTML inside Python""" def __init__(self, fileName): # hip (HTMLInsidePython) scripts try: hip = HIP.HIP(fileName) except HIP.ParseError, msg: raise ParseError, msg pc = hip.pythonCode() BaseScript.__init__(self, fileName, pc, None)
def Include(self, includedUrl, **args): """Include a document inside the current script output The other document is searched in current script directory If it's a script, it is run in the same namespace as the script ; if additional args are supplied they are added to the namespace If it's a plain document its content is sent to the standard output """ url = urlparse.urljoin(self.path, includedUrl) url_without_qs, qs = URLResolution.split_query(url) qs = k_utils.applyQueryConvention(qs) args.update(qs) fileName = URLResolution.translate_path(url_without_qs) if not fileName: raise IOError if os.path.isdir(fileName): # search an index file # if no one or more than one is found, an exception is raised indexFile = URLResolution.indexFile(fileName) fileName = os.path.join(fileName, indexFile) if url.endswith("/"): url = urlparse.urljoin(url, indexFile) else: url = urlparse.urljoin(url + "/", indexFile) elif not os.path.exists(fileName): # search for a file with name fileName.ext # with extension in htm, html, py, pih, hip, ks # if no one or more than one is found, an exception is raised ext = URLResolution.search(url_without_qs, fileName) fileName += ext fileExt = os.path.splitext(fileName)[1][1:] if not fileExt.lower() in k_config.handled_extensions: script = BaseScript(fileName, open(fileName).read(), {}) output = Output(script, 1, script.code) else: # create a Script object and keep track of the script from which # it was called (to localize errors when debugging) script = getScript(fileName) # set attributes for the included script script.url = url_without_qs script.parent = self.stack[-1] self.stack.append(script) # before execution, chdir to script dir saveDir = os.getcwd() thisDir = os.path.dirname(fileName) os.chdir(thisDir) if not thisDir in sys.path: sys.path.append(thisDir) output = script.render(self.nameSpace, **args) os.chdir(saveDir) script.loadTranslations(self.nameSpace, saveDir) self.stack.pop() sys.stdout.write(str(output)) self.output.append(output)
class Script(BaseScript): """Karrigell Service""" def __init__(self, fileName): # Python script : read, normalize line separator source = open(fileName).readlines() source = [elt.rstrip() for elt in source] source = '\n'.join(source) source = source + '\n' # list of functions available by a url self.functions = [] self.flag = False # if True, next token is a function name try: for info in tokenize.generate_tokens(open(fileName).readline): self.get_functions(info) except tokenize.TokenError, msg: pass BaseScript.__init__(self, fileName, source, None)
def Include(self,includedUrl,**args): """Include a document inside the current script output The other document is searched in current script directory If it's a script, it is run in the same namespace as the script ; if additional args are supplied they are added to the namespace If it's a plain document its content is sent to the standard output """ url=urlparse.urljoin(self.path,includedUrl) url_without_qs,qs=URLResolution.split_query(url) qs=k_utils.applyQueryConvention(qs) args.update(qs) fileName=URLResolution.translate_path(url_without_qs) if not fileName: raise IOError if os.path.isdir(fileName): # search an index file # if no one or more than one is found, an exception is raised indexFile=URLResolution.indexFile(fileName) fileName=os.path.join(fileName,indexFile) if url.endswith("/"): url=urlparse.urljoin(url,indexFile) else: url=urlparse.urljoin(url+"/",indexFile) elif not os.path.exists(fileName): # search for a file with name fileName.ext # with extension in htm, html, py, pih, hip, ks # if no one or more than one is found, an exception is raised ext=URLResolution.search(url_without_qs,fileName) fileName+=ext fileExt=os.path.splitext(fileName)[1][1:] if not fileExt.lower() in k_config.handled_extensions: script=BaseScript(fileName,open(fileName).read(),{}) output=Output(script,1,script.code) else: # create a Script object and keep track of the script from which # it was called (to localize errors when debugging) script=getScript(fileName) # set attributes for the included script script.url=url_without_qs script.parent=self.stack[-1] self.stack.append(script) # before execution, chdir to script dir saveDir=os.getcwd() thisDir=os.path.dirname(fileName) os.chdir(thisDir) if not thisDir in sys.path: sys.path.append(thisDir) output=script.render(self.nameSpace,**args) os.chdir(saveDir) script.loadTranslations(self.nameSpace,saveDir) self.stack.pop() sys.stdout.write(str(output)) self.output.append(output)
def __init__(self, fileName): pc = open(fileName).read().rstrip() pc = pc.replace('\r\n', '\n') # normalize line separator BaseScript.__init__(self, fileName, pc, None)
def __init__(self, fileName): pc=open(fileName).read().rstrip() pc = pc.replace('\r\n','\n') # normalize line separator BaseScript.__init__(self, fileName, pc, None)