[IronPython] expose some namespaces of own application

Dino Viehland dinov at exchange.microsoft.com
Wed Aug 16 17:44:17 CEST 2006


This is actually a bug - ReflectedPackage.TryGetAttr is looking at all types, not just exported types.   I've opened CodePlex bug 2199 to track this.

I've tentatively set it for 1.01 but we'll need to triage the bug properly to decide what release it goes in.

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Stanislas Pinte
Sent: Wednesday, August 16, 2006 7:37 AM
To: Discussion of IronPython
Subject: Re: [IronPython] expose some namespaces of own application

Stanislas Pinte a écrit :
> Shri Borde a écrit :
>> Could you use mark the types as internal and public depending on whether you wanted to prevent or allow access from IronPython? IronPython code will not be able to access types or methods marked as internal in your C# code.

Hello,

the following code demonstrates that importing internal types in own Assembly works, while it shouldn't (according to what we think).

Any ideas?

Kind regards,

Stan.

namespace Test
{
  [TestFixture]
  public class EngineIntegrationTests
  {
    [Test]
    public void TestPublicVsInternalImports()
    {
      PythonEngine engine = new PythonEngine();
      //import self assembly
      //try to import public type. should pass
      //try to import internal type. should fail
      engine.LoadAssembly(this.GetType().Assembly);
      engine.Execute("from testnamespace.test import Foo");
      engine.Execute("foo = Foo()");
      engine.Execute("from testnamespace.test import Bar");
      engine.Execute("bar = Bar()");
    }
  }
}

namespace testnamespace.test
{
  public class Foo
  {
    //
  }

  internal class Bar
  {
    //
  }
}

>
> Is this true? Because that is exactly what I want...I can then give
> the reference of my own assembly to the python engine, and then the
> user will only be able to use public types!!
>
> Great,
>
> thanks.
>
> Stan.
>
>> -----Original Message-----
>> From: users-bounces at lists.ironpython.com
>> [mailto:users-bounces at lists.ironpython.com] On Behalf Of Dino
>> Viehland
>> Sent: Tuesday, August 15, 2006 8:09 AM
>> To: Discussion of IronPython
>> Subject: Re: [IronPython] expose some namespaces of own application
>>
>> It is currently an all-or-nothing situation.  As a work around you could create your own module (import imp.new_module('modulename')) and then you could add the namespaces onto the new module, then publish the module in sysmodules:
>>
>> import imp
>> import sys
>>
>> mod = imp.new_module('test')
>> mod.abc = 'xyz'
>> sys.modules['test'] = mod
>>
>> import test
>> print test.abc
>>
>> You can do this w/o giving IronPython the reference to your assembly.  Just load the assembly, and from Python you can access the namespaces/types directly off the assembly object.
>>
>> -----Original Message-----
>> From: users-bounces at lists.ironpython.com
>> [mailto:users-bounces at lists.ironpython.com] On Behalf Of Stanislas
>> Pinte
>> Sent: Tuesday, August 15, 2006 12:34 AM
>> To: Discussion of IronPython
>> Subject: [IronPython] expose some namespaces of own application
>>
>> Hello,
>>
>> We are using IP as a scripting engine, embedded in one of our products.
>>
>> I would like to be able to expose a subset of the namespaces present in my application assembly (MyApp.exe) to the scripting engine...but hide the rest:
>>
>> i.e. when a user does an "from a.b.c import Bar", if a.b.c is "hidden", then it fails:
>>
>>>>> from a.b.c import Bar
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in ?
>> ImportError: No module named a.b.c
>>
>> whereas if a.b.pub has been "exposed" to the scripting engine, then the user can import it.
>>
>> Is this currently possible? I have the impression that it is an all-or-nothing situation...and I would like to avoid having to split my classes in several assemblies.
>>
>> Thanks for all input,
>>
>> Kind regards,
>>
>> Stan.
>>
>> --
>> -----------------------------------------------------------------
>>    Stanislas Pinte             e-mail: stan at ertmssolutions.com
>>    ERTMS Solutions               http://www.ertmssolutions.com
>>    Rue de l'Autonomie, 1             Tel:    + 322 - 522.06.63
>>    1070        Bruxelles              Fax:   + 322 - 522.09.30
>> -----------------------------------------------------------------
>>    Skype (http://www.skype.com) id:                  stanpinte
>> -----------------------------------------------------------------
>> _______________________________________________
>> users mailing list
>> users at lists.ironpython.com
>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>> _______________________________________________
>> users mailing list
>> users at lists.ironpython.com
>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>> _______________________________________________
>> users mailing list
>> users at lists.ironpython.com
>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>>
>>
>
>


--
-----------------------------------------------------------------
   Stanislas Pinte             e-mail: stan at ertmssolutions.com
   ERTMS Solutions               http://www.ertmssolutions.com
   Rue de l'Autonomie, 1             Tel:    + 322 - 522.06.63
   1070        Bruxelles              Fax:   + 322 - 522.09.30
-----------------------------------------------------------------
   Skype (http://www.skype.com) id:                  stanpinte
-----------------------------------------------------------------

_______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



More information about the Ironpython-users mailing list