annotate pycaptcha/Captcha/Visual/Tests.py @ 161:c1d5474c3386

Make test not test itself.
author Arnaud Bergeron <abergeron@gmail.com>
date Thu, 25 Feb 2010 18:11:25 -0500
parents 4775b4195b4b
children
rev   line source
87
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
1 """ Captcha.Visual.Tests
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
2
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
3 Visual CAPTCHA tests
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
4 """
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
5 #
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
6 # PyCAPTCHA Package
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
7 # Copyright (C) 2004 Micah Dowty <micah@navi.cx>
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
8 #
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
9
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
10 from Captcha.Visual import Text, Backgrounds, Distortions, ImageCaptcha
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
11 from Captcha import Words
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
12 import random
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
13
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
14 __all__ = ["PseudoGimpy", "AngryGimpy", "AntiSpam"]
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
15
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
16
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
17 class PseudoGimpy(ImageCaptcha):
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
18 """A relatively easy CAPTCHA that's somewhat easy on the eyes"""
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
19 def getLayers(self):
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
20 word = Words.defaultWordList.pick()
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
21 self.addSolution(word)
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
22 return [
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
23 # random.choice([
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
24 # Backgrounds.CroppedImage(),
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
25 # Backgrounds.TiledImage(),
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
26 # ]),
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
27 Text.TextLayer(word, borderSize=1),
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
28 Distortions.SineWarp(),
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
29 ]
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
30
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
31
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
32 class AngryGimpy(ImageCaptcha):
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
33 """A harder but less visually pleasing CAPTCHA"""
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
34 def getLayers(self):
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
35 word = Words.defaultWordList.pick()
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
36 self.addSolution(word)
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
37 return [
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
38 # suppression du background
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
39 # Backgrounds.TiledImage(),
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
40 # Backgrounds.RandomDots(),
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
41 Text.TextLayer(word, borderSize=1),
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
42 # Distortions.SineWarp(periodRange = (0.04, 0.07))
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
43 Distortions.WigglyBlocks(),
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
44 ]
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
45
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
46
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
47 class AntiSpam(ImageCaptcha):
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
48 """A fixed-solution CAPTCHA that can be used to hide email addresses or URLs from bots"""
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
49 fontFactory = Text.FontFactory(20, "vera/VeraBd.ttf")
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
50 defaultSize = (512,50)
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
51
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
52 def getLayers(self, solution="murray@example.com"):
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
53 self.addSolution(solution)
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
54
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
55 textLayer = Text.TextLayer(solution,
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
56 borderSize = 2,
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
57 fontFactory = self.fontFactory)
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
58
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
59 return [
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
60 Backgrounds.CroppedImage(),
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
61 textLayer,
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
62 Distortions.SineWarp(amplitudeRange = (3, 5)),
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
63 ]
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
64
4775b4195b4b code pour la generation de captchas
goldfinger
parents:
diff changeset
65 ### The End ###