Skip to content

Commit d686660

Browse files
committed
Fixed a potential bug in _get_server_information() regarding buffering. Fixed a bug having to do with old versions of Python and the set module. Basic Jython 2.2 compatibility now exists.
1 parent 952168b commit d686660

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

README

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Changes
2929
pymysql.version_info attribute.
3030
-Now runs with no warnings with the -3 command-line switch
3131
-Added test cases for all outstanding tickets and closed most of them.
32+
-Basic Jython support added
3233

3334
0.2 -Changed connection parameter name 'password' to 'passwd'
3435
to make it more plugin replaceable for the other mysql clients.

pymysql/__init__.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
frozenset
1515
except NameError:
1616
from sets import ImmutableSet as frozenset
17-
from sets import BaseSet as set
17+
try:
18+
from sets import BaseSet as set
19+
except ImportError:
20+
from sets import Set as set
1821

1922
threadsafety = 1
2023
apilevel = "2.0"

pymysql/connections.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# Python implementation of the MySQL client-server protocol
22
# http://forge.mysql.com/wiki/MySQL_Internals_ClientServer_Protocol
33

4-
# TODO: use streams instead of send() and recv()
5-
64
import re
75

86
try:
@@ -127,7 +125,7 @@ def _hash_password_323(password):
127125
add = 7L
128126
nr2 = 0x12345671L
129127

130-
for c in (ord(x) for x in password if x not in (' ', '\t')):
128+
for c in [ord(x) for x in password if x not in (' ', '\t')]:
131129
nr^= (((nr & 63)+add)*c)+ (nr << 8) & 0xFFFFFFFF
132130
nr2= (nr2 + ((nr2 << 8) ^ nr)) & 0xFFFFFFFF
133131
add= (add + c) & 0xFFFFFFFF
@@ -211,6 +209,8 @@ def __recv_packet(self, socket):
211209

212210
def packet_number(self): return self.__packet_number
213211

212+
def get_all_data(self): return self.__data
213+
214214
def read(self, size):
215215
"""Read the first 'size' bytes in packet and advance cursor past them."""
216216
result = self.peek(size)
@@ -618,7 +618,7 @@ def _send_authentication(self):
618618
data = (struct.pack('i', self.client_flag)) + "\0\0\0\x01" + \
619619
'\x08' + '\0'*23 + \
620620
self.user+"\0" + _scramble(self.password, self.salt)
621-
621+
622622
if self.db:
623623
data += self.db + "\0"
624624

@@ -635,7 +635,7 @@ def _send_authentication(self):
635635
# if old_passwords is enabled the packet will be 1 byte long and
636636
# have the octet 254
637637

638-
if auth_packet.get_bytes(0,2) == chr(254):
638+
if auth_packet.is_eof_packet():
639639
# send legacy handshake
640640
raise NotImplementedError, "old_passwords are not supported. Check to see if mysqld was started with --old-passwords, if old-passwords=1 in a my.cnf file, or if there are some short hashes in your mysql.user table."
641641
#data = _scramble_323(self.password, self.salt) + "\0"
@@ -663,11 +663,12 @@ def get_proto_info(self):
663663
def _get_server_information(self):
664664
sock = self.socket
665665
i = 0
666-
# TODO: likely bug here because recv() might return less bytes than we need
667-
data = sock.recv(BUFFER_SIZE)
666+
packet = MysqlPacket(sock)
667+
data = packet.get_all_data()
668+
668669
if DEBUG: dump_packet(data)
669-
packet_len = ord(data[i:i+1])
670-
i += 4
670+
#packet_len = ord(data[i:i+1])
671+
#i += 4
671672
self.protocol_version = ord(data[i:i+1])
672673

673674
i += 1

pymysql/converters.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
from pymysql.times import Date, Time, TimeDelta, Timestamp
88
from pymysql.constants import FIELD_TYPE
99

10+
try:
11+
set
12+
except NameError:
13+
try:
14+
from sets import BaseSet as set
15+
except ImportError:
16+
from sets import Set as set
17+
1018
ESCAPE_REGEX = re.compile(r"[\0\n\r\032\'\"\\]")
1119
ESCAPE_MAP = {'\0': '\\0', '\n': '\\n', '\r': '\\r', '\032': '\\Z',
1220
'\'': '\\\'', '"': '\\"', '\\': '\\\\'}
@@ -125,7 +133,7 @@ def convert_timedelta(obj):
125133
"""
126134
from math import modf
127135
try:
128-
hours, minutes, seconds = tuple(int(x) for x in obj.split(':'))
136+
hours, minutes, seconds = tuple([int(x) for x in obj.split(':')])
129137
tdelta = datetime.timedelta(
130138
hours = int(hours),
131139
minutes = int(minutes),

0 commit comments

Comments
 (0)