From oorrii at gmail.com Wed Aug 1 14:07:34 2007 From: oorrii at gmail.com (Ori) Date: Wed, 1 Aug 2007 05:07:34 -0700 (PDT) Subject: [IronPython] Some questions about Iron-Python Message-ID: <11940989.post@talk.nabble.com> Hello, I'm new to IronPython and I have a few qusetions: 1. Is there an option to add a context object to the compiled module (so all properties and methods from the object will be accesible) 2. Can a python class inherit from a class located in some referenced .net assembly? 3. Can I save compiled code in memory and use it to evaluate code multiple times? I've seen there is a CompiledCode object but I saw only an Execute method. Thanks, Ori -- View this message in context: http://www.nabble.com/Some-questions-about-Iron-Python-tf4198487.html#a11940989 Sent from the IronPython mailing list archive at Nabble.com. From garabatus at gmail.com Wed Aug 1 19:19:45 2007 From: garabatus at gmail.com (Garabatus Raptus) Date: Wed, 1 Aug 2007 13:19:45 -0400 Subject: [IronPython] SslStream exception Message-ID: Hi there, I'm new to IronPython and I would like to know how can I catch an exception generated by SslStream, Example: client = TcpClient(self.server, self.port) sslStream = SslStream( client.GetStream(), False, RemoteCertificateValidationCallback (self.ValidateServerCertificate), None) try: sslStream.AuthenticateAsClient("secure.mydomain....") except : .... ... return Is there any link where I can read about it and found some examples? regards, gara From dinov at exchange.microsoft.com Wed Aug 1 19:50:32 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Wed, 1 Aug 2007 10:50:32 -0700 Subject: [IronPython] SslStream exception In-Reply-To: References: Message-ID: <7AD436E4270DD54A94238001769C2227B82F4B0C5A@DF-GRTDANE-MSG.exchange.corp.microsoft.com> You have two options: You can catch a Python exception or a .NET exception, and you'll get either the Python exception object or the .NET exception object. To catch a .NET exception as a Python exception you need to catch the closest base exception which might be Exception or SystemError (if you let the exception go unhandled it's whatever gets reported there). To catch the .NET exception you just need to grab it from the correct namespace, for example: try: # do something except System.ArgumentException, ex: print ex and ex will end up being the ArgumentException instance. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Garabatus Raptus Sent: Wednesday, August 01, 2007 10:20 AM To: users at lists.ironpython.com Subject: [IronPython] SslStream exception Hi there, I'm new to IronPython and I would like to know how can I catch an exception generated by SslStream, Example: client = TcpClient(self.server, self.port) sslStream = SslStream( client.GetStream(), False, RemoteCertificateValidationCallback (self.ValidateServerCertificate), None) try: sslStream.AuthenticateAsClient("secure.mydomain....") except : .... ... return Is there any link where I can read about it and found some examples? regards, gara _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From dinov at exchange.microsoft.com Wed Aug 1 19:57:43 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Wed, 1 Aug 2007 10:57:43 -0700 Subject: [IronPython] Some questions about Iron-Python In-Reply-To: <11940989.post@talk.nabble.com> References: <11940989.post@talk.nabble.com> Message-ID: <7AD436E4270DD54A94238001769C2227B82F4B0C60@DF-GRTDANE-MSG.exchange.corp.microsoft.com> #1) After creating a module you should be able to publish the object directly into the module's scope. The normal CreateModule APIs allow you to provide a dictionary which could already contain this object. Unfortunately all the objects members won't be magically available, you'll need to access the members through the object. You could execute some python code such as: import sys mymod = sys.modules[__name__] for x in dir(myobj): setattr(mymod, x, getattr(myobj, x)) which will copy all the members from the object into the module (you could also do the equivalent from C# using Ops.GetAttrNames, Ops.GetAttr, and Ops.SetAttr). #2 - yes, to do this you just need to add a reference to the assembly and import the type from the correct namespace. E.g.: import clr clr.AddReference('System.Windows.Forms') from System.Windows.Forms import Form class MyForm(Form): pass a = MyForm() #3 - There's a couple of ways to do this. You could use the CreateMethod / CreateLambda APIs which will return a strongly typed delegate w/ some code you can later call. You can also use the CompiledCode method and the Execute method will re-run it. The overload that takes an EngineModule allows you to execute the code multiple times with a different set of globals. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Ori Sent: Wednesday, August 01, 2007 5:08 AM To: users at lists.ironpython.com Subject: [IronPython] Some questions about Iron-Python Hello, I'm new to IronPython and I have a few qusetions: 1. Is there an option to add a context object to the compiled module (so all properties and methods from the object will be accesible) 2. Can a python class inherit from a class located in some referenced .net assembly? 3. Can I save compiled code in memory and use it to evaluate code multiple times? I've seen there is a CompiledCode object but I saw only an Execute method. Thanks, Ori -- View this message in context: http://www.nabble.com/Some-questions-about-Iron-Python-tf4198487.html#a11940989 Sent from the IronPython mailing list archive at Nabble.com. _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From garabatus at gmail.com Wed Aug 1 21:37:32 2007 From: garabatus at gmail.com (Garabatus Raptus) Date: Wed, 1 Aug 2007 15:37:32 -0400 Subject: [IronPython] SslStream exception In-Reply-To: <7AD436E4270DD54A94238001769C2227B82F4B0C5A@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <7AD436E4270DD54A94238001769C2227B82F4B0C5A@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: Thanxs a lot. Now, I'm having another issue ... I want to bypass the Validation of the server certificate but looks like the callback funtion is not working properly. Is this the way to create the Sslstream: sslStream = SslStream( client.GetStream(), False, RemoteCertificateValidationCallback ( self.ValidateServerCertificate), None) ------------------ def ValidateServerCertificate( sender, certificate, chain, sslPolicyErrors): return True regards, gara On 8/1/07, Dino Viehland wrote: > You have two options: You can catch a Python exception or a .NET exception, and you'll get either the Python exception object or the .NET exception object. To catch a .NET exception as a Python exception you need to catch the closest base exception which might be Exception or SystemError (if you let the exception go unhandled it's whatever gets reported there). To catch the .NET exception you just need to grab it from the correct namespace, for example: > > try: > # do something > except System.ArgumentException, ex: > print ex > > and ex will end up being the ArgumentException instance. > > > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Garabatus Raptus > Sent: Wednesday, August 01, 2007 10:20 AM > To: users at lists.ironpython.com > Subject: [IronPython] SslStream exception > > Hi there, > > I'm new to IronPython and I would like to know how can I catch an > exception generated by SslStream, Example: > > client = TcpClient(self.server, self.port) > > sslStream = SslStream( client.GetStream(), False, > RemoteCertificateValidationCallback (self.ValidateServerCertificate), > None) > > try: > sslStream.AuthenticateAsClient("secure.mydomain....") > except : > > .... ... > return > > Is there any link where I can read about it and found some examples? > > regards, > > gara > _______________________________________________ > 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 > From daftspaniel at gmail.com Thu Aug 2 00:34:01 2007 From: daftspaniel at gmail.com (Davy Mitchell) Date: Wed, 1 Aug 2007 23:34:01 +0100 Subject: [IronPython] Application? Message-ID: <20253b0c0708011534x2984d563ofc30315bd7cad99c@mail.gmail.com> Is there a way to use the Application namespace in IronPython? Hoping to use methods like Application.CommonAppDataPath but they all seem assembly focussed? Thanks, Davy -- Davy Mitchell Blog - http://www.latedecember.co.uk/sites/personal/davy/ Twitter - http://twitter.com/daftspaniel Skype - daftspaniel needgod.com From dinov at exchange.microsoft.com Thu Aug 2 01:13:30 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Wed, 1 Aug 2007 16:13:30 -0700 Subject: [IronPython] SslStream exception In-Reply-To: References: <7AD436E4270DD54A94238001769C2227B82F4B0C5A@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <7AD436E4270DD54A94238001769C2227B830BD9533@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Assuming that you're defining ValidateServerCerificate as a member of a class you'll need to add a "self" parameter to it, eg: class foo(object): def ValidateServerCertificate(self, sender, certificate, chain, sslPolicyErrors): return True That will cause the expression "self.ValidateServerCertificate" to produce a bound method which contains the function + the reference to self and Python should be able to expose that method as a 4 parameter delegate which receives sender, certificate, chain, sslPolicyErrors. Or you can just define VSC as a top-level function or a static method and not have it take self. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Garabatus Raptus Sent: Wednesday, August 01, 2007 12:38 PM To: Discussion of IronPython Subject: Re: [IronPython] SslStream exception Thanxs a lot. Now, I'm having another issue ... I want to bypass the Validation of the server certificate but looks like the callback funtion is not working properly. Is this the way to create the Sslstream: sslStream = SslStream( client.GetStream(), False, RemoteCertificateValidationCallback ( self.ValidateServerCertificate), None) ------------------ def ValidateServerCertificate( sender, certificate, chain, sslPolicyErrors): return True regards, gara On 8/1/07, Dino Viehland wrote: > You have two options: You can catch a Python exception or a .NET exception, and you'll get either the Python exception object or the .NET exception object. To catch a .NET exception as a Python exception you need to catch the closest base exception which might be Exception or SystemError (if you let the exception go unhandled it's whatever gets reported there). To catch the .NET exception you just need to grab it from the correct namespace, for example: > > try: > # do something > except System.ArgumentException, ex: > print ex > > and ex will end up being the ArgumentException instance. > > > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Garabatus Raptus > Sent: Wednesday, August 01, 2007 10:20 AM > To: users at lists.ironpython.com > Subject: [IronPython] SslStream exception > > Hi there, > > I'm new to IronPython and I would like to know how can I catch an > exception generated by SslStream, Example: > > client = TcpClient(self.server, self.port) > > sslStream = SslStream( client.GetStream(), False, > RemoteCertificateValidationCallback (self.ValidateServerCertificate), > None) > > try: > sslStream.AuthenticateAsClient("secure.mydomain....") > except : > > .... ... > return > > Is there any link where I can read about it and found some examples? > > regards, > > gara > _______________________________________________ > 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 From dinov at exchange.microsoft.com Thu Aug 2 01:14:53 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Wed, 1 Aug 2007 16:14:53 -0700 Subject: [IronPython] Application? In-Reply-To: <20253b0c0708011534x2984d563ofc30315bd7cad99c@mail.gmail.com> References: <20253b0c0708011534x2984d563ofc30315bd7cad99c@mail.gmail.com> Message-ID: <7AD436E4270DD54A94238001769C2227B830BD9534@DF-GRTDANE-MSG.exchange.corp.microsoft.com> This works for me: >>> import System >>> import clr >>> clr.AddReference('System.Windows.Forms') >>> from System.Windows.Forms import Application >>> dir(Application) ['AddMessageFilter', 'AllowQuit', 'ApplicationExit', 'CommonAppDataPath', 'CommonAppDataRegistry', 'CompanyName', 'CurrentCulture', 'CurrentInputLanguage', 'DoEvents', 'EnableVisualStyles', 'EnterThreadModal', 'Equals', 'ExecutablePath', 'Exit', 'ExitThread', 'FilterMessage', 'Finalize', 'GetHashCode', 'GetTy pe', 'Idle', 'LeaveThreadModal', 'LocalUserAppDataPath', 'MakeDynamicType', 'MemberwiseClone', 'MessageLoop', 'MessageLoopCallback', 'OleRequired', 'OnThre adException', 'OpenForms', 'ProductName', 'ProductVersion', 'RaiseIdle', 'Reduce', 'ReferenceEquals', 'RegisterMessageLoop', 'RemoveMessageFilter', 'Render WithVisualStyles', 'Restart', 'Run', 'SafeTopLevelCaptionFormat', 'SetCompatibleTextRenderingDefault', 'SetSuspendState', 'SetUnhandledExceptionMode', 'Sta rtupPath', 'ThreadException', 'ThreadExit', 'ToString', 'UnregisterMessageLoop', 'UseWaitCursor', 'UserAppDataPath', 'UserAppDataRegistry', 'VisualStyleSta te', '__class__', '__doc__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', 'add_ApplicationExit', 'add_EnterThreadModal', 'add_Idle', 'add_LeaveThreadModal', 'add_ThreadException', 'add_ThreadExit', 'remove_ApplicationExit', 'remove_EnterThreadModal', 'remove_Idle', 'remove_L eaveThreadModal', 'remove_ThreadException', 'remove_ThreadExit'] >>> Application.CommonAppDataPath 'C:\\ProgramData\\Microsoft\\IronPython\\1.1' >>> -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Davy Mitchell Sent: Wednesday, August 01, 2007 3:34 PM To: Discussion of IronPython Subject: [IronPython] Application? Is there a way to use the Application namespace in IronPython? Hoping to use methods like Application.CommonAppDataPath but they all seem assembly focussed? Thanks, Davy -- Davy Mitchell Blog - http://www.latedecember.co.uk/sites/personal/davy/ Twitter - http://twitter.com/daftspaniel Skype - daftspaniel needgod.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From yangkehua at hotmail.com Thu Aug 2 06:35:56 2007 From: yangkehua at hotmail.com (=?gb2312?B?0e4gv8a7rw==?=) Date: Thu, 02 Aug 2007 12:35:56 +0800 Subject: [IronPython] help,please In-Reply-To: <7AD436E4270DD54A94238001769C2227B830BD9533@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: hi , I wanna contribute to the source? But I cann't download it because it require a user name and password. Please respond to yangkehua at hotmail.com Thanks, eric yang _________________________________________________________________ ???? MSN Explorer: http://explorer.msn.com/lccn From daftspaniel at gmail.com Thu Aug 2 10:04:45 2007 From: daftspaniel at gmail.com (Davy Mitchell) Date: Thu, 2 Aug 2007 09:04:45 +0100 Subject: [IronPython] Application? In-Reply-To: <7AD436E4270DD54A94238001769C2227B830BD9534@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <20253b0c0708011534x2984d563ofc30315bd7cad99c@mail.gmail.com> <7AD436E4270DD54A94238001769C2227B830BD9534@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <20253b0c0708020104i2d5a2091vc3964d277dac93c@mail.gmail.com> Thanks Dino. Yes the Application does work but all the paths point to the PythonConsoleHost folder name and version so are not much use. The version and app name seem to be set in AssemblyInfo file in a VS project. Is this achievable with IronPython? Thanks, Davy On 8/2/07, Dino Viehland wrote: > This works for me: > > >>> import System > >>> import clr > >>> clr.AddReference('System.Windows.Forms') > >>> from System.Windows.Forms import Application > >>> dir(Application) > ['AddMessageFilter', 'AllowQuit', 'ApplicationExit', 'CommonAppDataPath', 'CommonAppDataRegistry', 'CompanyName', 'CurrentCulture', 'CurrentInputLanguage', > 'DoEvents', 'EnableVisualStyles', 'EnterThreadModal', 'Equals', 'ExecutablePath', 'Exit', 'ExitThread', 'FilterMessage', 'Finalize', 'GetHashCode', 'GetTy > pe', 'Idle', 'LeaveThreadModal', 'LocalUserAppDataPath', 'MakeDynamicType', 'MemberwiseClone', 'MessageLoop', 'MessageLoopCallback', 'OleRequired', 'OnThre > adException', 'OpenForms', 'ProductName', 'ProductVersion', 'RaiseIdle', 'Reduce', 'ReferenceEquals', 'RegisterMessageLoop', 'RemoveMessageFilter', 'Render > WithVisualStyles', 'Restart', 'Run', 'SafeTopLevelCaptionFormat', 'SetCompatibleTextRenderingDefault', 'SetSuspendState', 'SetUnhandledExceptionMode', 'Sta > rtupPath', 'ThreadException', 'ThreadExit', 'ToString', 'UnregisterMessageLoop', 'UseWaitCursor', 'UserAppDataPath', 'UserAppDataRegistry', 'VisualStyleSta > te', '__class__', '__doc__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', 'add_ApplicationExit', 'add_EnterThreadModal', > 'add_Idle', 'add_LeaveThreadModal', 'add_ThreadException', 'add_ThreadExit', 'remove_ApplicationExit', 'remove_EnterThreadModal', 'remove_Idle', 'remove_L > eaveThreadModal', 'remove_ThreadException', 'remove_ThreadExit'] > >>> Application.CommonAppDataPath > 'C:\\ProgramData\\Microsoft\\IronPython\\1.1' > >>> > > > > > > > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Davy Mitchell > Sent: Wednesday, August 01, 2007 3:34 PM > To: Discussion of IronPython > Subject: [IronPython] Application? > > Is there a way to use the Application namespace in IronPython? > > Hoping to use methods like Application.CommonAppDataPath but they all > seem assembly focussed? > > Thanks, > Davy > > -- > Davy Mitchell > Blog - http://www.latedecember.co.uk/sites/personal/davy/ > Twitter - http://twitter.com/daftspaniel > Skype - daftspaniel > needgod.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 > -- Davy Mitchell Blog - http://www.latedecember.co.uk/sites/personal/davy/ Twitter - http://twitter.com/daftspaniel Skype - daftspaniel needgod.com From yangkehua at hotmail.com Thu Aug 2 16:39:00 2007 From: yangkehua at hotmail.com (=?gb2312?B?0e4gv8a7rw==?=) Date: Thu, 02 Aug 2007 22:39:00 +0800 Subject: [IronPython] help,please,still In-Reply-To: Message-ID: hi , I wanna contribute to the source of ironpython IDE? But I cann't checkout it from "http://lynanda.com/svn/IronPython-IDE" website ,because it require a user name and password. Please respond to yangkehua at hotmail.com Thanks, eric yang _________________________________________________________________ ?????????????? MSN Messenger: http://messenger.msn.com/cn From dinov at exchange.microsoft.com Thu Aug 2 18:33:38 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Thu, 2 Aug 2007 09:33:38 -0700 Subject: [IronPython] help,please,still In-Reply-To: References: Message-ID: <7AD436E4270DD54A94238001769C2227B979ABD26C@DF-GRTDANE-MSG.exchange.corp.microsoft.com> I don't think this is the right mailing list to contact for that. I'm not sure who lynanda.com is, what their IDE is, or if they're accepting contributions. Unless someone else on the list knows about this you might want to contact them directly. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of ? ?? Sent: Thursday, August 02, 2007 7:39 AM To: users at lists.ironpython.com Subject: [IronPython] help,please,still hi , I wanna contribute to the source of ironpython IDE? But I cann't checkout it from "http://lynanda.com/svn/IronPython-IDE" website ,because it require a user name and password. Please respond to yangkehua at hotmail.com Thanks, eric yang _________________________________________________________________ ?????????????? MSN Messenger: http://messenger.msn.com/cn _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From dinov at exchange.microsoft.com Thu Aug 2 18:42:58 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Thu, 2 Aug 2007 09:42:58 -0700 Subject: [IronPython] Application? In-Reply-To: <20253b0c0708020104i2d5a2091vc3964d277dac93c@mail.gmail.com> References: <20253b0c0708011534x2984d563ofc30315bd7cad99c@mail.gmail.com> <7AD436E4270DD54A94238001769C2227B830BD9534@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <20253b0c0708020104i2d5a2091vc3964d277dac93c@mail.gmail.com> Message-ID: <7AD436E4270DD54A94238001769C2227B979ABD27E@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Ahh, I see. It looks like this info ultimately comes from custom attributes exposed off of Assembly.GetEntryAssembly(). Therefore w/ the VS SDK sample (which I assume is where the VS side of things come in) and the IronPython command line these are both going to reflect the hosting app. It would be theoretically possible to do this w/ the pyc sample and some changes to the PythonCompiler class. The PythonCompiler class would need to expose the AssemblyGen object and set the appropriate custom attributes on it via, something like: ag.myAssembly.SetCustomAttribute(new CustomAttributeBuilder( typeof(AssemblyInformationalVersionAttribute).GetConstructor(new Type[]{typeof(string)}), "2.0") ); That has the downside of requiring you to compile your code (or at least your main EXE). But basically it looks like we have no good support for this right now. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Davy Mitchell Sent: Thursday, August 02, 2007 1:05 AM To: Discussion of IronPython Subject: Re: [IronPython] Application? Thanks Dino. Yes the Application does work but all the paths point to the PythonConsoleHost folder name and version so are not much use. The version and app name seem to be set in AssemblyInfo file in a VS project. Is this achievable with IronPython? Thanks, Davy On 8/2/07, Dino Viehland wrote: > This works for me: > > >>> import System > >>> import clr > >>> clr.AddReference('System.Windows.Forms') > >>> from System.Windows.Forms import Application > >>> dir(Application) > ['AddMessageFilter', 'AllowQuit', 'ApplicationExit', 'CommonAppDataPath', 'CommonAppDataRegistry', 'CompanyName', 'CurrentCulture', 'CurrentInputLanguage', > 'DoEvents', 'EnableVisualStyles', 'EnterThreadModal', 'Equals', 'ExecutablePath', 'Exit', 'ExitThread', 'FilterMessage', 'Finalize', 'GetHashCode', 'GetTy > pe', 'Idle', 'LeaveThreadModal', 'LocalUserAppDataPath', 'MakeDynamicType', 'MemberwiseClone', 'MessageLoop', 'MessageLoopCallback', 'OleRequired', 'OnThre > adException', 'OpenForms', 'ProductName', 'ProductVersion', 'RaiseIdle', 'Reduce', 'ReferenceEquals', 'RegisterMessageLoop', 'RemoveMessageFilter', 'Render > WithVisualStyles', 'Restart', 'Run', 'SafeTopLevelCaptionFormat', 'SetCompatibleTextRenderingDefault', 'SetSuspendState', 'SetUnhandledExceptionMode', 'Sta > rtupPath', 'ThreadException', 'ThreadExit', 'ToString', 'UnregisterMessageLoop', 'UseWaitCursor', 'UserAppDataPath', 'UserAppDataRegistry', 'VisualStyleSta > te', '__class__', '__doc__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', 'add_ApplicationExit', 'add_EnterThreadModal', > 'add_Idle', 'add_LeaveThreadModal', 'add_ThreadException', 'add_ThreadExit', 'remove_ApplicationExit', 'remove_EnterThreadModal', 'remove_Idle', 'remove_L > eaveThreadModal', 'remove_ThreadException', 'remove_ThreadExit'] > >>> Application.CommonAppDataPath > 'C:\\ProgramData\\Microsoft\\IronPython\\1.1' > >>> > > > > > > > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Davy Mitchell > Sent: Wednesday, August 01, 2007 3:34 PM > To: Discussion of IronPython > Subject: [IronPython] Application? > > Is there a way to use the Application namespace in IronPython? > > Hoping to use methods like Application.CommonAppDataPath but they all > seem assembly focussed? > > Thanks, > Davy > > -- > Davy Mitchell > Blog - http://www.latedecember.co.uk/sites/personal/davy/ > Twitter - http://twitter.com/daftspaniel > Skype - daftspaniel > needgod.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 > -- Davy Mitchell Blog - http://www.latedecember.co.uk/sites/personal/davy/ Twitter - http://twitter.com/daftspaniel Skype - daftspaniel needgod.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From daftspaniel at gmail.com Thu Aug 2 23:03:09 2007 From: daftspaniel at gmail.com (Davy Mitchell) Date: Thu, 2 Aug 2007 22:03:09 +0100 Subject: [IronPython] Application? In-Reply-To: <7AD436E4270DD54A94238001769C2227B979ABD27E@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <20253b0c0708011534x2984d563ofc30315bd7cad99c@mail.gmail.com> <7AD436E4270DD54A94238001769C2227B830BD9534@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <20253b0c0708020104i2d5a2091vc3964d277dac93c@mail.gmail.com> <7AD436E4270DD54A94238001769C2227B979ABD27E@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <20253b0c0708021403g177f5b00h2bcbc87c335fd42a@mail.gmail.com> Thanks Dino - didn't think it quite fitted the IronPython model. Looks like I can get the path from Enviroment module. from System import Environment print Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) Cheers, Davy Mitchell On 8/2/07, Dino Viehland wrote: > Ahh, I see. It looks like this info ultimately comes from custom attributes exposed off of Assembly.GetEntryAssembly(). Therefore w/ the VS SDK sample (which I assume is where the VS side of things come in) and the IronPython command line these are both going to reflect the hosting app. > > It would be theoretically possible to do this w/ the pyc sample and some changes to the PythonCompiler class. The PythonCompiler class would need to expose the AssemblyGen object and set the appropriate custom attributes on it via, something like: > > ag.myAssembly.SetCustomAttribute(new CustomAttributeBuilder( > typeof(AssemblyInformationalVersionAttribute).GetConstructor(new Type[]{typeof(string)}), "2.0") > ); > > That has the downside of requiring you to compile your code (or at least your main EXE). But basically it looks like we have no good support for this right now. > > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Davy Mitchell > Sent: Thursday, August 02, 2007 1:05 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Application? > > Thanks Dino. > > Yes the Application does work but all the paths point to the > PythonConsoleHost folder name and version so are not much use. > > The version and app name seem to be set in AssemblyInfo file in a VS > project. Is this achievable with IronPython? > > Thanks, > Davy > > On 8/2/07, Dino Viehland wrote: > > This works for me: > > > > >>> import System > > >>> import clr > > >>> clr.AddReference('System.Windows.Forms') > > >>> from System.Windows.Forms import Application > > >>> dir(Application) > > ['AddMessageFilter', 'AllowQuit', 'ApplicationExit', 'CommonAppDataPath', 'CommonAppDataRegistry', 'CompanyName', 'CurrentCulture', 'CurrentInputLanguage', > > 'DoEvents', 'EnableVisualStyles', 'EnterThreadModal', 'Equals', 'ExecutablePath', 'Exit', 'ExitThread', 'FilterMessage', 'Finalize', 'GetHashCode', 'GetTy > > pe', 'Idle', 'LeaveThreadModal', 'LocalUserAppDataPath', 'MakeDynamicType', 'MemberwiseClone', 'MessageLoop', 'MessageLoopCallback', 'OleRequired', 'OnThre > > adException', 'OpenForms', 'ProductName', 'ProductVersion', 'RaiseIdle', 'Reduce', 'ReferenceEquals', 'RegisterMessageLoop', 'RemoveMessageFilter', 'Render > > WithVisualStyles', 'Restart', 'Run', 'SafeTopLevelCaptionFormat', 'SetCompatibleTextRenderingDefault', 'SetSuspendState', 'SetUnhandledExceptionMode', 'Sta > > rtupPath', 'ThreadException', 'ThreadExit', 'ToString', 'UnregisterMessageLoop', 'UseWaitCursor', 'UserAppDataPath', 'UserAppDataRegistry', 'VisualStyleSta > > te', '__class__', '__doc__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', 'add_ApplicationExit', 'add_EnterThreadModal', > > 'add_Idle', 'add_LeaveThreadModal', 'add_ThreadException', 'add_ThreadExit', 'remove_ApplicationExit', 'remove_EnterThreadModal', 'remove_Idle', 'remove_L > > eaveThreadModal', 'remove_ThreadException', 'remove_ThreadExit'] > > >>> Application.CommonAppDataPath > > 'C:\\ProgramData\\Microsoft\\IronPython\\1.1' > > >>> > > > > > > > > > > > > > > -----Original Message----- > > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Davy Mitchell > > Sent: Wednesday, August 01, 2007 3:34 PM > > To: Discussion of IronPython > > Subject: [IronPython] Application? > > > > Is there a way to use the Application namespace in IronPython? > > > > Hoping to use methods like Application.CommonAppDataPath but they all > > seem assembly focussed? > > > > Thanks, > > Davy > > > > -- > > Davy Mitchell > > Blog - http://www.latedecember.co.uk/sites/personal/davy/ > > Twitter - http://twitter.com/daftspaniel > > Skype - daftspaniel > > needgod.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 > > > > > -- > Davy Mitchell > Blog - http://www.latedecember.co.uk/sites/personal/davy/ > Twitter - http://twitter.com/daftspaniel > Skype - daftspaniel > needgod.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 > -- Davy Mitchell Blog - http://www.latedecember.co.uk/sites/personal/davy/ Twitter - http://twitter.com/daftspaniel Skype - daftspaniel needgod.com From daftspaniel at gmail.com Thu Aug 2 23:48:16 2007 From: daftspaniel at gmail.com (Davy Mitchell) Date: Thu, 2 Aug 2007 22:48:16 +0100 Subject: [IronPython] Odd behaviour for unknown property Message-ID: <20253b0c0708021448w47c42201ibc34143973ae2ba9@mail.gmail.com> Oh that subject line is clumsy.... Is this a bug (2.0A3)? import clr clr.AddReference('System.Windows.Forms') from System import * from System.Windows.Forms import * class LDForm(Form): def __init__(self): pass #This reports an AttributeError the method as read only. test = LDForm() print test.Idontexist #This reports an AttributeError method as not existing as expected. test = Form() print test.Idontexist Not sure if this is related to using or subclassing .Net objects - its just what I was using at the time. Davy -- Davy Mitchell Blog - http://www.latedecember.co.uk/sites/personal/davy/ Twitter - http://twitter.com/daftspaniel Skype - daftspaniel needgod.com From dinov at exchange.microsoft.com Fri Aug 3 00:23:00 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Thu, 2 Aug 2007 15:23:00 -0700 Subject: [IronPython] Odd behaviour for unknown property In-Reply-To: <20253b0c0708021448w47c42201ibc34143973ae2ba9@mail.gmail.com> References: <20253b0c0708021448w47c42201ibc34143973ae2ba9@mail.gmail.com> Message-ID: <7AD436E4270DD54A94238001769C2227B979ABD3C1@DF-GRTDANE-MSG.exchange.corp.microsoft.com> This is a bug - I've got a fix for it so it'll be in the next release. If you want to know the details: the reason why it only affects user objects is that normal objects and user objects actually go through two wildly different code paths. The user types are all instances of IDynamicObject whose implementation lives in UserTypeOps.cs. Normal .NET objects for the most part get their members lookup handled by GetMemberBinderHelper in Microsoft.Scripting. Both of these end up producing custom rules for use in a dynamic site which enables the member lookup to be quite fast. Anyway, the implementation for user types is creating a rule which calls the wrong method to make the error. It calls an overload that takes object, SymbolId and should get the type name and call the string, SymbolId overload. Thanks for the report! -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Davy Mitchell Sent: Thursday, August 02, 2007 2:48 PM To: Discussion of IronPython Subject: [IronPython] Odd behaviour for unknown property Oh that subject line is clumsy.... Is this a bug (2.0A3)? import clr clr.AddReference('System.Windows.Forms') from System import * from System.Windows.Forms import * class LDForm(Form): def __init__(self): pass #This reports an AttributeError the method as read only. test = LDForm() print test.Idontexist #This reports an AttributeError method as not existing as expected. test = Form() print test.Idontexist Not sure if this is related to using or subclassing .Net objects - its just what I was using at the time. Davy -- Davy Mitchell Blog - http://www.latedecember.co.uk/sites/personal/davy/ Twitter - http://twitter.com/daftspaniel Skype - daftspaniel needgod.com _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From oorrii at gmail.com Fri Aug 3 07:52:56 2007 From: oorrii at gmail.com (Ori) Date: Thu, 2 Aug 2007 22:52:56 -0700 (PDT) Subject: [IronPython] Declare a class in Python and use it in .net Message-ID: <11977831.post@talk.nabble.com> Hello, I have a .net class (in some assembly). I want to inherit from it and override a function in it - with python code. I'm using c# to compile the python code, and after the compilation is done I want to create an instance of the new class inside c#. Is there a way to do it? Thanks, Ori -- View this message in context: http://www.nabble.com/Declare-a-class-in-Python-and-use-it-in-.net-tf4210730.html#a11977831 Sent from the IronPython mailing list archive at Nabble.com. From oorrii at gmail.com Fri Aug 3 08:42:19 2007 From: oorrii at gmail.com (Ori) Date: Thu, 2 Aug 2007 23:42:19 -0700 (PDT) Subject: [IronPython] Find the compile erros Message-ID: <11978230.post@talk.nabble.com> Hello, I'm using PythonEngine.Compile to compile code. The code I compile may contain errors and that's why I want to format the error(s). Currently I'm using try-catch and I work with the exception error text. Is there a btter way to get the compilation errors? Thanks, Ori -- View this message in context: http://www.nabble.com/Find-the-compile-erros-tf4210886.html#a11978230 Sent from the IronPython mailing list archive at Nabble.com. From dinov at exchange.microsoft.com Fri Aug 3 17:22:37 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Fri, 3 Aug 2007 08:22:37 -0700 Subject: [IronPython] Declare a class in Python and use it in .net In-Reply-To: <11977831.post@talk.nabble.com> References: <11977831.post@talk.nabble.com> Message-ID: <7AD436E4270DD54A94238001769C2227B979ABD477@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Because Python doesn't create normal .NET classes they basically have to be created from Python code. You could hand a delegate (just a Python function that matches the delegates # of arguments) off to the C# code and call that from C# and get the result back. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Ori Sent: Thursday, August 02, 2007 10:53 PM To: users at lists.ironpython.com Subject: [IronPython] Declare a class in Python and use it in .net Hello, I have a .net class (in some assembly). I want to inherit from it and override a function in it - with python code. I'm using c# to compile the python code, and after the compilation is done I want to create an instance of the new class inside c#. Is there a way to do it? Thanks, Ori -- View this message in context: http://www.nabble.com/Declare-a-class-in-Python-and-use-it-in-.net-tf4210730.html#a11977831 Sent from the IronPython mailing list archive at Nabble.com. _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From dinov at exchange.microsoft.com Fri Aug 3 17:27:09 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Fri, 3 Aug 2007 08:27:09 -0700 Subject: [IronPython] Find the compile erros In-Reply-To: <11978230.post@talk.nabble.com> References: <11978230.post@talk.nabble.com> Message-ID: <7AD436E4270DD54A94238001769C2227B979ABD479@DF-GRTDANE-MSG.exchange.corp.microsoft.com> You can use the Parser class directly for this (e.g. Parser.FromFile or Parser.FromString). You just need to give it a CompilerContext which includes a CompilerSink object. Your CompilerSink object will get called back w/ the errors. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Ori Sent: Thursday, August 02, 2007 11:42 PM To: users at lists.ironpython.com Subject: [IronPython] Find the compile erros Hello, I'm using PythonEngine.Compile to compile code. The code I compile may contain errors and that's why I want to format the error(s). Currently I'm using try-catch and I work with the exception error text. Is there a btter way to get the compilation errors? Thanks, Ori -- View this message in context: http://www.nabble.com/Find-the-compile-erros-tf4210886.html#a11978230 Sent from the IronPython mailing list archive at Nabble.com. _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From oorrii at gmail.com Fri Aug 3 19:28:16 2007 From: oorrii at gmail.com (Ori) Date: Fri, 3 Aug 2007 10:28:16 -0700 (PDT) Subject: [IronPython] Declare a class in Python and use it in .net In-Reply-To: <7AD436E4270DD54A94238001769C2227B979ABD477@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <11977831.post@talk.nabble.com> <7AD436E4270DD54A94238001769C2227B979ABD477@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <11987743.post@talk.nabble.com> How can I do what I asked using delegate? I have to inherit from a class, override a method and return an object. I guess I can manage with returning a delegate that execute the overriden method - but it is important to me that the metod will be a part of a class because the code has calls to other class properties and methods. Dino Viehland wrote: > > Because Python doesn't create normal .NET classes they basically have to > be created from Python code. You could hand a delegate (just a Python > function that matches the delegates # of arguments) off to the C# code and > call that from C# and get the result back. > > -----Original Message----- > From: users-bounces at lists.ironpython.com > [mailto:users-bounces at lists.ironpython.com] On Behalf Of Ori > Sent: Thursday, August 02, 2007 10:53 PM > To: users at lists.ironpython.com > Subject: [IronPython] Declare a class in Python and use it in .net > > > Hello, > > I have a .net class (in some assembly). I want to inherit from it and > override a function in it - with python code. I'm using c# to compile the > python code, and after the compilation is done I want to create an > instance > of the new class inside c#. > > Is there a way to do it? > > Thanks, > Ori > -- > View this message in context: > http://www.nabble.com/Declare-a-class-in-Python-and-use-it-in-.net-tf4210730.html#a11977831 > Sent from the IronPython mailing list archive at Nabble.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 > > -- View this message in context: http://www.nabble.com/Declare-a-class-in-Python-and-use-it-in-.net-tf4210730.html#a11987743 Sent from the IronPython mailing list archive at Nabble.com. From oorrii at gmail.com Fri Aug 3 19:34:43 2007 From: oorrii at gmail.com (Ori) Date: Fri, 3 Aug 2007 10:34:43 -0700 (PDT) Subject: [IronPython] Find the compile erros In-Reply-To: <7AD436E4270DD54A94238001769C2227B979ABD479@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <11978230.post@talk.nabble.com> <7AD436E4270DD54A94238001769C2227B979ABD479@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <11987835.post@talk.nabble.com> I'm sorry but I couldn't find such methods. I'm using version 1.1. Should I upgrade? Dino Viehland wrote: > > You can use the Parser class directly for this (e.g. Parser.FromFile or > Parser.FromString). You just need to give it a CompilerContext which > includes a CompilerSink object. Your CompilerSink object will get called > back w/ the errors. > > -----Original Message----- > From: users-bounces at lists.ironpython.com > [mailto:users-bounces at lists.ironpython.com] On Behalf Of Ori > Sent: Thursday, August 02, 2007 11:42 PM > To: users at lists.ironpython.com > Subject: [IronPython] Find the compile erros > > > Hello, > > I'm using PythonEngine.Compile to compile code. The code I compile may > contain errors and that's why I want to format the error(s). Currently I'm > using try-catch and I work with the exception error text. Is there a btter > way to get the compilation errors? > > Thanks, > Ori > -- > View this message in context: > http://www.nabble.com/Find-the-compile-erros-tf4210886.html#a11978230 > Sent from the IronPython mailing list archive at Nabble.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 > > -- View this message in context: http://www.nabble.com/Find-the-compile-erros-tf4210886.html#a11987835 Sent from the IronPython mailing list archive at Nabble.com. From dinov at exchange.microsoft.com Fri Aug 3 19:35:24 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Fri, 3 Aug 2007 10:35:24 -0700 Subject: [IronPython] Declare a class in Python and use it in .net In-Reply-To: <11987743.post@talk.nabble.com> References: <11977831.post@talk.nabble.com> <7AD436E4270DD54A94238001769C2227B979ABD477@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <11987743.post@talk.nabble.com> Message-ID: <7AD436E4270DD54A94238001769C2227B979ABD4AD@DF-GRTDANE-MSG.exchange.corp.microsoft.com> The inheritance part is no problem, that will just work. For example (warning, compiled w/ Outlook): C#: namespace MyNamespace { public delegate MyClass MyDelegate(); public class MyClass { public virtual string Foo() { return "C# in the house"; } public string CallFoo() { return Foo(); } public static MyClass CreateFoo(MyDelegate creator) { return creator(); } } } Python: import clr clr.AddReference('MyAssembly') from MyNamespace import MyClass class PyClass(MyClass): def Foo(self): return "Python in the house" a = PyClass() a.Foo() # returns 'Python in the house' a.CallFoo() # also returns 'Python in the house' it's the creation of the Python object that's hard. For that you need the delegate because C# won't ever see PyClass as a .NET type that it can allocate: def createPyClass(): return PyClass() MyClass.CreateFoo(createPyClass) # returns a new PyClass -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Ori Sent: Friday, August 03, 2007 10:28 AM To: users at lists.ironpython.com Subject: Re: [IronPython] Declare a class in Python and use it in .net How can I do what I asked using delegate? I have to inherit from a class, override a method and return an object. I guess I can manage with returning a delegate that execute the overriden method - but it is important to me that the metod will be a part of a class because the code has calls to other class properties and methods. Dino Viehland wrote: > > Because Python doesn't create normal .NET classes they basically have to > be created from Python code. You could hand a delegate (just a Python > function that matches the delegates # of arguments) off to the C# code and > call that from C# and get the result back. > > -----Original Message----- > From: users-bounces at lists.ironpython.com > [mailto:users-bounces at lists.ironpython.com] On Behalf Of Ori > Sent: Thursday, August 02, 2007 10:53 PM > To: users at lists.ironpython.com > Subject: [IronPython] Declare a class in Python and use it in .net > > > Hello, > > I have a .net class (in some assembly). I want to inherit from it and > override a function in it - with python code. I'm using c# to compile the > python code, and after the compilation is done I want to create an > instance > of the new class inside c#. > > Is there a way to do it? > > Thanks, > Ori > -- > View this message in context: > http://www.nabble.com/Declare-a-class-in-Python-and-use-it-in-.net-tf4210730.html#a11977831 > Sent from the IronPython mailing list archive at Nabble.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 > > -- View this message in context: http://www.nabble.com/Declare-a-class-in-Python-and-use-it-in-.net-tf4210730.html#a11987743 Sent from the IronPython mailing list archive at Nabble.com. _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From dinov at exchange.microsoft.com Fri Aug 3 19:38:15 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Fri, 3 Aug 2007 10:38:15 -0700 Subject: [IronPython] Find the compile erros In-Reply-To: <11987835.post@talk.nabble.com> References: <11978230.post@talk.nabble.com> <7AD436E4270DD54A94238001769C2227B979ABD479@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <11987835.post@talk.nabble.com> Message-ID: <7AD436E4270DD54A94238001769C2227B979ABD4B4@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Sorry, these are a little scattered around the code base and (mostly) live outside the Hosting namespace. The Parser class is IronPython.Compiler.Parser, the CompilerContext is IronPython.Compiler.CompilerContext, and the CompilerSink which you need to derive from and override AddError is IronPython.Hosting.CompilerSink. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Ori Sent: Friday, August 03, 2007 10:35 AM To: users at lists.ironpython.com Subject: Re: [IronPython] Find the compile erros I'm sorry but I couldn't find such methods. I'm using version 1.1. Should I upgrade? Dino Viehland wrote: > > You can use the Parser class directly for this (e.g. Parser.FromFile or > Parser.FromString). You just need to give it a CompilerContext which > includes a CompilerSink object. Your CompilerSink object will get called > back w/ the errors. > > -----Original Message----- > From: users-bounces at lists.ironpython.com > [mailto:users-bounces at lists.ironpython.com] On Behalf Of Ori > Sent: Thursday, August 02, 2007 11:42 PM > To: users at lists.ironpython.com > Subject: [IronPython] Find the compile erros > > > Hello, > > I'm using PythonEngine.Compile to compile code. The code I compile may > contain errors and that's why I want to format the error(s). Currently I'm > using try-catch and I work with the exception error text. Is there a btter > way to get the compilation errors? > > Thanks, > Ori > -- > View this message in context: > http://www.nabble.com/Find-the-compile-erros-tf4210886.html#a11978230 > Sent from the IronPython mailing list archive at Nabble.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 > > -- View this message in context: http://www.nabble.com/Find-the-compile-erros-tf4210886.html#a11987835 Sent from the IronPython mailing list archive at Nabble.com. _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From oorrii at gmail.com Fri Aug 3 19:45:44 2007 From: oorrii at gmail.com (Ori) Date: Fri, 3 Aug 2007 10:45:44 -0700 (PDT) Subject: [IronPython] Find the compile erros In-Reply-To: <7AD436E4270DD54A94238001769C2227B979ABD4B4@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <11978230.post@talk.nabble.com> <7AD436E4270DD54A94238001769C2227B979ABD479@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <11987835.post@talk.nabble.com> <7AD436E4270DD54A94238001769C2227B979ABD4B4@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <11988015.post@talk.nabble.com> I still can't find how can I create a Parser, and I don't see the fuctions you mentioned: FromFile and FromString. Dino Viehland wrote: > > Sorry, these are a little scattered around the code base and (mostly) live > outside the Hosting namespace. > > The Parser class is IronPython.Compiler.Parser, the CompilerContext is > IronPython.Compiler.CompilerContext, and the CompilerSink which you need > to derive from and override AddError is IronPython.Hosting.CompilerSink. > > -----Original Message----- > From: users-bounces at lists.ironpython.com > [mailto:users-bounces at lists.ironpython.com] On Behalf Of Ori > Sent: Friday, August 03, 2007 10:35 AM > To: users at lists.ironpython.com > Subject: Re: [IronPython] Find the compile erros > > > I'm sorry but I couldn't find such methods. I'm using version 1.1. > Should I upgrade? > > > Dino Viehland wrote: >> >> You can use the Parser class directly for this (e.g. Parser.FromFile or >> Parser.FromString). You just need to give it a CompilerContext which >> includes a CompilerSink object. Your CompilerSink object will get called >> back w/ the errors. >> >> -----Original Message----- >> From: users-bounces at lists.ironpython.com >> [mailto:users-bounces at lists.ironpython.com] On Behalf Of Ori >> Sent: Thursday, August 02, 2007 11:42 PM >> To: users at lists.ironpython.com >> Subject: [IronPython] Find the compile erros >> >> >> Hello, >> >> I'm using PythonEngine.Compile to compile code. The code I compile may >> contain errors and that's why I want to format the error(s). Currently >> I'm >> using try-catch and I work with the exception error text. Is there a >> btter >> way to get the compilation errors? >> >> Thanks, >> Ori >> -- >> View this message in context: >> http://www.nabble.com/Find-the-compile-erros-tf4210886.html#a11978230 >> Sent from the IronPython mailing list archive at Nabble.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 >> >> > > -- > View this message in context: > http://www.nabble.com/Find-the-compile-erros-tf4210886.html#a11987835 > Sent from the IronPython mailing list archive at Nabble.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 > > -- View this message in context: http://www.nabble.com/Find-the-compile-erros-tf4210886.html#a11988015 Sent from the IronPython mailing list archive at Nabble.com. From dinov at exchange.microsoft.com Fri Aug 3 19:57:25 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Fri, 3 Aug 2007 10:57:25 -0700 Subject: [IronPython] Find the compile erros In-Reply-To: <11988015.post@talk.nabble.com> References: <11978230.post@talk.nabble.com> <7AD436E4270DD54A94238001769C2227B979ABD479@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <11987835.post@talk.nabble.com> <7AD436E4270DD54A94238001769C2227B979ABD4B4@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <11988015.post@talk.nabble.com> Message-ID: <7AD436E4270DD54A94238001769C2227B979ABD4C7@DF-GRTDANE-MSG.exchange.corp.microsoft.com> The FromFile and FromString methods are public static methods on the Parser class that create the Parser object. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Ori Sent: Friday, August 03, 2007 10:46 AM To: users at lists.ironpython.com Subject: Re: [IronPython] Find the compile erros I still can't find how can I create a Parser, and I don't see the fuctions you mentioned: FromFile and FromString. Dino Viehland wrote: > > Sorry, these are a little scattered around the code base and (mostly) live > outside the Hosting namespace. > > The Parser class is IronPython.Compiler.Parser, the CompilerContext is > IronPython.Compiler.CompilerContext, and the CompilerSink which you need > to derive from and override AddError is IronPython.Hosting.CompilerSink. > > -----Original Message----- > From: users-bounces at lists.ironpython.com > [mailto:users-bounces at lists.ironpython.com] On Behalf Of Ori > Sent: Friday, August 03, 2007 10:35 AM > To: users at lists.ironpython.com > Subject: Re: [IronPython] Find the compile erros > > > I'm sorry but I couldn't find such methods. I'm using version 1.1. > Should I upgrade? > > > Dino Viehland wrote: >> >> You can use the Parser class directly for this (e.g. Parser.FromFile or >> Parser.FromString). You just need to give it a CompilerContext which >> includes a CompilerSink object. Your CompilerSink object will get called >> back w/ the errors. >> >> -----Original Message----- >> From: users-bounces at lists.ironpython.com >> [mailto:users-bounces at lists.ironpython.com] On Behalf Of Ori >> Sent: Thursday, August 02, 2007 11:42 PM >> To: users at lists.ironpython.com >> Subject: [IronPython] Find the compile erros >> >> >> Hello, >> >> I'm using PythonEngine.Compile to compile code. The code I compile may >> contain errors and that's why I want to format the error(s). Currently >> I'm >> using try-catch and I work with the exception error text. Is there a >> btter >> way to get the compilation errors? >> >> Thanks, >> Ori >> -- >> View this message in context: >> http://www.nabble.com/Find-the-compile-erros-tf4210886.html#a11978230 >> Sent from the IronPython mailing list archive at Nabble.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 >> >> > > -- > View this message in context: > http://www.nabble.com/Find-the-compile-erros-tf4210886.html#a11987835 > Sent from the IronPython mailing list archive at Nabble.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 > > -- View this message in context: http://www.nabble.com/Find-the-compile-erros-tf4210886.html#a11988015 Sent from the IronPython mailing list archive at Nabble.com. _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From oorrii at gmail.com Sat Aug 4 06:53:36 2007 From: oorrii at gmail.com (Ori) Date: Fri, 3 Aug 2007 21:53:36 -0700 (PDT) Subject: [IronPython] Find the compile erros In-Reply-To: <7AD436E4270DD54A94238001769C2227B979ABD4C7@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <11978230.post@talk.nabble.com> <7AD436E4270DD54A94238001769C2227B979ABD479@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <11987835.post@talk.nabble.com> <7AD436E4270DD54A94238001769C2227B979ABD4B4@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <11988015.post@talk.nabble.com> <7AD436E4270DD54A94238001769C2227B979ABD4C7@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <11993930.post@talk.nabble.com> thanks, but I still can't make it. I Implemented my own CompilerSink and tried the following code: SystemState state = new SystemState(); CompilerContext context = new CompilerContext(string.Empty, new MySink()); Parser parser = Parser.FromString(state, context, "some code with error"); but the AddError method was not called. Dino Viehland wrote: > > The FromFile and FromString methods are public static methods on the > Parser class that create the Parser object. > > -----Original Message----- > From: users-bounces at lists.ironpython.com > [mailto:users-bounces at lists.ironpython.com] On Behalf Of Ori > Sent: Friday, August 03, 2007 10:46 AM > To: users at lists.ironpython.com > Subject: Re: [IronPython] Find the compile erros > > > I still can't find how can I create a Parser, and I don't see the fuctions > you mentioned: FromFile and FromString. > > > Dino Viehland wrote: >> >> Sorry, these are a little scattered around the code base and (mostly) >> live >> outside the Hosting namespace. >> >> The Parser class is IronPython.Compiler.Parser, the CompilerContext is >> IronPython.Compiler.CompilerContext, and the CompilerSink which you need >> to derive from and override AddError is IronPython.Hosting.CompilerSink. >> >> -----Original Message----- >> From: users-bounces at lists.ironpython.com >> [mailto:users-bounces at lists.ironpython.com] On Behalf Of Ori >> Sent: Friday, August 03, 2007 10:35 AM >> To: users at lists.ironpython.com >> Subject: Re: [IronPython] Find the compile erros >> >> >> I'm sorry but I couldn't find such methods. I'm using version 1.1. >> Should I upgrade? >> >> >> Dino Viehland wrote: >>> >>> You can use the Parser class directly for this (e.g. Parser.FromFile or >>> Parser.FromString). You just need to give it a CompilerContext which >>> includes a CompilerSink object. Your CompilerSink object will get >>> called >>> back w/ the errors. >>> >>> -----Original Message----- >>> From: users-bounces at lists.ironpython.com >>> [mailto:users-bounces at lists.ironpython.com] On Behalf Of Ori >>> Sent: Thursday, August 02, 2007 11:42 PM >>> To: users at lists.ironpython.com >>> Subject: [IronPython] Find the compile erros >>> >>> >>> Hello, >>> >>> I'm using PythonEngine.Compile to compile code. The code I compile may >>> contain errors and that's why I want to format the error(s). Currently >>> I'm >>> using try-catch and I work with the exception error text. Is there a >>> btter >>> way to get the compilation errors? >>> >>> Thanks, >>> Ori >>> -- >>> View this message in context: >>> http://www.nabble.com/Find-the-compile-erros-tf4210886.html#a11978230 >>> Sent from the IronPython mailing list archive at Nabble.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 >>> >>> >> >> -- >> View this message in context: >> http://www.nabble.com/Find-the-compile-erros-tf4210886.html#a11987835 >> Sent from the IronPython mailing list archive at Nabble.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 >> >> > > -- > View this message in context: > http://www.nabble.com/Find-the-compile-erros-tf4210886.html#a11988015 > Sent from the IronPython mailing list archive at Nabble.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 > > -- View this message in context: http://www.nabble.com/Find-the-compile-erros-tf4210886.html#a11993930 Sent from the IronPython mailing list archive at Nabble.com. From oorrii at gmail.com Sat Aug 4 12:54:14 2007 From: oorrii at gmail.com (Ori) Date: Sat, 4 Aug 2007 03:54:14 -0700 (PDT) Subject: [IronPython] Inheritance from a c# subclass Message-ID: <11995601.post@talk.nabble.com> Hello, I have a public subclass in an assembly I reference. I want to create a new python class which inherits from the subcalss. I tried: from MyNamespace import MyClass.MySubClass class PyClass(MyClass.MySubClass) but I got the following compile error: unexpected token . Is there a way to do it? Thanks, Ori -- View this message in context: http://www.nabble.com/Inheritance-from-a-c--subclass-tf4216398.html#a11995601 Sent from the IronPython mailing list archive at Nabble.com. From oorrii at gmail.com Sat Aug 4 12:59:42 2007 From: oorrii at gmail.com (Ori) Date: Sat, 4 Aug 2007 03:59:42 -0700 (PDT) Subject: [IronPython] avoiding using the keyword 'self' Message-ID: <11995646.post@talk.nabble.com> Hello, I have a python class which inherits from some other (c#) class. Something like: from MyNamespace import MyClass class PyClass(MyClass) def myMethod(self) return self.PropertyFormInheritedClass I don't understand why I have to write the "self." prefix - the context is the inherited class. Is there a way to avoid this prefix? Thanks, Ori -- View this message in context: http://www.nabble.com/avoiding-using-the-keyword-%27self%27-tf4216418.html#a11995646 Sent from the IronPython mailing list archive at Nabble.com. From fuzzyman at voidspace.org.uk Sat Aug 4 13:30:04 2007 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Sat, 04 Aug 2007 12:30:04 +0100 Subject: [IronPython] avoiding using the keyword 'self' In-Reply-To: <11995646.post@talk.nabble.com> References: <11995646.post@talk.nabble.com> Message-ID: <46B4633C.3030507@voidspace.org.uk> Ori wrote: > Hello, > > I have a python class which inherits from some other (c#) class. Something > like: > from MyNamespace import MyClass > class PyClass(MyClass) > def myMethod(self) > return self.PropertyFormInheritedClass > You appear to have a syntax error here (which may be the answer to your previous question about why your inheritance doesn't work). The class declaration must be terminated with a colon: class PyClass(MyClass): > I don't understand why I have to write the "self." prefix - the context is > the inherited class. Is there a way to avoid this prefix? > Please read the Python FAQ about self (Python is not C#). 'Why must 'self' be used explicitly in method definitions and calls?' http://www.python.org/doc/faq/general/#why-must-self-be-used-explicitly-in-method-definitions-and-calls Michael Foord http://www.ironpython.info/ > Thanks, > Ori > From oorrii at gmail.com Sat Aug 4 16:19:52 2007 From: oorrii at gmail.com (Ori) Date: Sat, 4 Aug 2007 07:19:52 -0700 (PDT) Subject: [IronPython] avoiding using the keyword 'self' In-Reply-To: <11995646.post@talk.nabble.com> References: <11995646.post@talk.nabble.com> Message-ID: <11996927.post@talk.nabble.com> I guess the answer is no, and I must explicitly use the 'self.' prefix. About the syntax error - you are right, there is one in the post, but it has nothing to do with ineriting from a sub-class Ori wrote: > > Hello, > > I have a python class which inherits from some other (c#) class. Something > like: > from MyNamespace import MyClass > class PyClass(MyClass) > def myMethod(self) > return self.PropertyFormInheritedClass > > I don't understand why I have to write the "self." prefix - the context is > the inherited class. Is there a way to avoid this prefix? > > Thanks, > Ori > -- View this message in context: http://www.nabble.com/avoiding-using-the-keyword-%27self%27-tf4216418.html#a11996927 Sent from the IronPython mailing list archive at Nabble.com. From darren at ontrenet.com Sun Aug 5 06:50:04 2007 From: darren at ontrenet.com (Darren Govoni) Date: Sun, 5 Aug 2007 00:50:04 -0400 Subject: [IronPython] .NET can see Python classes? Message-ID: Hi, Can .NET see python defined classes or objects? I define a class in Python but one of my .NET classes tries to find it via reflection and it cannot. I saw a post about this that is over a year old saying it was not then supported. Could this possible in IP 2.0? thank you, D -------------- next part -------------- An HTML attachment was scrubbed... URL: From oorrii at gmail.com Sun Aug 5 06:57:49 2007 From: oorrii at gmail.com (Ori) Date: Sat, 4 Aug 2007 21:57:49 -0700 (PDT) Subject: [IronPython] .NET can see Python classes? In-Reply-To: References: Message-ID: <12002302.post@talk.nabble.com> you can try the following code: PythonEngine engine = new PythonEngine(); EngineModule module = engine.CreateModule(); engine.Execute(handleCode(code, def), module); # code contains definition for python class 'PyClass' UserType ptype = module.Globals["PyClass"] as UserType; object obj = Ops.Call(ptype); Darren Govoni-2 wrote: > > Hi, > Can .NET see python defined classes or objects? I define a class in > Python > but one of my .NET classes tries to find it via reflection and it cannot. > I saw a post about this that is over a year old saying it was not then > supported. > > Could this possible in IP 2.0? > > thank you, > D > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > -- View this message in context: http://www.nabble.com/-IronPython--.NET-can-see-Python-classes--tf4218815.html#a12002302 Sent from the IronPython mailing list archive at Nabble.com. From sanxiyn at gmail.com Sun Aug 5 07:37:14 2007 From: sanxiyn at gmail.com (Sanghyeon Seo) Date: Sun, 5 Aug 2007 14:37:14 +0900 Subject: [IronPython] avoiding using the keyword 'self' In-Reply-To: <11995646.post@talk.nabble.com> References: <11995646.post@talk.nabble.com> Message-ID: <5b0248170708042237h56d2a65dma470cd3baf544881@mail.gmail.com> 2007/8/4, Ori : > I don't understand why I have to write the "self." prefix - the context is > the inherited class. Is there a way to avoid this prefix? No. You are programming in Python. -- Seo Sanghyeon From sanxiyn at gmail.com Sun Aug 5 07:38:25 2007 From: sanxiyn at gmail.com (Sanghyeon Seo) Date: Sun, 5 Aug 2007 14:38:25 +0900 Subject: [IronPython] .NET can see Python classes? In-Reply-To: References: Message-ID: <5b0248170708042238g11510f3am4f1a549c9b740b31@mail.gmail.com> 2007/8/5, Darren Govoni : > Can .NET see python defined classes or objects? No. -- Seo Sanghyeon From oorrii at gmail.com Sun Aug 5 08:49:56 2007 From: oorrii at gmail.com (Ori) Date: Sun, 05 Aug 2007 06:49:56 -0000 Subject: [IronPython] Inheritance from a c# subclass In-Reply-To: <11995601.post@talk.nabble.com> References: <11995601.post@talk.nabble.com> Message-ID: <1186296596.202018.203930@57g2000hsv.googlegroups.com> I found the problem. the 'from' section should not contain the subclass name On Aug 4, 1:54 pm, Ori wrote: > Hello, > > I have a public subclass in an assembly I reference. I want to create a new > python class which inherits from the subcalss. > > I tried: > from MyNamespace import MyClass.MySubClass > class PyClass(MyClass.MySubClass) > > but I got the following compile error: unexpected token . > > Is there a way to do it? > > Thanks, > Ori > > -- > View this message in context:http://www.nabble.com/Inheritance-from-a-c--subclass-tf4216398.html#a... > Sent from the IronPython mailing list archive at Nabble.com. > > _______________________________________________ > Users mailing list > Us... at lists.ironpython.comhttp://lists.ironpython.com/listinfo.cgi/users-ironpython.com From curt at hagenlocher.org Sun Aug 5 18:31:59 2007 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Sun, 5 Aug 2007 09:31:59 -0700 Subject: [IronPython] .NET can see Python classes? In-Reply-To: References: Message-ID: On 8/4/07, Darren Govoni wrote: > > Can .NET see python defined classes or objects? I define a class in > Python > but one of my .NET classes tries to find it via reflection and it cannot. > I saw a post about this that is over a year old saying it was not then > supported. > The fundamental issue here is that Python classes don't follow the same semantics as CLR classes. They are, for instance, mutable after construction in ways that CLR classes are not. In order to expose a Python class directly to the CLR, it would have to be "frozen" in some manner, and you might prefer to be able to specify the types of the parameters instead of dealing with everything as "object". This would require some sort of non-Python syntax to accomplish. Fortunately, there already is such a thing: a CLR interface. Define an interface in an external assembly and you can derive from it in Python. Your CLR classes can then access the Python code through the interface. -- Curt Hagenlocher curt at hagenlocher.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From darren at ontrenet.com Sun Aug 5 19:24:58 2007 From: darren at ontrenet.com (Darren Govoni) Date: Sun, 5 Aug 2007 13:24:58 -0400 Subject: [IronPython] .NET can see Python classes? In-Reply-To: References: Message-ID: I see. Currently, my python class extends a CLR class, but the python class is not resolvable from CLR. I want a CLR persistence engine to be able to reflect on the python class as if it were a CLR class, but it says it cannot find the MyPython class created in my python script. I guess my python classes also do not fall under a given CLR namespace either? Now, if it were a pure interface implementation, I suppose its not possible to pass an instance of MyPython back to CLR to process as a normal class instance (including reflection)? thanks. I really like IronPython and it works great embedded in my app. Darren ----- Original Message ----- From: Curt Hagenlocher To: Discussion of IronPython Sent: Sunday, August 05, 2007 12:31 PM Subject: Re: [IronPython] .NET can see Python classes? On 8/4/07, Darren Govoni wrote: Can .NET see python defined classes or objects? I define a class in Python but one of my .NET classes tries to find it via reflection and it cannot. I saw a post about this that is over a year old saying it was not then supported. The fundamental issue here is that Python classes don't follow the same semantics as CLR classes. They are, for instance, mutable after construction in ways that CLR classes are not. In order to expose a Python class directly to the CLR, it would have to be "frozen" in some manner, and you might prefer to be able to specify the types of the parameters instead of dealing with everything as "object". This would require some sort of non-Python syntax to accomplish. Fortunately, there already is such a thing: a CLR interface. Define an interface in an external assembly and you can derive from it in Python. Your CLR classes can then access the Python code through the interface. -- Curt Hagenlocher curt at hagenlocher.org ------------------------------------------------------------------------------ _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From jjl at pobox.com Sun Aug 5 19:53:48 2007 From: jjl at pobox.com (John J Lee) Date: Sun, 5 Aug 2007 18:53:48 +0100 (BST) Subject: [IronPython] .NET can see Python classes? In-Reply-To: References: Message-ID: On Sun, 5 Aug 2007, Curt Hagenlocher wrote: > On 8/4/07, Darren Govoni wrote: [...] > construction in ways that CLR classes are not. In order to expose a Python > class directly to the CLR, it would have to be "frozen" in some manner, and A metaclass could achieve that. > you might prefer to be able to specify the types of the parameters instead > of dealing with everything as "object". This would require some sort of > non-Python syntax to accomplish. Fortunately, there already is such a Maybe in the future this will be used? http://www.python.org/dev/peps/pep-3107/ John From belred at gmail.com Sun Aug 5 20:05:01 2007 From: belred at gmail.com (Bryan) Date: Sun, 5 Aug 2007 11:05:01 -0700 Subject: [IronPython] .NET can see Python classes? In-Reply-To: References: Message-ID: <38f48f590708051104w7a1dc5a6qcb012f6a7ea357c7@mail.gmail.com> On 8/5/07, Curt Hagenlocher wrote: > On 8/4/07, Darren Govoni wrote: > > The fundamental issue here is that Python classes don't follow the same > semantics as CLR classes. They are, for instance, mutable after > construction in ways that CLR classes are not. In order to expose a Python > class directly to the CLR, it would have to be "frozen" in some manner, and > you might prefer to be able to specify the types of the parameters instead > of dealing with everything as "object". This would require some sort of > non-Python syntax to accomplish. Fortunately, there already is such a > thing: a CLR interface. Define an interface in an external assembly and you > can derive from it in Python. Your CLR classes can then access the Python > code through the interface. > > -- > Curt Hagenlocher > curt at hagenlocher.org hi curt, i to would like to do this. i don't understand a part of this. i understand creating a CLR interface and i understand creating a python file that has a class that derives from the CLR interface. but how does the CLR code instantiate the derived class and access the Python code through the interface? where does this instance come from? thanks, bryan From curt at hagenlocher.org Sun Aug 5 20:32:59 2007 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Sun, 5 Aug 2007 11:32:59 -0700 Subject: [IronPython] .NET can see Python classes? In-Reply-To: <38f48f590708051104w7a1dc5a6qcb012f6a7ea357c7@mail.gmail.com> References: <38f48f590708051104w7a1dc5a6qcb012f6a7ea357c7@mail.gmail.com> Message-ID: On 8/5/07, Bryan wrote: > > > i to would like to do this. i don't understand a part of this. i > understand creating a CLR interface and i understand creating a python > file that has a class that derives from the CLR interface. but how > does the CLR code instantiate the derived class and access the Python > code through the interface? where does this instance come from? You would have to interact directly with the IronPython engine from the "CLR code" in order to get an instance of the class. Something like the code that Ori posted earlier in the thread would work for that. -- Curt Hagenlocher curt at hagenlocher.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuzzyman at voidspace.org.uk Sun Aug 5 21:28:38 2007 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Sun, 05 Aug 2007 20:28:38 +0100 Subject: [IronPython] .NET can see Python classes? In-Reply-To: <12002302.post@talk.nabble.com> References: <12002302.post@talk.nabble.com> Message-ID: <46B624E6.2090402@voidspace.org.uk> Ori wrote: > you can try the following code: > > PythonEngine engine = new PythonEngine(); > EngineModule module = engine.CreateModule(); > engine.Execute(handleCode(code, def), module); # code contains definition > for python class 'PyClass' > UserType ptype = module.Globals["PyClass"] as UserType; > object obj = Ops.Call(ptype); > Here is a full example: using System; using IronPython.Hosting; using IronPython.Runtime.Types; using IronPython.Runtime.Operations; namespace TestPythonConsole { class Program { static void Main() { string code = "import clr\r\nclr.AddReference('TestPythonConsole')\r\nfrom TestPythonConsole import Test\r\nclass X(Test):\r\n def test(self):\r\n return 'hello'\r\n\r\n"; PythonEngine engine = new PythonEngine(); EngineModule module = engine.CreateModule(); engine.DefaultModule = module; engine.Execute(code); UserType ptype = module.Globals["X"] as UserType; Test obj = Ops.Call(ptype) as Test; Console.WriteLine(obj.test()); } } public class Test { virtual public string test() { return "goodbye"; } } } The Python code imports 'Test' (it has to add the right reference to the assembly first). It then subclasses 'Test' in a class called X. The class we pull out of the Python engine globals is called and the result cast to Test. Calling the method 'test' calls the subclass rather than the parent class. I hope that helps. Michael Foord http://www.ironpython.info/ > > Darren Govoni-2 wrote: > >> Hi, >> Can .NET see python defined classes or objects? I define a class in >> Python >> but one of my .NET classes tries to find it via reflection and it cannot. >> I saw a post about this that is over a year old saying it was not then >> supported. >> >> Could this possible in IP 2.0? >> >> thank you, >> D >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> >> >> > > From oorrii at gmail.com Sun Aug 5 21:51:43 2007 From: oorrii at gmail.com (Ori) Date: Sun, 5 Aug 2007 12:51:43 -0700 (PDT) Subject: [IronPython] Compiler error for invalid field access Message-ID: <12007623.post@talk.nabble.com> Hello, I'm using the following code to compile python code: SystemState state = new SystemState(); MyCompilerSink sink = new MyCompilerSink(); CompilerContext context = new CompilerContext(string.Empty, sink); Parser parser = Parser.FromString(state, context, "my code"); parser.ParseFileInput(); it works find for finding syntax mistakes - but I also wan to know about invalid property names / method names. If for example the code uses the expression 'self.Name' I would like to see a compilation error if the object does not have a 'Name' property. Is there a way to do it? Thanks, Ori -- View this message in context: http://www.nabble.com/Compiler-error-for-invalid-field-access-tf4220967.html#a12007623 Sent from the IronPython mailing list archive at Nabble.com. From fuzzyman at voidspace.org.uk Sun Aug 5 21:56:04 2007 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Sun, 05 Aug 2007 20:56:04 +0100 Subject: [IronPython] Compiler error for invalid field access In-Reply-To: <12007623.post@talk.nabble.com> References: <12007623.post@talk.nabble.com> Message-ID: <46B62B54.3030602@voidspace.org.uk> Ori wrote: > Hello, > > I'm using the following code to compile python code: > > SystemState state = new SystemState(); > MyCompilerSink sink = new MyCompilerSink(); > CompilerContext context = new CompilerContext(string.Empty, sink); > Parser parser = Parser.FromString(state, context, "my code"); > parser.ParseFileInput(); > > it works find for finding syntax mistakes - but I also wan to know about > invalid property names / method names. If for example the code uses the > expression 'self.Name' I would like to see a compilation error if the object > does not have a 'Name' property. > > Is there a way to do it? > Python does not generate 'compile' errors for these sorts of problems. Python is dynamically typed, so it doesn't know about the type of objects at compile time - instead errors will be generated at runtime. As well as catching errors at compilation (syntax errors) you will also need to catch potential errors where these objects are used. This is the joy and the pain of using a dynamically typed language. All the best, Michael Foord http://www.ironpython.info/ > Thanks, > Ori > From wd at teleri.net Sun Aug 5 21:57:55 2007 From: wd at teleri.net (Chip Norkus) Date: Sun, 5 Aug 2007 12:57:55 -0700 Subject: [IronPython] Compiler error for invalid field access In-Reply-To: <12007623.post@talk.nabble.com> References: <12007623.post@talk.nabble.com> Message-ID: <20070805195755.GA25884@teleri.net> On Sun Aug 05, 2007; 12:51PM -0700, Ori wrote: > > Hello, > > I'm using the following code to compile python code: > > SystemState state = new SystemState(); > MyCompilerSink sink = new MyCompilerSink(); > CompilerContext context = new CompilerContext(string.Empty, sink); > Parser parser = Parser.FromString(state, context, "my code"); > parser.ParseFileInput(); > > it works find for finding syntax mistakes - but I also wan to know about > invalid property names / method names. If for example the code uses the > expression 'self.Name' I would like to see a compilation error if the object > does not have a 'Name' property. > Because objects are mutable Python by its nature does not resolve member/property references until they occur within the code. Consider the following example (which is valid functional Python): class foo(object): setup = False f = foo() def bar(f): if f.setup: f.baz = "hi" print f.baz else: f.setup = True print "setup" bar(f) bar(f) > Is there a way to do it? > > Thanks, > Ori > -- > View this message in context: http://www.nabble.com/Compiler-error-for-invalid-field-access-tf4220967.html#a12007623 > Sent from the IronPython mailing list archive at Nabble.com. > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > -chip -- personal: chip norkus; irc: wd; wd at teleri.net info: finger wd at teleri.net for plan or keys; http://telekinesis.org From oorrii at gmail.com Sun Aug 5 22:07:34 2007 From: oorrii at gmail.com (Ori) Date: Sun, 5 Aug 2007 13:07:34 -0700 (PDT) Subject: [IronPython] Compiler error for invalid field access In-Reply-To: <20070805195755.GA25884@teleri.net> References: <12007623.post@talk.nabble.com> <20070805195755.GA25884@teleri.net> Message-ID: <12007689.post@talk.nabble.com> Executing the code to know if there is a problem or not is not what I wish for. I really can't do it because in my case the context does not exist. I will try to create a 'fake' context in order to run the code, but I'm not sure it is a good idea.. Chip Norkus wrote: > > On Sun Aug 05, 2007; 12:51PM -0700, Ori wrote: >> >> Hello, >> >> I'm using the following code to compile python code: >> >> SystemState state = new SystemState(); >> MyCompilerSink sink = new MyCompilerSink(); >> CompilerContext context = new CompilerContext(string.Empty, sink); >> Parser parser = Parser.FromString(state, context, "my code"); >> parser.ParseFileInput(); >> >> it works find for finding syntax mistakes - but I also wan to know about >> invalid property names / method names. If for example the code uses the >> expression 'self.Name' I would like to see a compilation error if the >> object >> does not have a 'Name' property. >> > > Because objects are mutable Python by its nature does not resolve > member/property references until they occur within the code. Consider > the following example (which is valid functional Python): > > class foo(object): > setup = False > > f = foo() > > def bar(f): > if f.setup: > f.baz = "hi" > print f.baz > else: > f.setup = True > print "setup" > > bar(f) > bar(f) > > > >> Is there a way to do it? >> >> Thanks, >> Ori >> -- >> View this message in context: >> http://www.nabble.com/Compiler-error-for-invalid-field-access-tf4220967.html#a12007623 >> Sent from the IronPython mailing list archive at Nabble.com. >> >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> > -chip > -- > personal: chip norkus; irc: wd; wd at teleri.net > info: finger wd at teleri.net for plan or keys; http://telekinesis.org > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > -- View this message in context: http://www.nabble.com/Compiler-error-for-invalid-field-access-tf4220967.html#a12007689 Sent from the IronPython mailing list archive at Nabble.com. From fuzzyman at voidspace.org.uk Sun Aug 5 22:11:14 2007 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Sun, 05 Aug 2007 21:11:14 +0100 Subject: [IronPython] Compiler error for invalid field access In-Reply-To: <12007689.post@talk.nabble.com> References: <12007623.post@talk.nabble.com> <20070805195755.GA25884@teleri.net> <12007689.post@talk.nabble.com> Message-ID: <46B62EE2.1000109@voidspace.org.uk> Ori wrote: > Executing the code to know if there is a problem or not is not what I wish > for. I really can't do it because in my case the context does not exist. > I will try to create a 'fake' context in order to run the code, but I'm not > sure it is a good idea.. > > I presume you are executing the code *somewhere*. What about catching the error there? (Or creating a 'safe execution' method that does the error trapping and routing all calls through that?) Michael Foord http://www.ironpython.info/ > Chip Norkus wrote: > >> On Sun Aug 05, 2007; 12:51PM -0700, Ori wrote: >> >>> Hello, >>> >>> I'm using the following code to compile python code: >>> >>> SystemState state = new SystemState(); >>> MyCompilerSink sink = new MyCompilerSink(); >>> CompilerContext context = new CompilerContext(string.Empty, sink); >>> Parser parser = Parser.FromString(state, context, "my code"); >>> parser.ParseFileInput(); >>> >>> it works find for finding syntax mistakes - but I also wan to know about >>> invalid property names / method names. If for example the code uses the >>> expression 'self.Name' I would like to see a compilation error if the >>> object >>> does not have a 'Name' property. >>> >>> >> Because objects are mutable Python by its nature does not resolve >> member/property references until they occur within the code. Consider >> the following example (which is valid functional Python): >> >> class foo(object): >> setup = False >> >> f = foo() >> >> def bar(f): >> if f.setup: >> f.baz = "hi" >> print f.baz >> else: >> f.setup = True >> print "setup" >> >> bar(f) >> bar(f) >> >> >> >> >>> Is there a way to do it? >>> >>> Thanks, >>> Ori >>> -- >>> View this message in context: >>> http://www.nabble.com/Compiler-error-for-invalid-field-access-tf4220967.html#a12007623 >>> Sent from the IronPython mailing list archive at Nabble.com. >>> >>> _______________________________________________ >>> Users mailing list >>> Users at lists.ironpython.com >>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >>> >>> >> -chip >> -- >> personal: chip norkus; irc: wd; wd at teleri.net >> info: finger wd at teleri.net for plan or keys; http://telekinesis.org >> _______________________________________________ >> Users mailing list >> Users at lists.ironpython.com >> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >> >> >> > > From oorrii at gmail.com Sun Aug 5 22:23:47 2007 From: oorrii at gmail.com (Ori - Gmail) Date: Sun, 5 Aug 2007 23:23:47 +0300 Subject: [IronPython] Compiler error for invalid field access In-Reply-To: <46B62EE2.1000109@voidspace.org.uk> Message-ID: <46b631d8.143f420a.32d3.fffff86e@mx.google.com> Well yes, *somewhere*, but there is a big difference between writing the code and executing it. It is not easy to create and manage the context in my case -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord Sent: ? 05 ?????? 2007 23:11 To: Discussion of IronPython Subject: Re: [IronPython] Compiler error for invalid field access Ori wrote: > Executing the code to know if there is a problem or not is not what I wish > for. I really can't do it because in my case the context does not exist. > I will try to create a 'fake' context in order to run the code, but I'm not > sure it is a good idea.. > > I presume you are executing the code *somewhere*. What about catching the error there? (Or creating a 'safe execution' method that does the error trapping and routing all calls through that?) Michael Foord http://www.ironpython.info/ > Chip Norkus wrote: > >> On Sun Aug 05, 2007; 12:51PM -0700, Ori wrote: >> >>> Hello, >>> >>> I'm using the following code to compile python code: >>> >>> SystemState state = new SystemState(); >>> MyCompilerSink sink = new MyCompilerSink(); >>> CompilerContext context = new CompilerContext(string.Empty, sink); >>> Parser parser = Parser.FromString(state, context, "my code"); >>> parser.ParseFileInput(); >>> >>> it works find for finding syntax mistakes - but I also wan to know about >>> invalid property names / method names. If for example the code uses the >>> expression 'self.Name' I would like to see a compilation error if the >>> object >>> does not have a 'Name' property. >>> >>> >> Because objects are mutable Python by its nature does not resolve >> member/property references until they occur within the code. Consider >> the following example (which is valid functional Python): >> >> class foo(object): >> setup = False >> >> f = foo() >> >> def bar(f): >> if f.setup: >> f.baz = "hi" >> print f.baz >> else: >> f.setup = True >> print "setup" >> >> bar(f) >> bar(f) >> >> >> >> >>> Is there a way to do it? >>> >>> Thanks, >>> Ori >>> -- >>> View this message in context: >>> http://www.nabble.com/Compiler-error-for-invalid-field-access-tf4220967.html #a12007623 >>> Sent from the IronPython mailing list archive at Nabble.com. >>> >>> _______________________________________________ >>> Users mailing list >>> Users at lists.ironpython.com >>> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com >>> >>> >> -chip >> -- >> personal: chip norkus; irc: wd; wd at teleri.net >> info: finger wd at teleri.net for plan or keys; http://telekinesis.org >> _______________________________________________ >> 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 From belred at gmail.com Sun Aug 5 22:51:43 2007 From: belred at gmail.com (Bryan) Date: Sun, 5 Aug 2007 13:51:43 -0700 Subject: [IronPython] .NET can see Python classes? In-Reply-To: <46B624E6.2090402@voidspace.org.uk> References: <12002302.post@talk.nabble.com> <46B624E6.2090402@voidspace.org.uk> Message-ID: <38f48f590708051351je36e62lbd435d9dccbf448a@mail.gmail.com> On 8/5/07, Michael Foord wrote: > Here is a full example: > > using System; > using IronPython.Hosting; > using IronPython.Runtime.Types; > using IronPython.Runtime.Operations; > > namespace TestPythonConsole > { > class Program > { > static void Main() > { > string code = "import > clr\r\nclr.AddReference('TestPythonConsole')\r\nfrom TestPythonConsole > import Test\r\nclass X(Test):\r\n def test(self):\r\n return > 'hello'\r\n\r\n"; > PythonEngine engine = new PythonEngine(); > EngineModule module = engine.CreateModule(); > engine.DefaultModule = module; > engine.Execute(code); > UserType ptype = module.Globals["X"] as UserType; > Test obj = Ops.Call(ptype) as Test; > Console.WriteLine(obj.test()); > } > } > > public class Test > { > virtual public string test() > { > return "goodbye"; > } > } > > } > > Michael Foord this is great news. this is very helpful... thanks. i assume there is another Execute method that you can pass in a path to file or take a file object so we don't have to write the code in a C# string. what i would like to do is create the skeleton of C# web services, then have it call out to python code. what you just showed here is that this is definitely possible. also, i see that your Test was a class and not a pure interface. i hope this will work with pure interfaces too. bryan From fuzzyman at voidspace.org.uk Sun Aug 5 22:58:32 2007 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Sun, 05 Aug 2007 21:58:32 +0100 Subject: [IronPython] .NET can see Python classes? In-Reply-To: <38f48f590708051351je36e62lbd435d9dccbf448a@mail.gmail.com> References: <12002302.post@talk.nabble.com> <46B624E6.2090402@voidspace.org.uk> <38f48f590708051351je36e62lbd435d9dccbf448a@mail.gmail.com> Message-ID: <46B639F8.9060106@voidspace.org.uk> Bryan wrote: > On 8/5/07, Michael Foord wrote: > >> Here is a full example: >> [snip...] >> > > this is great news. this is very helpful... thanks. i assume there > is another Execute method that you can pass in a path to file or take > a file object so we don't have to write the code in a C# string. I believe there is an ExecuteFile method but you should check the docs. > what > i would like to do is create the skeleton of C# web services, then > have it call out to python code. what you just showed here is that > this is definitely possible. also, i see that your Test was a class > and not a pure interface. i hope this will work with pure interfaces > too. > I'm sure it will. I'm not sure of the exact semantics though. I know that I have created Python classes that inherit from .NET interfaces. Alternatively you could create an abstract C# class that implements the interface and inherit from that. If it does work, posting an example would be great. Michael http://www.ironpython.info/ > > bryan > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > From hugonz-lists at h-lab.net Mon Aug 6 00:28:48 2007 From: hugonz-lists at h-lab.net (=?ISO-8859-1?Q?Hugo_Gonz=E1lez_Monteverde?=) Date: Sun, 05 Aug 2007 17:28:48 -0500 Subject: [IronPython] New to Ironpython. Want to glue DLL with Python code Message-ID: <46B64F20.1090405@h-lab.net> Hi all, I'm new to IronPython, thought I've been using CPython for two years now. I am now developing a project using a library for processing Biometrics (fingerprint recognition) and would like to use Python to invoke the functions in the DLL. The DLL comes with C# examples, so I'm assuming here that I could use it with IronPython. What I've tried so far: Using ctypes: the dll has a a C++ interface, so using ctypes is a torture, functions are only imported ordinally, and no names or anything is available. From here I thought IronPython would be better. using IronPython: Tried to directly import the classes in the DLL, this did not work. I have read a bit on LoadAssembly, but I'm not sure how it works. SO far I've only been able to "import System" from IronPython, but pretty much nothing else can be imported. There is a full app in C# include with the software. I'm using Windows XP with the latest ironpython. I'm really beginning here, so the question would be: how do I import classes and functions from a DLL what I know is accessible from a C# application, using IronPython? Thanks for any advice or direction, Hugo G. From fuzzyman at voidspace.org.uk Mon Aug 6 03:14:46 2007 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Mon, 06 Aug 2007 02:14:46 +0100 Subject: [IronPython] New to Ironpython. Want to glue DLL with Python code In-Reply-To: <46B64F20.1090405@h-lab.net> References: <46B64F20.1090405@h-lab.net> Message-ID: <46B67606.80608@voidspace.org.uk> Hugo Gonz?lez Monteverde wrote: > [snip..] > > I'm really beginning here, so the question would be: how do I import > classes and functions from a DLL what I know is accessible from a C# > application, using IronPython? > > Thanks for any advice or direction, > Could you show an example of how it is accessed from C#? Then perhaps we can show you equivalent IronPython. All the best, Michael Foord http://www.ironpython.info/ > Hugo G. > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > From hrh1818 at comcast.net Mon Aug 6 06:05:39 2007 From: hrh1818 at comcast.net (Howard R. Hansen) Date: Sun, 05 Aug 2007 23:05:39 -0500 Subject: [IronPython] New to Ironpython. Want to glue DLL with Python code In-Reply-To: <46B64F20.1090405@h-lab.net> References: <46B64F20.1090405@h-lab.net> Message-ID: <46B69E13.7060802@comcast.net> What type of compiler was used to write the dll? Is it a .net dll or some other type like unmanaged C++? Howard Hugo Gonz?lez Monteverde wrote: > Hi all, > > I'm new to IronPython, thought I've been using CPython for two years now. > > I am now developing a project using a library for processing Biometrics > (fingerprint recognition) and would like to use Python to invoke the > functions in the DLL. The DLL comes with C# examples, so I'm assuming > here that I could use it with IronPython. > > What I've tried so far: > > Using ctypes: the dll has a a C++ interface, so using ctypes is a > torture, functions are only imported ordinally, and no names or anything > is available. From here I thought IronPython would be better. > > using IronPython: Tried to directly import the classes in the DLL, this > did not work. I have read a bit on LoadAssembly, but I'm not sure how it > works. SO far I've only been able to "import System" from IronPython, > but pretty much nothing else can be imported. There is a full app in C# > include with the software. > > I'm using Windows XP with the latest ironpython. > > I'm really beginning here, so the question would be: how do I import > classes and functions from a DLL what I know is accessible from a C# > application, using IronPython? > > Thanks for any advice or direction, > > Hugo G. > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > From smsrku.2002 at gmail.com Mon Aug 6 07:02:48 2007 From: smsrku.2002 at gmail.com (sms rku) Date: Sun, 5 Aug 2007 22:02:48 -0700 Subject: [IronPython] C# and IronPython Message-ID: <3e49a69c0708052202g5b417368l289b4ad9ccacc743@mail.gmail.com> I am very new to Python and IronPython. Could you please let me know if it is possible to Make my application [.exe] that has a static Main method and 3 other public methods defined in a class to be accessed from IronPython script? i.e, Will I be able to create instance of the class from IronPython script? Will I be able to call the public methods from the script? and also, is it possible to call the main function from the script? [ i.e run my application] If yes, could you please tell me how it can be done? Thanks in advance sms -------------- next part -------------- An HTML attachment was scrubbed... URL: From hugonz-lists at h-lab.net Mon Aug 6 07:57:17 2007 From: hugonz-lists at h-lab.net (=?ISO-8859-1?Q?Hugo_Gonz=E1lez_Monteverde?=) Date: Mon, 06 Aug 2007 00:57:17 -0500 Subject: [IronPython] New to Ironpython. Want to glue DLL with Python code In-Reply-To: <46B69E13.7060802@comcast.net> References: <46B64F20.1090405@h-lab.net> <46B69E13.7060802@comcast.net> Message-ID: <46B6B83D.5020308@h-lab.net> Howard R. Hansen wrote: > What type of compiler was used to write the dll? Is it a .net dll or > some other type like unmanaged > C++? Hi Howard (and Michael), The DLL is a proprietary one from the GrFinger SDK package (http://www.griaule.com/page/en-us/grfinger_fingerprint_sdk) so I don't have that information. There are examples of use also for VB.NET and C++.NET. So I would guess the DLL would be a .NET dll, does this make sense? The example code they provide in C# does this: ////////////////// using GrFingerXLib using System ... ... //and then is used as // Extract a fingerprint template from current image public int ExtractTemplate() { int result; // set current buffer size for the extract template _tpt._size = (int)GRConstants.GR_MAX_SIZE_TEMPLATE; result = (int)_grfingerx.Extract( ref _raw.img, _raw.width, _raw.height, _raw.Res, ref _tpt._tpt,ref _tpt._size, (int)GRConstants.GR_DEFAULT_CONTEXT); // if error, set template size to 0 if (result < 0) { // Result < 0 => extraction problem _tpt._size = 0; } return result; } ///////////////////////////////// I was hoping that a DLL named GrFingerXLib would be available somewhere in my system (after the installation of the SDK) but there is none. There are several different files: GrFinger.dll and GrFingerX.dll This is what I (naively) attempted: C:\IronPython-1.1>ipy IronPython 1.1 (1.1) on .NET 2.0.50727.832 Copyright (c) Microsoft Corporation. All rights reserved. >>> import GrFinger Traceback (most recent call last): File , line 0, in ##9 File , line 0, in __import__##4 ImportError: No module named GrFinger >>> import GrFingerX Traceback (most recent call last): File , line 0, in ##10 File , line 0, in __import__##4 ImportError: No module named GrFingerX >>> import GrFingerXLib Traceback (most recent call last): File , line 0, in ##11 File , line 0, in __import__##4 ImportError: No module named GrFingerXLib >>> Hope that is useful. I can make the files available privately if that helps. Hugo From hfoffani at gmail.com Mon Aug 6 11:13:03 2007 From: hfoffani at gmail.com (Hernan M Foffani) Date: Mon, 6 Aug 2007 11:13:03 +0200 Subject: [IronPython] New to Ironpython. Want to glue DLL with Python code In-Reply-To: <46B6B83D.5020308@h-lab.net> References: <46B64F20.1090405@h-lab.net> <46B69E13.7060802@comcast.net> <46B6B83D.5020308@h-lab.net> Message-ID: <11fab4bc0708060213v4cfba4f1md4161cb6c4dfcd99@mail.gmail.com> > ////////////////// > using GrFingerXLib > using System > ... > > I was hoping that a DLL named GrFingerXLib would be available somewhere > in my system (after the installation of the SDK) but there is none. > There are several different files: GrFinger.dll and GrFingerX.dll C#'s "using" statement has nothing to do with libraries. It refers to a namespace, not a DLL. For the later you need to add the corresponding reference. In Visual Studio we usually do this at compile time by adding the reference of the DLL to the project. In IronPython you add the reference at runtime. You want to look for clr.AddReference samples in the mailing-list archives at: http://lists.ironpython.com/pipermail/users-ironpython.com/ Regards, -H. > > This is what I (naively) attempted: > > C:\IronPython-1.1>ipy > IronPython 1.1 (1.1) on .NET 2.0.50727.832 > Copyright (c) Microsoft Corporation. All rights reserved. > >>> import GrFinger > Traceback (most recent call last): > File , line 0, in ##9 > File , line 0, in __import__##4 > ImportError: No module named GrFinger > >>> import GrFingerX > Traceback (most recent call last): > File , line 0, in ##10 > File , line 0, in __import__##4 > ImportError: No module named GrFingerX > >>> import GrFingerXLib > Traceback (most recent call last): > File , line 0, in ##11 > File , line 0, in __import__##4 > ImportError: No module named GrFingerXLib > >>> > > Hope that is useful. I can make the files available privately if that helps. > > Hugo > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > From dinov at exchange.microsoft.com Mon Aug 6 18:14:34 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Mon, 6 Aug 2007 09:14:34 -0700 Subject: [IronPython] C# and IronPython In-Reply-To: <3e49a69c0708052202g5b417368l289b4ad9ccacc743@mail.gmail.com> References: <3e49a69c0708052202g5b417368l289b4ad9ccacc743@mail.gmail.com> Message-ID: <7AD436E4270DD54A94238001769C2227B97B23BCA0@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Yes, as long as the class is also public. You just need to start ipy.exe in the directory where your exe's at and then do: import clr clr.AddReference('MyApplication') from MyApplicationsNamespace import MyApplicationsClass # if it's in a particular namespace or import MyApplicationsClass # if it's in the global namespace MyApplicationsClass.Main('arg1', 'arg2', 'arg3') Or MyApplicationsClass.SomeOtherMethod() Or x = MyApplicationsClass() x.SomeInstanceMethod() From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of sms rku Sent: Sunday, August 05, 2007 10:03 PM To: users at lists.ironpython.com Subject: [IronPython] C# and IronPython I am very new to Python and IronPython. Could you please let me know if it is possible to Make my application [.exe] that has a static Main method and 3 other public methods defined in a class to be accessed from IronPython script? i.e, Will I be able to create instance of the class from IronPython script? Will I be able to call the public methods from the script? and also, is it possible to call the main function from the script? [ i.e run my application] If yes, could you please tell me how it can be done? Thanks in advance sms -------------- next part -------------- An HTML attachment was scrubbed... URL: From hugonz-lists at h-lab.net Mon Aug 6 23:21:27 2007 From: hugonz-lists at h-lab.net (=?ISO-8859-1?Q?Hugo_Gonz=E1lez_Monteverde?=) Date: Mon, 06 Aug 2007 16:21:27 -0500 Subject: [IronPython] New to Ironpython. Want to glue DLL with Python code In-Reply-To: <11fab4bc0708060213v4cfba4f1md4161cb6c4dfcd99@mail.gmail.com> References: <46B64F20.1090405@h-lab.net> <46B69E13.7060802@comcast.net> <46B6B83D.5020308@h-lab.net> <11fab4bc0708060213v4cfba4f1md4161cb6c4dfcd99@mail.gmail.com> Message-ID: <46B790D7.1080804@h-lab.net> Hernan M Foffani wrote: > You want to look for clr.AddReference samples in the mailing-list > archives at: > http://lists.ironpython.com/pipermail/users-ironpython.com/ > Hi Hernan, Thanks a lot, I will take a look and try to get it working with it. Hugo G. From smsrku.2002 at gmail.com Tue Aug 7 07:04:54 2007 From: smsrku.2002 at gmail.com (sms rku) Date: Mon, 6 Aug 2007 22:04:54 -0700 Subject: [IronPython] C# and IronPython In-Reply-To: <7AD436E4270DD54A94238001769C2227B97B23BCA0@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <3e49a69c0708052202g5b417368l289b4ad9ccacc743@mail.gmail.com> <7AD436E4270DD54A94238001769C2227B97B23BCA0@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <3e49a69c0708062204h407ec828g43fee17470cccfa8@mail.gmail.com> Thanks Dino, In similar lines, I can also call functions from assembly, I guess... I have read some articles related to CodeDom, using which we can compile and run code(C# or VB.NET) at runtime. Which one of these two (using CodeDom OR using IronPython) is the better approach if the requirement is to 1. Use loops like for, while etc -i,e call methods in a loop in the script 2. use script occasionally, that means scripting is not the feature that is used regularly by the user of the application -Thanks sms On 8/6/07, Dino Viehland wrote: > > Yes, as long as the class is also public. You just need to start ipy.exein the directory where your exe's at and then do: > > > > import clr > > clr.AddReference('MyApplication') > > from MyApplicationsNamespace import MyApplicationsClass # if it's in a > particular namespace > > or > > import MyApplicationsClass # if it's in the global namespace > > MyApplicationsClass.Main('arg1', 'arg2', 'arg3') > > Or > > MyApplicationsClass.SomeOtherMethod() > > Or > > x = MyApplicationsClass() > > x.SomeInstanceMethod() > > > > > > *From:* users-bounces at lists.ironpython.com [mailto: > users-bounces at lists.ironpython.com] *On Behalf Of *sms rku > *Sent:* Sunday, August 05, 2007 10:03 PM > *To:* users at lists.ironpython.com > *Subject:* [IronPython] C# and IronPython > > > > I am very new to Python and IronPython. > > Could you please let me know if it is possible to > > Make my application [.exe] that has a static Main method and 3 other > public methods defined in a class to be accessed from IronPython script? > > i.e, Will I be able to create instance of the class from IronPython > script? > Will I be able to call the public methods from the script? > > and also, is it possible to call the main function from the script? > [ i.e run my application] > > If yes, could you please tell me how it can be done? > > Thanks in advance > sms > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dinov at exchange.microsoft.com Tue Aug 7 17:46:58 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Tue, 7 Aug 2007 08:46:58 -0700 Subject: [IronPython] C# and IronPython In-Reply-To: <3e49a69c0708062204h407ec828g43fee17470cccfa8@mail.gmail.com> References: <3e49a69c0708052202g5b417368l289b4ad9ccacc743@mail.gmail.com> <7AD436E4270DD54A94238001769C2227B97B23BCA0@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <3e49a69c0708062204h407ec828g43fee17470cccfa8@mail.gmail.com> Message-ID: <7AD436E4270DD54A94238001769C2227B97B23BEF0@DF-GRTDANE-MSG.exchange.corp.microsoft.com> My guess is it depends on how often you'll be doing this and how many iterations you'll be running - or if performance is an issue for you at all. The overhead of invoking the C# compiler is going to be much greater than asking IronPython to generate some new code in process. But the C# code is also going to run much faster. So depending on if you're doing compilations a lot and how long the generated code one way may be better than the other. Another consideration is the amount of compilations you'll be doing: IronPython will compile the code as DynamicMethod's so its collectible by the GC but the C# generated code will end up in an assembly which requires an app domain unload to go away (which means creating app domains, getting the isolation right, etc...). If none of those are issues for you then I would suggest personal preference of which one you like more, and which API you want to interact w/ to create the code - e.g. CodeDom can be a little verbose but with Python you'll be building the strings yourself. From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of sms rku Sent: Monday, August 06, 2007 10:05 PM To: Discussion of IronPython Subject: Re: [IronPython] C# and IronPython Thanks Dino, In similar lines, I can also call functions from assembly, I guess... I have read some articles related to CodeDom, using which we can compile and run code(C# or VB.NET) at runtime. Which one of these two (using CodeDom OR using IronPython) is the better approach if the requirement is to 1. Use loops like for, while etc -i,e call methods in a loop in the script 2. use script occasionally, that means scripting is not the feature that is used regularly by the user of the application -Thanks sms On 8/6/07, Dino Viehland > wrote: Yes, as long as the class is also public. You just need to start ipy.exe in the directory where your exe's at and then do: import clr clr.AddReference('MyApplication') from MyApplicationsNamespace import MyApplicationsClass # if it's in a particular namespace or import MyApplicationsClass # if it's in the global namespace MyApplicationsClass.Main('arg1', 'arg2', 'arg3') Or MyApplicationsClass.SomeOtherMethod() Or x = MyApplicationsClass() x.SomeInstanceMethod() From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of sms rku Sent: Sunday, August 05, 2007 10:03 PM To: users at lists.ironpython.com Subject: [IronPython] C# and IronPython I am very new to Python and IronPython. Could you please let me know if it is possible to Make my application [.exe] that has a static Main method and 3 other public methods defined in a class to be accessed from IronPython script? i.e, Will I be able to create instance of the class from IronPython script? Will I be able to call the public methods from the script? and also, is it possible to call the main function from the script? [ i.e run my application] If yes, could you please tell me how it can be done? Thanks in advance sms _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From miguel at novell.com Wed Aug 8 02:47:42 2007 From: miguel at novell.com (Miguel de Icaza) Date: Tue, 07 Aug 2007 20:47:42 -0400 Subject: [IronPython] IronPython 2.0a3 Unix Makefiles In-Reply-To: <1185503127.3940.1.camel@erandi.dom> References: <1185503127.3940.1.camel@erandi.dom> Message-ID: <1186534062.31224.99.camel@erandi.dom> Hello, Here is a Makefile for buliding IronPython 2.0a3 using Unix. This makefile will create the needed directories, uses Unix pathnames and includes the missing reference to the AssemblyVersion.cs file that is required to build IronPython in a couple of places that were missing in the bundled Makefile. To build use: $ make CSC=gmcs Miguel. -------------- next part -------------- A non-text attachment was scrubbed... Name: makefile Type: text/x-makefile Size: 1910 bytes Desc: not available URL: From sanxiyn at gmail.com Wed Aug 8 05:17:19 2007 From: sanxiyn at gmail.com (Sanghyeon Seo) Date: Wed, 8 Aug 2007 12:17:19 +0900 Subject: [IronPython] IronPython 2.0a3 Unix Makefiles In-Reply-To: <1186534062.31224.99.camel@erandi.dom> References: <1185503127.3940.1.camel@erandi.dom> <1186534062.31224.99.camel@erandi.dom> Message-ID: <5b0248170708072017h5a70f182p7c892e7147260261@mail.gmail.com> 2007/8/8, Miguel de Icaza : > Here is a Makefile for buliding IronPython 2.0a3 using Unix. Sorry, but this Makefile doesn't do resource generation for Microsoft.Scripting.dll and IronPython.dll, and the resulting IronPython console won't work correctly. -- Seo Sanghyeon From fuzzyman at voidspace.org.uk Thu Aug 9 00:50:01 2007 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Wed, 08 Aug 2007 23:50:01 +0100 Subject: [IronPython] Dear Lazy Web - IronPython 2 Parser Message-ID: <46BA4899.9070800@voidspace.org.uk> Hello all, Sorry for being lazy, but... What is the easiest way of building an AST from IronPython 2 code? I would like an AST that I can modify and then flatten again in Silverlight.... It needn't be a Python AST, an IronPython one is fine. I only need access to 'name' nodes... I wish to change some of the names and turn the AST back into code before exec'ing. :-) Thanks Michael http://www.ironpython.info/ From aryeh at bigfoot.com Thu Aug 9 15:49:23 2007 From: aryeh at bigfoot.com (Arye) Date: Thu, 9 Aug 2007 15:49:23 +0200 Subject: [IronPython] SOAP with headers client Message-ID: <6f63a0ad0708090649r4015770dlfe249efd5150dc11@mail.gmail.com> Hello list, I would like to consume a web method that expects a SOAP header with ironpython. I used wsdl.exe to generate the stub and then compiled it to a library that can be imported in ipy. My understanding is that I need to create a "header" object. I would appreciate any info on how I can do this. Its creation does not seem to be exposed in the generated library (the generated code does include the header definition). Sincerely, Arye. From psherr at gmail.com Thu Aug 9 15:55:35 2007 From: psherr at gmail.com (Paul Sherr) Date: Thu, 09 Aug 2007 08:55:35 -0500 Subject: [IronPython] Please remove me from the mailing list - thanks Message-ID: <46BB1CD7.4050009@gmail.com> -- Paul Sherr Those are my principles, and if you don't like them... well, I have others. Groucho Marx -------------- next part -------------- A non-text attachment was scrubbed... Name: psherr.vcf Type: text/x-vcard Size: 323 bytes Desc: not available URL: From sh at defuze.org Thu Aug 9 16:16:46 2007 From: sh at defuze.org (Sylvain Hellegouarch) Date: Thu, 09 Aug 2007 15:16:46 +0100 Subject: [IronPython] Please remove me from the mailing list - thanks In-Reply-To: <46BB1CD7.4050009@gmail.com> References: <46BB1CD7.4050009@gmail.com> Message-ID: <46BB21CE.1070906@defuze.org> Paul Sherr a ?crit : > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > Read the instructions: http://lists.ironpython.com/listinfo.cgi/users-ironpython.com - Sylvain From dreamwinterlb at gmail.com Fri Aug 10 07:27:02 2007 From: dreamwinterlb at gmail.com (Bing Li) Date: Fri, 10 Aug 2007 13:27:02 +0800 Subject: [IronPython] How to get the result of callback Message-ID: <9547a46f0708092227l115c78u101a4e9abf9726e2@mail.gmail.com> Hi,guy. I want to call python lambda expression in C#. The following is lambda expression. "CheckNumber = x,y:x>y" So, I want to use C# to execute the expression, I wirte a following function that, The parameter expression is lambada expression, the parameters is a key-value list. The key is the name of parameter in lambda expression 'x' and 'y'. public object CallPythonLambda(string expression, Hashtable parameters) { PythonEngine pe = PythonEngine.CurrentEngine; //TODO: not implement. } Can anybody help me to complete the function? By the way, the version of IronPython is 2.0A3. Thanks a lot! -------------- next part -------------- An HTML attachment was scrubbed... URL: From dinov at exchange.microsoft.com Fri Aug 10 17:22:15 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Fri, 10 Aug 2007 08:22:15 -0700 Subject: [IronPython] How to get the result of callback In-Reply-To: <9547a46f0708092227l115c78u101a4e9abf9726e2@mail.gmail.com> References: <9547a46f0708092227l115c78u101a4e9abf9726e2@mail.gmail.com> Message-ID: <7AD436E4270DD54A94238001769C2227B97B23C608@DF-GRTDANE-MSG.exchange.corp.microsoft.com> We have a feature in v1.x which is almost exactly what you want called CreateLambda / CreateMethod. This allows you to give the body of a function which takes parameters and it gives you a strongly typed delegate back. Unfortunately we removed it from v2.0 because it was getting in the way of our refactoring work but that doesn?t mean it won?t come back at some point. That being said we actually have enough features in place to make this work manually. Here?s the code to do this in Python: import clr clr.AddReference('Microsoft.Scripting') clr.AddReference('IronPython') from IronPython.Hosting import PythonEngine from Microsoft.Scripting.Utils import Function pe = PythonEngine.CurrentEngine a = pe.EvaluateAs[Function[object, object, bool]]('lambda x,y: x>y') a(2,3) a(3,2) in C# it?d be something like: Function func = pe.EvaluateAs>(?lambda x,y: x>y?); bool res1 = func(2,3); bool res2 = func(3,2); From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Bing Li Sent: Thursday, August 09, 2007 10:27 PM To: users at lists.ironpython.com Subject: [IronPython] How to get the result of callback Hi,guy. I want to call python lambda expression in C#. The following is lambda expression. "CheckNumber = x,y:x>y" So, I want to use C# to execute the expression, I wirte a following function that, The parameter expression is lambada expression, the parameters is a key-value list. The key is the name of parameter in lambda expression 'x' and 'y'. public object CallPythonLambda(string expression, Hashtable parameters) { PythonEngine pe = PythonEngine.CurrentEngine; //TODO: not implement. } Can anybody help me to complete the function? By the way, the version of IronPython is 2.0A3. Thanks a lot! -------------- next part -------------- An HTML attachment was scrubbed... URL: From tiyota at gmail.com Fri Aug 10 17:57:35 2007 From: tiyota at gmail.com (Tianyong Tang) Date: Fri, 10 Aug 2007 17:57:35 +0200 Subject: [IronPython] TypeError: integer expected occurs when __getitem__ is called Message-ID: Hi, I am a newbie with IronPython, and want to test pysnmp eggs of CPython in IronPython. It works in CPython, but when I try it in IronPython, error occurred with the import of libraries at the beginning: >>> from pysnmp.entity.rfc3413.oneliner import cmdgen Traceback (most recent call last): File , line 0, in ##254 File , line 0, in _stub_##2 File C:\Python25\lib\site-packages\pysnmp\v4\entity\rfc3413\oneliner\cmdgen.py, line 2, in Initialize File , line 0, in _stub_##2 File C:\Python25\lib\site-packages\pysnmp\v4\entity\engine.py, line 2, in Initialize File , line 0, in _stub_##2 File C:\Python25\lib\site-packages\pysnmp\v4\proto\rfc3412.py, line 5, in Initialize File , line 0, in _stub_##2 File C:\Python25\lib\site-packages\pysnmp\v4\proto\api\__init__.py, line 1, in Initialize File , line 0, in _stub_##2 File C:\Python25\lib\site-packages\pysnmp\v4\proto\api\v1.py, line 3, in Initialize File , line 0, in _stub_##2 File C:\Python25\lib\site-packages\pysnmp\v4\proto\rfc1155.py, line 37, in Initialize File C:\Python25\lib\site-packages\pysnmp\v4\proto\rfc1155.py, line 38, in IpAddress File , line 0, in _stub_##37 File C:\Python25\lib\site-packages\pyasn1\v1\type\tag.py, line 84, in tagImplicitly File , line 0, in _stub_##248 File C:\Python25\lib\site-packages\pyasn1\v1\type\tag.py, line 89, in __getitem__ File , line 0, in _stub_##253 TypeError: integer expected can IronPython get around such errors? any response would be appreciated. Thanks in advanced. Good weekend. regards, Tianyong -------------- next part -------------- An HTML attachment was scrubbed... URL: From dinov at exchange.microsoft.com Fri Aug 10 18:07:31 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Fri, 10 Aug 2007 09:07:31 -0700 Subject: [IronPython] TypeError: integer expected occurs when __getitem__ is called In-Reply-To: References: Message-ID: <7AD436E4270DD54A94238001769C2227B97B23C61E@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Do you know what type of object is being indexed and what the index type is (what's happening on line 89 in tag.py)? You could also run with the -X:ExceptionDetail command line option and then we'd know where on the .NET side of things this exception is coming from. Although I doubt this will help you might want to try running against the 2.4 standard libraries. Our 2.5 support is still incomplete and there are things the 2.5 std lib depends upon which we don't have implemented. You could also see if the bug repros on v1.1 of IronPython as it could be a regression in the 2.0 tree. From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Tianyong Tang Sent: Friday, August 10, 2007 8:58 AM To: users at lists.ironpython.com Subject: [IronPython] TypeError: integer expected occurs when __getitem__ is called Hi, I am a newbie with IronPython, and want to test pysnmp eggs of CPython in IronPython. It works in CPython, but when I try it in IronPython, error occurred with the import of libraries at the beginning: >>> from pysnmp.entity.rfc3413.oneliner import cmdgen Traceback (most recent call last): File , line 0, in ##254 File , line 0, in _stub_##2 File C:\Python25\lib\site-packages\pysnmp\v4\entity\rfc3413\oneliner\cmdgen.py, line 2, in Initialize File , line 0, in _stub_##2 File C:\Python25\lib\site-packages\pysnmp\v4\entity\engine.py, line 2, in Initialize File , line 0, in _stub_##2 File C:\Python25\lib\site-packages\pysnmp\v4\proto\rfc3412.py, line 5, in Initialize File , line 0, in _stub_##2 File C:\Python25\lib\site-packages\pysnmp\v4\proto\api\__init__.py, line 1, in Initialize File , line 0, in _stub_##2 File C:\Python25\lib\site-packages\pysnmp\v4\proto\api\v1.py, line 3, in Initialize File , line 0, in _stub_##2 File C:\Python25\lib\site-packages\pysnmp\v4\proto\rfc1155.py, line 37, in Initialize File C:\Python25\lib\site-packages\pysnmp\v4\proto\rfc1155.py, line 38, in IpAddress File , line 0, in _stub_##37 File C:\Python25\lib\site-packages\pyasn1\v1\type\tag.py, line 84, in tagImplicitly File , line 0, in _stub_##248 File C:\Python25\lib\site-packages\pyasn1\v1\type\tag.py, line 89, in __getitem__ File , line 0, in _stub_##253 TypeError: integer expected can IronPython get around such errors? any response would be appreciated. Thanks in advanced. Good weekend. regards, Tianyong -------------- next part -------------- An HTML attachment was scrubbed... URL: From tiyota at gmail.com Fri Aug 10 18:26:13 2007 From: tiyota at gmail.com (Tianyong Tang) Date: Fri, 10 Aug 2007 18:26:13 +0200 Subject: [IronPython] TypeError: integer expected occurs when __getitem__ is called In-Reply-To: <7AD436E4270DD54A94238001769C2227B97B23C61E@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <7AD436E4270DD54A94238001769C2227B97B23C61E@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: Never be answered so quickly. :) I tested with -X:ExceptionDetail and here is the output: IronPython console: IronPython 2.0A3 (2.0.10724.00) on .NET 2.0.50727.832 Copyright (c) Microsoft Corporation. All rights reserved. >>> from pysnmp.entity.rfc3413.oneliner import cmdgen cannot import entity from pysnmp in IronPython.Runtime.Importer.ImportNestedModule(CodeContext context, ScriptModule mod, String name) in IronPython.Runtime.Importer.ImportModuleFrom(CodeContext context, Object mod, String name) in IronPython.Runtime.Importer.ImportModule(CodeContext context, String modName, Boolean bottom) in IronPython.Runtime.Builtin.Import(CodeContext context, String name, Object globals, Object locals, Object fromList) in _stub_##2(Object[] , DynamicSite`6 , CodeContext , Object , String , IAttributesCollection , IAttributesCollection , List ) in Microsoft.Scripting.Actions.DynamicSite`6.Invoke(CodeContext context, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) in IronPython.Runtime.Operations.PythonOps.ImportWithNames(CodeContext context, String fullName, String[] names) in ##13(Object[] , CodeContext ) in Microsoft.Scripting.ScriptCode.Run(CodeContext codeContext) in Microsoft.Scripting.Hosting.CompiledCode.Evaluate(IScriptModule module) in Microsoft.Scripting.Hosting.ScriptEngine.ExecuteCommand(String code, IScriptModule module) in Microsoft.Scripting.Shell.CommandLine.RunOneInteraction() in Microsoft.Scripting.Shell.CommandLine.TryInteractiveAction() in IronPython.Hosting.PythonCommandLine.TryInteractiveAction() in Microsoft.Scripting.Shell.CommandLine.RunInteractiveLoop() ImportError: cannot import entity from pysnmp >>> from pysnmp.entity.rfc3413.oneliner import cmdgen integer expected in IronPython.Modules.PythonOperator.SliceToInt(Object o) in IronPython.Modules.PythonOperator.MakeSlice(Object a, Object b) in IronPython.Modules.PythonOperator.GetSlice(Object a, Object b, Object c) in _stub_##249(Object[] , DynamicSite`5 , CodeContext , Object , Object , Object , Object ) in Microsoft.Scripting.Actions.DynamicSite`5.UpdateBindingAndInvoke(CodeContext context, T0 arg0, T1 arg1, T2 arg2, T3 arg3) in Microsoft.Scripting.Actions.DynamicSiteHelpers.UninitializedTargetHelper`7.Invoke4(DynamicSite`5 site, CodeContext context, T0 arg0, T1 arg1, T2 arg2, T3 arg3) in Microsoft.Scripting.Actions.DynamicSite`5.Invoke(CodeContext context, T0 arg0, T1 arg1, T2 arg2, T3 arg3) in pyasn1.v1.type.tag$mod_35.__getitem__$687(CodeContext $context, Object self, Object idx) in C:\Python25\lib\site-packages\pyasn1\v1\type\tag.py:riga 89 in IronPython.Runtime.Calls.FunctionWithContext2.Call(CodeContext context, Object arg0, Object arg1) in IronPython.Runtime.Calls.FunctionWithContext2.Call(CodeContext context, Object[] args) in IronPython.Runtime.Calls.PythonFunction.CallInstance(CodeContext context, Object instance, Object[] args) in IronPython.Runtime.Calls.Method.Call(CodeContext context, Object[] args) in IronPython.Runtime.Operations.PythonOps.CallWithContext(CodeContext context, Object func, Object[] args) in IronPython.Runtime.Operations.PythonOps.InvokeWithContext(CodeContext context, Object target, SymbolId name, Object[] args) in IronPython.Runtime.Types.OldInstance.GetItem(CodeContext context, Object item) in _stub_##244(Object[] , DynamicSite`3 , CodeContext , Object , Object ) in Microsoft.Scripting.Actions.DynamicSite`3.UpdateBindingAndInvoke(CodeContext context, T0 arg0, T1 arg1) in Microsoft.Scripting.Actions.DynamicSiteHelpers.UninitializedTargetHelper`7.Invoke2(DynamicSite`3 site, CodeContext context, T0 arg0, T1 arg1) in Microsoft.Scripting.Actions.DynamicSite`3.Invoke(CodeContext context, T0 arg0, T1 arg1) in pyasn1.v1.type.tag$mod_35.tagImplicitly$685(CodeContext $context, Object self, Object superTag) in C:\Python25\lib\site-packages\pyasn1\v1\type\tag.py:riga 84 in IronPython.Runtime.Calls.FunctionWithContext2.Call(CodeContext context, Object arg0, Object arg1) in IronPython.Runtime.Calls.PythonFunction.CallInstance(CodeContext context, Object arg0, Object arg1) in IronPython.Runtime.Calls.Method.Call(CodeContext context, Object arg0) in Microsoft.Scripting.RuntimeHelpers.CallWithContext(CodeContext context, Object func, Object arg0) in _stub_##33(Object[] , DynamicSite`3 , CodeContext , Object , Object ) in Microsoft.Scripting.Actions.DynamicSite`3.UpdateBindingAndInvoke(CodeContext context, T0 arg0, T1 arg1) in Microsoft.Scripting.Actions.DynamicSiteHelpers.UninitializedTargetHelper`7.Invoke2(DynamicSite`3 site, CodeContext context, T0 arg0, T1 arg1) in Microsoft.Scripting.Actions.DynamicSite`3.Invoke(CodeContext context, T0 arg0, T1 arg1) in pysnmp.v4.proto.rfc1155$mod_38.IpAddress$738() in C:\Python25\lib\site-packages\pysnmp\v4\proto\rfc1155.py:riga 38 in IronPython.Runtime.Operations.PythonOps.MakeClass(CodeContext context, String name, Object[] bases, String selfNames, Delegate body) in pysnmp.v4.proto.rfc1155$mod_38.Initialize(CodeContext ) in C:\Python25\lib\site-packages\pysnmp\v4\proto\rfc1155.py:riga 37 in Microsoft.Scripting.ScriptCode.Run(CodeContext codeContext) in Microsoft.Scripting.ScriptModule.Execute() in IronPython.Runtime.Importer.InitializeModule(String fullName, ScriptModule smod, Boolean executeModule) in IronPython.Runtime.Importer.LoadFromSourceUnit(SourceFileUnit sourceUnit) in IronPython.Runtime.Importer.ImportFromPath(CodeContext context, String name, String fullName, List path) in IronPython.Runtime.Importer.ImportNestedModule(CodeContext context, ScriptModule mod, String name) in IronPython.Runtime.Importer.ImportFrom(CodeContext context, Object mod, String name) in IronPython.Runtime.Builtin.Import(CodeContext context, String name, Object globals, Object locals, Object fromList) in _stub_##2(Object[] , DynamicSite`6 , CodeContext , Object , String , IAttributesCollection , IAttributesCollection , List ) in Microsoft.Scripting.Actions.DynamicSite`6.Invoke(CodeContext context, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) in IronPython.Runtime.Operations.PythonOps.ImportWithNames(CodeContext context, String fullName, String[] names) in pysnmp.v4.proto.api.v1$mod_29.Initialize(CodeContext ) in C:\Python25\lib\site-packages\pysnmp\v4\proto\api\v1.py:riga 3 in Microsoft.Scripting.ScriptCode.Run(CodeContext codeContext) in Microsoft.Scripting.ScriptModule.Execute() in IronPython.Runtime.Importer.InitializeModule(String fullName, ScriptModule smod, Boolean executeModule) in IronPython.Runtime.Importer.LoadFromSourceUnit(SourceFileUnit sourceUnit) in IronPython.Runtime.Importer.ImportFromPath(CodeContext context, String name, String fullName, List path) in IronPython.Runtime.Importer.ImportNestedModule(CodeContext context, ScriptModule mod, String name) in IronPython.Runtime.Importer.ImportFrom(CodeContext context, Object mod, String name) in IronPython.Runtime.Builtin.Import(CodeContext context, String name, Object globals, Object locals, Object fromList) in _stub_##2(Object[] , DynamicSite`6 , CodeContext , Object , String , IAttributesCollection , IAttributesCollection , List ) in Microsoft.Scripting.Actions.DynamicSite`6.Invoke(CodeContext context, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) in IronPython.Runtime.Operations.PythonOps.ImportWithNames(CodeContext context, String fullName, String[] names) in pysnmp.v4.proto.api$mod_28.Initialize(CodeContext ) in C:\Python25\lib\site-packages\pysnmp\v4\proto\api\__init__.py:riga 1 in Microsoft.Scripting.ScriptCode.Run(CodeContext codeContext) in Microsoft.Scripting.ScriptModule.Execute() in IronPython.Runtime.Importer.InitializeModule(String fullName, ScriptModule smod, Boolean executeModule) in IronPython.Runtime.Importer.LoadFromSourceUnit(SourceFileUnit sourceUnit) in IronPython.Runtime.Importer.ImportFromPath(CodeContext context, String name, String fullName, List path) in IronPython.Runtime.Importer.ImportNestedModule(CodeContext context, ScriptModule mod, String name) in IronPython.Runtime.Importer.ImportModuleFrom(CodeContext context, Object mod, String name) in IronPython.Runtime.Importer.ImportModule(CodeContext context, String modName, Boolean bottom) in IronPython.Runtime.Builtin.Import(CodeContext context, String name, Object globals, Object locals, Object fromList) in _stub_##2(Object[] , DynamicSite`6 , CodeContext , Object , String , IAttributesCollection , IAttributesCollection , List ) in Microsoft.Scripting.Actions.DynamicSite`6.Invoke(CodeContext context, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) in IronPython.Runtime.Operations.PythonOps.ImportWithNames(CodeContext context, String fullName, String[] names) in pysnmp.v4.proto.rfc3412$mod_16.Initialize(CodeContext ) in C:\Python25\lib\site-packages\pysnmp\v4\proto\rfc3412.py:riga 5 in Microsoft.Scripting.ScriptCode.Run(CodeContext codeContext) in Microsoft.Scripting.ScriptModule.Execute() in IronPython.Runtime.Importer.InitializeModule(String fullName, ScriptModule smod, Boolean executeModule) in IronPython.Runtime.Importer.LoadFromSourceUnit(SourceFileUnit sourceUnit) in IronPython.Runtime.Importer.ImportFromPath(CodeContext context, String name, String fullName, List path) in IronPython.Runtime.Importer.ImportNestedModule(CodeContext context, ScriptModule mod, String name) in IronPython.Runtime.Importer.ImportModuleFrom(CodeContext context, Object mod, String name) in IronPython.Runtime.Importer.ImportModule(CodeContext context, String modName, Boolean bottom) in IronPython.Runtime.Builtin.Import(CodeContext context, String name, Object globals, Object locals, Object fromList) in _stub_##2(Object[] , DynamicSite`6 , CodeContext , Object , String , IAttributesCollection , IAttributesCollection , List ) in Microsoft.Scripting.Actions.DynamicSite`6.Invoke(CodeContext context, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) in IronPython.Runtime.Operations.PythonOps.ImportWithNames(CodeContext context, String fullName, String[] names) in pysnmp.v4.entity.engine$mod_14.Initialize(CodeContext ) in C:\Python25\lib\site-packages\pysnmp\v4\entity\engine.py:riga 2 in Microsoft.Scripting.ScriptCode.Run(CodeContext codeContext) in Microsoft.Scripting.ScriptModule.Execute() in IronPython.Runtime.Importer.InitializeModule(String fullName, ScriptModule smod, Boolean executeModule) in IronPython.Runtime.Importer.LoadFromSourceUnit(SourceFileUnit sourceUnit) in IronPython.Runtime.Importer.ImportFromPath(CodeContext context, String name, String fullName, List path) in IronPython.Runtime.Importer.ImportNestedModule(CodeContext context, ScriptModule mod, String name) in IronPython.Runtime.Importer.ImportFrom(CodeContext context, Object mod, String name) in IronPython.Runtime.Builtin.Import(CodeContext context, String name, Object globals, Object locals, Object fromList) in _stub_##2(Object[] , DynamicSite`6 , CodeContext , Object , String , IAttributesCollection , IAttributesCollection , List ) in Microsoft.Scripting.Actions.DynamicSite`6.Invoke(CodeContext context, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) in IronPython.Runtime.Operations.PythonOps.ImportWithNames(CodeContext context, String fullName, String[] names) in pysnmp.v4.entity.rfc3413.oneliner.cmdgen$mod_12.Initialize(CodeContext ) in C:\Python25\lib\site-packages\pysnmp\v4\entity\rfc3413\oneliner\cmdgen.py:riga 2 in Microsoft.Scripting.ScriptCode.Run(CodeContext codeContext) in Microsoft.Scripting.ScriptModule.Execute() in IronPython.Runtime.Importer.InitializeModule(String fullName, ScriptModule smod, Boolean executeModule) in IronPython.Runtime.Importer.LoadFromSourceUnit(SourceFileUnit sourceUnit) in IronPython.Runtime.Importer.ImportFromPath(CodeContext context, String name, String fullName, List path) in IronPython.Runtime.Importer.ImportNestedModule(CodeContext context, ScriptModule mod, String name) in IronPython.Runtime.Importer.ImportFrom(CodeContext context, Object mod, String name) in IronPython.Runtime.Builtin.Import(CodeContext context, String name, Object globals, Object locals, Object fromList) in _stub_##2(Object[] , DynamicSite`6 , CodeContext , Object , String , IAttributesCollection , IAttributesCollection , List ) in Microsoft.Scripting.Actions.DynamicSite`6.Invoke(CodeContext context, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) in IronPython.Runtime.Operations.PythonOps.ImportWithNames(CodeContext context, String fullName, String[] names) in ##112(Object[] , CodeContext ) in Microsoft.Scripting.ScriptCode.Run(CodeContext codeContext) in Microsoft.Scripting.Hosting.CompiledCode.Evaluate(IScriptModule module) in Microsoft.Scripting.Hosting.ScriptEngine.ExecuteCommand(String code, IScriptModule module) in Microsoft.Scripting.Shell.CommandLine.RunOneInteraction() in Microsoft.Scripting.Shell.CommandLine.TryInteractiveAction() in IronPython.Hosting.PythonCommandLine.TryInteractiveAction() in Microsoft.Scripting.Shell.CommandLine.RunInteractiveLoop() TypeError: integer expected You are very kind. Thanks a lot! BTW: I'd go home now. Bye. On 8/10/07, Dino Viehland wrote: > > Do you know what type of object is being indexed and what the index type > is (what's happening on line 89 in tag.py)? You could also run with the > ?X:ExceptionDetail command line option and then we'd know where on the .NET > side of things this exception is coming from. > > > > Although I doubt this will help you might want to try running against the > 2.4 standard libraries. Our 2.5 support is still incomplete and there are > things the 2.5 std lib depends upon which we don't have implemented. You > could also see if the bug repros on v1.1 of IronPython as it could be a > regression in the 2.0 tree. > > > > *From:* users-bounces at lists.ironpython.com [mailto: > users-bounces at lists.ironpython.com] *On Behalf Of *Tianyong Tang > *Sent:* Friday, August 10, 2007 8:58 AM > *To:* users at lists.ironpython.com > *Subject:* [IronPython] TypeError: integer expected occurs when > __getitem__ is called > > > > Hi, > > I am a newbie with IronPython, and want to test pysnmp eggs of CPython > in IronPython. > > It works in CPython, but when I try it in IronPython, error occurred with > the import of libraries at the beginning: > > >>> from pysnmp.entity.rfc3413.oneliner import cmdgen > Traceback (most recent call last): > File , line 0, in ##254 > File , line 0, in _stub_##2 > File > C:\Python25\lib\site-packages\pysnmp\v4\entity\rfc3413\oneliner\cmdgen.py, > line 2, in Initialize > File , line 0, in _stub_##2 > File C:\Python25\lib\site-packages\pysnmp\v4\entity\engine.py, line 2, > in Initialize > File , line 0, in _stub_##2 > File C:\Python25\lib\site-packages\pysnmp\v4\proto\rfc3412.py, line 5, > in Initialize > File , line 0, in _stub_##2 > File C:\Python25\lib\site-packages\pysnmp\v4\proto\api\__init__.py, line > 1, in Initialize > File , line 0, in _stub_##2 > File C:\Python25\lib\site-packages\pysnmp\v4\proto\api\v1.py, line 3, in > Initialize > File , line 0, in _stub_##2 > File C:\Python25\lib\site-packages\pysnmp\v4\proto\rfc1155.py, line 37, > in Initialize > File C:\Python25\lib\site-packages\pysnmp\v4\proto\rfc1155.py, line 38, > in IpAddress > File , line 0, in _stub_##37 > File C:\Python25\lib\site-packages\pyasn1\v1\type\tag.py, line 84, in > tagImplicitly > File , line 0, in _stub_##248 > File C:\Python25\lib\site-packages\pyasn1\v1\type\tag.py, line 89, in > __getitem__ > File , line 0, in _stub_##253 > TypeError: integer expected > > can IronPython get around such errors? > > any response would be appreciated. > > Thanks in advanced. > > Good weekend. > > regards, > > Tianyong > > > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From miguel at novell.com Sat Aug 11 00:56:26 2007 From: miguel at novell.com (Miguel de Icaza) Date: Fri, 10 Aug 2007 18:56:26 -0400 Subject: [IronPython] IronPython on Unix issues. In-Reply-To: <5b0248170708072017h5a70f182p7c892e7147260261@mail.gmail.com> References: <1185503127.3940.1.camel@erandi.dom> <1186534062.31224.99.camel@erandi.dom> <5b0248170708072017h5a70f182p7c892e7147260261@mail.gmail.com> Message-ID: <1186786586.3922.7.camel@erandi.dom> Hello, To get IronPython to run on Unix, it is necessary to swap some code, it seems that the code in SystemState.cs tries to swap some builtins before the builtins are loaded. The code is the check for Unix inside InitializeBuiltins (patch is attached for those on Unix). Also Sanghyeon pointed out that the Makefile I posted was wrong: > Sorry, but this Makefile doesn't do resource generation for > Microsoft.Scripting.dll and IronPython.dll, and the resulting > IronPython console won't work correctly. You are correct Sanghyeon, I merely used the assemblies to do some work on our build system for Moonlight. I have now included a modified version of your nant build file. To get a working ipy.exe it is still necessary to move some code around. Miguel -------------- next part -------------- --- IronPython/Runtime/SystemState.cs.~1~ 2007-08-10 13:10:47.000000000 -0400 +++ IronPython/Runtime/SystemState.cs 2007-08-10 18:51:34.000000000 -0400 @@ -536,21 +536,6 @@ // We should register builtins, if any, from IronPython.dll _autoLoadBuiltins.Add(typeof(SystemState).Assembly); - if (Environment.OSVersion.Platform == PlatformID.Unix) { - // we make our nt package show up as a posix package - // on unix platforms. Because we build on top of the - // CLI for all file operations we should be good from - // there, but modules that check for the presence of - // names (e.g. os) will do the right thing. - Debug.Assert(_builtinsDict.ContainsKey("nt")); - _builtinsDict["posix"] = _builtinsDict["nt"]; - _builtinsDict.Remove("nt"); - } - DynamicHelpers.TopPackage.AssemblyLoaded += new EventHandler(TopPackage_AssemblyLoaded); PythonExtensionTypeAttribute._sysState = this; @@ -562,6 +547,17 @@ foreach(Assembly builtinsAssembly in _autoLoadBuiltins) { LoadBuiltins(builtinsAssembly); } + if (Environment.OSVersion.Platform == PlatformID.Unix) { + // we make our nt package show up as a posix package + // on unix platforms. Because we build on top of the + // CLI for all file operations we should be good from + // there, but modules that check for the presence of + // names (e.g. os) will do the right thing. + Debug.Assert(_builtinsDict.ContainsKey("nt")); + _builtinsDict["posix"] = _builtinsDict["nt"]; + _builtinsDict.Remove("nt"); + } + } private void TopPackage_AssemblyLoaded(object sender, AssemblyLoadedEventArgs e) { -------------- next part -------------- A non-text attachment was scrubbed... Name: IronPython.build Type: application/xml Size: 2265 bytes Desc: not available URL: From sanxiyn at gmail.com Sat Aug 11 05:49:06 2007 From: sanxiyn at gmail.com (Sanghyeon Seo) Date: Sat, 11 Aug 2007 12:49:06 +0900 Subject: [IronPython] TypeError: integer expected occurs when __getitem__ is called In-Reply-To: References: Message-ID: <5b0248170708102049n44af0e40t9b264bb8588649ea@mail.gmail.com> 2007/8/11, Tianyong Tang : > I am a newbie with IronPython, and want to test pysnmp eggs of CPython in > IronPython. > > It works in CPython, but when I try it in IronPython, error occurred with > the import of libraries at the beginning: (snip) > > File C:\Python25\lib\site-packages\pyasn1\v1\type\tag.py, > line 84, in tagImplicitly > File C:\Python25\lib\site-packages\pyasn1\v1\type\tag.py, > line 89, in __getitem__ > TypeError: integer expected This is IronPython issue #2728, reported last year. http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=2728 For the IronPython team: here's the relevant lines in the traceback: # A method of TagSet old-style class def tagImplicitly(self, superTag): # some lines omitted return self[:-1] + superTag So the index type is slice(None, -1, None), and the index should be converted by calling __len__ (which IronPython doesn't do). And then __getitem__ tries to index by None and TypeError is raised. -- Seo Sanghyeon From thane at tkpcorp.com Sun Aug 12 00:03:47 2007 From: thane at tkpcorp.com (Thane Plummer) Date: Sat, 11 Aug 2007 18:03:47 -0400 Subject: [IronPython] array missing in IPY 2.0A3 Message-ID: <000901c7dc63$7e58a480$6703a8c0@Dell9150> Any plans on re-implementing the built-in array module in IPY 2.0? IronPython console: IronPython 2.0A3 (2.0.10724.00) on .NET 2.0.50727.832 Copyright (c) Microsoft Corporation. All rights reserved. >>> import array Traceback (most recent call last): File , line 0, in ##28 File , line 0, in _stub_##2 ImportError: No module named array >>> IronPython 1.1 (1.1) on .NET 2.0.50727.832 Copyright (c) Microsoft Corporation. All rights reserved. >>> import array >>> arr = array.array('I') >>> li = range(12) >>> li [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] >>> arr.fromlist(li) >>> arr array('I', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ]) >>> type(arr) >>> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import array >>> arr = array.array('I') >>> l = range(12) >>> l [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] >>> arr.fromlist(l) >>> arr array('I', [0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L]) >>> type(arr) >>> Thane Plummer TKP Inc. Augusta, GA No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.476 / Virus Database: 269.11.13/946 - Release Date: 8/10/2007 3:50 PM -------------- next part -------------- An HTML attachment was scrubbed... URL: From oorrii at gmail.com Mon Aug 13 08:33:46 2007 From: oorrii at gmail.com (Ori) Date: Sun, 12 Aug 2007 23:33:46 -0700 (PDT) Subject: [IronPython] Using blocks separators instead of indentation Message-ID: <12121490.post@talk.nabble.com> Hello, Is there a way to use code blocks (like { and } in other languages) instead of indentation? Thanks, Ori -- View this message in context: http://www.nabble.com/Using-blocks-separators-instead-of-indentation-tf4259431.html#a12121490 Sent from the IronPython mailing list archive at Nabble.com. From sanxiyn at gmail.com Mon Aug 13 08:59:43 2007 From: sanxiyn at gmail.com (Sanghyeon Seo) Date: Mon, 13 Aug 2007 15:59:43 +0900 Subject: [IronPython] Using blocks separators instead of indentation In-Reply-To: <12121490.post@talk.nabble.com> References: <12121490.post@talk.nabble.com> Message-ID: <5b0248170708122359x4247cbd0t450f938fb1ce7c17@mail.gmail.com> 2007/8/13, Ori : > Is there a way to use code blocks (like { and } in other languages) instead > of indentation? >>> from __future__ import braces SyntaxError: not a chance -- Seo Sanghyeon From mclinton at procard.com Mon Aug 13 16:54:14 2007 From: mclinton at procard.com (Matt Clinton) Date: Mon, 13 Aug 2007 08:54:14 -0600 Subject: [IronPython] Using blocks separators instead of indentation In-Reply-To: <12121490.post@talk.nabble.com> References: <12121490.post@talk.nabble.com> Message-ID: <046C79B13A2D204A9FFB87C2EA406CA70256B479@glesexcc03.procard.local> Ori, I'm pretty sure there isn't - that's a basic 'feature' of Python itself: code blocks are defined by whitespace. (one of many bug-reduction syntax features) If you're working in VS, you'll often spend a little time highlighting a block of rows then pulling down Edit - Advanced - Increase/Decrease Indent when refactoring. Other editors (I'm fond of Crimson) make that even easier. Maybe Dino and Team can / have implement(ed) something special so IP can recognize blocks defined by curly-braces, but it would be rather anti-pythonic to do so. Why do you need to? Cheers, -- Matt -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Ori Sent: Monday, August 13, 2007 12:34 AM To: users at lists.ironpython.com Subject: [IronPython] Using blocks separators instead of indentation Hello, Is there a way to use code blocks (like { and } in other languages) instead of indentation? Thanks, Ori -- View this message in context: http://www.nabble.com/Using-blocks-separators-instead-of-indentation-tf4 259431.html#a12121490 Sent from the IronPython mailing list archive at Nabble.com. _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From m_tayseer82 at yahoo.com Mon Aug 13 17:16:25 2007 From: m_tayseer82 at yahoo.com (Mohammad Tayseer) Date: Mon, 13 Aug 2007 08:16:25 -0700 (PDT) Subject: [IronPython] Using blocks separators instead of indentation In-Reply-To: <046C79B13A2D204A9FFB87C2EA406CA70256B479@glesexcc03.procard.local> Message-ID: <185886.78364.qm@web31110.mail.mud.yahoo.com> You can use VB, or IronRuby or Managed JScript. But Python, no way!!!!!! Matt Clinton wrote: Ori, I'm pretty sure there isn't - that's a basic 'feature' of Python itself: code blocks are defined by whitespace. (one of many bug-reduction syntax features) If you're working in VS, you'll often spend a little time highlighting a block of rows then pulling down Edit - Advanced - Increase/Decrease Indent when refactoring. Other editors (I'm fond of Crimson) make that even easier. Maybe Dino and Team can / have implement(ed) something special so IP can recognize blocks defined by curly-braces, but it would be rather anti-pythonic to do so. Why do you need to? Cheers, -- Matt -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Ori Sent: Monday, August 13, 2007 12:34 AM To: users at lists.ironpython.com Subject: [IronPython] Using blocks separators instead of indentation Hello, Is there a way to use code blocks (like { and } in other languages) instead of indentation? Thanks, Ori -- View this message in context: http://www.nabble.com/Using-blocks-separators-instead-of-indentation-tf4 259431.html#a12121490 Sent from the IronPython mailing list archive at Nabble.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 Mohammad Tayseer http://spellcoder.com/blogs/tayseer --------------------------------- Yahoo! oneSearch: Finally, mobile search that gives answers, not web links. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dinov at exchange.microsoft.com Mon Aug 13 17:28:43 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Mon, 13 Aug 2007 08:28:43 -0700 Subject: [IronPython] Using blocks separators instead of indentation In-Reply-To: <046C79B13A2D204A9FFB87C2EA406CA70256B479@glesexcc03.procard.local> References: <12121490.post@talk.nabble.com> <046C79B13A2D204A9FFB87C2EA406CA70256B479@glesexcc03.procard.local> Message-ID: <7AD436E4270DD54A94238001769C2227B97B23C8A3@DF-GRTDANE-MSG.exchange.corp.microsoft.com> This is the extend part of embrace and extend everyone's expecting? :) I wouldn't be hold my breath waiting for this feature. (BTW, I use Shift-Tab/Tab to dedent/indent in VS). -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Matt Clinton Sent: Monday, August 13, 2007 7:54 AM To: Discussion of IronPython Subject: Re: [IronPython] Using blocks separators instead of indentation Ori, I'm pretty sure there isn't - that's a basic 'feature' of Python itself: code blocks are defined by whitespace. (one of many bug-reduction syntax features) If you're working in VS, you'll often spend a little time highlighting a block of rows then pulling down Edit - Advanced - Increase/Decrease Indent when refactoring. Other editors (I'm fond of Crimson) make that even easier. Maybe Dino and Team can / have implement(ed) something special so IP can recognize blocks defined by curly-braces, but it would be rather anti-pythonic to do so. Why do you need to? Cheers, -- Matt -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Ori Sent: Monday, August 13, 2007 12:34 AM To: users at lists.ironpython.com Subject: [IronPython] Using blocks separators instead of indentation Hello, Is there a way to use code blocks (like { and } in other languages) instead of indentation? Thanks, Ori -- View this message in context: http://www.nabble.com/Using-blocks-separators-instead-of-indentation-tf4 259431.html#a12121490 Sent from the IronPython mailing list archive at Nabble.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 From dinov at exchange.microsoft.com Mon Aug 13 17:31:45 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Mon, 13 Aug 2007 08:31:45 -0700 Subject: [IronPython] IronPython on Unix issues. In-Reply-To: <1186786586.3922.7.camel@erandi.dom> References: <1185503127.3940.1.camel@erandi.dom> <1186534062.31224.99.camel@erandi.dom> <5b0248170708072017h5a70f182p7c892e7147260261@mail.gmail.com> <1186786586.3922.7.camel@erandi.dom> Message-ID: <7AD436E4270DD54A94238001769C2227B97B23C8A4@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Thanks for the report Miguel, we'll get InitializeBuiltins fixed for the next release. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Miguel de Icaza Sent: Friday, August 10, 2007 3:56 PM To: Discussion of IronPython Subject: [IronPython] IronPython on Unix issues. Hello, To get IronPython to run on Unix, it is necessary to swap some code, it seems that the code in SystemState.cs tries to swap some builtins before the builtins are loaded. The code is the check for Unix inside InitializeBuiltins (patch is attached for those on Unix). Also Sanghyeon pointed out that the Makefile I posted was wrong: > Sorry, but this Makefile doesn't do resource generation for > Microsoft.Scripting.dll and IronPython.dll, and the resulting > IronPython console won't work correctly. You are correct Sanghyeon, I merely used the assemblies to do some work on our build system for Moonlight. I have now included a modified version of your nant build file. To get a working ipy.exe it is still necessary to move some code around. Miguel From dinov at exchange.microsoft.com Mon Aug 13 17:41:41 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Mon, 13 Aug 2007 08:41:41 -0700 Subject: [IronPython] Dear Lazy Web - IronPython 2 Parser In-Reply-To: <46BA4899.9070800@voidspace.org.uk> References: <46BA4899.9070800@voidspace.org.uk> Message-ID: <7AD436E4270DD54A94238001769C2227B97B23C8A5@DF-GRTDANE-MSG.exchange.corp.microsoft.com> I don't know if you figured this out yet but here goes... Our Parser class is still public (I'm not sure if this will change or not) but you can do (IronPython.Compiler.)Parser.CreateParser. That takes a CompilerContext class which is going to point the parser at a SourceUnit that we are currently parsing. >From there you can call ParseFileInput and it'll parse the file and return you the IronPython AST. The interesting part might be if you actually want to compile that code later on :). In that case you might want to look at PythonScriptCompiler to see the rest of the process - it's really just one call to PythonScriptCompiler.BindAndTransform which also seems to be public (again, I'm not sure if that'll change or not). Alternately if you just want a way to paramterize some user code you might want to look at ScriptCompiler.ParseCodeDom. This allows you to provide a limited CodeDom tree (we support CodeMemberMethod, and snippet statement / expressions and that's it) which you could create from some user input. The nice thing about that is it won't be Python specific (although I'm guessing that's not a problem for you :) ). -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord Sent: Wednesday, August 08, 2007 3:50 PM To: Discussion of IronPython Subject: [IronPython] Dear Lazy Web - IronPython 2 Parser Hello all, Sorry for being lazy, but... What is the easiest way of building an AST from IronPython 2 code? I would like an AST that I can modify and then flatten again in Silverlight.... It needn't be a Python AST, an IronPython one is fine. I only need access to 'name' nodes... I wish to change some of the names and turn the AST back into code before exec'ing. :-) Thanks Michael http://www.ironpython.info/ _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From dinov at exchange.microsoft.com Mon Aug 13 17:42:08 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Mon, 13 Aug 2007 08:42:08 -0700 Subject: [IronPython] array missing in IPY 2.0A3 In-Reply-To: <000901c7dc63$7e58a480$6703a8c0@Dell9150> References: <000901c7dc63$7e58a480$6703a8c0@Dell9150> Message-ID: <7AD436E4270DD54A94238001769C2227B97B23C8A7@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Yes, I've just been slacking on porting it forward. Sorry about that. From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Thane Plummer Sent: Saturday, August 11, 2007 3:04 PM To: 'Discussion of IronPython' Subject: [IronPython] array missing in IPY 2.0A3 Any plans on re-implementing the built-in array module in IPY 2.0? IronPython console: IronPython 2.0A3 (2.0.10724.00) on .NET 2.0.50727.832 Copyright (c) Microsoft Corporation. All rights reserved. >>> import array Traceback (most recent call last): File , line 0, in ##28 File , line 0, in _stub_##2 ImportError: No module named array >>> IronPython 1.1 (1.1) on .NET 2.0.50727.832 Copyright (c) Microsoft Corporation. All rights reserved. >>> import array >>> arr = array.array('I') >>> li = range(12) >>> li [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] >>> arr.fromlist(li) >>> arr array('I', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ]) >>> type(arr) >>> Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import array >>> arr = array.array('I') >>> l = range(12) >>> l [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] >>> arr.fromlist(l) >>> arr array('I', [0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L]) >>> type(arr) >>> Thane Plummer TKP Inc. Augusta, GA No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.476 / Virus Database: 269.11.13/946 - Release Date: 8/10/2007 3:50 PM -------------- next part -------------- An HTML attachment was scrubbed... URL: From dinov at exchange.microsoft.com Mon Aug 13 17:48:07 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Mon, 13 Aug 2007 08:48:07 -0700 Subject: [IronPython] TypeError: integer expected occurs when __getitem__ is called In-Reply-To: <5b0248170708102049n44af0e40t9b264bb8588649ea@mail.gmail.com> References: <5b0248170708102049n44af0e40t9b264bb8588649ea@mail.gmail.com> Message-ID: <7AD436E4270DD54A94238001769C2227B97B23C8AB@DF-GRTDANE-MSG.exchange.corp.microsoft.com> We actually have the right infrastructure in place to fix this fairly easily in v2.0. In v1.x our old-style instances were rather strange in that they were subclasses of our DynamicType class. Now they're (mostly - other than special cases here and there) just plain old new-style classes in v2.0 which matches CPython's behavior. So now they don't share this code path w/ new-style classes and old-style classes can be patched. Voting for this bug would be great but I also might just fix it in the v2.0 branch. Thanks for the report Tianyong and Seo for the great repro and initial report. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Sanghyeon Seo Sent: Friday, August 10, 2007 8:49 PM To: Discussion of IronPython Subject: Re: [IronPython] TypeError: integer expected occurs when __getitem__ is called 2007/8/11, Tianyong Tang : > I am a newbie with IronPython, and want to test pysnmp eggs of CPython in > IronPython. > > It works in CPython, but when I try it in IronPython, error occurred with > the import of libraries at the beginning: (snip) > > File C:\Python25\lib\site-packages\pyasn1\v1\type\tag.py, > line 84, in tagImplicitly > File C:\Python25\lib\site-packages\pyasn1\v1\type\tag.py, > line 89, in __getitem__ > TypeError: integer expected This is IronPython issue #2728, reported last year. http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=2728 For the IronPython team: here's the relevant lines in the traceback: # A method of TagSet old-style class def tagImplicitly(self, superTag): # some lines omitted return self[:-1] + superTag So the index type is slice(None, -1, None), and the index should be converted by calling __len__ (which IronPython doesn't do). And then __getitem__ tries to index by None and TypeError is raised. -- Seo Sanghyeon _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From oorrii at gmail.com Mon Aug 13 22:44:03 2007 From: oorrii at gmail.com (Ori) Date: Mon, 13 Aug 2007 13:44:03 -0700 (PDT) Subject: [IronPython] Using blocks separators instead of indentation In-Reply-To: <12121490.post@talk.nabble.com> References: <12121490.post@talk.nabble.com> Message-ID: <12133742.post@talk.nabble.com> OK I got the point. I have to use several statements in a single line. For exmpale, something like: i = 1; if (i >=1): i = 0 is there a way to do it? Is there a replacement to the newline char? Thanks. Ori wrote: > > Hello, > > Is there a way to use code blocks (like { and } in other languages) > instead of indentation? > > Thanks, > Ori > -- View this message in context: http://www.nabble.com/Using-blocks-separators-instead-of-indentation-tf4259431.html#a12133742 Sent from the IronPython mailing list archive at Nabble.com. From curt at hagenlocher.org Mon Aug 13 22:55:02 2007 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Mon, 13 Aug 2007 13:55:02 -0700 Subject: [IronPython] Using blocks separators instead of indentation In-Reply-To: <12133742.post@talk.nabble.com> References: <12121490.post@talk.nabble.com> <12133742.post@talk.nabble.com> Message-ID: On 8/13/07, Ori wrote: > > > OK I got the point. I have to use several statements in a single line. > > For exmpale, something like: > i = 1; if (i >=1): i = 0 > > is there a way to do it? Is there a replacement to the newline char? This is legal Python: a = 1; b = 2 if a != b: print 'different' I don't know *why* someone would want to write code like this unless they've been programming for such a short time that they've never had to go back and change something that they wrote over a year ago. I find this style unreadable. -- Curt Hagenlocher curt at hagenlocher.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From oorrii at gmail.com Mon Aug 13 23:23:27 2007 From: oorrii at gmail.com (Ori) Date: Mon, 13 Aug 2007 14:23:27 -0700 (PDT) Subject: [IronPython] Using blocks separators instead of indentation In-Reply-To: References: <12121490.post@talk.nabble.com> <12133742.post@talk.nabble.com> Message-ID: <12134397.post@talk.nabble.com> Thanks but I did not ask if it is ugly or not. I just need it. Is there a way to do it? Curt Hagenlocher wrote: > > On 8/13/07, Ori wrote: >> >> >> OK I got the point. I have to use several statements in a single line. >> >> For exmpale, something like: >> i = 1; if (i >=1): i = 0 >> >> is there a way to do it? Is there a replacement to the newline char? > > > This is legal Python: > > a = 1; b = 2 > if a != b: print 'different' > > I don't know *why* someone would want to write code like this unless > they've > been programming for such a short time that they've never had to go back > and > change something that they wrote over a year ago. I find this style > unreadable. > > -- > Curt Hagenlocher > curt at hagenlocher.org > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > -- View this message in context: http://www.nabble.com/Using-blocks-separators-instead-of-indentation-tf4259431.html#a12134397 Sent from the IronPython mailing list archive at Nabble.com. From curt at hagenlocher.org Mon Aug 13 23:39:00 2007 From: curt at hagenlocher.org (Curt Hagenlocher) Date: Mon, 13 Aug 2007 14:39:00 -0700 Subject: [IronPython] Using blocks separators instead of indentation In-Reply-To: <12134397.post@talk.nabble.com> References: <12121490.post@talk.nabble.com> <12133742.post@talk.nabble.com> <12134397.post@talk.nabble.com> Message-ID: On 8/13/07, Ori wrote: > > > Thanks but I did not ask if it is ugly or not. I just need it. > Is there a way to do it? In my email, I also gave two examples of legal Python code with more than one statement per line. In general, you can put any number of commands on the same line using a semi-colon as separator. That means that the following is legal Python: print 'hello'; print 'goodbye'; print 'up'; print down However, conditional and looping constructs that contain a colon -- that is, "if", "for", "while", etc. -- are limited to one per line, and the statement ending in a colon must be the first one on the line. That is, the first of these lines is legal Python and the second and third are not. if 1: print 'goodbye'; print 'hello' print 'hello'; if 1: print 'goodbye' if 1: print 'goodbye'; else: print 'hello' -- Curt Hagenlocher curt at hagenlocher.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From thane at tkpcorp.com Mon Aug 13 23:41:07 2007 From: thane at tkpcorp.com (Thane Plummer) Date: Mon, 13 Aug 2007 17:41:07 -0400 Subject: [IronPython] Using blocks separators instead of indentation In-Reply-To: <12134397.post@talk.nabble.com> Message-ID: <004101c7ddf2$a81d8700$6703a8c0@Dell9150> >>> mycommand = "i = 1\nif i >= 1:\n\tprint 'Test passed'\nelse:\n\tprint 'test failed'" >>> exec(mycommand) Test passed -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Ori Sent: Monday, August 13, 2007 5:23 PM To: users at lists.ironpython.com Subject: Re: [IronPython] Using blocks separators instead of indentation Thanks but I did not ask if it is ugly or not. I just need it. Is there a way to do it? Curt Hagenlocher wrote: > > On 8/13/07, Ori wrote: >> >> >> OK I got the point. I have to use several statements in a single line. >> >> For exmpale, something like: >> i = 1; if (i >=1): i = 0 >> >> is there a way to do it? Is there a replacement to the newline char? > > > This is legal Python: > > a = 1; b = 2 > if a != b: print 'different' > > I don't know *why* someone would want to write code like this unless > they've > been programming for such a short time that they've never had to go back > and > change something that they wrote over a year ago. I find this style > unreadable. > > -- > Curt Hagenlocher > curt at hagenlocher.org > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > -- View this message in context: http://www.nabble.com/Using-blocks-separators-instead-of-indentation-tf42594 31.html#a12134397 Sent from the IronPython mailing list archive at Nabble.com. _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.476 / Virus Database: 269.11.15/949 - Release Date: 8/12/2007 11:03 AM No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.476 / Virus Database: 269.11.15/949 - Release Date: 8/12/2007 11:03 AM From thane at tkpcorp.com Mon Aug 13 23:45:44 2007 From: thane at tkpcorp.com (Thane Plummer) Date: Mon, 13 Aug 2007 17:45:44 -0400 Subject: [IronPython] Using blocks separators instead of indentation In-Reply-To: <12134397.post@talk.nabble.com> Message-ID: <004201c7ddf3$4d3d1a70$6703a8c0@Dell9150> Ori, In my previous post I forgot to join the line with a semi-colon. The following is a legal -- albeit "unpythonic" -- single line that meets your requirement: >>> mycommand = "i = 1\nif i >= 1:\n\tprint 'Test passed'\nelse:\n\tprint 'test failed'"; exec(mycommand) Test passed >>> May the Python gods have mercy! --Thane -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Ori Sent: Monday, August 13, 2007 5:23 PM To: users at lists.ironpython.com Subject: Re: [IronPython] Using blocks separators instead of indentation Thanks but I did not ask if it is ugly or not. I just need it. Is there a way to do it? Curt Hagenlocher wrote: > > On 8/13/07, Ori wrote: >> >> >> OK I got the point. I have to use several statements in a single line. >> >> For exmpale, something like: >> i = 1; if (i >=1): i = 0 >> >> is there a way to do it? Is there a replacement to the newline char? > > > This is legal Python: > > a = 1; b = 2 > if a != b: print 'different' > > I don't know *why* someone would want to write code like this unless > they've > been programming for such a short time that they've never had to go back > and > change something that they wrote over a year ago. I find this style > unreadable. > > -- > Curt Hagenlocher > curt at hagenlocher.org > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > -- View this message in context: http://www.nabble.com/Using-blocks-separators-instead-of-indentation-tf42594 31.html#a12134397 Sent from the IronPython mailing list archive at Nabble.com. _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.476 / Virus Database: 269.11.15/949 - Release Date: 8/12/2007 11:03 AM No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.476 / Virus Database: 269.11.15/949 - Release Date: 8/12/2007 11:03 AM From fuzzyman at voidspace.org.uk Tue Aug 14 02:06:09 2007 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Tue, 14 Aug 2007 01:06:09 +0100 Subject: [IronPython] Dear Lazy Web - IronPython 2 Parser In-Reply-To: <7AD436E4270DD54A94238001769C2227B97B23C8A5@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <46BA4899.9070800@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227B97B23C8A5@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <46C0F1F1.1030704@voidspace.org.uk> Thanks for the reply Dino. Leaving some kind of API exposed to the Python parser would be appreciated, rather than making it private. What I would like to do in this case, is discover what variable names a Python expression uses. I know how to do this for a Python AST (name nodes that are the first child of an atom node). I don't even need to modify the AST - I just want to pull the names out. From what you said, I *think* that using Parser.CreateParser sounds the closest. With the help you provided, I got as far as the following code: import clr clr.AddReference('IronPython') clr.AddReference('Microsoft.Scripting') from IronPython import PythonEngineOptions from IronPython.Hosting import PythonEngine from IronPython.Compiler import Parser from Microsoft.Scripting import CompilerContext, SourceCodeUnit expression = "3 * 3" pe = PythonEngine.CurrentEngine s = SourceCodeUnit(pe, expression) c = CompilerContext(s) p = Parser.CreateParser(c, PythonEngineOptions()) e = p.ParseExpression() This gets me a BinaryExpression object, which has interesting properties like 'Left', 'Right', 'Start' and 'End' and a Walk method that takes a PythonWalker. (Presumably BinaryExpression is a node type - the root node of this particular expression.) I can find Microsoft.Scripting.Ast.Walker (which has multiple overloads of Walk for different node types). I assume the PythonWalker is a subclass of this. Can I use the expression object to inspect its nodes without creating a walker? Thanks for the help. :-) Michael Dino Viehland wrote: > I don't know if you figured this out yet but here goes... > > Our Parser class is still public (I'm not sure if this will change or not) but you can do (IronPython.Compiler.)Parser.CreateParser. That takes a CompilerContext class which is going to point the parser at a SourceUnit that we are currently parsing. > > >From there you can call ParseFileInput and it'll parse the file and return you the IronPython AST. The interesting part might be if you actually want to compile that code later on :). In that case you might want to look at PythonScriptCompiler to see the rest of the process - it's really just one call to PythonScriptCompiler.BindAndTransform which also seems to be public (again, I'm not sure if that'll change or not). > > Alternately if you just want a way to paramterize some user code you might want to look at ScriptCompiler.ParseCodeDom. This allows you to provide a limited CodeDom tree (we support CodeMemberMethod, and snippet statement / expressions and that's it) which you could create from some user input. The nice thing about that is it won't be Python specific (although I'm guessing that's not a problem for you :) ). > > > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord > Sent: Wednesday, August 08, 2007 3:50 PM > To: Discussion of IronPython > Subject: [IronPython] Dear Lazy Web - IronPython 2 Parser > > Hello all, > > Sorry for being lazy, but... > > What is the easiest way of building an AST from IronPython 2 code? I > would like an AST that I can modify and then flatten again in > Silverlight.... It needn't be a Python AST, an IronPython one is fine. I > only need access to 'name' nodes... I wish to change some of the names > and turn the AST back into code before exec'ing. > > :-) > > Thanks > > > Michael > http://www.ironpython.info/ > _______________________________________________ > 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 > > > From dinov at exchange.microsoft.com Tue Aug 14 02:14:51 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Mon, 13 Aug 2007 17:14:51 -0700 Subject: [IronPython] Dear Lazy Web - IronPython 2 Parser In-Reply-To: <46C0F1F1.1030704@voidspace.org.uk> References: <46BA4899.9070800@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227B97B23C8A5@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <46C0F1F1.1030704@voidspace.org.uk> Message-ID: <7AD436E4270DD54A94238001769C2227B97B23CAAA@DF-GRTDANE-MSG.exchange.corp.microsoft.com> PythonWalker and MS.Ast.Walker are actually different - PythonWalker walks the IronPython AST before its transformed to a DLR AST, and MS.Ast.Walker walks the DLR AST. You can certainly party on the Expression object all you want. But it'd be much easier (and less prone to break as we make changes to the AST) to create a subclass of PythonWalker. This is really easy in C# because it's just: class MyWalker : PythonWalker { public override bool Walk(NameExpression node) { Console.WriteLine(SymbolTable.IdToString(node.Name)); return true; // means walk this node, not important for a Name node. } } Then: e = p.ParseExpression() e.Walk(MyWalker()) >From Python it's a little more tricky because all the Walk nodes are overloaded - and by a little more tricky I mean you just need to test the type of node coming in :). (I haven't actually compiled any of this, but that's the theory). -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord Sent: Monday, August 13, 2007 5:06 PM To: Discussion of IronPython Subject: Re: [IronPython] Dear Lazy Web - IronPython 2 Parser Thanks for the reply Dino. Leaving some kind of API exposed to the Python parser would be appreciated, rather than making it private. What I would like to do in this case, is discover what variable names a Python expression uses. I know how to do this for a Python AST (name nodes that are the first child of an atom node). I don't even need to modify the AST - I just want to pull the names out. From what you said, I *think* that using Parser.CreateParser sounds the closest. With the help you provided, I got as far as the following code: import clr clr.AddReference('IronPython') clr.AddReference('Microsoft.Scripting') from IronPython import PythonEngineOptions from IronPython.Hosting import PythonEngine from IronPython.Compiler import Parser from Microsoft.Scripting import CompilerContext, SourceCodeUnit expression = "3 * 3" pe = PythonEngine.CurrentEngine s = SourceCodeUnit(pe, expression) c = CompilerContext(s) p = Parser.CreateParser(c, PythonEngineOptions()) e = p.ParseExpression() This gets me a BinaryExpression object, which has interesting properties like 'Left', 'Right', 'Start' and 'End' and a Walk method that takes a PythonWalker. (Presumably BinaryExpression is a node type - the root node of this particular expression.) I can find Microsoft.Scripting.Ast.Walker (which has multiple overloads of Walk for different node types). I assume the PythonWalker is a subclass of this. Can I use the expression object to inspect its nodes without creating a walker? Thanks for the help. :-) Michael Dino Viehland wrote: > I don't know if you figured this out yet but here goes... > > Our Parser class is still public (I'm not sure if this will change or not) but you can do (IronPython.Compiler.)Parser.CreateParser. That takes a CompilerContext class which is going to point the parser at a SourceUnit that we are currently parsing. > > >From there you can call ParseFileInput and it'll parse the file and return you the IronPython AST. The interesting part might be if you actually want to compile that code later on :). In that case you might want to look at PythonScriptCompiler to see the rest of the process - it's really just one call to PythonScriptCompiler.BindAndTransform which also seems to be public (again, I'm not sure if that'll change or not). > > Alternately if you just want a way to paramterize some user code you might want to look at ScriptCompiler.ParseCodeDom. This allows you to provide a limited CodeDom tree (we support CodeMemberMethod, and snippet statement / expressions and that's it) which you could create from some user input. The nice thing about that is it won't be Python specific (although I'm guessing that's not a problem for you :) ). > > > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord > Sent: Wednesday, August 08, 2007 3:50 PM > To: Discussion of IronPython > Subject: [IronPython] Dear Lazy Web - IronPython 2 Parser > > Hello all, > > Sorry for being lazy, but... > > What is the easiest way of building an AST from IronPython 2 code? I > would like an AST that I can modify and then flatten again in > Silverlight.... It needn't be a Python AST, an IronPython one is fine. I > only need access to 'name' nodes... I wish to change some of the names > and turn the AST back into code before exec'ing. > > :-) > > Thanks > > > Michael > http://www.ironpython.info/ > _______________________________________________ > 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 From joe at notcharles.ca Tue Aug 14 05:30:14 2007 From: joe at notcharles.ca (Joe Mason) Date: Mon, 13 Aug 2007 23:30:14 -0400 Subject: [IronPython] Using blocks separators instead of indentation In-Reply-To: <12133742.post@talk.nabble.com> References: <12121490.post@talk.nabble.com> <12133742.post@talk.nabble.com> Message-ID: On 8/13/07, Ori wrote: > > > OK I got the point. I have to use several statements in a single line. > > For exmpale, something like: > i = 1; if (i >=1): i = 0 > > is there a way to do it? Is there a replacement to the newline char? Why does it have to be in a single line? Just put it on two lines. If you're storing it in a data file or something, just embed \n and \t's in it to represent newlines and indentation levels. Escape it somehow if you have to. Joe -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuzzyman at voidspace.org.uk Wed Aug 15 00:45:21 2007 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Tue, 14 Aug 2007 23:45:21 +0100 Subject: [IronPython] Dear Lazy Web - IronPython 2 Parser In-Reply-To: <7AD436E4270DD54A94238001769C2227B97B23CAAA@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <46BA4899.9070800@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227B97B23C8A5@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <46C0F1F1.1030704@voidspace.org.uk> <7AD436E4270DD54A94238001769C2227B97B23CAAA@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <46C23081.3060204@voidspace.org.uk> Great! Thanks Dino. With the following C# code: using System; using System.Collections; using System.Collections.Generic; using IronPython.Compiler.Ast; using Microsoft.Scripting; namespace ExpressionWalker { public class ExpressionWalker : PythonWalker { public List names = new List(); public override bool Walk(NameExpression node) { names.Add(SymbolTable.IdToString(node.Name)); return true; // means walk this node, not important for a Name node. } } } The following Python code: import clr clr.AddReference('ExpressionWalker') clr.AddReference('IronPython') clr.AddReference('Microsoft.Scripting') from IronPython import PythonEngineOptions from IronPython.Hosting import PythonEngine from IronPython.Compiler import Parser from Microsoft.Scripting import CompilerContext, SourceCodeUnit from ExpressionWalker import ExpressionWalker expression = "A1 * 3 + B4" pe = PythonEngine.CurrentEngine s = SourceCodeUnit(pe, expression) c = CompilerContext(s) p = Parser.CreateParser(c, PythonEngineOptions()) e = p.ParseExpression() w = ExpressionWalker() e.Walk(w) print list(w.names) Produces: ['A1', 'B4'] This works in Silverlight (which is my intention). :-) I'll add this to the cookbook, but I realise that parts of this interface may be unstable... Michael Dino Viehland wrote: > PythonWalker and MS.Ast.Walker are actually different - PythonWalker walks the IronPython AST before its transformed to a DLR AST, and MS.Ast.Walker walks the DLR AST. > > You can certainly party on the Expression object all you want. But it'd be much easier (and less prone to break as we make changes to the AST) to create a subclass of PythonWalker. This is really easy in C# because it's just: > > class MyWalker : PythonWalker { > public override bool Walk(NameExpression node) { > Console.WriteLine(SymbolTable.IdToString(node.Name)); > return true; // means walk this node, not important for a Name node. > } > } > > Then: > e = p.ParseExpression() > e.Walk(MyWalker()) > > >From Python it's a little more tricky because all the Walk nodes are overloaded - and by a little more tricky I mean you just need to test the type of node coming in :). > (I haven't actually compiled any of this, but that's the theory). > > > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord > Sent: Monday, August 13, 2007 5:06 PM > To: Discussion of IronPython > Subject: Re: [IronPython] Dear Lazy Web - IronPython 2 Parser > > Thanks for the reply Dino. > > Leaving some kind of API exposed to the Python parser would be > appreciated, rather than making it private. > > What I would like to do in this case, is discover what variable names a > Python expression uses. > > I know how to do this for a Python AST (name nodes that are the first > child of an atom node). I don't even need to modify the AST - I just > want to pull the names out. > > From what you said, I *think* that using Parser.CreateParser sounds the > closest. > > With the help you provided, I got as far as the following code: > > import clr > clr.AddReference('IronPython') > clr.AddReference('Microsoft.Scripting') > > from IronPython import PythonEngineOptions > from IronPython.Hosting import PythonEngine > from IronPython.Compiler import Parser > from Microsoft.Scripting import CompilerContext, SourceCodeUnit > > expression = "3 * 3" > pe = PythonEngine.CurrentEngine > > s = SourceCodeUnit(pe, expression) > c = CompilerContext(s) > p = Parser.CreateParser(c, PythonEngineOptions()) > > e = p.ParseExpression() > > This gets me a BinaryExpression object, which has interesting properties > like 'Left', 'Right', 'Start' and 'End' and a Walk method that takes a > PythonWalker. (Presumably BinaryExpression is a node type - the root > node of this particular expression.) > > I can find Microsoft.Scripting.Ast.Walker (which has multiple overloads > of Walk for different node types). I assume the PythonWalker is a > subclass of this. > > Can I use the expression object to inspect its nodes without creating a > walker? > > Thanks for the help. :-) > > Michael > > Dino Viehland wrote: > >> I don't know if you figured this out yet but here goes... >> >> Our Parser class is still public (I'm not sure if this will change or not) but you can do (IronPython.Compiler.)Parser.CreateParser. That takes a CompilerContext class which is going to point the parser at a SourceUnit that we are currently parsing. >> >> >From there you can call ParseFileInput and it'll parse the file and return you the IronPython AST. The interesting part might be if you actually want to compile that code later on :). In that case you might want to look at PythonScriptCompiler to see the rest of the process - it's really just one call to PythonScriptCompiler.BindAndTransform which also seems to be public (again, I'm not sure if that'll change or not). >> >> Alternately if you just want a way to paramterize some user code you might want to look at ScriptCompiler.ParseCodeDom. This allows you to provide a limited CodeDom tree (we support CodeMemberMethod, and snippet statement / expressions and that's it) which you could create from some user input. The nice thing about that is it won't be Python specific (although I'm guessing that's not a problem for you :) ). >> >> >> -----Original Message----- >> From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord >> Sent: Wednesday, August 08, 2007 3:50 PM >> To: Discussion of IronPython >> Subject: [IronPython] Dear Lazy Web - IronPython 2 Parser >> >> Hello all, >> >> Sorry for being lazy, but... >> >> What is the easiest way of building an AST from IronPython 2 code? I >> would like an AST that I can modify and then flatten again in >> Silverlight.... It needn't be a Python AST, an IronPython one is fine. I >> only need access to 'name' nodes... I wish to change some of the names >> and turn the AST back into code before exec'ing. >> >> :-) >> >> Thanks >> >> >> Michael >> http://www.ironpython.info/ >> _______________________________________________ >> 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 > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > > > From walgri at gmail.com Wed Aug 15 10:54:02 2007 From: walgri at gmail.com (walgri) Date: Wed, 15 Aug 2007 10:54:02 +0200 Subject: [IronPython] WPF 3D: Missing Viewport3D when importing Message-ID: <5f59b5ad0708150154x7d150be6j9136401d649c0ef9@mail.gmail.com> Hello, I have some Python experience, but I'm very new to .Net/WPF programming. I find that Media3D is missing Viewport3D in 2.0A3: IronPython console: IronPython 2.0A3 (2.0.10724.00) on .NET 2.0.50727.42 Copyright (c) Microsoft Corporation. All rights reserved. >>> import clr >>> clr.AddReferenceByPartialName("PresentationCore") >>> import System.Windows.Media.Media3D as media3d >>> dir(media3d) ['AffineTransform3D', 'AmbientLight', 'AxisAngleRotation3D', 'Camera', 'Converte rs', 'DiffuseMaterial', 'DirectionalLight', 'EmissiveMaterial', 'Geometry3D', 'G eometryModel3D', 'HitTestParameters3D', 'Light', 'Material', 'MaterialCollection ', 'MaterialGroup', 'Matrix3D', 'Matrix3DConverter', 'MatrixCamera', 'MatrixTran sform3D', 'MeshGeometry3D', 'Model3D', 'Model3DCollection', 'Model3DGroup', 'Mod elVisual3D', 'OrthographicCamera', 'PerspectiveCamera', 'Point3D', 'Point3DColle ction', 'Point3DCollectionConverter', 'Point3DConverter', 'Point4D', 'Point4DCon verter', 'PointLight', 'PointLightBase', 'ProjectionCamera', 'Quaternion', 'Quat ernionConverter', 'QuaternionRotation3D', 'RayHitTestParameters', 'RayHitTestRes ult', 'RayMeshGeometry3DHitTestResult', 'Rect3D', 'Rect3DConverter', 'RotateTran sform3D', 'Rotation3D', 'ScaleTransform3D', 'Size3D', 'Size3DConverter', 'Specul arMaterial', 'SpotLight', 'Transform3D', 'Transform3DCollection', 'Transform3DGr oup', 'TranslateTransform3D', 'Vector3D', 'Vector3DCollection', 'Vector3DCollect ionConverter', 'Vector3DConverter', 'Viewport3DVisual', 'Visual3D', 'Visual3DCol lection'] >>> v=Viewport3D() Traceback (most recent call last): File , line 0, in ##18 NameError: name 'Viewport3D' is not defined >>> In Ipy 1.1, with previous import of avalon.py, Viewport3D is still missing, but is actually avaliable: IronPython 1.1 (1.1) on .NET 2.0.50727.42 Copyright (c) Microsoft Corporation. All rights reserved. >>> >>> from avalon import * >>> clr.AddReferenceByPartialName("PresentationCore") >>> import System.Windows.Media.Media3D as media3d >>> dir(media3d) ['AffineTransform3D', 'AmbientLight', 'AxisAngleRotation3D', 'Camera', 'Converte rs', 'DiffuseMaterial', 'DirectionalLight', 'EmissiveMaterial', 'Geometry3D', 'G eometryModel3D', 'HitTestParameters3D', 'Light', 'Material', 'MaterialCollection ', 'MaterialGroup', 'Matrix3D', 'Matrix3DConverter', 'MatrixCamera', 'MatrixTran sform3D', 'MeshGeometry3D', 'Model3D', 'Model3DCollection', 'Model3DGroup', 'Mod elVisual3D', 'OrthographicCamera', 'PerspectiveCamera', 'Point3D', 'Point3DColle ction', 'Point3DCollectionConverter', 'Point3DConverter', 'Point4D', 'Point4DCon verter', 'PointLight', 'PointLightBase', 'ProjectionCamera', 'Quaternion', 'Quat ernionConverter', 'QuaternionRotation3D', 'RayHitTestParameters', 'RayHitTestRes ult', 'RayMeshGeometry3DHitTestResult', 'Rect3D', 'Rect3DConverter', 'RotateTran sform3D', 'Rotation3D', 'ScaleTransform3D', 'Size3D', 'Size3DConverter', 'Specul arMaterial', 'SpotLight', 'Transform3D', 'Transform3DCollection', 'Transform3DGr oup', 'TranslateTransform3D', 'Vector3D', 'Vector3DCollection', 'Vector3DCollect ionConverter', 'Vector3DConverter', 'Viewport3DVisual', 'Visual3D', 'Visual3DCol lection', '__builtins__', '__dict__', '__name__'] >>> v=Viewport3D() >>> Actually the following code works if I cut and paste it in an Ipy 1.1 session, but fails as a standalone app: ###for IronPython 1.1: #from avalon import * ### for IronPython 2.0A3: import clr clr.AddReferenceByPartialName("PresentationCore") clr.AddReferenceByPartialName("PresentationFramework") from System.Windows import * from System.Windows.Media import * from System.Windows.Media.Media3D import * w=Window() v=Viewport3D() cam = PerspectiveCamera() cam.FarPlaneDistance = 100 cam.LookDirection = Vector3D(-11,-10,-9) cam.UpDirection = Vector3D(0,0,1) cam.NearPlaneDistance = 1 cam.Position = Point3D(11,10,9) cam.FieldOfView = 70 v.Camera = cam triangleMesh = MeshGeometry3D() point0 = Point3D(0, 0, 0) point1 = Point3D(5, 0, 0) point2 = Point3D(0, 0, 5) triangleMesh.Positions.Add(point0) triangleMesh.Positions.Add(point1) triangleMesh.Positions.Add(point2) triangleMesh.TriangleIndices.Add(0) triangleMesh.TriangleIndices.Add(2) triangleMesh.TriangleIndices.Add(1) normal = Vector3D(0, 1, 0) triangleMesh.Normals.Add(normal) triangleMesh.Normals.Add(normal) triangleMesh.Normals.Add(normal) material = DiffuseMaterial(SolidColorBrush(Colors.Lime)) triangleModel = GeometryModel3D(triangleMesh, material) model = ModelVisual3D() model.Content = triangleModel v.Children.Add(model) #let there be light: lightmodel = ModelVisual3D() light = DirectionalLight() light.Color=Colors.White light.Direction=Vector3D(-2,-3,-1) lightmodel.Content = light v.Children.Add(lightmodel) #show: w.Content=v w.Show() Any help or advice in getting this code running as an application would be very appreciated. Best regards, Walgri From walgri at gmail.com Wed Aug 15 16:00:43 2007 From: walgri at gmail.com (walgri) Date: Wed, 15 Aug 2007 14:00:43 -0000 Subject: [IronPython] WPF 3D: Missing Viewport3D when importing In-Reply-To: <5f59b5ad0708150154x7d150be6j9136401d649c0ef9@mail.gmail.com> References: <5f59b5ad0708150154x7d150be6j9136401d649c0ef9@mail.gmail.com> Message-ID: <1187186443.294835.110930@k79g2000hse.googlegroups.com> Sorry, please replace the previous script with the following one. Running this script as standalone actually shows what I meant and hangs. But I guess this is unrelated to the Viewport3D issue. ############################# import clr from avalon import * clr.AddReferenceByPartialName("PresentationCore") clr.AddReferenceByPartialName("PresentationFramework") from System.Windows import * from System.Windows.Media import * from System.Windows.Media.Media3D import * #from System.Windows.Media.Media3D import Viewport3D w=Window() v=Viewport3D() cam = PerspectiveCamera() cam.FarPlaneDistance = 100 cam.LookDirection = Vector3D(-11,-10,-9) cam.UpDirection = Vector3D(0,0,1) cam.NearPlaneDistance = 1 cam.Position = Point3D(11,10,9) cam.FieldOfView = 70 v.Camera = cam triangleMesh = MeshGeometry3D() point0 = Point3D(0, 0, 0) point1 = Point3D(5, 0, 0) point2 = Point3D(0, 0, 5) triangleMesh.Positions.Add(point0) triangleMesh.Positions.Add(point1) triangleMesh.Positions.Add(point2) triangleMesh.TriangleIndices.Add(0) triangleMesh.TriangleIndices.Add(2) triangleMesh.TriangleIndices.Add(1) normal = Vector3D(0, 1, 0) triangleMesh.Normals.Add(normal) triangleMesh.Normals.Add(normal) triangleMesh.Normals.Add(normal) material = DiffuseMaterial(SolidColorBrush(Colors.Lime)) triangleModel = GeometryModel3D(triangleMesh, material) model = ModelVisual3D() model.Content = triangleModel v.Children.Add(model) #aggiungo una luce lightmodel = ModelVisual3D() light = DirectionalLight() light.Color=Colors.White light.Direction=Vector3D(-2,-3,-1) lightmodel.Content = light v.Children.Add(lightmodel) #visualizza: w.Content=v w.Show() ############################# Best regards, Walgri From dinov at exchange.microsoft.com Wed Aug 15 16:49:32 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Wed, 15 Aug 2007 07:49:32 -0700 Subject: [IronPython] WPF 3D: Missing Viewport3D when importing In-Reply-To: <1187186443.294835.110930@k79g2000hse.googlegroups.com> References: <5f59b5ad0708150154x7d150be6j9136401d649c0ef9@mail.gmail.com> <1187186443.294835.110930@k79g2000hse.googlegroups.com> Message-ID: <7AD436E4270DD54A94238001769C2227B97B762498@DF-GRTDANE-MSG.exchange.corp.microsoft.com> This is hanging due to the way avalon.py works. It's primarily intended for working at the interactive console. When Avalon.py gets started it hijacks the console execution so that all execution occurs on another thread. This other thread is the primary thread for the app's window and its constantly pumping messages. This allows you to continue to work at the console while the app remains responsive. When you run this from a script that's not going to work because the script isn't being entered at the console. The key thing you need to do is app = Application() and then app.Run() at the bottom of your script. I copied the necessary lines out of Avalon.py and ended up with: import clr #from avalon import * clr.AddReferenceByPartialName("PresentationCore") clr.AddReferenceByPartialName("PresentationFramework") clr.AddReferenceByPartialName("WindowsBase") from System import * from System.Windows import * from System.Windows.Media import * from System.Windows.Media.Animation import * from System.Windows.Controls import * from System.Windows.Shapes import * from System.Windows.Threading import * from System.Windows import * from System.Windows.Media import * from System.Windows.Media.Media3D import * #from System.Windows.Media.Media3D import Viewport3D w=Window() v=Viewport3D() cam = PerspectiveCamera() cam.FarPlaneDistance = 100 cam.LookDirection = Vector3D(-11,-10,-9) cam.UpDirection = Vector3D(0,0,1) cam.NearPlaneDistance = 1 cam.Position = Point3D(11,10,9) cam.FieldOfView = 70 v.Camera = cam triangleMesh = MeshGeometry3D() point0 = Point3D(0, 0, 0) point1 = Point3D(5, 0, 0) point2 = Point3D(0, 0, 5) triangleMesh.Positions.Add(point0) triangleMesh.Positions.Add(point1) triangleMesh.Positions.Add(point2) triangleMesh.TriangleIndices.Add(0) triangleMesh.TriangleIndices.Add(2) triangleMesh.TriangleIndices.Add(1) normal = Vector3D(0, 1, 0) triangleMesh.Normals.Add(normal) triangleMesh.Normals.Add(normal) triangleMesh.Normals.Add(normal) material = DiffuseMaterial(SolidColorBrush(Colors.Lime)) triangleModel = GeometryModel3D(triangleMesh, material) model = ModelVisual3D() model.Content = triangleModel v.Children.Add(model) #aggiungo una luce lightmodel = ModelVisual3D() light = DirectionalLight() light.Color=Colors.White light.Direction=Vector3D(-2,-3,-1) lightmodel.Content = light v.Children.Add(lightmodel) #visualizza: w.Content=v w.Show() app = Application() app.Run() ############################# -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of walgri Sent: Wednesday, August 15, 2007 7:01 AM To: users at lists.ironpython.com Subject: Re: [IronPython] WPF 3D: Missing Viewport3D when importing Sorry, please replace the previous script with the following one. Running this script as standalone actually shows what I meant and hangs. But I guess this is unrelated to the Viewport3D issue. ############################# import clr from avalon import * clr.AddReferenceByPartialName("PresentationCore") clr.AddReferenceByPartialName("PresentationFramework") from System.Windows import * from System.Windows.Media import * from System.Windows.Media.Media3D import * #from System.Windows.Media.Media3D import Viewport3D w=Window() v=Viewport3D() cam = PerspectiveCamera() cam.FarPlaneDistance = 100 cam.LookDirection = Vector3D(-11,-10,-9) cam.UpDirection = Vector3D(0,0,1) cam.NearPlaneDistance = 1 cam.Position = Point3D(11,10,9) cam.FieldOfView = 70 v.Camera = cam triangleMesh = MeshGeometry3D() point0 = Point3D(0, 0, 0) point1 = Point3D(5, 0, 0) point2 = Point3D(0, 0, 5) triangleMesh.Positions.Add(point0) triangleMesh.Positions.Add(point1) triangleMesh.Positions.Add(point2) triangleMesh.TriangleIndices.Add(0) triangleMesh.TriangleIndices.Add(2) triangleMesh.TriangleIndices.Add(1) normal = Vector3D(0, 1, 0) triangleMesh.Normals.Add(normal) triangleMesh.Normals.Add(normal) triangleMesh.Normals.Add(normal) material = DiffuseMaterial(SolidColorBrush(Colors.Lime)) triangleModel = GeometryModel3D(triangleMesh, material) model = ModelVisual3D() model.Content = triangleModel v.Children.Add(model) #aggiungo una luce lightmodel = ModelVisual3D() light = DirectionalLight() light.Color=Colors.White light.Direction=Vector3D(-2,-3,-1) lightmodel.Content = light v.Children.Add(lightmodel) #visualizza: w.Content=v w.Show() ############################# Best regards, Walgri _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From walgri at gmail.com Thu Aug 16 14:06:50 2007 From: walgri at gmail.com (walgri) Date: Thu, 16 Aug 2007 14:06:50 +0200 Subject: [IronPython] WPF 3D: Missing Viewport3D when importing In-Reply-To: <7AD436E4270DD54A94238001769C2227B97B762498@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <5f59b5ad0708150154x7d150be6j9136401d649c0ef9@mail.gmail.com> <1187186443.294835.110930@k79g2000hse.googlegroups.com> <7AD436E4270DD54A94238001769C2227B97B762498@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <5f59b5ad0708160506m529e81aara589057fcd7f4138@mail.gmail.com> Thank you very much Dino. You also showed me that Viewport3D lives actually in System.Windows.Controls Best regards, Walgri On 8/15/07, Dino Viehland wrote: > This is hanging due to the way avalon.py works. It's primarily intended for working at the interactive console. When Avalon.py gets started it hijacks the console execution so that all execution occurs on another thread. This other thread is the primary thread for the app's window and its constantly pumping messages. This allows you to continue to work at the console while the app remains responsive. > > When you run this from a script that's not going to work because the script isn't being entered at the console. The key thing you need to do is app = Application() and then app.Run() at the bottom of your script. I copied the necessary lines out of Avalon.py and ended up with: [...] From empirebuilder at gmail.com Fri Aug 17 14:08:32 2007 From: empirebuilder at gmail.com (Dody Gunawinata) Date: Fri, 17 Aug 2007 15:08:32 +0300 Subject: [IronPython] Implementing an interface with ref parameters Message-ID: <8cd017b80708170508q594e09ccrc7c8fa1155c867c3@mail.gmail.com> Hi all, I'm trying to implement a C# interface with methods that contains ref parameter, eg: public interface IContent { void BeginProcess(ref bool captureContent); void EndProcess(string content); } A straight implementation will not work because IronPython does not modify the captureContent value class ImageGallery(IContent): def BeginProcess(captureContent): captureContent = False # This doesn't work. -- nomadlife.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From dinov at exchange.microsoft.com Fri Aug 17 23:46:06 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Fri, 17 Aug 2007 14:46:06 -0700 Subject: [IronPython] Implementing an interface with ref parameters In-Reply-To: <8cd017b80708170508q594e09ccrc7c8fa1155c867c3@mail.gmail.com> References: <8cd017b80708170508q594e09ccrc7c8fa1155c867c3@mail.gmail.com> Message-ID: <7AD436E4270DD54A94238001769C2227B97B7629CF@DF-GRTDANE-MSG.exchange.corp.microsoft.com> I believe what we should be doing is passing you a Reference object where T in this case is bool. The Reference object has a Value property which you can set and when you return the ref parameter should get updated. Let me know if that doesn't work for you. From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Dody Gunawinata Sent: Friday, August 17, 2007 5:09 AM To: users at lists.ironpython.com Subject: [IronPython] Implementing an interface with ref parameters Hi all, I'm trying to implement a C# interface with methods that contains ref parameter, eg: public interface IContent { void BeginProcess(ref bool captureContent); void EndProcess(string content); } A straight implementation will not work because IronPython does not modify the captureContent value class ImageGallery(IContent): def BeginProcess(captureContent): captureContent = False # This doesn't work. -- nomadlife.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From empirebuilder at gmail.com Sat Aug 18 07:28:34 2007 From: empirebuilder at gmail.com (Dody Gunawinata) Date: Sat, 18 Aug 2007 08:28:34 +0300 Subject: [IronPython] Implementing an interface with ref parameters In-Reply-To: <7AD436E4270DD54A94238001769C2227B97B7629CF@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <8cd017b80708170508q594e09ccrc7c8fa1155c867c3@mail.gmail.com> <7AD436E4270DD54A94238001769C2227B97B7629CF@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <8cd017b80708172228g3e8c69cemc9a6579b1ef62818@mail.gmail.com> Great. It works now. Thank you. public interface IContent { void BeginProcess(ref bool captureContent); void EndProcess(string content); } class ImageGallery(IContent): def BeginProcess(captureContent): captureContent.Value = False # Now works On 8/18/07, Dino Viehland wrote: > > I believe what we should be doing is passing you a Reference object > where T in this case is bool. The Reference object has a Value property > which you can set and when you return the ref parameter should get updated. > > > > Let me know if that doesn't work for you. > > > > *From:* users-bounces at lists.ironpython.com [mailto: > users-bounces at lists.ironpython.com] *On Behalf Of *Dody Gunawinata > *Sent:* Friday, August 17, 2007 5:09 AM > *To:* users at lists.ironpython.com > *Subject:* [IronPython] Implementing an interface with ref parameters > > > > Hi all, > > I'm trying to implement a C# interface with methods that contains ref > parameter, eg: > > public interface IContent > { > void BeginProcess(ref bool captureContent); > void EndProcess(string content); > } > > A straight implementation will not work because IronPython does not modify > the captureContent value > > class ImageGallery(IContent): > def BeginProcess(captureContent): > captureContent = False # This doesn't work. > > > > -- > nomadlife.org > -- nomadlife.org -------------- next part -------------- An HTML attachment was scrubbed... URL: From richarde at talkingtech.com Mon Aug 20 01:33:59 2007 From: richarde at talkingtech.com (Richard Ertel) Date: Mon, 20 Aug 2007 11:33:59 +1200 Subject: [IronPython] Problem loading lastest IronPython Solution (Change Set 25569) Message-ID: <0C38A083FABB3F4F80E155D6B4DE181BCB7498@MATRIXV2.talkingtech.com> Hi All, I've tried loading the latest checkin of the Iron Python solution (Change Set 25569), however Visual Studio complains about some malformed xml in 2 of the project files. The first being in IronPython.Modules.csproj. The error is: The project file could not be loaded. The 'ItemGroup' start tag on line 101 does not match the end tag of 'None'. Line 103, position 7. The second being in Microsoft.Scripting.csproj. It's the same error however on a different line, 471. Both ItemGroups appear to be trying to establish a path to a Strong Name Key file. Below is the invalid node content: Properties\25StrongName.snk If you remove the offending ItemGroup node from each file the problem is resolved and the solution & projects will load successfully. Thanks, Richard Ertel -------------- next part -------------- An HTML attachment was scrubbed... URL: From rdawson at exchange.microsoft.com Mon Aug 20 20:12:06 2007 From: rdawson at exchange.microsoft.com (Ryan Dawson) Date: Mon, 20 Aug 2007 11:12:06 -0700 Subject: [IronPython] Problem loading lastest IronPython Solution (Change Set 25569) In-Reply-To: <0C38A083FABB3F4F80E155D6B4DE181BCB7498@MATRIXV2.talkingtech.com> References: <0C38A083FABB3F4F80E155D6B4DE181BCB7498@MATRIXV2.talkingtech.com> Message-ID: <50B69702CA6E6D4E849D30CD4989AB8E9C838CDA2E@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Thanks for the report Richard. I've just pushed an update to the Codeplex source that includes a fix for this. We have a different layout internally than we do on Codeplex and this was an artifact of our scripts to transform the two. -Ryan From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Richard Ertel Sent: Sunday, August 19, 2007 4:34 PM To: users at lists.ironpython.com Subject: [IronPython] Problem loading lastest IronPython Solution (Change Set 25569) Hi All, I've tried loading the latest checkin of the Iron Python solution (Change Set 25569), however Visual Studio complains about some malformed xml in 2 of the project files. The first being in IronPython.Modules.csproj. The error is: The project file could not be loaded. The 'ItemGroup' start tag on line 101 does not match the end tag of 'None'. Line 103, position 7. The second being in Microsoft.Scripting.csproj. It's the same error however on a different line, 471. Both ItemGroups appear to be trying to establish a path to a Strong Name Key file. Below is the invalid node content: Properties\25StrongName.snk If you remove the offending ItemGroup node from each file the problem is resolved and the solution & projects will load successfully. Thanks, Richard Ertel -------------- next part -------------- An HTML attachment was scrubbed... URL: From sanxiyn at gmail.com Wed Aug 29 08:14:09 2007 From: sanxiyn at gmail.com (Sanghyeon Seo) Date: Wed, 29 Aug 2007 15:14:09 +0900 Subject: [IronPython] Microsoft Permissive License's asymmetry of binary and source distribution Message-ID: <5b0248170708282314u7e6481fcn538178f63e465459@mail.gmail.com> Hi, I hope this post is on topic on this list, since IronPython 2.0 is licensed under Microsoft Permissive License (Ms-PL), currently v1.1. As you may have heard, Microsoft Permissive License was submitted to Open Source Initiative for its license approval process. During the process, many people pointed out an asymmetry in Ms-PL's permission for binary and source distribution. Namely the cluase "If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license". In other words, Source distribution: only under Ms-PL Binary distribution: under a license that compiles with Ms-PL I haven't given my due attention to this clause in the past, but given the extremely clear wording, this is obviously intentional. Now, suppose a collective work composed of Ms-PL-licensed sources and GPL-licensed sources. My understanding is that it is undistributable in source code form since both licenses want it to be licensed "under this license". I think GPL would "comply with Ms-PL", but GPL requires distributing in binary form to be accompanied with the complete machine-readable source code, so the source code needs to be distributable too. That would be rather unfortunate, since I like both Ms-PL and GPL. But I guess that's what Microsoft intended after all. I'm not a lawyer, this not legal advice, corrections welcome, etc. -- Seo Sanghyeon From anakinnani at hotmail.com Wed Aug 29 12:00:50 2007 From: anakinnani at hotmail.com (jane janet) Date: Wed, 29 Aug 2007 10:00:50 +0000 Subject: [IronPython] (no subject) Message-ID: An HTML attachment was scrubbed... URL: From xmlhacker at gmail.com Wed Aug 29 12:25:56 2007 From: xmlhacker at gmail.com (M. David Peterson) Date: Wed, 29 Aug 2007 04:25:56 -0600 Subject: [IronPython] Microsoft Permissive License's asymmetry of binary and source distribution In-Reply-To: <5b0248170708282314u7e6481fcn538178f63e465459@mail.gmail.com> References: <5b0248170708282314u7e6481fcn538178f63e465459@mail.gmail.com> Message-ID: On 8/29/07, Sanghyeon Seo wrote: > > > Now, suppose a collective work composed of Ms-PL-licensed sources and > GPL-licensed sources. My understanding is that it is undistributable > in source code form since both licenses want it to be licensed "under > this license". I think GPL would "comply with Ms-PL", but GPL requires > distributing in binary form to be accompanied with the complete > machine-readable source code, so the source code needs to be > distributable too. Isn't this true about most BSD-esque licenses? I'll admit that I have never really dug much deeper than the surface as to why BSD-esque and GPL licenses tend to be incompatible and therefore redistribution of a GPL'd software package inside of a BSD-esque software package is not allowed. But off the top of my head, the Trac <> MoinMoin incompatibility comes to mind, and there are obviously LOTS and LOTS of other similar situations. Is this particular issue really all that unique, or am I missing something obvious? -- /M:D M. David Peterson http://mdavid.name | http://www.oreillynet.com/pub/au/2354 | http://dev.aol.com/blog/3155 -------------- next part -------------- An HTML attachment was scrubbed... URL: From xmlhacker at gmail.com Wed Aug 29 12:37:56 2007 From: xmlhacker at gmail.com (M. David Peterson) Date: Wed, 29 Aug 2007 04:37:56 -0600 Subject: [IronPython] Microsoft Permissive License's asymmetry of binary and source distribution In-Reply-To: References: <5b0248170708282314u7e6481fcn538178f63e465459@mail.gmail.com> Message-ID: Oh yeah, OBLIGATORY IANAL CLAUSE Which is a true statement, so for what its worth, nothing I have said is worth the paper its not printed on as far as the law is concerned. That said, as it turns out I am meeting with a room full of them this morning to discuss a very similar topic in regards to how to properly license the source code and other items as they relate to an upcoming release from my company. I'll bring up this issue and see what they have to say on the matter and follow-up with the result**. ** Which of course will in no way be legally binding or potentially even accurate as it relates to anything other than my companies choice of licensing schemes. But information from people who are paid to know legal stuff about stuff is always nice to have around. If nothing else it can make for good non-legally binding trivia to be slung around IRC in a way that makes people think you actually know what you're taking about***. ;-) *** And you can never get enough of non-legally binding IRCable trivia if you were to ask me****. **** Which if you did it wouldn't be legally binding because as well are now ever so painfully overly aware, I AM NOT A LAWYER*****! ***** Thank God, is all I, and I can only assume *MANY* others have to say. ;-) On 8/29/07, M. David Peterson wrote: > > On 8/29/07, Sanghyeon Seo wrote: > > > > > > Now, suppose a collective work composed of Ms-PL-licensed sources and > > GPL-licensed sources. My understanding is that it is undistributable > > in source code form since both licenses want it to be licensed "under > > this license". I think GPL would "comply with Ms-PL", but GPL requires > > distributing in binary form to be accompanied with the complete > > machine-readable source code, so the source code needs to be > > distributable too. > > > > Isn't this true about most BSD-esque licenses? I'll admit that I have > never really dug much deeper than the surface as to why BSD-esque and GPL > licenses tend to be incompatible and therefore redistribution of a GPL'd > software package inside of a BSD-esque software package is not allowed. But > off the top of my head, the Trac <> MoinMoin incompatibility comes to mind, > and there are obviously LOTS and LOTS of other similar situations. > > > Is this particular issue really all that unique, or am I missing something > obvious? > > > -- > /M:D > > M. David Peterson > http://mdavid.name | http://www.oreillynet.com/pub/au/2354 | http://dev.aol.com/blog/3155 > -- /M:D M. David Peterson http://mdavid.name | http://www.oreillynet.com/pub/au/2354 | http://dev.aol.com/blog/3155 -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuzzyman at voidspace.org.uk Wed Aug 29 15:33:25 2007 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Wed, 29 Aug 2007 14:33:25 +0100 Subject: [IronPython] Microsoft Permissive License's asymmetry of binary and source distribution In-Reply-To: References: <5b0248170708282314u7e6481fcn538178f63e465459@mail.gmail.com> Message-ID: <46D575A5.5040404@voidspace.org.uk> M. David Peterson wrote: > On 8/29/07, *Sanghyeon Seo* > wrote: > > > Now, suppose a collective work composed of Ms-PL-licensed sources and > GPL-licensed sources. My understanding is that it is undistributable > in source code form since both licenses want it to be licensed "under > this license". I think GPL would "comply with Ms-PL", but GPL requires > distributing in binary form to be accompanied with the complete > machine-readable source code, so the source code needs to be > distributable too. > > > Isn't this true about most BSD-esque licenses? The BSD license generally is compatible with GPL. The most common form of the BSD license is the 'revised BSD'. The original BSD license wasn't compatible. See: http://www.gnu.org/licenses/gpl-faq.html#OrigBSD All the best, Michael Foord http://www.ironpython.info/ > I'll admit that I have never really dug much deeper than the surface > as to why BSD-esque and GPL licenses tend to be incompatible and > therefore redistribution of a GPL'd software package inside of a > BSD-esque software package is not allowed. But off the top of my > head, the Trac <> MoinMoin incompatibility comes to mind, and there > are obviously LOTS and LOTS of other similar situations. > > Is this particular issue really all that unique, or am I missing > something obvious? > > -- > /M:D > > M. David Peterson > http://mdavid.name | http://www.oreillynet.com/pub/au/2354 | > http://dev.aol.com/blog/3155 > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > From anakinnani at hotmail.com Wed Aug 29 15:40:01 2007 From: anakinnani at hotmail.com (jane janet) Date: Wed, 29 Aug 2007 13:40:01 +0000 Subject: [IronPython] IronPython and Database In-Reply-To: <46D575A5.5040404@voidspace.org.uk> Message-ID: An HTML attachment was scrubbed... URL: From joesox at gmail.com Wed Aug 29 15:52:35 2007 From: joesox at gmail.com (JoeSox) Date: Wed, 29 Aug 2007 06:52:35 -0700 Subject: [IronPython] IronPython and Database In-Reply-To: References: <46D575A5.5040404@voidspace.org.uk> Message-ID: <785694cd0708290652i69b98f9fuad9a6e98cf13ef99@mail.gmail.com> On 8/29/07, jane janet wrote: > Hello eveybody, > > I really want to know how to access database both Oracle XE 10g and > PostgreSQL by using Ironpython. The server and client are in different host. > > Please help me. Have you read...? Use Oracle With ADO.NET Access Oracle databases from your .NET apps. http://www.ftponline.com/vsm/2003_01/magazine/features/beauchemin/ -- Later, JoeSox From anakinnani at hotmail.com Wed Aug 29 19:24:27 2007 From: anakinnani at hotmail.com (jane janet) Date: Wed, 29 Aug 2007 17:24:27 +0000 Subject: [IronPython] IronPython and Oracle Message-ID: An HTML attachment was scrubbed... URL: From dinov at exchange.microsoft.com Wed Aug 29 19:41:25 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Wed, 29 Aug 2007 10:41:25 -0700 Subject: [IronPython] IronPython and Oracle In-Reply-To: References: Message-ID: <7AD436E4270DD54A94238001769C2227BCB1CA87BD@DF-GRTDANE-MSG.exchange.corp.microsoft.com> You might try starting IronPython with -X:ExceptionDetail to get the full stack trace and the CLR exception info. That's likely to be more useful in this case than the python exception display you're seeing here. Once you've got the right exception name a search on the web might tell you what causes that specific error. From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of jane janet Sent: Wednesday, August 29, 2007 10:24 AM To: users at lists.ironpython.com Subject: [IronPython] IronPython and Oracle Dear Everybody, I installed Oracle Database 10g Express Edition (Universal) on the Server Host. And then, I used Ironpython access this database on server host by Microsoft OLE DB Provider for Oracle. It's work. import clr import System clr.AddReference("System.Data") from System.Data import DataSet from System.Data.OleDb import OleDbConnection, OleDbDataAdapter, OleDbCommand conStr = "Provider=MSDAORA.1;User ID=name;Password=pwd;Persist Security Info=False" con = OleDbConnection(conStr) query = "SELECT * FROM TEST" adapter = OleDbDataAdapter(query,con) ds = DataSet() con.Open() adapter.Fill(ds,"t1") for i in range(ds.Tables["t1"].Rows.Count -1 ): print ds.Tables["t1"].Rows[i][0] print ds.Tables["t1"].Rows[i][1] print ds.Tables["t1"].Rows[i][2] con.Close() But my problem is I can't access Oracle Server side from client side by the same provider. I changed conStr to this conStr = """Provider=MSDAORA.1;User ID=name;Password=pwd; (DESCRIPTION=(CONNECT_DATA=(SID =XE) (CID=(PROGRAM=C:\WINDOWS\system32\Rundll32.exe) (HOST=hostname)(USER=name))) (ADDRESS=(PROTOCOL=TCP)(HOST=xx.yy.zz.ww) (PORT=1521)))""" I got EnvironmentError: ORA-12560: TNS:protocol adapter error I don't know how to solve this problem. Please help me everything i missed and everything i should know. What I should do or change something, please tell me. Thank you. ________________________________ Puzzles, trivia teasers, word scrambles and more. Play for your chance to win! -------------- next part -------------- An HTML attachment was scrubbed... URL: From fuzzyman at voidspace.org.uk Wed Aug 29 22:19:19 2007 From: fuzzyman at voidspace.org.uk (Michael Foord) Date: Wed, 29 Aug 2007 21:19:19 +0100 Subject: [IronPython] [python] IronPython and Oracle In-Reply-To: References: Message-ID: <46D5D4C7.3060907@voidspace.org.uk> Hello Jane, I hope you don't mind, but I added your example code to the IronPython cookbook: http://www.ironpython.info/index.php/Oracle_%26_OleDb All the best, Michael Foord jane janet wrote: > > Dear Everybody, > > I installed Oracle Database 10/g/ Express Edition (Universal) on the > Server Host. > > And then, I used Ironpython access this database on server host by > Microsoft OLE DB Provider for Oracle. It's work. > > * * > > *import clr* > > *import System* > > *clr.AddReference("System.Data")* > > *from System.Data import DataSet * > > *from System.Data.OleDb import OleDbConnection, OleDbDataAdapter, > OleDbCommand* > > *conStr = "Provider=MSDAORA.1;User ID=name;Password=pwd;Persist > Security Info=False"* > > *con = OleDbConnection(conStr)* > > *query = "SELECT * FROM TEST"* > > *adapter = OleDbDataAdapter(query,con)* > > *ds = DataSet()* > > *con.Open()* > > *adapter.Fill(ds,"t1")* > > *for i in range(ds.Tables["t1"].Rows.Count -1 ):* > > *print ds.Tables["t1"].Rows[i][0]* > > *print ds.Tables["t1"].Rows[i][1]* > > *print ds.Tables["t1"].Rows[i][2]* > > *con.Close()* > > But my problem is I can't access Oracle Server side from client side > by the same provider. > > I changed conStr to this > > conStr = """Provider=MSDAORA.1;User ID=name;Password=pwd; > (DESCRIPTION=(CONNECT_DATA=(SID =XE) > (CID=(PROGRAM=C:\WINDOWS\system32\Rundll32.exe) > (HOST=hostname)(USER=name))) > (ADDRESS=(PROTOCOL=TCP)(HOST=xx.yy.zz.ww) > (PORT=1521)))""" > > I got EnvironmentError: ORA-12560: TNS:protocol adapter error > > I don't know how to solve this problem. > > Please help me everything i missed and everything i should know. What > I should do or change something, please tell me. > > Thank you. > > > > > > > > > ------------------------------------------------------------------------ > Puzzles, trivia teasers, word scrambles and more. Play for your chance > to win! > ------------------------------------------------------------------------ > > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > From sanxiyn at gmail.com Thu Aug 30 01:40:10 2007 From: sanxiyn at gmail.com (Sanghyeon Seo) Date: Thu, 30 Aug 2007 08:40:10 +0900 Subject: [IronPython] IronPython and Oracle In-Reply-To: References: Message-ID: <5b0248170708291640i4a75df46ue9a9d54079d9dc49@mail.gmail.com> 2007/8/30, jane janet : > I got EnvironmentError: ORA-12560: TNS:protocol adapter error > I don't know how to solve this problem. Can you run SQL*Plus on the client side? If you can't, it's most likely Oracle configuration problem, unrelated to IronPython. Oracle configuration problems are not on-topic on this list, but take a look at: http://www.orafaq.com/forum/t/85568/0/ -- Seo Sanghyeon From riltim at gmail.com Thu Aug 30 04:09:40 2007 From: riltim at gmail.com (Tim Riley) Date: Wed, 29 Aug 2007 22:09:40 -0400 Subject: [IronPython] Hosting: Delegates from Ironpython to C# Message-ID: I'm embedding IronPython in a C# dll that is hosted inside a program called AutoCAD. In order to register commands in AutoCAD from .NET I need to P/Invoke a C function inside a .dll. I can do this fairly easy from C# but I can't figure out the right way to call my C# wrapper from IronPython to have it register the command. I have perused the hosting docs for 1.1 and haven't been able to come up with a solution that works. Here is my C# code. I either want to call the PyRegCmds void or the PythonRegister void. Both of which expect a delegate.for example if I had a python function like: def test1: print "This is a test". I can't figure out how to map test to the delegate required in the code below. Note: I can call this from C# fine. See :static public void test(). Can anyone give me any pointers? It would be greatly appreciated. code: using System ; using System.Runtime.InteropServices; using Autodesk.AutoCAD.Runtime ; using Autodesk.AutoCAD.EditorInput; namespace PyAcadDotNet { /// /// PyAcadCmd Class: /// Used to register commands on the AutoCAD command stack. /// public class PyAcadCmd { public PyAcadCmd() { } public delegate void CmdDelegate(); /// /// RegPyAcadCmd: /// Registers a delegate (callback) with the AutoCAD command string /// on the command stack. /// [DllImport("PyRegCmd.dll", CallingConvention=CallingConvention.Cdecl,CharSet = CharSet.Unicode, EntryPoint = "?RegPyCmd@@YAXPB_W0HP6AXXZ at Z")] public static extern void RegPyCmd( string cmd_group, string cmd_name, Autodesk.AutoCAD.Runtime.CommandFlags cmd_flags, [MarshalAs(UnmanagedType.FunctionPtr)] PyAcadCmd.CmdDelegate cmd_delegate); public static void PythonRegister(string CommandName, CmdDelegate FuncPointer, CommandFlags flags) { RegPyCmd("_pycmds", CommandName, flags, FuncPointer); } //testing stuff public static void testcommand() { Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; ed.WriteMessage("\ncb1 delegate seems to work!\n"); } [CommandMethod("regcmds")] static public void test() // This method can have any name { CmdDelegate cb1 = new CmdDelegate(PyAcadCmd.testcommand); PythonRegister("testcommand", cb1, CommandFlags.Session); } } } From xmlhacker at gmail.com Thu Aug 30 10:20:56 2007 From: xmlhacker at gmail.com (M. David Peterson) Date: Thu, 30 Aug 2007 02:20:56 -0600 Subject: [IronPython] Microsoft Permissive License's asymmetry of binary and source distribution In-Reply-To: <46D575A5.5040404@voidspace.org.uk> References: <5b0248170708282314u7e6481fcn538178f63e465459@mail.gmail.com> <46D575A5.5040404@voidspace.org.uk> Message-ID: On 8/29/07, Michael Foord wrote: > > > > Isn't this true about most BSD-esque licenses? > > The BSD license generally is compatible with GPL. The most common form > of the BSD license is the 'revised BSD'. > > The original BSD license wasn't compatible. See: > > http://www.gnu.org/licenses/gpl-faq.html#OrigBSD Thanks for the clarification, Michael! -- /M:D M. David Peterson http://mdavid.name | http://www.oreillynet.com/pub/au/2354 | http://dev.aol.com/blog/3155 -------------- next part -------------- An HTML attachment was scrubbed... URL: From trond.andersen at gmail.com Thu Aug 30 15:02:02 2007 From: trond.andersen at gmail.com (Trond Andersen) Date: Thu, 30 Aug 2007 15:02:02 +0200 Subject: [IronPython] IronPython with libgmail gives trouble with HTTPSHandler Message-ID: <9356cb300708300602s13d3b09cxe96111aa4b77a838@mail.gmail.com> I'm testing out using a python based library towards GMail with IronPython, but I run into a problem when using the API. http://libgmail.sourceforge.net/ The following statements work in Iron Python: import sys sys.path.append("C:\\Dev\\libgmail\\build\\lib") import libgmail But the following line fails: ga = libgmail.GmailAccount("my.username at gmail.com", "mypassword") With this error message: AttributeError: 'module' object has no attribute 'HTTPSHandler' The same code work when using regular Python (2.4.4) on the same Windows machine. Any ideas on how to handle this? ------- Trond From sanxiyn at gmail.com Thu Aug 30 15:32:41 2007 From: sanxiyn at gmail.com (Sanghyeon Seo) Date: Thu, 30 Aug 2007 22:32:41 +0900 Subject: [IronPython] IronPython with libgmail gives trouble with HTTPSHandler In-Reply-To: <9356cb300708300602s13d3b09cxe96111aa4b77a838@mail.gmail.com> References: <9356cb300708300602s13d3b09cxe96111aa4b77a838@mail.gmail.com> Message-ID: <5b0248170708300632j4ea9f8f4qb362cb1863212dbc@mail.gmail.com> 2007/8/30, Trond Andersen : > With this error message: > AttributeError: 'module' object has no attribute 'HTTPSHandler' IronPython currently lacks SSL support. FePy includes SSL support. I tested libgmail and it works on FePy. http://fepy.sourceforge.net/ -- Seo Sanghyeon From dinov at exchange.microsoft.com Thu Aug 30 17:27:33 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Thu, 30 Aug 2007 08:27:33 -0700 Subject: [IronPython] Hosting: Delegates from Ironpython to C# In-Reply-To: References: Message-ID: <7AD436E4270DD54A94238001769C2227BD9F666736@DF-GRTDANE-MSG.exchange.corp.microsoft.com> I think you should be able to just pass a function object to PythonRegister and it should be converted into a delegate. For example: import clr clr.AddReference('PyAcadDotNet') from PyAcadDotNet import PyAcadCmd def foo(): print 'hello world' PyAcadCmd.PythonRegister('some command', foo, CommandFlags.Whatever) Does that not work? -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Tim Riley Sent: Wednesday, August 29, 2007 7:10 PM To: Discussion of IronPython Subject: [IronPython] Hosting: Delegates from Ironpython to C# I'm embedding IronPython in a C# dll that is hosted inside a program called AutoCAD. In order to register commands in AutoCAD from .NET I need to P/Invoke a C function inside a .dll. I can do this fairly easy from C# but I can't figure out the right way to call my C# wrapper from IronPython to have it register the command. I have perused the hosting docs for 1.1 and haven't been able to come up with a solution that works. Here is my C# code. I either want to call the PyRegCmds void or the PythonRegister void. Both of which expect a delegate.for example if I had a python function like: def test1: print "This is a test". I can't figure out how to map test to the delegate required in the code below. Note: I can call this from C# fine. See :static public void test(). Can anyone give me any pointers? It would be greatly appreciated. code: using System ; using System.Runtime.InteropServices; using Autodesk.AutoCAD.Runtime ; using Autodesk.AutoCAD.EditorInput; namespace PyAcadDotNet { /// /// PyAcadCmd Class: /// Used to register commands on the AutoCAD command stack. /// public class PyAcadCmd { public PyAcadCmd() { } public delegate void CmdDelegate(); /// /// RegPyAcadCmd: /// Registers a delegate (callback) with the AutoCAD command string /// on the command stack. /// [DllImport("PyRegCmd.dll", CallingConvention=CallingConvention.Cdecl,CharSet = CharSet.Unicode, EntryPoint = "?RegPyCmd@@YAXPB_W0HP6AXXZ at Z")] public static extern void RegPyCmd( string cmd_group, string cmd_name, Autodesk.AutoCAD.Runtime.CommandFlags cmd_flags, [MarshalAs(UnmanagedType.FunctionPtr)] PyAcadCmd.CmdDelegate cmd_delegate); public static void PythonRegister(string CommandName, CmdDelegate FuncPointer, CommandFlags flags) { RegPyCmd("_pycmds", CommandName, flags, FuncPointer); } //testing stuff public static void testcommand() { Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; ed.WriteMessage("\ncb1 delegate seems to work!\n"); } [CommandMethod("regcmds")] static public void test() // This method can have any name { CmdDelegate cb1 = new CmdDelegate(PyAcadCmd.testcommand); PythonRegister("testcommand", cb1, CommandFlags.Session); } } } _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From riltim at gmail.com Thu Aug 30 17:59:01 2007 From: riltim at gmail.com (Tim Riley) Date: Thu, 30 Aug 2007 11:59:01 -0400 Subject: [IronPython] Hosting: Delegates from Ironpython to C# In-Reply-To: <7AD436E4270DD54A94238001769C2227BD9F666736@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <7AD436E4270DD54A94238001769C2227BD9F666736@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: Dino: I was trying something similar to what you had posted and was getting an error. I also just tried the code you gave me with a minor correction to fix the CommandFlags part and received the error below. If it helps I have also added the C# code use to call the python file below the error if that will help at all. *********ERROR*********** Command: pyfile System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at PyAcadDotNet.PyAcadCmd.RegPyCmd(String cmd_group, String cmd_name, CommandFlags cmd_flags, CmdDelegate cmd_delegate) at PyAcadDotNet.PyAcadCmd.PythonRegister(String CommandName, CmdDelegate FuncPointer, CommandFlags flags) in C:\Documents and Settings\TJRiley\My Documents\pyacaddotnet\registercommand.cs:line 65 at PythonRegister##20(Object , Object , Object ) at IronPython.Runtime.Calls.CallTarget3.Invoke(Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.FastCallable3.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.BuiltinFunction.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext context, Object func, Object arg0, Object arg1, Object arg2) at C:\Documents and Settings\TJRiley\My Documents\pyacaddotnet\Samples\commandmethod_test.py##22(ModuleScope ) at IronPython.Hosting.CompiledCodeDelegate.Invoke(ModuleScope moduleScope) at IronPython.Hosting.CompiledCode.Run(ModuleScope moduleScope) at IronPython.Hosting.CompiledCode.Execute(EngineModule engineModule, IDictionary`2 locals) at IronPython.Hosting.CompiledCode.Execute() at PyAcadDotNet.AcadInterface.pythonfile() in C:\Documents and Settings\TJRiley\My Documents\pyacaddotnet\PyAcadDotNet.cs:line 98 *********ERROR*********** *********CODE************** using System; using System.Collections; using System.Windows.Forms; using System.IO; using System.Text; using System.Runtime.InteropServices; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.EditorInput; using AcEd = Autodesk.AutoCAD.EditorInput; using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application; using IronPython.Hosting; namespace PyAcadDotNet { public class AcadInterface : IExtensionApplication { static internal AcEd.Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor; public delegate void TestDelegate(); public void Initialize() { ed.WriteMessage("\nPyAcad.NET Loaded Successfully...."); ed.WriteMessage("\ntype 'pyhelp' for commands...."); } public void Terminate() { this.Terminate(); } internal delegate void AddReference(object assembly); [CommandMethod("pyfile", CommandFlags.Session)] static public void pythonfile() { using (PythonEngine engine = new PythonEngine()) { using (AcadCommandLine myCommandLine = new AcadCommandLine()) { try { // Create a new instance of PythonEngine and set variables. engine.AddToPath(Environment.CurrentDirectory); // Send Stdout and Stderr to the AutoCAD command line. engine.SetStandardOutput(myCommandLine); engine.SetStandardError(myCommandLine); engine.Import("clr"); PyAcadCmd regcmds = new PyAcadCmd(); engine.Globals.Add("regcmds", regcmds); //lets load some AutoCAD assemblies. AddReference adr = engine.CreateMethod("clr.AddReference(assembly)"); adr(typeof(BlockTableRecord).Assembly); adr(typeof(Editor).Assembly); // Display an OpenFileDialog and run the script. OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Python files (*.py)|*.py|All files (*.*)|*.*"; ofd.ShowDialog(); // Run the file selected by the open file dialog box. //engine.ExecuteFile(ofd.FileName); CompiledCode cc = engine.CompileFile(ofd.FileName); cc.Execute(); } catch (System.Exception e) { ed.WriteMessage(e.ToString()); } } } } } // public class AcadCommandLine : Stream //Modified version of a class coded by Mike Stall. { public AcadCommandLine() { //constructor } #region unsupported Read + Seek members public override bool CanRead { get { return false; } } public override bool CanSeek { get { return false; } } public override bool CanWrite { get { return true; } } public override void Flush() { // } public override long Length { get { throw new NotSupportedException("Seek not supported"); } // can't seek } public override long Position { get { throw new NotSupportedException("Seek not supported"); // can't seek } set { throw new NotSupportedException("Seek not supported"); // can't seek } } public override int Read(byte[] buffer, int offset, int count) { throw new NotSupportedException("Reed not supported"); // can't read } public override long Seek(long offset, SeekOrigin origin) { throw new NotSupportedException("Seek not supported"); // can't seek } public override void SetLength(long value) { throw new NotSupportedException("Seek not supported"); // can't seek } #endregion public override void Write(byte[] buffer, int offset, int count) { try { // Very bad hack: Ignore single newline char. This is because we expect the newline is following // previous content and we already placed a newline on that. AcEd.Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor; if (count == 1 && buffer[offset] == '\n') return; StringBuilder sb = new StringBuilder(); while (count > 0) { char ch = (char)buffer[offset]; if (ch == '\n') { ed.WriteMessage(sb.ToString() + "\n"); sb.Length = 0; // reset. } else if (ch != '\r') { sb.Append(ch); } offset++; count--; } if (sb.Length > 0) ed.WriteMessage(sb.ToString() + "\n"); } catch (System.Exception e) { throw e; } } } } *********CODE************** On 8/30/07, Dino Viehland wrote: > I think you should be able to just pass a function object to PythonRegister and it should be converted into a delegate. For example: > > import clr > clr.AddReference('PyAcadDotNet') > from PyAcadDotNet import PyAcadCmd > > def foo(): > print 'hello world' > > PyAcadCmd.PythonRegister('some command', foo, CommandFlags.Whatever) > > Does that not work? > > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Tim Riley > Sent: Wednesday, August 29, 2007 7:10 PM > To: Discussion of IronPython > Subject: [IronPython] Hosting: Delegates from Ironpython to C# > > I'm embedding IronPython in a C# dll that is hosted inside a program > called AutoCAD. In order to register commands in AutoCAD from .NET I > need to P/Invoke a C function inside a .dll. I can do this fairly easy > from C# but I can't figure out the right way to call my C# wrapper > from IronPython to have it register the command. I have perused the > hosting docs for 1.1 and haven't been able to come up with a solution > that works. Here is my C# code. I either want to call the PyRegCmds > void or the PythonRegister void. Both of which expect a delegate.for > example if I had a python function like: > > def test1: > print "This is a test". > > I can't figure out how to map test to the delegate required in the code below. > Note: I can call this from C# fine. See :static public void test(). > > Can anyone give me any pointers? It would be greatly appreciated. > > > code: > > using System ; > using System.Runtime.InteropServices; > using Autodesk.AutoCAD.Runtime ; > using Autodesk.AutoCAD.EditorInput; > > namespace PyAcadDotNet > { > /// > /// PyAcadCmd Class: > /// Used to register commands on the AutoCAD command stack. > /// > public class PyAcadCmd > { > public PyAcadCmd() > { > } > public delegate void CmdDelegate(); > > /// > /// RegPyAcadCmd: > /// Registers a delegate (callback) with the AutoCAD command string > /// on the command stack. > /// > [DllImport("PyRegCmd.dll", > CallingConvention=CallingConvention.Cdecl,CharSet = CharSet.Unicode, > EntryPoint = "?RegPyCmd@@YAXPB_W0HP6AXXZ at Z")] > public static extern void RegPyCmd( > string cmd_group, > string cmd_name, > Autodesk.AutoCAD.Runtime.CommandFlags cmd_flags, > [MarshalAs(UnmanagedType.FunctionPtr)] PyAcadCmd.CmdDelegate cmd_delegate); > > > public static void PythonRegister(string CommandName, > CmdDelegate FuncPointer, CommandFlags flags) > { > RegPyCmd("_pycmds", CommandName, flags, FuncPointer); > } > > //testing stuff > public static void testcommand() > { > Editor ed = > Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; > ed.WriteMessage("\ncb1 delegate seems to work!\n"); > } > [CommandMethod("regcmds")] > static public void test() // This method can have any name > { > CmdDelegate cb1 = new CmdDelegate(PyAcadCmd.testcommand); > PythonRegister("testcommand", cb1, CommandFlags.Session); > } > } > > > } > _______________________________________________ > 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 > From dinov at exchange.microsoft.com Thu Aug 30 18:19:41 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Thu, 30 Aug 2007 09:19:41 -0700 Subject: [IronPython] Hosting: Delegates from Ironpython to C# In-Reply-To: References: <7AD436E4270DD54A94238001769C2227BD9F666736@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <7AD436E4270DD54A94238001769C2227BD9F66674E@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Well at this point we've successfully created the delegate and passed it off to you so it's hard to tell what's going wrong here. Couple of suggestions on things to try and troubleshoot the issue: Instead of handing the delegate you get off to the P/Invoke call can you just turn around and invoke the delegate from C# code and successfully call back into the Python code? If that works can you do something like: class PythonDelegateWrapper { private CmdDelegate cmdDelegate; public PythonDelegateWrapper(CmdDelegate dlg) { cmdDelegate = dlg; } public void Invoke() { cmdDelegate(); } } And then pass "new CmdDelegate(new PythonDelegateWrapper(dlg).Invoke)" to the P/Invoke function? The reason why I'm proposing this is maybe there's a strange interaction between dynamic methods (which the Python delegate will be) and the P/Invoke call - this might help isolate the issue. And the final thing that might be interesting to try would be to make sure you keep the reference to the delegate alive during the lifetime of the call. In theory this should be happening for you automatically - but if the unmanaged side is going to hold onto this delegate for longer than the duration of the call you'll need to do this anyway. Given that you're still in the call this shouldn't be an issue but you could set the environment variable COMPlus_MDA=1 to enable CLR Managed Debugging Assistants to see if you get any warnings about that firing. I don't really believe this could be happening but it would be consistent w/ the exception you're getting. Those are my 1st two guesses as to what could be going wrong, hopefully one of them will be helpful :). -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Tim Riley Sent: Thursday, August 30, 2007 8:59 AM To: Discussion of IronPython Subject: Re: [IronPython] Hosting: Delegates from Ironpython to C# Dino: I was trying something similar to what you had posted and was getting an error. I also just tried the code you gave me with a minor correction to fix the CommandFlags part and received the error below. If it helps I have also added the C# code use to call the python file below the error if that will help at all. *********ERROR*********** Command: pyfile System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at PyAcadDotNet.PyAcadCmd.RegPyCmd(String cmd_group, String cmd_name, CommandFlags cmd_flags, CmdDelegate cmd_delegate) at PyAcadDotNet.PyAcadCmd.PythonRegister(String CommandName, CmdDelegate FuncPointer, CommandFlags flags) in C:\Documents and Settings\TJRiley\My Documents\pyacaddotnet\registercommand.cs:line 65 at PythonRegister##20(Object , Object , Object ) at IronPython.Runtime.Calls.CallTarget3.Invoke(Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.FastCallable3.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Calls.BuiltinFunction.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext context, Object func, Object arg0, Object arg1, Object arg2) at C:\Documents and Settings\TJRiley\My Documents\pyacaddotnet\Samples\commandmethod_test.py##22(ModuleScope ) at IronPython.Hosting.CompiledCodeDelegate.Invoke(ModuleScope moduleScope) at IronPython.Hosting.CompiledCode.Run(ModuleScope moduleScope) at IronPython.Hosting.CompiledCode.Execute(EngineModule engineModule, IDictionary`2 locals) at IronPython.Hosting.CompiledCode.Execute() at PyAcadDotNet.AcadInterface.pythonfile() in C:\Documents and Settings\TJRiley\My Documents\pyacaddotnet\PyAcadDotNet.cs:line 98 *********ERROR*********** *********CODE************** using System; using System.Collections; using System.Windows.Forms; using System.IO; using System.Text; using System.Runtime.InteropServices; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.EditorInput; using AcEd = Autodesk.AutoCAD.EditorInput; using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application; using IronPython.Hosting; namespace PyAcadDotNet { public class AcadInterface : IExtensionApplication { static internal AcEd.Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor; public delegate void TestDelegate(); public void Initialize() { ed.WriteMessage("\nPyAcad.NET Loaded Successfully...."); ed.WriteMessage("\ntype 'pyhelp' for commands...."); } public void Terminate() { this.Terminate(); } internal delegate void AddReference(object assembly); [CommandMethod("pyfile", CommandFlags.Session)] static public void pythonfile() { using (PythonEngine engine = new PythonEngine()) { using (AcadCommandLine myCommandLine = new AcadCommandLine()) { try { // Create a new instance of PythonEngine and set variables. engine.AddToPath(Environment.CurrentDirectory); // Send Stdout and Stderr to the AutoCAD command line. engine.SetStandardOutput(myCommandLine); engine.SetStandardError(myCommandLine); engine.Import("clr"); PyAcadCmd regcmds = new PyAcadCmd(); engine.Globals.Add("regcmds", regcmds); //lets load some AutoCAD assemblies. AddReference adr = engine.CreateMethod("clr.AddReference(assembly)"); adr(typeof(BlockTableRecord).Assembly); adr(typeof(Editor).Assembly); // Display an OpenFileDialog and run the script. OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Python files (*.py)|*.py|All files (*.*)|*.*"; ofd.ShowDialog(); // Run the file selected by the open file dialog box. //engine.ExecuteFile(ofd.FileName); CompiledCode cc = engine.CompileFile(ofd.FileName); cc.Execute(); } catch (System.Exception e) { ed.WriteMessage(e.ToString()); } } } } } // public class AcadCommandLine : Stream //Modified version of a class coded by Mike Stall. { public AcadCommandLine() { //constructor } #region unsupported Read + Seek members public override bool CanRead { get { return false; } } public override bool CanSeek { get { return false; } } public override bool CanWrite { get { return true; } } public override void Flush() { // } public override long Length { get { throw new NotSupportedException("Seek not supported"); } // can't seek } public override long Position { get { throw new NotSupportedException("Seek not supported"); // can't seek } set { throw new NotSupportedException("Seek not supported"); // can't seek } } public override int Read(byte[] buffer, int offset, int count) { throw new NotSupportedException("Reed not supported"); // can't read } public override long Seek(long offset, SeekOrigin origin) { throw new NotSupportedException("Seek not supported"); // can't seek } public override void SetLength(long value) { throw new NotSupportedException("Seek not supported"); // can't seek } #endregion public override void Write(byte[] buffer, int offset, int count) { try { // Very bad hack: Ignore single newline char. This is because we expect the newline is following // previous content and we already placed a newline on that. AcEd.Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor; if (count == 1 && buffer[offset] == '\n') return; StringBuilder sb = new StringBuilder(); while (count > 0) { char ch = (char)buffer[offset]; if (ch == '\n') { ed.WriteMessage(sb.ToString() + "\n"); sb.Length = 0; // reset. } else if (ch != '\r') { sb.Append(ch); } offset++; count--; } if (sb.Length > 0) ed.WriteMessage(sb.ToString() + "\n"); } catch (System.Exception e) { throw e; } } } } *********CODE************** On 8/30/07, Dino Viehland wrote: > I think you should be able to just pass a function object to PythonRegister and it should be converted into a delegate. For example: > > import clr > clr.AddReference('PyAcadDotNet') > from PyAcadDotNet import PyAcadCmd > > def foo(): > print 'hello world' > > PyAcadCmd.PythonRegister('some command', foo, CommandFlags.Whatever) > > Does that not work? > > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Tim Riley > Sent: Wednesday, August 29, 2007 7:10 PM > To: Discussion of IronPython > Subject: [IronPython] Hosting: Delegates from Ironpython to C# > > I'm embedding IronPython in a C# dll that is hosted inside a program > called AutoCAD. In order to register commands in AutoCAD from .NET I > need to P/Invoke a C function inside a .dll. I can do this fairly easy > from C# but I can't figure out the right way to call my C# wrapper > from IronPython to have it register the command. I have perused the > hosting docs for 1.1 and haven't been able to come up with a solution > that works. Here is my C# code. I either want to call the PyRegCmds > void or the PythonRegister void. Both of which expect a delegate.for > example if I had a python function like: > > def test1: > print "This is a test". > > I can't figure out how to map test to the delegate required in the code below. > Note: I can call this from C# fine. See :static public void test(). > > Can anyone give me any pointers? It would be greatly appreciated. > > > code: > > using System ; > using System.Runtime.InteropServices; > using Autodesk.AutoCAD.Runtime ; > using Autodesk.AutoCAD.EditorInput; > > namespace PyAcadDotNet > { > /// > /// PyAcadCmd Class: > /// Used to register commands on the AutoCAD command stack. > /// > public class PyAcadCmd > { > public PyAcadCmd() > { > } > public delegate void CmdDelegate(); > > /// > /// RegPyAcadCmd: > /// Registers a delegate (callback) with the AutoCAD command string > /// on the command stack. > /// > [DllImport("PyRegCmd.dll", > CallingConvention=CallingConvention.Cdecl,CharSet = CharSet.Unicode, > EntryPoint = "?RegPyCmd@@YAXPB_W0HP6AXXZ at Z")] > public static extern void RegPyCmd( > string cmd_group, > string cmd_name, > Autodesk.AutoCAD.Runtime.CommandFlags cmd_flags, > [MarshalAs(UnmanagedType.FunctionPtr)] PyAcadCmd.CmdDelegate cmd_delegate); > > > public static void PythonRegister(string CommandName, > CmdDelegate FuncPointer, CommandFlags flags) > { > RegPyCmd("_pycmds", CommandName, flags, FuncPointer); > } > > //testing stuff > public static void testcommand() > { > Editor ed = > Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; > ed.WriteMessage("\ncb1 delegate seems to work!\n"); > } > [CommandMethod("regcmds")] > static public void test() // This method can have any name > { > CmdDelegate cb1 = new CmdDelegate(PyAcadCmd.testcommand); > PythonRegister("testcommand", cb1, CommandFlags.Session); > } > } > > > } > _______________________________________________ > 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 From riltim at gmail.com Thu Aug 30 20:55:04 2007 From: riltim at gmail.com (Tim Riley) Date: Thu, 30 Aug 2007 14:55:04 -0400 Subject: [IronPython] Hosting: Delegates from Ironpython to C# In-Reply-To: <7AD436E4270DD54A94238001769C2227BD9F66674E@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <7AD436E4270DD54A94238001769C2227BD9F666736@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <7AD436E4270DD54A94238001769C2227BD9F66674E@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: Dino: I tried using the PythonDelegateWrapper you posted below with the same results. To make things easier I tried moving all my testing into a single C# file and have it run the code from C# instead of a compiling a python file. Below is the code. When I execute "regtest" in AutoCAD it fatal errors on me. I also added System.Environment.SetEnvironmentVariable("COMPlus_MDA", "1"); to the initialize of my code but it doesn't do anything for me. Any other ideas? ********code********* using System ; using System.Runtime.InteropServices; using Autodesk.AutoCAD.Runtime ; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using IronPython.Hosting; namespace PyAcadDotNet { /// /// PyAcadCmd Class: /// Used to register commands on the AutoCAD command stack. /// public class PyAcadCmd { public PyAcadCmd() { } public delegate void CmdDelegate(); internal delegate void AddReference(object assembly); /// /// RegPyAcadCmd: /// Registers a delegate (callback) with the AutoCAD command string /// on the command stack. /// [DllImport("PyRegCmd.dll", CallingConvention=CallingConvention.Cdecl,CharSet = CharSet.Unicode, EntryPoint = "?RegPyCmd@@YAXPB_W0HP6AXXZ at Z")] public static extern void RegPyCmd( string cmd_group, string cmd_name, Autodesk.AutoCAD.Runtime.CommandFlags cmd_flags, [MarshalAs(UnmanagedType.FunctionPtr)] CmdDelegate cmd_delegate); public static void PythonRegister(string CommandName, CmdDelegate FuncPointer, CommandFlags flags) { RegPyCmd("_pycmds", CommandName, flags, new CmdDelegate(new PythonDelegateWrapper(FuncPointer).Invoke)); } //testing stuff public static void testcommand() { Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; ed.WriteMessage("\ncb1 delegate seems to work!\n"); } [CommandMethod("regcmds")] static public void test() // This method can have any name { CmdDelegate cb1 = new CmdDelegate(PyAcadCmd.testcommand); PythonRegister("testcommand", cb1, CommandFlags.Session); } [CommandMethod("regtest", CommandFlags.Session)] static public void regtest() { PythonEngine engine = new PythonEngine(); engine.Import("clr"); AddReference adr = engine.CreateMethod("clr.AddReference(assembly)"); adr(typeof(BlockTableRecord).Assembly); adr(typeof(Editor).Assembly); CompiledCode cc = engine.Compile( @" import Autodesk.AutoCAD.Runtime import clr clr.AddReference('PyAcadDotNet') from PyAcadDotNet import PyAcadCmd def foo(): print 'hello world' PyAcadCmd.PythonRegister('pythontester', foo, Autodesk.AutoCAD.Runtime.CommandFlags.Session)"); cc.Execute(); } } class PythonDelegateWrapper { private PyAcadCmd.CmdDelegate cmdDelegate; public PythonDelegateWrapper(PyAcadCmd.CmdDelegate dlg) { cmdDelegate = dlg; } public void Invoke() { cmdDelegate(); } } } ********code********** On 8/30/07, Dino Viehland wrote: > Well at this point we've successfully created the delegate and passed it off to you so it's hard to tell what's going wrong here. Couple of suggestions on things to try and troubleshoot the issue: > Instead of handing the delegate you get off to the P/Invoke call can you just turn around and invoke the delegate from C# code and successfully call back into the Python code? > If that works can you do something like: > > class PythonDelegateWrapper { > private CmdDelegate cmdDelegate; > public PythonDelegateWrapper(CmdDelegate dlg) { > cmdDelegate = dlg; > } > > public void Invoke() { > cmdDelegate(); > } > } > > And then pass "new CmdDelegate(new PythonDelegateWrapper(dlg).Invoke)" to the P/Invoke function? > > The reason why I'm proposing this is maybe there's a strange interaction between dynamic methods (which the Python delegate will be) and the P/Invoke call - this might help isolate the issue. > > And the final thing that might be interesting to try would be to make sure you keep the reference to the delegate alive during the lifetime of the call. In theory this should be happening for you automatically - but if the unmanaged side is going to hold onto this delegate for longer than the duration of the call you'll need to do this anyway. Given that you're still in the call this shouldn't be an issue but you could set the environment variable COMPlus_MDA=1 to enable CLR Managed Debugging Assistants to see if you get any warnings about that firing. I don't really believe this could be happening but it would be consistent w/ the exception you're getting. > > Those are my 1st two guesses as to what could be going wrong, hopefully one of them will be helpful :). > > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Tim Riley > Sent: Thursday, August 30, 2007 8:59 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Hosting: Delegates from Ironpython to C# > > Dino: > > I was trying something similar to what you had posted and was getting > an error. I also just tried the code you gave me with a minor > correction to fix the CommandFlags part and received the error below. > If it helps I have also added the C# code use to call the python file > below the error if that will help at all. > > > *********ERROR*********** > Command: pyfile > System.AccessViolationException: Attempted to read or write protected memory. > This is often an indication that other memory is corrupt. > at PyAcadDotNet.PyAcadCmd.RegPyCmd(String cmd_group, String cmd_name, CommandFlags cmd_flags, CmdDelegate cmd_delegate) > at PyAcadDotNet.PyAcadCmd.PythonRegister(String CommandName, CmdDelegate FuncPointer, CommandFlags flags) in C:\Documents and Settings\TJRiley\My Documents\pyacaddotnet\registercommand.cs:line 65 > at PythonRegister##20(Object , Object , Object ) > at IronPython.Runtime.Calls.CallTarget3.Invoke(Object arg0, Object arg1, Object arg2) > at IronPython.Runtime.Calls.FastCallable3.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) > at IronPython.Runtime.Calls.BuiltinFunction.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) > at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext context, Object func, Object arg0, Object arg1, Object arg2) > at C:\Documents and Settings\TJRiley\My Documents\pyacaddotnet\Samples\commandmethod_test.py##22(ModuleScope ) > at IronPython.Hosting.CompiledCodeDelegate.Invoke(ModuleScope moduleScope) > at IronPython.Hosting.CompiledCode.Run(ModuleScope moduleScope) > at IronPython.Hosting.CompiledCode.Execute(EngineModule engineModule, IDictionary`2 locals) > at IronPython.Hosting.CompiledCode.Execute() > at PyAcadDotNet.AcadInterface.pythonfile() in C:\Documents and > Settings\TJRiley\My Documents\pyacaddotnet\PyAcadDotNet.cs:line 98 > *********ERROR*********** > > > *********CODE************** > using System; > using System.Collections; > using System.Windows.Forms; > using System.IO; > using System.Text; > using System.Runtime.InteropServices; > > using Autodesk.AutoCAD.ApplicationServices; > using Autodesk.AutoCAD.DatabaseServices; > using Autodesk.AutoCAD.Runtime; > using Autodesk.AutoCAD.EditorInput; > > using AcEd = Autodesk.AutoCAD.EditorInput; > using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application; > > using IronPython.Hosting; > > namespace PyAcadDotNet > { > public class AcadInterface : IExtensionApplication > { > static internal AcEd.Editor ed = > AcadApp.DocumentManager.MdiActiveDocument.Editor; > > public delegate void TestDelegate(); > > > public void Initialize() > { > ed.WriteMessage("\nPyAcad.NET Loaded Successfully...."); > ed.WriteMessage("\ntype 'pyhelp' for commands...."); > } > > public void Terminate() > { > this.Terminate(); > } > > internal delegate void AddReference(object assembly); > > [CommandMethod("pyfile", CommandFlags.Session)] > static public void pythonfile() > { > using (PythonEngine engine = new PythonEngine()) > { > using (AcadCommandLine myCommandLine = new AcadCommandLine()) > { > try > { > // Create a new instance of PythonEngine and set variables. > engine.AddToPath(Environment.CurrentDirectory); > // Send Stdout and Stderr to the AutoCAD command line. > engine.SetStandardOutput(myCommandLine); > engine.SetStandardError(myCommandLine); > engine.Import("clr"); > PyAcadCmd regcmds = new PyAcadCmd(); > engine.Globals.Add("regcmds", regcmds); > //lets load some AutoCAD assemblies. > AddReference adr = > engine.CreateMethod("clr.AddReference(assembly)"); > adr(typeof(BlockTableRecord).Assembly); > adr(typeof(Editor).Assembly); > > // Display an OpenFileDialog and run the script. > OpenFileDialog ofd = new OpenFileDialog(); > ofd.Filter = "Python files (*.py)|*.py|All files (*.*)|*.*"; > ofd.ShowDialog(); > > // Run the file selected by the open file dialog box. > //engine.ExecuteFile(ofd.FileName); > CompiledCode cc = engine.CompileFile(ofd.FileName); > cc.Execute(); > } > catch (System.Exception e) > { > ed.WriteMessage(e.ToString()); > } > } > } > } > } > > // > public class AcadCommandLine : Stream > //Modified version of a class coded by Mike Stall. > { > public AcadCommandLine() > { > //constructor > } > > #region unsupported Read + Seek members > public override bool CanRead > { > get { return false; } > } > > public override bool CanSeek > { > get { return false; } > } > > public override bool CanWrite > { > get { return true; } > } > > public override void Flush() > { > // > } > > public override long Length > { > get { throw new NotSupportedException("Seek not supported"); } > // can't seek > } > > public override long Position > { > get > { > throw new NotSupportedException("Seek not supported"); // can't seek > } > set > { > throw new NotSupportedException("Seek not supported"); // can't seek > } > } > > public override int Read(byte[] buffer, int offset, int count) > { > throw new NotSupportedException("Reed not supported"); // can't read > } > > public override long Seek(long offset, SeekOrigin origin) > { > throw new NotSupportedException("Seek not supported"); // can't seek > } > > public override void SetLength(long value) > { > throw new NotSupportedException("Seek not supported"); // can't seek > } > #endregion > > public override void Write(byte[] buffer, int offset, int count) > { > try > { > // Very bad hack: Ignore single newline char. This is because > we expect the newline is following > // previous content and we already placed a newline on that. > AcEd.Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor; > > if (count == 1 && buffer[offset] == '\n') > return; > > StringBuilder sb = new StringBuilder(); > while (count > 0) > { > char ch = (char)buffer[offset]; > if (ch == '\n') > { > ed.WriteMessage(sb.ToString() + "\n"); > sb.Length = 0; // reset. > } > else if (ch != '\r') > { > sb.Append(ch); > } > > offset++; > count--; > } > if (sb.Length > 0) > ed.WriteMessage(sb.ToString() + "\n"); > } > catch (System.Exception e) > { > throw e; > } > } > } > } > *********CODE************** > On 8/30/07, Dino Viehland wrote: > > I think you should be able to just pass a function object to PythonRegister and it should be converted into a delegate. For example: > > > > import clr > > clr.AddReference('PyAcadDotNet') > > from PyAcadDotNet import PyAcadCmd > > > > def foo(): > > print 'hello world' > > > > PyAcadCmd.PythonRegister('some command', foo, CommandFlags.Whatever) > > > > Does that not work? > > > > -----Original Message----- > > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Tim Riley > > Sent: Wednesday, August 29, 2007 7:10 PM > > To: Discussion of IronPython > > Subject: [IronPython] Hosting: Delegates from Ironpython to C# > > > > I'm embedding IronPython in a C# dll that is hosted inside a program > > called AutoCAD. In order to register commands in AutoCAD from .NET I > > need to P/Invoke a C function inside a .dll. I can do this fairly easy > > from C# but I can't figure out the right way to call my C# wrapper > > from IronPython to have it register the command. I have perused the > > hosting docs for 1.1 and haven't been able to come up with a solution > > that works. Here is my C# code. I either want to call the PyRegCmds > > void or the PythonRegister void. Both of which expect a delegate.for > > example if I had a python function like: > > > > def test1: > > print "This is a test". > > > > I can't figure out how to map test to the delegate required in the code below. > > Note: I can call this from C# fine. See :static public void test(). > > > > Can anyone give me any pointers? It would be greatly appreciated. > > > > > > code: > > > > using System ; > > using System.Runtime.InteropServices; > > using Autodesk.AutoCAD.Runtime ; > > using Autodesk.AutoCAD.EditorInput; > > > > namespace PyAcadDotNet > > { > > /// > > /// PyAcadCmd Class: > > /// Used to register commands on the AutoCAD command stack. > > /// > > public class PyAcadCmd > > { > > public PyAcadCmd() > > { > > } > > public delegate void CmdDelegate(); > > > > /// > > /// RegPyAcadCmd: > > /// Registers a delegate (callback) with the AutoCAD command string > > /// on the command stack. > > /// > > [DllImport("PyRegCmd.dll", > > CallingConvention=CallingConvention.Cdecl,CharSet = CharSet.Unicode, > > EntryPoint = "?RegPyCmd@@YAXPB_W0HP6AXXZ at Z")] > > public static extern void RegPyCmd( > > string cmd_group, > > string cmd_name, > > Autodesk.AutoCAD.Runtime.CommandFlags cmd_flags, > > [MarshalAs(UnmanagedType.FunctionPtr)] PyAcadCmd.CmdDelegate cmd_delegate); > > > > > > public static void PythonRegister(string CommandName, > > CmdDelegate FuncPointer, CommandFlags flags) > > { > > RegPyCmd("_pycmds", CommandName, flags, FuncPointer); > > } > > > > //testing stuff > > public static void testcommand() > > { > > Editor ed = > > Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; > > ed.WriteMessage("\ncb1 delegate seems to work!\n"); > > } > > [CommandMethod("regcmds")] > > static public void test() // This method can have any name > > { > > CmdDelegate cb1 = new CmdDelegate(PyAcadCmd.testcommand); > > PythonRegister("testcommand", cb1, CommandFlags.Session); > > } > > } > > > > > > } > > _______________________________________________ > > 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 > _______________________________________________ > Users mailing list > Users at lists.ironpython.com > http://lists.ironpython.com/listinfo.cgi/users-ironpython.com > From dinov at exchange.microsoft.com Thu Aug 30 21:29:56 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Thu, 30 Aug 2007 12:29:56 -0700 Subject: [IronPython] Hosting: Delegates from Ironpython to C# In-Reply-To: References: <7AD436E4270DD54A94238001769C2227BD9F666736@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <7AD436E4270DD54A94238001769C2227BD9F66674E@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <7AD436E4270DD54A94238001769C2227BD9F66683B@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Setting the env var at runtime won't help, you'll want to set it at a command prompt and start your app from the command prompt. One other tweak: public static void PythonRegister(string CommandName, CmdDelegate FuncPointer, CommandFlags flags) { PythonDelegateWrapper pdw = new PythonDelegateWrapper(FuncPointer)); RegPyCmd("_pycmds", CommandName, flags, new CmdDelegate(pdw.Invoke); GC.KeepAlive(pdw); } Which will ensure it's not a delegate getting collected issue. If that doesn't work then we'll need to go into unmanaged debugging territory w/ windbg/cdb/ntsd :). -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Tim Riley Sent: Thursday, August 30, 2007 11:55 AM To: Discussion of IronPython Subject: Re: [IronPython] Hosting: Delegates from Ironpython to C# Dino: I tried using the PythonDelegateWrapper you posted below with the same results. To make things easier I tried moving all my testing into a single C# file and have it run the code from C# instead of a compiling a python file. Below is the code. When I execute "regtest" in AutoCAD it fatal errors on me. I also added System.Environment.SetEnvironmentVariable("COMPlus_MDA", "1"); to the initialize of my code but it doesn't do anything for me. Any other ideas? ********code********* using System ; using System.Runtime.InteropServices; using Autodesk.AutoCAD.Runtime ; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using IronPython.Hosting; namespace PyAcadDotNet { /// /// PyAcadCmd Class: /// Used to register commands on the AutoCAD command stack. /// public class PyAcadCmd { public PyAcadCmd() { } public delegate void CmdDelegate(); internal delegate void AddReference(object assembly); /// /// RegPyAcadCmd: /// Registers a delegate (callback) with the AutoCAD command string /// on the command stack. /// [DllImport("PyRegCmd.dll", CallingConvention=CallingConvention.Cdecl,CharSet = CharSet.Unicode, EntryPoint = "?RegPyCmd@@YAXPB_W0HP6AXXZ at Z")] public static extern void RegPyCmd( string cmd_group, string cmd_name, Autodesk.AutoCAD.Runtime.CommandFlags cmd_flags, [MarshalAs(UnmanagedType.FunctionPtr)] CmdDelegate cmd_delegate); public static void PythonRegister(string CommandName, CmdDelegate FuncPointer, CommandFlags flags) { RegPyCmd("_pycmds", CommandName, flags, new CmdDelegate(new PythonDelegateWrapper(FuncPointer).Invoke)); } //testing stuff public static void testcommand() { Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; ed.WriteMessage("\ncb1 delegate seems to work!\n"); } [CommandMethod("regcmds")] static public void test() // This method can have any name { CmdDelegate cb1 = new CmdDelegate(PyAcadCmd.testcommand); PythonRegister("testcommand", cb1, CommandFlags.Session); } [CommandMethod("regtest", CommandFlags.Session)] static public void regtest() { PythonEngine engine = new PythonEngine(); engine.Import("clr"); AddReference adr = engine.CreateMethod("clr.AddReference(assembly)"); adr(typeof(BlockTableRecord).Assembly); adr(typeof(Editor).Assembly); CompiledCode cc = engine.Compile( @" import Autodesk.AutoCAD.Runtime import clr clr.AddReference('PyAcadDotNet') from PyAcadDotNet import PyAcadCmd def foo(): print 'hello world' PyAcadCmd.PythonRegister('pythontester', foo, Autodesk.AutoCAD.Runtime.CommandFlags.Session)"); cc.Execute(); } } class PythonDelegateWrapper { private PyAcadCmd.CmdDelegate cmdDelegate; public PythonDelegateWrapper(PyAcadCmd.CmdDelegate dlg) { cmdDelegate = dlg; } public void Invoke() { cmdDelegate(); } } } ********code********** On 8/30/07, Dino Viehland wrote: > Well at this point we've successfully created the delegate and passed it off to you so it's hard to tell what's going wrong here. Couple of suggestions on things to try and troubleshoot the issue: > Instead of handing the delegate you get off to the P/Invoke call can you just turn around and invoke the delegate from C# code and successfully call back into the Python code? > If that works can you do something like: > > class PythonDelegateWrapper { > private CmdDelegate cmdDelegate; > public PythonDelegateWrapper(CmdDelegate dlg) { > cmdDelegate = dlg; > } > > public void Invoke() { > cmdDelegate(); > } > } > > And then pass "new CmdDelegate(new PythonDelegateWrapper(dlg).Invoke)" to the P/Invoke function? > > The reason why I'm proposing this is maybe there's a strange interaction between dynamic methods (which the Python delegate will be) and the P/Invoke call - this might help isolate the issue. > > And the final thing that might be interesting to try would be to make sure you keep the reference to the delegate alive during the lifetime of the call. In theory this should be happening for you automatically - but if the unmanaged side is going to hold onto this delegate for longer than the duration of the call you'll need to do this anyway. Given that you're still in the call this shouldn't be an issue but you could set the environment variable COMPlus_MDA=1 to enable CLR Managed Debugging Assistants to see if you get any warnings about that firing. I don't really believe this could be happening but it would be consistent w/ the exception you're getting. > > Those are my 1st two guesses as to what could be going wrong, hopefully one of them will be helpful :). > > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Tim Riley > Sent: Thursday, August 30, 2007 8:59 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Hosting: Delegates from Ironpython to C# > > Dino: > > I was trying something similar to what you had posted and was getting > an error. I also just tried the code you gave me with a minor > correction to fix the CommandFlags part and received the error below. > If it helps I have also added the C# code use to call the python file > below the error if that will help at all. > > > *********ERROR*********** > Command: pyfile > System.AccessViolationException: Attempted to read or write protected memory. > This is often an indication that other memory is corrupt. > at PyAcadDotNet.PyAcadCmd.RegPyCmd(String cmd_group, String cmd_name, CommandFlags cmd_flags, CmdDelegate cmd_delegate) > at PyAcadDotNet.PyAcadCmd.PythonRegister(String CommandName, CmdDelegate FuncPointer, CommandFlags flags) in C:\Documents and Settings\TJRiley\My Documents\pyacaddotnet\registercommand.cs:line 65 > at PythonRegister##20(Object , Object , Object ) > at IronPython.Runtime.Calls.CallTarget3.Invoke(Object arg0, Object arg1, Object arg2) > at IronPython.Runtime.Calls.FastCallable3.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) > at IronPython.Runtime.Calls.BuiltinFunction.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) > at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext context, Object func, Object arg0, Object arg1, Object arg2) > at C:\Documents and Settings\TJRiley\My Documents\pyacaddotnet\Samples\commandmethod_test.py##22(ModuleScope ) > at IronPython.Hosting.CompiledCodeDelegate.Invoke(ModuleScope moduleScope) > at IronPython.Hosting.CompiledCode.Run(ModuleScope moduleScope) > at IronPython.Hosting.CompiledCode.Execute(EngineModule engineModule, IDictionary`2 locals) > at IronPython.Hosting.CompiledCode.Execute() > at PyAcadDotNet.AcadInterface.pythonfile() in C:\Documents and > Settings\TJRiley\My Documents\pyacaddotnet\PyAcadDotNet.cs:line 98 > *********ERROR*********** > > > *********CODE************** > using System; > using System.Collections; > using System.Windows.Forms; > using System.IO; > using System.Text; > using System.Runtime.InteropServices; > > using Autodesk.AutoCAD.ApplicationServices; > using Autodesk.AutoCAD.DatabaseServices; > using Autodesk.AutoCAD.Runtime; > using Autodesk.AutoCAD.EditorInput; > > using AcEd = Autodesk.AutoCAD.EditorInput; > using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application; > > using IronPython.Hosting; > > namespace PyAcadDotNet > { > public class AcadInterface : IExtensionApplication > { > static internal AcEd.Editor ed = > AcadApp.DocumentManager.MdiActiveDocument.Editor; > > public delegate void TestDelegate(); > > > public void Initialize() > { > ed.WriteMessage("\nPyAcad.NET Loaded Successfully...."); > ed.WriteMessage("\ntype 'pyhelp' for commands...."); > } > > public void Terminate() > { > this.Terminate(); > } > > internal delegate void AddReference(object assembly); > > [CommandMethod("pyfile", CommandFlags.Session)] > static public void pythonfile() > { > using (PythonEngine engine = new PythonEngine()) > { > using (AcadCommandLine myCommandLine = new AcadCommandLine()) > { > try > { > // Create a new instance of PythonEngine and set variables. > engine.AddToPath(Environment.CurrentDirectory); > // Send Stdout and Stderr to the AutoCAD command line. > engine.SetStandardOutput(myCommandLine); > engine.SetStandardError(myCommandLine); > engine.Import("clr"); > PyAcadCmd regcmds = new PyAcadCmd(); > engine.Globals.Add("regcmds", regcmds); > //lets load some AutoCAD assemblies. > AddReference adr = > engine.CreateMethod("clr.AddReference(assembly)"); > adr(typeof(BlockTableRecord).Assembly); > adr(typeof(Editor).Assembly); > > // Display an OpenFileDialog and run the script. > OpenFileDialog ofd = new OpenFileDialog(); > ofd.Filter = "Python files (*.py)|*.py|All files (*.*)|*.*"; > ofd.ShowDialog(); > > // Run the file selected by the open file dialog box. > //engine.ExecuteFile(ofd.FileName); > CompiledCode cc = engine.CompileFile(ofd.FileName); > cc.Execute(); > } > catch (System.Exception e) > { > ed.WriteMessage(e.ToString()); > } > } > } > } > } > > // > public class AcadCommandLine : Stream > //Modified version of a class coded by Mike Stall. > { > public AcadCommandLine() > { > //constructor > } > > #region unsupported Read + Seek members > public override bool CanRead > { > get { return false; } > } > > public override bool CanSeek > { > get { return false; } > } > > public override bool CanWrite > { > get { return true; } > } > > public override void Flush() > { > // > } > > public override long Length > { > get { throw new NotSupportedException("Seek not supported"); } > // can't seek > } > > public override long Position > { > get > { > throw new NotSupportedException("Seek not supported"); // can't seek > } > set > { > throw new NotSupportedException("Seek not supported"); // can't seek > } > } > > public override int Read(byte[] buffer, int offset, int count) > { > throw new NotSupportedException("Reed not supported"); // can't read > } > > public override long Seek(long offset, SeekOrigin origin) > { > throw new NotSupportedException("Seek not supported"); // can't seek > } > > public override void SetLength(long value) > { > throw new NotSupportedException("Seek not supported"); // can't seek > } > #endregion > > public override void Write(byte[] buffer, int offset, int count) > { > try > { > // Very bad hack: Ignore single newline char. This is because > we expect the newline is following > // previous content and we already placed a newline on that. > AcEd.Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor; > > if (count == 1 && buffer[offset] == '\n') > return; > > StringBuilder sb = new StringBuilder(); > while (count > 0) > { > char ch = (char)buffer[offset]; > if (ch == '\n') > { > ed.WriteMessage(sb.ToString() + "\n"); > sb.Length = 0; // reset. > } > else if (ch != '\r') > { > sb.Append(ch); > } > > offset++; > count--; > } > if (sb.Length > 0) > ed.WriteMessage(sb.ToString() + "\n"); > } > catch (System.Exception e) > { > throw e; > } > } > } > } > *********CODE************** > On 8/30/07, Dino Viehland wrote: > > I think you should be able to just pass a function object to PythonRegister and it should be converted into a delegate. For example: > > > > import clr > > clr.AddReference('PyAcadDotNet') > > from PyAcadDotNet import PyAcadCmd > > > > def foo(): > > print 'hello world' > > > > PyAcadCmd.PythonRegister('some command', foo, CommandFlags.Whatever) > > > > Does that not work? > > > > -----Original Message----- > > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Tim Riley > > Sent: Wednesday, August 29, 2007 7:10 PM > > To: Discussion of IronPython > > Subject: [IronPython] Hosting: Delegates from Ironpython to C# > > > > I'm embedding IronPython in a C# dll that is hosted inside a program > > called AutoCAD. In order to register commands in AutoCAD from .NET I > > need to P/Invoke a C function inside a .dll. I can do this fairly easy > > from C# but I can't figure out the right way to call my C# wrapper > > from IronPython to have it register the command. I have perused the > > hosting docs for 1.1 and haven't been able to come up with a solution > > that works. Here is my C# code. I either want to call the PyRegCmds > > void or the PythonRegister void. Both of which expect a delegate.for > > example if I had a python function like: > > > > def test1: > > print "This is a test". > > > > I can't figure out how to map test to the delegate required in the code below. > > Note: I can call this from C# fine. See :static public void test(). > > > > Can anyone give me any pointers? It would be greatly appreciated. > > > > > > code: > > > > using System ; > > using System.Runtime.InteropServices; > > using Autodesk.AutoCAD.Runtime ; > > using Autodesk.AutoCAD.EditorInput; > > > > namespace PyAcadDotNet > > { > > /// > > /// PyAcadCmd Class: > > /// Used to register commands on the AutoCAD command stack. > > /// > > public class PyAcadCmd > > { > > public PyAcadCmd() > > { > > } > > public delegate void CmdDelegate(); > > > > /// > > /// RegPyAcadCmd: > > /// Registers a delegate (callback) with the AutoCAD command string > > /// on the command stack. > > /// > > [DllImport("PyRegCmd.dll", > > CallingConvention=CallingConvention.Cdecl,CharSet = CharSet.Unicode, > > EntryPoint = "?RegPyCmd@@YAXPB_W0HP6AXXZ at Z")] > > public static extern void RegPyCmd( > > string cmd_group, > > string cmd_name, > > Autodesk.AutoCAD.Runtime.CommandFlags cmd_flags, > > [MarshalAs(UnmanagedType.FunctionPtr)] PyAcadCmd.CmdDelegate cmd_delegate); > > > > > > public static void PythonRegister(string CommandName, > > CmdDelegate FuncPointer, CommandFlags flags) > > { > > RegPyCmd("_pycmds", CommandName, flags, FuncPointer); > > } > > > > //testing stuff > > public static void testcommand() > > { > > Editor ed = > > Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; > > ed.WriteMessage("\ncb1 delegate seems to work!\n"); > > } > > [CommandMethod("regcmds")] > > static public void test() // This method can have any name > > { > > CmdDelegate cb1 = new CmdDelegate(PyAcadCmd.testcommand); > > PythonRegister("testcommand", cb1, CommandFlags.Session); > > } > > } > > > > > > } > > _______________________________________________ > > 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 > _______________________________________________ > 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 From riltim at gmail.com Thu Aug 30 21:49:30 2007 From: riltim at gmail.com (Tim Riley) Date: Thu, 30 Aug 2007 15:49:30 -0400 Subject: [IronPython] Hosting: Delegates from Ironpython to C# In-Reply-To: <7AD436E4270DD54A94238001769C2227BD9F66683B@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <7AD436E4270DD54A94238001769C2227BD9F666736@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <7AD436E4270DD54A94238001769C2227BD9F66674E@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <7AD436E4270DD54A94238001769C2227BD9F66683B@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: Dino: I revised the code to what you suggested and still no luck. Is there any way I can set the environment variable other than via the command prompt? My application is hosted inside another application and I can't set the variable from there. Tim On 8/30/07, Dino Viehland wrote: > Setting the env var at runtime won't help, you'll want to set it at a command prompt and start your app from the command prompt. One other tweak: > > public static void PythonRegister(string CommandName, > CmdDelegate FuncPointer, CommandFlags flags) > { > PythonDelegateWrapper pdw = new PythonDelegateWrapper(FuncPointer)); > RegPyCmd("_pycmds", CommandName, flags, new > CmdDelegate(pdw.Invoke); > GC.KeepAlive(pdw); > } > > Which will ensure it's not a delegate getting collected issue. > > If that doesn't work then we'll need to go into unmanaged debugging territory w/ windbg/cdb/ntsd :). > > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Tim Riley > Sent: Thursday, August 30, 2007 11:55 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Hosting: Delegates from Ironpython to C# > > Dino: > > I tried using the PythonDelegateWrapper you posted below with the same > results. To make things easier I tried moving all my testing into a > single C# file and have it run the code from C# instead of a compiling > a python file. Below is the code. When I execute "regtest" in AutoCAD > it fatal errors on me. I also added > System.Environment.SetEnvironmentVariable("COMPlus_MDA", "1"); to the > initialize of my code but it doesn't do anything for me. Any other > ideas? > > ********code********* > using System ; > using System.Runtime.InteropServices; > using Autodesk.AutoCAD.Runtime ; > using Autodesk.AutoCAD.EditorInput; > using Autodesk.AutoCAD.ApplicationServices; > using Autodesk.AutoCAD.DatabaseServices; > > using IronPython.Hosting; > > namespace PyAcadDotNet > { > /// > /// PyAcadCmd Class: > /// Used to register commands on the AutoCAD command stack. > /// > public class PyAcadCmd > { > public PyAcadCmd() > { > } > public delegate void CmdDelegate(); > internal delegate void AddReference(object assembly); > > /// > /// RegPyAcadCmd: > /// Registers a delegate (callback) with the AutoCAD command string > /// on the command stack. > /// > [DllImport("PyRegCmd.dll", > CallingConvention=CallingConvention.Cdecl,CharSet = CharSet.Unicode, > EntryPoint = "?RegPyCmd@@YAXPB_W0HP6AXXZ at Z")] > public static extern void RegPyCmd( > string cmd_group, > string cmd_name, > Autodesk.AutoCAD.Runtime.CommandFlags cmd_flags, > [MarshalAs(UnmanagedType.FunctionPtr)] CmdDelegate cmd_delegate); > > > public static void PythonRegister(string CommandName, > CmdDelegate FuncPointer, CommandFlags flags) > { > RegPyCmd("_pycmds", CommandName, flags, new > CmdDelegate(new PythonDelegateWrapper(FuncPointer).Invoke)); > } > > //testing stuff > public static void testcommand() > { > Editor ed = > Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; > ed.WriteMessage("\ncb1 delegate seems to work!\n"); > } > [CommandMethod("regcmds")] > static public void test() // This method can have any name > { > CmdDelegate cb1 = new CmdDelegate(PyAcadCmd.testcommand); > PythonRegister("testcommand", cb1, CommandFlags.Session); > } > [CommandMethod("regtest", CommandFlags.Session)] > static public void regtest() > { > PythonEngine engine = new PythonEngine(); > engine.Import("clr"); > AddReference adr = > engine.CreateMethod("clr.AddReference(assembly)"); > adr(typeof(BlockTableRecord).Assembly); > adr(typeof(Editor).Assembly); > CompiledCode cc = engine.Compile( > @" > import Autodesk.AutoCAD.Runtime > import clr > clr.AddReference('PyAcadDotNet') > from PyAcadDotNet import PyAcadCmd > def foo(): > print 'hello world' > PyAcadCmd.PythonRegister('pythontester', foo, > Autodesk.AutoCAD.Runtime.CommandFlags.Session)"); > cc.Execute(); > } > } > > class PythonDelegateWrapper > { > private PyAcadCmd.CmdDelegate cmdDelegate; > public PythonDelegateWrapper(PyAcadCmd.CmdDelegate dlg) > { > cmdDelegate = dlg; > } > public void Invoke() > { > cmdDelegate(); > } > } > } > ********code********** > > > > On 8/30/07, Dino Viehland wrote: > > Well at this point we've successfully created the delegate and passed it off to you so it's hard to tell what's going wrong here. Couple of suggestions on things to try and troubleshoot the issue: > > Instead of handing the delegate you get off to the P/Invoke call can you just turn around and invoke the delegate from C# code and successfully call back into the Python code? > > If that works can you do something like: > > > > class PythonDelegateWrapper { > > private CmdDelegate cmdDelegate; > > public PythonDelegateWrapper(CmdDelegate dlg) { > > cmdDelegate = dlg; > > } > > > > public void Invoke() { > > cmdDelegate(); > > } > > } > > > > And then pass "new CmdDelegate(new PythonDelegateWrapper(dlg).Invoke)" to the P/Invoke function? > > > > The reason why I'm proposing this is maybe there's a strange interaction between dynamic methods (which the Python delegate will be) and the P/Invoke call - this might help isolate the issue. > > > > And the final thing that might be interesting to try would be to make sure you keep the reference to the delegate alive during the lifetime of the call. In theory this should be happening for you automatically - but if the unmanaged side is going to hold onto this delegate for longer than the duration of the call you'll need to do this anyway. Given that you're still in the call this shouldn't be an issue but you could set the environment variable COMPlus_MDA=1 to enable CLR Managed Debugging Assistants to see if you get any warnings about that firing. I don't really believe this could be happening but it would be consistent w/ the exception you're getting. > > > > Those are my 1st two guesses as to what could be going wrong, hopefully one of them will be helpful :). > > > > -----Original Message----- > > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Tim Riley > > Sent: Thursday, August 30, 2007 8:59 AM > > To: Discussion of IronPython > > Subject: Re: [IronPython] Hosting: Delegates from Ironpython to C# > > > > Dino: > > > > I was trying something similar to what you had posted and was getting > > an error. I also just tried the code you gave me with a minor > > correction to fix the CommandFlags part and received the error below. > > If it helps I have also added the C# code use to call the python file > > below the error if that will help at all. > > > > > > *********ERROR*********** > > Command: pyfile > > System.AccessViolationException: Attempted to read or write protected memory. > > This is often an indication that other memory is corrupt. > > at PyAcadDotNet.PyAcadCmd.RegPyCmd(String cmd_group, String cmd_name, CommandFlags cmd_flags, CmdDelegate cmd_delegate) > > at PyAcadDotNet.PyAcadCmd.PythonRegister(String CommandName, CmdDelegate FuncPointer, CommandFlags flags) in C:\Documents and Settings\TJRiley\My Documents\pyacaddotnet\registercommand.cs:line 65 > > at PythonRegister##20(Object , Object , Object ) > > at IronPython.Runtime.Calls.CallTarget3.Invoke(Object arg0, Object arg1, Object arg2) > > at IronPython.Runtime.Calls.FastCallable3.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) > > at IronPython.Runtime.Calls.BuiltinFunction.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) > > at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext context, Object func, Object arg0, Object arg1, Object arg2) > > at C:\Documents and Settings\TJRiley\My Documents\pyacaddotnet\Samples\commandmethod_test.py##22(ModuleScope ) > > at IronPython.Hosting.CompiledCodeDelegate.Invoke(ModuleScope moduleScope) > > at IronPython.Hosting.CompiledCode.Run(ModuleScope moduleScope) > > at IronPython.Hosting.CompiledCode.Execute(EngineModule engineModule, IDictionary`2 locals) > > at IronPython.Hosting.CompiledCode.Execute() > > at PyAcadDotNet.AcadInterface.pythonfile() in C:\Documents and > > Settings\TJRiley\My Documents\pyacaddotnet\PyAcadDotNet.cs:line 98 > > *********ERROR*********** > > > > > > *********CODE************** > > using System; > > using System.Collections; > > using System.Windows.Forms; > > using System.IO; > > using System.Text; > > using System.Runtime.InteropServices; > > > > using Autodesk.AutoCAD.ApplicationServices; > > using Autodesk.AutoCAD.DatabaseServices; > > using Autodesk.AutoCAD.Runtime; > > using Autodesk.AutoCAD.EditorInput; > > > > using AcEd = Autodesk.AutoCAD.EditorInput; > > using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application; > > > > using IronPython.Hosting; > > > > namespace PyAcadDotNet > > { > > public class AcadInterface : IExtensionApplication > > { > > static internal AcEd.Editor ed = > > AcadApp.DocumentManager.MdiActiveDocument.Editor; > > > > public delegate void TestDelegate(); > > > > > > public void Initialize() > > { > > ed.WriteMessage("\nPyAcad.NET Loaded Successfully...."); > > ed.WriteMessage("\ntype 'pyhelp' for commands...."); > > } > > > > public void Terminate() > > { > > this.Terminate(); > > } > > > > internal delegate void AddReference(object assembly); > > > > [CommandMethod("pyfile", CommandFlags.Session)] > > static public void pythonfile() > > { > > using (PythonEngine engine = new PythonEngine()) > > { > > using (AcadCommandLine myCommandLine = new AcadCommandLine()) > > { > > try > > { > > // Create a new instance of PythonEngine and set variables. > > engine.AddToPath(Environment.CurrentDirectory); > > // Send Stdout and Stderr to the AutoCAD command line. > > engine.SetStandardOutput(myCommandLine); > > engine.SetStandardError(myCommandLine); > > engine.Import("clr"); > > PyAcadCmd regcmds = new PyAcadCmd(); > > engine.Globals.Add("regcmds", regcmds); > > //lets load some AutoCAD assemblies. > > AddReference adr = > > engine.CreateMethod("clr.AddReference(assembly)"); > > adr(typeof(BlockTableRecord).Assembly); > > adr(typeof(Editor).Assembly); > > > > // Display an OpenFileDialog and run the script. > > OpenFileDialog ofd = new OpenFileDialog(); > > ofd.Filter = "Python files (*.py)|*.py|All files (*.*)|*.*"; > > ofd.ShowDialog(); > > > > // Run the file selected by the open file dialog box. > > //engine.ExecuteFile(ofd.FileName); > > CompiledCode cc = engine.CompileFile(ofd.FileName); > > cc.Execute(); > > } > > catch (System.Exception e) > > { > > ed.WriteMessage(e.ToString()); > > } > > } > > } > > } > > } > > > > // > > public class AcadCommandLine : Stream > > //Modified version of a class coded by Mike Stall. > > { > > public AcadCommandLine() > > { > > //constructor > > } > > > > #region unsupported Read + Seek members > > public override bool CanRead > > { > > get { return false; } > > } > > > > public override bool CanSeek > > { > > get { return false; } > > } > > > > public override bool CanWrite > > { > > get { return true; } > > } > > > > public override void Flush() > > { > > // > > } > > > > public override long Length > > { > > get { throw new NotSupportedException("Seek not supported"); } > > // can't seek > > } > > > > public override long Position > > { > > get > > { > > throw new NotSupportedException("Seek not supported"); // can't seek > > } > > set > > { > > throw new NotSupportedException("Seek not supported"); // can't seek > > } > > } > > > > public override int Read(byte[] buffer, int offset, int count) > > { > > throw new NotSupportedException("Reed not supported"); // can't read > > } > > > > public override long Seek(long offset, SeekOrigin origin) > > { > > throw new NotSupportedException("Seek not supported"); // can't seek > > } > > > > public override void SetLength(long value) > > { > > throw new NotSupportedException("Seek not supported"); // can't seek > > } > > #endregion > > > > public override void Write(byte[] buffer, int offset, int count) > > { > > try > > { > > // Very bad hack: Ignore single newline char. This is because > > we expect the newline is following > > // previous content and we already placed a newline on that. > > AcEd.Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor; > > > > if (count == 1 && buffer[offset] == '\n') > > return; > > > > StringBuilder sb = new StringBuilder(); > > while (count > 0) > > { > > char ch = (char)buffer[offset]; > > if (ch == '\n') > > { > > ed.WriteMessage(sb.ToString() + "\n"); > > sb.Length = 0; // reset. > > } > > else if (ch != '\r') > > { > > sb.Append(ch); > > } > > > > offset++; > > count--; > > } > > if (sb.Length > 0) > > ed.WriteMessage(sb.ToString() + "\n"); > > } > > catch (System.Exception e) > > { > > throw e; > > } > > } > > } > > } > > *********CODE************** > > On 8/30/07, Dino Viehland wrote: > > > I think you should be able to just pass a function object to PythonRegister and it should be converted into a delegate. For example: > > > > > > import clr > > > clr.AddReference('PyAcadDotNet') > > > from PyAcadDotNet import PyAcadCmd > > > > > > def foo(): > > > print 'hello world' > > > > > > PyAcadCmd.PythonRegister('some command', foo, CommandFlags.Whatever) > > > > > > Does that not work? > > > > > > -----Original Message----- > > > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Tim Riley > > > Sent: Wednesday, August 29, 2007 7:10 PM > > > To: Discussion of IronPython > > > Subject: [IronPython] Hosting: Delegates from Ironpython to C# > > > > > > I'm embedding IronPython in a C# dll that is hosted inside a program > > > called AutoCAD. In order to register commands in AutoCAD from .NET I > > > need to P/Invoke a C function inside a .dll. I can do this fairly easy > > > from C# but I can't figure out the right way to call my C# wrapper > > > from IronPython to have it register the command. I have perused the > > > hosting docs for 1.1 and haven't been able to come up with a solution > > > that works. Here is my C# code. I either want to call the PyRegCmds > > > void or the PythonRegister void. Both of which expect a delegate.for > > > example if I had a python function like: > > > > > > def test1: > > > print "This is a test". > > > > > > I can't figure out how to map test to the delegate required in the code below. > > > Note: I can call this from C# fine. See :static public void test(). > > > > > > Can anyone give me any pointers? It would be greatly appreciated. > > > > > > > > > code: > > > > > > using System ; > > > using System.Runtime.InteropServices; > > > using Autodesk.AutoCAD.Runtime ; > > > using Autodesk.AutoCAD.EditorInput; > > > > > > namespace PyAcadDotNet > > > { > > > /// > > > /// PyAcadCmd Class: > > > /// Used to register commands on the AutoCAD command stack. > > > /// > > > public class PyAcadCmd > > > { > > > public PyAcadCmd() > > > { > > > } > > > public delegate void CmdDelegate(); > > > > > > /// > > > /// RegPyAcadCmd: > > > /// Registers a delegate (callback) with the AutoCAD command string > > > /// on the command stack. > > > /// > > > [DllImport("PyRegCmd.dll", > > > CallingConvention=CallingConvention.Cdecl,CharSet = CharSet.Unicode, > > > EntryPoint = "?RegPyCmd@@YAXPB_W0HP6AXXZ at Z")] > > > public static extern void RegPyCmd( > > > string cmd_group, > > > string cmd_name, > > > Autodesk.AutoCAD.Runtime.CommandFlags cmd_flags, > > > [MarshalAs(UnmanagedType.FunctionPtr)] PyAcadCmd.CmdDelegate cmd_delegate); > > > > > > > > > public static void PythonRegister(string CommandName, > > > CmdDelegate FuncPointer, CommandFlags flags) > > > { > > > RegPyCmd("_pycmds", CommandName, flags, FuncPointer); > > > } > > > > > > //testing stuff > > > public static void testcommand() > > > { > > > Editor ed = > > > Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; > > > ed.WriteMessage("\ncb1 delegate seems to work!\n"); > > > } > > > [CommandMethod("regcmds")] > > > static public void test() // This method can have any name > > > { > > > CmdDelegate cb1 = new CmdDelegate(PyAcadCmd.testcommand); > > > PythonRegister("testcommand", cb1, CommandFlags.Session); > > > } > > > } > > > > > > > > > } > > > _______________________________________________ > > > 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 > > _______________________________________________ > > 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 > From dinov at exchange.microsoft.com Thu Aug 30 21:55:42 2007 From: dinov at exchange.microsoft.com (Dino Viehland) Date: Thu, 30 Aug 2007 12:55:42 -0700 Subject: [IronPython] Hosting: Delegates from Ironpython to C# In-Reply-To: References: <7AD436E4270DD54A94238001769C2227BD9F666736@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <7AD436E4270DD54A94238001769C2227BD9F66674E@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <7AD436E4270DD54A94238001769C2227BD9F66683B@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: <7AD436E4270DD54A94238001769C2227BD9F66684E@DF-GRTDANE-MSG.exchange.corp.microsoft.com> You can set it in the registry instead: HKLM\Software\Microsoft\.NETFramework And set MDA="1" This website http://msdn2.microsoft.com/en-us/library/d21c150d.aspx has a reg file you can use to do it. This will enable MDAs globally for all managed processes on your machine so you'll want to turn it off when you're done. -----Original Message----- From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Tim Riley Sent: Thursday, August 30, 2007 12:50 PM To: Discussion of IronPython Subject: Re: [IronPython] Hosting: Delegates from Ironpython to C# Dino: I revised the code to what you suggested and still no luck. Is there any way I can set the environment variable other than via the command prompt? My application is hosted inside another application and I can't set the variable from there. Tim On 8/30/07, Dino Viehland wrote: > Setting the env var at runtime won't help, you'll want to set it at a command prompt and start your app from the command prompt. One other tweak: > > public static void PythonRegister(string CommandName, > CmdDelegate FuncPointer, CommandFlags flags) > { > PythonDelegateWrapper pdw = new PythonDelegateWrapper(FuncPointer)); > RegPyCmd("_pycmds", CommandName, flags, new > CmdDelegate(pdw.Invoke); > GC.KeepAlive(pdw); > } > > Which will ensure it's not a delegate getting collected issue. > > If that doesn't work then we'll need to go into unmanaged debugging territory w/ windbg/cdb/ntsd :). > > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Tim Riley > Sent: Thursday, August 30, 2007 11:55 AM > To: Discussion of IronPython > Subject: Re: [IronPython] Hosting: Delegates from Ironpython to C# > > Dino: > > I tried using the PythonDelegateWrapper you posted below with the same > results. To make things easier I tried moving all my testing into a > single C# file and have it run the code from C# instead of a compiling > a python file. Below is the code. When I execute "regtest" in AutoCAD > it fatal errors on me. I also added > System.Environment.SetEnvironmentVariable("COMPlus_MDA", "1"); to the > initialize of my code but it doesn't do anything for me. Any other > ideas? > > ********code********* > using System ; > using System.Runtime.InteropServices; > using Autodesk.AutoCAD.Runtime ; > using Autodesk.AutoCAD.EditorInput; > using Autodesk.AutoCAD.ApplicationServices; > using Autodesk.AutoCAD.DatabaseServices; > > using IronPython.Hosting; > > namespace PyAcadDotNet > { > /// > /// PyAcadCmd Class: > /// Used to register commands on the AutoCAD command stack. > /// > public class PyAcadCmd > { > public PyAcadCmd() > { > } > public delegate void CmdDelegate(); > internal delegate void AddReference(object assembly); > > /// > /// RegPyAcadCmd: > /// Registers a delegate (callback) with the AutoCAD command string > /// on the command stack. > /// > [DllImport("PyRegCmd.dll", > CallingConvention=CallingConvention.Cdecl,CharSet = CharSet.Unicode, > EntryPoint = "?RegPyCmd@@YAXPB_W0HP6AXXZ at Z")] > public static extern void RegPyCmd( > string cmd_group, > string cmd_name, > Autodesk.AutoCAD.Runtime.CommandFlags cmd_flags, > [MarshalAs(UnmanagedType.FunctionPtr)] CmdDelegate cmd_delegate); > > > public static void PythonRegister(string CommandName, > CmdDelegate FuncPointer, CommandFlags flags) > { > RegPyCmd("_pycmds", CommandName, flags, new > CmdDelegate(new PythonDelegateWrapper(FuncPointer).Invoke)); > } > > //testing stuff > public static void testcommand() > { > Editor ed = > Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; > ed.WriteMessage("\ncb1 delegate seems to work!\n"); > } > [CommandMethod("regcmds")] > static public void test() // This method can have any name > { > CmdDelegate cb1 = new CmdDelegate(PyAcadCmd.testcommand); > PythonRegister("testcommand", cb1, CommandFlags.Session); > } > [CommandMethod("regtest", CommandFlags.Session)] > static public void regtest() > { > PythonEngine engine = new PythonEngine(); > engine.Import("clr"); > AddReference adr = > engine.CreateMethod("clr.AddReference(assembly)"); > adr(typeof(BlockTableRecord).Assembly); > adr(typeof(Editor).Assembly); > CompiledCode cc = engine.Compile( > @" > import Autodesk.AutoCAD.Runtime > import clr > clr.AddReference('PyAcadDotNet') > from PyAcadDotNet import PyAcadCmd > def foo(): > print 'hello world' > PyAcadCmd.PythonRegister('pythontester', foo, > Autodesk.AutoCAD.Runtime.CommandFlags.Session)"); > cc.Execute(); > } > } > > class PythonDelegateWrapper > { > private PyAcadCmd.CmdDelegate cmdDelegate; > public PythonDelegateWrapper(PyAcadCmd.CmdDelegate dlg) > { > cmdDelegate = dlg; > } > public void Invoke() > { > cmdDelegate(); > } > } > } > ********code********** > > > > On 8/30/07, Dino Viehland wrote: > > Well at this point we've successfully created the delegate and passed it off to you so it's hard to tell what's going wrong here. Couple of suggestions on things to try and troubleshoot the issue: > > Instead of handing the delegate you get off to the P/Invoke call can you just turn around and invoke the delegate from C# code and successfully call back into the Python code? > > If that works can you do something like: > > > > class PythonDelegateWrapper { > > private CmdDelegate cmdDelegate; > > public PythonDelegateWrapper(CmdDelegate dlg) { > > cmdDelegate = dlg; > > } > > > > public void Invoke() { > > cmdDelegate(); > > } > > } > > > > And then pass "new CmdDelegate(new PythonDelegateWrapper(dlg).Invoke)" to the P/Invoke function? > > > > The reason why I'm proposing this is maybe there's a strange interaction between dynamic methods (which the Python delegate will be) and the P/Invoke call - this might help isolate the issue. > > > > And the final thing that might be interesting to try would be to make sure you keep the reference to the delegate alive during the lifetime of the call. In theory this should be happening for you automatically - but if the unmanaged side is going to hold onto this delegate for longer than the duration of the call you'll need to do this anyway. Given that you're still in the call this shouldn't be an issue but you could set the environment variable COMPlus_MDA=1 to enable CLR Managed Debugging Assistants to see if you get any warnings about that firing. I don't really believe this could be happening but it would be consistent w/ the exception you're getting. > > > > Those are my 1st two guesses as to what could be going wrong, hopefully one of them will be helpful :). > > > > -----Original Message----- > > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Tim Riley > > Sent: Thursday, August 30, 2007 8:59 AM > > To: Discussion of IronPython > > Subject: Re: [IronPython] Hosting: Delegates from Ironpython to C# > > > > Dino: > > > > I was trying something similar to what you had posted and was getting > > an error. I also just tried the code you gave me with a minor > > correction to fix the CommandFlags part and received the error below. > > If it helps I have also added the C# code use to call the python file > > below the error if that will help at all. > > > > > > *********ERROR*********** > > Command: pyfile > > System.AccessViolationException: Attempted to read or write protected memory. > > This is often an indication that other memory is corrupt. > > at PyAcadDotNet.PyAcadCmd.RegPyCmd(String cmd_group, String cmd_name, CommandFlags cmd_flags, CmdDelegate cmd_delegate) > > at PyAcadDotNet.PyAcadCmd.PythonRegister(String CommandName, CmdDelegate FuncPointer, CommandFlags flags) in C:\Documents and Settings\TJRiley\My Documents\pyacaddotnet\registercommand.cs:line 65 > > at PythonRegister##20(Object , Object , Object ) > > at IronPython.Runtime.Calls.CallTarget3.Invoke(Object arg0, Object arg1, Object arg2) > > at IronPython.Runtime.Calls.FastCallable3.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) > > at IronPython.Runtime.Calls.BuiltinFunction.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) > > at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext context, Object func, Object arg0, Object arg1, Object arg2) > > at C:\Documents and Settings\TJRiley\My Documents\pyacaddotnet\Samples\commandmethod_test.py##22(ModuleScope ) > > at IronPython.Hosting.CompiledCodeDelegate.Invoke(ModuleScope moduleScope) > > at IronPython.Hosting.CompiledCode.Run(ModuleScope moduleScope) > > at IronPython.Hosting.CompiledCode.Execute(EngineModule engineModule, IDictionary`2 locals) > > at IronPython.Hosting.CompiledCode.Execute() > > at PyAcadDotNet.AcadInterface.pythonfile() in C:\Documents and > > Settings\TJRiley\My Documents\pyacaddotnet\PyAcadDotNet.cs:line 98 > > *********ERROR*********** > > > > > > *********CODE************** > > using System; > > using System.Collections; > > using System.Windows.Forms; > > using System.IO; > > using System.Text; > > using System.Runtime.InteropServices; > > > > using Autodesk.AutoCAD.ApplicationServices; > > using Autodesk.AutoCAD.DatabaseServices; > > using Autodesk.AutoCAD.Runtime; > > using Autodesk.AutoCAD.EditorInput; > > > > using AcEd = Autodesk.AutoCAD.EditorInput; > > using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application; > > > > using IronPython.Hosting; > > > > namespace PyAcadDotNet > > { > > public class AcadInterface : IExtensionApplication > > { > > static internal AcEd.Editor ed = > > AcadApp.DocumentManager.MdiActiveDocument.Editor; > > > > public delegate void TestDelegate(); > > > > > > public void Initialize() > > { > > ed.WriteMessage("\nPyAcad.NET Loaded Successfully...."); > > ed.WriteMessage("\ntype 'pyhelp' for commands...."); > > } > > > > public void Terminate() > > { > > this.Terminate(); > > } > > > > internal delegate void AddReference(object assembly); > > > > [CommandMethod("pyfile", CommandFlags.Session)] > > static public void pythonfile() > > { > > using (PythonEngine engine = new PythonEngine()) > > { > > using (AcadCommandLine myCommandLine = new AcadCommandLine()) > > { > > try > > { > > // Create a new instance of PythonEngine and set variables. > > engine.AddToPath(Environment.CurrentDirectory); > > // Send Stdout and Stderr to the AutoCAD command line. > > engine.SetStandardOutput(myCommandLine); > > engine.SetStandardError(myCommandLine); > > engine.Import("clr"); > > PyAcadCmd regcmds = new PyAcadCmd(); > > engine.Globals.Add("regcmds", regcmds); > > //lets load some AutoCAD assemblies. > > AddReference adr = > > engine.CreateMethod("clr.AddReference(assembly)"); > > adr(typeof(BlockTableRecord).Assembly); > > adr(typeof(Editor).Assembly); > > > > // Display an OpenFileDialog and run the script. > > OpenFileDialog ofd = new OpenFileDialog(); > > ofd.Filter = "Python files (*.py)|*.py|All files (*.*)|*.*"; > > ofd.ShowDialog(); > > > > // Run the file selected by the open file dialog box. > > //engine.ExecuteFile(ofd.FileName); > > CompiledCode cc = engine.CompileFile(ofd.FileName); > > cc.Execute(); > > } > > catch (System.Exception e) > > { > > ed.WriteMessage(e.ToString()); > > } > > } > > } > > } > > } > > > > // > > public class AcadCommandLine : Stream > > //Modified version of a class coded by Mike Stall. > > { > > public AcadCommandLine() > > { > > //constructor > > } > > > > #region unsupported Read + Seek members > > public override bool CanRead > > { > > get { return false; } > > } > > > > public override bool CanSeek > > { > > get { return false; } > > } > > > > public override bool CanWrite > > { > > get { return true; } > > } > > > > public override void Flush() > > { > > // > > } > > > > public override long Length > > { > > get { throw new NotSupportedException("Seek not supported"); } > > // can't seek > > } > > > > public override long Position > > { > > get > > { > > throw new NotSupportedException("Seek not supported"); // can't seek > > } > > set > > { > > throw new NotSupportedException("Seek not supported"); // can't seek > > } > > } > > > > public override int Read(byte[] buffer, int offset, int count) > > { > > throw new NotSupportedException("Reed not supported"); // can't read > > } > > > > public override long Seek(long offset, SeekOrigin origin) > > { > > throw new NotSupportedException("Seek not supported"); // can't seek > > } > > > > public override void SetLength(long value) > > { > > throw new NotSupportedException("Seek not supported"); // can't seek > > } > > #endregion > > > > public override void Write(byte[] buffer, int offset, int count) > > { > > try > > { > > // Very bad hack: Ignore single newline char. This is because > > we expect the newline is following > > // previous content and we already placed a newline on that. > > AcEd.Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor; > > > > if (count == 1 && buffer[offset] == '\n') > > return; > > > > StringBuilder sb = new StringBuilder(); > > while (count > 0) > > { > > char ch = (char)buffer[offset]; > > if (ch == '\n') > > { > > ed.WriteMessage(sb.ToString() + "\n"); > > sb.Length = 0; // reset. > > } > > else if (ch != '\r') > > { > > sb.Append(ch); > > } > > > > offset++; > > count--; > > } > > if (sb.Length > 0) > > ed.WriteMessage(sb.ToString() + "\n"); > > } > > catch (System.Exception e) > > { > > throw e; > > } > > } > > } > > } > > *********CODE************** > > On 8/30/07, Dino Viehland wrote: > > > I think you should be able to just pass a function object to PythonRegister and it should be converted into a delegate. For example: > > > > > > import clr > > > clr.AddReference('PyAcadDotNet') > > > from PyAcadDotNet import PyAcadCmd > > > > > > def foo(): > > > print 'hello world' > > > > > > PyAcadCmd.PythonRegister('some command', foo, CommandFlags.Whatever) > > > > > > Does that not work? > > > > > > -----Original Message----- > > > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Tim Riley > > > Sent: Wednesday, August 29, 2007 7:10 PM > > > To: Discussion of IronPython > > > Subject: [IronPython] Hosting: Delegates from Ironpython to C# > > > > > > I'm embedding IronPython in a C# dll that is hosted inside a program > > > called AutoCAD. In order to register commands in AutoCAD from .NET I > > > need to P/Invoke a C function inside a .dll. I can do this fairly easy > > > from C# but I can't figure out the right way to call my C# wrapper > > > from IronPython to have it register the command. I have perused the > > > hosting docs for 1.1 and haven't been able to come up with a solution > > > that works. Here is my C# code. I either want to call the PyRegCmds > > > void or the PythonRegister void. Both of which expect a delegate.for > > > example if I had a python function like: > > > > > > def test1: > > > print "This is a test". > > > > > > I can't figure out how to map test to the delegate required in the code below. > > > Note: I can call this from C# fine. See :static public void test(). > > > > > > Can anyone give me any pointers? It would be greatly appreciated. > > > > > > > > > code: > > > > > > using System ; > > > using System.Runtime.InteropServices; > > > using Autodesk.AutoCAD.Runtime ; > > > using Autodesk.AutoCAD.EditorInput; > > > > > > namespace PyAcadDotNet > > > { > > > /// > > > /// PyAcadCmd Class: > > > /// Used to register commands on the AutoCAD command stack. > > > /// > > > public class PyAcadCmd > > > { > > > public PyAcadCmd() > > > { > > > } > > > public delegate void CmdDelegate(); > > > > > > /// > > > /// RegPyAcadCmd: > > > /// Registers a delegate (callback) with the AutoCAD command string > > > /// on the command stack. > > > /// > > > [DllImport("PyRegCmd.dll", > > > CallingConvention=CallingConvention.Cdecl,CharSet = CharSet.Unicode, > > > EntryPoint = "?RegPyCmd@@YAXPB_W0HP6AXXZ at Z")] > > > public static extern void RegPyCmd( > > > string cmd_group, > > > string cmd_name, > > > Autodesk.AutoCAD.Runtime.CommandFlags cmd_flags, > > > [MarshalAs(UnmanagedType.FunctionPtr)] PyAcadCmd.CmdDelegate cmd_delegate); > > > > > > > > > public static void PythonRegister(string CommandName, > > > CmdDelegate FuncPointer, CommandFlags flags) > > > { > > > RegPyCmd("_pycmds", CommandName, flags, FuncPointer); > > > } > > > > > > //testing stuff > > > public static void testcommand() > > > { > > > Editor ed = > > > Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; > > > ed.WriteMessage("\ncb1 delegate seems to work!\n"); > > > } > > > [CommandMethod("regcmds")] > > > static public void test() // This method can have any name > > > { > > > CmdDelegate cb1 = new CmdDelegate(PyAcadCmd.testcommand); > > > PythonRegister("testcommand", cb1, CommandFlags.Session); > > > } > > > } > > > > > > > > > } > > > _______________________________________________ > > > 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 > > _______________________________________________ > > 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 > _______________________________________________ Users mailing list Users at lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com From riltim at gmail.com Thu Aug 30 22:22:20 2007 From: riltim at gmail.com (Tim Riley) Date: Thu, 30 Aug 2007 16:22:20 -0400 Subject: [IronPython] Hosting: Delegates from Ironpython to C# In-Reply-To: <7AD436E4270DD54A94238001769C2227BD9F66684E@DF-GRTDANE-MSG.exchange.corp.microsoft.com> References: <7AD436E4270DD54A94238001769C2227BD9F666736@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <7AD436E4270DD54A94238001769C2227BD9F66674E@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <7AD436E4270DD54A94238001769C2227BD9F66683B@DF-GRTDANE-MSG.exchange.corp.microsoft.com> <7AD436E4270DD54A94238001769C2227BD9F66684E@DF-GRTDANE-MSG.exchange.corp.microsoft.com> Message-ID: Ok, I was able to get debugging going better with MDA support. I have attached screen shot that shows the System.AccessViolationException and the values of pdw when the exception is raised. I have also attached the C function that I am trying to access via P/Invoke in the event that it may help somehow. ********C code********* #pragma unmanaged __declspec(dllexport) void __cdecl RegPyCmd(const ACHAR * cmdGroup, const ACHAR * cmdName, int cmdFlags, void(*functionptr)()) { // Note: cast functionptr as AcRxFuctionPtr. Acad::ErrorStatus es = acedRegCmds->addCommand(cmdGroup, cmdName, cmdName, (int)cmdFlags,(AcRxFunctionPtr)functionptr); if(es != eOk) { acutPrintf(L"Error loading command %s: error status %d", cmdName, acadErrorStatusText(es)); } } ********C code********* On 8/30/07, Dino Viehland wrote: > You can set it in the registry instead: > > HKLM\Software\Microsoft\.NETFramework > > And set MDA="1" > > This website http://msdn2.microsoft.com/en-us/library/d21c150d.aspx has a reg file you can use to do it. This will enable MDAs globally for all managed processes on your machine so you'll want to turn it off when you're done. > > -----Original Message----- > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Tim Riley > Sent: Thursday, August 30, 2007 12:50 PM > To: Discussion of IronPython > Subject: Re: [IronPython] Hosting: Delegates from Ironpython to C# > > Dino: > I revised the code to what you suggested and still no luck. > > Is there any way I can set the environment variable other than via the > command prompt? My application is hosted inside another application > and I can't set the variable from there. > > Tim > > On 8/30/07, Dino Viehland wrote: > > Setting the env var at runtime won't help, you'll want to set it at a command prompt and start your app from the command prompt. One other tweak: > > > > public static void PythonRegister(string CommandName, > > CmdDelegate FuncPointer, CommandFlags flags) > > { > > PythonDelegateWrapper pdw = new PythonDelegateWrapper(FuncPointer)); > > RegPyCmd("_pycmds", CommandName, flags, new > > CmdDelegate(pdw.Invoke); > > GC.KeepAlive(pdw); > > } > > > > Which will ensure it's not a delegate getting collected issue. > > > > If that doesn't work then we'll need to go into unmanaged debugging territory w/ windbg/cdb/ntsd :). > > > > -----Original Message----- > > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Tim Riley > > Sent: Thursday, August 30, 2007 11:55 AM > > To: Discussion of IronPython > > Subject: Re: [IronPython] Hosting: Delegates from Ironpython to C# > > > > Dino: > > > > I tried using the PythonDelegateWrapper you posted below with the same > > results. To make things easier I tried moving all my testing into a > > single C# file and have it run the code from C# instead of a compiling > > a python file. Below is the code. When I execute "regtest" in AutoCAD > > it fatal errors on me. I also added > > System.Environment.SetEnvironmentVariable("COMPlus_MDA", "1"); to the > > initialize of my code but it doesn't do anything for me. Any other > > ideas? > > > > ********code********* > > using System ; > > using System.Runtime.InteropServices; > > using Autodesk.AutoCAD.Runtime ; > > using Autodesk.AutoCAD.EditorInput; > > using Autodesk.AutoCAD.ApplicationServices; > > using Autodesk.AutoCAD.DatabaseServices; > > > > using IronPython.Hosting; > > > > namespace PyAcadDotNet > > { > > /// > > /// PyAcadCmd Class: > > /// Used to register commands on the AutoCAD command stack. > > /// > > public class PyAcadCmd > > { > > public PyAcadCmd() > > { > > } > > public delegate void CmdDelegate(); > > internal delegate void AddReference(object assembly); > > > > /// > > /// RegPyAcadCmd: > > /// Registers a delegate (callback) with the AutoCAD command string > > /// on the command stack. > > /// > > [DllImport("PyRegCmd.dll", > > CallingConvention=CallingConvention.Cdecl,CharSet = CharSet.Unicode, > > EntryPoint = "?RegPyCmd@@YAXPB_W0HP6AXXZ at Z")] > > public static extern void RegPyCmd( > > string cmd_group, > > string cmd_name, > > Autodesk.AutoCAD.Runtime.CommandFlags cmd_flags, > > [MarshalAs(UnmanagedType.FunctionPtr)] CmdDelegate cmd_delegate); > > > > > > public static void PythonRegister(string CommandName, > > CmdDelegate FuncPointer, CommandFlags flags) > > { > > RegPyCmd("_pycmds", CommandName, flags, new > > CmdDelegate(new PythonDelegateWrapper(FuncPointer).Invoke)); > > } > > > > //testing stuff > > public static void testcommand() > > { > > Editor ed = > > Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; > > ed.WriteMessage("\ncb1 delegate seems to work!\n"); > > } > > [CommandMethod("regcmds")] > > static public void test() // This method can have any name > > { > > CmdDelegate cb1 = new CmdDelegate(PyAcadCmd.testcommand); > > PythonRegister("testcommand", cb1, CommandFlags.Session); > > } > > [CommandMethod("regtest", CommandFlags.Session)] > > static public void regtest() > > { > > PythonEngine engine = new PythonEngine(); > > engine.Import("clr"); > > AddReference adr = > > engine.CreateMethod("clr.AddReference(assembly)"); > > adr(typeof(BlockTableRecord).Assembly); > > adr(typeof(Editor).Assembly); > > CompiledCode cc = engine.Compile( > > @" > > import Autodesk.AutoCAD.Runtime > > import clr > > clr.AddReference('PyAcadDotNet') > > from PyAcadDotNet import PyAcadCmd > > def foo(): > > print 'hello world' > > PyAcadCmd.PythonRegister('pythontester', foo, > > Autodesk.AutoCAD.Runtime.CommandFlags.Session)"); > > cc.Execute(); > > } > > } > > > > class PythonDelegateWrapper > > { > > private PyAcadCmd.CmdDelegate cmdDelegate; > > public PythonDelegateWrapper(PyAcadCmd.CmdDelegate dlg) > > { > > cmdDelegate = dlg; > > } > > public void Invoke() > > { > > cmdDelegate(); > > } > > } > > } > > ********code********** > > > > > > > > On 8/30/07, Dino Viehland wrote: > > > Well at this point we've successfully created the delegate and passed it off to you so it's hard to tell what's going wrong here. Couple of suggestions on things to try and troubleshoot the issue: > > > Instead of handing the delegate you get off to the P/Invoke call can you just turn around and invoke the delegate from C# code and successfully call back into the Python code? > > > If that works can you do something like: > > > > > > class PythonDelegateWrapper { > > > private CmdDelegate cmdDelegate; > > > public PythonDelegateWrapper(CmdDelegate dlg) { > > > cmdDelegate = dlg; > > > } > > > > > > public void Invoke() { > > > cmdDelegate(); > > > } > > > } > > > > > > And then pass "new CmdDelegate(new PythonDelegateWrapper(dlg).Invoke)" to the P/Invoke function? > > > > > > The reason why I'm proposing this is maybe there's a strange interaction between dynamic methods (which the Python delegate will be) and the P/Invoke call - this might help isolate the issue. > > > > > > And the final thing that might be interesting to try would be to make sure you keep the reference to the delegate alive during the lifetime of the call. In theory this should be happening for you automatically - but if the unmanaged side is going to hold onto this delegate for longer than the duration of the call you'll need to do this anyway. Given that you're still in the call this shouldn't be an issue but you could set the environment variable COMPlus_MDA=1 to enable CLR Managed Debugging Assistants to see if you get any warnings about that firing. I don't really believe this could be happening but it would be consistent w/ the exception you're getting. > > > > > > Those are my 1st two guesses as to what could be going wrong, hopefully one of them will be helpful :). > > > > > > -----Original Message----- > > > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Tim Riley > > > Sent: Thursday, August 30, 2007 8:59 AM > > > To: Discussion of IronPython > > > Subject: Re: [IronPython] Hosting: Delegates from Ironpython to C# > > > > > > Dino: > > > > > > I was trying something similar to what you had posted and was getting > > > an error. I also just tried the code you gave me with a minor > > > correction to fix the CommandFlags part and received the error below. > > > If it helps I have also added the C# code use to call the python file > > > below the error if that will help at all. > > > > > > > > > *********ERROR*********** > > > Command: pyfile > > > System.AccessViolationException: Attempted to read or write protected memory. > > > This is often an indication that other memory is corrupt. > > > at PyAcadDotNet.PyAcadCmd.RegPyCmd(String cmd_group, String cmd_name, CommandFlags cmd_flags, CmdDelegate cmd_delegate) > > > at PyAcadDotNet.PyAcadCmd.PythonRegister(String CommandName, CmdDelegate FuncPointer, CommandFlags flags) in C:\Documents and Settings\TJRiley\My Documents\pyacaddotnet\registercommand.cs:line 65 > > > at PythonRegister##20(Object , Object , Object ) > > > at IronPython.Runtime.Calls.CallTarget3.Invoke(Object arg0, Object arg1, Object arg2) > > > at IronPython.Runtime.Calls.FastCallable3.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) > > > at IronPython.Runtime.Calls.BuiltinFunction.Call(ICallerContext context, Object arg0, Object arg1, Object arg2) > > > at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext context, Object func, Object arg0, Object arg1, Object arg2) > > > at C:\Documents and Settings\TJRiley\My Documents\pyacaddotnet\Samples\commandmethod_test.py##22(ModuleScope ) > > > at IronPython.Hosting.CompiledCodeDelegate.Invoke(ModuleScope moduleScope) > > > at IronPython.Hosting.CompiledCode.Run(ModuleScope moduleScope) > > > at IronPython.Hosting.CompiledCode.Execute(EngineModule engineModule, IDictionary`2 locals) > > > at IronPython.Hosting.CompiledCode.Execute() > > > at PyAcadDotNet.AcadInterface.pythonfile() in C:\Documents and > > > Settings\TJRiley\My Documents\pyacaddotnet\PyAcadDotNet.cs:line 98 > > > *********ERROR*********** > > > > > > > > > *********CODE************** > > > using System; > > > using System.Collections; > > > using System.Windows.Forms; > > > using System.IO; > > > using System.Text; > > > using System.Runtime.InteropServices; > > > > > > using Autodesk.AutoCAD.ApplicationServices; > > > using Autodesk.AutoCAD.DatabaseServices; > > > using Autodesk.AutoCAD.Runtime; > > > using Autodesk.AutoCAD.EditorInput; > > > > > > using AcEd = Autodesk.AutoCAD.EditorInput; > > > using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application; > > > > > > using IronPython.Hosting; > > > > > > namespace PyAcadDotNet > > > { > > > public class AcadInterface : IExtensionApplication > > > { > > > static internal AcEd.Editor ed = > > > AcadApp.DocumentManager.MdiActiveDocument.Editor; > > > > > > public delegate void TestDelegate(); > > > > > > > > > public void Initialize() > > > { > > > ed.WriteMessage("\nPyAcad.NET Loaded Successfully...."); > > > ed.WriteMessage("\ntype 'pyhelp' for commands...."); > > > } > > > > > > public void Terminate() > > > { > > > this.Terminate(); > > > } > > > > > > internal delegate void AddReference(object assembly); > > > > > > [CommandMethod("pyfile", CommandFlags.Session)] > > > static public void pythonfile() > > > { > > > using (PythonEngine engine = new PythonEngine()) > > > { > > > using (AcadCommandLine myCommandLine = new AcadCommandLine()) > > > { > > > try > > > { > > > // Create a new instance of PythonEngine and set variables. > > > engine.AddToPath(Environment.CurrentDirectory); > > > // Send Stdout and Stderr to the AutoCAD command line. > > > engine.SetStandardOutput(myCommandLine); > > > engine.SetStandardError(myCommandLine); > > > engine.Import("clr"); > > > PyAcadCmd regcmds = new PyAcadCmd(); > > > engine.Globals.Add("regcmds", regcmds); > > > //lets load some AutoCAD assemblies. > > > AddReference adr = > > > engine.CreateMethod("clr.AddReference(assembly)"); > > > adr(typeof(BlockTableRecord).Assembly); > > > adr(typeof(Editor).Assembly); > > > > > > // Display an OpenFileDialog and run the script. > > > OpenFileDialog ofd = new OpenFileDialog(); > > > ofd.Filter = "Python files (*.py)|*.py|All files (*.*)|*.*"; > > > ofd.ShowDialog(); > > > > > > // Run the file selected by the open file dialog box. > > > //engine.ExecuteFile(ofd.FileName); > > > CompiledCode cc = engine.CompileFile(ofd.FileName); > > > cc.Execute(); > > > } > > > catch (System.Exception e) > > > { > > > ed.WriteMessage(e.ToString()); > > > } > > > } > > > } > > > } > > > } > > > > > > // > > > public class AcadCommandLine : Stream > > > //Modified version of a class coded by Mike Stall. > > > { > > > public AcadCommandLine() > > > { > > > //constructor > > > } > > > > > > #region unsupported Read + Seek members > > > public override bool CanRead > > > { > > > get { return false; } > > > } > > > > > > public override bool CanSeek > > > { > > > get { return false; } > > > } > > > > > > public override bool CanWrite > > > { > > > get { return true; } > > > } > > > > > > public override void Flush() > > > { > > > // > > > } > > > > > > public override long Length > > > { > > > get { throw new NotSupportedException("Seek not supported"); } > > > // can't seek > > > } > > > > > > public override long Position > > > { > > > get > > > { > > > throw new NotSupportedException("Seek not supported"); // can't seek > > > } > > > set > > > { > > > throw new NotSupportedException("Seek not supported"); // can't seek > > > } > > > } > > > > > > public override int Read(byte[] buffer, int offset, int count) > > > { > > > throw new NotSupportedException("Reed not supported"); // can't read > > > } > > > > > > public override long Seek(long offset, SeekOrigin origin) > > > { > > > throw new NotSupportedException("Seek not supported"); // can't seek > > > } > > > > > > public override void SetLength(long value) > > > { > > > throw new NotSupportedException("Seek not supported"); // can't seek > > > } > > > #endregion > > > > > > public override void Write(byte[] buffer, int offset, int count) > > > { > > > try > > > { > > > // Very bad hack: Ignore single newline char. This is because > > > we expect the newline is following > > > // previous content and we already placed a newline on that. > > > AcEd.Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor; > > > > > > if (count == 1 && buffer[offset] == '\n') > > > return; > > > > > > StringBuilder sb = new StringBuilder(); > > > while (count > 0) > > > { > > > char ch = (char)buffer[offset]; > > > if (ch == '\n') > > > { > > > ed.WriteMessage(sb.ToString() + "\n"); > > > sb.Length = 0; // reset. > > > } > > > else if (ch != '\r') > > > { > > > sb.Append(ch); > > > } > > > > > > offset++; > > > count--; > > > } > > > if (sb.Length > 0) > > > ed.WriteMessage(sb.ToString() + "\n"); > > > } > > > catch (System.Exception e) > > > { > > > throw e; > > > } > > > } > > > } > > > } > > > *********CODE************** > > > On 8/30/07, Dino Viehland wrote: > > > > I think you should be able to just pass a function object to PythonRegister and it should be converted into a delegate. For example: > > > > > > > > import clr > > > > clr.AddReference('PyAcadDotNet') > > > > from PyAcadDotNet import PyAcadCmd > > > > > > > > def foo(): > > > > print 'hello world' > > > > > > > > PyAcadCmd.PythonRegister('some command', foo, CommandFlags.Whatever) > > > > > > > > Does that not work? > > > > > > > > -----Original Message----- > > > > From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Tim Riley > > > > Sent: Wednesday, August 29, 2007 7:10 PM > > > > To: Discussion of IronPython > > > > Subject: [IronPython] Hosting: Delegates from Ironpython to C# > > > > > > > > I'm embedding IronPython in a C# dll that is hosted inside a program > > > > called AutoCAD. In order to register commands in AutoCAD from .NET I > > > > need to P/Invoke a C function inside a .dll. I can do this fairly easy > > > > from C# but I can't figure out the right way to call my C# wrapper > > > > from IronPython to have it register the command. I have perused the > > > > hosting docs for 1.1 and haven't been able to come up with a solution > > > > that works. Here is my C# code. I either want to call the PyRegCmds > > > > void or the PythonRegister void. Both of which expect a delegate.for > > > > example if I had a python function like: > > > > > > > > def test1: > > > > print "This is a test". > > > > > > > > I can't figure out how to map test to the delegate required in the code below. > > > > Note: I can call this from C# fine. See :static public void test(). > > > > > > > > Can anyone give me any pointers? It would be greatly appreciated. > > > > > > > > > > > > code: > > > > > > > > using System ; > > > > using System.Runtime.InteropServices; > > > > using Autodesk.AutoCAD.Runtime ; > > > > using Autodesk.AutoCAD.EditorInput; > > > > > > > > namespace PyAcadDotNet > > > > { > > > > /// > > > > /// PyAcadCmd Class: > > > > /// Used to register commands on the AutoCAD command stack. > > > > /// > > > > public class PyAcadCmd > > > > { > > > > public PyAcadCmd() > > > > { > > > > } > > > > public delegate void CmdDelegate(); > > > > > > > > /// > > > > /// RegPyAcadCmd: > > > > /// Registers a delegate (callback) with the AutoCAD command string > > > > /// on the command stack. > > > > /// > > > > [DllImport("PyRegCmd.dll", > > > > CallingConvention=CallingConvention.Cdecl,CharSet = CharSet.Unicode, > > > > EntryPoint = "?RegPyCmd@@YAXPB_W0HP6AXXZ at Z")] > > > > public static extern void RegPyCmd( > > > > string cmd_group, > > > > string cmd_name, > > > > Autodesk.AutoCAD.Runtime.CommandFlags cmd_flags, > > > > [MarshalAs(UnmanagedType.FunctionPtr)] PyAcadCmd.CmdDelegate cmd_delegate); > > > > > > > > > > > > public static void PythonRegister(string CommandName, > > > > CmdDelegate FuncPointer, CommandFlags flags) > > > > { > > > > RegPyCmd("_pycmds", CommandName, flags, FuncPointer); > > > > } > > > > > > > > //testing stuff > > > > public static void testcommand() > > > > { > > > > Editor ed = > > > > Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; > > > > ed.WriteMessage("\ncb1 delegate seems to work!\n"); > > > > } > > > > [CommandMethod("regcmds")] > > > > static public void test() // This method can have any name > > > > { > > > > CmdDelegate cb1 = new CmdDelegate(PyAcadCmd.testcommand); > > > > PythonRegister("testcommand", cb1, CommandFlags.Session); > > > > } > > > > } > > > > > > > > > > > > } > > > > _______________________________________________ > > > > 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 > > > _______________________________________________ > > > 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 > > > _______________________________________________ > 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 > -------------- next part -------------- A non-text attachment was scrubbed... Name: delegate_error.png Type: image/png Size: 33084 bytes Desc: not available URL: