[Jython-checkins] jython (2.5): Move java imports out of functions for pep8 and perf.
frank.wierzbicki
jython-checkins at python.org
Fri Jul 27 23:27:45 CEST 2012
http://hg.python.org/jython/rev/005b97117ae9
changeset: 6813:005b97117ae9
branch: 2.5
parent: 6810:f9ccaa02aa02
user: Frank Wierzbicki <fwierzbicki at gmail.com>
date: Fri Jul 27 14:00:25 2012 -0700
summary:
Move java imports out of functions for pep8 and perf.
files:
Lib/decimal.py | 8 ++++++++
Lib/isql.py | 6 ++++--
Lib/platform.py | 6 ++++--
Lib/test/test_decimal_jy.py | 19 +++++++++++++++++++
4 files changed, 35 insertions(+), 4 deletions(-)
diff --git a/Lib/decimal.py b/Lib/decimal.py
--- a/Lib/decimal.py
+++ b/Lib/decimal.py
@@ -392,6 +392,14 @@
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:
diff --git a/Lib/isql.py b/Lib/isql.py
--- a/Lib/isql.py
+++ b/Lib/isql.py
@@ -1,5 +1,8 @@
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.
@@ -24,9 +27,8 @@
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
diff --git a/Lib/platform.py b/Lib/platform.py
--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -111,6 +111,10 @@
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)'
@@ -623,8 +627,6 @@
def _java_getprop(name,default):
- from java.lang import System
- from org.python.core.Py import newString
try:
return newString(System.getProperty(name))
except:
diff --git a/Lib/test/test_decimal_jy.py b/Lib/test/test_decimal_jy.py
new file mode 100644
--- /dev/null
+++ b/Lib/test/test_decimal_jy.py
@@ -0,0 +1,19 @@
+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()
--
Repository URL: http://hg.python.org/jython
More information about the Jython-checkins
mailing list