From gary at zope.com Tue Aug 2 21:35:57 2005 From: gary at zope.com (Gary Poster) Date: Tue, 2 Aug 2005 15:35:57 -0400 Subject: [Python.NET] Fredericksburg, VA ZPUG August 10: .Net, functional testing Message-ID: Please join us August 10, 7:30-9:00 PM, for the third meeting of the Fredericksburg, VA Zope and Python User Group ("ZPUG"). This meeting has four features of note. - Brian Lloyd, the author of Python for .Net (http://www.zope.org/ Members/Brian/PythonNet/) and the Zope Corporation VP of Engineering, will discuss his .Net platform and give a brief .Net overview. - Benji York, Zope Corp Senior Software Engineer, will discuss current functional testing practices on Zope 3, including using Selenium on Zope 3, using demo storage for functional testing, and using his own compelling new functional test package. Note that the majority of this discussion has strong applicability to automated testing of all web frameworks and applications. - We will serve the now-usual geek-chic fruit, cheese, and soft drinks. - Fred Drake, Zope Corp Senior Software Engineer, Python core developer, Python documentation maintainer and editor, and co-author of the O'Reilly book Python & XML will give two of his books (http:// www.amazon.com/exec/obidos/tg/detail/-/0596001282/) to new attendees. Upon pressure, he admitted that he would be willing to autograph them if bribed with fruit, cheese, and soft drinks. Note that we are eager to have non-Zope-Corporation employees give presentations. :-) We had three new attendees last meeting, for a total of ten. Please come and bring friends! More information http://www.zope.org/Members/poster/ fxbgzpug_announce_3 and below. Hope to see you there! Gary General ZPUG information ------------------------------------ When: second Wednesday of every month, 7:30-9:00. Where: Zope Corporation offices. 513 Prince Edward Street; Fredericksburg, VA 22408 (tinyurl for map is http://tinyurl.com/duoab). Parking: Zope Corporation parking lot; entrance on Prince Edward Street. Topics: As desired (and offered) by participants, within the constraints of having to do with Python. Contact: Gary Poster (gary at zope.com) From glc at well.com Fri Aug 5 23:15:54 2005 From: glc at well.com (Greg Chapman) Date: Fri, 5 Aug 2005 21:15:54 +0000 (UTC) Subject: [Python.NET] Refcount leak in DelegateManager.Dispatcher.TrueDispatch Message-ID: I'm posting this here because the zope issue tracker seems to be broken; at least it won't let me in. Anyway, it looks like there is a refcount leak in Dispatcher.TrueDispatch when the underlying delegate has a void return type. In that case, TrueDispatch returns without Decrefing the result of the call to the python function which the Dispatcher is wrapping. I think the code should be: if (rtype == typeof(void)) { Runtime.Decref(op); // this line added return null; } --- Greg Chapman From Steffen.Guhlemann at mailbox.tu-dresden.de Tue Aug 9 19:46:30 2005 From: Steffen.Guhlemann at mailbox.tu-dresden.de (Steffen Guhlemann) Date: Tue, 9 Aug 2005 19:46:30 +0200 Subject: [Python.NET] problem with strong typed .net-enums Message-ID: <1123609590.42f8ebf6a5693@rmc60-231.urz.tu-dresden.de> Hi, by bad chance i experienced a strange and buggy treatening of .Net-Enums in Python, that causes headache: (i use Python 2.3, so if this is fixed in 2.4, please just tell me) In Python .Net-enums lose their typeinformation and get simple ints, so when used in overloaded functions they work by chance depending on the order of the c#-functions in the source-file. An example is the constructor of the font class, where 4 3-argument-overloads exist, of which 2 are of interest: Font(string,float,FontStyle) and Font(string,float,GraphicsUnit) where both FontStyle and GraphicsUnit are enums, which are treated by Python as simple ints. So which of thoose constructors is choosen depends on some circumstances during the compilation of System.Drawing.dll. It startet with a simple construction of a Font: ... Assembly.LoadWithPartialName("System.Drawing") from CLR.System.Drawing import Font, FontStyle ... myFont=Font("Arial",8,FontStyle.Bold) That code used to work a long time and looks very innocent... But then by chance it throw an exception on one computer: "no constructor matches given argument" (but on every other computer it worked, ...) Later i realized, that on that computer besides the current framework 1.1 the beta of .Net 2.0 was installed, and LoadWithPartialName took the latest System.Drawing.dll. And maybe they changed some order of constructors in their files... somehow with 2.0 it didn't work. My Diagnostic tool for locating the error was a small c#-class with the same 3-argument-overloads, the font-class has, and one more with all arguments as object. It does nothing but prints out, which constructor is called: public class MyFont{ //... public MyFont(string familyName,float size, FontStyle style) {Console.WriteLine("string,float,FontStyle");} //... } Then i invoked my testclass with the arguments above: myTestFont=MyFont("Arial",8,FontStyle.Bold) It occurs that depending of the order of the 2 constructors of interest in my c#-source-file one time the MyFont(string,float,GraphicsUnit) and another time the correct constructor MyFont(string,float,FontStyle) is choosen (it seemed to be the constructor later in the file .. but i'm not sure if this depends more on random compilation issues) What worries about that fact is not the issue with Font, which behavior may change when it comes to .Net2.0. I'm concerned more about which other functions i might implicitely call without knowing it, because of an ambiguity that does not exist in c# because of strong typed enums. Does someone know, if this problem is solved with 2.4, or maybe there is another python-term, that helps strong type enums? thanks for your help Steffen Guhlemann From Steffen.Guhlemann at mailbox.tu-dresden.de Tue Aug 9 20:25:27 2005 From: Steffen.Guhlemann at mailbox.tu-dresden.de (Steffen Guhlemann) Date: Tue, 9 Aug 2005 20:25:27 +0200 Subject: [Python.NET] requesting a certain .Net-Version Message-ID: <1123611927.42f8f51760396@rmc60-231.urz.tu-dresden.de> Hi again, is there a way to request Python to bind to a certain .Net-Runtime-Version (e.g. 1.1 in the presense of the 2.0-beta)? There are certain incompabilites for instance with fonts, so it would be usefull not just to bind against the latest version but to self determine the version. especially for mscorlib i see no way in standard Python.net. thanks Steffen From mgavalda at gmail.com Tue Aug 9 23:13:36 2005 From: mgavalda at gmail.com (=?ISO-8859-1?Q?Marsal_Gavald=E0?=) Date: Tue, 9 Aug 2005 17:13:36 -0400 Subject: [Python.NET] packaging pythondotnet with py2exe Message-ID: <6370cae8050809141375966d2a@mail.gmail.com> Apologies if this has been answered before, but what modules/DLLs are needed to package, using py2exe, a python app that uses pythondotnet? Thank you so much, marsal From brian at zope.com Wed Aug 10 15:59:31 2005 From: brian at zope.com (Brian Lloyd) Date: Wed, 10 Aug 2005 09:59:31 -0400 Subject: [Python.NET] packaging pythondotnet with py2exe In-Reply-To: <6370cae8050809141375966d2a@mail.gmail.com> Message-ID: For windows, you need to include CLR.dll and PythonRuntime.dll (as well as anything from the standard Python distro that you use, of course). HTH, Brian Lloyd brian at zope.com V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com > -----Original Message----- > From: pythondotnet-bounces at python.org > [mailto:pythondotnet-bounces at python.org]On Behalf Of Marsal Gavalda > Sent: Tuesday, August 09, 2005 4:14 PM > To: pythondotnet at python.org > Subject: [Python.NET] packaging pythondotnet with py2exe > > > Apologies if this has been answered before, but what modules/DLLs are > needed to package, using py2exe, a python app that uses pythondotnet? > > Thank you so much, > > marsal > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet > From meddington at gmail.com Sun Aug 14 08:35:53 2005 From: meddington at gmail.com (Michael Eddington) Date: Sat, 13 Aug 2005 23:35:53 -0700 Subject: [Python.NET] Adding PyRun_String to Runtime Message-ID: <2db0cefa050813233518ec6793@mail.gmail.com> I would like to run Python strings and get an object return from .NET. To this end I added PyRun_String to the Runtime object and another method to PythonEngine ala the existing SimpleString implementation. Everything compiles, but Runtime.PyRun_String always returns a NULL, and it does not look like the code is being run. Is there any trick to adding new methods to the Runtime? // From Runtime.cs [DllImport(Runtime.dll, CallingConvention=CallingConvention.Cdecl, ExactSpelling=true, CharSet=CharSet.Ansi)] internal unsafe static extern IntPtr PyRun_String(string code, int start, IntPtr globals, IntPtr locals); // From Python.cs public static PyObject RunString(string code) { IntPtr globals = Runtime.PyEval_GetGlobals(); IntPtr locals = Runtime.PyEval_GetLocals(); IntPtr ret; ret = Runtime.PyRun_String(code, 257,globals, locals); Runtime.Decref(globals); Runtime.Decref(locals); if (ret == IntPtr.Zero) { throw new PythonException(); } return new PyObject(ret); } From brian at zope.com Mon Aug 15 18:23:03 2005 From: brian at zope.com (Brian Lloyd) Date: Mon, 15 Aug 2005 12:23:03 -0400 Subject: [Python.NET] Adding PyRun_String to Runtime In-Reply-To: <2db0cefa050813233518ec6793@mail.gmail.com> Message-ID: Hi Michael - I assume you're running an older version of Python for NET? The current version has an implementation of RunString: public static PyObject RunString(string code) { IntPtr globals = Runtime.PyEval_GetGlobals(); IntPtr locals = Runtime.PyDict_New(); IntPtr builtins = Runtime.PyEval_GetBuiltins(); Runtime.PyDict_SetItemString(locals, "__builtins__", builtins); IntPtr flag = (IntPtr)257; /* Py_file_input */ IntPtr result = Runtime.PyRun_String(code, flag, globals, locals); Runtime.Decref(locals); if (result == IntPtr.Zero) { return null; } return new PyObject(result); } The trick is that for various reasons you can't depend on the PyEval_GetLocals call to return anything meaningful, so you have to build the locals dict manually. HTH, Brian Lloyd brian at zope.com V.P. Engineering 540.361.1716 Zope Corporation http://www.zope.com > -----Original Message----- > From: pythondotnet-bounces at python.org > [mailto:pythondotnet-bounces at python.org]On Behalf Of Michael Eddington > Sent: Sunday, August 14, 2005 1:36 AM > To: pythondotnet at python.org > Subject: [Python.NET] Adding PyRun_String to Runtime > > > I would like to run Python strings and get an object return from .NET. > To this end I added PyRun_String to the Runtime object and another > method to PythonEngine ala the existing SimpleString implementation. > > Everything compiles, but Runtime.PyRun_String always returns a NULL, > and it does not look like the code is being run. > > Is there any trick to adding new methods to the Runtime? > > // From Runtime.cs > > [DllImport(Runtime.dll, CallingConvention=CallingConvention.Cdecl, > ExactSpelling=true, CharSet=CharSet.Ansi)] > internal unsafe static extern IntPtr > PyRun_String(string code, int start, IntPtr globals, > IntPtr locals); > > > // From Python.cs > > public static PyObject RunString(string code) > { > IntPtr globals = Runtime.PyEval_GetGlobals(); > IntPtr locals = Runtime.PyEval_GetLocals(); > IntPtr ret; > > ret = Runtime.PyRun_String(code, > 257,globals, locals); > > Runtime.Decref(globals); > Runtime.Decref(locals); > > if (ret == IntPtr.Zero) > { > throw new PythonException(); > } > > return new PyObject(ret); > } > _________________________________________________ > Python.NET mailing list - PythonDotNet at python.org > http://mail.python.org/mailman/listinfo/pythondotnet > From meddington at gmail.com Wed Aug 24 20:12:09 2005 From: meddington at gmail.com (Michael Eddington) Date: Wed, 24 Aug 2005 11:12:09 -0700 Subject: [Python.NET] Adding PyRun_String to Runtime In-Reply-To: References: Message-ID: <430CB879.60006@gmail.com> Brian, I upgraded to the latest distribution but still had issues with the RunString included. Seems GetGlobals also has issues. I ended up re-writing the implementation as such follows. This seems to work reliably. One difference from the two implementations is I'm sending __builtin__ as the globals dictionary Searching through the Python mail archives I found a couple of references that this is the correct thing todo. Also, I'm keeping the locals dictionary around, seems like the right things todo, but not sure. protected static PyDict locals = null; public static PyObject RunString(string code) { PyDict globals = new PyDict(Runtime.PyModule_GetDict(ImportModule("__builtin__").Handle)); if(locals == null) { locals = new PyDict(Runtime.PyDict_New()); } IntPtr flag = (IntPtr)257; /* Py_file_input */ IntPtr result = Runtime.PyRun_String(code, flag, globals.Handle, locals.Handle); if (result == IntPtr.Zero) { return null; } return new PyObject(result); } Brian Lloyd wrote: >Hi Michael - I assume you're running an older version of >Python for NET? The current version has an implementation >of RunString: > > public static PyObject RunString(string code) { > IntPtr globals = Runtime.PyEval_GetGlobals(); > IntPtr locals = Runtime.PyDict_New(); > > IntPtr builtins = Runtime.PyEval_GetBuiltins(); > Runtime.PyDict_SetItemString(locals, "__builtins__", builtins); > > IntPtr flag = (IntPtr)257; /* Py_file_input */ > IntPtr result = Runtime.PyRun_String(code, flag, globals, locals); > Runtime.Decref(locals); > if (result == IntPtr.Zero) { > return null; > } > return new PyObject(result); > } > >The trick is that for various reasons you can't depend on the >PyEval_GetLocals call to return anything meaningful, so you have >to build the locals dict manually. > >HTH, > > >Brian Lloyd brian at zope.com >V.P. Engineering 540.361.1716 >Zope Corporation http://www.zope.com > > > > >>-----Original Message----- >>From: pythondotnet-bounces at python.org >>[mailto:pythondotnet-bounces at python.org]On Behalf Of Michael Eddington >>Sent: Sunday, August 14, 2005 1:36 AM >>To: pythondotnet at python.org >>Subject: [Python.NET] Adding PyRun_String to Runtime >> >> >>I would like to run Python strings and get an object return from .NET. >> To this end I added PyRun_String to the Runtime object and another >>method to PythonEngine ala the existing SimpleString implementation. >> >>Everything compiles, but Runtime.PyRun_String always returns a NULL, >>and it does not look like the code is being run. >> >>Is there any trick to adding new methods to the Runtime? >> >>// From Runtime.cs >> >> [DllImport(Runtime.dll, CallingConvention=CallingConvention.Cdecl, >> ExactSpelling=true, CharSet=CharSet.Ansi)] >> internal unsafe static extern IntPtr >> PyRun_String(string code, int start, IntPtr globals, >>IntPtr locals); >> >> >>// From Python.cs >> >> public static PyObject RunString(string code) >> { >> IntPtr globals = Runtime.PyEval_GetGlobals(); >> IntPtr locals = Runtime.PyEval_GetLocals(); >> IntPtr ret; >> >> ret = Runtime.PyRun_String(code, >>257,globals, locals); >> >> Runtime.Decref(globals); >> Runtime.Decref(locals); >> >> if (ret == IntPtr.Zero) >> { >> throw new PythonException(); >> } >> >> return new PyObject(ret); >> } >>_________________________________________________ >>Python.NET mailing list - PythonDotNet at python.org >>http://mail.python.org/mailman/listinfo/pythondotnet >> >> >> > > > From meddington at gmail.com Thu Aug 25 02:30:58 2005 From: meddington at gmail.com (Michael Eddington) Date: Wed, 24 Aug 2005 17:30:58 -0700 Subject: [Python.NET] nmake version of makefile (makefile.nmake) Message-ID: <430D1142.6040700@gmail.com> "Ported" the makefile to nmake (attached). mike -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: makefile.nmake Url: http://mail.python.org/pipermail/pythondotnet/attachments/20050824/56a3e1e9/makefile.diff From stan at phidani.be Fri Aug 26 10:51:28 2005 From: stan at phidani.be (Stan Pinte) Date: Fri, 26 Aug 2005 08:51:28 +0000 Subject: [Python.NET] BUG in python delegates returning int called from C# Message-ID: <430ED810.9020405@phidani.be> hello, the following code may point to a bug in delegates implementation python: def stringFunc(): return "Hello world" def intFunc(): return 0 test.AnotherClass.SetStringDelegate (test.StringDelegate(stringFunc)) test.AnotherClass.SetIntDelegate (test.IntDelegate(intFunc)) t = test.MyClass() t.Dump(2) C#: public static void Dump () { Console.Out.WriteLine (stringDelegate() + " " + intDelegate()); } see output: [Debug]> python test.py Got : 2 Hello world 80098912 Hello world 80099400 [Debug]> --> As we see, the call to intDelegate() returns unspecified results...whereas it should return 0..... Full test case below. Stan. /* * Created by SharpDevelop. * User: hans * Date: 25/08/2005 * Time: 18:54 * * To change this template use Tools | Options | Coding | Edit Standard Headers. */ using System; namespace test { public delegate string StringDelegate(); public delegate int IntDelegate(); public class AnotherClass { static StringDelegate stringDelegate; static IntDelegate intDelegate; public static void SetStringDelegate (StringDelegate v) { stringDelegate = v; } public static void SetIntDelegate (IntDelegate v) { intDelegate = v; } public static void Dump () { Console.Out.WriteLine (stringDelegate() + " " + intDelegate()); } } /// /// Description of MyClass. /// public class MyClass { public void Dump (int v) { Console.Out.WriteLine ("Got : " + v); AnotherClass.Dump(); AnotherClass.Dump(); } } } from CLR.System.Reflection import Assembly Assembly.LoadWithPartialName("test") from CLR import test def stringFunc(): return "Hello world" def intFunc(): return 0 test.AnotherClass.SetStringDelegate (test.StringDelegate(stringFunc)) test.AnotherClass.SetIntDelegate (test.IntDelegate(intFunc)) t = test.MyClass() t.Dump(2)