def xcode(text, encoding="utf8", mode="ignore"):
    """
    Converts unicode encoding to str

    >>> xcode(b'hello')
    b'hello'
    >>> xcode('hello')
    b'hello'
    """
    return text.encode(encoding, mode) if isinstance(text, str) else text