code: def encode(self, encoding='utf-8', errors='strict'):
          
          from future.types.newbytes import newbytes
          # Py2 unicode.encode() takes encoding and errors as optional parameter,
          # not keyword arguments as in Python 3 str.
  
          # For the surrogateescape error handling mechanism, the
          # codecs.register_error() function seems to be inadequate for an
          # implementation of it when encoding. (Decoding seems fine, however.)
          # For example, in the case of
          #     u'\udcc3'.encode('ascii', 'surrogateescape_handler')
          # after registering the ``surrogateescape_handler`` function in
          # future.utils.surrogateescape, both Python 2.x and 3.x raise an
          # exception anyway after the function is called because the unicode
          # string it has to return isn't encodable strictly as ASCII.
  
          if errors == 'surrogateescape':
              if encoding == 'utf-16':
                  # Known to fail here. See test_encoding_works_normally()
                  raise NotImplementedError('FIXME: surrogateescape handling is '
                                            'not yet implemented properly')
              # Encode char by char, building up list of byte-strings
              mybytes = []
              for c in self:
                  code = ord(c)
                  if 0xD800 <= code <= 0xDCFF:
                      mybytes.append(newbytes([code - 0xDC00]))
                  else:
                      mybytes.append(c.encode(encoding=encoding))
              return newbytes(b'').join(mybytes)
          return newbytes(super(newstr, self).encode(encoding, errors))
docs: Returns bytes
  
          Encode S using the codec registered for encoding. Default encoding
          is 'utf-8'. errors may be given to set a different error
          handling scheme. Default is 'strict' meaning that encoding errors raise
          a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
          'xmlcharrefreplace' as well as any other name registered with
          codecs.register_error that can handle UnicodeEncodeErrors.