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

Allow lib.print to accept a braced string like lib.format #1227

Merged
merged 4 commits into from May 14, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion synapse/lib/stormtypes.py
Expand Up @@ -103,9 +103,13 @@ async def _max(self, *args):
ints = [intify(x) for x in vals]
return max(*ints)

async def _print(self, mesg):
async def _print(self, mesg, **kwargs):
if not isinstance(mesg, str):
mesg = repr(mesg)
elif kwargs:
for name, valu in kwargs.items():
jnwatson marked this conversation as resolved.
Show resolved Hide resolved
temp = '{%s}' % (name,)
mesg = mesg.replace(temp, str(valu))
await self.runt.printf(mesg)

async def _dict(self, **kwargs):
Expand Down
5 changes: 5 additions & 0 deletions synapse/tests/test_lib_stormtypes.py
Expand Up @@ -80,6 +80,11 @@ async def test_storm_lib_base(self):
self.eq('vertex.link', mesgs[0][1]['mesg'])
self.eq('woot.com', mesgs[1][1]['mesg'])

mesgs = [m async for m in prox.storm("$lib.print('woot at: {s} {num}', s=hello, num=$(42+43))")]
mesgs = [m for m in mesgs if m[0] == 'print']
self.len(1, mesgs)
self.eq('woot at: hello 85', mesgs[0][1]['mesg'])
jnwatson marked this conversation as resolved.
Show resolved Hide resolved

async def test_storm_lib_dict(self):

async with self.getTestCore() as core:
Expand Down