1
0
mirror of https://github.com/django/django.git synced 2025-07-05 10:19:20 +00:00

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

git-svn-id: http://code.djangoproject.com/svn/django/branches/new-admin@817 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Robert Wittams 2005-10-09 14:40:10 +00:00
parent 0442a5440a
commit f114e652e3
2 changed files with 28 additions and 26 deletions

View File

@ -113,11 +113,6 @@ class Template:
def __init__(self, template_string, filename=UNKNOWN_SOURCE):
"Compilation stage"
self.nodelist = compile_string(template_string, filename)
from pprint import pprint, pformat
print "------------------------"
print filename
pprint(self.nodelist)
print "------------------------"
def __iter__(self):
for node in self.nodelist:
@ -193,35 +188,42 @@ class Token:
self.source[0], self.source[1]
)
def find_linebreaks(template_string):
for match in newline_re.finditer(template_string):
yield match.start()
def tokenize(template_string, filename):
"Return a list of tokens from a given template_string"
# remove all empty strings, because the regex has a tendency to add them
linebreaks = [match.start() for match in newline_re.finditer(template_string)]
lastline = len(linebreaks)
token_tups = []
upto = 0
line = 1
#TODO:Py2.4 generator expression
linebreaks = find_linebreaks(template_string)
next_linebreak = linebreaks.next()
try:
for match in tag_re.finditer(template_string):
start, end = match.span()
if start > upto:
token_tups.append( (template_string[upto:start], line) )
upto = start
while next_linebreak <= upto:
next_linebreak = linebreaks.next()
line += 1
for match in tag_re.finditer(template_string):
start, end = match.span()
if start > upto:
token_tups.append( (template_string[upto:start], line) )
upto = start
while linebreaks and line != lastline and linebreaks[line] <= upto:
token_tups.append( (template_string[start:end], line) )
upto = end
while next_linebreak <= upto:
next_linebreak = linebreaks.next()
line += 1
token_tups.append( (template_string[start:end], line) )
upto = end
while linebreaks and line != lastline and linebreaks[line] <= upto:
line += 1
except StopIteration:
pass
last_bit = template_string[upto:]
if len(last_bit):
token_tups.append( (last_bit, line) )
token_tups.append( (last_bit, line) )
return [ create_token(tok, (filename, line)) for tok, line in token_tups]

View File

@ -552,7 +552,7 @@ class AdminBoundField(BoundField):
self.is_file_field = isinstance(field, meta.FileField)
self.needs_add_label = field.rel and isinstance(field.rel, meta.ManyToOne) or isinstance(field.rel, meta.ManyToMany) and field.rel.to.admin
self.not_in_table = isinstance(self.field, meta.AutoField)
self.first = True
self.first = False
classes = []
if(self.raw_id_admin):