Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #64

Merged
merged 8 commits into from
Jan 28, 2025
Merged

Dev #64

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## CHANGELOG

### [25.3.2] - Jan 28, 2025
- Allow `/` and `.` to be used in template names
- Updated code to call `JinjaFx()._jinjafx()` instead of `JinjaFx().jinjafx()`
- Updated exception handling during template generation

### [25.3.1] - Jan 23, 2025
- Fixed a regression where `jinjafx_input` wasn't working due to Output name validation

Expand Down Expand Up @@ -391,6 +396,7 @@
- Initial release


[25.3.2]: https://github.com/cmason3/jinjafx_server/compare/25.3.1...25.3.2
[25.3.1]: https://github.com/cmason3/jinjafx_server/compare/25.3.0...25.3.1
[25.3.0]: https://github.com/cmason3/jinjafx_server/compare/25.2.2...25.3.0
[25.2.2]: https://github.com/cmason3/jinjafx_server/compare/25.2.1...25.2.2
Expand Down
34 changes: 21 additions & 13 deletions jinjafx_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@

from http.server import HTTPServer, BaseHTTPRequestHandler
from jinja2 import __version__ as jinja2_version
from jinja2 import TemplateError

import jinjafx, os, io, socket, signal, threading, yaml, json, base64, time, datetime, resource
import re, argparse, hashlib, traceback, glob, hmac, uuid, struct, binascii, gzip, requests, ctypes, subprocess
import cmarkgfm, emoji

__version__ = '25.3.1'
__version__ = '25.3.2'

llock = threading.RLock()
rlock = threading.RLock()
Expand Down Expand Up @@ -516,7 +517,7 @@ def yaml_vault_tag(loader, node):
ocount = 0
ret = [0, None]

t = StoppableJinjaFx(jinjafx.JinjaFx().jinjafx, template, data.decode('utf-8'), gvars, ret)
t = StoppableJinjaFx(jinjafx.JinjaFx()._jinjafx, template, data.decode('utf-8'), gvars, ret)

if timelimit > 0:
while t.is_alive() and ((time.time() * 1000) - st) <= (timelimit * 1000):
Expand Down Expand Up @@ -583,17 +584,24 @@ def html_escape(text):
if ocount == 0:
raise Exception('nothing to output')

except Exception as e:
tb = traceback.format_exc()
match = re.search(r'[\s\S]*File "<(?:template|unknown)>", line ([0-9]+), in.*template', tb, re.IGNORECASE)
if match:
error = 'error[template.j2:' + match.group(1) + ']: ' + type(e).__name__ + ': ' + str(e)
elif 'yaml.SafeLoader' in tb:
error = 'error[vars.yml]: ' + type(e).__name__ + ': ' + str(e)
except TemplateError as e:
if hasattr(e, 'name') and e.name and hasattr(e, 'lineno') and e.lineno:
t = e.name.replace('Default', 'template.j2')
error = f'error[{t}:{e.lineno}]: {type(e).__name__}: {e}'

else:
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
error = 'error[jinjafx_server.py:' + str(exc_tb.tb_lineno) + ']: ' + type(e).__name__ + ': ' + str(e)
m = re.search(r'(?s:.*)File "(.+)", line ([0-9]+), .+ template', traceback.format_exc(), re.IGNORECASE | re.MULTILINE)
error = f'error[{m.group(1)}:{m.group(2)}]: {type(e).__name__}: {e}'

jsr = {
'status': 'error',
'error': error
}
self.error = error

except Exception as e:
xyz = sys.exc_info()
error = f'error[jinjafx_server.py:{xyz[2].tb_lineno}]: {type(e).__name__}: {e}'

