# Buggy code
def paste(self, parameter_s=""):
    """Paste & execute a pre-formatted code block from clipboard.

    The text is pulled directly from the clipboard without user
    intervention and printed back on the screen before execution (unless
    the -q flag is given to force quiet mode).

    The block is dedented prior to execution to enable execution of method
    definitions. '>' and '+' characters at the beginning of a line are
    ignored, to allow pasting directly from e-mails, diff files and
    doctests (the '...' continuation prompt is also stripped).  The
    executed block is also assigned to variable named 'pasted_block' for
    later editing with '%edit pasted_block'.

    You can also pass a variable name as an argument, e.g. '%paste foo'.
    This assigns the pasted block to variable 'foo' as string, without
    executing it (preceding >>> and + is still stripped).

    Options
    -------

      -r: re-executes the block previously entered by cpaste.

      -q: quiet mode: do not echo the pasted text back to the terminal.

    IPython statements (magics, shell escapes) are not supported (yet).

    See also
    --------
    cpaste: manually paste code into terminal until you mark its end.
    """
    opts, name = self.parse_options(parameter_s, "rq", mode="string")
    if "r" in opts:
        self.rerun_pasted()
        return
    try:
        block = self.shell.hooks.clipboard_get()
    except TryNext as clipboard_exc:
        message = getattr(clipboard_exc, "args")
        if message:
            error(message[0])
        else:
            error("Could not get text from the clipboard.")
        return

    # By default, echo back to terminal unless quiet mode is requested
    if "q" not in opts:
        write = self.shell.write
        write(self.shell.pycolorize(block))
        if not block.endswith("\n"):
            write("\n")
        write("## -- End pasted text --\n")

    self.store_or_execute(block, name)


# 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 paste(self, parameter_s=""):
    """Paste & execute a pre-formatted code block from clipboard.

    The text is pulled directly from the clipboard without user
    intervention and printed back on the screen before execution (unless
    the -q flag is given to force quiet mode).

    The block is dedented prior to execution to enable execution of method
    definitions. '>' and '+' characters at the beginning of a line are
    ignored, to allow pasting directly from e-mails, diff files and
    doctests (the '...' continuation prompt is also stripped).  The
    executed block is also assigned to variable named 'pasted_block' for
    later editing with '%edit pasted_block'.

    You can also pass a variable name as an argument, e.g. '%paste foo'.
    This assigns the pasted block to variable 'foo' as string, without
    executing it (preceding >>> and + is still stripped).

    Options
    -------

      -r: re-executes the block previously entered by cpaste.

      -q: quiet mode: do not echo the pasted text back to the terminal.

    IPython statements (magics, shell escapes) are not supported (yet).

    See also
    --------
    cpaste: manually paste code into terminal until you mark its end.
    """
    opts, name = self.parse_options(parameter_s, "rq", mode="string")
    if "r" in opts:
        self.rerun_pasted()
        return
    try:
        block = self.shell.hooks.clipboard_get()
    except TryNext as clipboard_exc:
        message = getattr(clipboard_exc, "args")
        if message:
            error(message[0])
        else:
            error("Could not get text from the clipboard.")
        return
    except ClipboardEmpty:
        raise UsageError("The clipboard appears to be empty")

    # By default, echo back to terminal unless quiet mode is requested
    if "q" not in opts:
        write = self.shell.write
        write(self.shell.pycolorize(block))
        if not block.endswith("\n"):
            write("\n")
        write("## -- End pasted text --\n")

    self.store_or_execute(block, name)