Skip to content

Commit

Permalink
Prevent RuntimeError with inheritance
Browse files Browse the repository at this point in the history
by removing self.__class__ and replacing it with the class name
  • Loading branch information
gamingrobot committed Aug 6, 2015
1 parent f3d7f23 commit 6abc898
Show file tree
Hide file tree
Showing 18 changed files with 54 additions and 50 deletions.
4 changes: 2 additions & 2 deletions spock/mcmap/mapdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def get_block(block_id, meta=0, init=True):
return blocks[block_id] if block_id < len(blocks) else None


class MapBlock:
class MapBlock(object):
display_name = 'Map Block'
name = 'map_block'
hardness = 0
Expand Down Expand Up @@ -1736,7 +1736,7 @@ def get_biome(biome_id):
return biomes[biome_id]() if biome_id in biomes else None


class MapBiome:
class MapBiome(object):
name = 'Map Biome'
temperature = 0.0

Expand Down
6 changes: 3 additions & 3 deletions spock/mcmap/smpmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
DIMENSION_END = 0x01


class ChunkData:
class ChunkData(object):
length = 16 * 16 * 16
ty = 'B'
data = None
Expand Down Expand Up @@ -94,14 +94,14 @@ def set(self, x, y, z, data):
self.data[i] = (self.data[i] & 0x0F) | ((data & 0x0F) << 4)


class Chunk:
class Chunk(object):
def __init__(self):
self.block_data = ChunkDataShort()
self.light_block = ChunkDataNibble()
self.light_sky = ChunkDataNibble()


class ChunkColumn:
class ChunkColumn(object):
def __init__(self):
self.chunks = [None] * 16
self.biome = BiomeData()
Expand Down
2 changes: 1 addition & 1 deletion spock/mcp/yggdrasil.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from urllib2 import HTTPError


class YggAuth:
class YggAuth(object):
def __init__(self, client_token=None, access_token=None, username=None,
password=None):
self.username = username
Expand Down
4 changes: 2 additions & 2 deletions spock/plugins/core/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def java_hex_digest(digest):
return d


class AuthCore:
class AuthCore(object):
def __init__(self, authenticated, event):
self.event = event
self.authenticated = authenticated
Expand Down Expand Up @@ -85,7 +85,7 @@ class AuthPlugin(PluginBase):
}

def __init__(self, ploader, settings):
super(self.__class__, self).__init__(ploader, settings)
super(PluginBase, self).__init__(ploader, settings)
self.authenticated = self.settings['authenticated']
self.sess_quit = self.settings['sess_quit']
self.auth = AuthCore(self.authenticated, self.event)
Expand Down
4 changes: 2 additions & 2 deletions spock/plugins/core/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
logger = logging.getLogger('spock')


class EventCore:
class EventCore(object):
def __init__(self):
self.kill_event = False
self.event_handlers = defaultdict(list)
Expand Down Expand Up @@ -45,6 +45,6 @@ def kill(self, *args):


@pl_announce('Event')
class EventPlugin:
class EventPlugin(object):
def __init__(self, ploader, settings):
ploader.provides('Event', EventCore())
8 changes: 4 additions & 4 deletions spock/plugins/core/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
logger = logging.getLogger('spock')


class AESCipher:
class AESCipher(object):
def __init__(self, shared_secret):
# Name courtesy of dx
self.encryptifier = AES.new(shared_secret, AES.MODE_CFB,
Expand All @@ -34,7 +34,7 @@ def decrypt(self, data):
return self.decryptifier.decrypt(data)


class SelectSocket:
class SelectSocket(object):
def __init__(self, timer):
self.sending = False
self.timer = timer
Expand Down Expand Up @@ -76,7 +76,7 @@ def reset(self):
self.sock.setblocking(False)


class NetCore:
class NetCore(object):
def __init__(self, sock, event):
self.sock = sock
self.event = event
Expand Down Expand Up @@ -187,7 +187,7 @@ class NetPlugin(PluginBase):
}

def __init__(self, ploader, settings):
super(self.__class__, self).__init__(ploader, settings)
super(PluginBase, self).__init__(ploader, settings)
self.bufsize = self.settings['bufsize']
self.sock_quit = self.settings['sock_quit']
self.sock = SelectSocket(self.timers)
Expand Down
4 changes: 2 additions & 2 deletions spock/plugins/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from spock.utils import get_settings, pl_announce


class PloaderFetch:
class PloaderFetch(object):
def __init__(self, plugins, plugin_settings):
self.plugins = plugins
self.plugin_settings = plugin_settings
Expand All @@ -15,7 +15,7 @@ def get_plugin_settings(self, plugin):


