Commit a0f105a3 authored by Thomas Holder's avatar Thomas Holder

extensions 2to3: // stdout.buffer sort(key)

parent ebb4c8eb
...@@ -49,7 +49,7 @@ class Code25i(Barcode): ...@@ -49,7 +49,7 @@ class Code25i(Barcode):
number = '0' + number number = '0' + number
# Number is encoded by pairs of 2 figures # Number is encoded by pairs of 2 figures
size = len(number) / 2 size = len(number) // 2
encoded = '1010' encoded = '1010'
for i in range(size): for i in range(size):
# First in the pair is encoded in black (1), second in white (0) # First in the pair is encoded in black (1), second in white (0)
......
...@@ -41,7 +41,7 @@ def process_file(filename): ...@@ -41,7 +41,7 @@ def process_file(filename):
while True: while True:
tag = f.read(1) tag = f.read(1)
if tag == '': if tag == b'':
break break
if ord(tag) > 128: if ord(tag) > 128:
......
...@@ -534,6 +534,7 @@ while line[0] and (line[1] != 'ENDSEC' or not inENTITIES): ...@@ -534,6 +534,7 @@ while line[0] and (line[1] != 'ENDSEC' or not inENTITIES):
if polylines: if polylines:
inkex.errormsg(_('%d ENTITIES of type POLYLINE encountered and ignored. Please try to convert to Release 13 format using QCad.') % polylines) inkex.errormsg(_('%d ENTITIES of type POLYLINE encountered and ignored. Please try to convert to Release 13 format using QCad.') % polylines)
doc.write(inkex.sys.stdout) out = sys.stdout if sys.version_info[0] < 3 else sys.stdout.buffer
doc.write(out)
# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99 # vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99
...@@ -101,7 +101,7 @@ class MyEffect(inkex.Effect): ...@@ -101,7 +101,7 @@ class MyEffect(inkex.Effect):
self.d = array([0], float) # knot vector self.d = array([0], float) # knot vector
self.poly = [[0.0,0.0]] # LWPOLYLINE data self.poly = [[0.0,0.0]] # LWPOLYLINE data
def output(self): def output(self):
print(''.join(self.dxf)) print(b''.join(self.dxf))
def dxf_add(self, str): def dxf_add(self, str):
self.dxf.append(str.encode(self.options.char_encode)) self.dxf.append(str.encode(self.options.char_encode))
def dxf_line(self,csp): def dxf_line(self,csp):
......
...@@ -1552,7 +1552,7 @@ def draw_pointer(x,color = "#f00", figure = "cross", group = None, comment = "", ...@@ -1552,7 +1552,7 @@ def draw_pointer(x,color = "#f00", figure = "cross", group = None, comment = "",
draw_text(text,x[0]+size*2.2,x[1]-size, group = group, font_size = font_size) draw_text(text,x[0]+size*2.2,x[1]-size, group = group, font_size = font_size)
if figure == "line" : if figure == "line" :
s = "" s = ""
for i in range(1,len(x)/2) : for i in range(1,len(x) // 2) :
s+= " %s, %s " %(x[i*2],x[i*2+1]) s+= " %s, %s " %(x[i*2],x[i*2+1])
attrib.update({"d": "M %s,%s L %s"%(x[0],x[1],s), "style":"fill:none;stroke:%s;stroke-width:%f;"%(color,width),"comment":str(comment)}) attrib.update({"d": "M %s,%s L %s"%(x[0],x[1],s), "style":"fill:none;stroke:%s;stroke-width:%f;"%(color,width),"comment":str(comment)})
inkex.etree.SubElement( group, inkex.addNS('path','svg'), attrib) inkex.etree.SubElement( group, inkex.addNS('path','svg'), attrib)
......
...@@ -273,7 +273,8 @@ class MyEffect(inkex.Effect): ...@@ -273,7 +273,8 @@ class MyEffect(inkex.Effect):
except: except:
pass pass
try: try:
sys.stdout.write(x.read()) stdout = sys.stdout if sys.version_info[0] < 3 else sys.stdout.buffer
stdout.write(x.read())
finally: finally:
x.close() x.close()
self.clear_tmp() self.clear_tmp()
......
...@@ -52,13 +52,6 @@ import simplestyle ...@@ -52,13 +52,6 @@ import simplestyle
locale.setlocale(locale.LC_ALL, '') locale.setlocale(locale.LC_ALL, '')
def float_sort(a, b):
'''
This is used to sort the horizontal and vertical guide positions,
which are floating point numbers, but which are held as text.
'''
return cmp(float(a), float(b))
class Guillotine(inkex.Effect): class Guillotine(inkex.Effect):
"""Exports slices made using guides""" """Exports slices made using guides"""
def __init__(self): def __init__(self):
...@@ -131,7 +124,7 @@ class Guillotine(inkex.Effect): ...@@ -131,7 +124,7 @@ class Guillotine(inkex.Effect):
if h >= 0 and float(h) <= float(height): if h >= 0 and float(h) <= float(height):
horizontals.append(h) horizontals.append(h)
horizontals.append(height) horizontals.append(height)
horizontals.sort(cmp=float_sort) horizontals.sort(key=float)
return horizontals return horizontals
def get_vertical_slice_positions(self): def get_vertical_slice_positions(self):
...@@ -147,7 +140,7 @@ class Guillotine(inkex.Effect): ...@@ -147,7 +140,7 @@ class Guillotine(inkex.Effect):
if v >= 0 and float(v) <= float(width): if v >= 0 and float(v) <= float(width):
verticals.append(v) verticals.append(v)
verticals.append(width) verticals.append(width)
verticals.sort(cmp=float_sort) verticals.sort(key=float)
return verticals return verticals
def get_slices(self): def get_slices(self):
......
...@@ -65,6 +65,7 @@ if 'UNKNOWN_COMMANDS' in warnings: ...@@ -65,6 +65,7 @@ if 'UNKNOWN_COMMANDS' in warnings:
inkex.errormsg(_("The HPGL data contained unknown (unsupported) commands, there is a possibility that the drawing is missing some content.")) inkex.errormsg(_("The HPGL data contained unknown (unsupported) commands, there is a possibility that the drawing is missing some content."))
# deliver document to inkscape # deliver document to inkscape
doc.write(inkex.sys.stdout) out = sys.stdout if sys.version_info[0] < 3 else sys.stdout.buffer
doc.write(out)
# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99 # vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99
...@@ -122,7 +122,8 @@ class MyEffect(inkex.Effect): ...@@ -122,7 +122,8 @@ class MyEffect(inkex.Effect):
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
# Output the file. # Output the file.
sys.stdout.write(out.read()) stdout = sys.stdout if sys.version_info[0] < 3 else sys.stdout.buffer
stdout.write(out.read())
sys.stdout.close() sys.stdout.close()
out.close() out.close()
......
...@@ -57,7 +57,7 @@ class JessyInk_Effects(inkex.Effect): ...@@ -57,7 +57,7 @@ class JessyInk_Effects(inkex.Effect):
inkex.errormsg(_("Could not obtain the selected layer for inclusion of the video element.\n\n")) inkex.errormsg(_("Could not obtain the selected layer for inclusion of the video element.\n\n"))
# Parse template file. # Parse template file.
tmplFile = open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'jessyInk_video.svg'), 'r') tmplFile = open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'jessyInk_video.svg'), 'rb')
tmplRoot = etree.fromstring(tmplFile.read()) tmplRoot = etree.fromstring(tmplFile.read())
tmplFile.close() tmplFile.close()
...@@ -83,7 +83,8 @@ class JessyInk_Effects(inkex.Effect): ...@@ -83,7 +83,8 @@ class JessyInk_Effects(inkex.Effect):
layer[0].append(elem) layer[0].append(elem)
def findInternalLinks(node, docRoot, nodeDict = {}): def findInternalLinks(node, docRoot, nodeDict = {}):
for entry in re.findall("url\(#.*\)", etree.tostring(node)): for entry in re.findall(b"url\(#.*\)", etree.tostring(node)):
entry = entry.decode()
linkId = entry[5:len(entry) - 1] linkId = entry[5:len(entry) - 1]
if linkId not in nodeDict: if linkId not in nodeDict:
......
...@@ -35,7 +35,9 @@ class NewGlyphLayer(inkex.Effect): ...@@ -35,7 +35,9 @@ class NewGlyphLayer(inkex.Effect):
def effect(self): def effect(self):
# Get all the options # Get all the options
unicode_chars = self.options.unicodechars.decode(self.encoding) unicode_chars = self.options.unicodechars
if sys.version_info[0] < 3:
unicode_chars = unicode_chars.decode(self.encoding)
#TODO: remove duplicate chars #TODO: remove duplicate chars
......
...@@ -267,7 +267,7 @@ def interleave( blocks, inter): ...@@ -267,7 +267,7 @@ def interleave( blocks, inter):
else: else:
result = [] result = []
for block in blocks: #for each codeword block in the stream for block in blocks: #for each codeword block in the stream
block_length = len(block)/inter #length of each interleaved block block_length = len(block) // inter #length of each interleaved block
inter_blocks = [[0] * block_length for i in xrange(inter)] #the interleaved blocks inter_blocks = [[0] * block_length for i in xrange(inter)] #the interleaved blocks
for i in range(block_length): #for each element in the interleaved blocks for i in range(block_length): #for each element in the interleaved blocks
...@@ -287,7 +287,7 @@ def combine_interleaved( blocks, inter, nd, nc, size144): ...@@ -287,7 +287,7 @@ def combine_interleaved( blocks, inter, nd, nc, size144):
return blocks return blocks
else: else:
result = [] result = []
for i in range( len(blocks) / inter ): #for each group of "inter" blocks -> one full datamatrix for i in range( len(blocks) // inter ): #for each group of "inter" blocks -> one full datamatrix
data_codewords = [] #interleaved data blocks data_codewords = [] #interleaved data blocks
if size144: if size144:
...@@ -298,10 +298,10 @@ def combine_interleaved( blocks, inter, nd, nc, size144): ...@@ -298,10 +298,10 @@ def combine_interleaved( blocks, inter, nd, nc, size144):
nc_range = nc*inter nc_range = nc*inter
for j in range(nd_range): #for each codeword in the final list for j in range(nd_range): #for each codeword in the final list
data_codewords.append( blocks[i*inter + j%inter][j/inter] ) data_codewords.append( blocks[i*inter + j%inter][j // inter] )
for j in range(nc_range): #for each block, add the ecc codewords for j in range(nc_range): #for each block, add the ecc codewords
data_codewords.append( blocks[i*inter + j%inter][nd + j/inter] ) data_codewords.append( blocks[i*inter + j%inter][nd + j // inter] )
result.append(data_codewords) result.append(data_codewords)
return result return result
...@@ -603,8 +603,8 @@ def add_finder_pattern( array, data_nrow, data_ncol, reg_row, reg_col ): ...@@ -603,8 +603,8 @@ def add_finder_pattern( array, data_nrow, data_ncol, reg_row, reg_col ):
for i in range( data_nrow*reg_row ): for i in range( data_nrow*reg_row ):
for j in range( data_ncol* reg_col ): for j in range( data_ncol* reg_col ):
dest_col = j + 1 + 2*(j/(data_ncol)) #offset by 1, plus two for every addition block dest_col = j + 1 + 2*(j // data_ncol) #offset by 1, plus two for every addition block
dest_row = i + 1 + 2*(i/(data_nrow)) dest_row = i + 1 + 2*(i // data_nrow)
datamatrix[dest_row][dest_col] = array[i][j] #transfer from the plain bit array datamatrix[dest_row][dest_col] = array[i][j] #transfer from the plain bit array
......
...@@ -977,7 +977,7 @@ class QRRSBlock: ...@@ -977,7 +977,7 @@ class QRRSBlock:
if rsBlock == None: if rsBlock == None:
raise Exception("bad rs block @ typeNumber:" + typeNumber + "/errorCorrectLevel:" + errorCorrectLevel) raise Exception("bad rs block @ typeNumber:" + typeNumber + "/errorCorrectLevel:" + errorCorrectLevel)
length = len(rsBlock) / 3 length = len(rsBlock) // 3
list = [] list = []
......
...@@ -77,7 +77,8 @@ def run(command_format, prog_name): ...@@ -77,7 +77,8 @@ def run(command_format, prog_name):
try: try:
f = open(svgfile, "rb") f = open(svgfile, "rb")
data = f.read() data = f.read()
sys.stdout.write(data) stdout = sys.stdout if sys.version_info[0] < 3 else sys.stdout.buffer
stdout.write(data)
f.close() f.close()
except IOError as inst: except IOError as inst:
msg = "Error reading temporary file: %s" % str(inst) msg = "Error reading temporary file: %s" % str(inst)
......
...@@ -55,9 +55,10 @@ class ScourInkscape (inkex.Effect): ...@@ -55,9 +55,10 @@ class ScourInkscape (inkex.Effect):
def effect(self): def effect(self):
try: try:
input = file(self.args[0], "r") input = open(self.args[0], "r")
self.options.infilename = self.args[0] self.options.infilename = self.args[0]
sys.stdout.write(scourString(input.read(), self.options).encode("UTF-8")) stdout = sys.stdout if sys.version_info[0] < 3 else sys.stdout.buffer
stdout.write(scourString(input.read(), self.options).encode("UTF-8"))
input.close() input.close()
sys.stdout.close() sys.stdout.close()
except Exception as e: except Exception as e:
......
...@@ -99,7 +99,8 @@ class CompressedMediaOutput(inkex.Effect): ...@@ -99,7 +99,8 @@ class CompressedMediaOutput(inkex.Effect):
msvcrt.setmode(1, os.O_BINARY) msvcrt.setmode(1, os.O_BINARY)
except: except:
pass pass
sys.stdout.write(out.read()) stdout = sys.stdout if sys.version_info[0] < 3 else sys.stdout.buffer
stdout.write(out.read())
out.close() out.close()
shutil.rmtree(self.tmp_dir) shutil.rmtree(self.tmp_dir)
......
...@@ -1072,7 +1072,8 @@ class SynfigExport(SynfigPrep): ...@@ -1072,7 +1072,8 @@ class SynfigExport(SynfigPrep):
for layer in layers: for layer in layers:
root_canvas.append(layer) root_canvas.append(layer)
d.get_root_tree().write(sys.stdout) out = sys.stdout if sys.version_info[0] < 3 else sys.stdout.buffer
d.get_root_tree().write(out)
def convert_node(self, node, d): def convert_node(self, node, d):
"""Convert an SVG node to a list of Synfig layers""" """Convert an SVG node to a list of Synfig layers"""
......
...@@ -25,10 +25,7 @@ import os ...@@ -25,10 +25,7 @@ import os
import sys import sys
import copy import copy
import tarfile import tarfile
if sys.version_info[0] < 3: import io
import StringIO
else:
import io as StringIO
import calendar import calendar
import time import time
...@@ -89,17 +86,18 @@ class LayersOutput(inkex.Effect): ...@@ -89,17 +86,18 @@ class LayersOutput(inkex.Effect):
return node.tag == GROUP and node.attrib.get(GROUPMODE,'').lower() == 'layer' return node.tag == GROUP and node.attrib.get(GROUPMODE,'').lower() == 'layer'
def io_document(self, name, doc): def io_document(self, name, doc):
string = StringIO.StringIO() string = io.BytesIO()
doc.write(string) doc.write(string)
string.seek(0)
info = tarfile.TarInfo(name=name+'.svg') info = tarfile.TarInfo(name=name+'.svg')
info.mtime = calendar.timegm(time.gmtime()) info.mtime = calendar.timegm(time.gmtime())
info.size = len(string.buf) info.size = string.tell()
string.seek(0)
return dict(tarinfo=info, fileobj=string) return dict(tarinfo=info, fileobj=string)
def effect(self): def effect(self):
# open output tar file as a stream (to stdout) # open output tar file as a stream (to stdout)
tar = tarfile.open(fileobj=sys.stdout, mode='w|') out = sys.stdout if sys.version_info[0] < 3 else sys.stdout.buffer
tar = tarfile.open(fileobj=out, mode='w|')
# Switch stdout to binary on Windows. # Switch stdout to binary on Windows.
if sys.platform == "win32": if sys.platform == "win32":
......
...@@ -74,7 +74,8 @@ def run(command_format, prog_name, uniconv_format): ...@@ -74,7 +74,8 @@ def run(command_format, prog_name, uniconv_format):
try: try:
f = open(outfile, "rb") f = open(outfile, "rb")
data = f.read() data = f.read()
sys.stdout.write(data) stdout = sys.stdout if sys.version_info[0] < 3 else sys.stdout.buffer
stdout.write(data)
f.close() f.close()
except IOError as inst: except IOError as inst:
msg = "Error reading temporary file: %s" % str(inst) msg = "Error reading temporary file: %s" % str(inst)
......
...@@ -149,7 +149,7 @@ class Wireframe_Sphere(inkex.Effect): ...@@ -149,7 +149,7 @@ class Wireframe_Sphere(inkex.Effect):
delta_long = 360.0/so.NUM_LONG #angle between neighbouring lines of longitude in degrees delta_long = 360.0/so.NUM_LONG #angle between neighbouring lines of longitude in degrees
for i in range(0,so.NUM_LONG/2): for i in range(0,so.NUM_LONG // 2):
long_angle = so.ROT_OFFSET + (i*delta_long)*(pi/180.0); #The longitude of this particular line in radians long_angle = so.ROT_OFFSET + (i*delta_long)*(pi/180.0); #The longitude of this particular line in radians
if long_angle > pi: if long_angle > pi:
long_angle -= 2*pi long_angle -= 2*pi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment