Revision: 2500 Author: janne.t.harkonen Date: Mon Feb 22 05:29:43 2010 Log: Moved unic to own module http://code.google.com/p/robotframework/source/detail?r=2500
Added: /trunk/src/robot/utils/unic.py Modified: /trunk/src/robot/utils/robottypes.py ======================================= --- /dev/null +++ /trunk/src/robot/utils/unic.py Mon Feb 22 05:29:43 2010 @@ -0,0 +1,39 @@ +# Copyright 2008-2009 Nokia Siemens Networks Oyj +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +import os +import sys +import types + + +if os.name == 'java': + from java.lang import Object + + def unic(item): + """Convert non-strings to unicode.""" + if isinstance(item, basestring): + return item + if sys.version_info[:2] > (2,2) and isinstance(item, Object): + item = item.toString() + return unicode(item) +else: + def unic(item): + """Convert non-strings to unicode.""" + typ = type(item) + if typ is types.UnicodeType: + return item + if typ is types.StringType: + return item.decode('UTF-8', 'ignore') + return unicode(item) ======================================= --- /trunk/src/robot/utils/robottypes.py Mon Feb 22 03:12:30 2010 +++ /trunk/src/robot/utils/robottypes.py Mon Feb 22 05:29:43 2010 @@ -127,20 +127,3 @@ if printable and _printable_type_mapping.has_key(ret): ret = _printable_type_mapping[ret] return ret - - -def unic(item): - """Convert non-strings to unicode.""" - typ = type(item) - if typ is types.UnicodeType: - return item - if typ is types.StringType: - # There's some weird bug in Jython that requires this to unicode to - # work but this causes other issues........ =/ - if os.name == 'java': - return item - return item.decode('UTF-8', 'ignore') - # Workaround for bug in Jython 2.2a1 - if os.name == 'java' and sys.version_info[:4] == (2,2,0,'alpha'): - return str(item) - return unicode(item)
