From 05e2a58fff4aca02ad7bd886c8edb95934a906af Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sat, 19 Apr 2025 13:21:18 +0800 Subject: [PATCH] bugfix --- appPublic/myTE.py | 14 ++++++++++++++ appPublic/sshx.py | 2 +- test/test.json | 4 ++++ test/test.tmpl | 2 ++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 test/test.json create mode 100644 test/test.tmpl diff --git a/appPublic/myTE.py b/appPublic/myTE.py index 0728638..e33f7fb 100755 --- a/appPublic/myTE.py +++ b/appPublic/myTE.py @@ -82,3 +82,17 @@ def tmpTml(f, ns): wf.write(b) return p +if __name__ == '__main__': + import sys + import json + if len(sys.argv) < 3: + print(f'{sys.argv[0]} tmplfile jsonfile') + sys.exit(1) + + te = MyTemplateEngine('.') + with codecs.open(sys.argv[1], 'r', 'utf-8') as f: + tmpl = f.read() + with codecs.open(sys.argv[2], 'r', 'utf-8') as f1: + ns = json.loads(f1.read()) + print(te.renders(tmpl, ns)) + diff --git a/appPublic/sshx.py b/appPublic/sshx.py index 03ee364..1d84e84 100644 --- a/appPublic/sshx.py +++ b/appPublic/sshx.py @@ -113,7 +113,7 @@ class SSHNode: self.conn = await self._connect(**j) @asynccontextmanager - async def getconnector(self): + async def get_connector(self): refconn = None for jj in self.jumpers: j = jj.copy() diff --git a/test/test.json b/test/test.json new file mode 100644 index 0000000..d0b9a3c --- /dev/null +++ b/test/test.json @@ -0,0 +1,4 @@ +{ + "user":"John", + "who":"Thomas" +} diff --git a/test/test.tmpl b/test/test.tmpl new file mode 100644 index 0000000..9494b8e --- /dev/null +++ b/test/test.tmpl @@ -0,0 +1,2 @@ +this is a {{user}}'s documents +{{who}} want it