THRIFT-5923: UUID python
Client: py
Patch: CJCombrink
This closes #3330
diff --git a/lib/py/src/protocol/TJSONProtocol.py b/lib/py/src/protocol/TJSONProtocol.py
index 004a40a..6782eeb 100644
--- a/lib/py/src/protocol/TJSONProtocol.py
+++ b/lib/py/src/protocol/TJSONProtocol.py
@@ -21,6 +21,7 @@
TProtocolFactory, checkIntegerLimits)
import base64
import math
+import uuid
__all__ = ['TJSONProtocol',
@@ -64,6 +65,7 @@
}
NUMERIC_CHAR = b'+-.0123456789Ee'
+# Type names as TJSONProtocol.cpp
CTYPES = {
TType.BOOL: 'tf',
TType.BYTE: 'i8',
@@ -76,6 +78,7 @@
TType.LIST: 'lst',
TType.SET: 'set',
TType.MAP: 'map',
+ TType.UUID: 'uid',
}
JTYPES = {}
@@ -480,6 +483,11 @@
def readBinary(self):
return self.readJSONBase64()
+ def readUuid(self):
+ buff = self.readJSONString(False)
+ val = uuid.UUID(buff)
+ return val
+
def writeMessageBegin(self, name, request_type, seqid):
self.resetWriteContext()
self.writeJSONArrayStart()
@@ -565,6 +573,9 @@
def writeBinary(self, binary):
self.writeJSONBase64(binary)
+ def writeUuid(self, uuid):
+ self.writeJSONString(str(uuid))
+
class TJSONProtocolFactory(TProtocolFactory):
def getProtocol(self, trans):
@@ -659,6 +670,9 @@
def writeBinary(self, binary):
self.writeJSONBase64(binary)
+ def writeUuid(self, uuid):
+ self.writeJSONString(str(uuid))
+
class TSimpleJSONProtocolFactory(TProtocolFactory):