def elem_quote(member, nonquote=True, stringify=False, encoding=None):
 if (not isinstance(member, basestring)):
  if stringify:
   member = str(member)
  else:
   raise TypeError(('Can only quote strings. "%s"' % str(member)))
 if (encoding and isinstance(member, str)):
  member = unicode(member, encoding)
 if ('\n' in member):
  raise QuoteError(('Multiline values can\'t be quoted.\n"%s"' % str(member)))
 if (nonquote and (badchars.match(member) is not None)):
  return member
 elif (member.find('"') == (-1)):
  return ('"%s"' % member)
 elif (member.find("'") == (-1)):
  return ("'%s'" % member)
 else:
  raise QuoteError(('Value can\'t be quoted : "%s"' % member))

def elem_quote ( member , nonquote = True , stringify = False , encoding = None ) : if ( not isinstance ( member , basestring ) ) : if stringify : member = str ( member ) else : raise TypeError ( ( 'Can only quote strings. "%s"' % str ( member ) ) ) if ( encoding and isinstance ( member , str ) ) : member = unicode ( member , encoding ) if ( '\n' in member ) : raise QuoteError ( ( 'Multiline values can\'t be quoted.\n"%s"' % str ( member ) ) ) if ( nonquote and ( badchars . match ( member ) is not None ) ) : return member elif ( member . find ( '"' ) == ( - 1 ) ) : return ( '"%s"' % member ) elif ( member . find ( "'" ) == ( - 1 ) ) : return ( "'%s'" % member ) else : raise QuoteError ( ( 'Value can\'t be quoted : "%s"' % member ) )
simple method to add the most appropriate quote to an element - either single quotes or double quotes .