| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f682e3f commit b123d58
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -221,30 +221,40 @@ public static Assembly LoadAssemblyPath(string name) { | |||
| 221 | 221 | // Call ONLY for namespaces that HAVE NOT been cached yet. | |
| 222 | 222 | //=================================================================== | |
| 223 | 223 | ||
| 224 | - public static bool LoadImplicit(string name, out bool fromFile) { | ||
| 225 | - // 2010-08-16: Deprecation support | ||
| 226 | - // Added out param to detect fully qualified name load | ||
| 227 | - fromFile = false; | ||
| 224 | + public static bool LoadImplicit(string name, bool warn=true) { | ||
| 228 | 225 | string[] names = name.Split('.'); | |
| 229 | 226 | bool loaded = false; | |
| 230 | 227 | string s = ""; | |
| 228 | + Assembly lastAssembly = null; | ||
| 229 | + HashSet<Assembly> assemblies = null; | ||
| 231 | 230 | for (int i = 0; i < names.Length; i++) { | |
| 232 | 231 | s = (i == 0) ? names[0] : s + "." + names[i]; | |
| 233 | 232 | if (!probed.ContainsKey(s)) { | |
| 234 | - if (LoadAssemblyPath(s) != null) { | ||
| 235 | - loaded = true; | ||
| 233 | + if (assemblies == null) { | ||
| 234 | + assemblies = new HashSet<Assembly>(AppDomain.CurrentDomain.GetAssemblies()); | ||
| 235 | + } | ||
| 236 | + Assembly a = LoadAssemblyPath(s); | ||
| 237 | + if (a == null) { | ||
| 238 | + a = LoadAssembly(s); | ||
| 236 | 239 | } | |
| 237 | - else if (LoadAssembly(s) != null) { | ||
| 240 | + if (a != null && !assemblies.Contains(a)) { | ||
| 238 | 241 | loaded = true; | |
| 242 | + lastAssembly = a; | ||
| 239 | 243 | } | |
| 240 | 244 | probed[s] = 1; | |
| 241 | - // 2010-12-24: Deprecation logic | ||
| 242 | - if (loaded && (s == name)) { | ||
| 243 | - fromFile = true; | ||
| 244 | - //break; | ||
| 245 | - } | ||
| 246 | 245 | } | |
| 247 | 246 | } | |
| 247 | + | ||
| 248 | + // Deprecation warning | ||
| 249 | + if (warn && loaded) | ||
| 250 | + { | ||
| 251 | + string deprWarning = String.Format( | ||
| 252 | + "\nThe module was found, but not in a referenced namespace.\n" + | ||
| 253 | + "Implicit loading is deprecated. Please use clr.AddReference(\"{0}\").", | ||
| 254 | + Path.GetFileNameWithoutExtension(lastAssembly.Location)); | ||
| 255 | + Exceptions.deprecation(deprWarning); | ||
| 256 | + } | ||
| 257 | + | ||
| 248 | 258 | return loaded; | |
| 249 | 259 | } | |
| 250 | 260 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -156,15 +156,7 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw) { | |||
| 156 | 156 | ||
| 157 | 157 | AssemblyManager.UpdatePath(); | |
| 158 | 158 | if (!AssemblyManager.IsValidNamespace(realname)) { | |
| 159 | - bool fromFile = false; | ||
| 160 | - if (AssemblyManager.LoadImplicit(realname, out fromFile)) { | ||
| 161 | - if (true == fromFile) { | ||
| 162 | - string deprWarning = String.Format("\nThe module was found, but not in a referenced namespace.\n" + | ||
| 163 | - "Implicit loading is deprecated. Please use clr.AddReference(\"{0}\").", realname); | ||
| 164 | - Exceptions.deprecation(deprWarning); | ||
| 165 | - } | ||
| 166 | - } | ||
| 167 | - else | ||
| 159 | + if (!AssemblyManager.LoadImplicit(realname)) | ||
| 168 | 160 | { | |
| 169 | 161 | // May be called when a module being imported imports a module. | |
| 170 | 162 | // In particular, I've seen decimal import copy import org.python.core | |
@@ -174,7 +166,6 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw) { | |||
| 174 | 166 | ||
| 175 | 167 | // See if sys.modules for this interpreter already has the | |
| 176 | 168 | // requested module. If so, just return the exising module. | |
| 177 | - | ||
| 178 | 169 | IntPtr modules = Runtime.PyImport_GetModuleDict(); | |
| 179 | 170 | IntPtr module = Runtime.PyDict_GetItem(modules, py_mod_name); | |
| 180 | 171 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -109,14 +109,8 @@ public ManagedType GetAttribute(string name, bool guess) { | |||
| 109 | 109 | // thing happens with implicit assembly loading at a reasonable | |
| 110 | 110 | // cost. Ask the AssemblyManager to do implicit loading for each | |
| 111 | 111 | // of the steps in the qualified name, then try it again. | |
| 112 | - bool fromFile; | ||
| 113 | - if (AssemblyManager.LoadImplicit(qname, out fromFile)) { | ||
| 114 | - bool ignore = name.StartsWith("__"); | ||
| 115 | - if (true == fromFile && (!ignore)) { | ||
| 116 | - string deprWarning = String.Format("\nThe module was found, but not in a referenced namespace.\n" + | ||
| 117 | - "Implicit loading is deprecated. Please use clr.AddReference(\"{0}\").", qname); | ||
| 118 | - Exceptions.deprecation(deprWarning); | ||
| 119 | - } | ||
| 112 | + bool ignore = name.StartsWith("__"); | ||
| 113 | + if (AssemblyManager.LoadImplicit(qname, !ignore)) { | ||
| 120 | 114 | if (AssemblyManager.IsValidNamespace(qname)) { | |
| 121 | 115 | m = new ModuleObject(qname); | |
| 122 | 116 | StoreAttribute(name, m); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,6 @@ | |||
| 9 | 9 | ||
| 10 | 10 | using System; | |
| 11 | 11 | using System.Collections; | |
| 12 | - using System.Windows.Forms; | ||
| 13 | 12 | ||
| 14 | 13 | namespace Python.Test { | |
| 15 | 14 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,6 @@ | |||
| 8 | 8 | // ========================================================================== | |
| 9 | 9 | ||
| 10 | 10 | using System; | |
| 11 | - using System.Windows.Forms; | ||
| 12 | 11 | ||
| 13 | 12 | namespace Python.Test { | |
| 14 | 13 | ||
@@ -21,22 +20,6 @@ namespace Python.Test { | |||
| 21 | 20 | ||
| 22 | 21 | public class EventTest { | |
| 23 | 22 | ||
| 24 | - | ||
| 25 | - public void WinFormTest() { | ||
| 26 | - EventTest e = new EventTest(); | ||
| 27 | - EventHandler h = new EventHandler(e.ClickHandler); | ||
| 28 | - | ||
| 29 | - Form f = new Form(); | ||
| 30 | - f.Click += h; | ||
| 31 | - //f.Click(null, new EventArgs()); | ||
| 32 | - f.Click -= h; | ||
| 33 | - } | ||
| 34 | - | ||
| 35 | - public void ClickHandler(object sender, EventArgs e) { | ||
| 36 | - Console.WriteLine("click"); | ||
| 37 | - } | ||
| 38 | - | ||
| 39 | - | ||
| 40 | 23 | public static event TestEventHandler PublicStaticEvent; | |
| 41 | 24 | ||
| 42 | 25 | protected static event TestEventHandler ProtectedStaticEvent; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,6 @@ | |||
| 9 | 9 | ||
| 10 | 10 | using System; | |
| 11 | 11 | using System.Collections; | |
| 12 | - using System.Windows.Forms; | ||
| 13 | 12 | ||
| 14 | 13 | namespace Python.Test { | |
| 15 | 14 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,6 @@ | |||
| 6 | 6 | # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | |
| 7 | 7 | # FOR A PARTICULAR PURPOSE. | |
| 8 | 8 | # =========================================================================== | |
| 9 | - | ||
| 10 | 9 | from System.Collections import Hashtable | |
| 11 | 10 | from Python.Test import ClassTest | |
| 12 | 11 | import sys, os, string, unittest, types | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,14 +6,13 @@ | |||
| 6 | 6 | # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS | |
| 7 | 7 | # FOR A PARTICULAR PURPOSE. | |
| 8 | 8 | # =========================================================================== | |
| 9 | - | ||
| 10 | 9 | import clr | |
| 11 | 10 | clr.AddReference('Python.Test') | |
| 12 | 11 | clr.AddReference('System.Data') | |
| 13 | 12 | ||
| 14 | 13 | # testImplicitAssemblyLoad() passes on deprecation warning; perfect! # | |
| 15 | 14 | ##clr.AddReference('System.Windows.Forms') | |
| 16 | - import sys, os, string, unittest, types | ||
| 15 | + import sys, os, string, unittest, types, warnings | ||
| 17 | 16 | ||
| 18 | 17 | ||
| 19 | 18 | class ModuleTests(unittest.TestCase): | |
@@ -42,8 +41,8 @@ def test000importClr(self): | |||
| 42 | 41 | def testPreloadVar(self): | |
| 43 | 42 | import clr | |
| 44 | 43 | self.assertTrue(clr.getPreload() is False, clr.getPreload()) | |
| 45 | - clr.setPreload(False) | ||
| 46 | - self.assertTrue(clr.getPreload() is False, clr.getPreload()) | ||
| 44 | + clr.setPreload(False) | ||
| 45 | + self.assertTrue(clr.getPreload() is False, clr.getPreload()) | ||
| 47 | 46 | try: | |
| 48 | 47 | clr.setPreload(True) | |
| 49 | 48 | self.assertTrue(clr.getPreload() is True, clr.getPreload()) | |
@@ -204,27 +203,25 @@ def testFromModuleImportStar(self): | |||
| 204 | 203 | ||
| 205 | 204 | def testImplicitAssemblyLoad(self): | |
| 206 | 205 | """Test implicit assembly loading via import.""" | |
| 207 | - # this test only applies to windows | ||
| 208 | - if sys.platform != "win32": | ||
| 209 | - return | ||
| 210 | - | ||
| 211 | - def test(): | ||
| 212 | - # This should fail until System.Windows.Forms has been | ||
| 213 | - # imported or that assembly has been explicitly loaded. | ||
| 214 | - # True for Windows; Not so for Mono 2.8.1 | ||
| 215 | - import System.Windows | ||
| 216 | - | ||
| 217 | - # The test fails when the project is compiled with MS VS 2005. Dunno why :( | ||
| 218 | - # Fails (as expected) on Late Binding model. Works as expected on an interactive sesson. | ||
| 219 | - self.assertRaises(ImportError, test) | ||
| 220 | - | ||
| 221 | - clr.AddReference("System.Windows.Forms") | ||
| 222 | - import System.Windows.Forms as Forms | ||
| 223 | - self.assertTrue(self.isCLRModule(Forms)) | ||
| 224 | - self.assertTrue(Forms.__name__ == 'System.Windows.Forms') | ||
| 225 | - from System.Windows.Forms import Form | ||
| 226 | - self.assertTrue(self.isCLRClass(Form)) | ||
| 227 | - self.assertTrue(Form.__name__ == 'Form') | ||
| 206 | + with warnings.catch_warnings(record=True) as w: | ||
| 207 | + warnings.simplefilter("always") | ||
| 208 | + | ||
| 209 | + # should trigger a DeprecationWarning as Microsoft.Build hasn't | ||
| 210 | + # been added as a reference yet (and should exist for mono) | ||
| 211 | + import Microsoft.Build | ||
| 212 | + | ||
| 213 | + self.assertEqual(len(w), 1) | ||
| 214 | + self.assertTrue(isinstance(w[0].message, DeprecationWarning)) | ||
| 215 | + | ||
| 216 | + with warnings.catch_warnings(record=True) as w: | ||
| 217 | + clr.AddReference("System.Windows.Forms") | ||
| 218 | + import System.Windows.Forms as Forms | ||
| 219 | + self.assertTrue(self.isCLRModule(Forms)) | ||
| 220 | + self.assertTrue(Forms.__name__ == 'System.Windows.Forms') | ||
| 221 | + from System.Windows.Forms import Form | ||
| 222 | + self.assertTrue(self.isCLRClass(Form)) | ||
| 223 | + self.assertTrue(Form.__name__ == 'Form') | ||
| 224 | + self.assertEqual(len(w), 0) | ||
| 228 | 225 | ||
| 229 | 226 | ||
| 230 | 227 | def testExplicitAssemblyLoad(self): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments