summaryrefslogtreecommitdiffstats
path: root/kexi/plugins/scripting/scripts/importxhtml/ImportXHTML.py
diff options
context:
space:
mode:
Diffstat (limited to 'kexi/plugins/scripting/scripts/importxhtml/ImportXHTML.py')
-rwxr-xr-xkexi/plugins/scripting/scripts/importxhtml/ImportXHTML.py36
1 files changed, 18 insertions, 18 deletions
diff --git a/kexi/plugins/scripting/scripts/importxhtml/ImportXHTML.py b/kexi/plugins/scripting/scripts/importxhtml/ImportXHTML.py
index 200b3dee6..03a6772a8 100755
--- a/kexi/plugins/scripting/scripts/importxhtml/ImportXHTML.py
+++ b/kexi/plugins/scripting/scripts/importxhtml/ImportXHTML.py
@@ -28,7 +28,7 @@ class SaxInput:
import xml.sax.saxlib
import xml.sax.saxexts
except:
- raise "Import of the python xml.sax.saxlib module failed. This module is needed by the ImportXHTML python script."
+ raise Exception("Import of the python xml.sax.saxlib module failed. This module is needed by the ImportXHTML python script.")
def read(self, outputwriter):
""" Start reading and parsing the XML-file. """
@@ -83,7 +83,7 @@ class SaxInput:
# Print some debugging-output to stdout.
for idx in range(self.level): sys.stdout.write(' ')
sys.stdout.write('Element: %s' % name)
- for attrName in attrs.keys():
+ for attrName in list(attrs.keys()):
sys.stdout.write(' %s="%s"' % (attrName,attrs.get(attrName)))
sys.stdout.write('\n')
@@ -110,12 +110,12 @@ class SaxInput:
self.field = None
elif name == "td" and (self.level == len(self.tablebase) + 1):
#if self.field == None:
- # raise "Unexpected closing </td>"
+ # raise Exception("Unexpected closing </td>")
self.record.setField( self.field )
self.field = None
elif name == "th" and (self.level == len(self.tablebase) + 1):
#if self.field == None:
- # raise "Unexpected closing </td>"
+ # raise Exceptin("Unexpected closing </td>")
self.record.setHeader( self.field )
self.field = None
@@ -126,7 +126,7 @@ class SaxInput:
if self.field != None:
# the xml-data is unicode and we need to encode it
# to latin-1 cause KexiDB deals only with latin-1.
- u = unicode(chars[offset:offset+length])
+ u = str(chars[offset:offset+length])
self.field.append(u.encode("latin-1"))
# start the job
@@ -163,14 +163,14 @@ class KexiDBOutput:
def success(self, record):
""" Called if a record was written successfully. """
- print "SUCCESS: %s" % str(record)
+ print("SUCCESS: %s" % str(record))
self.successcount += 1
if hasattr(self.outputwriter,"logfile"):
self.addLog(record, "Success")
def failed(self, record):
""" Called if we failed to write a record. """
- print "FAILED: %s" % str(record)
+ print("FAILED: %s" % str(record))
self.failedcount += 1
if hasattr(self.outputwriter,"logfile"):
self.addLog(record, "Failed")
@@ -207,7 +207,7 @@ class KexiDBOutput:
try:
self.connection = keximainwindow.getConnection()
except:
- raise "No connection established. Please open a project before."
+ raise Exception("No connection established. Please open a project before.")
self.fieldlist = None
self.headerrecord = None
@@ -215,9 +215,9 @@ class KexiDBOutput:
def begin(self):
""" Called before parsing starts. """
- print "START JOB"
+ print("START JOB")
if self.fieldlist == None:
- raise "Invalid tableschema or fieldlist!"
+ raise Exceptin("Invalid tableschema or fieldlist!")
global KexiDBOutput
self.result = KexiDBOutput.Result(self)
if hasattr(self,"logfilename") and self.logfilename != None and self.logfilename != "":
@@ -225,7 +225,7 @@ class KexiDBOutput:
def end(self):
""" Called if parsing is fineshed. """
- print "END JOB"
+ print("END JOB")
self.logfile = None
self.mapping = {}
#self.headerrecord = None
@@ -240,12 +240,12 @@ class KexiDBOutput:
""" Set the tablename we like to import the data to. """
tableschema = self.connection.tableSchema(tablename)
if tableschema == None:
- raise "There exists no table with the name '%s'!" % tablename
+ raise Exceptin("There exists no table with the name '%s'!" % tablename)
self.fieldlist = tableschema.fieldlist()
fields = self.fieldlist.fields()
for field in fields:
- print "KexiDBOutput.setTable(%s): %s(%s)" % (tablename,field.name(),field.type())
- print "names=%s" % self.fieldlist.names()
+ print("KexiDBOutput.setTable(%s): %s(%s)" % (tablename,field.name(),field.type()))
+ print("names=%s" % self.fieldlist.names())
def setMapping(self, mapping):
""" Set the tablefieldname=xmlcolnr dictonary we should map the data to. """
@@ -277,7 +277,7 @@ class KexiDBOutput:
values = []
for k in self.fieldlist.names():
values.append( str(record.fields[ int(self.mapping[k]) ]) )
- print "Import values: %s" % values
+ print("Import values: %s" % values)
try:
if self.connection.insertRecord(self.fieldlist, values):
@@ -343,7 +343,7 @@ class GuiApp:
msgbox.show()
self.doCancel()
- except RuntimeError, e:
+ except RuntimeError as e:
pass
#except Exception, e:
# import traceback
@@ -392,7 +392,7 @@ class GuiApp:
i += 1
if not field.isAutoInc():
l.set(i)
- except ValueError, e:
+ except ValueError as e:
if not field.type() in ("Integer","BigInteger","ShortInteger","Float","Double"):
i += 1
l.set(i)
@@ -411,7 +411,7 @@ class GuiApp:
fieldname = field.name()
colnr = str( l.get() ).split(":",1)[0]
if colnr.isdigit():
- print "Table field '%s' is mapped to XML column '%s'" % (fieldname,colnr)
+ print("Table field '%s' is mapped to XML column '%s'" % (fieldname,colnr))
mapping[ fieldname ] = colnr
self.outputwriter.setMapping(mapping)
self.ok = True