Macros in Python?

Alexander Schmolck a.schmolck at gmx.net
Wed Apr 9 16:04:29 EDT 2003


Dominic <oblivious at web.de> writes:

> 
> Is something like this feasible?
> 
> def server(a,b):
>    if cond:
>        ...
>    else:
>      With_Root_Privs:
>         if x in user:
>            active.append(x)
>           (...)
> 
> Ciao,
>   Dominic
> 

No. you can only do something like this:

def withRootPrivs(fun):
    uid = geteuid
    setuid(0)
    try:     return fun()
    finally: setuid(uid)

def server(a,b):
    if cond:
       ...
    else:
       def useRootPrivs():
           if x in user:
              active.append(x)
           (...)
       withRootPrivs(useRootPrivs)

(well, technicall you could screw around with the source code of the function
but that way lies insanity)

'as




More information about the Python-list mailing list