def _stringify(value):
 if isinstance(value, (list, tuple)):
  if (len(value) == 1):
   value = _stringify(value[0])
   if (value[0] == '{'):
    value = ('{%s}' % value)
  else:
   value = ('{%s}' % _join(value))
 else:
  if isinstance(value, str):
   value = unicode(value, 'utf-8')
  elif (not isinstance(value, unicode)):
   value = str(value)
  if (not value):
   value = '{}'
  elif _magic_re.search(value):
   value = _magic_re.sub('\\\\\\1', value)
   value = _space_re.sub('\\\\\\1', value)
  elif ((value[0] == '"') or _space_re.search(value)):
   value = ('{%s}' % value)
 return value

def _stringify ( value ) : if isinstance ( value , ( list , tuple ) ) : if ( len ( value ) == 1 ) : value = _stringify ( value [ 0 ] ) if ( value [ 0 ] == '{' ) : value = ( '{%s}' % value ) else : value = ( '{%s}' % _join ( value ) ) else : if isinstance ( value , str ) : value = unicode ( value , 'utf-8' ) elif ( not isinstance ( value , unicode ) ) : value = str ( value ) if ( not value ) : value = '{}' elif _magic_re . search ( value ) : value = _magic_re . sub ( '\\\\\\1' , value ) value = _space_re . sub ( '\\\\\\1' , value ) elif ( ( value [ 0 ] == '"' ) or _space_re . search ( value ) ) : value = ( '{%s}' % value ) return value
internal function .