code: def _quote(str, LegalChars=_LegalChars):
      r
      if all(c in LegalChars for c in str):
          return str
      else:
          return '"' + _nulljoin(_Translator.get(s, s) for s in str) + '"'
docs: r"""Quote a string for use in a cookie header.
  
      If the string does not need to be double-quoted, then just return the
      string.  Otherwise, surround the string in doublequotes and quote
      (with a \) special characters.