@pl_announce('PloaderFetch')
class SettingsPlugin:
class SettingsPlugin(object):
def __init__(self, ploader, kwargs):
settings = get_settings(kwargs.get('settings', {}), kwargs)
plugin_list = settings.get('plugins', DefaultPlugins)
Expand Down
10 changes: 5 additions & 5 deletions spock/plugins/core/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def reset(self):
# Time based timer
class EventTimer(BaseTimer):
def __init__(self, wait_time, callback, runs=1):
super(self.__class__, self).__init__(callback, runs)
super(BaseTimer, self).__init__(callback, runs)
self.wait_time = wait_time
self.end_time = time.time() + self.wait_time

Expand All @@ -65,7 +65,7 @@ def reset(self):
# World tick based timer
class TickTimer(BaseTimer):
def __init__(self, world, wait_ticks, callback, runs=1):
super(self.__class__, self).__init__(callback, runs)
super(BaseTimer, self).__init__(callback, runs)
self.world = world
self.wait_ticks = wait_ticks
self.end_tick = self.world.age + self.wait_ticks
Expand All @@ -79,7 +79,7 @@ def reset(self):
self.end_tick = self.world.age + self.wait_ticks


class TimerCore:
class TimerCore(object):
def __init__(self, world):
self.timers = []
self.persist_timers = []
Expand All @@ -106,7 +106,7 @@ def reg_tick_timer(self, wait_ticks, callback, runs=-1, persist=False):
persist)


class WorldTick:
class WorldTick(object):
def __init__(self):
self.age = 0

Expand All @@ -120,7 +120,7 @@ class TimerPlugin(PluginBase):
}

def __init__(self, ploader, settings):
super(self.__class__, self).__init__(ploader, settings)
super(PluginBase, self).__init__(ploader, settings)
if not self.world:
self.world = WorldTick()
ploader.reg_event_handler('PLAY<Time Update',
Expand Down
6 changes: 3 additions & 3 deletions spock/plugins/helpers/clientinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self):

class PlayerPosition(Position):
def __init__(self):
super(self.__class__, self).__init__()
super(Position, self).__init__()
self.yaw = 0.0
self.pitch = 0.0
self.on_ground = False
Expand All @@ -57,7 +57,7 @@ def __init__(self):
self.gamemode = 0


class ClientInfo:
class ClientInfo(object):
def __init__(self):
self.eid = 0
self.name = ""
Expand Down Expand Up @@ -90,7 +90,7 @@ class ClientInfoPlugin(PluginBase):
}

def __init__(self, ploader, settings):
super(self.__class__, self).__init__(ploader, settings)
super(PluginBase, self).__init__(ploader, settings)
self.uuids = {}
self.defered_pl = {}
self.client_info = ClientInfo()
Expand Down
4 changes: 2 additions & 2 deletions spock/plugins/helpers/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class GlobalEntity(MCEntity):
z = 0


class EntityCore:
class EntityCore(object):
def __init__(self):
self.client_player = ClientPlayerEntity()
self.entities = {}
Expand Down Expand Up @@ -116,7 +116,7 @@ class EntityPlugin(PluginBase):
}

def __init__(self, ploader, settings):
super(self.__class__, self).__init__(ploader, settings)
super(PluginBase, self).__init__(ploader, settings)
self.ec = EntityCore()
ploader.provides('Entities', self.ec)

Expand Down
26 changes: 15 additions & 11 deletions spock/plugins/helpers/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ def get_dict(self):
data = {'id': self.item_id}
if self.item_id != INV_ITEMID_EMPTY:
data['damage'] = self.damage





data['amount'] = self.amount
if self.nbt is not None:
data['enchants'] = self.nbt
Expand All @@ -93,15 +98,14 @@ def __repr__(self):

class SlotCursor(Slot):
def __init__(self, id=INV_ITEMID_EMPTY, damage=0, amount=0, enchants=None):
class CursorWindow:
class CursorWindow(object):
window_id = INV_WINID_CURSOR

def __repr__(self):
return 'CursorWindow()'

super(self.__class__, self).__init__(CursorWindow(),
INV_SLOT_NR_CURSOR, id, damage,
amount, enchants)
super(Slot, self).__init__(CursorWindow(), INV_SLOT_NR_CURSOR, id,
damage, amount, enchants)

