Django

Code

Changeset 817

Show
Ignore:
Timestamp:
10/09/05 09:40:10 (3 years ago)
Author:
rjwittams
Message:

clean up token parsing for error stuff and removed debug statements.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/new-admin/django/core/template.py

    r802 r817  
    114114        "Compilation stage" 
    115115        self.nodelist = compile_string(template_string, filename) 
    116         from pprint import pprint, pformat 
    117         print "------------------------" 
    118         print filename 
    119         pprint(self.nodelist) 
    120         print "------------------------" 
    121  
     116        
    122117    def __iter__(self): 
    123118        for node in self.nodelist: 
     
    194189            ) 
    195190 
     191def find_linebreaks(template_string): 
     192    for match in newline_re.finditer(template_string): 
     193        yield match.start() 
    196194 
    197195def tokenize(template_string, filename): 
    198196    "Return a list of tokens from a given template_string" 
    199     # remove all empty strings, because the regex has a tendency to add them 
    200     linebreaks = [match.start() for match in newline_re.finditer(template_string)] 
    201     lastline = len(linebreaks) 
     197     
    202198    token_tups = [] 
    203199    upto = 0 
    204200    line = 1 
     201    #TODO:Py2.4 generator expression  
     202    linebreaks = find_linebreaks(template_string) 
     203    next_linebreak = linebreaks.next() 
     204    try: 
     205        for match in tag_re.finditer(template_string): 
     206            start, end = match.span() 
     207            if start > upto: 
     208                token_tups.append( (template_string[upto:start], line) ) 
     209                upto = start 
     210                 
     211                while next_linebreak <= upto: 
     212                    next_linebreak = linebreaks.next() 
     213                    line += 1 
     214             
     215            token_tups.append( (template_string[start:end], line) ) 
     216            upto = end 
    205217     
    206     
    207     for match in tag_re.finditer(template_string): 
    208         start, end = match.span() 
    209         if start > upto: 
    210             token_tups.append( (template_string[upto:start], line) ) 
    211             upto = start 
    212             while linebreaks and line != lastline and linebreaks[line] <= upto: 
     218            while next_linebreak <= upto: 
     219                next_linebreak = linebreaks.next() 
    213220                line += 1 
    214          
    215         token_tups.append( (template_string[start:end], line) ) 
    216         upto = end 
    217          
    218         while linebreaks and line != lastline and linebreaks[line] <= upto: 
    219            line += 1 
     221    except StopIteration: 
     222        pass 
    220223     
    221224    last_bit = template_string[upto:] 
    222225    if len(last_bit): 
    223         token_tups.append( (last_bit, line) ) 
    224   
    225   
     226       token_tups.append( (last_bit, line) ) 
     227     
    226228    return [ create_token(tok, (filename, line)) for tok, line in token_tups] 
    227229 
  • django/branches/new-admin/django/views/admin/main.py

    r802 r817  
    553553        self.needs_add_label = field.rel and isinstance(field.rel, meta.ManyToOne) or isinstance(field.rel, meta.ManyToMany) and field.rel.to.admin 
    554554        self.not_in_table = isinstance(self.field, meta.AutoField) 
    555         self.first = Tru
     555        self.first = Fals
    556556         
    557557        classes = []