← 输入框|github.com|刷新
Skip to content

Crash when using docutils.core.publish_doctree #113

Open

Description

@slide

From @pekkaklarck on September 16, 2015 11:40

I'm trying to use docutils with IronPython. Installation succeeded with pip without problems and running a sample rst file through rst2html.py worked fine too. However, when I try to use publish_doctree programmatically, the whole IronPython process crashes with a dialog saying

IronPython console has stopped working.

and after closing it I got

Process is terminated due to StackOverflowException.

to console. I can reliably reproduce the crash with just this code:

from docutils.core import publish_doctree
publish_doctree("hello\n-----\n")

This is likely related to #1040. The difference is that in my usage rst2html.py worked fine.

Copied from original issue: IronLanguages/main#1230

Activity

  1. self-assigned this
    on Jun 9, 2017
  2. slide commented on Jun 15, 2018

    @slide
    ContributorAuthor

    Here is a reproduction case

    class reprunicode(unicode):
        """
        A unicode sub-class that removes the initial u from unicode's repr.
        """
    
        def __repr__(self):
            return unicode.__repr__(self)[1:]
    
    class Text(reprunicode):
    
        """
        Instances are terminal nodes (leaves) containing text only; no child
        nodes or attributes.  Initialize by passing a string to the constructor.
        Access the text itself with the `astext` method.
        """
    
        tagname = '#text'
    
        def __new__(cls, data, rawsource=None):
            """Prevent the rawsource argument from propagating to str."""
            return reprunicode.__new__(cls, data)
    
        def __init__(self, data, rawsource=''):
            self.rawsource = rawsource
            """The raw text from which this element was constructed."""
    
        def shortrepr(self, maxlen=18):
            data = self
            if len(data) > maxlen:
                data = data[:maxlen-4] + ' ...'
            return '<%s: %r>' % (self.tagname, reprunicode(data))
    
        def __repr__(self):
            return self.shortrepr(maxlen=68)
    
        def __str__(self):
            return unicode(self).encode('raw_unicode_escape')
    
        def astext(self):
            return reprunicode(self)
    
    x = Text(u'This is a test')
    print '%r' % x

    The __str__ method seems to be the issue on IronPython

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions