def canonicalize_path(path):
    """Canonicalizes a potential path.

    Returns a binary string encoded into filesystem encoding.
    """
    if isinstance(path, six.binary_type):
        return path
    if isinstance(path, six.text_type):
        return _fsencode(path)
    else:
        return canonicalize_path(str(path))