question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Py3k error with "unicode" identifier in dotted_toc extension

See original GitHub issue

I’ve seen port to py3K is in progress, thanks a lot for that!

Just in case, I tried launching my pdf build on today’s rst2pdf github master, under python3.7.3, it failed due to this line:

Traceback (most recent call last):
  File "....a\lib\site-packages\reportlab\platypus\flowables.py", line
700, in wrap
    W,H = _listWrapOn(self._content,aW,self.canv,dims=dims)
  File "....\lib\site-packages\reportlab\platypus\flowables.py", line
624, in _listWrapOn
    w,h = f.wrapOn(canv,availWidth,0xfffffff)
  File "....\lib\site-packages\reportlab\platypus\flowables.py", line
125, in wrapOn
    w, h = self.wrap(aW,aH)
  File "....\lib\site-packages\rst2pdf\extensions\dotted_toc.py", line 137, in wrap
    if not isinstance(text, unicode):
NameError: name 'unicode' is not defined

Maybe there is a need for a global search-replace of “unicode” with six utility, to batch-solve this kind?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
tbpassincommented, Nov 21, 2019

Here’s a simple way around this problem, along with a couple of others )Ihave found in the code:

# rst2pdf hacks for python 3+
unicode = type(str) # all strings in Python 3 are unicode.
unichr = chr # Python 3 equivalent.
basestring = str # see https://www.atemon.com/blog/python-3-unexpected-exception-name-basestring-is-not-defined-when-invoking-ansible2/

Add these statements to the top of the module that is failing, after the imports. Better would be to make these definitions conditional on the Python version, something like this:

try:
   basestring
except NameError:
   basestring = str
0reactions
lornajanecommented, May 21, 2020

I think we’re fully python3 compatible at this point so this should be solved. Going to close but if anyone has more information please do comment!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot open text files in Python 3: Unicode error
In your first example, file_path = "c:\Users\username\Documents\folder1\some_file.txt" The \U in \Users represents a Unicode escape sequence ...
Read more >
C/C++ extension does not work with Unicode identifiers #2034
I use Unicode identifiers everywhere in my C++ code. It is well supported in Visual Studio. There are some bugs with syntax highlighting...
Read more >
Unicode Objects and Codecs — Python 3.11.1 documentation
This function checks that unicode is a Unicode object and the index is not out of bounds, in contrast to PyUnicode_READ_CHAR() , which...
Read more >
UAX #31: Unicode Identifier and Pattern Syntax
A common task facing an implementer of the Unicode Standard is the provision of a parsing and/or lexing engine for identifiers, such as ......
Read more >
Unicode & Character Encodings in Python: A Painless Guide
Unicode vs UTF-8; Encoding and Decoding in Python 3; Python 3: All-In on ... Most of these constants should be self-documenting in their...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found