Skip to content

Commit 7971eb9

Browse files
codegen: upgrade rabbitmq-codegen, improve compatibility with Python 3
Mako still has issues on 3.6, so we cannot switch to Python 3 by default :(
1 parent b32f587 commit 7971eb9

File tree

5 files changed

+45
-39
lines changed

5 files changed

+45
-39
lines changed

codegen/codegen.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
try:
1313
from mako.template import Template
1414
except ImportError:
15-
print "Mako isn't installed. Please install mako via pip or similar."
15+
print("Mako isn't installed. Please install mako via pip or similar.")
1616
sys.exit(1)
1717

1818
# main class
@@ -57,7 +57,7 @@ def new_init(self, arg):
5757

5858
# method.accepted_by("server")
5959
# method.accepted_by("client", "server")
60-
accepted_by_update = json.loads(file("codegen/amqp_0.9.1_changes.json").read())
60+
accepted_by_update = json.loads(open("codegen/amqp_0.9.1_changes.json").read())
6161

6262
def accepted_by(self, *receivers):
6363
def get_accepted_by(self):
@@ -143,7 +143,7 @@ def generateMain(type):
143143
def main(json_spec_path):
144144
spec = AmqpSpecObject(json_spec_path)
145145
spec.type = type
146-
print render("codegen/protocol.rb.pytemplate", spec = spec)
146+
print(render("codegen/protocol.rb.pytemplate", spec = spec))
147147

148148
return main
149149

codegen/codegen_helpers.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# -*- coding: utf-8 -*-
22

3+
from __future__ import print_function
4+
35
def genSingleEncode(spec, cValue, unresolved_domain):
46
buffer = []
57
type = spec.resolveDomain(unresolved_domain)
@@ -24,7 +26,7 @@ def genSingleEncode(spec, cValue, unresolved_domain):
2426
elif type == 'table':
2527
buffer.append("buffer << AMQ::Protocol::Table.encode(%s)" % (cValue,))
2628
else:
27-
raise "Illegal domain in genSingleEncode", type
29+
raise "Illegal domain in genSingleEncode: {0}".format(type)
2830

2931
return buffer
3032

@@ -34,7 +36,7 @@ def genSingleDecode(spec, field):
3436

3537
if cLvalue == "known_hosts":
3638
import sys
37-
print >> sys.stderr, field, field.ignored
39+
print(field, field.ignored, file = sys.stderr)
3840

3941
type = spec.resolveDomain(unresolved_domain)
4042
buffer = []
@@ -70,7 +72,7 @@ def genSingleDecode(spec, field):
7072
buffer.append("%s = Table.decode(data[offset, table_length + 4])" % (cLvalue,))
7173
buffer.append("offset += table_length + 4")
7274
else:
73-
raise StandardError("Illegal domain '" + type + "' in genSingleDecode")
75+
raise StandardError("Illegal domain '{0}' in genSingleDecode".format(type))
7476

7577
return buffer
7678

generate.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#!/usr/bin/env ruby
22
# encoding: utf-8
33

4+
# rabbitmq-codegen is Python 3 compatible and so is
5+
# the code in this repo but Mako still fails with 3.6 as of May 2017 :( MK.
6+
python = ENV.fetch("PYTHON", "python2")
7+
48
def sh(*args)
59
system(*args)
610
end
@@ -13,8 +17,8 @@ def sh(*args)
1317
end
1418

1519
path = "lib/amq/protocol/client.rb"
16-
puts "Running ./codegen/codegen.py client #{spec} #{path}"
17-
sh "./codegen/codegen.py client #{spec} #{extensions.join(' ')} #{path}"
20+
puts "Running '#{python} ./codegen/codegen.py client #{spec} #{extensions.join(' ')} #{path}'"
21+
sh "#{python} ./codegen/codegen.py client #{spec} #{extensions.join(' ')} #{path}"
1822
if File.file?(path)
1923
sh "ruby -c #{path}"
2024
end

lib/amq/protocol/client.rb

+30-30
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def self.has_content?
251251
end
252252

253253
# @return
254-
# [u'client_properties = nil', u"mechanism = u'PLAIN'", u'response = nil', u"locale = u'en_US'"]
254+
# ['client_properties = nil', "mechanism = 'PLAIN'", 'response = nil', "locale = 'en_US'"]
255255
def self.encode(client_properties, mechanism, response, locale)
256256
channel = 0
257257
buffer = @packed_indexes.dup
@@ -307,7 +307,7 @@ def self.has_content?
307307
end
308308

309309
# @return
310-
# [u'response = nil']
310+
# ['response = nil']
311311
def self.encode(response)
312312
channel = 0
313313
buffer = @packed_indexes.dup
@@ -362,7 +362,7 @@ def self.has_content?
362362
end
363363

364364
# @return
365-
# [u'channel_max = false', u'frame_max = false', u'heartbeat = false']
365+
# ['channel_max = false', 'frame_max = false', 'heartbeat = false']
366366
def self.encode(channel_max, frame_max, heartbeat)
367367
channel = 0
368368
buffer = @packed_indexes.dup
@@ -386,7 +386,7 @@ def self.has_content?
386386
end
387387

388388
# @return
389-
# [u"virtual_host = u'/'", u'capabilities = EMPTY_STRING', u'insist = false']
389+
# ["virtual_host = '/'", 'capabilities = EMPTY_STRING', 'insist = false']
390390
def self.encode(virtual_host)
391391
capabilities = EMPTY_STRING
392392
insist = false
@@ -467,7 +467,7 @@ def self.has_content?
467467
end
468468

469469
# @return
470-
# [u'reply_code = nil', u'reply_text = EMPTY_STRING', u'class_id = nil', u'method_id = nil']
470+
# ['reply_code = nil', 'reply_text = EMPTY_STRING', 'class_id = nil', 'method_id = nil']
471471
def self.encode(reply_code, reply_text, class_id, method_id)
472472
channel = 0
473473
buffer = @packed_indexes.dup
@@ -536,7 +536,7 @@ def self.has_content?
536536
end
537537

538538
# @return
539-
# [u'reason = EMPTY_STRING']
539+
# ['reason = EMPTY_STRING']
540540
def self.encode(reason)
541541
channel = 0
542542
buffer = @packed_indexes.dup
@@ -596,7 +596,7 @@ def self.has_content?
596596
end
597597

598598
# @return
599-
# [u'out_of_band = EMPTY_STRING']
599+
# ['out_of_band = EMPTY_STRING']
600600
def self.encode(channel, out_of_band)
601601
buffer = @packed_indexes.dup
602602
buffer << out_of_band.to_s.bytesize.chr
@@ -659,7 +659,7 @@ def self.has_content?
659659
end
660660

661661
# @return
662-
# [u'active = nil']
662+
# ['active = nil']
663663
def self.encode(channel, active)
664664
buffer = @packed_indexes.dup
665665
bit_buffer = 0
@@ -695,7 +695,7 @@ def self.has_content?
695695
end
696696

697697
# @return
698-
# [u'active = nil']
698+
# ['active = nil']
699699
def self.encode(channel, active)
700700
buffer = @packed_indexes.dup
701701
bit_buffer = 0
@@ -741,7 +741,7 @@ def self.has_content?
741741
end
742742

743743
# @return
744-
# [u'reply_code = nil', u'reply_text = EMPTY_STRING', u'class_id = nil', u'method_id = nil']
744+
# ['reply_code = nil', 'reply_text = EMPTY_STRING', 'class_id = nil', 'method_id = nil']
745745
def self.encode(channel, reply_code, reply_text, class_id, method_id)
746746
buffer = @packed_indexes.dup
747747
buffer << [reply_code].pack(PACK_UINT16)
@@ -802,7 +802,7 @@ def self.has_content?
802802
end
803803

804804
# @return
805-
# [u'ticket = 0', u'exchange = nil', u"type = u'direct'", u'passive = false', u'durable = false', u'auto_delete = false', u'internal = false', u'nowait = false', u'arguments = {}']
805+
# ['ticket = 0', 'exchange = nil', "type = 'direct'", 'passive = false', 'durable = false', 'auto_delete = false', 'internal = false', 'nowait = false', 'arguments = {}']
806806
def self.encode(channel, exchange, type, passive, durable, auto_delete, internal, nowait, arguments)
807807
ticket = 0
808808
buffer = @packed_indexes.dup
@@ -858,7 +858,7 @@ def self.has_content?
858858
end
859859

860860
# @return
861-
# [u'ticket = 0', u'exchange = nil', u'if_unused = false', u'nowait = false']
861+
# ['ticket = 0', 'exchange = nil', 'if_unused = false', 'nowait = false']
862862
def self.encode(channel, exchange, if_unused, nowait)
863863
ticket = 0
864864
buffer = @packed_indexes.dup
@@ -908,7 +908,7 @@ def self.has_content?
908908
end
909909

910910
# @return
911-
# [u'ticket = 0', u'destination = nil', u'source = nil', u'routing_key = EMPTY_STRING', u'nowait = false', u'arguments = {}']
911+
# ['ticket = 0', 'destination = nil', 'source = nil', 'routing_key = EMPTY_STRING', 'nowait = false', 'arguments = {}']
912912
def self.encode(channel, destination, source, routing_key, nowait, arguments)
913913
ticket = 0
914914
buffer = @packed_indexes.dup
@@ -962,7 +962,7 @@ def self.has_content?
962962
end
963963

964964
# @return
965-
# [u'ticket = 0', u'destination = nil', u'source = nil', u'routing_key = EMPTY_STRING', u'nowait = false', u'arguments = {}']
965+
# ['ticket = 0', 'destination = nil', 'source = nil', 'routing_key = EMPTY_STRING', 'nowait = false', 'arguments = {}']
966966
def self.encode(channel, destination, source, routing_key, nowait, arguments)
967967
ticket = 0
968968
buffer = @packed_indexes.dup
@@ -1024,7 +1024,7 @@ def self.has_content?
10241024
end
10251025

10261026
# @return
1027-
# [u'ticket = 0', u'queue = EMPTY_STRING', u'passive = false', u'durable = false', u'exclusive = false', u'auto_delete = false', u'nowait = false', u'arguments = {}']
1027+
# ['ticket = 0', 'queue = EMPTY_STRING', 'passive = false', 'durable = false', 'exclusive = false', 'auto_delete = false', 'nowait = false', 'arguments = {}']
10281028
def self.encode(channel, queue, passive, durable, exclusive, auto_delete, nowait, arguments)
10291029
ticket = 0
10301030
buffer = @packed_indexes.dup
@@ -1090,7 +1090,7 @@ def self.has_content?
10901090
end
10911091

10921092
# @return
1093-
# [u'ticket = 0', u'queue = EMPTY_STRING', u'exchange = nil', u'routing_key = EMPTY_STRING', u'nowait = false', u'arguments = {}']
1093+
# ['ticket = 0', 'queue = EMPTY_STRING', 'exchange = nil', 'routing_key = EMPTY_STRING', 'nowait = false', 'arguments = {}']
10941094
def self.encode(channel, queue, exchange, routing_key, nowait, arguments)
10951095
ticket = 0
10961096
buffer = @packed_indexes.dup
@@ -1144,7 +1144,7 @@ def self.has_content?
11441144
end
11451145

11461146
# @return
1147-
# [u'ticket = 0', u'queue = EMPTY_STRING', u'nowait = false']
1147+
# ['ticket = 0', 'queue = EMPTY_STRING', 'nowait = false']
11481148
def self.encode(channel, queue, nowait)
11491149
ticket = 0
11501150
buffer = @packed_indexes.dup
@@ -1197,7 +1197,7 @@ def self.has_content?
11971197
end
11981198

11991199
# @return
1200-
# [u'ticket = 0', u'queue = EMPTY_STRING', u'if_unused = false', u'if_empty = false', u'nowait = false']
1200+
# ['ticket = 0', 'queue = EMPTY_STRING', 'if_unused = false', 'if_empty = false', 'nowait = false']
12011201
def self.encode(channel, queue, if_unused, if_empty, nowait)
12021202
ticket = 0
12031203
buffer = @packed_indexes.dup
@@ -1252,7 +1252,7 @@ def self.has_content?
12521252
end
12531253

12541254
# @return
1255-
# [u'ticket = 0', u'queue = EMPTY_STRING', u'exchange = nil', u'routing_key = EMPTY_STRING', u'arguments = {}']
1255+
# ['ticket = 0', 'queue = EMPTY_STRING', 'exchange = nil', 'routing_key = EMPTY_STRING', 'arguments = {}']
12561256
def self.encode(channel, queue, exchange, routing_key, arguments)
12571257
ticket = 0
12581258
buffer = @packed_indexes.dup
@@ -1540,7 +1540,7 @@ def self.has_content?
15401540
end
15411541

15421542
# @return
1543-
# [u'prefetch_size = false', u'prefetch_count = false', u'global = false']
1543+
# ['prefetch_size = false', 'prefetch_count = false', 'global = false']
15441544
def self.encode(channel, prefetch_size, prefetch_count, global)
15451545
buffer = @packed_indexes.dup
15461546
buffer << [prefetch_size].pack(PACK_UINT32)
@@ -1587,7 +1587,7 @@ def self.has_content?
15871587
end
15881588

15891589
# @return
1590-
# [u'ticket = 0', u'queue = EMPTY_STRING', u'consumer_tag = EMPTY_STRING', u'no_local = false', u'no_ack = false', u'exclusive = false', u'nowait = false', u'arguments = {}']
1590+
# ['ticket = 0', 'queue = EMPTY_STRING', 'consumer_tag = EMPTY_STRING', 'no_local = false', 'no_ack = false', 'exclusive = false', 'nowait = false', 'arguments = {}']
15911591
def self.encode(channel, queue, consumer_tag, no_local, no_ack, exclusive, nowait, arguments)
15921592
ticket = 0
15931593
buffer = @packed_indexes.dup
@@ -1666,7 +1666,7 @@ def self.has_content?
16661666
end
16671667

16681668
# @return
1669-
# [u'consumer_tag = nil', u'nowait = false']
1669+
# ['consumer_tag = nil', 'nowait = false']
16701670
def self.encode(channel, consumer_tag, nowait)
16711671
buffer = @packed_indexes.dup
16721672
buffer << consumer_tag.to_s.bytesize.chr
@@ -1719,7 +1719,7 @@ def self.has_content?
17191719
end
17201720

17211721
# @return
1722-
# [u'ticket = 0', u'exchange = EMPTY_STRING', u'routing_key = EMPTY_STRING', u'mandatory = false', u'immediate = false', 'user_headers = nil', 'payload = ""', 'frame_size = nil']
1722+
# ['ticket = 0', 'exchange = EMPTY_STRING', 'routing_key = EMPTY_STRING', 'mandatory = false', 'immediate = false', 'user_headers = nil', 'payload = ""', 'frame_size = nil']
17231723
def self.encode(channel, payload, user_headers, exchange, routing_key, mandatory, immediate, frame_size)
17241724
ticket = 0
17251725
buffer = @packed_indexes.dup
@@ -1843,7 +1843,7 @@ def self.has_content?
18431843
end
18441844

18451845
# @return
1846-
# [u'ticket = 0', u'queue = EMPTY_STRING', u'no_ack = false']
1846+
# ['ticket = 0', 'queue = EMPTY_STRING', 'no_ack = false']
18471847
def self.encode(channel, queue, no_ack)
18481848
ticket = 0
18491849
buffer = @packed_indexes.dup
@@ -1957,7 +1957,7 @@ def self.has_content?
19571957
end
19581958

19591959
# @return
1960-
# [u'delivery_tag = false', u'multiple = false']
1960+
# ['delivery_tag = false', 'multiple = false']
19611961
def self.encode(channel, delivery_tag, multiple)
19621962
buffer = @packed_indexes.dup
19631963
buffer << AMQ::Pack.pack_uint64_big_endian(delivery_tag)
@@ -1981,7 +1981,7 @@ def self.has_content?
19811981
end
19821982

19831983
# @return
1984-
# [u'delivery_tag = nil', u'requeue = true']
1984+
# ['delivery_tag = nil', 'requeue = true']
19851985
def self.encode(channel, delivery_tag, requeue)
19861986
buffer = @packed_indexes.dup
19871987
buffer << AMQ::Pack.pack_uint64_big_endian(delivery_tag)
@@ -2005,7 +2005,7 @@ def self.has_content?
20052005
end
20062006

20072007
# @return
2008-
# [u'requeue = false']
2008+
# ['requeue = false']
20092009
def self.encode(channel, requeue)
20102010
buffer = @packed_indexes.dup
20112011
bit_buffer = 0
@@ -2028,7 +2028,7 @@ def self.has_content?
20282028
end
20292029

20302030
# @return
2031-
# [u'requeue = false']
2031+
# ['requeue = false']
20322032
def self.encode(channel, requeue)
20332033
buffer = @packed_indexes.dup
20342034
bit_buffer = 0
@@ -2091,7 +2091,7 @@ def self.has_content?
20912091
end
20922092

20932093
# @return
2094-
# [u'delivery_tag = false', u'multiple = false', u'requeue = true']
2094+
# ['delivery_tag = false', 'multiple = false', 'requeue = true']
20952095
def self.encode(channel, delivery_tag, multiple, requeue)
20962096
buffer = @packed_indexes.dup
20972097
buffer << AMQ::Pack.pack_uint64_big_endian(delivery_tag)
@@ -2271,7 +2271,7 @@ def self.has_content?
22712271
end
22722272

22732273
# @return
2274-
# [u'nowait = false']
2274+
# ['nowait = false']
22752275
def self.encode(channel, nowait)
22762276
buffer = @packed_indexes.dup
22772277
bit_buffer = 0

0 commit comments

Comments
 (0)