diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2014-12-24 14:24:24 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2014-12-24 14:32:23 +0100 |
commit | 8af6ecfe31a7767f1d76f36581b01ddd26fb3220 (patch) | |
tree | a5cf60c5de6a34843fceb23895473cbb25c80fa2 /whitelist.py | |
parent | 45552a9cb1ac5433fd2010d1736b41a3393b9b6b (diff) | |
download | pygn-8af6ecfe31a7767f1d76f36581b01ddd26fb3220.tar.gz |
Mighty cleanup
* Use more of the standard methods for OrderedDicts
* remove pyginfo module (with SSOT being mail2news module)
* remove TODO, INSTALL, and changelog.Debian
* all FIXMEs and TODOs are filed as bugs in the issue tracker
Diffstat (limited to 'whitelist.py')
-rw-r--r-- | whitelist.py | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/whitelist.py b/whitelist.py index c017402..ea3f646 100644 --- a/whitelist.py +++ b/whitelist.py @@ -27,7 +27,7 @@ class whitelist(object): wl = {} debug = None - log = None # filedescriptor + logf = None # filedescriptor # constants DENY = 0 @@ -52,18 +52,18 @@ class whitelist(object): # print '%s: %s = %s' % (owner,option,self.wl[owner][option]) try: - self.log = open(logfile, 'a') + self.logf = open(logfile, 'a') self.lock() except (Exception), message: print '%s\nAre you authorized to use this program? ' % message sys.exit(1) def lock(self): - fcntl.flock(self.log.fileno(), fcntl.LOCK_EX) + fcntl.flock(self.logf.fileno(), fcntl.LOCK_EX) # to unlock fd locked, usually fd are unlocked after process exit() def unlock(self): - fcntl.flock(self.log.fileno(), fcntl.LOCK_UN) + fcntl.flock(self.logf.fileno(), fcntl.LOCK_UN) def checkfrom(self, fromhead): """have you permission to be here, sir?""" @@ -78,14 +78,12 @@ class whitelist(object): else: return None - # FIXME self.log has been already defined as a variable of None value on - # line 30. def log(self, string): """Captain Diary, Astral Date 962555394 from epoch. it rawly write a line in logfile. Remeber to indent it, if you like. """ - self.log.write(string + '\n') + self.logf.write(string + '\n') def logmsg(self, heads, ok=DENY, owner=None): """who are walking through my gate? @@ -100,33 +98,33 @@ class whitelist(object): tzone = time.tzname[0] if ok == self.ACCEPT: - self.log.write('Permission Accorded ') + self.logf.write('Permission Accorded ') else: - self.log.write('Permission Denied ') + self.logf.write('Permission Denied ') - self.log.write('at %s (%s)\n' % (ltime, tzone)) + self.logf.write('at %s (%s)\n' % (ltime, tzone)) if owner is not None: - self.log.write('\tWLOwner: ' + owner + '\n') - self.log.write('\tFrom: ' + heads.get('From', 'NOT PRESENT\n')) - self.log.write('\tSubject: ' + heads.get('Subject', 'NOT PRESENT\n')) - self.log.write('\tSender: ' + heads.get('Sender', 'NOT PRESENT\n')) - self.log.write('\tDate: ' + heads.get('Date', 'NOT PRESENT\n')) + self.logf.write('\tWLOwner: ' + owner + '\n') + self.logf.write('\tFrom: ' + heads.get('From', 'NOT PRESENT\n')) + self.logf.write('\tSubject: ' + heads.get('Subject', 'NOT PRESENT\n')) + self.logf.write('\tSender: ' + heads.get('Sender', 'NOT PRESENT\n')) + self.logf.write('\tDate: ' + heads.get('Date', 'NOT PRESENT\n')) # some client create Message-Id other Message-ID. if 'Message-ID' in heads: - self.log.write('\tMessage-ID: ' + heads.get('Message-ID')) + self.logf.write('\tMessage-ID: ' + heads.get('Message-ID')) else: - self.log.write('\tMessage-Id: ' + heads.get('Message-Id', + self.logf.write('\tMessage-Id: ' + heads.get('Message-Id', 'NOT PRESENT\n')) # X-Newsgroups: and To: are present if user is trusted, else # Newsgroup: exists since no changes on nntp headers are done. if 'X-Newsgroups' in heads: - self.log.write('\tTo: ' + heads.get('To', 'NOT PRESENT\n')) - self.log.write('\tX-Newsgroups: ' + heads.get('X-Newsgroups', + self.logf.write('\tTo: ' + heads.get('To', 'NOT PRESENT\n')) + self.logf.write('\tX-Newsgroups: ' + heads.get('X-Newsgroups', 'NOT PRESENT\n')) else: - self.log.write('\tNewsgroups: ' + + self.logf.write('\tNewsgroups: ' + heads.get('Newsgroups', 'NOT PRESENT\n')) - self.log.write('\n') + self.logf.write('\n') |