Re: statement level resumable exception

2011-01-21 Thread Jon Clements
On Jan 21, 8:41 am, ilejn  wrote:
> Arnaud,
>
> it looks like a solution.
> Perhaps it is better than plain try/accept and than proxy class with
> __getattr__.
> It is not for free, e.g. because syntax check such as parentheses
> matching is lazy too, though looks
> very interesting.
>
> Thanks a lot!
>
> On Jan 21, 10:41 am, Arnaud Delobelle  wrote:
>
>
>
> > ilejn  writes:
> > > Arnaud,
>
> > > these lists are not generated.
>
> > > Actually these lists are a sort of interpreted programs and contain
> > > some application logic.
>
> > > Here is an example
> > >         [
> > >         [PUSH, [get_modified_interface, req]],
> > >         [TIMEOUT, 3],
> > >         [PULL, [out_interface, '']],
> > >         [PULL, [err_interface, '']],
> > >         [PULL, [out_mined_interface, req]],
> > >         ]
>
> > > If any interface name is unknown the list must not be invoked (in
> > > other words, f function
> > > call with this list must be somehow bypassed).
>
> > > Thanks.
>
> > You could still use the same idea and delay evaluation of the lists. E.g.
>
> > prg1 = """[
> >     [PUSH, [get_modified_interface, req]],
> >     [TIMEOUT, 3],
> >     ...
> > """
>
> > prg2 = """[
> >     [OPCODE, [arguments, blah]],
> >     ...
> > """
>
> > ...
>
> > prgN = """..."""
>
> > for prg in prg1, prg2, ..., prgN:
> >     try:
> >         prg = eval(prg)
> >     except NameError:
> >         continue
> >     f(prg)
>
> > --
> > Arnaud
>
> Best regards,
> Ilja Golshtein

Not sure if a good idea or not, but:

I would probably use pyparsing and create a small grammar to parse
your list data. If parsing an entry with an unknown interface, then
skip to the next list entry. If the entire list parses, then you can
execute your function calls.

hth

Jon.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: statement level resumable exception

2011-01-21 Thread ilejn
Arnaud,

it looks like a solution.
Perhaps it is better than plain try/accept and than proxy class with
__getattr__.
It is not for free, e.g. because syntax check such as parentheses
matching is lazy too, though looks
very interesting.

Thanks a lot!

On Jan 21, 10:41 am, Arnaud Delobelle  wrote:
> ilejn  writes:
> > Arnaud,
>
> > these lists are not generated.
>
> > Actually these lists are a sort of interpreted programs and contain
> > some application logic.
>
> > Here is an example
> >         [
> >         [PUSH, [get_modified_interface, req]],
> >         [TIMEOUT, 3],
> >         [PULL, [out_interface, '']],
> >         [PULL, [err_interface, '']],
> >         [PULL, [out_mined_interface, req]],
> >         ]
>
> > If any interface name is unknown the list must not be invoked (in
> > other words, f function
> > call with this list must be somehow bypassed).
>
> > Thanks.
>
> You could still use the same idea and delay evaluation of the lists. E.g.
>
> prg1 = """[
>     [PUSH, [get_modified_interface, req]],
>     [TIMEOUT, 3],
>     ...
> """
>
> prg2 = """[
>     [OPCODE, [arguments, blah]],
>     ...
> """
>
> ...
>
> prgN = """..."""
>
> for prg in prg1, prg2, ..., prgN:
>     try:
>         prg = eval(prg)
>     except NameError:
>         continue
>     f(prg)
>
> --
> Arnaud

Best regards,
Ilja Golshtein
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: statement level resumable exception

2011-01-20 Thread Arnaud Delobelle
ilejn  writes:

> Arnaud,
>
> these lists are not generated.
>
> Actually these lists are a sort of interpreted programs and contain
> some application logic.
>
> Here is an example
> [
> [PUSH, [get_modified_interface, req]],
> [TIMEOUT, 3],
> [PULL, [out_interface, '']],
> [PULL, [err_interface, '']],
> [PULL, [out_mined_interface, req]],
> ]
>
> If any interface name is unknown the list must not be invoked (in
> other words, f function
> call with this list must be somehow bypassed).
>
> Thanks.

You could still use the same idea and delay evaluation of the lists. E.g.

prg1 = """[
[PUSH, [get_modified_interface, req]],
[TIMEOUT, 3],
...
"""

prg2 = """[
[OPCODE, [arguments, blah]],
...
"""

...

prgN = """..."""

for prg in prg1, prg2, ..., prgN:
try:
prg = eval(prg)
except NameError:
continue
f(prg)

-- 
Arnaud
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: statement level resumable exception

2011-01-20 Thread ilejn
Arnaud,

these lists are not generated.

Actually these lists are a sort of interpreted programs and contain
some application logic.

Here is an example
[
[PUSH, [get_modified_interface, req]],
[TIMEOUT, 3],
[PULL, [out_interface, '']],
[PULL, [err_interface, '']],
[PULL, [out_mined_interface, req]],
]

If any interface name is unknown the list must not be invoked (in
other words, f function
call with this list must be somehow bypassed).

Thanks.


