

@internationalizeDocstring
def encode(self, irc, msg, args, encoding, text):
    '<encoding> <text>\n\n        Returns an encoded form of the given text; the valid encodings are\n        available in the documentation of the Python codecs module:\n        <http://docs.python.org/library/codecs.html#standard-encodings>.\n        '
    if (encoding in 'base64 bz2 hex quopri uu zlib'):
        encoding += '_codec'
    if encoding.endswith('_codec'):
        text = text.encode()
    try:
        encoder = codecs.getencoder(encoding)
    except LookupError:
        irc.errorInvalid(_('encoding'), encoding)
    text = encoder(text)[0]
    if (encoding.endswith('_codec') and (encoding != 'base64_codec')):
        text = codecs.getencoder('base64_codec')(text)[0].decode()
    if (minisix.PY2 and isinstance(text, unicode)):
        text = text.encode('utf-8')
    elif (minisix.PY3 and isinstance(text, bytes)):
        text = text.decode()
    if (encoding in ('base64', 'base64_codec')):
        text = text.replace('\n', '')
    irc.reply(text.rstrip('\n'))

dataset/ETHPy150Open ProgVal/Limnoria/plugins/String/plugin.py String.encode/original