[reportlab-users] Undeclared dependency on chardet
    Matt Folwell 
    mjf at pearson.co.uk
       
    Thu Nov  9 08:18:10 EST 2023
    
    
  
reportlab/lib/rparsexml.py contains a smartDecode class, which tries to 
import chardet at runtime, but reportlab doesn't declare a dependency on 
chardet, so that gives an error.
Also smartDecode contains what look suspiciously like debugging print() calls.
It first appeared in Reportlab 3.6.12
rparsexml.py is only used by platypus/para.py and I realise para.py doesn't 
get a lot of attention, but it would be nice if it worked in a default 
installation, either by declaring the dependency, or reverting rparsexml.py 
to a version that didn't try to guess at an encoding.
Minimal failing example (the paragraph content has to contain a & or < to 
trigger it):
 >>> from reportlab.platypus.para import Paragraph
 >>> from reportlab.lib.styles import ParagraphStyle
 >>> style = ParagraphStyle("trivial")
 >>> Paragraph("&", style)
initial
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File 
"/home/mjf/.virtualenvs/test/lib/python3.11/site-packages/reportlab/platypus/para.py", 
line 2062, in Paragraph
     parsedpara = rparsexml.parsexmlSimple(text,entityReplacer=None)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File 
"/home/mjf/.virtualenvs/test/lib/python3.11/site-packages/reportlab/lib/rparsexml.py", 
line 115, in parsexmlSimple
     (result, cursor) = parsexml0(xmltext,entityReplacer=entityReplacer)
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   File 
"/home/mjf/.virtualenvs/test/lib/python3.11/site-packages/reportlab/lib/rparsexml.py", 
line 163, in parsexml0
     xmltext = smartDecode(xmltext)
               ^^^^^^^^^^^^^^^^^^^^
   File 
"/home/mjf/.virtualenvs/test/lib/python3.11/site-packages/reportlab/lib/rparsexml.py", 
line 84, in __call__
     import chardet
ModuleNotFoundError: No module named 'chardet'
--
Matt Folwell
    
    
More information about the reportlab-users
mailing list