[reportlab-users] Unicode problem in para.py

Robin Becker robin at reportlab.com
Wed Sep 9 08:23:49 EDT 2009


Michael Egorov wrote:

> I have unicode problem in para.py here:

>

> elif standard.has_key(name):

> fragment = standard[name]+fragment[semi+1:]

> elif greeks.has_key(name):

> fragment = greeks[name]+fragment[semi+1:] # just here

> (line 2041)

>

> It happens because greeks[name] is a string whether fragment is unicode.

> String cannot be converted to unicode if you don't know the encoding.

> To reproduce that you need any character from greeks in text for Para

>

> The patch wich makes it working:

>

> --- platypus/para.py (revision 3542)

> +++ platypus/para.py (working copy)

> @@ -2038,7 +2038,7 @@

> elif standard.has_key(name):

> fragment = standard[name]+fragment[semi+1:]

> elif greeks.has_key(name):

> - fragment = greeks[name]+fragment[semi+1:]

> + fragment = unicode(greeks[name],

> "utf-8")+fragment[semi+1:]

> else:

> # add back the &

> fragment = "&"+fragment

>

> Is it possible to commit that to the main repository somehow?

> How to get a developer access to the reportlab svn?

.......

Logically we have two cases, when fragment is unicode or when fragment is str.
We ought to do all of these additions more carefully in the unicode/str world.
Does this work for you?

--- para.py (revision 3542)
+++ para.py (working copy)
@@ -2036,9 +2036,15 @@
else:
fragment = "&"+fragment
elif standard.has_key(name):
- fragment = standard[name]+fragment[semi+1:]
+ s = standard[name]
+ if isinstance(fragment,unicode):
+ s = s.decode('utf8')
+ fragment = s+fragment[semi+1:]
elif greeks.has_key(name):
- fragment = greeks[name]+fragment[semi+1:]
+ s = greeks[name]
+ if isinstance(fragment,unicode):
+ s = s.decode('utf8')
+ fragment = s+fragment[semi+1:]
else:
# add back the &
fragment = "&"+fragment

I'm not a great user of para.py and it probably doesn't get much attention.
--
Robin Becker


More information about the reportlab-users mailing list