|
|
|
"""
|
|
|
|
Data Transport - 1.0
|
|
|
|
Steve L. Nyemba, The Phi Technology LLC
|
|
|
|
|
|
|
|
This module is designed to serve as a wrapper to a set of supported data stores :
|
|
|
|
- couchdb
|
|
|
|
- mongodb
|
|
|
|
- Files (character delimited)
|
|
|
|
for xchar in delim:
|
|
|
|
|
|
|
|
def split (self,row):
|
|
|
|
"""
|
|
|
|
This function performs a split of a record and tries to attempt to preserve the integrity of the data within i.e accounting for the double quotes.
|
|
|
|
@pre : self.xchar is not None
|
|
|
|
"""
|
|
|
|
|
|
|
|
pattern = "".join(["(?:^|",self.xchar,")(\"(?:[^\"]+|\"\")*\"|[^",self.xchar,"]*)"])
|
|
|
|
return re.findall(pattern,row.replace('\n',''))
|
|
|
|
|
|
|
|
|
|
|
|
class Writer:
|
|
|
|
|
|
|
|
def format(self,row,xchar):
|
|
|
|
if xchar is not None and isinstance(row,list):
|
|
|
|
return xchar.join(row)+'\n'
|
|
|
|
elif xchar is None and isinstance(row,dict):
|
|
|
|
row = json.dumps(row)
|
|
|
|
return row
|
|
|
|
"""
|
|
|
|
It is important to be able to archive data so as to insure that growth is controlled
|
|
|
|
Nothing in nature grows indefinitely neither should data being handled.
|
|
|
|
"""
|
|
|
|
def archive(self):
|
|
|
|
pass
|
|
|
|
def flush(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
# class factory :
|
|
|
|
# @staticmethod
|
|
|
|
# def instance(**args):
|
|
|
|
# """
|
|
|
|
# This class will create an instance of a transport when providing
|
|
|
|
# :type name of the type we are trying to create
|
|
|
|
# :args The arguments needed to create the instance
|
|
|
|
# """
|
|
|
|
# source = args['type']
|
|
|
|
# params = args['args']
|
|
|
|
# anObject = None
|
|
|
|
|
|
|
|
# if source in ['HttpRequestReader','HttpSessionWriter']:
|
|
|
|
# #
|
|
|
|
# # @TODO: Make sure objects are serializable, be smart about them !!
|
|
|
|
# #
|
|
|
|
# aClassName = ''.join([source,'(**params)'])
|
|
|
|
|
|
|
|
|
|
|
|
# else:
|
|
|
|
|
|
|
|
# stream = json.dumps(params)
|
|
|
|
# aClassName = ''.join([source,'(**',stream,')'])
|
|
|
|
# try:
|
|
|
|
# anObject = eval( aClassName)
|
|
|
|
# #setattr(anObject,'name',source)
|
|
|
|
# except Exception,e:
|
|
|
|
# print ['Error ',e]
|
|
|
|
# return anObject
|