From 4dd0dd99d907ddb3547c2155e05a4747db9c00a2 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 26 Jun 2010 16:51:29 -0400 Subject: [PATCH] Use dict_ in export_mysql to avoid clobbering builtin dict --- sitecore/prof/export_mysql.py | 44 ++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/sitecore/prof/export_mysql.py b/sitecore/prof/export_mysql.py index 5b873d6..70bd392 100644 --- a/sitecore/prof/export_mysql.py +++ b/sitecore/prof/export_mysql.py @@ -65,51 +65,53 @@ class SimpleDB (object): def set_default_table(self, table): self.table = table - def add_entry(self, dict, table=None): + def add_entry(self, dict_, table=None): if table == None: table = self.table - dict = self._clean_dict(dict) - keys = dict.keys() - values = ["'%s'" % dict[key] for key in keys] + dict_ = self._clean_dict(dict_) + keys = dict_.keys() + values = ["'%s'" % dict_[key] for key in keys] self.execute("INSERT INTO %s (%s) VALUES (%s)" % (table, ', '.join(keys), ', '.join(values))) # error checking - def list_entries(self, dict=None, table=None): + def list_entries(self, dict_=None, table=None): if table == None: table = self.table - where = self._where_string(dict) + where = self._where_string(dict_) self.execute('SELECT * FROM %s%s' % (table, where)) numrows = int(self.cursor.rowcount) - print '\t'.join([dtuple[0] for dtuple in self.cursor.description]) + fields = [dtuple[0] for dtuple in self.cursor.description] + ret = [] for x in range(0,numrows): row = self.cursor.fetchone() - print '\t'.join(['%s' % x for x in row]) + ret.append(dict(zip(fields, row))) + return ret - def delete_entries(self, dict, table=None): + def delete_entries(self, dict_, table=None): if table == None: table = self.table - where = self._where_string(dict) + where = self._where_string(dict_) self.execute('DELETE FROM %s%s' % (table, where)) - def _clean_dict(self, dict=None): - if dict == None: + def _clean_dict(self, dict_=None): + if dict_ == None: return None - for key in dict.keys(): - value = dict.pop(key) + for key in dict_.keys(): + value = dict_.pop(key) value = MySQLdb.escape_string(value) key = MySQLdb.escape_string(key) - assert key not in dict, '%s in %s!' % (key, dict) - dict[key] = value - return dict + assert key not in dict_, '%s in %s!' % (key, dict_) + dict_[key] = value + return dict_ - def _where_string(self, dict=None): - dict = self._clean_dict(dict) - if dict == None or len(dict) == 0: + def _where_string(self, dict_=None): + dict_ = self._clean_dict(dict_) + if dict_ == None or len(dict_) == 0: where = '' else: where_args = [] - for key,value in dict.items(): + for key,value in dict_.items(): where_args.append("%s='%s'" % (key,value)) where = ' where %s' % ' and '.join(where_args) return where -- 2.26.2