Code cleanup:

* Removed some regexp
* Using String Formatting Operation to fill 1byte string with '0'
This commit is contained in:
Stefan Ritter 2009-12-02 12:19:30 +01:00
parent e2b597fc1b
commit 31b7b41d65

View File

@ -125,8 +125,8 @@ if static_display: static_display = re.sub('/', '', static_display)
post_display = action.getvalue('p')
if post_display:
post_display = re.sub(' ', '-', post_display)
post_display = re.sub('/', '', post_display)
post_display = post_display.replace(' ', '-') \
.replace('/', '')
allentries_display = action.getvalue('a')
feed_display = action.getvalue('feed')
@ -151,12 +151,12 @@ if not cquizv: cquizv = ""
# Comment to commit?
if cname and ctext and ctitle:
# Prevent XSS hacks
cname = cname.replace("<", "&lt;") \
.replace(">", "&gt;") \
.replace("\"", "&quot;")
ctext = ctext.replace("<", "&lt;") \
.replace(">", "&gt;") \
.replace("\"", "&quot;")
cname = cname.replace('<', '&lt;') \
.replace('>', '&gt;') \
.replace('\'', '&quot;')
ctext = ctext.replace('<', '&lt;') \
.replace('>', '&gt;') \
.replace('\'', '&quot;')
# Add comment
if not cquiz == cquizv:
@ -169,7 +169,6 @@ if cname and ctext and ctitle:
content.close()
except:
errorpage(entries_dir, 'isn\'t writable!')
comments_file = glob.glob(entries_dir + ctitle + '.comments')
try:
content = open(comments_file[0], "a+")
content.write("-." + cname + "\n")
@ -209,17 +208,12 @@ if feed_display == "atom":
blog_title_md5sum = generate_uuid(blog_title)
title_md5sum = generate_uuid(title)
# Atom needs a 2byte string
month = str(date[1])
day = str(date[2])
hour = str(date[3])
min = str(date[4])
sec = str(date[5])
if len(str(date[1])) == 1: month = '0' + str(date[1])
if len(str(date[2])) == 1: day = '0' + str(date[2])
if len(str(date[3])) == 1: hour = '0' + str(date[3])
if len(str(date[4])) == 1: min = '0' + str(date[4])
if len(str(date[5])) == 1: sec = '0' + str(date[5])
# Append 0 to the beginning if len of integer is 1 (value<10)
month = '%(#)02d' % {'#': int(date[1])}
day = '%(#)02d' % {'#': int(date[2])}
hour = '%(#)02d' % {'#':int(date[3])}
min = '%(#)02d' % {'#': int(date[4])}
sec = '%(#)02d' % {'#': int(date[5])}
document_header("atom")
print '<link href="' + blog_url + '/?feed=atom" rel="self" type="application/atom+xml"/>'
@ -260,11 +254,11 @@ elif feed_display == "rss":
print ' </item>'
print ' </channel>'
print '</rss>'
print date
# Generate regular page
else:
document_header("xhtml-strict")
# XHTML Header
print ' <head>'
print ' <title>' + blog_title + '</title>'
print ' <meta http-equiv="content-type" content="text/html; charset=utf-8" />'
@ -403,7 +397,7 @@ else:
title = title.replace('.' + entries_suffix, '')
if month_display == date_to_compare or not month_display:
if post_display == re.sub(' ', '-', title) or not post_display:
if post_display == post_display.replace(' ', '-') or not post_display:
if allentries_display == "1" or entry_counter < entries_per_page:
content = open(entry, "r")
print ' <div class="entry">'
@ -492,7 +486,7 @@ else:
comments_file = glob.glob(entries_dir + title + '.comments')
if not comments_file and not post_display:
print ' <div class="entry_comment">'
print ' <a href="?p=' + re.sub(' ','-', title) + '" class="entry_comment">no comments</a>'
print ' <a href="?p=' + title.replace(' ','-') + '" class="entry_comment">no comments</a>'
print ' </div>'
print ' </div>'
print ''
@ -502,7 +496,7 @@ else:
for line in comments_content:
if line.split(".", 1)[0] == "-": comments_counter += 1
print ' <div class="entry_comment">'
print ' <a href="?p=' + re.sub(' ', '-', title) + '" class="entry_comment">comments (' + str(comments_counter) + ')</a>'
print ' <a href="?p=' + title.replace(' ', '-') + '" class="entry_comment">comments (' + str(comments_counter) + ')</a>'
print ' </div>'
print ' </div>'
print ''