def _asFilesystemBytes(path, encoding=None):
    """
    Return C{path} as a string of L{bytes} suitable for use on this system's
    filesystem.

    @param path: The path to be made suitable.
    @type path: L{bytes} or L{unicode}
    @param encoding: The encoding to use if coercing to L{bytes}. If none is
        given, L{sys.getfilesystemencoding} is used.

    @return: L{bytes}
    """
    if type(path) == bytes:
        return path
    else:
        if encoding is None:
            encoding = sys.getfilesystemencoding()
        return path.encode(encoding)

    Return C{path} as a string of L{bytes} suitable for use on this system's
    filesystem.

    @param path: The path to be made suitable.
    @type path: L{bytes} or L{unicode}
    @param encoding: The encoding to use if coercing to L{bytes}. If none is
        given, L{sys.getfilesystemencoding} is used.

    @return: L{bytes}
    
stackoverflow/venv/lib/python3.6/site-packages/twisted/python/filepath.py