Fix several bugs caused or exposed by running in Python 3.
This commit is contained in:
1 parent
471350cea8
commit
c8b3e7a809
6 files changed
+15
-23
No files matched your search
@@ -13,6 +13,8 @@ import sys
|
||||
import json
|
||||
import re
|
||||
|
||||
from future.utils import raise_
|
||||
|
||||
from ..compat import unicode
|
||||
from .types import VarInt
|
||||
from . import packets
|
||||
@@ -259,7 +261,7 @@ class NetworkingThread(threading.Thread):
|
||||
self.connection.file_object)
|
||||
|
||||
if exc_info is not None:
|
||||
raise exc_info[0], exc_info[1], exc_info[2]
|
||||
raise_(*exc_info)
|
||||
|
||||
time.sleep(0.05)
|
||||
|
||||
@@ -290,11 +292,10 @@ class PacketReactor(object):
|
||||
for packet in self.__class__.get_clientbound_packets(context)}
|
||||
|
||||
def read_packet(self, stream):
|
||||
ready_to_read = select.select([self.connection.socket], [], [],
|
||||
self.TIME_OUT)[0]
|
||||
ready_to_read = select.select([stream], [], [], self.TIME_OUT)[0]
|
||||
|
||||
if self.connection.socket in ready_to_read:
|
||||
length = VarInt.read_socket(self.connection.socket)
|
||||
if stream in ready_to_read:
|
||||
length = VarInt.read(stream)
|
||||
|
||||
packet_data = packets.PacketBuffer()
|
||||
packet_data.send(stream.read(length))
|
||||
|
||||
@@ -70,6 +70,8 @@ class EncryptedFileObjectWrapper(object):
|
||||
def read(self, length):
|
||||
return self.decryptor.update(self.actual_file_object.read(length))
|
||||
|
||||
def fileno(self):
|
||||
return self.actual_file_object.fileno()
|
||||
|
||||
class EncryptedSocketWrapper(object):
|
||||
def __init__(self, socket, encryptor, decryptor):
|
||||
|
||||
@@ -381,7 +381,7 @@ class PlayerListItemPacket(Packet):
|
||||
__slots__ = (
|
||||
'uuid', 'name', 'properties', 'gamemode', 'ping', 'display_name')
|
||||
def __init__(self, **kwds):
|
||||
for key, val in kwds.iteritems():
|
||||
for key, val in kwds.items():
|
||||
setattr(self, key, val)
|
||||
|
||||
class PlayerProperty(object):
|
||||
@@ -501,10 +501,10 @@ class MapPacket(Packet):
|
||||
|
||||
class MapIcon(object):
|
||||
__slots__ = 'type', 'direction', 'location'
|
||||
def __init__(self, type, direction, (x, z)):
|
||||
def __init__(self, type, direction, location):
|
||||
self.type = type
|
||||
self.direction = direction
|
||||
self.location = (x, z)
|
||||
self.location = location
|
||||
def __repr__(self):
|
||||
return ('MapIcon(type=%s, direction=%s, location=%s)'
|
||||
% (self.type, self.direction, self.location))
|
||||
@@ -533,7 +533,7 @@ class MapPacket(Packet):
|
||||
def __init__(self):
|
||||
self.maps_by_id = dict()
|
||||
def __repr__(self):
|
||||
return 'MapSet(%s)' % ', '.join(self.maps_by_id.itervalues())
|
||||
return 'MapSet(%s)' % ', '.join(self.maps_by_id.values())
|
||||
def __str__(self):
|
||||
return self.__repr__()
|
||||
|
||||
@@ -590,7 +590,7 @@ class MapPacket(Packet):
|
||||
def __repr__(self):
|
||||
return 'MapPacket(%s)' % ', '.join(
|
||||
'%s=%r' % (k, v)
|
||||
for (k,v) in self.__dict__.iteritems()
|
||||
for (k,v) in self.__dict__.items()
|
||||
if k != 'pixels')
|
||||
def __str__(self):
|
||||
return self.__repr__()
|
||||
|
||||
@@ -80,19 +80,6 @@ class Integer(Type):
|
||||
|
||||
|
||||
class VarInt(Type):
|
||||
@staticmethod
|
||||
def read_socket(socket):
|
||||
number = 0
|
||||
for i in range(5):
|
||||
byte = socket.recv(1)
|
||||
if byte == "" or len(byte) == 0:
|
||||
raise RuntimeError("Socket disconnected")
|
||||
byte = ord(byte)
|
||||
number |= (byte & 0x7F) << 7 * i
|
||||
if not byte & 0x80:
|
||||
break
|
||||
return number
|
||||
|
||||
@staticmethod
|
||||
def read(file_object):
|
||||
number = 0
|
||||
|
||||
Reference in new issue
Block a user