Example #1
0
def test_strip_email():
    src = """\
        >> >>> def f(x):
        >> ...   return x+1
        >> ... 
        >> >>> zz = f(2.5)"""
    cln = """\
>>> def f(x):
...   return x+1
... 
>>> zz = f(2.5)"""
    nt.assert_equals(text.strip_email_quotes(src), cln)
Example #2
0
def test_strip_email():
    src = """\
        >> >>> def f(x):
        >> ...   return x+1
        >> ... 
        >> >>> zz = f(2.5)"""
    cln = """\
>>> def f(x):
...   return x+1
... 
>>> zz = f(2.5)"""
    nt.assert_equal(text.strip_email_quotes(src), cln)
Example #3
0
def test_strip_email():
    src = """\
        >> >>> def f(x):
        >> ...   return x+1
        >> ... 
        >> >>> zz = f(2.5)"""
    cln = """\
>>> def f(x):
...   return x+1
... 
>>> zz = f(2.5)"""
    assert text.strip_email_quotes(src) == cln
Example #4
0
    def cleanup_input(self, block):
        """Apply all possible IPython cleanups to an input block.

        This means:

        - remove any global leading whitespace (dedent)
        - remove any email quotes ('>') if they are present in *all* lines
        - apply all static inputsplitter transforms and break into sub-blocks
        - apply prefilter() to each sub-block that is a single line.

        Parameters
        ----------
        block : str
          A possibly multiline input string of code.

        Returns
        -------
        transformed block : str
          The input, with all transformations above applied.
        """
        # We have to effectively implement client-side the loop that is done by
        # the terminal frontend, and furthermore do it on a block that can
        # possibly contain multiple statments pasted in one go.

        # First, run the input through the block splitting code.  We should
        # eventually make this a self-contained method in the inputsplitter.
        isp = self.input_splitter
        isp.reset()
        b = textwrap.dedent(block)

        # Remove email quotes first.  These must be consistently applied to
        # *all* lines to be removed
        b = strip_email_quotes(b)

        # Split the input into independent sub-blocks so we can later do
        # prefiltering (which must be done *only* to single-line inputs)
        blocks = []
        last_block = []
        for line in b.splitlines():
            isp.push(line)
            last_block.append(line)
            if not isp.push_accepts_more():
                blocks.append(isp.source_reset())
                last_block = []
        if last_block:
            blocks.append('\n'.join(last_block))

        # Now, apply prefiltering to any one-line block to match the behavior
        # of the interactive terminal
        final_blocks = []
        for block in blocks:
            lines = block.splitlines()
            if len(lines) == 1:
                final_blocks.append(self.shell.prefilter(lines[0]))
            else:
                final_blocks.append(block)

        # We now have the final version of the input code as a list of blocks,
        # with all inputsplitter transformations applied and single-line blocks
        # run through prefilter.  For further processing, turn into a single
        # string as the rest of our apis use string inputs.
        return '\n'.join(final_blocks)
Example #5
0
def test_strip_email2():
    src = '> > > list()'
    cln = 'list()'
    nt.assert_equals(text.strip_email_quotes(src), cln)
Example #6
0
 def preclean_input(self, block):
     lines = block.splitlines()
     while lines and not lines[0].strip():
         lines = lines[1:]
     return strip_email_quotes('\n'.join(lines))
Example #7
0
    def cleanup_input(self, block):
        """Apply all possible IPython cleanups to an input block.

        This means:

        - remove any global leading whitespace (dedent)
        - remove any email quotes ('>') if they are present in *all* lines
        - apply all static inputsplitter transforms and break into sub-blocks
        - apply prefilter() to each sub-block that is a single line.

        Parameters
        ----------
        block : str
          A possibly multiline input string of code.

        Returns
        -------
        transformed block : str
          The input, with all transformations above applied.
        """
        # We have to effectively implement client-side the loop that is done by
        # the terminal frontend, and furthermore do it on a block that can
        # possibly contain multiple statments pasted in one go.

        # First, run the input through the block splitting code.  We should
        # eventually make this a self-contained method in the inputsplitter.
        isp = self.input_splitter
        isp.reset()
        b = textwrap.dedent(block)

        # Remove email quotes first.  These must be consistently applied to
        # *all* lines to be removed
        b = strip_email_quotes(b)

        # Split the input into independent sub-blocks so we can later do
        # prefiltering (which must be done *only* to single-line inputs)
        blocks = []
        last_block = []
        for line in b.splitlines():
            isp.push(line)
            last_block.append(line)
            if not isp.push_accepts_more():
                blocks.append(isp.source_reset())
                last_block = []
        if last_block:
            blocks.append('\n'.join(last_block))

        # Now, apply prefiltering to any one-line block to match the behavior
        # of the interactive terminal
        final_blocks = []
        for block in blocks:
            lines = block.splitlines()
            if len(lines) == 1:
                final_blocks.append(self.shell.prefilter(lines[0]))
            else:
                final_blocks.append(block)

        # We now have the final version of the input code as a list of blocks,
        # with all inputsplitter transformations applied and single-line blocks
        # run through prefilter.  For further processing, turn into a single
        # string as the rest of our apis use string inputs.
        return '\n'.join(final_blocks)
Example #8
0
def test_strip_email2():
    src = '> > > list()'
    cln = 'list()'
    nt.assert_equal(text.strip_email_quotes(src), cln)
Example #9
0
 def preclean_input(self, block):
     lines = block.splitlines()
     while lines and not lines[0].strip():
         lines = lines[1:]
     return strip_email_quotes('\n'.join(lines))
Example #10
0
def test_strip_email2():
    src = "> > > list()"
    cln = "list()"
    nt.assert_equal(text.strip_email_quotes(src), cln)
Example #11
0
def test_strip_email2():
    src = "> > > list()"
    cln = "list()"
    assert text.strip_email_quotes(src) == cln
Example #12
0
def test_strip_email2():
    src = '> > > list()'
    cln = 'list()'
    assert text.strip_email_quotes(src) == cln