@classmethod
def normalize_url_path(cls, url_path):
    """
        Given a URL path, possibly empty, return a path consisting
        only of directory components. The URL path must end with a
        trailing slash for the last path element to be considered a
        directory. Also the URL path must begin with a slash. Empty
        input returns '/'.

        Examples:

        ''          -> '/'
        '/'         -> '/'
        'foo'       -> '/'
        'foo/'      -> '/'
        '/foo       -> '/'
        '/foo/'     -> '/foo'
        '/foo/bar'  -> '/foo'
        '/foo/bar/' -> '/foo/bar'
        """
    url_path = url_path.lower()
    if not url_path:
        return '/'
    if not url_path.startswith('/'):
        return '/'
    if url_path.count('/') <= 1:
        return '/'
    return url_path[:url_path.rindex('/')]
