Mailing List Archive

First Macro: include -- request style help
Hi, I whipped up a little macro to allow including external http files.
I had some style questions wrt to the macros. Hopefully someone w/
some more experience might be able to help out?

* Am I using the txt properly for arguments? Are these parsed into an
array if there are multiple arguments?

* What's the preferred way to throw errors in Trac? (obviously not how
I have it coded)


def execute(hdf, txt, env):
args = txt or ''
if args:
import urllib
f = urllib.urlopen(args)
return f.read()
else:
return '<span class="error">The include macro requires an
argument</span>'
First Macro: include -- request style help [ In reply to ]
> * Am I using the txt properly for arguments? Are these parsed into an
> array if there are multiple arguments?

No, txt is just a string, you can interpret it however you like, so if
you expect it to be comma separated arguments, you'll have to split it.

> * What's the preferred way to throw errors in Trac? (obviously not how
> I have it coded)

Hmm, I'm not really sure about that one.

--
Matthew Good <trac@matt-good.net>
First Macro: include -- request style help [ In reply to ]
>>* What's the preferred way to throw errors in Trac? (obviously not how
>>I have it coded)
>

From Wiki.py

from util import escape, TracError, get_reporter_id

...
...


raise TracError('Sorry, Cannot create new version, this
page has '
'already been modified by someone else.')


M