Discretion in quote-closing a completed dict key

This pertains to #5304 and the issue noted there by @takluyver. It takes a fairly maximal approach.

This PR distinguishes a completion request from a readline frontend to those triggered otherwise. It avoids an explicit endquote in the readline case.

I have managed to test it with:
* local console
* `--existing` console
* notebook

I do not have qt set up to test there.

@takluyver, WDYT?

(I am yet to add a unit test with `from_readline=True`.)