Re: Line Ending Woes in .js files when using Athena

Jean-Paul Calderone <[email protected]> Wed, 6 Jun 2007 07:04:39 -0400
Newsgroups gmane.comp.python.quotient.dev
Message-ID <20070606110439.30678.833187926.divmod.quotient.11521@ohm>
On Wed, 06 Jun 2007 10:01:35 +0200, Werner Thie <[email protected]> wrote:
>Hi all
>
>Just spent a few extra hours debugging a problem which manifested itself as 
>a well running code on MSW and same code throwing on **IX.
>
>The problem was eventually tracked back to having its source in the regexp 
>used for extracting the imported modules out of the .js file when using 
>statements of the form
>
>// import Nevow.Athena
>
>If those files are stored with a MSW/DOS line endings (0x0d, 0x0a), the 
>regexp
>
>_importExpression = re.compile('^// import (.+)$', re.MULTILINE)
>
>in line 175 of athena.py delivers back an additional '\r' at the end of the 
>isolated 'Nevow.Athena', thus preventing the lookup of the module in the 
>CachedFile.load() function in util.py which throws a KeyError in this case.
>
>The short solution is to save .js files with **IX line endings (0x0a) 
>exclusively.
>
>I am not that fluent in speaking regexps; is somebody out there listening, 
>which knows how to massage the regexp or would the solution be doing a
>
>strip(r'\r')
>
>on the generated keys.
>

Another solution would be for _getDeps to open the file in 'rU' mode,
which would have Python get rid of the \r bytes.  If you file a ticket
(<http://divmod.org/trac/newticket> - you'll need an account) for this
I'll try to take care of it (if you attach a patch with a unit test and
the fix, then it'll be really easy for me to take care of ;).

Jean-Paul