Ticket #10440: trac_10440_scripts_repo.patch

File trac_10440_scripts_repo.patch, 1.6 KB (added by ddrake, 9 years ago)

apply to scripts repo

  • sage-preparse

    # HG changeset patch
    # User Dan Drake <drake@kaist.edu>
    # Date 1291783547 -32400
    # Node ID e8012ae4d242f1375f864de0e3606dc0427f3b21
    # Parent  69dab430f8c416b0aa27d1e416d0fae7697b0046
    fix preparsing of files with an encoding declaration (trac 10440)
    
    diff --git a/sage-preparse b/sage-preparse
    a b  
    66    -- William Stein (2005): first version
    77    -- William Stein (2008): fix trac #2391 and document the code.
    88    -- Dan Drake (2009): fix trac #5052
     9    -- Dan Drake (2010-12-08): fix trac #10440
    910"""
    1011
    1112import os, sys, re
     
    104105    # Finally open the file
    105106    F = open(f).read()
    106107
    107     #Check to see if a coding is specified in the .sage file.
    108     #If it is, then we want to copy it over to the new file
    109     #and not include it in the preprocessing
    110     if F.startswith('# -*- coding:'):
    111         end = F.find('\n')
    112         coding = F[:end+1] if end != -1 else F
    113         F = F[len(coding):]
    114     else:
    115         coding = ''
     108    # Check to see if a coding is specified in the .sage file. If it is,
     109    # then we want to copy it over to the new file and not include it in
     110    # the preprocessing. If both the first and second line have an
     111    # encoding declaration, the second line's encoding will get used.
     112
     113    lines = F.splitlines()
     114    coding = ''
     115    for num, line in enumerate(lines[:2]):
     116        if re.search(r"coding[:=]\s*([-\w.]+)", line):
     117            coding = line + '\n'
     118            F = '\n'.join(lines[:num] + lines[(num+1):])
    116119
    117120    # Preparse it
    118121    from sage.misc.preparser  import preparse_file