http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/apache/airavata/model/file/ttypes.py ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/apache/airavata/model/file/ttypes.py b/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/apache/airavata/model/file/ttypes.py deleted file mode 100644 index dc6b187..0000000 --- a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/apache/airavata/model/file/ttypes.py +++ /dev/null @@ -1,550 +0,0 @@ -# -# Autogenerated by Thrift Compiler (0.9.3) -# -# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING -# -# options string: py -# - -from thrift.Thrift import TType, TMessageType, TException, TApplicationException - -from thrift.transport import TTransport -from thrift.protocol import TBinaryProtocol, TProtocol -try: - from thrift.protocol import fastbinary -except: - fastbinary = None - - -class StorageResourceProtocol: - SCP = 0 - SFTP = 1 - HTTP = 2 - HTTPS = 3 - GridFTP = 4 - LOCAL = 5 - - _VALUES_TO_NAMES = { - 0: "SCP", - 1: "SFTP", - 2: "HTTP", - 3: "HTTPS", - 4: "GridFTP", - 5: "LOCAL", - } - - _NAMES_TO_VALUES = { - "SCP": 0, - "SFTP": 1, - "HTTP": 2, - "HTTPS": 3, - "GridFTP": 4, - "LOCAL": 5, - } - -class FileNodeTypes: - DIRECTORY = 0 - FILE = 1 - - _VALUES_TO_NAMES = { - 0: "DIRECTORY", - 1: "FILE", - } - - _NAMES_TO_VALUES = { - "DIRECTORY": 0, - "FILE": 1, - } - -class FileTransferMode: - SYNC = 0 - ASYNC = 1 - - _VALUES_TO_NAMES = { - 0: "SYNC", - 1: "ASYNC", - } - - _NAMES_TO_VALUES = { - "SYNC": 0, - "ASYNC": 1, - } - -class FileTransferStatus: - CREATED = 0 - QUEUED = 1 - RUNNING = 2 - COMPLETED = 3 - FAILED = 4 - - _VALUES_TO_NAMES = { - 0: "CREATED", - 1: "QUEUED", - 2: "RUNNING", - 3: "COMPLETED", - 4: "FAILED", - } - - _NAMES_TO_VALUES = { - "CREATED": 0, - "QUEUED": 1, - "RUNNING": 2, - "COMPLETED": 3, - "FAILED": 4, - } - - -class FileTransferRequest: - """ - Attributes: - - transferId - - srcHostname - - srcLoginName - - srcPort - - srcProtocol - - srcFilePath - - srcHostCredToken - - destHostname - - destLoginName - - destPort - - destProtocol - - destFilePath - - destHostCredToken - - fileTransferMode - - transferStatus - - fileSize - - transferTime - - createdTime - - lastModifiedType - """ - - thrift_spec = ( - None, # 0 - (1, TType.STRING, 'transferId', None, None, ), # 1 - (2, TType.STRING, 'srcHostname', None, None, ), # 2 - (3, TType.STRING, 'srcLoginName', None, None, ), # 3 - (4, TType.I64, 'srcPort', None, None, ), # 4 - (5, TType.I32, 'srcProtocol', None, None, ), # 5 - (6, TType.STRING, 'srcFilePath', None, None, ), # 6 - (7, TType.STRING, 'srcHostCredToken', None, None, ), # 7 - (8, TType.STRING, 'destHostname', None, None, ), # 8 - (9, TType.STRING, 'destLoginName', None, None, ), # 9 - (10, TType.I64, 'destPort', None, None, ), # 10 - (11, TType.I32, 'destProtocol', None, None, ), # 11 - (12, TType.STRING, 'destFilePath', None, None, ), # 12 - (13, TType.STRING, 'destHostCredToken', None, None, ), # 13 - (14, TType.I32, 'fileTransferMode', None, None, ), # 14 - (15, TType.I32, 'transferStatus', None, None, ), # 15 - (16, TType.I64, 'fileSize', None, None, ), # 16 - (17, TType.I64, 'transferTime', None, None, ), # 17 - (18, TType.I64, 'createdTime', None, None, ), # 18 - (19, TType.I64, 'lastModifiedType', None, None, ), # 19 - ) - - def __init__(self, transferId=None, srcHostname=None, srcLoginName=None, srcPort=None, srcProtocol=None, srcFilePath=None, srcHostCredToken=None, destHostname=None, destLoginName=None, destPort=None, destProtocol=None, destFilePath=None, destHostCredToken=None, fileTransferMode=None, transferStatus=None, fileSize=None, transferTime=None, createdTime=None, lastModifiedType=None,): - self.transferId = transferId - self.srcHostname = srcHostname - self.srcLoginName = srcLoginName - self.srcPort = srcPort - self.srcProtocol = srcProtocol - self.srcFilePath = srcFilePath - self.srcHostCredToken = srcHostCredToken - self.destHostname = destHostname - self.destLoginName = destLoginName - self.destPort = destPort - self.destProtocol = destProtocol - self.destFilePath = destFilePath - self.destHostCredToken = destHostCredToken - self.fileTransferMode = fileTransferMode - self.transferStatus = transferStatus - self.fileSize = fileSize - self.transferTime = transferTime - self.createdTime = createdTime - self.lastModifiedType = lastModifiedType - - 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)) - return - iprot.readStructBegin() - while True: - (fname, ftype, fid) = iprot.readFieldBegin() - if ftype == TType.STOP: - break - if fid == 1: - if ftype == TType.STRING: - self.transferId = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 2: - if ftype == TType.STRING: - self.srcHostname = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 3: - if ftype == TType.STRING: - self.srcLoginName = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 4: - if ftype == TType.I64: - self.srcPort = iprot.readI64() - else: - iprot.skip(ftype) - elif fid == 5: - if ftype == TType.I32: - self.srcProtocol = iprot.readI32() - else: - iprot.skip(ftype) - elif fid == 6: - if ftype == TType.STRING: - self.srcFilePath = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 7: - if ftype == TType.STRING: - self.srcHostCredToken = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 8: - if ftype == TType.STRING: - self.destHostname = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 9: - if ftype == TType.STRING: - self.destLoginName = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 10: - if ftype == TType.I64: - self.destPort = iprot.readI64() - else: - iprot.skip(ftype) - elif fid == 11: - if ftype == TType.I32: - self.destProtocol = iprot.readI32() - else: - iprot.skip(ftype) - elif fid == 12: - if ftype == TType.STRING: - self.destFilePath = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 13: - if ftype == TType.STRING: - self.destHostCredToken = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 14: - if ftype == TType.I32: - self.fileTransferMode = iprot.readI32() - else: - iprot.skip(ftype) - elif fid == 15: - if ftype == TType.I32: - self.transferStatus = iprot.readI32() - else: - iprot.skip(ftype) - elif fid == 16: - if ftype == TType.I64: - self.fileSize = iprot.readI64() - else: - iprot.skip(ftype) - elif fid == 17: - if ftype == TType.I64: - self.transferTime = iprot.readI64() - else: - iprot.skip(ftype) - elif fid == 18: - if ftype == TType.I64: - self.createdTime = iprot.readI64() - else: - iprot.skip(ftype) - elif fid == 19: - if ftype == TType.I64: - self.lastModifiedType = iprot.readI64() - else: - iprot.skip(ftype) - else: - iprot.skip(ftype) - iprot.readFieldEnd() - iprot.readStructEnd() - - def write(self, oprot): - if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None: - oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec))) - return - oprot.writeStructBegin('FileTransferRequest') - if self.transferId is not None: - oprot.writeFieldBegin('transferId', TType.STRING, 1) - oprot.writeString(self.transferId) - oprot.writeFieldEnd() - if self.srcHostname is not None: - oprot.writeFieldBegin('srcHostname', TType.STRING, 2) - oprot.writeString(self.srcHostname) - oprot.writeFieldEnd() - if self.srcLoginName is not None: - oprot.writeFieldBegin('srcLoginName', TType.STRING, 3) - oprot.writeString(self.srcLoginName) - oprot.writeFieldEnd() - if self.srcPort is not None: - oprot.writeFieldBegin('srcPort', TType.I64, 4) - oprot.writeI64(self.srcPort) - oprot.writeFieldEnd() - if self.srcProtocol is not None: - oprot.writeFieldBegin('srcProtocol', TType.I32, 5) - oprot.writeI32(self.srcProtocol) - oprot.writeFieldEnd() - if self.srcFilePath is not None: - oprot.writeFieldBegin('srcFilePath', TType.STRING, 6) - oprot.writeString(self.srcFilePath) - oprot.writeFieldEnd() - if self.srcHostCredToken is not None: - oprot.writeFieldBegin('srcHostCredToken', TType.STRING, 7) - oprot.writeString(self.srcHostCredToken) - oprot.writeFieldEnd() - if self.destHostname is not None: - oprot.writeFieldBegin('destHostname', TType.STRING, 8) - oprot.writeString(self.destHostname) - oprot.writeFieldEnd() - if self.destLoginName is not None: - oprot.writeFieldBegin('destLoginName', TType.STRING, 9) - oprot.writeString(self.destLoginName) - oprot.writeFieldEnd() - if self.destPort is not None: - oprot.writeFieldBegin('destPort', TType.I64, 10) - oprot.writeI64(self.destPort) - oprot.writeFieldEnd() - if self.destProtocol is not None: - oprot.writeFieldBegin('destProtocol', TType.I32, 11) - oprot.writeI32(self.destProtocol) - oprot.writeFieldEnd() - if self.destFilePath is not None: - oprot.writeFieldBegin('destFilePath', TType.STRING, 12) - oprot.writeString(self.destFilePath) - oprot.writeFieldEnd() - if self.destHostCredToken is not None: - oprot.writeFieldBegin('destHostCredToken', TType.STRING, 13) - oprot.writeString(self.destHostCredToken) - oprot.writeFieldEnd() - if self.fileTransferMode is not None: - oprot.writeFieldBegin('fileTransferMode', TType.I32, 14) - oprot.writeI32(self.fileTransferMode) - oprot.writeFieldEnd() - if self.transferStatus is not None: - oprot.writeFieldBegin('transferStatus', TType.I32, 15) - oprot.writeI32(self.transferStatus) - oprot.writeFieldEnd() - if self.fileSize is not None: - oprot.writeFieldBegin('fileSize', TType.I64, 16) - oprot.writeI64(self.fileSize) - oprot.writeFieldEnd() - if self.transferTime is not None: - oprot.writeFieldBegin('transferTime', TType.I64, 17) - oprot.writeI64(self.transferTime) - oprot.writeFieldEnd() - if self.createdTime is not None: - oprot.writeFieldBegin('createdTime', TType.I64, 18) - oprot.writeI64(self.createdTime) - oprot.writeFieldEnd() - if self.lastModifiedType is not None: - oprot.writeFieldBegin('lastModifiedType', TType.I64, 19) - oprot.writeI64(self.lastModifiedType) - oprot.writeFieldEnd() - oprot.writeFieldStop() - oprot.writeStructEnd() - - def validate(self): - return - - - def __hash__(self): - value = 17 - value = (value * 31) ^ hash(self.transferId) - value = (value * 31) ^ hash(self.srcHostname) - value = (value * 31) ^ hash(self.srcLoginName) - value = (value * 31) ^ hash(self.srcPort) - value = (value * 31) ^ hash(self.srcProtocol) - value = (value * 31) ^ hash(self.srcFilePath) - value = (value * 31) ^ hash(self.srcHostCredToken) - value = (value * 31) ^ hash(self.destHostname) - value = (value * 31) ^ hash(self.destLoginName) - value = (value * 31) ^ hash(self.destPort) - value = (value * 31) ^ hash(self.destProtocol) - value = (value * 31) ^ hash(self.destFilePath) - value = (value * 31) ^ hash(self.destHostCredToken) - value = (value * 31) ^ hash(self.fileTransferMode) - value = (value * 31) ^ hash(self.transferStatus) - value = (value * 31) ^ hash(self.fileSize) - value = (value * 31) ^ hash(self.transferTime) - value = (value * 31) ^ hash(self.createdTime) - value = (value * 31) ^ hash(self.lastModifiedType) - return value - - def __repr__(self): - L = ['%s=%r' % (key, value) - for key, value in self.__dict__.iteritems()] - return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) - - def __eq__(self, other): - return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ - - def __ne__(self, other): - return not (self == other) - -class FileNode: - """ - Attributes: - - type - - size - - nativeType - - name - - path - - storageHostName - - lastModifiedType - - createdTime - """ - - thrift_spec = ( - None, # 0 - (1, TType.I32, 'type', None, None, ), # 1 - (2, TType.I64, 'size', None, None, ), # 2 - (3, TType.STRING, 'nativeType', None, None, ), # 3 - (4, TType.STRING, 'name', None, None, ), # 4 - (5, TType.STRING, 'path', None, None, ), # 5 - (6, TType.STRING, 'storageHostName', None, None, ), # 6 - (7, TType.I64, 'lastModifiedType', None, None, ), # 7 - (8, TType.I64, 'createdTime', None, None, ), # 8 - ) - - def __init__(self, type=None, size=None, nativeType=None, name=None, path=None, storageHostName=None, lastModifiedType=None, createdTime=None,): - self.type = type - self.size = size - self.nativeType = nativeType - self.name = name - self.path = path - self.storageHostName = storageHostName - self.lastModifiedType = lastModifiedType - self.createdTime = createdTime - - 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)) - return - iprot.readStructBegin() - while True: - (fname, ftype, fid) = iprot.readFieldBegin() - if ftype == TType.STOP: - break - if fid == 1: - if ftype == TType.I32: - self.type = iprot.readI32() - else: - iprot.skip(ftype) - elif fid == 2: - if ftype == TType.I64: - self.size = iprot.readI64() - else: - iprot.skip(ftype) - elif fid == 3: - if ftype == TType.STRING: - self.nativeType = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 4: - if ftype == TType.STRING: - self.name = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 5: - if ftype == TType.STRING: - self.path = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 6: - if ftype == TType.STRING: - self.storageHostName = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 7: - if ftype == TType.I64: - self.lastModifiedType = iprot.readI64() - else: - iprot.skip(ftype) - elif fid == 8: - if ftype == TType.I64: - self.createdTime = iprot.readI64() - else: - iprot.skip(ftype) - else: - iprot.skip(ftype) - iprot.readFieldEnd() - iprot.readStructEnd() - - def write(self, oprot): - if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None: - oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec))) - return - oprot.writeStructBegin('FileNode') - if self.type is not None: - oprot.writeFieldBegin('type', TType.I32, 1) - oprot.writeI32(self.type) - oprot.writeFieldEnd() - if self.size is not None: - oprot.writeFieldBegin('size', TType.I64, 2) - oprot.writeI64(self.size) - oprot.writeFieldEnd() - if self.nativeType is not None: - oprot.writeFieldBegin('nativeType', TType.STRING, 3) - oprot.writeString(self.nativeType) - oprot.writeFieldEnd() - if self.name is not None: - oprot.writeFieldBegin('name', TType.STRING, 4) - oprot.writeString(self.name) - oprot.writeFieldEnd() - if self.path is not None: - oprot.writeFieldBegin('path', TType.STRING, 5) - oprot.writeString(self.path) - oprot.writeFieldEnd() - if self.storageHostName is not None: - oprot.writeFieldBegin('storageHostName', TType.STRING, 6) - oprot.writeString(self.storageHostName) - oprot.writeFieldEnd() - if self.lastModifiedType is not None: - oprot.writeFieldBegin('lastModifiedType', TType.I64, 7) - oprot.writeI64(self.lastModifiedType) - oprot.writeFieldEnd() - if self.createdTime is not None: - oprot.writeFieldBegin('createdTime', TType.I64, 8) - oprot.writeI64(self.createdTime) - oprot.writeFieldEnd() - oprot.writeFieldStop() - oprot.writeStructEnd() - - def validate(self): - return - - - def __hash__(self): - value = 17 - value = (value * 31) ^ hash(self.type) - value = (value * 31) ^ hash(self.size) - value = (value * 31) ^ hash(self.nativeType) - value = (value * 31) ^ hash(self.name) - value = (value * 31) ^ hash(self.path) - value = (value * 31) ^ hash(self.storageHostName) - value = (value * 31) ^ hash(self.lastModifiedType) - value = (value * 31) ^ hash(self.createdTime) - return value - - def __repr__(self): - L = ['%s=%r' % (key, value) - for key, value in self.__dict__.iteritems()] - return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) - - def __eq__(self, other): - return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ - - def __ne__(self, other): - return not (self == other)
http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/apache/airavata/model/replica/__init__.py ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/apache/airavata/model/replica/__init__.py b/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/apache/airavata/model/replica/__init__.py deleted file mode 100644 index adefd8e..0000000 --- a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/apache/airavata/model/replica/__init__.py +++ /dev/null @@ -1 +0,0 @@ -__all__ = ['ttypes', 'constants'] http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/apache/airavata/model/replica/constants.py ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/apache/airavata/model/replica/constants.py b/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/apache/airavata/model/replica/constants.py deleted file mode 100644 index 4a6492b..0000000 --- a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/apache/airavata/model/replica/constants.py +++ /dev/null @@ -1,11 +0,0 @@ -# -# Autogenerated by Thrift Compiler (0.9.3) -# -# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING -# -# options string: py -# - -from thrift.Thrift import TType, TMessageType, TException, TApplicationException -from ttypes import * - http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/apache/airavata/model/replica/ttypes.py ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/apache/airavata/model/replica/ttypes.py b/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/apache/airavata/model/replica/ttypes.py deleted file mode 100644 index 58b9cff..0000000 --- a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/apache/airavata/model/replica/ttypes.py +++ /dev/null @@ -1,574 +0,0 @@ -# -# Autogenerated by Thrift Compiler (0.9.3) -# -# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING -# -# options string: py -# - -from thrift.Thrift import TType, TMessageType, TException, TApplicationException -import apache.airavata.model.data.movement.ttypes - - -from thrift.transport import TTransport -from thrift.protocol import TBinaryProtocol, TProtocol -try: - from thrift.protocol import fastbinary -except: - fastbinary = None - - -class ReplicaLocationCategory: - GATEWAY_DATA_STORE = 0 - COMPUTE_RESOURCE = 1 - LONG_TERM_STORAGE_RESOURCE = 2 - OTHER = 3 - - _VALUES_TO_NAMES = { - 0: "GATEWAY_DATA_STORE", - 1: "COMPUTE_RESOURCE", - 2: "LONG_TERM_STORAGE_RESOURCE", - 3: "OTHER", - } - - _NAMES_TO_VALUES = { - "GATEWAY_DATA_STORE": 0, - "COMPUTE_RESOURCE": 1, - "LONG_TERM_STORAGE_RESOURCE": 2, - "OTHER": 3, - } - -class ReplicaPersistentType: - TRANSIENT = 0 - PERSISTENT = 1 - - _VALUES_TO_NAMES = { - 0: "TRANSIENT", - 1: "PERSISTENT", - } - - _NAMES_TO_VALUES = { - "TRANSIENT": 0, - "PERSISTENT": 1, - } - -class DataResourceType: - COLLECTION = 0 - FILE = 1 - - _VALUES_TO_NAMES = { - 0: "COLLECTION", - 1: "FILE", - } - - _NAMES_TO_VALUES = { - "COLLECTION": 0, - "FILE": 1, - } - - -class DataResourceModel: - """ - Attributes: - - resourceId - - gatewayId - - parentResourceId - - resourceName - - resourceDescription - - ownerName - - sha256Checksum - - dataResourceType - - resourceSize - - nativeFormat - - creationTime - - lastModifiedTime - - resourceMetadata - - replicaLocations - - childResources - """ - - thrift_spec = ( - None, # 0 - (1, TType.STRING, 'resourceId', None, None, ), # 1 - (2, TType.STRING, 'gatewayId', None, None, ), # 2 - (3, TType.STRING, 'parentResourceId', None, None, ), # 3 - (4, TType.STRING, 'resourceName', None, None, ), # 4 - (5, TType.STRING, 'resourceDescription', None, None, ), # 5 - (6, TType.STRING, 'ownerName', None, None, ), # 6 - (7, TType.STRING, 'sha256Checksum', None, None, ), # 7 - (8, TType.I32, 'dataResourceType', None, None, ), # 8 - (9, TType.I32, 'resourceSize', None, None, ), # 9 - (10, TType.STRING, 'nativeFormat', None, None, ), # 10 - (11, TType.I64, 'creationTime', None, None, ), # 11 - (12, TType.I64, 'lastModifiedTime', None, None, ), # 12 - (13, TType.MAP, 'resourceMetadata', (TType.STRING,None,TType.STRING,None), None, ), # 13 - (14, TType.LIST, 'replicaLocations', (TType.STRUCT,(DataReplicaLocationModel, DataReplicaLocationModel.thrift_spec)), None, ), # 14 - (15, TType.LIST, 'childResources', (TType.STRUCT,(DataResourceModel, DataResourceModel.thrift_spec)), None, ), # 15 - ) - - def __init__(self, resourceId=None, gatewayId=None, parentResourceId=None, resourceName=None, resourceDescription=None, ownerName=None, sha256Checksum=None, dataResourceType=None, resourceSize=None, nativeFormat=None, creationTime=None, lastModifiedTime=None, resourceMetadata=None, replicaLocations=None, childResources=None,): - self.resourceId = resourceId - self.gatewayId = gatewayId - self.parentResourceId = parentResourceId - self.resourceName = resourceName - self.resourceDescription = resourceDescription - self.ownerName = ownerName - self.sha256Checksum = sha256Checksum - self.dataResourceType = dataResourceType - self.resourceSize = resourceSize - self.nativeFormat = nativeFormat - self.creationTime = creationTime - self.lastModifiedTime = lastModifiedTime - self.resourceMetadata = resourceMetadata - self.replicaLocations = replicaLocations - self.childResources = childResources - - 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)) - return - iprot.readStructBegin() - while True: - (fname, ftype, fid) = iprot.readFieldBegin() - if ftype == TType.STOP: - break - if fid == 1: - if ftype == TType.STRING: - self.resourceId = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 2: - if ftype == TType.STRING: - self.gatewayId = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 3: - if ftype == TType.STRING: - self.parentResourceId = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 4: - if ftype == TType.STRING: - self.resourceName = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 5: - if ftype == TType.STRING: - self.resourceDescription = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 6: - if ftype == TType.STRING: - self.ownerName = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 7: - if ftype == TType.STRING: - self.sha256Checksum = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 8: - if ftype == TType.I32: - self.dataResourceType = iprot.readI32() - else: - iprot.skip(ftype) - elif fid == 9: - if ftype == TType.I32: - self.resourceSize = iprot.readI32() - else: - iprot.skip(ftype) - elif fid == 10: - if ftype == TType.STRING: - self.nativeFormat = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 11: - if ftype == TType.I64: - self.creationTime = iprot.readI64() - else: - iprot.skip(ftype) - elif fid == 12: - if ftype == TType.I64: - self.lastModifiedTime = iprot.readI64() - else: - iprot.skip(ftype) - elif fid == 13: - if ftype == TType.MAP: - self.resourceMetadata = {} - (_ktype1, _vtype2, _size0 ) = iprot.readMapBegin() - for _i4 in xrange(_size0): - _key5 = iprot.readString() - _val6 = iprot.readString() - self.resourceMetadata[_key5] = _val6 - iprot.readMapEnd() - else: - iprot.skip(ftype) - elif fid == 14: - if ftype == TType.LIST: - self.replicaLocations = [] - (_etype10, _size7) = iprot.readListBegin() - for _i11 in xrange(_size7): - _elem12 = DataReplicaLocationModel() - _elem12.read(iprot) - self.replicaLocations.append(_elem12) - iprot.readListEnd() - else: - iprot.skip(ftype) - elif fid == 15: - if ftype == TType.LIST: - self.childResources = [] - (_etype16, _size13) = iprot.readListBegin() - for _i17 in xrange(_size13): - _elem18 = DataResourceModel() - _elem18.read(iprot) - self.childResources.append(_elem18) - iprot.readListEnd() - else: - iprot.skip(ftype) - else: - iprot.skip(ftype) - iprot.readFieldEnd() - iprot.readStructEnd() - - def write(self, oprot): - if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None: - oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec))) - return - oprot.writeStructBegin('DataResourceModel') - if self.resourceId is not None: - oprot.writeFieldBegin('resourceId', TType.STRING, 1) - oprot.writeString(self.resourceId) - oprot.writeFieldEnd() - if self.gatewayId is not None: - oprot.writeFieldBegin('gatewayId', TType.STRING, 2) - oprot.writeString(self.gatewayId) - oprot.writeFieldEnd() - if self.parentResourceId is not None: - oprot.writeFieldBegin('parentResourceId', TType.STRING, 3) - oprot.writeString(self.parentResourceId) - oprot.writeFieldEnd() - if self.resourceName is not None: - oprot.writeFieldBegin('resourceName', TType.STRING, 4) - oprot.writeString(self.resourceName) - oprot.writeFieldEnd() - if self.resourceDescription is not None: - oprot.writeFieldBegin('resourceDescription', TType.STRING, 5) - oprot.writeString(self.resourceDescription) - oprot.writeFieldEnd() - if self.ownerName is not None: - oprot.writeFieldBegin('ownerName', TType.STRING, 6) - oprot.writeString(self.ownerName) - oprot.writeFieldEnd() - if self.sha256Checksum is not None: - oprot.writeFieldBegin('sha256Checksum', TType.STRING, 7) - oprot.writeString(self.sha256Checksum) - oprot.writeFieldEnd() - if self.dataResourceType is not None: - oprot.writeFieldBegin('dataResourceType', TType.I32, 8) - oprot.writeI32(self.dataResourceType) - oprot.writeFieldEnd() - if self.resourceSize is not None: - oprot.writeFieldBegin('resourceSize', TType.I32, 9) - oprot.writeI32(self.resourceSize) - oprot.writeFieldEnd() - if self.nativeFormat is not None: - oprot.writeFieldBegin('nativeFormat', TType.STRING, 10) - oprot.writeString(self.nativeFormat) - oprot.writeFieldEnd() - if self.creationTime is not None: - oprot.writeFieldBegin('creationTime', TType.I64, 11) - oprot.writeI64(self.creationTime) - oprot.writeFieldEnd() - if self.lastModifiedTime is not None: - oprot.writeFieldBegin('lastModifiedTime', TType.I64, 12) - oprot.writeI64(self.lastModifiedTime) - oprot.writeFieldEnd() - if self.resourceMetadata is not None: - oprot.writeFieldBegin('resourceMetadata', TType.MAP, 13) - oprot.writeMapBegin(TType.STRING, TType.STRING, len(self.resourceMetadata)) - for kiter19,viter20 in self.resourceMetadata.items(): - oprot.writeString(kiter19) - oprot.writeString(viter20) - oprot.writeMapEnd() - oprot.writeFieldEnd() - if self.replicaLocations is not None: - oprot.writeFieldBegin('replicaLocations', TType.LIST, 14) - oprot.writeListBegin(TType.STRUCT, len(self.replicaLocations)) - for iter21 in self.replicaLocations: - iter21.write(oprot) - oprot.writeListEnd() - oprot.writeFieldEnd() - if self.childResources is not None: - oprot.writeFieldBegin('childResources', TType.LIST, 15) - oprot.writeListBegin(TType.STRUCT, len(self.childResources)) - for iter22 in self.childResources: - iter22.write(oprot) - oprot.writeListEnd() - oprot.writeFieldEnd() - oprot.writeFieldStop() - oprot.writeStructEnd() - - def validate(self): - return - - - def __hash__(self): - value = 17 - value = (value * 31) ^ hash(self.resourceId) - value = (value * 31) ^ hash(self.gatewayId) - value = (value * 31) ^ hash(self.parentResourceId) - value = (value * 31) ^ hash(self.resourceName) - value = (value * 31) ^ hash(self.resourceDescription) - value = (value * 31) ^ hash(self.ownerName) - value = (value * 31) ^ hash(self.sha256Checksum) - value = (value * 31) ^ hash(self.dataResourceType) - value = (value * 31) ^ hash(self.resourceSize) - value = (value * 31) ^ hash(self.nativeFormat) - value = (value * 31) ^ hash(self.creationTime) - value = (value * 31) ^ hash(self.lastModifiedTime) - value = (value * 31) ^ hash(self.resourceMetadata) - value = (value * 31) ^ hash(self.replicaLocations) - value = (value * 31) ^ hash(self.childResources) - return value - - def __repr__(self): - L = ['%s=%r' % (key, value) - for key, value in self.__dict__.iteritems()] - return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) - - def __eq__(self, other): - return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ - - def __ne__(self, other): - return not (self == other) - -class DataReplicaLocationModel: - """ - Attributes: - - replicaId - - resourceId - - replicaName - - replicaDescription - - sourceReplicaId - - creationTime - - lastModifiedTime - - validUntilTime - - replicaLocationCategory - - replicaPersistentType - - storageResourceId - - fileAbsolutePath - - replicaMetadata - """ - - thrift_spec = ( - None, # 0 - (1, TType.STRING, 'replicaId', None, None, ), # 1 - (2, TType.STRING, 'resourceId', None, None, ), # 2 - (3, TType.STRING, 'replicaName', None, None, ), # 3 - (4, TType.STRING, 'replicaDescription', None, None, ), # 4 - (5, TType.STRING, 'sourceReplicaId', None, None, ), # 5 - (6, TType.I64, 'creationTime', None, None, ), # 6 - (7, TType.I64, 'lastModifiedTime', None, None, ), # 7 - (8, TType.I64, 'validUntilTime', None, None, ), # 8 - (9, TType.I32, 'replicaLocationCategory', None, None, ), # 9 - (10, TType.I32, 'replicaPersistentType', None, None, ), # 10 - (11, TType.STRING, 'storageResourceId', None, None, ), # 11 - (12, TType.STRING, 'fileAbsolutePath', None, None, ), # 12 - (13, TType.MAP, 'replicaMetadata', (TType.STRING,None,TType.STRING,None), None, ), # 13 - ) - - def __init__(self, replicaId=None, resourceId=None, replicaName=None, replicaDescription=None, sourceReplicaId=None, creationTime=None, lastModifiedTime=None, validUntilTime=None, replicaLocationCategory=None, replicaPersistentType=None, storageResourceId=None, fileAbsolutePath=None, replicaMetadata=None,): - self.replicaId = replicaId - self.resourceId = resourceId - self.replicaName = replicaName - self.replicaDescription = replicaDescription - self.sourceReplicaId = sourceReplicaId - self.creationTime = creationTime - self.lastModifiedTime = lastModifiedTime - self.validUntilTime = validUntilTime - self.replicaLocationCategory = replicaLocationCategory - self.replicaPersistentType = replicaPersistentType - self.storageResourceId = storageResourceId - self.fileAbsolutePath = fileAbsolutePath - self.replicaMetadata = replicaMetadata - - 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)) - return - iprot.readStructBegin() - while True: - (fname, ftype, fid) = iprot.readFieldBegin() - if ftype == TType.STOP: - break - if fid == 1: - if ftype == TType.STRING: - self.replicaId = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 2: - if ftype == TType.STRING: - self.resourceId = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 3: - if ftype == TType.STRING: - self.replicaName = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 4: - if ftype == TType.STRING: - self.replicaDescription = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 5: - if ftype == TType.STRING: - self.sourceReplicaId = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 6: - if ftype == TType.I64: - self.creationTime = iprot.readI64() - else: - iprot.skip(ftype) - elif fid == 7: - if ftype == TType.I64: - self.lastModifiedTime = iprot.readI64() - else: - iprot.skip(ftype) - elif fid == 8: - if ftype == TType.I64: - self.validUntilTime = iprot.readI64() - else: - iprot.skip(ftype) - elif fid == 9: - if ftype == TType.I32: - self.replicaLocationCategory = iprot.readI32() - else: - iprot.skip(ftype) - elif fid == 10: - if ftype == TType.I32: - self.replicaPersistentType = iprot.readI32() - else: - iprot.skip(ftype) - elif fid == 11: - if ftype == TType.STRING: - self.storageResourceId = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 12: - if ftype == TType.STRING: - self.fileAbsolutePath = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 13: - if ftype == TType.MAP: - self.replicaMetadata = {} - (_ktype24, _vtype25, _size23 ) = iprot.readMapBegin() - for _i27 in xrange(_size23): - _key28 = iprot.readString() - _val29 = iprot.readString() - self.replicaMetadata[_key28] = _val29 - iprot.readMapEnd() - else: - iprot.skip(ftype) - else: - iprot.skip(ftype) - iprot.readFieldEnd() - iprot.readStructEnd() - - def write(self, oprot): - if oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and self.thrift_spec is not None and fastbinary is not None: - oprot.trans.write(fastbinary.encode_binary(self, (self.__class__, self.thrift_spec))) - return - oprot.writeStructBegin('DataReplicaLocationModel') - if self.replicaId is not None: - oprot.writeFieldBegin('replicaId', TType.STRING, 1) - oprot.writeString(self.replicaId) - oprot.writeFieldEnd() - if self.resourceId is not None: - oprot.writeFieldBegin('resourceId', TType.STRING, 2) - oprot.writeString(self.resourceId) - oprot.writeFieldEnd() - if self.replicaName is not None: - oprot.writeFieldBegin('replicaName', TType.STRING, 3) - oprot.writeString(self.replicaName) - oprot.writeFieldEnd() - if self.replicaDescription is not None: - oprot.writeFieldBegin('replicaDescription', TType.STRING, 4) - oprot.writeString(self.replicaDescription) - oprot.writeFieldEnd() - if self.sourceReplicaId is not None: - oprot.writeFieldBegin('sourceReplicaId', TType.STRING, 5) - oprot.writeString(self.sourceReplicaId) - oprot.writeFieldEnd() - if self.creationTime is not None: - oprot.writeFieldBegin('creationTime', TType.I64, 6) - oprot.writeI64(self.creationTime) - oprot.writeFieldEnd() - if self.lastModifiedTime is not None: - oprot.writeFieldBegin('lastModifiedTime', TType.I64, 7) - oprot.writeI64(self.lastModifiedTime) - oprot.writeFieldEnd() - if self.validUntilTime is not None: - oprot.writeFieldBegin('validUntilTime', TType.I64, 8) - oprot.writeI64(self.validUntilTime) - oprot.writeFieldEnd() - if self.replicaLocationCategory is not None: - oprot.writeFieldBegin('replicaLocationCategory', TType.I32, 9) - oprot.writeI32(self.replicaLocationCategory) - oprot.writeFieldEnd() - if self.replicaPersistentType is not None: - oprot.writeFieldBegin('replicaPersistentType', TType.I32, 10) - oprot.writeI32(self.replicaPersistentType) - oprot.writeFieldEnd() - if self.storageResourceId is not None: - oprot.writeFieldBegin('storageResourceId', TType.STRING, 11) - oprot.writeString(self.storageResourceId) - oprot.writeFieldEnd() - if self.fileAbsolutePath is not None: - oprot.writeFieldBegin('fileAbsolutePath', TType.STRING, 12) - oprot.writeString(self.fileAbsolutePath) - oprot.writeFieldEnd() - if self.replicaMetadata is not None: - oprot.writeFieldBegin('replicaMetadata', TType.MAP, 13) - oprot.writeMapBegin(TType.STRING, TType.STRING, len(self.replicaMetadata)) - for kiter30,viter31 in self.replicaMetadata.items(): - oprot.writeString(kiter30) - oprot.writeString(viter31) - oprot.writeMapEnd() - oprot.writeFieldEnd() - oprot.writeFieldStop() - oprot.writeStructEnd() - - def validate(self): - return - - - def __hash__(self): - value = 17 - value = (value * 31) ^ hash(self.replicaId) - value = (value * 31) ^ hash(self.resourceId) - value = (value * 31) ^ hash(self.replicaName) - value = (value * 31) ^ hash(self.replicaDescription) - value = (value * 31) ^ hash(self.sourceReplicaId) - value = (value * 31) ^ hash(self.creationTime) - value = (value * 31) ^ hash(self.lastModifiedTime) - value = (value * 31) ^ hash(self.validUntilTime) - value = (value * 31) ^ hash(self.replicaLocationCategory) - value = (value * 31) ^ hash(self.replicaPersistentType) - value = (value * 31) ^ hash(self.storageResourceId) - value = (value * 31) ^ hash(self.fileAbsolutePath) - value = (value * 31) ^ hash(self.replicaMetadata) - return value - - def __repr__(self): - L = ['%s=%r' % (key, value) - for key, value in self.__dict__.iteritems()] - return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) - - def __eq__(self, other): - return isinstance(other, self.__class__) and self.__dict__ == other.__dict__ - - def __ne__(self, other): - return not (self == other) http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/apache/airavata/model/ttypes.py ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/apache/airavata/model/ttypes.py b/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/apache/airavata/model/ttypes.py index e3e0e8f..ddb7404 100644 --- a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/apache/airavata/model/ttypes.py +++ b/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/apache/airavata/model/ttypes.py @@ -19,8 +19,9 @@ import apache.airavata.model.process.ttypes import apache.airavata.model.scheduling.ttypes import apache.airavata.model.status.ttypes import apache.airavata.model.data.movement.ttypes -import apache.airavata.model.replica.ttypes -import apache.airavata.model.file.ttypes +import apache.airavata.model.file.replica.ttypes +import apache.airavata.model.file.transfer.ttypes +import apache.airavata.model.file.metadata.ttypes from thrift.transport import TTransport http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/TSCons.py ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/TSCons.py b/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/TSCons.py deleted file mode 100644 index da8d283..0000000 --- a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/TSCons.py +++ /dev/null @@ -1,35 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -from os import path -from SCons.Builder import Builder - - -def scons_env(env, add=''): - opath = path.dirname(path.abspath('$TARGET')) - lstr = 'thrift --gen cpp -o ' + opath + ' ' + add + ' $SOURCE' - cppbuild = Builder(action=lstr) - env.Append(BUILDERS={'ThriftCpp': cppbuild}) - - -def gen_cpp(env, dir, file): - scons_env(env) - suffixes = ['_types.h', '_types.cpp'] - targets = map(lambda s: 'gen-cpp/' + file + s, suffixes) - return env.ThriftCpp(targets, dir + file + '.thrift') http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/TSerialization.py ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/TSerialization.py b/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/TSerialization.py deleted file mode 100644 index 54f10e2..0000000 --- a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/TSerialization.py +++ /dev/null @@ -1,38 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -from lib.thrift.protocol import TBinaryProtocol -from lib.thrift.transport import TTransport - - -def serialize(thrift_object, - protocol_factory=TBinaryProtocol.TBinaryProtocolFactory()): - transport = TTransport.TMemoryBuffer() - protocol = protocol_factory.getProtocol(transport) - thrift_object.write(protocol) - return transport.getvalue() - - -def deserialize(base, - buf, - protocol_factory=TBinaryProtocol.TBinaryProtocolFactory()): - transport = TTransport.TMemoryBuffer(buf) - protocol = protocol_factory.getProtocol(transport) - base.read(protocol) - return base http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/TTornado.py ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/TTornado.py b/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/TTornado.py deleted file mode 100644 index af309c3..0000000 --- a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/TTornado.py +++ /dev/null @@ -1,153 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -from cStringIO import StringIO -import logging -import socket -import struct - -from thrift.transport import TTransport -from thrift.transport.TTransport import TTransportException - -from tornado import gen -from tornado import iostream -from tornado import netutil - - -class TTornadoStreamTransport(TTransport.TTransportBase): - """a framed, buffered transport over a Tornado stream""" - def __init__(self, host, port, stream=None): - self.host = host - self.port = port - self.is_queuing_reads = False - self.read_queue = [] - self.__wbuf = StringIO() - - # servers provide a ready-to-go stream - self.stream = stream - if self.stream is not None: - self._set_close_callback() - - # not the same number of parameters as TTransportBase.open - def open(self, callback): - logging.debug('socket connecting') - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0) - self.stream = iostream.IOStream(sock) - - def on_close_in_connect(*_): - message = 'could not connect to {}:{}'.format(self.host, self.port) - raise TTransportException( - type=TTransportException.NOT_OPEN, - message=message) - self.stream.set_close_callback(on_close_in_connect) - - def finish(*_): - self._set_close_callback() - callback() - - self.stream.connect((self.host, self.port), callback=finish) - - def _set_close_callback(self): - def on_close(): - raise TTransportException( - type=TTransportException.END_OF_FILE, - message='socket closed') - self.stream.set_close_callback(self.close) - - def close(self): - # don't raise if we intend to close - self.stream.set_close_callback(None) - self.stream.close() - - def read(self, _): - # The generated code for Tornado shouldn't do individual reads -- only - # frames at a time - assert "you're doing it wrong" is True - - @gen.engine - def readFrame(self, callback): - self.read_queue.append(callback) - logging.debug('read queue: %s', self.read_queue) - - if self.is_queuing_reads: - # If a read is already in flight, then the while loop below should - # pull it from self.read_queue - return - - self.is_queuing_reads = True - while self.read_queue: - next_callback = self.read_queue.pop() - result = yield gen.Task(self._readFrameFromStream) - next_callback(result) - self.is_queuing_reads = False - - @gen.engine - def _readFrameFromStream(self, callback): - logging.debug('_readFrameFromStream') - frame_header = yield gen.Task(self.stream.read_bytes, 4) - frame_length, = struct.unpack('!i', frame_header) - logging.debug('received frame header, frame length = %i', frame_length) - frame = yield gen.Task(self.stream.read_bytes, frame_length) - logging.debug('received frame payload') - callback(frame) - - def write(self, buf): - self.__wbuf.write(buf) - - def flush(self, callback=None): - wout = self.__wbuf.getvalue() - wsz = len(wout) - # reset wbuf before write/flush to preserve state on underlying failure - self.__wbuf = StringIO() - # N.B.: Doing this string concatenation is WAY cheaper than making - # two separate calls to the underlying socket object. Socket writes in - # Python turn out to be REALLY expensive, but it seems to do a pretty - # good job of managing string buffer operations without excessive copies - buf = struct.pack("!i", wsz) + wout - - logging.debug('writing frame length = %i', wsz) - self.stream.write(buf, callback) - - -class TTornadoServer(netutil.TCPServer): - def __init__(self, processor, iprot_factory, oprot_factory=None, - *args, **kwargs): - super(TTornadoServer, self).__init__(*args, **kwargs) - - self._processor = processor - self._iprot_factory = iprot_factory - self._oprot_factory = (oprot_factory if oprot_factory is not None - else iprot_factory) - - def handle_stream(self, stream, address): - try: - host, port = address - trans = TTornadoStreamTransport(host=host, port=port, stream=stream) - oprot = self._oprot_factory.getProtocol(trans) - - def next_pass(): - if not trans.stream.closed(): - self._processor.process(trans, self._iprot_factory, oprot, - callback=next_pass) - - next_pass() - - except Exception: - logging.exception('thrift exception in handle_stream') - trans.close() http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/Thrift.py ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/Thrift.py b/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/Thrift.py deleted file mode 100644 index 9890af7..0000000 --- a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/Thrift.py +++ /dev/null @@ -1,170 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -import sys - - -class TType: - STOP = 0 - VOID = 1 - BOOL = 2 - BYTE = 3 - I08 = 3 - DOUBLE = 4 - I16 = 6 - I32 = 8 - I64 = 10 - STRING = 11 - UTF7 = 11 - STRUCT = 12 - MAP = 13 - SET = 14 - LIST = 15 - UTF8 = 16 - UTF16 = 17 - - _VALUES_TO_NAMES = ('STOP', - 'VOID', - 'BOOL', - 'BYTE', - 'DOUBLE', - None, - 'I16', - None, - 'I32', - None, - 'I64', - 'STRING', - 'STRUCT', - 'MAP', - 'SET', - 'LIST', - 'UTF8', - 'UTF16') - - -class TMessageType: - CALL = 1 - REPLY = 2 - EXCEPTION = 3 - ONEWAY = 4 - - -class TProcessor: - """Base class for procsessor, which works on two streams.""" - - def process(iprot, oprot): - pass - - -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): - def _get_message(self): - return self._message - - def _set_message(self, message): - self._message = message - message = property(_get_message, _set_message) - - def __init__(self, message=None): - Exception.__init__(self, message) - self.message = message - - -class TApplicationException(TException): - """Application level thrift exceptions.""" - - UNKNOWN = 0 - UNKNOWN_METHOD = 1 - INVALID_MESSAGE_TYPE = 2 - WRONG_METHOD_NAME = 3 - BAD_SEQUENCE_ID = 4 - MISSING_RESULT = 5 - INTERNAL_ERROR = 6 - PROTOCOL_ERROR = 7 - INVALID_TRANSFORM = 8 - INVALID_PROTOCOL = 9 - UNSUPPORTED_CLIENT_TYPE = 10 - - def __init__(self, type=UNKNOWN, message=None): - TException.__init__(self, message) - self.type = type - - def __str__(self): - if self.message: - return self.message - elif self.type == self.UNKNOWN_METHOD: - return 'Unknown method' - elif self.type == self.INVALID_MESSAGE_TYPE: - return 'Invalid message type' - elif self.type == self.WRONG_METHOD_NAME: - return 'Wrong method name' - elif self.type == self.BAD_SEQUENCE_ID: - return 'Bad sequence ID' - elif self.type == self.MISSING_RESULT: - return 'Missing result' - elif self.type == self.INTERNAL_ERROR: - return 'Internal error' - elif self.type == self.PROTOCOL_ERROR: - return 'Protocol error' - elif self.type == self.INVALID_TRANSFORM: - return 'Invalid transform' - elif self.type == self.INVALID_PROTOCOL: - return 'Invalid protocol' - elif self.type == self.UNSUPPORTED_CLIENT_TYPE: - return 'Unsupported client type' - else: - return 'Default (unknown) TApplicationException' - - def read(self, iprot): - iprot.readStructBegin() - while True: - (fname, ftype, fid) = iprot.readFieldBegin() - if ftype == TType.STOP: - break - if fid == 1: - if ftype == TType.STRING: - self.message = iprot.readString() - else: - iprot.skip(ftype) - elif fid == 2: - if ftype == TType.I32: - self.type = iprot.readI32() - else: - iprot.skip(ftype) - else: - iprot.skip(ftype) - iprot.readFieldEnd() - iprot.readStructEnd() - - def write(self, oprot): - oprot.writeStructBegin('TApplicationException') - if self.message is not None: - oprot.writeFieldBegin('message', TType.STRING, 1) - oprot.writeString(self.message) - oprot.writeFieldEnd() - if self.type is not None: - oprot.writeFieldBegin('type', TType.I32, 2) - oprot.writeI32(self.type) - oprot.writeFieldEnd() - oprot.writeFieldStop() - oprot.writeStructEnd() http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/__init__.py ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/__init__.py b/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/__init__.py deleted file mode 100644 index 48d659c..0000000 --- a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/__init__.py +++ /dev/null @@ -1,20 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -__all__ = ['Thrift', 'TSCons'] http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/protocol/TBase.py ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/protocol/TBase.py b/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/protocol/TBase.py deleted file mode 100644 index 6cbd5f3..0000000 --- a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/protocol/TBase.py +++ /dev/null @@ -1,81 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -from thrift.Thrift import * -from thrift.protocol import TBinaryProtocol -from thrift.transport import TTransport - -try: - from thrift.protocol import fastbinary -except: - fastbinary = None - - -class TBase(object): - __slots__ = [] - - def __repr__(self): - L = ['%s=%r' % (key, getattr(self, key)) - for key in self.__slots__] - return '%s(%s)' % (self.__class__.__name__, ', '.join(L)) - - def __eq__(self, other): - if not isinstance(other, self.__class__): - return False - for attr in self.__slots__: - my_val = getattr(self, attr) - other_val = getattr(other, attr) - 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)) - return - iprot.readStruct(self, self.thrift_spec) - - def write(self, oprot): - if (oprot.__class__ == TBinaryProtocol.TBinaryProtocolAccelerated and - self.thrift_spec is not None and - fastbinary is not None): - oprot.trans.write( - fastbinary.encode_binary(self, (self.__class__, self.thrift_spec))) - return - oprot.writeStruct(self, self.thrift_spec) - - -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 http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/protocol/TBinaryProtocol.py ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/protocol/TBinaryProtocol.py b/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/protocol/TBinaryProtocol.py deleted file mode 100644 index 35b6d05..0000000 --- a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/protocol/TBinaryProtocol.py +++ /dev/null @@ -1,261 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -from struct import pack, unpack - -from lib.thrift.protocol.TProtocol import * - - -class TBinaryProtocol(TProtocolBase): - """Binary implementation of the Thrift protocol driver.""" - - # NastyHaxx. Python 2.4+ on 32-bit machines forces hex constants to be - # positive, converting this into a long. If we hardcode the int value - # instead it'll stay in 32 bit-land. - - # VERSION_MASK = 0xffff0000 - VERSION_MASK = -65536 - - # VERSION_1 = 0x80010000 - VERSION_1 = -2147418112 - - TYPE_MASK = 0x000000ff - - def __init__(self, trans, strictRead=False, strictWrite=True): - TProtocolBase.__init__(self, trans) - self.strictRead = strictRead - self.strictWrite = strictWrite - - def writeMessageBegin(self, name, type, seqid): - if self.strictWrite: - self.writeI32(TBinaryProtocol.VERSION_1 | type) - self.writeString(name) - self.writeI32(seqid) - else: - self.writeString(name) - self.writeByte(type) - self.writeI32(seqid) - - def writeMessageEnd(self): - pass - - def writeStructBegin(self, name): - pass - - def writeStructEnd(self): - pass - - def writeFieldBegin(self, name, type, id): - self.writeByte(type) - self.writeI16(id) - - def writeFieldEnd(self): - pass - - def writeFieldStop(self): - self.writeByte(TType.STOP) - - def writeMapBegin(self, ktype, vtype, size): - self.writeByte(ktype) - self.writeByte(vtype) - self.writeI32(size) - - def writeMapEnd(self): - pass - - def writeListBegin(self, etype, size): - self.writeByte(etype) - self.writeI32(size) - - def writeListEnd(self): - pass - - def writeSetBegin(self, etype, size): - self.writeByte(etype) - self.writeI32(size) - - def writeSetEnd(self): - pass - - def writeBool(self, bool): - if bool: - self.writeByte(1) - else: - self.writeByte(0) - - def writeByte(self, byte): - buff = pack("!b", byte) - self.trans.write(buff) - - def writeI16(self, i16): - buff = pack("!h", i16) - self.trans.write(buff) - - def writeI32(self, i32): - buff = pack("!i", i32) - self.trans.write(buff) - - def writeI64(self, i64): - buff = pack("!q", i64) - self.trans.write(buff) - - def writeDouble(self, dub): - buff = pack("!d", dub) - self.trans.write(buff) - - def writeString(self, str): - self.writeI32(len(str)) - self.trans.write(str) - - def readMessageBegin(self): - sz = self.readI32() - if sz < 0: - version = sz & TBinaryProtocol.VERSION_MASK - if version != TBinaryProtocol.VERSION_1: - raise TProtocolException( - type=TProtocolException.BAD_VERSION, - message='Bad version in readMessageBegin: %d' % (sz)) - type = sz & TBinaryProtocol.TYPE_MASK - name = self.readString() - seqid = self.readI32() - else: - if self.strictRead: - raise TProtocolException(type=TProtocolException.BAD_VERSION, - message='No protocol version header') - name = self.trans.readAll(sz) - type = self.readByte() - seqid = self.readI32() - return (name, type, seqid) - - def readMessageEnd(self): - pass - - def readStructBegin(self): - pass - - def readStructEnd(self): - pass - - def readFieldBegin(self): - type = self.readByte() - if type == TType.STOP: - return (None, type, 0) - id = self.readI16() - return (None, type, id) - - def readFieldEnd(self): - pass - - def readMapBegin(self): - ktype = self.readByte() - vtype = self.readByte() - size = self.readI32() - return (ktype, vtype, size) - - def readMapEnd(self): - pass - - def readListBegin(self): - etype = self.readByte() - size = self.readI32() - return (etype, size) - - def readListEnd(self): - pass - - def readSetBegin(self): - etype = self.readByte() - size = self.readI32() - return (etype, size) - - def readSetEnd(self): - pass - - def readBool(self): - byte = self.readByte() - if byte == 0: - return False - return True - - def readByte(self): - buff = self.trans.readAll(1) - val, = unpack('!b', buff) - return val - - def readI16(self): - buff = self.trans.readAll(2) - val, = unpack('!h', buff) - return val - - def readI32(self): - buff = self.trans.readAll(4) - val, = unpack('!i', buff) - return val - - def readI64(self): - buff = self.trans.readAll(8) - val, = unpack('!q', buff) - return val - - def readDouble(self): - buff = self.trans.readAll(8) - val, = unpack('!d', buff) - return val - - def readString(self): - len = self.readI32() - str = self.trans.readAll(len) - return str - - -class TBinaryProtocolFactory: - def __init__(self, strictRead=False, strictWrite=True): - self.strictRead = strictRead - self.strictWrite = strictWrite - - def getProtocol(self, trans): - prot = TBinaryProtocol(trans, self.strictRead, self.strictWrite) - return prot - - -class TBinaryProtocolAccelerated(TBinaryProtocol): - """C-Accelerated version of TBinaryProtocol. - - This class does not override any of TBinaryProtocol's methods, - but the generated code recognizes it directly and will call into - 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.) - - In order to take advantage of the C module, just use - TBinaryProtocolAccelerated instead of TBinaryProtocol. - - NOTE: This code was contributed by an external developer. - The internal Thrift team has reviewed and tested it, - but we cannot guarantee that it is production-ready. - Please feel free to report bugs and/or success stories - to the public mailing list. - """ - pass - - -class TBinaryProtocolAcceleratedFactory: - def getProtocol(self, trans): - return TBinaryProtocolAccelerated(trans) http://git-wip-us.apache.org/repos/asf/airavata/blob/b61cfcd3/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/protocol/TCompactProtocol.py ---------------------------------------------------------------------- diff --git a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/protocol/TCompactProtocol.py b/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/protocol/TCompactProtocol.py deleted file mode 100644 index 09ca6ad..0000000 --- a/airavata-api/airavata-client-sdks/airavata-python-sdk/src/main/resources/lib/thrift/protocol/TCompactProtocol.py +++ /dev/null @@ -1,405 +0,0 @@ -# -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# - -from struct import pack, unpack - -from lib.thrift.protocol.TProtocol import * - - -__all__ = ['TCompactProtocol', 'TCompactProtocolFactory'] - -CLEAR = 0 -FIELD_WRITE = 1 -VALUE_WRITE = 2 -CONTAINER_WRITE = 3 -BOOL_WRITE = 4 -FIELD_READ = 5 -CONTAINER_READ = 6 -VALUE_READ = 7 -BOOL_READ = 8 - - -def make_helper(v_from, container): - def helper(func): - def nested(self, *args, **kwargs): - assert self.state in (v_from, container), (self.state, v_from, container) - return func(self, *args, **kwargs) - return nested - return helper -writer = make_helper(VALUE_WRITE, CONTAINER_WRITE) -reader = make_helper(VALUE_READ, CONTAINER_READ) - - -def makeZigZag(n, bits): - return (n << 1) ^ (n >> (bits - 1)) - - -def fromZigZag(n): - return (n >> 1) ^ -(n & 1) - - -def writeVarint(trans, n): - out = [] - while True: - if n & ~0x7f == 0: - out.append(n) - break - else: - out.append((n & 0xff) | 0x80) - n = n >> 7 - trans.write(''.join(map(chr, out))) - - -def readVarint(trans): - result = 0 - shift = 0 - while True: - x = trans.readAll(1) - byte = ord(x) - result |= (byte & 0x7f) << shift - if byte >> 7 == 0: - return result - shift += 7 - - -class CompactType: - STOP = 0x00 - TRUE = 0x01 - FALSE = 0x02 - BYTE = 0x03 - I16 = 0x04 - I32 = 0x05 - I64 = 0x06 - DOUBLE = 0x07 - BINARY = 0x08 - LIST = 0x09 - SET = 0x0A - MAP = 0x0B - STRUCT = 0x0C - -CTYPES = {TType.STOP: CompactType.STOP, - TType.BOOL: CompactType.TRUE, # used for collection - TType.BYTE: CompactType.BYTE, - TType.I16: CompactType.I16, - TType.I32: CompactType.I32, - TType.I64: CompactType.I64, - TType.DOUBLE: CompactType.DOUBLE, - TType.STRING: CompactType.BINARY, - TType.STRUCT: CompactType.STRUCT, - TType.LIST: CompactType.LIST, - TType.SET: CompactType.SET, - TType.MAP: CompactType.MAP - } - -TTYPES = {} -for k, v in CTYPES.items(): - TTYPES[v] = k -TTYPES[CompactType.FALSE] = TType.BOOL -del k -del v - - -class TCompactProtocol(TProtocolBase): - """Compact implementation of the Thrift protocol driver.""" - - PROTOCOL_ID = 0x82 - VERSION = 1 - VERSION_MASK = 0x1f - TYPE_MASK = 0xe0 - TYPE_SHIFT_AMOUNT = 5 - - def __init__(self, trans): - TProtocolBase.__init__(self, trans) - self.state = CLEAR - self.__last_fid = 0 - self.__bool_fid = None - self.__bool_value = None - self.__structs = [] - self.__containers = [] - - def __writeVarint(self, n): - writeVarint(self.trans, n) - - def writeMessageBegin(self, name, type, seqid): - assert self.state == CLEAR - self.__writeUByte(self.PROTOCOL_ID) - self.__writeUByte(self.VERSION | (type << self.TYPE_SHIFT_AMOUNT)) - self.__writeVarint(seqid) - self.__writeString(name) - self.state = VALUE_WRITE - - def writeMessageEnd(self): - assert self.state == VALUE_WRITE - self.state = CLEAR - - def writeStructBegin(self, name): - assert self.state in (CLEAR, CONTAINER_WRITE, VALUE_WRITE), self.state - self.__structs.append((self.state, self.__last_fid)) - self.state = FIELD_WRITE - self.__last_fid = 0 - - def writeStructEnd(self): - assert self.state == FIELD_WRITE - self.state, self.__last_fid = self.__structs.pop() - - def writeFieldStop(self): - self.__writeByte(0) - - def __writeFieldHeader(self, type, fid): - delta = fid - self.__last_fid - if 0 < delta <= 15: - self.__writeUByte(delta << 4 | type) - else: - self.__writeByte(type) - self.__writeI16(fid) - self.__last_fid = fid - - def writeFieldBegin(self, name, type, fid): - assert self.state == FIELD_WRITE, self.state - if type == TType.BOOL: - self.state = BOOL_WRITE - self.__bool_fid = fid - else: - self.state = VALUE_WRITE - self.__writeFieldHeader(CTYPES[type], fid) - - def writeFieldEnd(self): - assert self.state in (VALUE_WRITE, BOOL_WRITE), self.state - self.state = FIELD_WRITE - - def __writeUByte(self, byte): - self.trans.write(pack('!B', byte)) - - def __writeByte(self, byte): - self.trans.write(pack('!b', byte)) - - def __writeI16(self, i16): - self.__writeVarint(makeZigZag(i16, 16)) - - def __writeSize(self, i32): - self.__writeVarint(i32) - - def writeCollectionBegin(self, etype, size): - assert self.state in (VALUE_WRITE, CONTAINER_WRITE), self.state - if size <= 14: - self.__writeUByte(size << 4 | CTYPES[etype]) - else: - self.__writeUByte(0xf0 | CTYPES[etype]) - self.__writeSize(size) - self.__containers.append(self.state) - self.state = CONTAINER_WRITE - writeSetBegin = writeCollectionBegin - writeListBegin = writeCollectionBegin - - def writeMapBegin(self, ktype, vtype, size): - assert self.state in (VALUE_WRITE, CONTAINER_WRITE), self.state - if size == 0: - self.__writeByte(0) - else: - self.__writeSize(size) - self.__writeUByte(CTYPES[ktype] << 4 | CTYPES[vtype]) - self.__containers.append(self.state) - self.state = CONTAINER_WRITE - - def writeCollectionEnd(self): - assert self.state == CONTAINER_WRITE, self.state - self.state = self.__containers.pop() - writeMapEnd = writeCollectionEnd - writeSetEnd = writeCollectionEnd - writeListEnd = writeCollectionEnd - - def writeBool(self, bool): - if self.state == BOOL_WRITE: - if bool: - ctype = CompactType.TRUE - else: - ctype = CompactType.FALSE - self.__writeFieldHeader(ctype, self.__bool_fid) - elif self.state == CONTAINER_WRITE: - if bool: - self.__writeByte(CompactType.TRUE) - else: - self.__writeByte(CompactType.FALSE) - else: - raise AssertionError("Invalid state in compact protocol") - - writeByte = writer(__writeByte) - writeI16 = writer(__writeI16) - - @writer - def writeI32(self, i32): - self.__writeVarint(makeZigZag(i32, 32)) - - @writer - def writeI64(self, i64): - self.__writeVarint(makeZigZag(i64, 64)) - - @writer - def writeDouble(self, dub): - self.trans.write(pack('!d', dub)) - - def __writeString(self, s): - self.__writeSize(len(s)) - self.trans.write(s) - writeString = writer(__writeString) - - def readFieldBegin(self): - assert self.state == FIELD_READ, self.state - type = self.__readUByte() - if type & 0x0f == TType.STOP: - return (None, 0, 0) - delta = type >> 4 - if delta == 0: - fid = self.__readI16() - else: - fid = self.__last_fid + delta - self.__last_fid = fid - type = type & 0x0f - if type == CompactType.TRUE: - self.state = BOOL_READ - self.__bool_value = True - elif type == CompactType.FALSE: - self.state = BOOL_READ - self.__bool_value = False - else: - self.state = VALUE_READ - return (None, self.__getTType(type), fid) - - def readFieldEnd(self): - assert self.state in (VALUE_READ, BOOL_READ), self.state - self.state = FIELD_READ - - def __readUByte(self): - result, = unpack('!B', self.trans.readAll(1)) - return result - - def __readByte(self): - result, = unpack('!b', self.trans.readAll(1)) - return result - - def __readVarint(self): - return readVarint(self.trans) - - def __readZigZag(self): - return fromZigZag(self.__readVarint()) - - def __readSize(self): - result = self.__readVarint() - if result < 0: - raise TException("Length < 0") - return result - - def readMessageBegin(self): - assert self.state == CLEAR - proto_id = self.__readUByte() - if proto_id != self.PROTOCOL_ID: - raise TProtocolException(TProtocolException.BAD_VERSION, - 'Bad protocol id in the message: %d' % proto_id) - ver_type = self.__readUByte() - type = (ver_type & self.TYPE_MASK) >> self.TYPE_SHIFT_AMOUNT - version = ver_type & self.VERSION_MASK - if version != self.VERSION: - raise TProtocolException(TProtocolException.BAD_VERSION, - 'Bad version: %d (expect %d)' % (version, self.VERSION)) - seqid = self.__readVarint() - name = self.__readString() - return (name, type, seqid) - - def readMessageEnd(self): - assert self.state == CLEAR - assert len(self.__structs) == 0 - - def readStructBegin(self): - assert self.state in (CLEAR, CONTAINER_READ, VALUE_READ), self.state - self.__structs.append((self.state, self.__last_fid)) - self.state = FIELD_READ - self.__last_fid = 0 - - def readStructEnd(self): - assert self.state == FIELD_READ - self.state, self.__last_fid = self.__structs.pop() - - def readCollectionBegin(self): - assert self.state in (VALUE_READ, CONTAINER_READ), self.state - size_type = self.__readUByte() - size = size_type >> 4 - type = self.__getTType(size_type) - if size == 15: - size = self.__readSize() - self.__containers.append(self.state) - self.state = CONTAINER_READ - return type, size - readSetBegin = readCollectionBegin - readListBegin = readCollectionBegin - - def readMapBegin(self): - assert self.state in (VALUE_READ, CONTAINER_READ), self.state - size = self.__readSize() - types = 0 - if size > 0: - types = self.__readUByte() - vtype = self.__getTType(types) - ktype = self.__getTType(types >> 4) - self.__containers.append(self.state) - self.state = CONTAINER_READ - return (ktype, vtype, size) - - def readCollectionEnd(self): - assert self.state == CONTAINER_READ, self.state - self.state = self.__containers.pop() - readSetEnd = readCollectionEnd - readListEnd = readCollectionEnd - readMapEnd = readCollectionEnd - - def readBool(self): - if self.state == BOOL_READ: - return self.__bool_value == CompactType.TRUE - elif self.state == CONTAINER_READ: - return self.__readByte() == CompactType.TRUE - else: - raise AssertionError("Invalid state in compact protocol: %d" % - self.state) - - readByte = reader(__readByte) - __readI16 = __readZigZag - readI16 = reader(__readZigZag) - readI32 = reader(__readZigZag) - readI64 = reader(__readZigZag) - - @reader - def readDouble(self): - buff = self.trans.readAll(8) - val, = unpack('!d', buff) - return val - - def __readString(self): - len = self.__readSize() - return self.trans.readAll(len) - readString = reader(__readString) - - def __getTType(self, byte): - return TTYPES[byte & 0x0f] - - -class TCompactProtocolFactory: - def __init__(self): - pass - - def getProtocol(self, trans): - return TCompactProtocol(trans)