jsr = {
'status': 'error',
Expand Down Expand Up @@ -1065,7 +1073,7 @@ def __init__(self, jinjafx, template, data, gvars, ret):

def run(self):
try:
self.ret[1] = self.jinjafx(self.template, self.data, self.gvars, 'Output', [], True)
self.ret[1] = self.jinjafx(self.template, self.data, self.gvars, 'Output', [], True, True)
self.ret[0] = 1

except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
packages=["jinjafx_server"],
include_package_data=True,
package_data={'': ['www/*', 'pandoc/reference.docx']},
install_requires=["jinjafx>=1.23.1", "requests", "cmarkgfm>=0.5.0", "emoji"],
install_requires=["jinjafx>=1.24.0", "requests", "cmarkgfm>=0.5.0", "emoji"],
entry_points={
"console_scripts": [
"jinjafx_server=jinjafx_server:main",
Expand Down
2 changes: 1 addition & 1 deletion www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-yaml/4.1.0/js-yaml.min.js" integrity="sha512-CSBhVREyzHAjAFfBlIBakjoRUKp5h7VSweP0InR/pAJyptH7peuhCsqAI/snV+TwZmXZqoUklpXp6R6wMnYf5Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dayjs/1.11.13/dayjs.min.js" integrity="sha512-FwNWaxyfy2XlEINoSnZh1JQ5TRRtGow0D6XcmAWmYCRgvqOUTnzCxPc9uF35u5ZEpirk1uhlPVA19tflhvnW1g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dayjs/1.11.13/plugin/relativeTime.min.js" integrity="sha512-MVzDPmm7QZ8PhEiqJXKz/zw2HJuv61waxb8XXuZMMs9b+an3LoqOqhOEt5Nq3LY1e4Ipbbd/e+AWgERdHlVgaA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="/d7ec0c8e/jinjafx_m.js"></script>
<script src="/b4c04dd7/jinjafx_m.js"></script>
</head>
<body>
<div id="overlay"></div>
Expand Down
2 changes: 1 addition & 1 deletion www/jinjafx_m.js
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,7 @@ function getStatusText(code) {
document.getElementById('ml-template-ok').onclick = function() {
var new_t = document.getElementById("t_name").value;

if (new_t.match(/^[A-Z][A-Z0-9_ -]*$/i)) {
if (new_t.match(/^[A-Z][A-Z0-9_ \/.-]*$/i)) {
var existing = '';
for (var p in templates) {
if (templates.hasOwnProperty(p)) {
Expand Down
4 changes: 2 additions & 2 deletions www/jinjafx_o.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,13 @@
}
else {
document.title = "Error";
document.body.innerHTML = "<div id=\"status\" class=\"alert alert-danger\"><strong><h4>JinjaFx Error</h4></strong><pre>"+ obj.error + "</pre></div>";
document.body.innerHTML = "<div id=\"status\" class=\"alert alert-danger\"><strong><h4>JinjaFx Error</h4></strong><pre>"+ window.opener.quote(obj.error) + "</pre></div>";
}
}
catch (e) {
console.log(e);
document.title = "Error";
document.body.innerHTML = "<div id=\"status\" class=\"alert alert-danger\"><strong><h4>Internal Error</h4></strong>" + e + "</div>";
document.body.innerHTML = "<div id=\"status\" class=\"alert alert-danger\"><strong><h4>Internal Error</h4></strong>" + window.opener.quote(e) + "</div>";
}
}
else {
Expand Down
2 changes: 1 addition & 1 deletion www/output.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/dayjs/1.11.13/dayjs.min.js" integrity="sha512-FwNWaxyfy2XlEINoSnZh1JQ5TRRtGow0D6XcmAWmYCRgvqOUTnzCxPc9uF35u5ZEpirk1uhlPVA19tflhvnW1g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dayjs/1.11.13/plugin/advancedFormat.min.js" integrity="sha512-oOF6H/+bcZjL9xEZ71lPxWSLn62axEgf6jDBuge0rTy7HjcMmWLQ7Y46WVC0m1hGibeYyTeHLi1ZUrZTvt2QxQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js" integrity="sha512-XMVd28F1oH/O71fzwBnV7HucLxVwtxf26XV8P4wPk26EDxuGZ91N8bsOttmnomcCD3CS5ZMRL50H0GgOHvegtg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="/09b3c467/jinjafx_o.js"></script>
<script src="/f4ceb754/jinjafx_o.js"></script>
</head>
<body>
<div id="status" class="alert alert-primary wait fw-bold">Generating Output...</div>
Expand Down