diff options
author | Walter Purcaro <vuolter@gmail.com> | 2015-01-29 15:56:57 +0100 |
---|---|---|
committer | Walter Purcaro <vuolter@gmail.com> | 2015-01-29 15:56:57 +0100 |
commit | cb9e67a5437ddfafd6a93f5a208b9faf3f2d5575 (patch) | |
tree | 2175310fe13226ac859dac57d5e3a1d14d9223bf /module/plugins/captcha | |
parent | [ExtractArchive] Fix typo (thx SelmaUrban) (diff) | |
download | pyload-cb9e67a5437ddfafd6a93f5a208b9faf3f2d5575.tar.xz |
Some file encoding fixup + optimizations
Diffstat (limited to 'module/plugins/captcha')
-rw-r--r-- | module/plugins/captcha/captcha.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/module/plugins/captcha/captcha.py b/module/plugins/captcha/captcha.py index e89ec2e81..1874ba07d 100644 --- a/module/plugins/captcha/captcha.py +++ b/module/plugins/captcha/captcha.py @@ -4,6 +4,7 @@ from __future__ import with_statement try: from PIL import Image, GifImagePlugin, JpegImagePlugin, PngImagePlugin, TiffImagePlugin + except ImportError: import Image, GifImagePlugin, JpegImagePlugin, PngImagePlugin, TiffImagePlugin @@ -12,13 +13,13 @@ import os import subprocess #import tempfile -from os.path import abspath, join +from module.utils import save_join class OCR(object): __name__ = "OCR" __type__ = "ocr" - __version__ = "0.10" + __version__ = "0.11" __description__ = """OCR base plugin""" __license__ = "GPLv3" @@ -58,11 +59,11 @@ class OCR(object): def run_tesser(self, subset=False, digits=True, lowercase=True, uppercase=True): #tmpTif = tempfile.NamedTemporaryFile(suffix=".tif") try: - tmpTif = open(join("tmp", "tmpTif_%s.tif" % self.__name__), "wb") + tmpTif = open(save_join("tmp", "tmpTif_%s.tif" % self.__name__), "wb") tmpTif.close() #tmpTxt = tempfile.NamedTemporaryFile(suffix=".txt") - tmpTxt = open(join("tmp", "tmpTxt_%s.txt" % self.__name__), "wb") + tmpTxt = open(save_join("tmp", "tmpTxt_%s.txt" % self.__name__), "wb") tmpTxt.close() except IOError, e: @@ -73,15 +74,15 @@ class OCR(object): self.image.save(tmpTif.name, 'TIFF') if os.name == "nt": - tessparams = [join(pypath, "tesseract", "tesseract.exe")] + tessparams = [os.path.join(pypath, "tesseract", "tesseract.exe")] else: tessparams = ["tesseract"] - tessparams.extend( [abspath(tmpTif.name), abspath(tmpTxt.name).replace(".txt", "")] ) + tessparams.extend( [os.path.abspath(tmpTif.name), os.path.abspath(tmpTxt.name).replace(".txt", "")] ) if subset and (digits or lowercase or uppercase): #tmpSub = tempfile.NamedTemporaryFile(suffix=".subset") - with open(join("tmp", "tmpSub_%s.subset" % self.__name__), "wb") as tmpSub: + with open(save_join("tmp", "tmpSub_%s.subset" % self.__name__), "wb") as tmpSub: tmpSub.write("tessedit_char_whitelist ") if digits: @@ -93,7 +94,7 @@ class OCR(object): tmpSub.write("\n") tessparams.append("nobatch") - tessparams.append(abspath(tmpSub.name)) + tessparams.append(os.path.abspath(tmpSub.name)) self.logger.debug("run tesseract") self.run(tessparams) |