Commits

Jakub Wilk committed 21d68ed

Always store captcha on disk and print its filename. Don't assume .gif extension.

Comments (0)

Files changed (1)

leechy/__init__.py

 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 # SOFTWARE.
 
+from __future__ import with_statement
+
 import locale
 import os
 import pkgutil
     def enhance_captcha(self, image):
         return image
 
-    def read_captcha(self, image_fp):
+    def show_captcha(self, image_fp):
         try:
             import aalib
         except ImportError:
                         for x in xrange(width):
                             sys.stdout.write('#' if image.getpixel((x, y)) > 0 else ' ')
                         sys.stdout.write('\n')
-            return _read_token()
         except ImportError:
-            pass
-        fp = tempfile.NamedTemporaryFile(prefix='leechy-', suffix='.gif')
-        try:
+            return
+
+    def read_captcha(self, image_fp):
+        with tempfile.NamedTemporaryFile(prefix='leechy-', suffix='.image') as fp:
+            fp.write(image_fp.read())
             fp.write(image_fp.read())
             fp.flush()
+            fp.seek(0)
             print 'Token image path:', fp.name
+            self.show_captcha(fp)
             return _read_token()
-        finally:
-            fp.close()
 
 
     log_info = staticmethod(log_info)