From 65750101575642ff696c396fbad5ee1741e5878e Mon Sep 17 00:00:00 2001 From: Stefan Ritter Date: Tue, 16 Nov 2010 08:45:21 +0100 Subject: Some code cleanup --- blogthon.cgi | 44 ++++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/blogthon.cgi b/blogthon.cgi index 63d0e2f..f883bea 100755 --- a/blogthon.cgi +++ b/blogthon.cgi @@ -16,17 +16,17 @@ # * Complete Atom Feed (like RSS) # * Fix broken charset in outgoing mails (needs some testing) -import ConfigParser +from ConfigParser import ConfigParser import os import sys import time import locale import re import cgi -import glob -import md5 -import random -import smtplib +from smtplib import SMTP +from md5 import new as newmd5 +from glob import glob +from random import randint # A wonderful place for doing some regexp ;) no_break = re.compile('^\s*(|||||||).*$') @@ -36,18 +36,13 @@ line_start_plus = re.compile('^\+.*$') tab = "\t" def generate_uuid(string): - string_md5sum = md5.new(string).hexdigest() + string_md5sum = newmd5(string).hexdigest() string = str.join('-', (string_md5sum[0:8], string_md5sum[8:12], string_md5sum[12:16], string_md5sum[16:20], string_md5sum[20:32])) return string def errorpage(string): - print 'Content-type: text/html\n' - print '' - print '' - print '' - print tab + 'Error!' - print '' + document_header('xhtml-strict') + print 'Error!' print '' print tab + string print '' @@ -74,7 +69,7 @@ def document_header(string): print '' print '' -configuration = ConfigParser.ConfigParser() +configuration = ConfigParser() # Look for a configuration: if os.path.exists('../blogthonrc'): @@ -217,7 +212,7 @@ if cname and ctext and ctitle: if not cquiz == cquizv: errorpage("Brainmode") else: - comments_file = glob.glob(entries_dir + ctitle + '.comments') + comments_file = glob(entries_dir + ctitle + '.comments') if not comments_file: try: content = open(entries_dir + ctitle + '.comments', "w") @@ -235,7 +230,8 @@ if cname and ctext and ctitle: # Send mail? if not new_comment_mail == 'False': msg = 'From: Blogthon\nTo: ' + mail_to + '\nSubject: New comment on ' + blog_title + '\n\nSomeone wrote a comment to this entry: ' + blog_url + '?p=' + ctitle.replace(' ', '-') - smtp = smtplib.SMTP(smtp_host) + smtp = SMTP(smtp_host) + smtp.starttls() # TODO: some hosts need TLS, needs testing smtp.sendmail(blog_title, mail_to, msg) smtp.quit() except: @@ -243,7 +239,7 @@ if cname and ctext and ctitle: # Read entries and store their title and timestamp entries = [] -entries_list = glob.glob(entries_dir + '*.' + entries_suffix) +entries_list = glob(entries_dir + '*.' + entries_suffix) for entry in entries_list: timestamp = os.stat(entry) @@ -346,7 +342,7 @@ else: # Plugins sys.path.append(plugins_dir) - for plugin in glob.glob(plugins_dir + '*.py'): + for plugin in glob(plugins_dir + '*.py'): __import__ (plugin.split('/')[1].replace('.py', '')) # Site header @@ -375,7 +371,7 @@ else: # Staticpages if staticpages == "True": staticpages = [] - staticpages_list = glob.glob(staticpages_dir + '*') + staticpages_list = glob(staticpages_dir + '*') staticpages_list.sort() print tab*2 + '
' print tab*3 + '
' + blog_locale[0] + '
' @@ -500,10 +496,10 @@ else: # Comments... # ... are shown when post_display and comments_file isn't false - comments_file = glob.glob(entries_dir + title + '.comments') + comments_file = glob(entries_dir + title + '.comments') if post_display: if comments_file: - comments_file = glob.glob(entries_dir + title + '.comments') + comments_file = glob(entries_dir + title + '.comments') comments_content = open(comments_file[0], "r") print tab*3 + '
' print tab*2 + '' @@ -544,8 +540,8 @@ else: # Form for adding comments if comments == "True": - random_int_a = random.randint(1,9) - random_int_b = random.randint(1,9) + random_int_a = randint(1,9) + random_int_b = randint(1,9) cquizv = random_int_a + random_int_b print tab*3 + '
' print tab*4 + '
' @@ -562,7 +558,7 @@ else: print '' if comments == "True": - comments_file = glob.glob(entries_dir + title + '.comments') + comments_file = glob(entries_dir + title + '.comments') if not comments_file and not post_display: print tab*4 + '
' print tab*5 + '' + blog_locale[3] + '' -- cgit v1.2.3