#215 --stylesheet and --stylesheet-path options broken


--stylesheet and --stylesheet-path options in Docutils 0.10 are broken with Python 2. This bug does not occur with Python 3.

$ PYTHONPATH="." python2.7 tools/buildhtml.py --stylesheet-path=docutils/writers/html4css1/html4css1.css
buildhtml.py [options] [<directory> ...]

buildhtml.py: error: Error in option "--stylesheet-path":
AttributeError: 'str' object has no attribute 'pop'


  • Arfrever

    Arfrever - 2012-12-30
  • Arfrever

    Arfrever - 2012-12-30

    The attached patch fixes this bug.

  • engelbert gruber

    fixed only validate_comma_separated_list
    replacing isinstance(value, unicode) with hasattr(value, 'pop')

    buildhtml calls this function 5 times with unicode once with str


    a) use isinstacne or hasattr ?
    b) how to test for this in python3, where "a" is unicode too ?
    c) is buildhtmls usage correct ?

    therefore still open

  • engelbert gruber

    • assigned_to: nobody --> grubert
    • status: open --> open-fixed
  • Arfrever

    Arfrever - 2013-01-01

    The original patch was tested successfully with both Python 2 and 3. You need to set PYTHONPATH correctly:
    $ rm -fr build
    $ python3.3 setup.py build
    $ PYTHONPATH="build/lib" python3.3 tools/buildhtml.py --stylesheet-path=docutils/writers/html4css1/html4css1.css

    A. isinstance() is the recommended way to test types of variables.
    B. setup.py runs 2to3 on docutils and test directories. Converted files are placed in ${build_directory}/lib/docutils (e.g. build/lib/docutils) and test3 directories. 2to3 replaces both unicode and basestring with str.

    $ echo "isinstance(value, unicode)" | 2to3 - 2>/dev/null
    --- <stdin> (original)
    +++ <stdin> (refactored)
    @@ -1 +1 @@
    -isinstance(value, unicode)
    +isinstance(value, str)
    $ echo "isinstance(value, basestring)" | 2to3 - 2>/dev/null
    --- <stdin> (original)
    +++ <stdin> (refactored)
    @@ -1 +1 @@
    -isinstance(value, basestring)
    +isinstance(value, str)

    C. Yes.

  • Arfrever

    Arfrever - 2013-01-01

    By the way, a unicode type is named "str" in Python 3:
    str in Python 2 == bytes in Python 3
    unicode in Python 2 == str in Python 3

    $ python2.7 -c 'print(type("a"))'
    <type 'str'>
    $ python2.7 -c 'print(type(b"a"))'
    <type 'str'>
    $ python2.7 -c 'print(type(u"a"))'
    <type 'unicode'>
    $ python3.3 -c 'print(type(b"a"))'
    <class 'bytes'>
    $ python3.3 -c 'print(type("a"))'
    <class 'str'>

  • engelbert gruber

    • status: open-fixed --> closed-fixed

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks