summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Stefano <l.stickell@yahoo.it> 2014-05-19 14:04:58 +0200
committerGravatar Walter Purcaro <vuolter@gmail.com> 2014-06-28 03:03:01 +0200
commit171904c1bf41c0444d1dde283ceb2f820bce75ea (patch)
treed6ac52600d2902671c6c8668b13cb9dd2d89c101
parentFixed just_header HEAD request issue. (diff)
downloadpyload-171904c1bf41c0444d1dde283ceb2f820bce75ea.tar.xz
Porting to Pillow
See #620 and #254 + PEP 8
-rw-r--r--module/plugins/captcha/LinksaveIn.py2
-rw-r--r--module/plugins/captcha/captcha.py57
-rw-r--r--systemCheck.py12
3 files changed, 36 insertions, 35 deletions
diff --git a/module/plugins/captcha/LinksaveIn.py b/module/plugins/captcha/LinksaveIn.py
index 8ce26fbac..a92572fb3 100644
--- a/module/plugins/captcha/LinksaveIn.py
+++ b/module/plugins/captcha/LinksaveIn.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from captcha import OCR
-import Image
+from PIL import Image
from os import sep
from os.path import dirname
from os.path import abspath
diff --git a/module/plugins/captcha/captcha.py b/module/plugins/captcha/captcha.py
index 7e4dec697..919739ad6 100644
--- a/module/plugins/captcha/captcha.py
+++ b/module/plugins/captcha/captcha.py
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
-
#
#Copyright (C) 2009 kingzero, RaNaN
#
@@ -17,23 +16,22 @@
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#
###
+
from __future__ import with_statement
import os
from os.path import join
from os.path import abspath
import logging
import subprocess
-#import tempfile
-import Image
-import TiffImagePlugin
-import PngImagePlugin
-import GifImagePlugin
-import JpegImagePlugin
+from PIL import Image
+from PIL import TiffImagePlugin
+from PIL import PngImagePlugin
+from PIL import GifImagePlugin
+from PIL import JpegImagePlugin
class OCR(object):
-
__name__ = "OCR"
def __init__(self):
@@ -54,16 +52,15 @@ class OCR(object):
def run(self, command):
"""Run a command"""
- popen = subprocess.Popen(command, bufsize = -1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ popen = subprocess.Popen(command, bufsize=-1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
popen.wait()
- output = popen.stdout.read() +" | "+ popen.stderr.read()
+ output = popen.stdout.read() + " | " + popen.stderr.read()
popen.stdout.close()
popen.stderr.close()
self.logger.debug("Tesseract ReturnCode %s Output: %s" % (popen.returncode, output))
def run_tesser(self, subset=False, digits=True, lowercase=True, uppercase=True):
#self.logger.debug("create tmp tif")
-
#tmp = tempfile.NamedTemporaryFile(suffix=".tif")
tmp = open(join("tmp", "tmpTif_%s.tif" % self.__name__), "wb")
tmp.close()
@@ -76,11 +73,11 @@ class OCR(object):
self.image.save(tmp.name, 'TIFF')
if os.name == "nt":
- tessparams = [join(pypath,"tesseract","tesseract.exe")]
+ tessparams = [join(pypath, "tesseract", "tesseract.exe")]
else:
tessparams = ['tesseract']
- tessparams.extend( [abspath(tmp.name), abspath(tmpTxt.name).replace(".txt", "")] )
+ tessparams.extend([abspath(tmp.name), abspath(tmpTxt.name).replace(".txt", "")])
if subset and (digits or lowercase or uppercase):
#self.logger.debug("create temp subset config")
@@ -143,28 +140,37 @@ class OCR(object):
for x in xrange(w):
for y in xrange(h):
- if pixels[x, y] == 255: continue
+ if pixels[x, y] == 255:
+ continue
# no point in processing white pixels since we only want to remove black pixel
count = 0
try:
- if pixels[x-1, y-1] != 255: count += 1
- if pixels[x-1, y] != 255: count += 1
- if pixels[x-1, y + 1] != 255: count += 1
- if pixels[x, y + 1] != 255: count += 1
- if pixels[x + 1, y + 1] != 255: count += 1
- if pixels[x + 1, y] != 255: count += 1
- if pixels[x + 1, y-1] != 255: count += 1
- if pixels[x, y-1] != 255: count += 1
+ if pixels[x - 1, y - 1] != 255:
+ count += 1
+ if pixels[x - 1, y] != 255:
+ count += 1
+ if pixels[x - 1, y + 1] != 255:
+ count += 1
+ if pixels[x, y + 1] != 255:
+ count += 1
+ if pixels[x + 1, y + 1] != 255:
+ count += 1
+ if pixels[x + 1, y] != 255:
+ count += 1
+ if pixels[x + 1, y - 1] != 255:
+ count += 1
+ if pixels[x, y - 1] != 255:
+ count += 1
except:
pass
- # not enough neighbors are dark pixels so mark this pixel
- # to be changed to white
+ # not enough neighbors are dark pixels so mark this pixel
+ # to be changed to white
if count < allowed:
pixels[x, y] = 1
- # second pass: this time set all 1's to 255 (white)
+ # second pass: this time set all 1's to 255 (white)
for x in xrange(w):
for y in xrange(h):
if pixels[x, y] == 1: pixels[x, y] = 255
@@ -198,7 +204,6 @@ class OCR(object):
if pixels[x, y] == 0:
pixels[x, y] = 255
-
count = {}
for x in xrange(w):
diff --git a/systemCheck.py b/systemCheck.py
index d46a2d99a..a1f8ba67f 100644
--- a/systemCheck.py
+++ b/systemCheck.py
@@ -6,11 +6,12 @@ import sys
#very ugly prints, but at least it works with python 3
+
def main():
print("##### System Information #####\n")
print("Platform:", sys.platform)
print("Operating System:", os.name)
- print("Python:", sys.version.replace("\n", "")+ "\n")
+ print("Python:", sys.version.replace("\n", "") + "\n")
try:
import pycurl
@@ -24,7 +25,6 @@ def main():
except:
print("py-crypto:", "missing")
-
try:
import OpenSSL
print("OpenSSL:", OpenSSL.version.__version__)
@@ -32,7 +32,7 @@ def main():
print("OpenSSL:", "missing")
try:
- import Image
+ from PIL import Image
print("image libary:", Image.VERSION)
except:
print("image libary:", "missing")
@@ -60,14 +60,13 @@ def main():
except:
core_err.append("Please install py-curl to use pyLoad.")
-
try:
from pycurl import AUTOREFERER
except:
core_err.append("Your py-curl version is to old, please upgrade!")
try:
- import Image
+ from PIL import Image
except:
core_err.append("Please install py-imaging/pil to use Hoster, which uses captchas.")
@@ -94,7 +93,6 @@ def main():
for line in core_info:
print(line)
-
print("\n## pyLoadGui ##")
gui_err = []
@@ -111,7 +109,6 @@ def main():
else:
print("No Problems detected, pyLoadGui should work fine.")
-
print("\n## Webinterface ##")
web_err = []
@@ -122,7 +119,6 @@ def main():
except:
web_info.append("Install Flup to use FastCGI or optional webservers.")
-
if web_err:
print("The system check has detected some errors:\n")
for err in web_err: