diff options
author | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-05-12 16:29:22 +0200 |
---|---|---|
committer | Walter Purcaro <vuolter@users.noreply.github.com> | 2015-05-12 16:29:22 +0200 |
commit | 18a808617f60c30e7ed817d79050f5564d289eb0 (patch) | |
tree | 04d1f0d6657dd951d2665da2330e54ebe0bd6665 | |
parent | Missing optional lib (diff) | |
download | pyload-18a808617f60c30e7ed817d79050f5564d289eb0.tar.xz |
Other import fixes (3)
-rw-r--r-- | pyload/plugin/account/WebshareCz.py | 5 | ||||
-rw-r--r-- | pyload/remote/ThriftBackend.py | 9 | ||||
-rw-r--r-- | pyload/remote/thriftbackend/Protocol.py | 6 | ||||
-rw-r--r-- | pyload/remote/thriftbackend/Socket.py | 15 | ||||
-rw-r--r-- | pyload/remote/thriftbackend/ThriftClient.py | 24 | ||||
-rw-r--r-- | pyload/remote/thriftbackend/ThriftTest.py | 14 | ||||
-rw-r--r-- | pyload/remote/thriftbackend/Transport.py | 11 | ||||
-rw-r--r-- | pyload/webui/__init__.py | 5 |
8 files changed, 43 insertions, 46 deletions
diff --git a/pyload/plugin/account/WebshareCz.py b/pyload/plugin/account/WebshareCz.py index c547534ba..35640dba0 100644 --- a/pyload/plugin/account/WebshareCz.py +++ b/pyload/plugin/account/WebshareCz.py @@ -1,11 +1,10 @@ # -*- coding: utf-8 -*- import hashlib +import passlib import re import time -from passlib.hash import md5_crypt - from pyload.plugin.Account import Account @@ -51,7 +50,7 @@ class WebshareCz(Account): self.wrongPassword() salt = re.search('<salt>(.+)</salt>', salt).group(1) - password = hashlib.sha1(md5_crypt.encrypt(data['password'], salt=salt)).hexdigest() + password = hashlib.sha1(passlib.hash.md5_crypt.encrypt(data['password'], salt=salt)).hexdigest() digest = hashlib.md5(user + ":Webshare:" + password).hexdigest() login = req.load("https://webshare.cz/api/login/", diff --git a/pyload/remote/ThriftBackend.py b/pyload/remote/ThriftBackend.py index 9e0afda16..f9aac2243 100644 --- a/pyload/remote/ThriftBackend.py +++ b/pyload/remote/ThriftBackend.py @@ -3,16 +3,15 @@ import os -from pyload.manager.Remote import BackendBase +import thrift +from pyload.manager.Remote import BackendBase from pyload.remote.thriftbackend.Processor import Processor from pyload.remote.thriftbackend.Protocol import ProtocolFactory from pyload.remote.thriftbackend.Socket import ServerSocket from pyload.remote.thriftbackend.Transport import TransportFactory # from pyload.remote.thriftbackend.Transport import TransportFactoryCompressed -from thrift.server import TServer - class ThriftBackend(BackendBase): @@ -35,10 +34,10 @@ class ThriftBackend(BackendBase): tfactory = TransportFactory() pfactory = ProtocolFactory() - self.server = TServer.TThreadedServer(processor, transport, tfactory, pfactory) + self.server = thrift.server.TServer.TThreadedServer(processor, transport, tfactory, pfactory) # self.server = TNonblockingServer.TNonblockingServer(processor, transport, tfactory, pfactory) - # server = TServer.TThreadPoolServer(processor, transport, tfactory, pfactory) + # server = thrift.server.TServer.TThreadPoolServer(processor, transport, tfactory, pfactory) def serve(self): diff --git a/pyload/remote/thriftbackend/Protocol.py b/pyload/remote/thriftbackend/Protocol.py index ecf0680ad..3aefa167f 100644 --- a/pyload/remote/thriftbackend/Protocol.py +++ b/pyload/remote/thriftbackend/Protocol.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- -from thrift.protocol import TBinaryProtocol +import thrift -class Protocol(TBinaryProtocol.TBinaryProtocol): +class Protocol(thrift.protocol.TBinaryProtocol.thrift.protocol.TBinaryProtocol): def writeString(self, str): try: @@ -26,7 +26,7 @@ class Protocol(TBinaryProtocol.TBinaryProtocol): return str -class ProtocolFactory(TBinaryProtocol.TBinaryProtocolFactory): +class ProtocolFactory(thrift.protocol.TBinaryProtocol.thrift.protocol.TBinaryProtocolFactory): def getProtocol(self, trans): prot = Protocol(trans, self.strictRead, self.strictWrite) diff --git a/pyload/remote/thriftbackend/Socket.py b/pyload/remote/thriftbackend/Socket.py index 6459d8f79..003439ba7 100644 --- a/pyload/remote/thriftbackend/Socket.py +++ b/pyload/remote/thriftbackend/Socket.py @@ -5,7 +5,8 @@ import socket import errno import time -from thrift.transport.TSocket import TSocket, TServerSocket, TTransportException +import thrift + WantReadError = Exception #: overwritten when ssl is used @@ -49,10 +50,10 @@ class SecureSocketConnection(object): return self.recv(buff) -class Socket(TSocket): +class Socket(thrift.transport.TSocket.TSocket): def __init__(self, host='localhost', port=7228, ssl=False): - TSocket.__init__(self, host, port) + thrift.transport.TSocket.TSocket.__init__(self, host, port) self.ssl = ssl @@ -81,8 +82,8 @@ class Socket(TSocket): (sys.platform == 'darwin' or sys.platform.startswith('freebsd'))): # freebsd and Mach don't follow POSIX semantic of recv # and fail with ECONNRESET if peer performed shutdown. - # See corresponding comment and code in TSocket::read() - # in lib/cpp/src/transport/TSocket.cpp. + # See corresponding comment and code in thrift.transport.TSocket.TSocket::read() + # in lib/cpp/src/transport/thrift.transport.TSocket.TSocket.cpp. self.close() # Trigger the check to raise the END_OF_FILE exception below. buff = '' @@ -99,11 +100,11 @@ class Socket(TSocket): raise if not len(buff): - raise TTransportException(type=TTransportException.END_OF_FILE, message='TSocket read 0 bytes') + raise thrift.transport.TSocket.TTransportException(type=thrift.transport.TSocket.TTransportException.END_OF_FILE, message='thrift.transport.TSocket.TSocket read 0 bytes') return buff -class ServerSocket(TServerSocket, Socket): +class ServerSocket(thrift.transport.TSocket.TServerSocket, Socket): def __init__(self, port=7228, host="0.0.0.0", key="", cert=""): self.host = host diff --git a/pyload/remote/thriftbackend/ThriftClient.py b/pyload/remote/thriftbackend/ThriftClient.py index ecd4086fa..259b6eff6 100644 --- a/pyload/remote/thriftbackend/ThriftClient.py +++ b/pyload/remote/thriftbackend/ThriftClient.py @@ -1,20 +1,20 @@ # -*- coding: utf-8 -*- +import socket import sys -import thrift import traceback -from Protocol import Protocol -from Socket import Socket -from socket import error -from thrift.transport import TTransport -# from thrift.transport.TZlibTransport import TZlibTransport +import thrift + +from pyload.remote.thriftbackend.Protocol import Protocol +from pyload.remote.thriftbackend.Socket import Socket # modules should import ttypes from here, when want to avoid importing API from pyload.remote.thriftbackend.thriftgen.pyload import Pyload from pyload.remote.thriftbackend.thriftgen.pyload.ttypes import * -ConnectionClosed = TTransport.TTransportException + +ConnectionClosed = thrift.transport.TTransport.TTransportException class WrongLogin(Exception): @@ -36,7 +36,8 @@ class ThriftClient(object): self.createConnection(host, port) try: self.transport.open() - except error, e: + + except socket.error, e: if e.args and e.args[0] in (111, 10061): raise NoConnection else: @@ -45,7 +46,8 @@ class ThriftClient(object): try: correct = self.client.login(user, password) - except error, e: + + except socket.error, e: if e.args and e.args[0] == 104: # connection reset by peer, probably wants ssl try: @@ -74,8 +76,8 @@ class ThriftClient(object): def createConnection(self, host, port, ssl=False): self.socket = Socket(host, port, ssl) - self.transport = TTransport.TBufferedTransport(self.socket) -# self.transport = TZlibTransport(TTransport.TBufferedTransport(self.socket)) + self.transport = thrift.transport.TTransport.TBufferedTransport(self.socket) + # self.transport = thrift.transport.TZlibTransport.TZlibTransport(thrift.transport.TTransport.TBufferedTransport(self.socket)) protocol = Protocol(self.transport) self.client = Pyload.Client(protocol) diff --git a/pyload/remote/thriftbackend/ThriftTest.py b/pyload/remote/thriftbackend/ThriftTest.py index 3ea67682b..b3d351c0b 100644 --- a/pyload/remote/thriftbackend/ThriftTest.py +++ b/pyload/remote/thriftbackend/ThriftTest.py @@ -7,14 +7,12 @@ import sys import time import xmlrpclib +import thrift + +from pyload.remote.thriftbackend.Protocol import Protocol +from pyload.remote.thriftbackend.Socket import Socket from pyload.remote.thriftbackend.thriftgen.pyload import Pyload from pyload.remote.thriftbackend.thriftgen.pyload.ttypes import * -from Socket import Socket - -from thrift import Thrift -from thrift.transport import TTransport - -from Protocol import Protocol def bench(f, *args, **kwargs): @@ -51,7 +49,7 @@ try: transport = Socket('localhost', 7228, False) # Buffering is critical. Raw sockets are very slow - transport = TTransport.TBufferedTransport(transport) + transport = thrift.transport.TTransport.TBufferedTransport(transport) # Wrap in a protocol protocol = Protocol(transport) @@ -84,5 +82,5 @@ try: # Close! transport.close() -except Thrift.TException, tx: +except thrift.Thrift.TException, tx: print 'ThriftExpection: %s' % tx.message diff --git a/pyload/remote/thriftbackend/Transport.py b/pyload/remote/thriftbackend/Transport.py index 1d3d81718..9946edd85 100644 --- a/pyload/remote/thriftbackend/Transport.py +++ b/pyload/remote/thriftbackend/Transport.py @@ -1,25 +1,24 @@ # -*- coding: utf-8 -*- -from thrift.transport.TTransport import TBufferedTransport -from thrift.transport.TZlibTransport import TZlibTransport +import thrift -class Transport(TBufferedTransport): +class Transport(thrift.transport.TTransport.TBufferedTransport): DEFAULT_BUFFER = 4096 def __init__(self, trans, rbuf_size = DEFAULT_BUFFER): - TBufferedTransport.__init__(self, trans, rbuf_size) + thrift.transport.TTransport.TBufferedTransport.__init__(self, trans, rbuf_size) self.handle = trans.handle self.remoteaddr = trans.handle.getpeername() -class TransportCompressed(TZlibTransport): +class TransportCompressed(thrift.transport.TZlibTransport.TZlibTransport): DEFAULT_BUFFER = 4096 def __init__(self, trans, rbuf_size = DEFAULT_BUFFER): - TZlibTransport.__init__(self, trans, rbuf_size) + thrift.transport.TZlibTransport.TZlibTransport.__init__(self, trans, rbuf_size) self.handle = trans.handle self.remoteaddr = trans.handle.getpeername() diff --git a/pyload/webui/__init__.py b/pyload/webui/__init__.py index 70928c458..a0e849a11 100644 --- a/pyload/webui/__init__.py +++ b/pyload/webui/__init__.py @@ -4,6 +4,7 @@ import os import sys +import beaker import bottle import jinja2 @@ -81,8 +82,6 @@ translation = gettext.translation("django", os.path.join(PYLOAD_DIR, "locale"), translation.install(True) env.install_gettext_translations(translation) -from beaker.middleware import SessionMiddleware - session_opts = { 'session.type': 'file', 'session.cookie_expires': False, @@ -90,7 +89,7 @@ session_opts = { 'session.auto': False } -web = StripPathMiddleware(SessionMiddleware(bottle.app(), session_opts)) +web = StripPathMiddleware(beaker.middleware.SessionMiddleware(bottle.app(), session_opts)) web = GZipMiddleWare(web) if PREFIX: |