# HG changeset patch # User boulanni # Date 1267316786 18000 # Node ID 81f8466dc12110fe0866c7a0a61cdba2f58889f6 # Parent 992ca8035a4d017f782a427b9d9e643f5b85a537 Transient exception handling in captchas (ie. lorsque le NFS est temporairement inaccessible) diff -r 992ca8035a4d -r 81f8466dc121 data_generation/transformations/pycaptcha/Captcha/File.py --- 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): diff -r 992ca8035a4d -r 81f8466dc121 data_generation/transformations/pycaptcha/Captcha/Visual/Text.py --- 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)