~fginther/landscape-client/fix-missing-install-dirs

« back to all changes in this revision

Viewing changes to landscape/broker/exchange.py

  • Committer: 🤖 Landscape Builder
  • Author(s): Free Ekanayaka
  • Date: 2017-04-06 17:59:25 UTC
  • mfrom: (1000.1.4 py3-registration)
  • Revision ID: _landscape_builder-20170406175925-y28xpj6q6ph0vwuu
Merge py3-registration [f=] [r=landscape-builder,simpoir,ericsnowcurrently] [a=Free Ekanayaka]
Adjust wire-to-language type conversions in order to have Landscape registration work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
347
347
from landscape.lib.hashlib import md5
348
348
 
349
349
from twisted.internet.defer import Deferred, succeed
 
350
from twisted.python.compat import _PY3
350
351
 
351
352
from landscape.lib.fetch import HTTPCodeError, PyCurlError
352
353
from landscape.lib.message import got_next_expected, ANCIENT
773
774
        # be 3.2, because it's the one that didn't have this field.
774
775
        server_api = result.get("server-api", b"3.2")
775
776
 
 
777
        if _PY3 and not isinstance(server_api, bytes):
 
778
            # The "server-api" field in the bpickle payload sent by the server
 
779
            # is a string, however in Python 3 we need to convert it to bytes,
 
780
            # since that's what the rest of the code expects.
 
781
            server_api = server_api.encode()
 
782
 
776
783
        if is_version_higher(server_api, message_store.get_server_api()):
777
784
            # The server can handle a message API that is higher than the one
778
785
            # we're currently using. If the highest server API is greater than
787
794
 
788
795
        sequence = message_store.get_server_sequence()
789
796
        for message in result.get("messages", ()):
 
797
            # The wire format of the 'type' field is bytes, but our handlers
 
798
            # actually expect it to be a string. Some unit tests set it to
 
799
            # a regular string (since there is no difference between strings
 
800
            # and bytes in Python 2), so we check the type before converting.
 
801
            if _PY3 and isinstance(message["type"], bytes):
 
802
                message["type"] = message["type"].decode("ascii")
790
803
            self.handle_message(message)
791
804
            sequence += 1
792
805
            message_store.set_server_sequence(sequence)