From f19bd188c22abc6a9510ffdf87039f774f6f893f Mon Sep 17 00:00:00 2001 From: Mickey Rose Date: Tue, 31 Dec 2019 12:39:57 +0100 Subject: [PATCH] 2to3 last remnants of Python 2 syntax --- benchmark/utils/random_image.py | 4 +-- scripts/travis-command-wrapper.py | 6 ++--- utils/shapefile/shapefile_reader.py | 42 ++++++++++++++--------------- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/benchmark/utils/random_image.py b/benchmark/utils/random_image.py index 43f0f89cc..6f94d4634 100644 --- a/benchmark/utils/random_image.py +++ b/benchmark/utils/random_image.py @@ -3,8 +3,8 @@ import random im = mapnik.Image(256,256) -for x in xrange(0,im.width()): - for y in xrange(0,im.height()): +for x in range(im.width()): + for y in range(im.height()): r = int(random.random() * 255) g = random.random() * 255 b = random.random() * 255 diff --git a/scripts/travis-command-wrapper.py b/scripts/travis-command-wrapper.py index 2fdf8dc88..f4799f7b0 100755 --- a/scripts/travis-command-wrapper.py +++ b/scripts/travis-command-wrapper.py @@ -50,10 +50,10 @@ parser.add_option("-d", "--deadline", def check_deadline(now): if options.deadline > 0 and options.deadline < now: - print "\n\n*** travis-cmd-wrapper: deadline reached, shutting down ***\n\n" + print("\n\n*** travis-cmd-wrapper: deadline reached, shutting down ***\n\n") sys.exit(1) else: - print "deadline not reached: %s > %s" % (options.deadline,now) + print("deadline not reached: %s > %s" % (options.deadline,now)) # Set up status alarm. When we have a deadline, we need to check more often # and/or sooner. Sending a SIGALRM manually will also trigger a status report @@ -95,7 +95,7 @@ try: line = cmd.stdout.readline() sys.stdout.write(line) sys.stdout.flush() - except IOError, ex: + except IOError as ex: if ex.errno != errno.EINTR: raise finally: diff --git a/utils/shapefile/shapefile_reader.py b/utils/shapefile/shapefile_reader.py index a57d516f1..1e03ad917 100755 --- a/utils/shapefile/shapefile_reader.py +++ b/utils/shapefile/shapefile_reader.py @@ -22,7 +22,7 @@ ShapeType = { 0 : "NullShape", def test_record(_type, record) : if _type == 0: - print "NULL shape" + print("NULL shape") elif _type == 11: #PointZ test_pointz(record) elif _type == 5: @@ -31,35 +31,35 @@ def test_record(_type, record) : def test_pointz(record): _type, = struct.unpack(">sys.stderr,"BAD SHAPE FILE: expected 36 bytes got",len(record) + print("BAD SHAPE FILE: expected 36 bytes got", len(record), file=sys.stderr) sys.exit(1) x,y,z,m = struct.unpack(">sys.stderr,"BAD SHAPE FILE: expected PointZ or NullShape got",_type + print("BAD SHAPE FILE: expected PointZ or NullShape got", _type, file=sys.stderr) sys.exit(1) def test_polygon(record): _type, = struct.unpack(">sys.stderr, "BAD SHAPE FILE: expected Polygon or NullShape got", _type + print("BAD SHAPE FILE: expected Polygon or NullShape got", _type, file=sys.stderr) sys.exit(1) length = len(record) rec_length = 44 + num_parts * 4 + num_points * 16 - if rec_length <> length: - print>>sys.stderr, "BAD SHAPE FILE: expected", rec_length, "got", length + if rec_length != length: + print("BAD SHAPE FILE: expected", rec_length, "got", length, file=sys.stderr) sys.exit(1) if __name__ == "__main__" : if len(sys.argv) !=2: - print>>sys.stderr, "Usage:",sys.argv[0],"" + print("Usage:",sys.argv[0],"", file=sys.stderr) sys.exit(1) shx_filename = sys.argv[1][:-3]+"shx" @@ -80,15 +80,15 @@ if __name__ == "__main__" : version,_type,lox,loy,hix,hiy,_,_,_,_ = header[1].unpack_from(shp.read(72)) shp_bbox = [lox,loy,hix,hiy] - if shx_bbox <> shp_bbox : - print "BAD SHAPE FILE: bounding box mismatch in *.shp and *.shx", shp_bbox, shx_bbox + if shx_bbox != shp_bbox : + print("BAD SHAPE FILE: bounding box mismatch in *.shp and *.shx", shp_bbox, shx_bbox) sys.exit(1) - print "SHX FILE_LENGTH=",shx_file_length,"bytes" - print "SHP FILE_LENGTH=",shp_file_length,"bytes" + print("SHX FILE_LENGTH=",shx_file_length,"bytes") + print("SHP FILE_LENGTH=",shp_file_length,"bytes") - print "TYPE", ShapeType[_type] - print "BBOX(",lox,loy,hix,hiy,")" + print("TYPE", ShapeType[_type]) + print("BBOX(",lox,loy,hix,hiy,")") record_header = struct.Struct(">II") record = struct.Struct(">II") calc_total_size = 50 @@ -97,19 +97,19 @@ if __name__ == "__main__" : offset,shx_content_length = record.unpack_from(shx.read(8)) shp.seek(offset*2, os.SEEK_SET) record_number,content_length = record_header.unpack_from(shp.read(8)) - if shx_content_length <> content_length: - print "BAD SHAPE FILE: content_lenght mismatch in SHP and SHX",shx_content_length,content_length + if shx_content_length != content_length: + print("BAD SHAPE FILE: content_lenght mismatch in SHP and SHX",shx_content_length,content_length) sys.exit(1) ## test_record(_type, shp.read(2*content_length)) calc_total_size +=(4 + content_length) count+=1 - print "SHAPES COUNT=",count + print("SHAPES COUNT=",count) delta = shp_file_length-calc_total_size if delta > 0 : - print "BAD SHAPE FILE: extra ", 2*delta,"bytes" + print("BAD SHAPE FILE: extra ", 2*delta,"bytes") elif delta < 0: - print "BAD SHAPE FILE: missing ", 2*delta,"bytes" + print("BAD SHAPE FILE: missing ", 2*delta,"bytes") else: - print "SHAPE FILE LOOKS GOOD!" + print("SHAPE FILE LOOKS GOOD!")