def strip_last_filename_from_url(url, sep='/'):
    """Given a url with a filename at the end, strip the last part off of the
    url and return the previous segment. If the seperator can't be located,
    this method will return the unmodified url.

    > strip_last_filename_from_ur("http://utldr.co/s/document.html")
    > "http://utldr.co/s/"

    :param url: The url to trim the filename off of.
    :type url: str.
    :param sep: (optional) Seperator to use when splitting the filename.

    :returns: The url with the last filename chopped off.
    :rtype: str.
    """
    path = ''.join(reversed(url))
    index = path.find(sep)
    if index == -1:
        return url
    return ''.join(reversed(path[index:]))
