##// END OF EJS Templates
Rewrite controller, remove MPDecorator to units (keep for plots an writers) use of queues for interproc comm instead of zmq, self operations are no longer supported
Rewrite controller, remove MPDecorator to units (keep for plots an writers) use of queues for interproc comm instead of zmq, self operations are no longer supported

File last commit:

r1167:1f521b07c958
r1287:af11e4aac00c
Show More
testServer.py
176 lines | 3.4 KiB | text/x-python | PythonLexer
Miguel Valdez
Merge with branch schain_julia_drifts from rev. 803 to 995....
r568 '''
Created on Jul 15, 2014
@author: roj-idl71
'''
import sys
import yaml
import numpy
import jsonpickle
# import schainpy.serializer.DynamicSerializer as DynamicSerializer
def isNotClassVar(myObj):
return not hasattr(myObj,'__dict__')
def isDictFormat(thisValue):
if type(thisValue) != type({}):
return False
George Yong
Python 2to3, Spectra (all operations) working
r1167 if '__name__' not in list(thisValue.keys()):
Miguel Valdez
Merge with branch schain_julia_drifts from rev. 803 to 995....
r568 return False
return True
def obj2Dict(myObj):
myDict = {}
myDict['__name__'] = myObj.__class__.__name__
George Yong
Python 2to3, Spectra (all operations) working
r1167 for thisKey, thisValue in list(myObj.__dict__.items()):
Miguel Valdez
Merge with branch schain_julia_drifts from rev. 803 to 995....
r568
if isNotClassVar(thisValue):
myDict[thisKey] = thisValue
continue
## If this value is another class instance
myNewDict = obj2Dict(thisValue)
myDict[thisKey] = myNewDict
return myDict
def dict2Obj(myDict):
'''
'''
George Yong
Python 2to3, Spectra (all operations) working
r1167 if '__name__' not in list(myDict.keys()):
Miguel Valdez
Merge with branch schain_julia_drifts from rev. 803 to 995....
r568 return None
className = eval(myDict['__name__'])
myObj = className()
George Yong
Python 2to3, Spectra (all operations) working
r1167 for thisKey, thisValue in list(myDict.items()):
Miguel Valdez
Merge with branch schain_julia_drifts from rev. 803 to 995....
r568
if thisKey == '__name__':
continue
if not isDictFormat(thisValue):
setattr(myObj, thisKey, thisValue)
continue
myNewObj = dict2Obj(thisValue)
setattr(myObj, thisKey, myNewObj)
return myObj
class myTestClass3(object):
def __init__(self):
'''
'''
self.y1 = 'y1'
self.y2 = 'y2'
class myTestClass2(object):
def __init__(self):
'''
'''
self.x1 = 'x1'
self.x2 = 'x2'
self.otherObj = myTestClass3()
class myTestClass(object):
flagNoData = True
value1 = 1
value2 = 2
myObj = None
def __init__(self):
'''
'''
self.flagNoData = True
self.value1 = 1
self.value2 = 2
self.myObj = myTestClass2()
def get_dtype(self):
'''
'''
return self.value1
def set_dtype(self, value):
'''
'''
self.value1 = value
dtype = property(get_dtype, set_dtype)
def myMsgPackTest():
import msgpack
import msgpack_numpy as m
import numpy as np
x = np.random.rand(5)
x_enc = m.encode(x)
x_rec = m.decode(x_enc)
George Yong
Python 2to3, Spectra (all operations) working
r1167 print(x_rec)
Miguel Valdez
Merge with branch schain_julia_drifts from rev. 803 to 995....
r568 #
# x_enc = msgpack.packb(x, default=m.encoder)
# x_rec = msgpack.unpackb(x_enc, object_hook=m.decoder)
if __name__ == '__main__':
myMsgPackTest()
sys.exit()
serializerObj = DynamicSerializer.DynamicSerializer('json')
serializerObj = jsonpickle
myTestObj = myTestClass()
myTestObj.flagNoData = False
myTestObj.value1 = [1+3.4j,4,'5',]
myTestObj.value2 = {'x2': numpy.complex(1,2),'x1': 'x1'}
# myTestObj.myObj.x2 = numpy.arange(15, dtype=numpy.complex)
myDict = obj2Dict(myTestObj)
myNewObj = dict2Obj(myDict)
# print myDict
# print myTestObj.__dict__
# print myNewObj.__dict__
# sys.exit()
George Yong
Python 2to3, Spectra (all operations) working
r1167 print(myDict)
Miguel Valdez
Merge with branch schain_julia_drifts from rev. 803 to 995....
r568
newSerial = serializerObj.encode(myDict)
# print newSerial
newDict = serializerObj.decode(newSerial)
George Yong
Python 2to3, Spectra (all operations) working
r1167 print(newDict)
Miguel Valdez
Merge with branch schain_julia_drifts from rev. 803 to 995....
r568
myNewObj = dict2Obj(newDict)
George Yong
Python 2to3, Spectra (all operations) working
r1167 print()
print()
print(50*'###')
print(myTestObj.__dict__)
print(myNewObj.__dict__)
Miguel Valdez
Merge with branch schain_julia_drifts from rev. 803 to 995....
r568