Commits

Frank Wierzbicki committed 005b971

Move java imports out of functions for pep8 and perf.

Comments (0)

Files changed (4)

     del sys, MockThreading
 
 try:
+    from java.lang import Object
+    from java.math import BigDecimal
+    from org.python.core import Py
+except ImportError:
+    #Not Jython, ignore.
+    pass
+
+try:
     threading.local
 
 except AttributeError:
 import dbexts, cmd, sys, os
 
+if sys.platform.startswith("java"):
+    import java.lang.String
+
 """
 Isql works in conjunction with dbexts to provide an interactive environment
 for database work.
         if len(self.isql.sqlbuffer) > 0:
             prompt = "... "
         return prompt
-    if os.name == 'java':
+    if sys.platform.startswith("java"):
         def __tojava__(self, cls):
-            import java.lang.String
             if cls == java.lang.String:
                 return self.__str__()
             return False
 
 import sys,string,os,re
 
+if sys.platform.startswith("java"):
+    from java.lang import System
+    from org.python.core.Py import newString
+
 ### Platform specific APIs
 
 _libc_search = re.compile(r'(__libc_init)'
 
 def _java_getprop(name,default):
 
-    from java.lang import System
-    from org.python.core.Py import newString
     try:
         return newString(System.getProperty(name))
     except:

Lib/test/test_decimal_jy.py

+import unittest
+from test import test_support
+
+from decimal import Decimal
+
+from java.math import BigDecimal
+
+
+class TestJavaDecimal(unittest.TestCase):
+
+    def test_decimal(self):
+        self.assertTrue(hasattr(Decimal, "__tojava__"))
+        x = Decimal("1.1")
+        y = x.__tojava__(BigDecimal)
+        self.assertTrue(isinstance(y, BigDecimal))
+
+
+if __name__ == '__main__':
+    unittest.main()