[Zope-Perl] Script (Perl) question

Chris McDonough chrism@digicool.com
Thu, 25 Jan 2001 15:51:58 -0500


I think you can expose Python::getattr in restricted PerlMs by editing
lib/perl/Zope.pm, much like Gisle's patch yesterday, e.g.:

    *{"$root\::AUTOLOAD"} = *AUTOLOAD;
    # make python constructors available
    *{"$root\::Python::int"}     = \&Python::int;
    *{"$root\::Python::long"}    = \&Python::long;
    *{"$root\::Python::float"}   = \&Python::float;
    *{"$root\::Python::complex"} = \&Python::complex;
    *{"$root\::Python::list"}    = \&Python::list;
    *{"$root\::Python::tuple"}   = \&Python::tuple;
    *{"$root\::Python::dict"}    = \&Python::dict;
    *{"$root\::Python::getattr"}    = \&Python::getattr;
    *{"$root\::Python::setattr"}    = \&Python::setattr;

    # This hack make sure Python::Object objects in the compartment will
    # not get confused about their names.
    require Hack::Names;

Then in the PerlM:

my @names;
my $cpl = Python::getattr($self, 'Control_Panel');
return Python::list($cpl->objectIds);

I have a feeling allowing access to setattr and getattr from Perl is a
*real* bad idea in restricted PerlMs, because I imagine that no security
checks are done in the process of setting/getting attrs.  I will check.

----- Original Message -----
From: "Andy McKay" <andym@ActiveState.com>
To: "Chris McDonough" <chrism@digicool.com>; "Gisle Aas"
<gisle@ActiveState.com>
Cc: <zope-perl@zope.org>
Sent: Thursday, January 25, 2001 2:59 PM
Subject: Re: [Zope-Perl] Script (Perl) question


> Well:
> $self->{Control_Panel}->objectIds() gives a this is not a HASH reference
> error
> $self->Control_Panel->objectIds() gives a __call__ error
> Python::getattr($self, 'Control_Panel') gives a Undefined subroutine
> &Zope::PerlMethod::__copy_5fof_5ftestPl::Python::getattr
>
> I think there is something wrong with my installation here.
> --
>   Andy McKay.
>
>
> ----- Original Message -----
> From: "Gisle Aas" <gisle@ActiveState.com>
> To: "Chris McDonough" <chrism@digicool.com>
> Cc: "Andy McKay" <andym@activestate.com>; <zope-perl@zope.org>
> Sent: Thursday, January 25, 2001 11:24 AM
> Subject: Re: [Zope-Perl] Script (Perl) question
>
>
> > "Chris McDonough" <chrism@digicool.com> writes:
> >
> > > I think you need to reference self.Control_Panel.objectIds in perl
> through
> > > the following:
> > >
> > > foreach $name ($self->{Control_Panel}->objectIds()) {
> > > ...
> > > }
> >
> > Assuming $o is some python object:
> >
> > Perl       |                        Python
> > -----------+------------------------------------
> > $o->{Foo}  | should be the same as  o["Foo"]
> > $o->Foo    | should be the same as  o.Foo
> >            |                    or  o.Foo()  (if o.Foo happens to be
> callable)
> >
> > If you want to avoid the auto-call feature of $o->Foo you need to
> > write it as Python::getattr($o, "Foo").
> >
> > --Gisle
> >
> >
> > > Gad, I found that I've forgotten everything I ever knew about Perl,
> which
> > > wasn't much to start with.  :-)
> > >
> > > ----- Original Message -----
> > > From: "Chris McDonough" <chrism@digicool.com>
> > > To: "Andy McKay" <andym@activestate.com>; <zope-perl@zope.org>
> > > Sent: Wednesday, January 24, 2001 7:12 PM
> > > Subject: Re: [Zope-Perl] Script (Perl) question
> > >
> > >
> > > > Are you passing in "self" as an argument on the PerlM arguments
line?
> > > >
> > > > ----- Original Message -----
> > > > From: "Andy McKay" <andym@activestate.com>
> > > > To: <zope-perl@zope.org>
> > > > Sent: Wednesday, January 24, 2001 6:48 PM
> > > > Subject: [Zope-Perl] Script (Perl) question
> > > >
> > > >
> > > > > Whats $self in Zope Perl, AFAIK it is a binding to the scripts
> > > container,
> > > > > similar to context to Script (Python). Anyway the following works
> fine
> > > in
> > > > > python:
> > > > >
> > > > > return context.Control_Panel.objectIds()
> > > > >
> > > > > The same in Perl would be:
> > > > >
> > > > > return $self->Control_Panel->objectIds();
> > > > >
> > > > > but I get a __call__ error. The Zope Book suggests that I have the

> right
> > > > > syntax. The problem seems to occur when moving into a sub-object,
> for
> > > > > example $self->objectIds(); works just fine. Any ideas anyone?
> > > > >
> > > > > Using: Zope 2.3b2, Win2k, Python 1.5.2, Perl 620, pyperl &
> > > > zoperl-1.0-beta3
> > > > >
> > > > > Cheers.
> > > > >
> > > > > --
> > > > >   Andy McKay.
> >
> > _______________________________________________
> > Zope-perl maillist  -  Zope-perl@zope.org
> > http://lists.zope.org/mailman/listinfo/zope-perl
> >
>
>