[libgda/LIBGDA_5.2] libgda-report: Code ported to Python3
- From: Daniel Espinosa Ortiz <despinosa src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda/LIBGDA_5.2] libgda-report: Code ported to Python3
- Date: Tue, 7 Jan 2020 14:56:13 +0000 (UTC)
commit bb2e1f3867d360d510437a42cc0a6b8ca1b8dc6c
Author: Pavlo Solntsev <p sun fun gmail com>
Date: Sat Nov 2 16:35:03 2019 -0500
libgda-report: Code ported to Python3
libgda-report/RML/trml2html/trml2html.py | 22 +++++++++++-----------
libgda-report/RML/trml2pdf/__init__.py | 2 +-
libgda-report/RML/trml2pdf/color.py | 2 +-
libgda-report/RML/trml2pdf/trml2pdf.py | 28 ++++++++++++++--------------
4 files changed, 27 insertions(+), 27 deletions(-)
---
diff --git a/libgda-report/RML/trml2html/trml2html.py b/libgda-report/RML/trml2html/trml2html.py
index 4c449616f..778d2e1e0 100644
--- a/libgda-report/RML/trml2html/trml2html.py
+++ b/libgda-report/RML/trml2html/trml2html.py
@@ -19,11 +19,11 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import sys
-import StringIO
+import io
import xml.dom.minidom
import copy
-import utils
+from . import utils
class _flowable(object):
def __init__(self, template, doc):
@@ -62,7 +62,7 @@ class _flowable(object):
def _tag_table(self, node):
node.tagName='table'
if node.hasAttribute('colWidths'):
- sizes = map(lambda x: utils.unit_get(x), node.getAttribute('colWidths').split(','))
+ sizes = [utils.unit_get(x) for x in node.getAttribute('colWidths').split(',')]
tr = self.doc.createElement('tr')
for s in sizes:
td = self.doc.createElement('td')
@@ -212,7 +212,7 @@ class _rml_draw_style(object):
def get(self,tag):
if not tag in self.style:
return ""
- return ';'.join(['%s:%s' % (x[0],x[1]) for x in self.style[tag].items()])
+ return ';'.join(['%s:%s' % (x[0],x[1]) for x in list(self.style[tag].items())])
class _rml_template(object):
def __init__(self, template):
@@ -244,7 +244,7 @@ class _rml_template(object):
frames[(t.posy,t.posx,n.localName)] = t
else:
self.style.update(n)
- keys = frames.keys()
+ keys = list(frames.keys())
keys.sort()
keys.reverse()
self.page_template[id] = []
@@ -338,20 +338,20 @@ def parseString(data, fout=None):
fp.close()
return fout
else:
- fp = StringIO.StringIO()
+ fp = io.StringIO()
r.render(fp)
return fp.getvalue()
def trml2pdf_help():
- print 'Usage: trml2pdf input.rml >output.html'
- print 'Render the standard input (RML) and output a PDF file'
+ print('Usage: trml2pdf input.rml >output.html')
+ print('Render the standard input (RML) and output a PDF file')
sys.exit(0)
if __name__=="__main__":
if len(sys.argv)>1:
if sys.argv[1]=='--help':
trml2pdf_help()
- print parseString(file(sys.argv[1], 'r').read()),
+ print(parseString(file(sys.argv[1], 'r').read()), end=' ')
else:
- print 'Usage: trml2pdf input.rml >output.pdf'
- print 'Try \'trml2pdf --help\' for more information.'
+ print('Usage: trml2pdf input.rml >output.pdf')
+ print('Try \'trml2pdf --help\' for more information.')
diff --git a/libgda-report/RML/trml2pdf/__init__.py b/libgda-report/RML/trml2pdf/__init__.py
index 5f4754597..5301b96ad 100644
--- a/libgda-report/RML/trml2pdf/__init__.py
+++ b/libgda-report/RML/trml2pdf/__init__.py
@@ -15,4 +15,4 @@
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-from trml2pdf import parseString
+from .trml2pdf import parseString
diff --git a/libgda-report/RML/trml2pdf/color.py b/libgda-report/RML/trml2pdf/color.py
index 841701c9c..2123212c8 100644
--- a/libgda-report/RML/trml2pdf/color.py
+++ b/libgda-report/RML/trml2pdf/color.py
@@ -25,7 +25,7 @@ regex_h = re.compile('#([0-9a-zA-Z][0-9a-zA-Z])([0-9a-zA-Z][0-9a-zA-Z])([0-9a-zA
def get(col_str):
global allcols
- if col_str in allcols.keys():
+ if col_str in list(allcols.keys()):
return allcols[col_str]
res = regex_t.search(col_str, 0)
if res:
diff --git a/libgda-report/RML/trml2pdf/trml2pdf.py b/libgda-report/RML/trml2pdf/trml2pdf.py
index 6067752eb..07a3781e8 100644
--- a/libgda-report/RML/trml2pdf/trml2pdf.py
+++ b/libgda-report/RML/trml2pdf/trml2pdf.py
@@ -21,7 +21,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import sys
-import StringIO
+import io
import xml.dom.minidom
import copy
@@ -29,8 +29,8 @@ import reportlab
from reportlab.pdfgen import canvas
from reportlab import platypus
-import utils
-import color
+from . import utils
+from . import color
#
# Change this to UTF-8 if you plan tu use Reportlab's UTF-8 support
@@ -250,7 +250,7 @@ class _rml_canvas(object):
flow.drawOn(self.canvas,infos['x'],infos['y'])
infos['height']-=h
else:
- raise ValueError, "Not enough space"
+ raise ValueError("Not enough space")
def _line_mode(self, node):
ljoin = {'round':1, 'mitered':0, 'bevelled':2}
@@ -270,10 +270,10 @@ class _rml_canvas(object):
self.canvas.setDash(node.getAttribute('dash').split(','))
def _image(self, node):
- import urllib
+ import urllib.request, urllib.parse, urllib.error
from reportlab.lib.utils import ImageReader
- u = urllib.urlopen(str(node.getAttribute('file')))
- s = StringIO.StringIO()
+ u = urllib.request.urlopen(str(node.getAttribute('file')))
+ s = io.StringIO()
s.write(u.read())
s.seek(0)
img = ImageReader(s)
@@ -501,7 +501,7 @@ class _rml_template(object):
if not node.hasAttribute('pageSize'):
pageSize = (utils.unit_get('21cm'), utils.unit_get('29.7cm'))
else:
- ps = map(lambda x:x.strip(), node.getAttribute('pageSize').replace(')',
'').replace('(', '').split(','))
+ ps = [x.strip() for x in node.getAttribute('pageSize').replace(')', '').replace('(',
'').split(',')]
pageSize = ( utils.unit_get(ps[0]),utils.unit_get(ps[1]) )
cm = reportlab.lib.units.cm
self.doc_tmpl = platypus.BaseDocTemplate(out, pagesize=pageSize, **utils.attr_get(node,
['leftMargin','rightMargin','topMargin','bottomMargin'],
{'allowSplitting':'int','showBoundary':'bool','title':'str','author':'str'}))
@@ -535,20 +535,20 @@ def parseString(data, fout=None):
fp.close()
return fout
else:
- fp = StringIO.StringIO()
+ fp = io.StringIO()
r.render(fp)
return fp.getvalue()
def trml2pdf_help():
- print 'Usage: trml2pdf input.rml >output.pdf'
- print 'Render the standard input (RML) and output a PDF file'
+ print('Usage: trml2pdf input.rml >output.pdf')
+ print('Render the standard input (RML) and output a PDF file')
sys.exit(0)
if __name__=="__main__":
if len(sys.argv)>1:
if sys.argv[1]=='--help':
trml2pdf_help()
- print parseString(file(sys.argv[1], 'r').read()),
+ print(parseString(file(sys.argv[1], 'r').read()), end=' ')
else:
- print 'Usage: trml2pdf input.rml >output.pdf'
- print 'Try \'trml2pdf --help\' for more information.'
+ print('Usage: trml2pdf input.rml >output.pdf')
+ print('Try \'trml2pdf --help\' for more information.')
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]