On Jan 20, 11:42 pm, Arnaud Delobelle  wrote:
> ilejn  writes:
> > Arnaud,
>
> > good idea, though I think it is not applicable in my case,
> > because my arg1 ... argN are "complex multilayer lists".
>
> > In reality it is not just
> > f(arg1),
> > it is more like
> > f([[subarg1, 'aa', subarg2], []])
>
> > Regarding your remark it is a strange problem ... well, may be it
> > is ;)
>
> > Thanks anyway.
>
> Are these lists automatically generated?
>
> --
> Arnaud

Best regards,
Ilja Golshtein.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: statement level resumable exception

2011-01-20 Thread Emile van Sebille

On 1/20/2011 11:49 AM ilejn said...

Chris,

this is a long story why arguments may be not known.
Briefly these arguments come (or may come) from XML and may be not
specified.

A function call which does not have all arguments defined must be
skipped as gracefully as possible.
What I am asking about is how to achieve this goal.



I might try using sets:

required = set(('a','b','c'))
if not (required - set(locals())): f(a,b,c)

HTH,

Emile


--
http://mail.python.org/mailman/listinfo/python-list


Re: statement level resumable exception

2011-01-20 Thread Arnaud Delobelle
ilejn  writes:

> Arnaud,
>
> good idea, though I think it is not applicable in my case,
> because my arg1 ... argN are "complex multilayer lists".
>
> In reality it is not just
> f(arg1),
> it is more like
> f([[subarg1, 'aa', subarg2], []])
>
> Regarding your remark it is a strange problem ... well, may be it
> is ;)
>
> Thanks anyway.

Are these lists automatically generated?

-- 
Arnaud
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: statement level resumable exception

2011-01-20 Thread ilejn
Arnaud,

good idea, though I think it is not applicable in my case,
because my arg1 ... argN are "complex multilayer lists".

In reality it is not just
f(arg1),
it is more like
f([[subarg1, 'aa', subarg2], []])

Regarding your remark it is a strange problem ... well, may be it
is ;)

Thanks anyway.

On Jan 20, 10:58 pm, Arnaud Delobelle  wrote:
> ilejn  writes:
> > Hello!
>
> > I have a sequence of a function calls. Basically it looks like
>
> > f(arg1)
> > f(arg2)
> > ...
> > f(argN)
>
> > though real arguments are complex multilayer lists.
>
> > The problem is some arguments are not known and I get NameError
> > exceptions.
>
> > The solutions I know
> > 1. wrap every f call in try/except block
> > 2. make (currently global) argument attributes of a class and use
> > __getattr__ to convert unknown attributes to something recognizable by
> > f.
>
> for name in 'arg1', 'arg2', ... 'argN':
>     try:
>         arg = globals()[name]
>     except NameError:
>         continue
>     f(arg)
>
> But this is a strange problem...  Sounds like you should do it
> differently.
>
> --
> Arnaud

Best regards,
Ilja Golshtein.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: statement level resumable exception

2011-01-20 Thread Arnaud Delobelle
ilejn  writes:

> Hello!
>
> I have a sequence of a function calls. Basically it looks like
>
> f(arg1)
> f(arg2)
> ...
> f(argN)
>
> though real arguments are complex multilayer lists.
>
> The problem is some arguments are not known and I get NameError
> exceptions.
>
> The solutions I know
> 1. wrap every f call in try/except block
> 2. make (currently global) argument attributes of a class and use
> __getattr__ to convert unknown attributes to something recognizable by
> f.

for name in 'arg1', 'arg2', ... 'argN':
try:
arg = globals()[name]
except NameError:
continue
f(arg)

But this is a strange problem...  Sounds like you should do it
differently.

-- 
Arnaud
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: statement level resumable exception

2011-01-20 Thread ilejn
Chris,

this is a long story why arguments may be not known.
Briefly these arguments come (or may come) from XML and may be not
specified.

A function call which does not have all arguments defined must be
skipped as gracefully as possible.
What I am asking about is how to achieve this goal.

Thanks.


On Jan 20, 9:58 pm, Chris Rebert  wrote:
> On Thu, Jan 20, 2011 at 9:32 AM, ilejn  wrote:
> > Hello!
>
> > I have a sequence of a function calls. Basically it looks like
>
> > f(arg1)

> Why aren't they known? It's a very bad code smell to have possibly
> completely-undefined variables.
>
> Cheers,
> Chris
> --http://blog.rebertia.com

Best regards,
Ilja Golshtein.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: statement level resumable exception

2011-01-20 Thread Chris Rebert
On Thu, Jan 20, 2011 at 9:32 AM, ilejn  wrote:
> Hello!
>
> I have a sequence of a function calls. Basically it looks like
>
> f(arg1)
> f(arg2)
> ...
> f(argN)
>
> though real arguments are complex multilayer lists.
>
> The problem is some arguments are not known and I get NameError
> exceptions.

Why aren't they known? It's a very bad code smell to have possibly
completely-undefined variables.

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


statement level resumable exception

2011-01-20 Thread ilejn
Hello!

I have a sequence of a function calls. Basically it looks like

f(arg1)
f(arg2)
...
f(argN)

though real arguments are complex multilayer lists.

The problem is some arguments are not known and I get NameError
exceptions.

The solutions I know
1. wrap every f call in try/except block
2. make (currently global) argument attributes of a class and use
__getattr__ to convert unknown attributes to something recognizable by
f.


Is it possible to use something more elegant?
I had a hope decorators are helpful here, though apparently they are
not ...
Suggestions?

Thanks.

PS. The question is about Python 2.4
-- 
http://mail.python.org/mailman/listinfo/python-list