web/captcha.py
changeset 10566 4c103a2c5e93
parent 9772 7d0d622c9bc9
child 10609 e2d8e81bfe68
equal deleted inserted replaced
10565:f5063eae939e 10566:4c103a2c5e93
    20 """
    20 """
    21 
    21 
    22 __docformat__ = "restructuredtext en"
    22 __docformat__ = "restructuredtext en"
    23 
    23 
    24 from random import randint, choice
    24 from random import randint, choice
    25 from cStringIO import StringIO
    25 from io import BytesIO
    26 
    26 
    27 from PIL import Image, ImageFont, ImageDraw, ImageFilter
    27 from PIL import Image, ImageFont, ImageDraw, ImageFilter
    28 
    28 
    29 
    29 
    30 from time import time
    30 from time import time
    65     """Generate an arbitrary text, return it together with a buffer containing
    65     """Generate an arbitrary text, return it together with a buffer containing
    66     the captcha image for the text
    66     the captcha image for the text
    67     """
    67     """
    68     text = u''.join(choice('QWERTYUOPASDFGHJKLZXCVBNM') for i in range(size))
    68     text = u''.join(choice('QWERTYUOPASDFGHJKLZXCVBNM') for i in range(size))
    69     img = pil_captcha(text, fontfile, fontsize)
    69     img = pil_captcha(text, fontfile, fontsize)
    70     out = StringIO()
    70     out = BytesIO()
    71     img.save(out, format)
    71     img.save(out, format)
    72     out.seek(0)
    72     out.seek(0)
    73     return text, out
    73     return text, out
    74 
    74 
    75 
    75