# Buggy code
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:
        from tkinter import Tk  # Py 3
    except ImportError:
        try:
            from Tkinter import Tk  # Py 2
        except ImportError:
            raise TryNext(
                "Getting text from the clipboard on this platform requires Tkinter."
            )
    root = Tk()
    root.withdraw()
    text = root.clipboard_get()
    root.destroy()
    text = py3compat.cast_unicode(text, py3compat.DEFAULT_ENCODING)
    return text


# Traceback (TypeError)
In [1]: %paste
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-86b9186405a3> in <module>()
----> 1 get_ipython().magic('paste')

/usr/local/lib/python3.3/site-packages/IPython/core/interactiveshell.py in magic(self, arg_s)
2135         magic_name, _, magic_arg_s = arg_s.partition(' ')
2136         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2137         return self.run_line_magic(magic_name, magic_arg_s)
2138
2139     #-------------------------------------------------------------------------

/usr/local/lib/python3.3/site-packages/IPython/core/interactiveshell.py in run_line_magic(self, magic_name, line)
2061                 args.append(sys._getframe(stack_depth).f_locals)
2062             with self.builtin_trap:
-> 2063                 result = fn(*args)
2064             return result
2065

/usr/local/lib/python3.3/site-packages/IPython/frontend/terminal/interactiveshell.py in paste(self, parameter_s)

/usr/local/lib/python3.3/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
190     # but it's overkill for just that one bit of state.
191     def magic_deco(arg):
--> 192         call = lambda f, *a, **k: f(*a, **k)
193
194         if isinstance(arg, collections.Callable):

/usr/local/lib/python3.3/site-packages/IPython/frontend/terminal/interactiveshell.py in paste(self, parameter_s)
282         if 'q' not in opts:
283             write = self.shell.write
--> 284             write(self.shell.pycolorize(block))
285             if not block.endswith('\n'):
286                 write('\n')

/usr/local/lib/python3.3/site-packages/IPython/core/interactiveshell.py in <lambda>(src)
575         # Python source parser/formatter for syntax highlighting
576         pyformat = PyColorize.Parser().format
--> 577         self.pycolorize = lambda src: pyformat(src,'str',self.colors)
578
579     def init_pushd_popd_magic(self):

/usr/local/lib/python3.3/site-packages/IPython/utils/PyColorize.py in format(self, raw, out, scheme)
127
128     def format(self, raw, out = None, scheme = ''):
--> 129         return self.format2(raw, out, scheme)[0]
130
131     def format2(self, raw, out = None, scheme = ''):

/usr/local/lib/python3.3/site-packages/IPython/utils/PyColorize.py in format2(self, raw, out, scheme)
174         lines_append = self.lines.append
175         while 1:
--> 176             pos = raw_find('\n', pos) + 1
177             if not pos: break
178             lines_append(pos)

TypeError: Type str doesn't support the buffer API

# Fixed code
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:
        from tkinter import Tk, TclError  # Py 3
    except ImportError:
        try:
            from Tkinter import Tk, TclError  # Py 2
        except ImportError:
            raise TryNext(
                "Getting text from the clipboard on this platform requires Tkinter."
            )
    root = Tk()
    root.withdraw()
    try:
        text = root.clipboard_get()
    except TclError:
        raise ClipboardEmpty
    finally:
        root.destroy()
    text = py3compat.cast_unicode(text, py3compat.DEFAULT_ENCODING)
    return text