This is precisely what I want. Thanks!
I'm not really interested (in my case) in creepy10 to remove
quotes from the input string. I'd rather they stay there so my
unrepr(...) function can work correctly.
In my wiki/cms/blog (1) engine macros (will now) will accept real
python values not just purely strings.
--james
--
-- James Mills
--
-- "Problems are solved by method"
Turns out this isn't what I want, nor does it do what i want :/
Here's the thing, say you have a macro:
<<foo "foobar" flag=True>>
flag comes back as a kwarg {"flag": 'True'}
What I need is some kind of rudamentary support for given
arguments and keywords arguments to macros real python ones.
Any ideas ?
My idea of simply running unrepr(...) a function which I've borrowed
from Cherrypy's project which they borrowed from some public domain
module lets you basically safely unrepr any given string. For example:
~/sahriswiki-0.8/sahriswiki
$ python
Python 2.6.5 (r265:79063, Jun 13 2010, 14:03:16)
[GCC 4.4.4 (CRUX)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from unrepr import unrepr
>>> unrepr("'foo'") # a string
'foo'
>>> unrepr("True") # a bool
True
>>> unrepr("1234") # an int
1234
>>> unrepr("[1, 2, 3, 4]") # a list
[1, 2, 3, 4]
>>>
cheers
James
The reason this doesn't work as I want is because of
how the input string is parsed.
<<foo "bar">>
is translated to args = ['bar']
Where I really need args ['\'bar\'']
And <<foo bar="foobar">>
is translated to kwargs {'bar': 'foobar'}
where I really need {'bar': '\'foobar\''}
I guess I want to do value conversion myselfl.
I did try this when you suggested it the first time.
It didn't quite work as well as I wanted behavior-wise :/
*sigh* :)
--James