summaryrefslogtreecommitdiffstats
path: root/pyload/remote/thriftbackend
diff options
context:
space:
mode:
Diffstat (limited to 'pyload/remote/thriftbackend')
-rw-r--r--pyload/remote/thriftbackend/Protocol.py6
-rw-r--r--pyload/remote/thriftbackend/Socket.py15
-rw-r--r--pyload/remote/thriftbackend/ThriftClient.py24
-rw-r--r--pyload/remote/thriftbackend/ThriftTest.py14
-rw-r--r--pyload/remote/thriftbackend/Transport.py11
5 files changed, 35 insertions, 35 deletions
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()