def unicode2bytes(x, encoding='utf-8', errors='strict'):
    """
    Convert a unicode string to C{bytes}.

    @param x: a unicode string, of type C{unicode} on Python 2,
              or C{str} on Python 3.
    @param encoding: an optional codec, default: 'utf-8'
    @param errors: error handling scheme, default 'strict'
    @return: a string of type C{bytes}
    """
    if isinstance(x, text_type):
        x = x.encode(encoding, errors)
    return x