def form_example(): err = None genResult = None message = "" source = None gen = None if request.method == 'POST': try: source = request.form.get('source') alias = request.form.get('generator') generatorId = Generators.generatorIdForAlias(alias) outputType = request.form.get(generatorId + '-output') gen = Generators.get(generatorId) if gen is None: raise Exception("invalid generator %s", generatorId) genResult = gen.generate(alias, source, outputType, useCached=True) if not genResult.isValid(): raise Exception("could not generate %s for %s", outputType, generatorId) except Exception as ex: err = ex return index(err=err, message=message, source=source, gen=gen, genResult=genResult)
def testGetGenerator(self): generators = ["graphviz", "mscgen", "plantuml"] for generator in generators: gen = Generators.get(generator) assert gen is not None info = gen.getHtmlInfo() if debug: print(info)
def renderForWikiExtension(): """ endpoint for diagrams extension""" generator = request.form.get('generator') source = request.form.get('source') types = request.form.get('types') gen = Generators.get(generator) ip = request.remote_addr result = gen.generate('dot', source, 'png') json = result.asJson(request.base_url) return json
def renderForWikiExtension(): """ endpoint for diagrams extension""" generator=getParam('generator') source=getParam('source') targetFormat=getParam('types') if targetFormat is None or targetFormat=="None": targetFormat="png" gen=Generators.get(generator) # use for DOS attack prevention ip=request.remote_addr result=gen.generate('dot',source,targetFormat) # force SSL json=result.asJson(request.base_url.replace('http:','https:')) return json
def testGenerateResult(self): ''' test provoked error ''' genid = Generators.generatorIdForAlias("plantuml") gen = Generators.get(genid) # provoke an error result = gen.generate('unknownalias', 'garbage input', "png") json = result.asJson('http://www.doe.com') print(json) # there is an image version of the error assert os.path.isfile(result.path) # which needs to be remove to make the test reproducible os.remove(result.path) assert "error" in json
def check(generator): gen = Generators.get(generator) if gen is not None: return gen.getHtmlInfo() else: return "%s is not a valid generator" % generator