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):
number = '0' + number
# Number is encoded by pairs of 2 figures
size = len(number) / 2
size = len(number) // 2
encoded = '1010'
for i in range(size):
# First in the pair is encoded in black (1), second in white (0)
......
......@@ -41,7 +41,7 @@ def process_file(filename):
while True:
tag = f.read(1)
if tag == '':
if tag == b'':
break
if ord(tag) > 128:
......
......@@ -534,6 +534,7 @@ while line[0] and (line[1] != 'ENDSEC' or not inENTITIES):
if 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
......@@ -101,7 +101,7 @@ class MyEffect(inkex.Effect):
self.d = array([0], float) # knot vector
self.poly = [[0.0,0.0]] # LWPOLYLINE data
def output(self):
print(''.join(self.dxf))
print(b''.join(self.dxf))
def dxf_add(self, str):
self.dxf.append(str.encode(self.options.char_encode))
def dxf_line(self,csp):
......
......@@ -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)
if figure == "line" :
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])
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)
......
......@@ -273,7 +273,8 @@ class MyEffect(inkex.Effect):
except:
pass
try:
sys.stdout.write(x.read())
stdout = sys.stdout if sys.version_info[0] < 3 else sys.stdout.buffer
stdout.write(x.read())
finally:
x.close()
self.clear_tmp()
......
......@@ -52,13 +52,6 @@ import simplestyle
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):
"""Exports slices made using guides"""
def __init__(self):
......@@ -131,7 +124,7 @@ class Guillotine(inkex.Effect):
if h >= 0 and float(h) <= float(height):
horizontals.append(h)
horizontals.append(height)
horizontals.sort(cmp=float_sort)
horizontals.sort(key=float)
return horizontals
def get_vertical_slice_positions(self):
......@@ -147,7 +140,7 @@ class Guillotine(inkex.Effect):
if v >= 0 and float(v) <= float(width):
verticals.append(v)
verticals.append(width)
verticals.sort(cmp=float_sort)
verticals.sort(key=float)
return verticals
def get_slices(self):
......
......@@ -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."))
# 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
......@@ -122,7 +122,8 @@ class MyEffect(inkex.Effect):
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
# 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()
out.close()
......
......@@ -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"))
# 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())
tmplFile.close()
......@@ -83,7 +83,8 @@ class JessyInk_Effects(inkex.Effect):
layer[0].append(elem)
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]
if linkId not in nodeDict:
......
......@@ -35,7 +35,9 @@ class NewGlyphLayer(inkex.Effect):
def effect(self):
# 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
......
......@@ -267,7 +267,7 @@ def interleave( blocks, inter):
else:
result = []
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
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):
return blocks
else:
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
if size144:
......@@ -298,10 +298,10 @@ def combine_interleaved( blocks, inter, nd, nc, size144):
nc_range = nc*inter
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
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)
return result
......@@ -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 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_row = i + 1 + 2*(i/(data_nrow))
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)
datamatrix[dest_row][dest_col] = array[i][j] #transfer from the plain bit array
......
......@@ -977,7 +977,7 @@ class QRRSBlock:
if rsBlock == None:
raise Exception("bad rs block @ typeNumber:" + typeNumber + "/errorCorrectLevel:" + errorCorrectLevel)
length = len(rsBlock) / 3
length = len(rsBlock) // 3
list = []
......
......@@ -77,7 +77,8 @@ def run(command_format, prog_name):
try:
f = open(svgfile, "rb")
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()
except IOError as inst:
msg = "Error reading temporary file: %s" % str(inst)
......
......@@ -55,9 +55,10 @@ class ScourInkscape (inkex.Effect):
def effect(self):
try:
input = file(self.args[0], "r")
input = open(self.args[0], "r")
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()
sys.stdout.close()
except Exception as e:
......
......@@ -99,7 +99,8 @@ class CompressedMediaOutput(inkex.Effect):
msvcrt.setmode(1, os.O_BINARY)
except:
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()
shutil.rmtree(self.tmp_dir)
......
......@@ -1072,7 +1072,8 @@ class SynfigExport(SynfigPrep):
for layer in layers:
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):
"""Convert an SVG node to a list of Synfig layers"""
......
......@@ -25,10 +25,7 @@ import os
import sys
import copy
import tarfile
if sys.version_info[0] < 3:
import StringIO
else:
import io as StringIO
import io
import calendar
import time
......@@ -89,17 +86,18 @@ class LayersOutput(inkex.Effect):
return node.tag == GROUP and node.attrib.get(GROUPMODE,'').lower() == 'layer'
def io_document(self, name, doc):
string = StringIO.StringIO()
string = io.BytesIO()
doc.write(string)
string.seek(0)
info = tarfile.TarInfo(name=name+'.svg')
info.mtime = calendar.timegm(time.gmtime())
info.size = len(string.buf)
info.size = string.tell()
string.seek(0)
return dict(tarinfo=info, fileobj=string)
def effect(self):
# 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.
if sys.platform == "win32":
......
......@@ -74,7 +74,8 @@ def run(command_format, prog_name, uniconv_format):
try:
f = open(outfile, "rb")
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()
except IOError as inst:
msg = "Error reading temporary file: %s" % str(inst)
......
......@@ -149,7 +149,7 @@ class Wireframe_Sphere(inkex.Effect):
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
if long_angle > 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