YUILibrary - Open source JavaScript and CSS for building richly interactive software.
Fork YUI on GitHub

YUI 2.x

Ticket #22 (checkedin defect)

Reporter


kamil t.
Opened: 12/22/08
Last modified: 07/3/09
Status: checkedin
Type: defect
Resolution: fixed

Owner


Adam Moore
Target Release: unspecified
Priority: P3 (normal)
Summary: Non-english / accented characters anywhere in code are causing parser to break
Description:

Test case file attached. If I remove all accented characters then parser will create documentation without problems. If I leave them in any place then it breaks.

<python traceback>

Traceback (most recent call last):
File "c:yuidocbinyuidoc.py", line 104, in <module>
main()
File "c:yuidocbinyuidoc.py", line 86, in main
opts.newext )
File "c:yuidocbinyuidoc_highlight.py", line 82, in __init__
highlightDir(os.path.abspath(i))
File "c:yuidocbinyuidoc_highlight.py", line 68, in highlightDir
highlightFile(path, i)
File "c:yuidocbinyuidoc_highlight.py", line 57, in highlightFile
out.writelines(highlighted)
TypeError: writelines() argument must be a sequence of strings

</python traceback>

My configuration: Windows XP SP3, Python 2.5, all dependencies of YUIDoc installed with easy_install few days ago (so probably up to date).

I can provide more details if necessary, also parser output, if attached file is not enough.

Type: defect Observed in Version: 1.0.0b1
Component: YUIDoc Severity: S3 (normal)
Assigned To: Adam Moore Target Release: unspecified
Location: Example Priority: P3 (normal)
Tags: Relates To:
Browsers: N/A
URL:
Test Information:

Attachments

Attachment #1: accented.js (download)

Change History

botmonster

Posted: 01/15/09

Changing *.js file encoding from utf-8 to something else could somethimes solve problem (depending on what kind of special characters we have in js file)

additional trackback - if we put in line 55 in yuidoc_highlight.py

highlighted = highlightString(fileStr)
print highlighted

we get this error:

Traceback (most recent call last):
File "c:yuidocbinyuidoc.py", line 104, in ?
main()
File "c:yuidocbinyuidoc.py", line 86, in main
opts.newext )
File "c:yuidocbinyuidoc_highlight.py", line 82, in __init__
highlightDir(os.path.abspath(i))
File "c:yuidocbinyuidoc_hi
ghlight.py", line 68, in highlightDir
highlightFile(path, i)
File "c:yuidocbinyuidoc_highlight.py", line 55, in highlightFile
print highlighted
File "C:Python24libencodingscp852.py", line 18, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode characters in position 272-273:
character maps to <undefined>

(I guess that line 42-46 in yuidoc_highlight.py is NOT catching exception properly)

def highlightString(src):
try:
return highlight(src, JavascriptLexer(), HtmlFormatter())
except:
return "File could not be highlighted"

tested on winXP & python 2.4

Lajos Koszti

YUI Contributor

Posted: 01/15/09

Hi,

I downloaded the YUIDoc 1.0.0b1. My files are encoded in utf-8 and I have to use some Hungarian character and when I ran the yuidoc on it I got a similar error.


  1. !python

Traceback (most recent call last):
File "/var/www/yuidoc/bin/yuidoc.py", line 104, in <module>
main()
File "/var/www/yuidoc/bin/yuidoc.py", line 86, in main
opts.newext )
File "/var/www/yuidoc/bin/yuidoc_highlight.py", line 82, in __init__
highlightDir(os.path.abspath(i))
File "/var/www/yuidoc/bin/yuidoc_highlight.py", line 68, in highlightDir
highlightFile(path, i)
File "/var/www/yuidoc/bin/yuidoc_highlight.py", line 57, in highlightFile
out.writelines(highlighted)
TypeError: writelines() argument must be a sequence of strings

For me the following change helped:


  1. !patch

--- ../bin/yuidoc_highlight.py 2008-12-08 08:40:50.000000000 +0100

+++ /var/www/yuidoc/bin/yuidoc_highlight.py 2009-01-15 21:05:38.000000000 +0100

@@ -54,7 +54,14 @@
highlighted = highlightString(fileStr)

out = open(os.path.join(self.outputdir, file + self.newext), "w")
- out.writelines(highlighted)

+ try:

+ out.writelines(highlighted)

+ except:

+ try:

+ out.writelines(str(highlighted))

+ except:

+ out.writelines(highlighted.encode('utf-8'))

+
out.close()

def highlightDir(path):

I'm not so familiar with python, but I hope it will help.

I'm using Debian Lenny.

Adam Moore

YUI Developer

Posted: 02/19/09
  • browser changed to
  • milestone changed to NEXT
  • status changed from new to accepted

Adam Moore

YUI Developer

Posted: 05/18/09
  • resolution changed to fixed
  • status changed from accepted to checkedin

highlight handles high bit characters better. [fixes #22]
View Commit: da22b2bcb970d14163124a125826ed9aca32b845

zhaozexin

Posted: 05/25/09
  • browser changed to N/A

I find out that if source file contains chinese,the generated highlight file would have a wrong encoding。So i modified yuidoc_highlight.py (line 50) into the following:

import codecs
......
fileStr = codecs.open( os.path.join(path, file), "r", "utf-8" ).read()

encoding is correct after modification。

Adam Moore

YUI Developer

Posted: 06/24/09

Fixed utf related highlighter crash [fixes #22]
View Commit: 8829c572fd8238e3621b1925c76665419f9b48b9

Adam Moore

YUI Developer

Posted: 07/2/09

Note: later versions of Cheetah (the template library yuidoc uses) is sometimes throwing an exception when it encounters international characters. If you encounter unicode errors, try downgrading to Cheetah 2.1.0.

Adam Moore

YUI Developer

Posted: 07/3/09

The issue in the previous post has been addressed; it is not necessary to downgrade Cheetah.

Adam Moore

YUI Developer

Posted: 08/11/09

Ticket #2173325 was marked as a duplicate of this ticket.