comparison captchamiddleware/middleware.py @ 2:c861518b2a44

fix bug whereby forbidden characters cause issues
author k0s <k0scist@gmail.com>
date Tue, 23 Feb 2010 19:50:23 -0500
parents 478d13061336
children b0ef5452a740
comparison
equal deleted inserted replaced
1:478d13061336 2:c861518b2a44
37 # get dictionary 37 # get dictionary
38 if self.dictionary.startswith('http://') or self.dictionary.startswith('https://'): 38 if self.dictionary.startswith('http://') or self.dictionary.startswith('https://'):
39 f = urlopen(self.dictionary) 39 f = urlopen(self.dictionary)
40 else: 40 else:
41 f = file(self.dictionary) 41 f = file(self.dictionary)
42
43 # characters skimpygimpy doesnt know about
44 forbidden_characters = set(["'"])
45
42 self.words = [ i.strip() for i in f.readlines() 46 self.words = [ i.strip() for i in f.readlines()
43 if len(i.strip()) > self.minimum_length ] 47 if (len(i.strip()) > self.minimum_length)
48 and not forbidden_characters.intersection(i) ]
44 random.shuffle(self.words) 49 random.shuffle(self.words)
45 50
46 51
47 def __call__(self, environ, start_response): 52 def __call__(self, environ, start_response):
48 request = Request(environ) 53 request = Request(environ)
49 if request.method == 'post' and not request.remote_user: 54 if request.method == 'POST' and not request.remote_user:
55 import pdb; pdb.set_trace()
50 pass # TODO: check CAPTCHA 56 pass # TODO: check CAPTCHA
51 57
52 return LXMLMiddleware.__call__(self, environ, start_response) 58 return LXMLMiddleware.__call__(self, environ, start_response)
53 59
54 def manipulate(self, environ, tree): 60 def manipulate(self, environ, tree):