diff options
author | Stefan Ritter <xeno@thehappy.de> | 2009-12-02 12:19:30 +0100 |
---|---|---|
committer | Stefan Ritter <xeno@thehappy.de> | 2009-12-02 12:19:30 +0100 |
commit | 31b7b41d65dc0b94bb07e90b006c67c7f4f411ea (patch) | |
tree | b30447796dfb22825d20ef4d67ce45cb6951f67d /blogthon.cgi | |
parent | e2b597fc1befc48537cbbbf9d857db2aea886b3f (diff) |
Code cleanup:
* Removed some regexp
* Using String Formatting Operation to fill 1byte string with '0'
Diffstat (limited to '')
-rwxr-xr-x | blogthon.cgi | 42 |
1 files changed, 18 insertions, 24 deletions
diff --git a/blogthon.cgi b/blogthon.cgi index 8533183..614a482 100755 --- a/blogthon.cgi +++ b/blogthon.cgi @@ -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("<", "<") \ - .replace(">", ">") \ - .replace("\"", """) - ctext = ctext.replace("<", "<") \ - .replace(">", ">") \ - .replace("\"", """) + cname = cname.replace('<', '<') \ + .replace('>', '>') \ + .replace('\'', '"') + ctext = ctext.replace('<', '<') \ + .replace('>', '>') \ + .replace('\'', '"') # 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 '' |