two points here:

1. `os.path.split` doesn't do what you expect here:

   ```python
   In [1]: os.path.split("/path/to/file")
   Out[1]: ('/path/to', 'file')
   ```

   You want `path.split(os.path.sep)`

2. never use `os.path.join` for writing URLs, use our own `html.utils.url_path_join`.  If `url_encode` is meant to convert file paths to URLs, then it needs to be changed (and should probably be renamed `path2url` or similar). If it is not, then you should stop using it to do this, and write another method.