# look up a class by window type ID when opening windows
inv_types = {}
Expand Down Expand Up @@ -172,9 +176,9 @@ def __init__(self, persistent_slots=None):
persistent_slots = [Slot(self, slot_nr) for slot_nr in
range(INV_SLOTS_PERSISTENT)]
# TODO title should be in chat format
super(self.__class__, self).__init__('player', INV_WINID_PLAYER,
self.name, INV_SLOTS_PLAYER,
persistent_slots)
super(InventoryBase, self).__init__('player', INV_WINID_PLAYER,
self.name, INV_SLOTS_PLAYER,
persistent_slots)

@property
def craft_result_slot(self):
Expand Down Expand Up @@ -332,13 +336,13 @@ class InventoryHorse(InventoryBase):
name = 'Horse'

def __init__(self, eid=0, **args):
super(self.__class__, self).__init__(**args)
super(InventoryBase, self).__init__(**args)
self.horse_entity_id = eid

# TODO horse slot getters


class BaseClick:
class BaseClick(object):
def get_packet(self, inv_plugin):
"""Called by send_click() to prepare the sent packet.
Abstract method.
Expand Down Expand Up @@ -463,7 +467,7 @@ def apply(self, inv_plugin):
# else: can't drop while holding an item


class InventoryCore:
class InventoryCore(object):
""" Handles operations with the player inventory. """

def __init__(self, net_plugin, send_click):
Expand Down Expand Up @@ -564,7 +568,7 @@ class InventoryPlugin(PluginBase):
}

def __init__(self, ploader, settings):
super(self.__class__, self).__init__(ploader, settings)
super(PluginBase, self).__init__(ploader, settings)

self.inventory = InventoryCore(self.net, self.send_click)
ploader.provides('Inventory', self.inventory)
Expand Down
4 changes: 2 additions & 2 deletions spock/plugins/helpers/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
logger = logging.getLogger('spock')


class MovementCore:
class MovementCore(object):
def __init__(self):
self.move_location = None

Expand All @@ -33,7 +33,7 @@ class MovementPlugin(PluginBase):
}

def __init__(self, ploader, settings):
super(self.__class__, self).__init__(ploader, settings)
super(PluginBase, self).__init__(ploader, settings)

self.movement = MovementCore()
ploader.provides('Movement', self.movement)
Expand Down
4 changes: 2 additions & 2 deletions spock/plugins/helpers/physics.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
logger = logging.getLogger('spock')


class PhysicsCore:
class PhysicsCore(object):
def __init__(self, vec, pos):
self.vec = vec
self.pos = pos
Expand Down Expand Up @@ -81,7 +81,7 @@ class PhysicsPlugin(PluginBase):
}

def __init__(self, ploader, settings):
super(self.__class__, self).__init__(ploader, settings)
super(PluginBase, self).__init__(ploader, settings)

self.vec = Vector3(0.0, 0.0, 0.0)
# wiki says 0.6 but I made it 0.8 to give a little wiggle room
Expand Down
2 changes: 1 addition & 1 deletion spock/plugins/helpers/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class StartPlugin(PluginBase):
}

def __init__(self, ploader, settings):
super(self.__class__, self).__init__(ploader, settings)
super(PluginBase, self).__init__(ploader, settings)
setattr(ploader, 'start', self.start)

def start(self, host=None, port=None):
Expand Down
6 changes: 3 additions & 3 deletions spock/plugins/helpers/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class WorldData(smpmap.Dimension):
def __init__(self, dimension=mcdata.SMP_OVERWORLD):
super(self.__class__, self).__init__(dimension)
super(smpmap.Dimension, self).__init__(dimension)
self.age = 0
self.time_of_day = 0

Expand All @@ -22,7 +22,7 @@ def update_time(self, data):
self.time_of_day = data['time_of_day']

def new_dimension(self, dimension):
super(self.__class__, self).__init__(dimension)
super(smpmap.Dimension, self).__init__(dimension)

def reset(self):
self.__init__(self.dimension)
Expand All @@ -43,7 +43,7 @@ class WorldPlugin(PluginBase):
}

def __init__(self, ploader, settings):
super(self.__class__, self).__init__(ploader, settings)
super(PluginBase, self).__init__(ploader, settings)
self.world = WorldData()
ploader.provides('World', self.world)

Expand Down
2 changes: 1 addition & 1 deletion spock/plugins/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
pl_warn = base_warn + ": %s"


class PluginLoader:
class PluginLoader(object):
def __init__(self, **kwargs):
self.announce = {}
self.extensions = {}
Expand Down

0 comments on commit 6abc898

Please sign in to comment.