forked from apache/qpid-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpy3.patch
5307 lines (4728 loc) · 184 KB
/
py3.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--- ./setup.py (original)
+++ ./setup.py (refactored)
@@ -17,6 +17,7 @@
# specific language governing permissions and limitations
# under the License.
#
+from __future__ import absolute_import
import os, re, sys, string, platform
from distutils.core import setup, Command
from distutils.command.build import build as _build
@@ -39,8 +40,7 @@
name, actor = self.actor(src, dst)
if actor:
if not os.path.isfile(src):
- raise DistutilsFileError, \
- "can't copy '%s': doesn't exist or not a regular file" % src
+ raise DistutilsFileError("can't copy '%s': doesn't exist or not a regular file" % src)
if os.path.isdir(dst):
dir = dst
@@ -61,22 +61,22 @@
else:
try:
fsrc = open(src, 'rb')
- except os.error, (errno, errstr):
- raise DistutilsFileError, \
- "could not open '%s': %s" % (src, errstr)
+ except os.error as xxx_todo_changeme1:
+ (errno, errstr) = xxx_todo_changeme1.args
+ raise DistutilsFileError("could not open '%s': %s" % (src, errstr))
if os.path.exists(dst):
try:
os.unlink(dst)
- except os.error, (errno, errstr):
- raise DistutilsFileError, \
- "could not delete '%s': %s" % (dst, errstr)
+ except os.error as xxx_todo_changeme:
+ (errno, errstr) = xxx_todo_changeme.args
+ raise DistutilsFileError("could not delete '%s': %s" % (dst, errstr))
try:
fdst = open(dst, 'wb')
- except os.error, (errno, errstr):
- raise DistutilsFileError, \
- "could not create '%s': %s" % (dst, errstr)
+ except os.error as xxx_todo_changeme2:
+ (errno, errstr) = xxx_todo_changeme2.args
+ raise DistutilsFileError("could not create '%s': %s" % (dst, errstr))
try:
fdst.write(actor(fsrc.read()))
@@ -129,7 +129,7 @@
try:
from epydoc.docbuilder import build_doc_index
from epydoc.docwriter.html import HTMLWriter
- except ImportError, e:
+ except ImportError as e:
log.warn('%s -- skipping build_doc', e)
return
--- ./examples/api/statistics.py (original)
+++ ./examples/api/statistics.py (refactored)
@@ -18,6 +18,8 @@
# under the License.
#
+from __future__ import absolute_import
+from __future__ import print_function
import time
TS = "ts"
@@ -110,7 +112,7 @@
self.batchCount+=1
if self.batchCount == self.batchSize:
self.header()
- print self.batch.report()
+ print(self.batch.report())
self.create()
self.batchCount = 0
@@ -119,13 +121,13 @@
if self.overall == None:
self.overall = self.create()
self.header()
- print self.overall.report()
+ print(self.overall.report())
def header(self):
if not self.headerPrinted:
if self.overall == None:
self.overall = self.create()
- print self.overall.header()
+ print(self.overall.header())
self.headerPrinted = True
--- ./examples/reservations/common.py (original)
+++ ./examples/reservations/common.py (refactored)
@@ -18,6 +18,8 @@
# under the License.
#
+from __future__ import absolute_import
+from __future__ import print_function
import traceback
from fnmatch import fnmatch
from qpid.messaging import *
@@ -25,7 +27,7 @@
class Dispatcher:
def unhandled(self, msg):
- print "UNHANDLED MESSAGE: %s" % msg
+ print("UNHANDLED MESSAGE: %s" % msg)
def ignored(self, msg):
return False
@@ -60,8 +62,8 @@
try:
snd = session.sender(to)
snd.send(r)
- except SendError, e:
- print e
+ except SendError as e:
+ print(e)
finally:
snd.close()
--- ./mllib/__init__.py (original)
+++ ./mllib/__init__.py (refactored)
@@ -22,22 +22,24 @@
both SGML and XML.
"""
+from __future__ import absolute_import
import os, dom, transforms, parsers, sys
import xml.sax, types
from xml.sax.handler import ErrorHandler
from xml.sax.xmlreader import InputSource
from cStringIO import StringIO
+import six
def transform(node, *args):
result = node
for t in args:
- if isinstance(t, types.ClassType):
+ if isinstance(t, type):
t = t()
result = result.dispatch(t)
return result
def sgml_parse(source):
- if isinstance(source, basestring):
+ if isinstance(source, six.string_types):
source = StringIO(source)
fname = "<string>"
elif hasattr(source, "name"):
--- ./mllib/dom.py (original)
+++ ./mllib/dom.py (refactored)
@@ -25,7 +25,9 @@
from __future__ import generators
from __future__ import nested_scopes
-import transforms
+from __future__ import absolute_import
+from . import transforms
+import six
class Container:
@@ -140,7 +142,7 @@
Node.__init__(self)
self.name = _name
self.attrs = list(attrs)
- self.attrs.extend(kwargs.items())
+ self.attrs.extend(list(kwargs.items()))
self.singleton = False
def get_attr(self, name):
@@ -177,7 +179,7 @@
base = None
def __init__(self, data):
- assert isinstance(data, basestring)
+ assert isinstance(data, six.string_types)
self.data = data
class Data(Leaf):
@@ -238,7 +240,7 @@
sources = [iter(self.source)]
while sources:
try:
- nd = sources[-1].next()
+ nd = next(sources[-1])
if isinstance(nd, Tree):
sources.append(iter(nd.children))
else:
@@ -267,7 +269,7 @@
yield value
def flatten_path(path):
- if isinstance(path, basestring):
+ if isinstance(path, six.string_types):
for part in path.split("/"):
yield part
elif callable(path):
@@ -290,7 +292,7 @@
select = Query
pred = p
source = query
- elif isinstance(p, basestring):
+ elif isinstance(p, six.string_types):
if p[0] == "@":
select = Values
pred = lambda x, n=p[1:]: x[0] == n
--- ./mllib/parsers.py (original)
+++ ./mllib/parsers.py (refactored)
@@ -21,8 +21,9 @@
Parsers for SGML and XML to dom.
"""
+from __future__ import absolute_import
import sgmllib, xml.sax.handler
-from dom import *
+from .dom import *
class Parser:
@@ -122,7 +123,7 @@
self.locator = locator
def startElement(self, name, attrs):
- self.parser.start(name, attrs.items())
+ self.parser.start(name, list(attrs.items()))
self.line()
def endElement(self, name):
--- ./mllib/transforms.py (original)
+++ ./mllib/transforms.py (refactored)
@@ -21,7 +21,8 @@
Useful transforms for dom objects.
"""
-import dom
+from __future__ import absolute_import
+from . import dom
from cStringIO import StringIO
class Visitor:
--- ./qpid/__init__.py (original)
+++ ./qpid/__init__.py (refactored)
@@ -17,7 +17,9 @@
# under the License.
#
-import connection
+from __future__ import absolute_import
+from . import connection
+from six.moves import zip
class Struct:
@@ -41,11 +43,11 @@
return field
def exists(self, attr):
- return self.type.fields.byname.has_key(attr)
+ return attr in self.type.fields.byname
def has(self, attr):
self._check(attr)
- return self._values.has_key(attr)
+ return attr in self._values
def set(self, attr, value):
self._check(attr)
--- ./qpid/client.py (original)
+++ ./qpid/client.py (refactored)
@@ -22,16 +22,19 @@
interacting with the server.
"""
+from __future__ import absolute_import
import os, threading
-from peer import Peer, Channel, Closed
-from delegate import Delegate
-from util import get_client_properties_with_defaults
-from connection08 import Connection, Frame, connect
-from spec08 import load
-from queue import Queue
-from reference import ReferenceId, References
-from saslmech.finder import get_sasl_mechanism
-from saslmech.sasl import SaslException
+from .peer import Peer, Channel, Closed
+from .delegate import Delegate
+from .util import get_client_properties_with_defaults
+from .connection08 import Connection, Frame, connect
+from .spec08 import load
+from .queue import Queue
+from .reference import ReferenceId, References
+from .saslmech.finder import get_sasl_mechanism
+from .saslmech.sasl import SaslException
+from six.moves import range
+from six.moves import zip
class Client:
@@ -42,7 +45,7 @@
if spec:
self.spec = spec
else:
- from specs_config import amqp_spec_0_9
+ from .specs_config import amqp_spec_0_9
self.spec = load(amqp_spec_0_9)
self.structs = StructFactory(self.spec)
self.sessions = {}
@@ -121,8 +124,8 @@
self.lock.acquire()
try:
id = None
- for i in xrange(1, 64*1024):
- if not self.sessions.has_key(i):
+ for i in range(1, 64*1024):
+ if i not in self.sessions:
id = i
break
finally:
@@ -184,7 +187,7 @@
msg.secure_ok(response=self.client.sasl.response(msg.challenge))
def connection_tune(self, ch, msg):
- tune_params = dict(zip(('channel_max', 'frame_max', 'heartbeat'), (msg.frame.args)))
+ tune_params = dict(list(zip(('channel_max', 'frame_max', 'heartbeat'), (msg.frame.args))))
if self.client.tune_params:
tune_params.update(self.client.tune_params)
msg.tune_ok(**tune_params)
@@ -257,9 +260,9 @@
self.factories = {}
def __getattr__(self, name):
- if self.factories.has_key(name):
+ if name in self.factories:
return self.factories[name]
- elif self.spec.domains.byname.has_key(name):
+ elif name in self.spec.domains.byname:
f = lambda *args, **kwargs: self.struct(name, *args, **kwargs)
self.factories[name] = f
return f
--- ./qpid/codec.py (original)
+++ ./qpid/codec.py (refactored)
@@ -26,11 +26,14 @@
The unit test for this module is located in tests/codec.py
"""
+from __future__ import absolute_import
import re, qpid, spec08, os
from cStringIO import StringIO
from struct import *
-from reference import ReferenceId
+from .reference import ReferenceId
from logging import getLogger
+import six
+from six.moves import range
log = getLogger("qpid.codec")
@@ -72,10 +75,10 @@
self.types = {}
self.codes = {}
- self.integertypes = [int, long]
+ self.integertypes = [int, int]
self.encodings = {
float: "double", # python uses 64bit floats, send them as doubles
- basestring: "longstr",
+ six.string_types: "longstr",
None.__class__:"void",
list: "sequence",
tuple: "sequence",
@@ -131,7 +134,7 @@
return "signed_long"
else:
raise ValueError('Integer value is outwith the supported 64bit signed range')
- if self.encodings.has_key(klass):
+ if klass in self.encodings:
return self.encodings[klass]
for base in klass.__bases__:
result = self.resolve(base, value)
@@ -461,7 +464,7 @@
log.debug("Field table entry key: %r", key)
code = self.decode_octet()
log.debug("Field table entry type code: %r", code)
- if self.types.has_key(code):
+ if code in self.types:
value = self.decode(self.types[code])
else:
w = width(code)
@@ -649,7 +652,7 @@
count = self.decode_long()
result = []
for i in range(0, count):
- if self.types.has_key(code):
+ if code in self.types:
value = self.decode(self.types[code])
else:
w = width(code)
--- ./qpid/codec010.py (original)
+++ ./qpid/codec010.py (refactored)
@@ -17,10 +17,14 @@
# under the License.
#
+from __future__ import absolute_import
import datetime, string
-from packer import Packer
-from datatypes import serial, timestamp, RangedSet, Struct, UUID
-from ops import Compound, PRIMITIVE, COMPOUND
+from .packer import Packer
+from .datatypes import serial, timestamp, RangedSet, Struct, UUID
+from .ops import Compound, PRIMITIVE, COMPOUND
+from six.moves import map
+import six
+from six.moves import range
class CodecException(Exception): pass
@@ -37,11 +41,11 @@
ENCODINGS = {
bool: direct("boolean"),
- unicode: direct("str16"),
+ six.text_type: direct("str16"),
str: map_str,
buffer: direct("vbin32"),
int: direct("int64"),
- long: direct("int64"),
+ int: direct("int64"),
float: direct("double"),
None.__class__: direct("void"),
list: direct("list"),
@@ -60,7 +64,7 @@
return PRIMITIVE[enc]
def _encoding(self, klass, obj):
- if self.ENCODINGS.has_key(klass):
+ if klass in self.ENCODINGS:
return self.ENCODINGS[klass](obj)
for base in klass.__bases__:
result = self._encoding(base, obj)
@@ -226,7 +230,7 @@
if isinstance(b, buffer):
b = str(b)
# Allow unicode values in connection 'response' field
- if isinstance(b, unicode):
+ if isinstance(b, six.text_type):
b = b.encode('utf8')
self.write_uint32(len(b))
self.write(b)
@@ -257,7 +261,7 @@
sc = StringCodec()
if m is not None:
sc.write_uint32(len(m))
- sc.write(string.joinfields(map(self._write_map_elem, m.keys(), m.values()), ""))
+ sc.write(string.joinfields(list(map(self._write_map_elem, list(m.keys()), list(m.values()))), ""))
self.write_vbin32(sc.encoded)
def read_array(self):
@@ -339,7 +343,7 @@
for i in range(len(op.FIELDS)):
f = op.FIELDS[i]
if flags & (0x1 << i):
- if COMPOUND.has_key(f.type):
+ if f.type in COMPOUND:
value = self.read_compound(COMPOUND[f.type])
else:
value = getattr(self, "read_%s" % f.type)()
@@ -360,7 +364,7 @@
for i in range(len(op.FIELDS)):
f = op.FIELDS[i]
if flags & (0x1 << i):
- if COMPOUND.has_key(f.type):
+ if f.type in COMPOUND:
enc = self.write_compound
else:
enc = getattr(self, "write_%s" % f.type)
--- ./qpid/compat.py (original)
+++ ./qpid/compat.py (refactored)
@@ -17,6 +17,7 @@
# under the License.
#
+from __future__ import absolute_import
import sys
import errno
import time
@@ -126,7 +127,7 @@
try:
ready, _, _ = select([self], [], [], timeout)
break
- except SelectError, e:
+ except SelectError as e:
if e[0] == errno.EINTR:
elapsed = time.time() - start
timeout = timeout - elapsed
--- ./qpid/concurrency.py (original)
+++ ./qpid/concurrency.py (refactored)
@@ -17,13 +17,14 @@
# under the License.
#
+from __future__ import absolute_import
import compat, inspect, time
def synchronized(meth):
args, vargs, kwargs, defs = inspect.getargspec(meth)
scope = {}
scope["meth"] = meth
- exec """
+ exec("""
def %s%s:
%s
%s._lock.acquire()
@@ -35,7 +36,7 @@
repr(inspect.getdoc(meth)), args[0],
inspect.formatargspec(args, vargs, kwargs, defs,
formatvalue=lambda x: ""),
- args[0]) in scope
+ args[0]), scope)
return scope[meth.__name__]
class Waiter(object):
--- ./qpid/connection.py (original)
+++ ./qpid/connection.py (refactored)
@@ -17,17 +17,19 @@
# under the License.
#
-import datatypes, session
+from __future__ import absolute_import
+from . import datatypes, session
from threading import Thread, Condition, RLock
-from util import wait, notify
-from codec010 import StringCodec
-from framing import *
-from session import Session
-from generator import control_invoker
-from exceptions import *
+from .util import wait, notify
+from .codec010 import StringCodec
+from .framing import *
+from .session import Session
+from .generator import control_invoker
+from .exceptions import *
from logging import getLogger
import delegates, socket
import sys
+from six.moves import range
class ChannelBusy(Exception): pass
@@ -43,7 +45,7 @@
def server(*args, **kwargs):
return delegates.Server(*args, **kwargs)
-from framer import Framer
+from .framer import Framer
class Connection(Framer):
@@ -111,8 +113,8 @@
self.lock.release()
def __channel(self):
- for i in xrange(1, self.channel_max):
- if not self.attached.has_key(i):
+ for i in range(1, self.channel_max):
+ if i not in self.attached:
return i
else:
raise ChannelsBusy()
@@ -182,7 +184,7 @@
break
else:
continue
- except socket.error, e:
+ except socket.error as e:
if self.aborted() or str(e) != "The read operation timed out":
self.close_code = (None, str(e))
self.detach_all()
@@ -195,7 +197,7 @@
for op in op_dec.read():
try:
self.delegate.received(op)
- except Closed, e:
+ except Closed as e:
self.close_code = (None, str(e))
if not self.opened:
self.failed = True
--- ./qpid/connection08.py (original)
+++ ./qpid/connection08.py (refactored)
@@ -23,12 +23,15 @@
server, or even a proxy implementation.
"""
+from __future__ import absolute_import
import socket, codec, errno, qpid
from cStringIO import StringIO
-from codec import EOF
-from compat import SHUT_RDWR
-from exceptions import VersionError
+from .codec import EOF
+from .compat import SHUT_RDWR
+from .exceptions import VersionError
from logging import getLogger, DEBUG
+from six.moves import range
+from six.moves import zip
log = getLogger("qpid.connection08")
@@ -63,7 +66,7 @@
try:
try:
self.sock.shutdown(SHUT_RDWR)
- except socket.error, e:
+ except socket.error as e:
if (e.errno == errno.ENOTCONN):
pass
else:
@@ -131,7 +134,7 @@
certfile=ssl_certfile,
ca_certs=ssl_trustfile,
cert_reqs=validate)
- except ImportError, e:
+ except ImportError as e:
# Python 2.5 and older
if ssl_verify_hostname:
log.error("Your version of Python does not support ssl hostname verification. Please upgrade your version of Python.")
@@ -310,10 +313,10 @@
def __new__(cls, name, bases, dict):
for attr in ("encode", "decode", "type"):
- if not dict.has_key(attr):
+ if attr not in dict:
raise TypeError("%s must define %s" % (name, attr))
dict["decode"] = staticmethod(dict["decode"])
- if dict.has_key("__init__"):
+ if "__init__" in dict:
__init__ = dict["__init__"]
def init(self, *args, **kwargs):
args = list(args)
--- ./qpid/content.py (original)
+++ ./qpid/content.py (refactored)
@@ -21,6 +21,8 @@
A simple python representation for AMQP content.
"""
+from __future__ import absolute_import
+from six.moves import map
def default(val, defval):
if val == None:
return defval
--- ./qpid/datatypes.py (original)
+++ ./qpid/datatypes.py (refactored)
@@ -17,8 +17,11 @@
# under the License.
#
+from __future__ import absolute_import
import threading, struct, datetime, time
-from exceptions import Timeout
+from .exceptions import Timeout
+from six.moves import map
+from six.moves import range
class Struct:
@@ -33,10 +36,10 @@
for field in _type.fields:
if idx < len(args):
arg = args[idx]
- if kwargs.has_key(field.name):
+ if field.name in kwargs:
raise TypeError("%s() got multiple values for keyword argument '%s'" %
(_type.name, field.name))
- elif kwargs.has_key(field.name):
+ elif field.name in kwargs:
arg = kwargs.pop(field.name)
else:
arg = field.default()
@@ -44,7 +47,7 @@
idx += 1
if kwargs:
- unexpected = kwargs.keys()[0]
+ unexpected = list(kwargs.keys())[0]
raise TypeError("%s() got an unexpected keyword argument '%s'" %
(_type.name, unexpected))
@@ -110,7 +113,7 @@
def __repr__(self):
args = []
if self.headers:
- args.extend(map(repr, self.headers))
+ args.extend(list(map(repr, self.headers)))
if self.body:
args.append(repr(self.body))
if self.id is not None:
@@ -126,19 +129,19 @@
class Serial:
def __init__(self, value):
- self.value = value & 0xFFFFFFFFL
+ self.value = value & 0xFFFFFFFF
def __hash__(self):
return hash(self.value)
def __cmp__(self, other):
- if other.__class__ not in (int, long, Serial):
+ if other.__class__ not in (int, int, Serial):
return 1
other = serial(other)
- delta = (self.value - other.value) & 0xFFFFFFFFL
- neg = delta & 0x80000000L
+ delta = (self.value - other.value) & 0xFFFFFFFF
+ neg = delta & 0x80000000
mag = delta & 0x7FFFFFFF
if neg:
@@ -319,7 +322,7 @@
rand = random.Random()
rand.seed((os.getpid(), time.time(), socket.gethostname()))
def random_uuid():
- bytes = [rand.randint(0, 255) for i in xrange(16)]
+ bytes = [rand.randint(0, 255) for i in range(16)]
# From RFC4122, the version bits are set to 0100
bytes[7] &= 0x0F
--- ./qpid/debug.py (original)
+++ ./qpid/debug.py (refactored)
@@ -17,6 +17,8 @@
# under the License.
#
+from __future__ import absolute_import
+from __future__ import print_function
import threading, traceback, signal, sys, time
def stackdump(sig, frm):
@@ -27,7 +29,7 @@
code.append('File: "%s", line %d, in %s' % (filename, lineno, name))
if line:
code.append(" %s" % (line.strip()))
- print "\n".join(code)
+ print("\n".join(code))
signal.signal(signal.SIGQUIT, stackdump)
@@ -39,12 +41,12 @@
def acquire(self, blocking=1):
while not self.lock.acquire(blocking=0):
time.sleep(1)
- print >> sys.out, "TRYING"
+ print("TRYING", file=sys.out)
traceback.print_stack(None, None, out)
- print >> sys.out, "TRYING"
- print >> sys.out, "ACQUIRED"
+ print("TRYING", file=sys.out)
+ print("ACQUIRED", file=sys.out)
traceback.print_stack(None, None, out)
- print >> sys.out, "ACQUIRED"
+ print("ACQUIRED", file=sys.out)
return True
def _is_owned(self):
--- ./qpid/delegate.py (original)
+++ ./qpid/delegate.py (refactored)
@@ -21,8 +21,10 @@
Delegate implementation intended for use with the peer module.
"""
+from __future__ import absolute_import
+from __future__ import print_function
import threading, inspect, traceback, sys
-from connection08 import Method, Request, Response
+from .connection08 import Method, Request, Response
def _handler_name(method):
return "%s_%s" % (method.klass.name, method.name)
@@ -46,8 +48,8 @@
try:
return handler(channel, frame)
except:
- print >> sys.stderr, "Error in handler: %s\n\n%s" % \
- (_handler_name(method), traceback.format_exc())
+ print("Error in handler: %s\n\n%s" % \
+ (_handler_name(method), traceback.format_exc()), file=sys.stderr)
def closed(self, reason):
- print "Connection closed: %s" % reason
+ print("Connection closed: %s" % reason)
--- ./qpid/delegates.py (original)
+++ ./qpid/delegates.py (refactored)
@@ -17,12 +17,13 @@
# under the License.
#
+from __future__ import absolute_import
import os, connection, session
-from util import notify, get_client_properties_with_defaults
-from datatypes import RangedSet
-from exceptions import VersionError, Closed
+from .util import notify, get_client_properties_with_defaults
+from .datatypes import RangedSet
+from .exceptions import VersionError, Closed
from logging import getLogger
-from ops import Control
+from .ops import Control
import sys
from qpid import sasl
@@ -187,7 +188,7 @@
initial = None
try:
mech, initial = self.sasl.start(mech_list)
- except Exception, e:
+ except Exception as e:
raise Closed(str(e))
ch.connection_start_ok(client_properties=self.client_properties,
mechanism=mech, response=initial)
@@ -196,7 +197,7 @@
resp = None
try:
resp = self.sasl.step(secure.challenge)
- except Exception, e:
+ except Exception as e:
raise Closed(str(e))
ch.connection_secure_ok(response=resp)
--- ./qpid/disp.py (original)
+++ ./qpid/disp.py (refactored)
@@ -19,7 +19,11 @@
# under the License.
#
+from __future__ import absolute_import
+from __future__ import print_function
from time import strftime, gmtime
+import six
+from six.moves import range
class Header:
""" """
@@ -130,7 +134,7 @@
for idx in range(diff):
row.append("")
- print title
+ print(title)
if len (rows) == 0:
return
colWidth = []
@@ -139,7 +143,7 @@
for head in heads:
width = len (head)
for row in rows:
- cellWidth = len (unicode (row[col]))
+ cellWidth = len (six.text_type (row[col]))
if cellWidth > width:
width = cellWidth
colWidth.append (width + self.tableSpacing)
@@ -148,23 +152,23 @@
for i in range (colWidth[col] - len (head)):
line = line + " "
col = col + 1
- print line
+ print(line)
line = self.tablePrefix
for width in colWidth:
line = line + "=" * width
line = line[:255]
- print line
+ print(line)
for row in rows:
line = self.tablePrefix
col = 0
for width in colWidth:
- line = line + unicode (row[col])
+ line = line + six.text_type (row[col])
if col < len (heads) - 1:
- for i in range (width - len (unicode (row[col]))):
+ for i in range (width - len (six.text_type (row[col]))):
line = line + " "
col = col + 1
- print line
+ print(line)
def do_setTimeFormat (self, fmt):
""" Select timestamp format """
--- ./qpid/framer.py (original)
+++ ./qpid/framer.py (refactored)
@@ -17,9 +17,10 @@
# under the License.
#
+from __future__ import absolute_import
import struct, socket
-from exceptions import Closed
-from packer import Packer
+from .exceptions import Closed
+from .packer import Packer
from threading import RLock
from logging import getLogger
@@ -53,7 +54,7 @@
if self.security_layer_tx:
try:
cipher_buf = self.security_layer_tx.encode(self.tx_buf)
- except SASLError, e:
+ except SASLError as e:
raise Closed(str(e))
self._write(cipher_buf)
else:
@@ -96,14 +97,14 @@
if self.security_layer_rx:
try:
s = self.security_layer_rx.decode(s)
- except SASLError, e:
+ except SASLError as e:
raise Closed(str(e))
except socket.timeout:
if self.aborted():
raise Closed()
else:
continue
- except socket.error, e:
+ except socket.error as e:
if self.rx_buf != "":
raise e
else:
--- ./qpid/framing.py (original)
+++ ./qpid/framing.py (refactored)
@@ -17,6 +17,7 @@
# under the License.
#
+from __future__ import absolute_import
import struct
FIRST_SEG = 0x08
@@ -197,9 +198,9 @@
self.frames = []
return result
-from ops import COMMANDS, CONTROLS, COMPOUND, Header, segment_type, track
-
-from codec010 import StringCodec
+from .ops import COMMANDS, CONTROLS, COMPOUND, Header, segment_type, track
+
+from .codec010 import StringCodec
class OpEncoder:
@@ -208,11 +209,11 @@
def write(self, *ops):
for op in ops:
- if COMMANDS.has_key(op.NAME):
+ if op.NAME in COMMANDS:
seg_type = segment_type.command
seg_track = track.command
enc = self.encode_command(op)
- elif CONTROLS.has_key(op.NAME):
+ elif op.NAME in CONTROLS:
seg_type = segment_type.control
seg_track = track.control
enc = self.encode_compound(op)
--- ./qpid/generator.py (original)
+++ ./qpid/generator.py (refactored)
@@ -17,9 +17,11 @@
# under the License.
#
+from __future__ import absolute_import
import sys
-from ops import *
+from .ops import *
+import six
def METHOD(module, op):
method = lambda self, *args, **kwargs: self.invoke(op, args, kwargs)
@@ -33,15 +35,15 @@
dict = {}
for name, enum in ENUMS.items():
- if isinstance(name, basestring):