summaryrefslogtreecommitdiffstats
path: root/module/lib/thrift
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@gmail.com> 2014-06-28 15:53:29 +0200
committerGravatar Walter Purcaro <vuolter@gmail.com> 2014-06-28 20:23:43 +0200
commitb8942672378fccc7d557dfc2e40a4d90aecf7a0d (patch)
tree1d4a4cd78988b0ac3c18fcad8e4f3791b11f3f27 /module/lib/thrift
parent[Lib] Update bottle.py to version 0.12.7 (diff)
downloadpyload-b8942672378fccc7d557dfc2e40a4d90aecf7a0d.tar.xz
[Lib] Revert libraries to original status (remove all cosmetics optimizations)
Diffstat (limited to 'module/lib/thrift')
-rw-r--r--module/lib/thrift/TSerialization.py1
-rw-r--r--module/lib/thrift/Thrift.py4
-rw-r--r--module/lib/thrift/protocol/TBase.py7
-rw-r--r--module/lib/thrift/protocol/TBinaryProtocol.py2
-rw-r--r--module/lib/thrift/protocol/TProtocol.py7
-rw-r--r--module/lib/thrift/server/TNonblockingServer.py22
-rw-r--r--module/lib/thrift/server/TProcessPoolServer.py1
-rw-r--r--module/lib/thrift/server/TServer.py2
-rw-r--r--module/lib/thrift/transport/TTransport.py4
-rw-r--r--module/lib/thrift/transport/TTwisted.py2
-rw-r--r--module/lib/thrift/transport/TZlibTransport.py24
11 files changed, 41 insertions, 35 deletions
diff --git a/module/lib/thrift/TSerialization.py b/module/lib/thrift/TSerialization.py
index 05f88f838..b19f98aa8 100644
--- a/module/lib/thrift/TSerialization.py
+++ b/module/lib/thrift/TSerialization.py
@@ -31,3 +31,4 @@ def deserialize(base, buf, protocol_factory = TBinaryProtocol.TBinaryProtocolFac
protocol = protocol_factory.getProtocol(transport)
base.read(protocol)
return base
+
diff --git a/module/lib/thrift/Thrift.py b/module/lib/thrift/Thrift.py
index 8c270ea28..1d271fcff 100644
--- a/module/lib/thrift/Thrift.py
+++ b/module/lib/thrift/Thrift.py
@@ -74,8 +74,8 @@ class TException(Exception):
"""Base class for all thrift exceptions."""
- # BaseException.message is deprecated in Python v[2.6, 3.0)
- if (2, 6, 0) <= sys.version_info < (3, 0):
+ # BaseException.message is deprecated in Python v[2.6,3.0)
+ if (2,6,0) <= sys.version_info < (3,0):
def _get_message(self):
return self._message
def _set_message(self, message):
diff --git a/module/lib/thrift/protocol/TBase.py b/module/lib/thrift/protocol/TBase.py
index 08e154026..e675c7dc0 100644
--- a/module/lib/thrift/protocol/TBase.py
+++ b/module/lib/thrift/protocol/TBase.py
@@ -43,10 +43,10 @@ class TBase(object):
if my_val != other_val:
return False
return True
-
+
def __ne__(self, other):
return not (self == other)
-
+
def read(self, iprot):
if iprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None and fastbinary is not None:
fastbinary.decode_binary(self, iprot.trans, (self.__class__, self.thrift_spec))
@@ -63,9 +63,10 @@ class TExceptionBase(Exception):
# old style class so python2.4 can raise exceptions derived from this
# This can't inherit from TBase because of that limitation.
__slots__ = []
-
+
__repr__ = TBase.__repr__.im_func
__eq__ = TBase.__eq__.im_func
__ne__ = TBase.__ne__.im_func
read = TBase.read.im_func
write = TBase.write.im_func
+
diff --git a/module/lib/thrift/protocol/TBinaryProtocol.py b/module/lib/thrift/protocol/TBinaryProtocol.py
index 0cc44178c..50c6aa896 100644
--- a/module/lib/thrift/protocol/TBinaryProtocol.py
+++ b/module/lib/thrift/protocol/TBinaryProtocol.py
@@ -239,7 +239,7 @@ class TBinaryProtocolAccelerated(TBinaryProtocol):
our C module to do the encoding, bypassing this object entirely.
We inherit from TBinaryProtocol so that the normal TBinaryProtocol
encoding can happen if the fastbinary module doesn't work for some
- reason. (TODO(dreiss): Make this happen sanely in more cases.)
+ reason. (TODO(dreiss): Make this happen sanely in more cases.)
In order to take advantage of the C module, just use
TBinaryProtocolAccelerated instead of TBinaryProtocol.
diff --git a/module/lib/thrift/protocol/TProtocol.py b/module/lib/thrift/protocol/TProtocol.py
index 595ca5ae6..7338ff68a 100644
--- a/module/lib/thrift/protocol/TProtocol.py
+++ b/module/lib/thrift/protocol/TProtocol.py
@@ -202,7 +202,7 @@ class TProtocolBase:
# tuple of: ( 'reader method' name, is_container boolean, 'writer_method' name )
_TTYPE_HANDLERS = (
- (None, None, False), # 0 == TType, STOP
+ (None, None, False), # 0 == TType,STOP
(None, None, False), # 1 == TType.VOID # TODO: handle void?
('readBool', 'writeBool', False), # 2 == TType.BOOL
('readByte', 'writeByte', False), # 3 == TType.BYTE and I08
@@ -279,7 +279,7 @@ class TProtocolBase:
obj = obj_class()
obj.read(self)
return obj
-
+
def readContainerMap(self, spec):
results = dict()
key_ttype, key_spec = spec[0], spec[1]
@@ -298,7 +298,7 @@ class TProtocolBase:
v_val = val_reader()
else:
v_val = self.readFieldByTType(val_ttype, val_spec)
- # this raises a TypeError with unhashable keys types. i.e. d=dict(); d[[0, 1]] = 2 fails
+ # this raises a TypeError with unhashable keys types. i.e. d=dict(); d[[0,1]] = 2 fails
results[k_val] = v_val
self.readMapEnd()
return results
@@ -401,3 +401,4 @@ class TProtocolBase:
class TProtocolFactory:
def getProtocol(self, trans):
pass
+
diff --git a/module/lib/thrift/server/TNonblockingServer.py b/module/lib/thrift/server/TNonblockingServer.py
index 26d6af38d..ea348a0b6 100644
--- a/module/lib/thrift/server/TNonblockingServer.py
+++ b/module/lib/thrift/server/TNonblockingServer.py
@@ -81,7 +81,7 @@ def socket_exception(func):
class Connection:
"""Basic class is represented connection.
-
+
It can be in state:
WAIT_LEN --- connection is reading request len.
WAIT_MESSAGE --- connection is reading request.
@@ -102,7 +102,7 @@ class Connection:
def _read_len(self):
"""Reads length of request.
-
+
It's really paranoic routine and it may be replaced by
self.socket.recv(4)."""
read = self.socket.recv(4 - len(self.message))
@@ -162,14 +162,14 @@ class Connection:
@locked
def ready(self, all_ok, message):
"""Callback function for switching state and waking up main thread.
-
+
This function is the only function witch can be called asynchronous.
-
+
The ready can switch Connection to three states:
WAIT_LEN if request was oneway.
SEND_ANSWER if request was processed in normal way.
CLOSED if request throws unexpected exception.
-
+
The one wakes up main thread.
"""
assert self.status == WAIT_PROCESS
@@ -243,12 +243,12 @@ class TNonblockingServer:
def wake_up(self):
"""Wake up main thread.
-
+
The server usualy waits in select call in we should terminate one.
The simplest way is using socketpair.
-
+
Select always wait to read from the first socket of socketpair.
-
+
In this case, we can just write anything to the second socket from
socketpair."""
self._write.send('1')
@@ -265,10 +265,10 @@ class TNonblockingServer:
if connection.is_closed():
del self.clients[i]
return select.select(readable, writable, readable)
-
+
def handle(self):
"""Handle requests.
-
+
WARNING! You must call prepare BEFORE calling handle.
"""
assert self.prepared, "You have to call prepare before handle"
@@ -302,7 +302,7 @@ class TNonblockingServer:
self.tasks.put([None, None, None, None, None])
self.socket.close()
self.prepared = False
-
+
def serve(self):
"""Serve forever."""
self.prepare()
diff --git a/module/lib/thrift/server/TProcessPoolServer.py b/module/lib/thrift/server/TProcessPoolServer.py
index 254f25340..7ed814a88 100644
--- a/module/lib/thrift/server/TProcessPoolServer.py
+++ b/module/lib/thrift/server/TProcessPoolServer.py
@@ -122,3 +122,4 @@ class TProcessPoolServer(TServer):
self.stopCondition.acquire()
self.stopCondition.notify()
self.stopCondition.release()
+
diff --git a/module/lib/thrift/server/TServer.py b/module/lib/thrift/server/TServer.py
index 5b5fd6813..8456e2d40 100644
--- a/module/lib/thrift/server/TServer.py
+++ b/module/lib/thrift/server/TServer.py
@@ -270,3 +270,5 @@ class TForkingServer(TServer):
self.children.remove(pid)
else:
break
+
+
diff --git a/module/lib/thrift/transport/TTransport.py b/module/lib/thrift/transport/TTransport.py
index 2b2e99eac..12e51a9bf 100644
--- a/module/lib/thrift/transport/TTransport.py
+++ b/module/lib/thrift/transport/TTransport.py
@@ -18,7 +18,7 @@
#
from cStringIO import StringIO
-from struct import pack, unpack
+from struct import pack,unpack
from thrift.Thrift import TException
class TTransportException(TException):
@@ -127,7 +127,7 @@ class TBufferedTransportFactory:
return buffered
-class TBufferedTransport(TTransportBase, CReadableTransport):
+class TBufferedTransport(TTransportBase,CReadableTransport):
"""Class that wraps another transport and buffers its I/O.
diff --git a/module/lib/thrift/transport/TTwisted.py b/module/lib/thrift/transport/TTwisted.py
index 141e299ca..b6dcb4e0b 100644
--- a/module/lib/thrift/transport/TTwisted.py
+++ b/module/lib/thrift/transport/TTwisted.py
@@ -79,7 +79,7 @@ class ThriftClientProtocol(basic.Int32StringReceiver):
self.started.callback(self.client)
def connectionLost(self, reason=connectionDone):
- for k, v in self.client._reqs.iteritems():
+ for k,v in self.client._reqs.iteritems():
tex = TTransport.TTransportException(
type=TTransport.TTransportException.END_OF_FILE,
message='Connection closed')
diff --git a/module/lib/thrift/transport/TZlibTransport.py b/module/lib/thrift/transport/TZlibTransport.py
index 89fa96f61..784d4e1e0 100644
--- a/module/lib/thrift/transport/TZlibTransport.py
+++ b/module/lib/thrift/transport/TZlibTransport.py
@@ -30,14 +30,14 @@ from TTransport import TTransportBase, CReadableTransport
class TZlibTransportFactory(object):
'''
Factory transport that builds zlib compressed transports.
-
+
This factory caches the last single client/transport that it was passed
and returns the same TZlibTransport object that was created.
-
+
This caching means the TServer class will get the _same_ transport
object for both input and output transports from this factory.
(For non-threaded scenarios only, since the cache only holds one object)
-
+
The purpose of this caching is to allocate only one TZlibTransport where
only one is really needed (since it must have separate read/write buffers),
and makes the statistics from getCompSavings() and getCompRatio()
@@ -52,11 +52,11 @@ class TZlibTransportFactory(object):
'''Wrap a transport , trans, with the TZlibTransport
compressed transport class, returning a new
transport to the caller.
-
+
@param compresslevel: The zlib compression level, ranging
from 0 (no compression) to 9 (best compression). Defaults to 9.
@type compresslevel: int
-
+
This method returns a TZlibTransport which wraps the
passed C{trans} TTransport derived instance.
'''
@@ -83,7 +83,7 @@ class TZlibTransport(TTransportBase, CReadableTransport):
'''
Create a new TZlibTransport, wrapping C{trans}, another
TTransport derived object.
-
+
@param trans: A thrift transport object, i.e. a TSocket() object.
@type trans: TTransport
@param compresslevel: The zlib compression level, ranging
@@ -125,19 +125,19 @@ class TZlibTransport(TTransportBase, CReadableTransport):
def getCompRatio(self):
'''
- Get the current measured compression ratios (in, out) from
+ Get the current measured compression ratios (in,out) from
this transport.
-
+
Returns a tuple of:
(inbound_compression_ratio, outbound_compression_ratio)
-
+
The compression ratios are computed as:
compressed / uncompressed
E.g., data that compresses by 10x will have a ratio of: 0.10
and data that compresses to half of ts original size will
have a ratio of 0.5
-
+
None is returned if no bytes have yet been processed in
a particular direction.
'''
@@ -152,10 +152,10 @@ class TZlibTransport(TTransportBase, CReadableTransport):
'''
Get the current count of saved bytes due to data
compression.
-
+
Returns a tuple of:
(inbound_saved_bytes, outbound_saved_bytes)
-
+
Note: if compression is actually expanding your
data (only likely with very tiny thrift objects), then
the values returned will be negative.