Fix filename handling in IPython tracebacks

* Only replace filename by the value of __file__ if the latter is an
  existing text file (this fixes tracebacks for Cython files).
* When making a relative filename absolute, try to make it absolute
  w.r.t. the sys.path entries instead of the current working directory.
* Still try to display source lines for binary files, you never know
  what linecache got from that file. Skip only the reading of names,
  but display the traceback as usual.

See also downstream Sage ticket
http://trac.sagemath.org/ticket/17382
My use case is Cython code, which also uses *relative* paths for its tracebacks. This actually makes sense, since Cython cannot know at runtime where it's source file are stored.

I'm simply copying the mechanism that linecache uses to find the source code. Without my patch, you can end up in a situation where the *right* source code lines are displayed in the traceback but with the *wrong* filename on top.

Assuming that `sys.path[0] == ''`, my code is a generalisation of the old code. If os.path.abspath(file) exists, it will be found like before.