def getUnicode(value, encoding=None, noneToNull=False):
 if (noneToNull and (value is None)):
  return NULL
 if isinstance(value, unicode):
  return value
 elif isinstance(value, basestring):
  while True:
   try:
    return unicode(value, (encoding or (kb.get('pageEncoding') if kb.get('originalPage') else None) or UNICODE_ENCODING))
   except UnicodeDecodeError as ex:
    try:
     return unicode(value, UNICODE_ENCODING)
    except:
     value = ((value[:ex.start] + ''.join(((INVALID_UNICODE_CHAR_FORMAT % ord(_)) for _ in value[ex.start:ex.end]))) + value[ex.end:])
 elif isListLike(value):
  value = list((getUnicode(_, encoding, noneToNull) for _ in value))
  return value
 else:
  try:
   return unicode(value)
  except UnicodeDecodeError:
   return unicode(str(value), errors='ignore')

def getUnicode ( value , encoding = None , noneToNull = False ) : if ( noneToNull and ( value is None ) ) : return NULL if isinstance ( value , unicode ) : return value elif isinstance ( value , basestring ) : while True : try : return unicode ( value , ( encoding or ( kb . get ( 'pageEncoding' ) if kb . get ( 'originalPage' ) else None ) or UNICODE_ENCODING ) ) except UnicodeDecodeError as ex : try : return unicode ( value , UNICODE_ENCODING ) except : value = ( ( value [ : ex . start ] + '' . join ( ( ( INVALID_UNICODE_CHAR_FORMAT % ord ( _ ) ) for _ in value [ ex . start : ex . end ] ) ) ) + value [ ex . end : ] ) elif isListLike ( value ) : value = list ( ( getUnicode ( _ , encoding , noneToNull ) for _ in value ) ) return value else : try : return unicode ( value ) except UnicodeDecodeError : return unicode ( str ( value ) , errors = 'ignore' )
return the unicode representation of the supplied value: .