import MySQLdb as mdb
import uuid as myUuid
-import utils as af
+from . import utils as af
import json
#import yaml
import time
It enters recursively in the dict var finding this kind of variables
'''
if type(var) is dict:
- for k,v in var.items():
+ for k,v in list(var.items()):
if type(v) is datetime.datetime:
var[k]= v.strftime('%Y-%m-%dT%H:%M:%S')
elif type(v) is dict or type(v) is list or type(v) is tuple:
None
'''
if type(data) is dict:
- for k in data.keys():
+ for k in list(data.keys()):
if type(data[k]) is dict or type(data[k]) is tuple or type(data[k]) is list:
_convert_bandwidth(data[k], reverse, logger)
if "bandwidth" in data:
None
'''
if type(data) is dict:
- for k in data.keys():
+ for k in list(data.keys()):
if type(data[k]) is dict or type(data[k]) is tuple or type(data[k]) is list:
_convert_str2boolean(data[k], items)
if k in items:
def __remove_quotes(self, data):
'''remove single quotes ' of any string content of data dictionary'''
- for k,v in data.items():
+ for k,v in list(data.items()):
if type(v) == str:
if "'" in v:
data[k] = data[k].replace("'","_")
Return: the number of updated rows, exception if error
'''
#gettting uuid
- values = ",".join(map(self.__tuple2db_format_set, UPDATE.iteritems() ))
+ values = ",".join(map(self.__tuple2db_format_set, iter(UPDATE.items()) ))
if modified_time:
values += ",modified_at={:f}".format(modified_time)
cmd= "UPDATE " + table +" SET " + values +\
- " WHERE " + " and ".join(map(self.__tuple2db_format_where, WHERE.iteritems() ))
+ " WHERE " + " and ".join(map(self.__tuple2db_format_where, iter(WHERE.items()) ))
self.logger.debug(cmd)
self.cur.execute(cmd)
return self.cur.rowcount
self.cur.execute(cmd)
#insertion
cmd= "INSERT INTO " + table +" SET " + \
- ",".join(map(self.__tuple2db_format_set, INSERT.iteritems() ))
+ ",".join(map(self.__tuple2db_format_set, iter(INSERT.items()) ))
if created_time:
cmd += ",created_at=%f" % created_time
if confidential_data:
#print 'from_', from_
if 'WHERE' in sql_dict and len(sql_dict['WHERE']) > 0:
w=sql_dict['WHERE']
- where_ = "WHERE " + " AND ".join(map(self.__tuple2db_format_where, w.iteritems()))
+ where_ = "WHERE " + " AND ".join(map(self.__tuple2db_format_where, iter(w.items())))
else: where_ = ""
if 'WHERE_NOT' in sql_dict and len(sql_dict['WHERE_NOT']) > 0:
w=sql_dict['WHERE_NOT']
- where_2 = " AND ".join(map(self.__tuple2db_format_where_not, w.iteritems()))
+ where_2 = " AND ".join(map(self.__tuple2db_format_where_not, iter(w.items())))
if len(where_)==0: where_ = "WHERE " + where_2
else: where_ = where_ + " AND " + where_2
#print 'where_', where_
where_or = ""
w=sql_dict.get('WHERE')
if w:
- where_and = " AND ".join(map(self.__tuple2db_format_where, w.iteritems() ))
+ where_and = " AND ".join(map(self.__tuple2db_format_where, iter(w.items()) ))
w=sql_dict.get('WHERE_NOT')
if w:
if where_and: where_and += " AND "
- where_and += " AND ".join(map(self.__tuple2db_format_where_not, w.iteritems() ) )
+ where_and += " AND ".join(map(self.__tuple2db_format_where_not, iter(w.items()) ) )
w=sql_dict.get('WHERE_OR')
if w:
- where_or = " OR ".join(map(self.__tuple2db_format_where, w.iteritems() ))
+ where_or = " OR ".join(map(self.__tuple2db_format_where, iter(w.items()) ))
if where_and and where_or:
if sql_dict.get("WHERE_AND_OR") == "AND":
where_ = "WHERE " + where_and + " AND (" + where_or + ")"
what = 'uuid' if af.check_valid_uuid(uuid_name) else 'name'
cmd = " SELECT * FROM {} WHERE {}='{}'".format(table, what, uuid_name)
if WHERE_OR:
- where_or = " OR ".join(map(self.__tuple2db_format_where, WHERE_OR.iteritems() ))
+ where_or = " OR ".join(map(self.__tuple2db_format_where, iter(WHERE_OR.items()) ))
if WHERE_AND_OR == "AND":
cmd += " AND (" + where_or + ")"
else:
rows = self.cur.fetchall()
return self.cur.rowcount, rows
except (mdb.Error, AttributeError) as e:
- print "nfvo_db.get_uuid DB Exception %d: %s" % (e.args[0], e.args[1])
+ print("nfvo_db.get_uuid DB Exception %d: %s" % (e.args[0], e.args[1]))
r,c = self._format_error(e)
if r!=-HTTP_Request_Timeout or retry_==1: return r,c