Mercurial > ift6266
changeset 184:81f8466dc121
Transient exception handling in captchas (ie. lorsque le NFS est temporairement inaccessible)
author | boulanni <nicolas_boulanger@hotmail.com> |
---|---|
date | Sat, 27 Feb 2010 19:26:26 -0500 |
parents | 992ca8035a4d |
children | c03692aa6158 |
files | data_generation/transformations/pycaptcha/Captcha/File.py data_generation/transformations/pycaptcha/Captcha/Visual/Text.py |
diffstat | 2 files changed, 16 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/data_generation/transformations/pycaptcha/Captcha/File.py Sat Feb 27 19:21:57 2010 -0500 +++ b/data_generation/transformations/pycaptcha/Captcha/File.py Sat Feb 27 19:26:26 2010 -0500 @@ -36,7 +36,10 @@ """From our given file list, find a list of full paths to files""" paths = [] for name in self.fileList: - path = os.path.join(dataDir, self.basePath, name) + if name[0] == '/': + path = name + else: + path = os.path.join(dataDir, self.basePath, name) if os.path.isdir(path): for content in os.listdir(path): if self._checkExtension(content):
--- a/data_generation/transformations/pycaptcha/Captcha/Visual/Text.py Sat Feb 27 19:21:57 2010 -0500 +++ b/data_generation/transformations/pycaptcha/Captcha/Visual/Text.py Sat Feb 27 19:26:26 2010 -0500 @@ -39,7 +39,7 @@ return (fileName, size) # Predefined font factories -defaultFontFactory = FontFactory(25, "allfonts") +defaultFontFactory = FontFactory(25, "/Tmp/allfonts") #defaultFontFactory = FontFactory((30, 40), "vera") class TextLayer(Visual.Layer): @@ -77,7 +77,17 @@ self.borderColor = borderColor def render(self, img): - font = ImageFont.truetype(*self.font) + + i=1 + while True: + try: + font = ImageFont.truetype(*self.font) + break + except: + print "try#", i, self.font + i += 1 + if i>10: raise + textSize = font.getsize(self.text) draw = ImageDraw.Draw(img)