From 26b64c6af0d686ba0c295ead2db1de7418e6e1f3 Mon Sep 17 00:00:00 2001 From: adustman Date: Sun, 23 Jan 2005 05:47:40 +0000 Subject: [PATCH] Bug #770825 --- MySQLdb/MySQLdb/connections.py | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/MySQLdb/MySQLdb/connections.py b/MySQLdb/MySQLdb/connections.py index 55556ab..869f49a 100644 --- a/MySQLdb/MySQLdb/connections.py +++ b/MySQLdb/MySQLdb/connections.py @@ -116,6 +116,7 @@ class Connection(_mysql.connection): from constants import CLIENT, FIELD_TYPE from converters import conversions import types + from weakref import proxy kwargs2 = kwargs.copy() if kwargs.has_key('conv'): kwargs2['conv'] = conv = kwargs['conv'] @@ -135,12 +136,20 @@ class Connection(_mysql.connection): self.charset = self.character_set_name().split('_')[0] if use_unicode: - conv[FIELD_TYPE.STRING] = unicode - conv[FIELD_TYPE.VAR_STRING] = unicode - conv[FIELD_TYPE.BLOB].insert(-1, (None, unicode)) - - self.converter[types.StringType] = self.string_literal - self.converter[types.UnicodeType] = self.unicode_literal + def u(s, self=proxy(self)): + return s.decode(self.charset) + conv[FIELD_TYPE.STRING] = u + conv[FIELD_TYPE.VAR_STRING] = u + conv[FIELD_TYPE.BLOB].insert(-1, (None, u)) + + def string_literal(obj, dummy=None, self=proxy(self)): + return self.string_literal(obj) + + def unicode_literal(u, dummy=None, self=proxy(self)): + return self.literal(u.encode(self.charset)) + + self.converter[types.StringType] = string_literal + self.converter[types.UnicodeType] = unicode_literal self._transactional = self.server_capabilities & CLIENT.TRANSACTIONS if self._transactional: # PEP-249 requires autocommit to be initially off @@ -171,19 +180,6 @@ class Connection(_mysql.connection): """ return self.escape(o, self.converter) - def unicode_literal(self, u, dummy=None): - """ - - Convert a unicode object u to a string using the current - character set as the encoding. If that's not available, - latin1 is used. - - Non-standard. For internal use; do not use this in your - applications. - - """ - return self.literal(u.encode(self.charset)) - if not hasattr(_mysql.connection, 'warning_count'): def warning_count(self):