| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,4 @@ | |||
| 1 | - | ||
| 2 | - //============================================================================ | ||
| 1 | + //============================================================================ | ||
| 3 | 2 | // This file replaces the hand-maintained stub that used to implement clr.dll. | |
| 4 | 3 | // This is a line-by-line port from IL back to C#. | |
| 5 | 4 | // We now use RGiesecke.DllExport on the required static init method so it can be | |
@@ -25,20 +24,15 @@ | |||
| 25 | 24 | using System; | |
| 26 | 25 | ||
| 27 | 26 | ||
| 28 | - | ||
| 29 | 27 | public class clrModule | |
| 30 | - | ||
| 31 | - | ||
| 32 | 28 | { | |
| 33 | - | ||
| 34 | 29 | #if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35) | |
| 35 | 30 | [RGiesecke.DllExport.DllExport("PyInit_clr", System.Runtime.InteropServices.CallingConvention.StdCall)] | |
| 36 | 31 | public static IntPtr PyInit_clr() | |
| 37 | 32 | #else | |
| 38 | 33 | [RGiesecke.DllExport.DllExport("initclr", System.Runtime.InteropServices.CallingConvention.StdCall)] | |
| 39 | 34 | public static void initclr() | |
| 40 | 35 | #endif | |
| 41 | - | ||
| 42 | 36 | { | |
| 43 | 37 | #if DEBUG_PRINT | |
| 44 | 38 | System.Console.WriteLine("Attempting to load Python.Runtime using standard binding rules... "); | |
@@ -54,12 +48,12 @@ public static void initclr() | |||
| 54 | 48 | // - A PrivateBinPath under ApplicationBase | |
| 55 | 49 | // With an unsigned assembly, the GAC is skipped. | |
| 56 | 50 | var pythonRuntimeName = new System.Reflection.AssemblyName("Python.Runtime") | |
| 57 | - { | ||
| 51 | + { | ||
| 58 | 52 | #if USE_PYTHON_RUNTIME_VERSION | |
| 59 | - Version = new System.Version("4.0.0.1"), | ||
| 53 | + Version = new System.Version("4.0.0.1"), | ||
| 60 | 54 | #endif | |
| 61 | - CultureInfo = System.Globalization.CultureInfo.InvariantCulture, | ||
| 62 | - }; | ||
| 55 | + CultureInfo = System.Globalization.CultureInfo.InvariantCulture, | ||
| 56 | + }; | ||
| 63 | 57 | #if USE_PYTHON_RUNTIME_PUBLIC_KEY_TOKEN | |
| 64 | 58 | pythonRuntimeName.SetPublicKeyToken(pythonRuntimePublicKeyTokenData); | |
| 65 | 59 | #endif | |
@@ -77,13 +71,13 @@ public static void initclr() | |||
| 77 | 71 | try | |
| 78 | 72 | { | |
| 79 | 73 | // If the above fails for any reason, we fallback to attempting to load "Python.Runtime.dll" | |
| 80 | - // from the directory this assembly is running in. "This assembly" is probably "clr.pyd", | ||
| 81 | - // sitting somewhere in PYTHONPATH. This is using Assembly.LoadFrom, and inherits all the | ||
| 82 | - // caveats of that call. See MSDN docs for details. | ||
| 83 | - // Suzanne Cook's blog is also an excellent source of info on this: | ||
| 84 | - // http://blogs.msdn.com/suzcook/ | ||
| 85 | - // http://blogs.msdn.com/suzcook/archive/2003/05/29/57143.aspx | ||
| 86 | - // http://blogs.msdn.com/suzcook/archive/2003/06/13/57180.aspx | ||
| 74 | + // from the directory this assembly is running in. "This assembly" is probably "clr.pyd", | ||
| 75 | + // sitting somewhere in PYTHONPATH. This is using Assembly.LoadFrom, and inherits all the | ||
| 76 | + // caveats of that call. See MSDN docs for details. | ||
| 77 | + // Suzanne Cook's blog is also an excellent source of info on this: | ||
| 78 | + // http://blogs.msdn.com/suzcook/ | ||
| 79 | + // http://blogs.msdn.com/suzcook/archive/2003/05/29/57143.aspx | ||
| 80 | + // http://blogs.msdn.com/suzcook/archive/2003/06/13/57180.aspx | ||
| 87 | 81 | ||
| 88 | 82 | var executingAssembly = System.Reflection.Assembly.GetExecutingAssembly(); | |
| 89 | 83 | var assemblyDirectory = System.IO.Path.GetDirectoryName(executingAssembly.Location); | |
@@ -95,7 +89,8 @@ public static void initclr() | |||
| 95 | 89 | #endif | |
| 96 | 90 | pythonRuntime = System.Reflection.Assembly.LoadFrom(pythonRuntimeDllPath); | |
| 97 | 91 | } | |
| 98 | - catch (System.InvalidOperationException) { | ||
| 92 | + catch (System.InvalidOperationException) | ||
| 93 | + { | ||
| 99 | 94 | #if DEBUG_PRINT | |
| 100 | 95 | System.Console.WriteLine("Could not load Python.Runtime, so sad."); | |
| 101 | 96 | #endif | |
@@ -108,7 +103,7 @@ public static void initclr() | |||
| 108 | 103 | } | |
| 109 | 104 | ||
| 110 | 105 | // Once here, we've successfully loaded SOME version of Python.Runtime | |
| 111 | - // So now we get the PythonEngine and execute the InitExt method on it. | ||
| 106 | + // So now we get the PythonEngine and execute the InitExt method on it. | ||
| 112 | 107 | var pythonEngineType = pythonRuntime.GetType("Python.Runtime.PythonEngine"); | |
| 113 | 108 | ||
| 114 | 109 | #if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35) | |
@@ -117,4 +112,4 @@ public static void initclr() | |||
| 117 | 112 | pythonEngineType.InvokeMember("InitExt", System.Reflection.BindingFlags.InvokeMethod, null, null, null); | |
| 118 | 113 | #endif | |
| 119 | 114 | } | |
| 120 | - } | ||
| 115 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,9 +2,10 @@ | |||
| 2 | 2 | using System.Runtime.CompilerServices; | |
| 3 | 3 | using System.Runtime.InteropServices; | |
| 4 | 4 | ||
| 5 | - // General Information about an assembly is controlled through the following | ||
| 5 | + // General Information about an assembly is controlled through the following | ||
| 6 | 6 | // set of attributes. Change these attribute values to modify the information | |
| 7 | 7 | // associated with an assembly. | |
| 8 | + | ||
| 8 | 9 | [assembly: AssemblyTitle("clrmodule")] | |
| 9 | 10 | [assembly: AssemblyDescription("")] | |
| 10 | 11 | [assembly: AssemblyConfiguration("")] | |
@@ -14,23 +15,26 @@ | |||
| 14 | 15 | [assembly: AssemblyTrademark("")] | |
| 15 | 16 | [assembly: AssemblyCulture("")] | |
| 16 | 17 | ||
| 17 | - // Setting ComVisible to false makes the types in this assembly not visible | ||
| 18 | - // to COM components. If you need to access a type in this assembly from | ||
| 18 | + // Setting ComVisible to false makes the types in this assembly not visible | ||
| 19 | + // to COM components. If you need to access a type in this assembly from | ||
| 19 | 20 | // COM, set the ComVisible attribute to true on that type. | |
| 21 | + | ||
| 20 | 22 | [assembly: ComVisible(false)] | |
| 21 | 23 | ||
| 22 | 24 | // The following GUID is for the ID of the typelib if this project is exposed to COM | |
| 25 | + | ||
| 23 | 26 | [assembly: Guid("ae10d6a4-55c2-482f-9716-9988e6c169e3")] | |
| 24 | 27 | ||
| 25 | 28 | // Version information for an assembly consists of the following four values: | |
| 26 | 29 | // | |
| 27 | 30 | // Major Version | |
| 28 | - // Minor Version | ||
| 31 | + // Minor Version | ||
| 29 | 32 | // Build Number | |
| 30 | 33 | // Revision | |
| 31 | 34 | // | |
| 32 | - // You can specify all the values or you can default the Build and Revision Numbers | ||
| 35 | + // You can specify all the values or you can default the Build and Revision Numbers | ||
| 33 | 36 | // by using the '*' as shown below: | |
| 34 | 37 | // [assembly: AssemblyVersion("1.0.*")] | |
| 38 | + | ||
| 35 | 39 | [assembly: AssemblyVersion("1.0.0.0")] | |
| 36 | 40 | [assembly: AssemblyFileVersion("1.0.0.0")] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | 1 | <?xml version="1.0" encoding="utf-8"?> | |
| 2 | + | ||
| 2 | 3 | <packages> | |
| 3 | 4 | <package id="UnmanagedExports" version="1.2.6" targetFramework="net40" /> | |
| 4 | 5 | </packages> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,7 @@ | |||
| 1 | 1 | <?xml version="1.0"?> | |
| 2 | + | ||
| 2 | 3 | <configuration> | |
| 3 | - <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration> | ||
| 4 | + <startup> | ||
| 5 | + <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" /> | ||
| 6 | + </startup> | ||
| 7 | + </configuration> | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,3 @@ | |||
| 1 | - | ||
| 2 | 1 | using System; | |
| 3 | 2 | using System.Reflection; | |
| 4 | 3 | using System.Security.Permissions; | |
@@ -11,11 +10,9 @@ | |||
| 11 | 10 | [assembly: AssemblyDefaultAliasAttribute("python.exe")] | |
| 12 | 11 | [assembly: CLSCompliant(true)] | |
| 13 | 12 | [assembly: ComVisible(false)] | |
| 14 | - | ||
| 15 | - | ||
| 16 | - [assembly:PermissionSetAttribute(SecurityAction.RequestMinimum, | ||
| 17 | - Name = "FullTrust")] | ||
| 13 | + [assembly: PermissionSetAttribute(SecurityAction.RequestMinimum, | ||
| 14 | + Name = "FullTrust")] | ||
| 18 | 15 | [assembly: AssemblyDescriptionAttribute("")] | |
| 19 | 16 | [assembly: AssemblyCopyrightAttribute("Zope Public License, Version 2.0 (ZPL)")] | |
| 20 | 17 | [assembly: AssemblyFileVersionAttribute("2.0.0.4")] | |
| 21 | - [assembly: NeutralResourcesLanguageAttribute("en")] | ||
| 18 | + [assembly: NeutralResourcesLanguageAttribute("en")] | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,64 +1,69 @@ | |||
| 1 | - | ||
| 2 | 1 | using System; | |
| 3 | 2 | using System.Reflection; | |
| 4 | 3 | using System.Collections.Generic; | |
| 5 | 4 | using Python.Runtime; | |
| 6 | 5 | ||
| 7 | - namespace Python.Runtime { | ||
| 8 | - | ||
| 9 | - public sealed class PythonConsole { | ||
| 10 | - | ||
| 11 | - private PythonConsole() {} | ||
| 12 | - | ||
| 13 | - [STAThread] | ||
| 14 | - public static int Main(string[] args) { | ||
| 15 | - // reference the static assemblyLoader to stop it being optimized away | ||
| 16 | - AssemblyLoader a = assemblyLoader; | ||
| 6 | + namespace Python.Runtime | ||
| 7 | + { | ||
| 8 | + public sealed class PythonConsole | ||
| 9 | + { | ||
| 10 | + private PythonConsole() | ||
| 11 | + { | ||
| 12 | + } | ||
| 17 | 13 | ||
| 18 | - string [] cmd = Environment.GetCommandLineArgs(); | ||
| 19 | - PythonEngine.Initialize(); | ||
| 14 | + [STAThread] | ||
| 15 | + public static int Main(string[] args) | ||
| 16 | + { | ||
| 17 | + // reference the static assemblyLoader to stop it being optimized away | ||
| 18 | + AssemblyLoader a = assemblyLoader; | ||
| 20 | 19 | ||
| 21 | - int i = Runtime.Py_Main(cmd.Length, cmd); | ||
| 22 | - PythonEngine.Shutdown(); | ||
| 20 | + string[] cmd = Environment.GetCommandLineArgs(); | ||
| 21 | + PythonEngine.Initialize(); | ||
| 23 | 22 | ||
| 24 | - return i; | ||
| 25 | - } | ||
| 23 | + int i = Runtime.Py_Main(cmd.Length, cmd); | ||
| 24 | + PythonEngine.Shutdown(); | ||
| 26 | 25 | ||
| 27 | - // Register a callback function to load embedded assmeblies. | ||
| 28 | - // (Python.Runtime.dll is included as a resource) | ||
| 29 | - private sealed class AssemblyLoader { | ||
| 30 | - Dictionary<string, Assembly> loadedAssemblies; | ||
| 26 | + return i; | ||
| 27 | + } | ||
| 31 | 28 | ||
| 32 | - public AssemblyLoader() { | ||
| 33 | - loadedAssemblies = new Dictionary<string, Assembly>(); | ||
| 29 | + // Register a callback function to load embedded assmeblies. | ||
| 30 | + // (Python.Runtime.dll is included as a resource) | ||
| 31 | + private sealed class AssemblyLoader | ||
| 32 | + { | ||
| 33 | + Dictionary<string, Assembly> loadedAssemblies; | ||
| 34 | 34 | ||
| 35 | - AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => { | ||
| 36 | - string shortName = args.Name.Split(',')[0]; | ||
| 37 | - String resourceName = shortName + ".dll"; | ||
| 35 | + public AssemblyLoader() | ||
| 36 | + { | ||
| 37 | + loadedAssemblies = new Dictionary<string, Assembly>(); | ||
| 38 | 38 | ||
| 39 | - if (loadedAssemblies.ContainsKey(resourceName)) { | ||
| 40 | - return loadedAssemblies[resourceName]; | ||
| 41 | - } | ||
| 39 | + AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => | ||
| 40 | + { | ||
| 41 | + string shortName = args.Name.Split(',')[0]; | ||
| 42 | + String resourceName = shortName + ".dll"; | ||
| 42 | 43 | ||
| 43 | - // looks for the assembly from the resources and load it | ||
| 44 | - using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) { | ||
| 45 | - if (stream != null) { | ||
| 46 | - Byte[] assemblyData = new Byte[stream.Length]; | ||
| 47 | - stream.Read(assemblyData, 0, assemblyData.Length); | ||
| 48 | - Assembly assembly = Assembly.Load(assemblyData); | ||
| 49 | - loadedAssemblies[resourceName] = assembly; | ||
| 50 | - return assembly; | ||
| 44 | + if (loadedAssemblies.ContainsKey(resourceName)) | ||
| 45 | + { | ||
| 46 | + return loadedAssemblies[resourceName]; | ||
| 51 | 47 | } | |
| 52 | - } | ||
| 53 | 48 | ||
| 54 | - return null; | ||
| 55 | - }; | ||
| 56 | - } | ||
| 57 | - }; | ||
| 58 | - | ||
| 59 | - private static AssemblyLoader assemblyLoader = new AssemblyLoader(); | ||
| 60 | - | ||
| 61 | - }; | ||
| 49 | + // looks for the assembly from the resources and load it | ||
| 50 | + using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) | ||
| 51 | + { | ||
| 52 | + if (stream != null) | ||
| 53 | + { | ||
| 54 | + Byte[] assemblyData = new Byte[stream.Length]; | ||
| 55 | + stream.Read(assemblyData, 0, assemblyData.Length); | ||
| 56 | + Assembly assembly = Assembly.Load(assemblyData); | ||
| 57 | + loadedAssemblies[resourceName] = assembly; | ||
| 58 | + return assembly; | ||
| 59 | + } | ||
| 60 | + } | ||
| 62 | 61 | ||
| 62 | + return null; | ||
| 63 | + }; | ||
| 64 | + } | ||
| 65 | + }; | ||
| 63 | 66 | ||
| 64 | - } | ||
| 67 | + private static AssemblyLoader assemblyLoader = new AssemblyLoader(); | ||
| 68 | + }; | ||
| 69 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | 1 | <?xml version="1.0" encoding="utf-8"?> | |
| 2 | + | ||
| 2 | 3 | <packages> | |
| 3 | 4 | <package id="NUnit" version="2.6.2" targetFramework="net40" /> | |
| 4 | 5 | </packages> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,7 +20,7 @@ public void SetUp() | |||
| 20 | 20 | //string here = Environment.CurrentDirectory; | |
| 21 | 21 | //trunk\pythonnet\src\embed_tests\bin\x86\DebugWin | |
| 22 | 22 | ||
| 23 | - /* | ||
| 23 | + /* | ||
| 24 | 24 | * Append the tests directory to sys.path | |
| 25 | 25 | * using reflection to circumvent the private modifires placed on most Runtime methods. | |
| 26 | 26 | */ | |
@@ -29,19 +29,21 @@ public void SetUp() | |||
| 29 | 29 | Type RTClass = typeof(Runtime.Runtime); | |
| 30 | 30 | ||
| 31 | 31 | /* pyStrPtr = PyString_FromString(s); */ | |
| 32 | - MethodInfo PyString_FromString = RTClass.GetMethod("PyString_FromString", BindingFlags.NonPublic | BindingFlags.Static); | ||
| 32 | + MethodInfo PyString_FromString = RTClass.GetMethod("PyString_FromString", | ||
| 33 | + BindingFlags.NonPublic | BindingFlags.Static); | ||
| 33 | 34 | object[] funcArgs = new object[1]; | |
| 34 | 35 | funcArgs[0] = s; | |
| 35 | 36 | IntPtr pyStrPtr = (IntPtr)PyString_FromString.Invoke(null, funcArgs); | |
| 36 | 37 | ||
| 37 | 38 | /* SysDotPath = sys.path */ | |
| 38 | - MethodInfo PySys_GetObject = RTClass.GetMethod("PySys_GetObject", BindingFlags.NonPublic | BindingFlags.Static); | ||
| 39 | + MethodInfo PySys_GetObject = RTClass.GetMethod("PySys_GetObject", | ||
| 40 | + BindingFlags.NonPublic | BindingFlags.Static); | ||
| 39 | 41 | funcArgs[0] = "path"; | |
| 40 | 42 | IntPtr SysDotPath = (IntPtr)PySys_GetObject.Invoke(null, funcArgs); | |
| 41 | 43 | ||
| 42 | 44 | /* SysDotPath.append(*pyStrPtr) */ | |
| 43 | 45 | MethodInfo PyList_Append = RTClass.GetMethod("PyList_Append", BindingFlags.NonPublic | BindingFlags.Static); | |
| 44 | - funcArgs = new object[] {SysDotPath, pyStrPtr}; | ||
| 46 | + funcArgs = new object[] { SysDotPath, pyStrPtr }; | ||
| 45 | 47 | int r = (int)PyList_Append.Invoke(null, funcArgs); | |
| 46 | 48 | } | |
| 47 | 49 | ||
@@ -57,7 +59,7 @@ public void TearDown() | |||
| 57 | 59 | /// </summary> | |
| 58 | 60 | /// <remarks> | |
| 59 | 61 | /// The required directory structure was added to the \trunk\pythonnet\src\tests directory: | |
| 60 | - /// | ||
| 62 | + /// | ||
| 61 | 63 | /// PyImportTest/ | |
| 62 | 64 | /// __init__.py | |
| 63 | 65 | /// test/ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,9 +35,9 @@ public void TestOnPyList() | |||
| 35 | 35 | foreach (PyObject item in list) | |
| 36 | 36 | result.Add(item.ToString()); | |
| 37 | 37 | Assert.AreEqual(3, result.Count); | |
| 38 | - Assert.AreEqual("foo",result[0]); | ||
| 39 | - Assert.AreEqual("bar",result[1]); | ||
| 40 | - Assert.AreEqual("baz",result[2]); | ||
| 38 | + Assert.AreEqual("foo", result[0]); | ||
| 39 | + Assert.AreEqual("bar", result[1]); | ||
| 40 | + Assert.AreEqual("baz", result[2]); | ||
| 41 | 41 | } | |
| 42 | 42 | } | |
| 43 | - } | ||
| 43 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,7 +27,7 @@ public void TearDown() | |||
| 27 | 27 | public void TestUnicode() | |
| 28 | 28 | { | |
| 29 | 29 | PyObject s = new PyString("foo\u00e9"); | |
| 30 | - Assert.AreEqual("foo\u00e9",s.ToString()); | ||
| 30 | + Assert.AreEqual("foo\u00e9", s.ToString()); | ||
| 31 | 31 | } | |
| 32 | 32 | } | |
| 33 | - } | ||
| 33 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments