Skip to content

Commit 5150b01

Browse files
author
Greg Turnquist
committed
Fixed XMLConfig issues.
1 parent 873c0cf commit 5150b01

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/springpython/config/_config_base.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@
2525
from springpython.factory import ReflectiveObjectFactory
2626
from springpython.container import InvalidObjectScope
2727

28+
def get_string(value):
29+
"""This function is used to parse text that could either be ASCII or unicode."""
30+
try:
31+
return str(value)
32+
except UnicodeEncodeError:
33+
return unicode(value)
34+
2835
class ObjectDef(object):
2936
"""
3037
ObjectDef is a format-neutral way of storing object definition information. It includes
@@ -171,7 +178,7 @@ def __init__(self, name, value):
171178

172179
def _replace_refs_with_actuals(self, obj, container):
173180
for i in range(0, len(self.value)):
174-
self.logger.debug("Checking out %s, wondering if I need to do any replacement..." % str(self.value[i]))
181+
self.logger.debug("Checking out %s, wondering if I need to do any replacement..." % get_string(self.value[i]))
175182
if hasattr(self.value[i], "ref"):
176183
self.value[i] = container.get_object(self.value[i].ref)
177184
else:

src/springpython/config/_xml_config.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ def _convert_list(self, list_node, id, name, ns):
480480
self.logger.debug("list: Parsing %s" % list_node)
481481
for element in list_node:
482482
if element.tag == ns+"value":
483-
list.append(str(element.text))
483+
list.append(get_string(element.text))
484484
elif element.tag == ns+"ref":
485485
list.append(self._convert_ref(element, "%s.list[%s]" % (name, len(list))))
486486
elif element.tag == ns+"object":
@@ -502,7 +502,7 @@ def _convert_tuple(self, tuple_node, id, name, ns):
502502
self.logger.debug("tuple: Looking at %s" % element)
503503
if element.tag == ns+"value":
504504
self.logger.debug("tuple: Appending %s" % element.text)
505-
list.append(str(element.text))
505+
list.append(get_string(element.text))
506506
elif element.tag == ns+"ref":
507507
list.append(self._convert_ref(element, "%s.tuple(%s}" % (name, len(list))))
508508
elif element.tag == ns+"object":
@@ -523,7 +523,7 @@ def _convert_set(self, set_node, id, name, ns):
523523
for element in set_node:
524524
self.logger.debug("Looking at element %s" % element)
525525
if element.tag == ns+"value":
526-
s.add(str(element.text))
526+
s.add(get_string(element.text))
527527
elif element.tag == ns+"ref":
528528
s.add(self._convert_ref(element, name + ".set"))
529529
elif element.tag == ns+"object":
@@ -566,14 +566,9 @@ def _convert_prop_def(self, comp, p, name, ns):
566566
return self._convert_ref(p.find(ns+"ref"), name)
567567
elif "value" in p.attrib or p.find(ns+"value") is not None:
568568
if "value" in p.attrib:
569-
return ValueDef(name, str(p.get("value")))
569+
return ValueDef(name, get_string(p.get("value")))
570570
else:
571-
text = p.find(ns+"value").text
572-
try:
573-
text = str(text)
574-
except UnicodeEncodeError, e:
575-
text = unicode(text)
576-
return ValueDef(name, text)
571+
return ValueDef(name, get_string(p.find(ns+"value").text))
577572
elif "dict" in p.attrib or p.find(ns+"dict") is not None:
578573
if "dict" in p.attrib:
579574
return self._convert_dict(p.get("dict"), comp.get("id"), name, ns)

0 commit comments

Comments
 (0)