Added precompiled regexp for commentfile parsing

This commit is contained in:
Stefan Ritter 2009-12-10 15:19:31 +01:00
parent c4b4c138c2
commit 59b3fe4272

View File

@ -22,7 +22,9 @@ import cgi, os, time, glob, re, md5, sys, random, smtplib
import ConfigParser import ConfigParser
# A wonderful place for doing some regexp ;) # A wonderful place for doing some regexp ;)
no_break = re.compile('^\s*(<ul|</ul>|<li|</li>|<ol|</ol>|<table|</table>|<tr|</tr>|<td|</td>|<th|</th>|<p|</p>).*$') no_break = re.compile('^\s*(<ul|</ul>|<li|</li>|<ol|</ol>|<table|</table>|<tr|</tr>|<td|</td>|<th|</th>|<p|</p>).*$')
line_start_hyphen = re.compile('^-.*$')
line_start_plus = re.compile('^\+.*$')
def generate_uuid(string): def generate_uuid(string):
string_md5sum = md5.new(string).hexdigest() string_md5sum = md5.new(string).hexdigest()
@ -374,7 +376,7 @@ else:
print ' <div class="months_list">' print ' <div class="months_list">'
print ' <ul class="months_list">' print ' <ul class="months_list">'
for entry in entries: for entry in entries:
date = time.strftime("%m%Y", entry[0]) date = time.strftime("%m%Y", entry[0])
date_display = time.strftime("%h %Y", entry[0]) date_display = time.strftime("%h %Y", entry[0])
if not olddate == date: if not olddate == date:
print ' <li class="months_list_entry"><a href="?m=' + date + '" class="months_list_entry">' + date_display + '</a></li>' print ' <li class="months_list_entry"><a href="?m=' + date + '" class="months_list_entry">' + date_display + '</a></li>'
@ -409,6 +411,7 @@ else:
print ' <div class="entries">' print ' <div class="entries">'
print '' print ''
# Staticpage # Staticpage
if static_display != "": if static_display != "":
content = open(staticpages_dir + static_display, "r") content = open(staticpages_dir + static_display, "r")
@ -417,7 +420,7 @@ else:
print ' <div class="entry_content">' print ' <div class="entry_content">'
print ' <p>' print ' <p>'
for line in content: for line in content:
if re.match(no_break, line): if no_break.match(line):
print ' ' + line.strip() print ' ' + line.strip()
else: else:
print ' ' + line.strip() + '<br />' print ' ' + line.strip() + '<br />'
@ -431,6 +434,7 @@ else:
print ' </div>' print ' </div>'
print '' print ''
content.close() content.close()
# Entry # Entry
else: else:
entry_counter = 0 entry_counter = 0
@ -453,7 +457,7 @@ else:
print ' <div class="entry_date">' + date + '</div>' print ' <div class="entry_date">' + date + '</div>'
print ' <div class="entry_content">' print ' <div class="entry_content">'
for line in content: for line in content:
if re.match(no_break, line): if no_break.match(line):
print ' ' + line.strip() print ' ' + line.strip()
else: else:
print ' ' + line.strip() + '<br />' print ' ' + line.strip() + '<br />'
@ -480,7 +484,7 @@ else:
label_count = 0 label_count = 0
for line in comments_content: for line in comments_content:
if re.search("^-", line): if line_start_hyphen.match(line):
if notfirstline == 1: if notfirstline == 1:
print ' </div>' print ' </div>'
print ' </div>' print ' </div>'
@ -492,7 +496,7 @@ else:
print ' <a name="' + str(label_count) + '"></a>' print ' <a name="' + str(label_count) + '"></a>'
print ' <div class="comment_author">' + line.split(".", 1)[1].strip() + '</div>' print ' <div class="comment_author">' + line.split(".", 1)[1].strip() + '</div>'
elif re.search("^\+", line): elif line_start_plus.match(line):
print ' <div class="comment_date">' + line.split(".", 1)[1].strip() + '</div>' print ' <div class="comment_date">' + line.split(".", 1)[1].strip() + '</div>'
print ' <div class="comment_content">' print ' <div class="comment_content">'
else: else: