Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

distributed: AstronInternalRepository et al is now compatible with Python 3 #30

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions direct/src/distributed/AstronClientRepository.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""AstronClientRepository module: contains the AstronClientRepository class"""

from panda3d.direct import STUint16, STUint32
from direct.directnotify import DirectNotifyGlobal
from ClientRepositoryBase import ClientRepositoryBase
from MsgTypes import *
from direct.distributed.PyDatagram import PyDatagram
from pandac.PandaModules import STUint16, STUint32
from .ClientRepositoryBase import ClientRepositoryBase
from .MsgTypes import *

class AstronClientRepository(ClientRepositoryBase):
"""
Expand Down
18 changes: 9 additions & 9 deletions direct/src/distributed/AstronDatabaseInterface.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from pandac.PandaModules import *
from MsgTypes import *
from panda3d.core import *
from direct.directnotify import DirectNotifyGlobal
from ConnectionRepository import ConnectionRepository
from PyDatagram import PyDatagram
from PyDatagramIterator import PyDatagramIterator
from .MsgTypes import *
from .ConnectionRepository import ConnectionRepository
from .PyDatagram import PyDatagram
from .PyDatagramIterator import PyDatagramIterator

class AstronDatabaseInterface:
"""
Expand Down Expand Up @@ -57,7 +57,7 @@ def createObject(self, databaseId, dclass, fields={}, callback=None):
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):
Expand Down Expand Up @@ -149,7 +149,7 @@ def handleQueryObjectResp(self, msgType, di):
unpacker = DCPacker()
unpacker.setUnpackData(di.getRemainingBytes())
fields = {}
for x in xrange(fieldCount):
for x in range(fieldCount):
fieldId = unpacker.rawUnpackInt16()
field = dclass.getFieldByIndex(fieldId)

Expand Down Expand Up @@ -239,7 +239,7 @@ def updateObject(self, databaseId, doId, dclass, newFields, oldFields=None, call
dg.addUint32(doId)
if fieldCount != 1:
dg.addUint16(fieldCount)
dg.appendData(fieldPacker.getString())
dg.appendData(fieldPacker.getBytes())
self.air.send(dg)

if oldFields is None and callback is not None:
Expand Down Expand Up @@ -276,7 +276,7 @@ def handleUpdateObjectResp(self, di, multi):
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)

Expand Down
29 changes: 15 additions & 14 deletions direct/src/distributed/AstronInternalRepository.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from pandac.PandaModules import *
from MsgTypes import *
import collections

from panda3d.core 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
import collections
from .MsgTypes import *
from .ConnectionRepository import ConnectionRepository
from .PyDatagram import PyDatagram
from .PyDatagramIterator import PyDatagramIterator
from .AstronDatabaseInterface import AstronDatabaseInterface
from .NetMessenger import NetMessenger

# Helper functions for logging output:
def msgpack_length(dg, length, fix, maxfix, tag8, tag16, tag32):
Expand All @@ -33,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:
Expand Down Expand Up @@ -71,7 +72,7 @@ def msgpack_encode(dg, element):
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
Expand Down Expand Up @@ -206,7 +207,7 @@ def addPostRemove(self, dg):
dg2 = PyDatagram()
dg2.addServerControlHeader(CONTROL_ADD_POST_REMOVE)
dg2.addUint64(self.ourChannel)
dg2.addString(dg.getMessage())
dg2.addBlob(dg.getMessage())
self.send(dg2)

def clearPostRemove(self):
Expand Down Expand Up @@ -407,7 +408,7 @@ def handleGetObjectResp(self, di):
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)
Expand All @@ -416,7 +417,7 @@ def handleGetObjectResp(self, di):

# 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)
Expand Down Expand Up @@ -521,7 +522,7 @@ def sendActivate(self, doId, parentId, zoneId, dclass=None, fields=None):
dg.addServerHeader(doId, self.ourChannel, STATESERVER_OBJECT_SET_FIELDS)
dg.addUint32(doId)
dg.addUint16(fieldCount)
dg.appendData(fieldPacker.getString())
dg.appendData(fieldPacker.getBytes())
self.send(dg)
# Now slide it into the zone we expect to see it in (so it
# generates onto us with all of the fields in place)
Expand Down