From 1200496c7cd81d0c4d1b59e911351eaed78fff9a Mon Sep 17 00:00:00 2001
From: Gary Williams <gary.williams@forgerock.com>
Date: Tue, 22 Nov 2011 15:52:14 +0000
Subject: [PATCH] Maintain backwards compatability with older version of Jython on Unicode
---
opendj-sdk/opends/tests/staf-tests/shared/python/common.py | 22 +++++++++++++++++++++-
opendj-sdk/opends/tests/staf-tests/shared/functions/utils.xml | 6 ++----
opendj-sdk/opends/tests/staf-tests/shared/functions/environment.xml | 10 +++++-----
3 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/opendj-sdk/opends/tests/staf-tests/shared/functions/environment.xml b/opendj-sdk/opends/tests/staf-tests/shared/functions/environment.xml
index 61837fc..f115f57 100755
--- a/opendj-sdk/opends/tests/staf-tests/shared/functions/environment.xml
+++ b/opendj-sdk/opends/tests/staf-tests/shared/functions/environment.xml
@@ -56,7 +56,7 @@
<iterate var="sharedLib" in="sharedLibs">
<import machine="STAF_LOCAL_HOSTNAME"
- file="'%s/%s' % (TESTS_FUNCTIONS_DIR,sharedLib)" />
+ file="'%s/%s' % (TESTS_FUNCTIONS_DIR,sharedLib)"/>
</iterate>
</sequence>
@@ -66,7 +66,7 @@
<function name="importPythonLibraries">
<function-prolog>
This function imports the Python libraries and objects,
- both starndard and local shared ones.
+ both standard and local shared ones.
</function-prolog>
<sequence>
@@ -76,7 +76,7 @@
import re
import os
import sys
- from org.python.core import PyString,PyUnicode,PyList,PyDictionary
+ from org.python.core import PyString,PyList,PyDictionary
</script>
<!-- Load in any additional Java classes -->
@@ -560,9 +560,9 @@
<script>
STAXLogMessage = 1
</script>
-
+
<call function="'importSharedLibraries'"/>
-
+
<call function="'importPythonLibraries'"/>
<call function="'initialiseGlobalVariables'"/>
diff --git a/opendj-sdk/opends/tests/staf-tests/shared/functions/utils.xml b/opendj-sdk/opends/tests/staf-tests/shared/functions/utils.xml
index a42affe..58a1423 100755
--- a/opendj-sdk/opends/tests/staf-tests/shared/functions/utils.xml
+++ b/opendj-sdk/opends/tests/staf-tests/shared/functions/utils.xml
@@ -298,8 +298,7 @@
</script>
<!-- Check that returnString is really a string or unicode -->
- <if expr='returnString.__class__ is not PyString
- and returnString.__class__ is not PyUnicode'>
+ <if expr='value_not_string(returnString)'>
<sequence>
<message log="1" level="'Error'">
'Invalid returnString type (%s), requires str or unicode.' \
@@ -415,8 +414,7 @@
</script>
<!-- Check that returnString is really a string -->
- <if expr='returnString.__class__ is not PyString
- and returnString.__class__ is not PyUnicode'>
+ <if expr='value_not_string(returnString)'>
<sequence>
<message log="1" level="'Error'">
'ERROR : Invalid returnString type (%s), requires str or unicode.' \
diff --git a/opendj-sdk/opends/tests/staf-tests/shared/python/common.py b/opendj-sdk/opends/tests/staf-tests/shared/python/common.py
index 7f46f4e..2c3299d 100644
--- a/opendj-sdk/opends/tests/staf-tests/shared/python/common.py
+++ b/opendj-sdk/opends/tests/staf-tests/shared/python/common.py
@@ -55,7 +55,8 @@
"list_matches" ,
"count_attr" ,
"host_is_localhost" ,
- "md5_hash"
+ "md5_hash" ,
+ "value_not_string"
]
class format_testcase:
@@ -856,3 +857,22 @@
import md5
m = md5.new()
return m
+
+def value_not_string(value):
+ from org.python.core import PyString,PyList,PyDictionary
+ try:
+ from org.python.core import PyUnicode
+ except ImportError:
+ # Unicode is NOT supported in this version of Jython
+ print "WARNING: Jython version does not support Unicode."
+ if value.__class__ is not PyString:
+ return 1
+ else:
+ return 0
+
+ # Unicode is supported in this version of Jython
+ if value.__class__ is not PyString and value.__class__ is not PyUnicode:
+ return 1
+ else:
+ return 0
+
--
Gitblit v1.10.0