On Sat, Jul 10, 2010 at 4:01 PM, Ryan Tucker
<rtucker-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
On Sat, Jul 10, 2010 at 5:06 PM, Sean Robinson <
seankrobinson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> After looking at blacklist.py (but not running it), it appears that the list of restricted URLs are hard coded into the source file. Is anyone interested in making this use a wiki page for the list of URLs?
If someone's looking for inspiration on how to retrieve the list from
a wiki page, the spell-checking code does this. There's probably some
good room for code reuse (or modularization!) there, for sure. -rt
The following is an attempt at a new blacklist.py. I am seeking comments and criticism to see if I understood what I was reading in the spell check code and whether I am using PageEditor correctly, etc. This is an early draft of non-working code, but I would appreciate feedback about my approach.
# -*- coding: utf-8 -*-
# blacklist against wiki spammers
# WikiSpot admins can add a URL to 'Global Blacklist Page' to disallow an
# edit which contains that URL.
import re, types
from Sycamore import config
from Sycamore.PageEditor import PageEditor
from Sycamore.request import RequestDummy
from Sycamore.security import Permissions
# get the global blacklist page contents
request = RequestDummy()
blacklist_page = PageEditor(config.global_blacklist_page, request)
if blacklist_page:
blacklist = blacklist_page.get_raw_body()
self.blacklist_re = "|".join(map(lambda s: "%s" % s.strip(), blacklist.strip().split("\n")))
self.blacklist_re = re.compile(self.blacklist_re)
class SecurityPolicy(Permissions):
def save(self, editor, newtext, datestamp, **kw):
match = blacklist_re.search(newtext)
if match:
print "blacklist match: %s" % match.group()
return match == None
--
Sean Robinson
WiFi Radar -
http://wifi-radar.berlios.dePython WiFi -
http://pythonwifi.wikispot.org