Changeset 96:eef8ca34bc9e in xplra


Ignore:
Timestamp:
05/19/19 11:18:03 (5 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

The Python client module works with both Python 2 and 3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/client/python/xplra.py

    r95 r96  
    55import struct
    66import array
     7import sys
     8
     9isPy3 = sys.version_info[0] >= 3
    710
    811#-------------------------------------------------------------------------------
     
    274277    def _packLength(x):
    275278        """Pack the given integer as a variable-length value."""
    276         s = ""
     279        s = bytes() if isPy3 else ""
    277280        while True:
    278281            y = x&0x7f
     
    286289    def _packString(s):
    287290        """Pack the given string."""
    288         return XPlane._packLength(len(s)) + s
     291        return XPlane._packLength(len(s)) + (bytes(s, "utf-8") if isPy3 else s)
    289292
    290293    def __init__(self):
     
    305308            s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    306309            s.connect("/tmp/xplra-" + os.environ["LOGNAME"])
    307             self._stream = s.makefile()
     310            self._stream = s.makefile("rwb")
    308311
    309312        for multiBuffer in self._multiBuffers:
Note: See TracChangeset for help on using the changeset viewer.