distributed: python 3.x support for astron code
This commit is contained in:
parent
9980fa3f9d
commit
c54f469f37
|
|
@ -1,8 +1,8 @@
|
|||
"""AstronClientRepository module: contains the AstronClientRepository class"""
|
||||
|
||||
from direct.directnotify import DirectNotifyGlobal
|
||||
from ClientRepositoryBase import ClientRepositoryBase
|
||||
from MsgTypes import *
|
||||
from .ClientRepositoryBase import ClientRepositoryBase
|
||||
from .MsgTypes import *
|
||||
from direct.distributed.PyDatagram import PyDatagram
|
||||
from panda3d.direct import STUint16, STUint32
|
||||
|
||||
|
|
@ -265,6 +265,6 @@ class AstronClientRepository(ClientRepositoryBase):
|
|||
"""
|
||||
This implicitly deletes all objects from the repository.
|
||||
"""
|
||||
for do_id in self.doId2do.keys():
|
||||
for do_id in list(self.doId2do.keys()):
|
||||
self.deleteObject(do_id)
|
||||
ClientRepositoryBase.disconnect(self)
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
from panda3d.direct import DCPacker
|
||||
from MsgTypes import *
|
||||
from .MsgTypes import *
|
||||
from direct.directnotify import DirectNotifyGlobal
|
||||
from ConnectionRepository import ConnectionRepository
|
||||
from PyDatagram import PyDatagram
|
||||
from PyDatagramIterator import PyDatagramIterator
|
||||
from .ConnectionRepository import ConnectionRepository
|
||||
from .PyDatagram import PyDatagram
|
||||
from .PyDatagramIterator import PyDatagramIterator
|
||||
|
||||
class AstronDatabaseInterface:
|
||||
"""
|
||||
|
|
@ -39,7 +39,7 @@ class AstronDatabaseInterface:
|
|||
# Pack up/count valid fields.
|
||||
fieldPacker = DCPacker()
|
||||
fieldCount = 0
|
||||
for k,v in fields.items():
|
||||
for k,v in list(fields.items()):
|
||||
field = dclass.getFieldByName(k)
|
||||
if not field:
|
||||
self.notify.error('Creation request for %s object contains '
|
||||
|
|
@ -57,7 +57,7 @@ class AstronDatabaseInterface:
|
|||
dg.addUint32(ctx)
|
||||
dg.addUint16(dclass.getNumber())
|
||||
dg.addUint16(fieldCount)
|
||||
dg.appendData(fieldPacker.getString())
|
||||
dg.appendData(fieldPacker.getBytes())
|
||||
self.air.send(dg)
|
||||
|
||||
def handleCreateObjectResp(self, di):
|
||||
|
|
@ -149,7 +149,7 @@ class AstronDatabaseInterface:
|
|||
unpacker = DCPacker()
|
||||
unpacker.setUnpackData(di.getRemainingBytes())
|
||||
fields = {}
|
||||
for x in xrange(fieldCount):
|
||||
for x in range(fieldCount):
|
||||
fieldId = unpacker.rawUnpackInt16()
|
||||
field = dclass.getFieldByIndex(fieldId)
|
||||
|
||||
|
|
@ -197,7 +197,7 @@ class AstronDatabaseInterface:
|
|||
|
||||
fieldPacker = DCPacker()
|
||||
fieldCount = 0
|
||||
for k,v in newFields.items():
|
||||
for k,v in list(newFields.items()):
|
||||
field = dclass.getFieldByName(k)
|
||||
if not field:
|
||||
self.notify.error('Update for %s(%d) object contains invalid'
|
||||
|
|
@ -276,7 +276,7 @@ class AstronDatabaseInterface:
|
|||
unpacker = DCPacker()
|
||||
unpacker.setUnpackData(di.getRemainingBytes())
|
||||
fields = {}
|
||||
for x in xrange(fieldCount):
|
||||
for x in range(fieldCount):
|
||||
fieldId = unpacker.rawUnpackInt16()
|
||||
field = self.air.getDcFile().getFieldByIndex(fieldId)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
from panda3d.core import *
|
||||
from panda3d.direct import DCPacker
|
||||
from MsgTypes import *
|
||||
from .MsgTypes import *
|
||||
from direct.showbase import ShowBase # __builtin__.config
|
||||
from direct.task.TaskManagerGlobal import * # taskMgr
|
||||
from direct.directnotify import DirectNotifyGlobal
|
||||
from ConnectionRepository import ConnectionRepository
|
||||
from PyDatagram import PyDatagram
|
||||
from PyDatagramIterator import PyDatagramIterator
|
||||
from AstronDatabaseInterface import AstronDatabaseInterface
|
||||
from NetMessenger import NetMessenger
|
||||
from .ConnectionRepository import ConnectionRepository
|
||||
from .PyDatagram import PyDatagram
|
||||
from .PyDatagramIterator import PyDatagramIterator
|
||||
from .AstronDatabaseInterface import AstronDatabaseInterface
|
||||
from .NetMessenger import NetMessenger
|
||||
import collections
|
||||
|
||||
# Helper functions for logging output:
|
||||
|
|
@ -34,7 +34,7 @@ def msgpack_encode(dg, element):
|
|||
dg.addUint8(0xc2)
|
||||
elif element is True:
|
||||
dg.addUint8(0xc3)
|
||||
elif isinstance(element, (int, long)):
|
||||
elif isinstance(element, int):
|
||||
if -32 <= element < 128:
|
||||
dg.addInt8(element)
|
||||
elif 128 <= element < 256:
|
||||
|
|
@ -65,19 +65,19 @@ def msgpack_encode(dg, element):
|
|||
raise ValueError('int out of range for msgpack: %d' % element)
|
||||
elif isinstance(element, dict):
|
||||
msgpack_length(dg, len(element), 0x80, 0x10, None, 0xde, 0xdf)
|
||||
for k,v in element.items():
|
||||
for k,v in list(element.items()):
|
||||
msgpack_encode(dg, k)
|
||||
msgpack_encode(dg, v)
|
||||
elif isinstance(element, list):
|
||||
msgpack_length(dg, len(element), 0x90, 0x10, None, 0xdc, 0xdd)
|
||||
for v in element:
|
||||
msgpack_encode(dg, v)
|
||||
elif isinstance(element, basestring):
|
||||
elif isinstance(element, str):
|
||||
# 0xd9 is str 8 in all recent versions of the MsgPack spec, but somehow
|
||||
# Logstash bundles a MsgPack implementation SO OLD that this isn't
|
||||
# handled correctly so this function avoids it too
|
||||
msgpack_length(dg, len(element), 0xa0, 0x20, None, 0xda, 0xdb)
|
||||
dg.appendData(element)
|
||||
dg.appendData(element.encode())
|
||||
elif isinstance(element, float):
|
||||
# Python does not distinguish between floats and doubles, so we send
|
||||
# everything as a double in MsgPack:
|
||||
|
|
@ -207,7 +207,7 @@ class AstronInternalRepository(ConnectionRepository):
|
|||
dg2 = PyDatagram()
|
||||
dg2.addServerControlHeader(CONTROL_ADD_POST_REMOVE)
|
||||
dg2.addUint64(self.ourChannel)
|
||||
dg2.addString(dg.getMessage())
|
||||
dg2.appendData(dg.getMessage())
|
||||
self.send(dg2)
|
||||
|
||||
def clearPostRemove(self):
|
||||
|
|
@ -408,7 +408,7 @@ class AstronInternalRepository(ConnectionRepository):
|
|||
unpacker.setUnpackData(di.getRemainingBytes())
|
||||
|
||||
# Required:
|
||||
for i in xrange(dclass.getNumInheritedFields()):
|
||||
for i in range(dclass.getNumInheritedFields()):
|
||||
field = dclass.getInheritedField(i)
|
||||
if not field.isRequired() or field.asMolecularField(): continue
|
||||
unpacker.beginUnpack(field)
|
||||
|
|
@ -417,7 +417,7 @@ class AstronInternalRepository(ConnectionRepository):
|
|||
|
||||
# Other:
|
||||
other = unpacker.rawUnpackUint16()
|
||||
for i in xrange(other):
|
||||
for i in range(other):
|
||||
field = dclass.getFieldByIndex(unpacker.rawUnpackUint16())
|
||||
unpacker.beginUnpack(field)
|
||||
fields[field.getName()] = field.unpackArgs(unpacker)
|
||||
|
|
@ -499,7 +499,7 @@ class AstronInternalRepository(ConnectionRepository):
|
|||
fieldPacker = DCPacker()
|
||||
fieldCount = 0
|
||||
if dclass and fields:
|
||||
for k,v in fields.items():
|
||||
for k,v in list(fields.items()):
|
||||
field = dclass.getFieldByName(k)
|
||||
if not field:
|
||||
self.notify.error('Activation request for %s object contains '
|
||||
|
|
|
|||
Loading…
Reference in New Issue