##// END OF EJS Templates
Merge pull request #2432 from bfroehle/revert_1831...
Merge pull request #2432 from bfroehle/revert_1831 Revert #1831, the `__file__` injection in safe_execfile / safe_execfile_ipy. This reverts commit 2717feb, reversing changes made to ea4f608. Pull request #1831 (fix #1814 set __file__ when running .ipy files) has been the source of a lot of grief: #2279: Setting __file__ to None breaks Mayavi import #2429: Using warnings.warn() results in TypeError In general the patch was inappropriate because it: 1. Fails to properly restore the context, by setting __file__ to None rather than deleting it. 2. Sets __file__ in the wrong dictionary (self.user_ns rather than where[0]).

File last commit:

r8308:0c7f867c
r8509:d3d37a3a merge
Show More
clipboard.py
56 lines | 1.7 KiB | text/x-python | PythonLexer
""" Utilities for accessing the platform's clipboard.
"""
import subprocess
import sys
from IPython.core.error import TryNext
import IPython.utils.py3compat as py3compat
def win32_clipboard_get():
""" Get the current clipboard's text on Windows.
Requires Mark Hammond's pywin32 extensions.
"""
try:
import win32clipboard
except ImportError:
raise TryNext("Getting text from the clipboard requires the pywin32 "
"extensions: http://sourceforge.net/projects/pywin32/")
win32clipboard.OpenClipboard()
text = win32clipboard.GetClipboardData(win32clipboard.CF_TEXT)
# FIXME: convert \r\n to \n?
win32clipboard.CloseClipboard()
return text
def osx_clipboard_get():
""" Get the clipboard's text on OS X.
"""
p = subprocess.Popen(['pbpaste', '-Prefer', 'ascii'],
stdout=subprocess.PIPE)
text, stderr = p.communicate()
# Text comes in with old Mac \r line endings. Change them to \n.
text = text.replace('\r', '\n')
text = py3compat.cast_unicode(text, py3compat.DEFAULT_ENCODING)
return text
def tkinter_clipboard_get():
""" Get the clipboard's text using Tkinter.
This is the default on systems that are not Windows or OS X. It may
interfere with other UI toolkits and should be replaced with an
implementation that uses that toolkit.
"""
try:
import Tkinter
except ImportError:
raise TryNext("Getting text from the clipboard on this platform "
"requires Tkinter.")
root = Tkinter.Tk()
root.withdraw()
text = root.clipboard_get()
root.destroy()
text = py3compat.cast_unicode(text, py3compat.DEFAULT_ENCODING)
return text