[Python-modules-commits] [python-odf] 04/04: modified libraries and utilities so they can be used with both Python2 and Python3.
Georges Khaznadar
georgesk at moszumanska.debian.org
Thu Oct 30 14:40:08 UTC 2014
This is an automated email from the git hooks/post-receive script.
georgesk pushed a commit to branch master
in repository python-odf.
commit cec86d988da7b37c20237bae27865624870284fe
Author: georgesk <georgesk at debian.org>
Date: Thu Oct 30 15:43:14 2014 +0100
modified libraries and utilities so they can be used with both Python2 and Python3.
---
csv2ods/Makefile | 10 +-
csv2ods/csv2ods | 330 ++--
debian/changelog | 46 +
debian/compat | 2 +-
debian/control | 45 +-
debian/examples | 1 -
debian/patches/libsToPython3.patch | 2250 ++++++++++++++++++++++++
debian/patches/series | 3 +
debian/patches/toPython3.patch | 2523 +++++++++++++++++++++++++++
debian/patches/util-test-and-dev-doc.patch | 2557 ++++++++++++++++++++++++++++
debian/python-odf-doc.install | 3 +
debian/python-odf-tools.install | 2 +
debian/python-odf.install | 1 +
debian/python3-odf.install | 1 +
debian/rules | 29 +-
debian/source/include-binaries | 3 +
mailodf/Makefile | 9 +-
mailodf/mailodf | 23 +-
odf/attrconverters.py | 76 +-
odf/chart.py | 6 +-
odf/dr3d.py | 2 +
odf/draw.py | 8 +-
odf/easyliststyle.py | 3 +-
odf/element.py | 88 +-
odf/grammar.py | 3 +-
odf/load.py | 9 +-
odf/manifest.py | 3 +
odf/odf2xhtml.py | 93 +-
odf/odfmanifest.py | 11 +-
odf/opendocument.py | 745 +++++---
odf/style.py | 2 +-
odf/text.py | 3 +
odf/userfield.py | 85 +-
odf2mht/Makefile | 8 +-
odf2mht/odf2mht | 24 +-
odf2xhtml/Makefile | 11 +-
odf2xhtml/odf2xhtml | 19 +-
odf2xml/Makefile | 8 +-
odf2xml/odf2xml | 15 +-
odfimgimport/Makefile | 10 +-
odfimgimport/odfimgimport | 62 +-
odflint/Makefile | 8 +-
odflint/odflint | 27 +-
odfmeta/Makefile | 8 +-
odfmeta/odfmeta | 29 +-
odfoutline/Makefile | 8 +-
odfoutline/odfoutline | 18 +-
odfuserfield/Makefile | 27 +-
odfuserfield/odfuserfield | 25 +-
tests/runtests | 3 +-
tests/testconverters.py | 22 +-
tests/testdatastyles.py | 18 +-
tests/testeasyliststyle.py | 10 +-
tests/testform.py | 4 +-
tests/testload.py | 44 +-
tests/testmasterstyles.py | 18 +-
tests/testmoinmoin.py | 56 +-
tests/teststyles.py | 56 +-
tests/testsubobjects.py | 68 +-
tests/testtext.py | 15 +-
tests/testtypes.py | 4 +-
tests/testunicode.py | 29 +-
tests/testuserfields.py | 122 +-
tests/testwhitespace.py | 30 +-
tests/testwrite.py | 4 +-
tests/testxhtml.py | 149 +-
tests/testxmlgen.py | 28 +-
xml2odf/Makefile | 10 +-
xml2odf/xml2odf | 26 +-
69 files changed, 9104 insertions(+), 894 deletions(-)
diff --git a/csv2ods/Makefile b/csv2ods/Makefile
index d5700f1..ac69d78 100644
--- a/csv2ods/Makefile
+++ b/csv2ods/Makefile
@@ -9,6 +9,14 @@ txt: csv2ods.txt
xmlto txt $<
clean:
- rm -f *.txt odf
+ rm -f *.1 *~ *.txt odf test.csv test2.ods test3.ods
odf:
ln -s ../odf
+
+test: clean odf
+ @echo 1,2,3,4 > test.csv
+ @echo 5,6,7,8 >> test.csv
+ @echo 9,10,11,12 >> test.csv
+ @python2 csv2ods -i test.csv -o test2.ods
+ @python3 csv2ods -i test.csv -o test3.ods
+ @echo created files test.csv, test2.ods and test3.ods
diff --git a/csv2ods/csv2ods b/csv2ods/csv2ods
index c4d7c6f..62e392c 100755
--- a/csv2ods/csv2ods
+++ b/csv2ods/csv2ods
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2008 Agustin Henze -> agustinhenze at gmail.com
#
@@ -16,136 +16,214 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Contributor(s):
+#
# Søren Roug
+#
+# Oct 2014: Georges Khaznadar <georgesk at debian.org>
+# - ported to Python3
+# - imlemented the missing switch -c / --encoding, with an extra
+# feature for POSIX platforms which can guess encoding.
from odf.opendocument import OpenDocumentSpreadsheet
from odf.style import Style, TextProperties, ParagraphProperties, TableColumnProperties
from odf.text import P
from odf.table import Table, TableColumn, TableRow, TableCell
from optparse import OptionParser
-import sys,csv,re
-
-PWENC = "utf-8"
-
-def csvToOds( pathFileCSV, pathFileODS, tableName='table', delimiter=',', quoting=csv.QUOTE_MINIMAL, quotechar = '"',
- escapechar = None, skipinitialspace = False, lineterminator = '\r\n'):
- textdoc = OpenDocumentSpreadsheet()
- # Create a style for the table content. One we can modify
- # later in the word processor.
- tablecontents = Style(name="Table Contents", family="paragraph")
- tablecontents.addElement(ParagraphProperties(numberlines="false", linenumber="0"))
- tablecontents.addElement(TextProperties(fontweight="bold"))
- textdoc.styles.addElement(tablecontents)
-
- # Start the table
- table = Table( name=tableName )
-
- reader = csv.reader(open(pathFileCSV), delimiter=delimiter,
- quoting=quoting, quotechar=quotechar, escapechar=escapechar,
- skipinitialspace=skipinitialspace, lineterminator=lineterminator)
- fltExp = re.compile('^\s*[-+]?\d+(\.\d+)?\s*$')
-
- for row in reader:
- tr = TableRow()
- table.addElement(tr)
- for val in row:
- if fltExp.match(val):
- tc = TableCell(valuetype="float", value=val.strip())
- else:
- tc = TableCell(valuetype="string")
- tr.addElement(tc)
- p = P(stylename=tablecontents,text=unicode(val,PWENC))
- tc.addElement(p)
-
- textdoc.spreadsheet.addElement(table)
- textdoc.save( pathFileODS )
-
+import sys,csv,re, os, codecs
+
+if sys.version_info.major==3: unicode=str
+
+if sys.version_info.major==2:
+ class UTF8Recoder:
+ """
+ Iterator that reads an encoded stream and reencodes the input to UTF-8
+ """
+ def __init__(self, f, encoding):
+ self.reader = codecs.getreader(encoding)(f)
+
+ def __iter__(self):
+ return self
+
+ def next(self):
+ return self.reader.next().encode("utf-8")
+
+ class UnicodeReader:
+ """
+ A CSV reader which will iterate over lines in the CSV file "f",
+ which is encoded in the given encoding.
+ """
+
+ def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
+ f = UTF8Recoder(f, encoding)
+ self.reader = csv.reader(f, dialect=dialect, **kwds)
+
+ def next(self):
+ row = self.reader.next()
+ return [unicode(s, "utf-8") for s in row]
+
+ def __iter__(self):
+ return self
+
+
+def csvToOds( pathFileCSV, pathFileODS, tableName='table',
+ delimiter=',', quoting=csv.QUOTE_MINIMAL,
+ quotechar = '"', escapechar = None,
+ skipinitialspace = False, lineterminator = '\r\n',
+ encoding="utf-8"):
+ textdoc = OpenDocumentSpreadsheet()
+ # Create a style for the table content. One we can modify
+ # later in the word processor.
+ tablecontents = Style(name="Table Contents", family="paragraph")
+ tablecontents.addElement(ParagraphProperties(numberlines="false", linenumber="0"))
+ tablecontents.addElement(TextProperties(fontweight="bold"))
+ textdoc.styles.addElement(tablecontents)
+
+ # Start the table
+ table = Table( name=tableName )
+
+ if sys.version_info.major==3:
+ reader = csv.reader(open(pathFileCSV, encoding=encoding),
+ delimiter=delimiter,
+ quoting=quoting,
+ quotechar=quotechar,
+ escapechar=escapechar,
+ skipinitialspace=skipinitialspace,
+ lineterminator=lineterminator)
+ else:
+ reader = UnicodeReader(open(pathFileCSV),
+ encoding=encoding,
+ delimiter=delimiter,
+ quoting=quoting,
+ quotechar=quotechar,
+ escapechar=escapechar,
+ skipinitialspace=skipinitialspace,
+ lineterminator=lineterminator)
+ fltExp = re.compile('^\s*[-+]?\d+(\.\d+)?\s*$')
+
+ for row in reader:
+ tr = TableRow()
+ table.addElement(tr)
+ for val in row:
+ if fltExp.match(val):
+ tc = TableCell(valuetype="float", value=val.strip())
+ else:
+ tc = TableCell(valuetype="string")
+ tr.addElement(tc)
+ p = P(stylename=tablecontents,text=val)
+ tc.addElement(p)
+
+ textdoc.spreadsheet.addElement(table)
+ textdoc.save( pathFileODS )
+
if __name__ == "__main__":
- usage = "%prog -i file.csv -o file.ods -d"
- parser = OptionParser(usage=usage, version="%prog 0.1")
- parser.add_option('-i','--input', action='store',
- dest='input', help='File input in csv')
- parser.add_option('-o','--output', action='store',
- dest='output', help='File output in ods')
- parser.add_option('-d','--delimiter', action='store',
- dest='delimiter', help='specifies a one-character string to use as the field separator. It defaults to ",".')
-
- parser.add_option('-c','--encoding', action='store',
- dest='encoding', help='specifies the encoding the file csv. It defaults to utf-8')
-
- parser.add_option('-t','--table', action='store',
- dest='tableName', help='The table name in the output file')
-
- parser.add_option('-s','--skipinitialspace',
- dest='skipinitialspace', help='''specifies how to interpret whitespace which
- immediately follows a delimiter. It defaults to False, which
- means that whitespace immediately following a delimiter is part
- of the following field.''')
-
- parser.add_option('-l','--lineterminator', action='store',
- dest='lineterminator', help='''specifies the character sequence which should
- terminate rows.''')
-
- parser.add_option('-q','--quoting', action='store',
- dest='quoting', help='''It can take on any of the following module constants:
- 0 = QUOTE_MINIMAL means only when required, for example, when a field contains either the quotechar or the delimiter
- 1 = QUOTE_ALL means that quotes are always placed around fields.
- 2 = QUOTE_NONNUMERIC means that quotes are always placed around fields which do not parse as integers or floating point numbers.
- 3 = QUOTE_NONE means that quotes are never placed around fields.
- It defaults is QUOTE_MINIMAL''')
-
- parser.add_option('-e','--escapechar', action='store',
- dest='escapechar', help='''specifies a one-character string used to escape the delimiter when quoting is set to QUOTE_NONE.''')
-
- parser.add_option('-r','--quotechar', action='store',
- dest='quotechar', help='''specifies a one-character string to use as the quoting character. It defaults to ".''')
-
- (options, args) = parser.parse_args()
-
- if options.input:
- pathFileCSV = options.input
- else:
- parser.print_help()
- exit( 0 )
-
- if options.output:
- pathFileODS = options.output
- else:
- parser.print_help()
- exit( 0 )
-
- if options.delimiter:
- delimiter = options.delimiter
- else:
- delimiter = ","
-
- if options.skipinitialspace:
- skipinitialspace = True
- else:
- skipinitialspace=False
-
- if options.lineterminator:
- lineterminator = options.lineterminator
- else:
- lineterminator ="\r\n"
-
- if options.escapechar:
- escapechar = options.escapechar
- else:
- escapechar=None
-
- if options.encoding:
- PWENC = options.encoding
-
- if options.tableName:
- tableName = options.tableName
- else:
- tableName = "table"
-
- if options.quotechar:
- quotechar = options.quotechar
- else:
- quotechar = "\""
-
- csvToOds( pathFileCSV=pathFileCSV, pathFileODS=pathFileODS, delimiter=delimiter, skipinitialspace=skipinitialspace,
- escapechar=escapechar, lineterminator=lineterminator, tableName=tableName, quotechar=quotechar)
+ usage = "%prog -i file.csv -o file.ods -d"
+ parser = OptionParser(usage=usage, version="%prog 0.1")
+ parser.add_option('-i','--input', action='store',
+ dest='input', help='File input in csv')
+ parser.add_option('-o','--output', action='store',
+ dest='output', help='File output in ods')
+ parser.add_option('-d','--delimiter', action='store',
+ dest='delimiter', help='specifies a one-character string to use as the field separator. It defaults to ",".')
+
+ parser.add_option('-c','--encoding', action='store',
+ dest='encoding', help='specifies the encoding the file csv. It defaults to utf-8')
+
+ parser.add_option('-t','--table', action='store',
+ dest='tableName', help='The table name in the output file')
+
+ parser.add_option('-s','--skipinitialspace',
+ dest='skipinitialspace', help='''specifies how to interpret whitespace which
+ immediately follows a delimiter. It defaults to False, which
+ means that whitespace immediately following a delimiter is part
+ of the following field.''')
+
+ parser.add_option('-l','--lineterminator', action='store',
+ dest='lineterminator', help='''specifies the character sequence which should
+ terminate rows.''')
+
+ parser.add_option('-q','--quoting', action='store',
+ dest='quoting', help='''It can take on any of the following module constants:
+ 0 = QUOTE_MINIMAL means only when required, for example, when a field contains either the quotechar or the delimiter
+ 1 = QUOTE_ALL means that quotes are always placed around fields.
+ 2 = QUOTE_NONNUMERIC means that quotes are always placed around fields which do not parse as integers or floating point numbers.
+ 3 = QUOTE_NONE means that quotes are never placed around fields.
+ It defaults is QUOTE_MINIMAL''')
+
+ parser.add_option('-e','--escapechar', action='store',
+ dest='escapechar', help='''specifies a one-character string used to escape the delimiter when quoting is set to QUOTE_NONE.''')
+
+ parser.add_option('-r','--quotechar', action='store',
+ dest='quotechar', help='''specifies a one-character string to use as the quoting character. It defaults to ".''')
+
+ (options, args) = parser.parse_args()
+
+ if options.input:
+ pathFileCSV = options.input
+ else:
+ parser.print_help()
+ exit( 0 )
+
+ if options.output:
+ pathFileODS = options.output
+ else:
+ parser.print_help()
+ exit( 0 )
+
+ if options.delimiter:
+ delimiter = options.delimiter
+ else:
+ delimiter = ","
+
+ if options.skipinitialspace:
+ skipinitialspace = True
+ else:
+ skipinitialspace=False
+
+ if options.lineterminator:
+ lineterminator = options.lineterminator
+ else:
+ lineterminator ="\r\n"
+
+ if options.escapechar:
+ escapechar = options.escapechar
+ else:
+ escapechar=None
+
+ if options.tableName:
+ tableName = options.tableName
+ else:
+ tableName = "table"
+
+ if options.quotechar:
+ quotechar = options.quotechar
+ else:
+ quotechar = "\""
+
+ encoding = "utf-8" # default setting
+ ###########################################################
+ ## try to guess the encoding; this is implemented only with
+ ## POSIX platforms. Can it be improved?
+ output = os.popen('/usr/bin/file ' + pathFileCSV).read()
+ m=re.match(r'^.*: ([-a-zA-Z0-9]+) text$', output)
+ if m:
+ encoding=m.group(1)
+ if 'ISO-8859' in encoding:
+ encoding="latin-1"
+ else:
+ encoding="utf-8"
+ ############################################################
+ # when the -c or --coding switch is used, it takes precedence
+ if options.encoding:
+ encoding = options.encoding
+
+ csvToOds( pathFileCSV=unicode(pathFileCSV),
+ pathFileODS=unicode(pathFileODS),
+ delimiter=delimiter, skipinitialspace=skipinitialspace,
+ escapechar=escapechar,
+ lineterminator=unicode(lineterminator),
+ tableName=tableName, quotechar=quotechar,
+ encoding=encoding)
+
+# Local Variables: ***
+# mode: python ***
+# End: ***
diff --git a/debian/changelog b/debian/changelog
index 0862873..2519cce 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,49 @@
+python-odf (1.2.0-6) unstable; urgency=medium
+
+ * fixed a lot of issues due to inconsistencies of the code initially
+ written for Python2, mainly confusions between byte strings
+ and unicode strings. The new code tries to use byte strings for
+ file-like streams and unicode strings for in-memory objects.
+ * added JavaDoc strings to document thoroughly functions and methods,
+ mainly in odf/opendocument.py
+ * added a config.dox file to allow one to build a documentation in HTML
+ and LaTeX, for library developpers and users.
+ * added many assert() clauses to ensure the types of parameters in
+ functions and methods
+ * modified the utilities to make them usable with both Python2 and Python3
+ * implemented a feature announced in csv2ods manfiles but not previously
+ active: -c / --encoding switch to take in account the encoding of
+ the CSV source file.
+ * added rules to build the developer's documentation and install it in
+ usr/share/python-odf/API-doc/html
+ * added a dependency python-odf-doc -> libjs-jquery necessary because
+ of HTML code output by Doxygen
+
+ -- Georges Khaznadar <georgesk at debian.org> Tue, 28 Oct 2014 10:41:32 +0100
+
+python-odf (1.2.0-5) unstable; urgency=medium
+
+ * fixed a small mistake: the new Standards-Version is 3.9.6
+ * recalled that this upload Closes: #766389
+
+ -- Georges Khaznadar <georgesk at debian.org> Sun, 26 Oct 2014 22:39:40 +0100
+
+python-odf (1.2.0-3) unstable; urgency=medium
+
+ * added myself to Uploaders
+ * modified the library to work with python3
+ * upgraded Standards-Version to 3.9.5, debhelper to 9
+ * added three new binary packages: python3-odf pythn-odf-tools
+ and python-odf-doc; the last one provides the documentation
+ for Odfpy's API as an opendocument
+ * modified the test routine to run tests with both python 2 and 3.
+ * fixed algorithms which might work with Python2 but were defeated by
+ Python3's unpredictability for order of iterables like dictionaries.
+ * modified the source of "binaries" to work with Python3 and checked
+ their features.
+
+ -- Georges Khaznadar <georgesk at debian.org> Tue, 21 Oct 2014 12:04:55 +0200
+
python-odf (1.2.0-2) unstable; urgency=low
* Build-dep on dh-python (Closes: #764984)
diff --git a/debian/compat b/debian/compat
index 45a4fb7..ec63514 100644
--- a/debian/compat
+++ b/debian/compat
@@ -1 +1 @@
-8
+9
diff --git a/debian/control b/debian/control
index ad377a2..e6ede41 100644
--- a/debian/control
+++ b/debian/control
@@ -2,15 +2,19 @@ Source: python-odf
Section: python
Priority: optional
Maintainer: Debian Python Modules Team <python-modules-team at lists.alioth.debian.org>
-Uploaders: Thomas Bechtold <thomasbechtold at jpberlin.de>, W. Martin Borgert <debacle at debian.org>
+Uploaders: Thomas Bechtold <thomasbechtold at jpberlin.de>,
+ W. Martin Borgert <debacle at debian.org>,
+ Georges Khaznadar <georgesk at debian.org>
Standards-Version: 3.9.6
-Build-Depends: debhelper (>= 8), python-all, xmlto, python-setuptools, dh-python
+Build-Depends: debhelper (>= 9), python-all, python3-all, xmlto,
+ python-setuptools, dh-python, doxygen, doxypy, graphviz
Homepage: https://github.com/eea/odfpy
Vcs-Git: git://anonscm.debian.org/python-modules/packages/python-odf.git
Vcs-Browser: http://anonscm.debian.org/gitweb/?p=python-modules/packages/python-odf.git
Package: python-odf
Architecture: all
+Recommends: python-odf-doc, python-odf-tools
Depends: ${misc:Depends}, ${python:Depends}
Description: Python API and tools to manipulate OpenDocument files
Odfpy is a library to read and write OpenDocument v. 1.1 files.
@@ -22,6 +26,36 @@ Description: Python API and tools to manipulate OpenDocument files
These checks and the API itself were generated from the RelaxNG
schema, and then hand-edited. Therefore the API is complete and can
handle all ODF constructions.
+
+Package: python-odf-tools
+Architecture: all
+Conflicts: python-odf (<< 1.2.0-3)
+Depends: ${misc:Depends}, ${python:Depends}, python3-odf
+Description: Python API and tools to manipulate OpenDocument files
+ Odfpy is a library to read and write OpenDocument v. 1.1 files.
+ The main focus has been to prevent the programmer from creating invalid
+ documents. It has checks that raise an exception if the programmer adds
+ an invalid element, adds an attribute unknown to the grammar, forgets to
+ add a required attribute or adds text to an element that doesn't allow it.
+ .
+ These checks and the API itself were generated from the RelaxNG
+ schema, and then hand-edited. Therefore the API is complete and can
+ handle all ODF constructions.
+
+Package: python3-odf
+Architecture: all
+Recommends: python-odf-doc, python-odf-tools
+Depends: ${misc:Depends}, ${python:Depends}, python3
+Description: Python API and tools to manipulate OpenDocument files
+ Odfpy is a library to read and write OpenDocument v. 1.1 files.
+ The main focus has been to prevent the programmer from creating invalid
+ documents. It has checks that raise an exception if the programmer adds
+ an invalid element, adds an attribute unknown to the grammar, forgets to
+ add a required attribute or adds text to an element that doesn't allow it.
+ .
+ These checks and the API itself were generated from the RelaxNG
+ schema, and then hand-edited. Therefore the API is complete and can
+ handle all ODF constructions.
.
In addition to the API, there are a few scripts:
.
@@ -36,3 +70,10 @@ Description: Python API and tools to manipulate OpenDocument files
- odfoutline - Show outline of OpenDocument
- odfuserfield - List or change the user-field declarations in an ODF file
- xml2odf - Create OD? package from OpenDocument in XML form
+
+Package: python-odf-doc
+Architecture: all
+Section: doc
+Depends: ${misc:Depends}, libjs-jquery
+Description: documentation and examples for python-odf and python3-odf
+ Odfpy is a library to read and write OpenDocument v. 1.1 files.
diff --git a/debian/examples b/debian/examples
deleted file mode 100644
index e39721e..0000000
--- a/debian/examples
+++ /dev/null
@@ -1 +0,0 @@
-examples/*
diff --git a/debian/patches/libsToPython3.patch b/debian/patches/libsToPython3.patch
new file mode 100644
index 0000000..82b02e1
--- /dev/null
+++ b/debian/patches/libsToPython3.patch
@@ -0,0 +1,2250 @@
+Index: python-odf-1.2.0/odf/attrconverters.py
+===================================================================
+--- python-odf-1.2.0.orig/odf/attrconverters.py
++++ python-odf-1.2.0/odf/attrconverters.py
+@@ -17,6 +17,9 @@
+ #
+ # Contributor(s):
+ #
++
++import sys, os.path
++sys.path.append(os.path.dirname(__file__))
+ from namespaces import *
+ import re, types
+
+@@ -29,10 +32,13 @@ def make_NCName(arg):
+ return arg
+
+ def cnv_angle(attribute, arg, element):
+- return unicode(arg)
++ if sys.version_info.major==2:
++ return unicode(arg)
++ else:
++ return str(arg)
+
+ def cnv_anyURI(attribute, arg, element):
+- return unicode(arg)
++ return str(arg)
+
+ def cnv_boolean(attribute, arg, element):
+ """ XML Schema Part 2: Datatypes Second Edition
+@@ -43,7 +49,7 @@ def cnv_boolean(attribute, arg, element)
+ return "false"
+ if str(arg).lower() in ("1","true","yes"):
+ return "true"
+- raise ValueError, "'%s' not allowed as Boolean value for %s" % (str(arg), attribute[1])
++ raise ValueError( "'%s' not allowed as Boolean value for %s" % (str(arg), attribute[1]))
+
+ # Potentially accept color values
+ def cnv_color(attribute, arg, element):
+@@ -55,12 +61,12 @@ def cnv_color(attribute, arg, element):
+ def cnv_configtype(attribute, arg, element):
+ if str(arg) not in ("boolean", "short", "int", "long",
+ "double", "string", "datetime", "base64Binary"):
+- raise ValueError, "'%s' not allowed" % str(arg)
++ raise ValueError( "'%s' not allowed" % str(arg))
+ return str(arg)
+
+ def cnv_data_source_has_labels(attribute, arg, element):
+ if str(arg) not in ("none","row","column","both"):
+- raise ValueError, "'%s' not allowed" % str(arg)
++ raise ValueError( "'%s' not allowed" % str(arg))
+ return str(arg)
+
+ # Understand different date formats
+@@ -81,7 +87,7 @@ def cnv_double(attribute, arg, element):
+
+ def cnv_draw_aspect(attribute, arg, element):
+ if str(arg) not in ("content", "thumbnail", "icon", "print-view"):
+- raise ValueError, "'%s' not allowed" % str(arg)
++ raise ValueError( "'%s' not allowed" % str(arg))
+ return str(arg)
+
+ def cnv_duration(attribute, arg, element):
+@@ -91,19 +97,19 @@ def cnv_family(attribute, arg, element):
+ """ A style family """
+ if str(arg) not in ("text", "paragraph", "section", "ruby", "table", "table-column", "table-row", "table-cell",
+ "graphic", "presentation", "drawing-page", "chart"):
+- raise ValueError, "'%s' not allowed" % str(arg)
++ raise ValueError( "'%s' not allowed" % str(arg))
+ return str(arg)
+
+ def __save_prefix(attribute, arg, element):
+ prefix = arg.split(':',1)[0]
+ if prefix == arg:
+- return unicode(arg)
++ return str(arg)
+ namespace = element.get_knownns(prefix)
+ if namespace is None:
+- #raise ValueError, "'%s' is an unknown prefix" % str(prefix)
+- return unicode(arg)
++ #raise ValueError( "'%s' is an unknown prefix" % str(prefix))
++ return str(arg)
+ p = element.get_nsprefix(namespace)
+- return unicode(arg)
++ return str(arg)
+
+ def cnv_formula(attribute, arg, element):
+ """ A string containing a formula. Formulas do not have a predefined syntax, but the string should
+@@ -127,12 +133,12 @@ pattern_language = re.compile(r'[a-zA-Z]
+ def cnv_language(attribute, arg, element):
+ global pattern_language
+ if not pattern_language.match(arg):
+- raise ValueError, "'%s' is not a valid language token" % arg
++ raise ValueError( "'%s' is not a valid language token" % arg)
+ return arg
+
+ def cnv_legend_position(attribute, arg, element):
+ if str(arg) not in ("start", "end", "top", "bottom", "top-start", "bottom-start", "top-end", "bottom-end"):
+- raise ValueError, "'%s' not allowed" % str(arg)
++ raise ValueError( "'%s' not allowed" % str(arg))
+ return str(arg)
+
+ pattern_length = re.compile(r'-?([0-9]+(\.[0-9]*)?|\.[0-9]+)((cm)|(mm)|(in)|(pt)|(pc)|(px))')
+@@ -143,7 +149,7 @@ def cnv_length(attribute, arg, element):
+ """
+ global pattern_length
+ if not pattern_length.match(arg):
+- raise ValueError, "'%s' is not a valid length" % arg
++ raise ValueError( "'%s' is not a valid length" % arg)
+ return arg
+
+ def cnv_lengthorpercent(attribute, arg, element):
+@@ -153,22 +159,22 @@ def cnv_lengthorpercent(attribute, arg,
+ try: return cnv_percent(attribute, arg, element)
+ except: failed = True
+ if failed:
+- raise ValueError, "'%s' is not a valid length or percent" % arg
++ raise ValueError( "'%s' is not a valid length or percent" % arg)
+ return arg
+
+ def cnv_list_linkage_type(attribute, arg, element):
+ if arg not in ('selection','selection-indices'):
+- raise ValueError, "'%s' is not either 'selection' or 'selection-indices'" % arg
++ raise ValueError( "'%s' is not either 'selection' or 'selection-indices'" % arg)
+ return str(arg)
+
+ def cnv_metavaluetype(attribute, arg, element):
+ if str(arg) not in ("float", "date", "time", "boolean", "string"):
+- raise ValueError, "'%s' not allowed" % str(arg)
++ raise ValueError( "'%s' not allowed" % str(arg))
+ return str(arg)
+
+ def cnv_major_minor(attribute, arg, element):
+ if arg not in ('major','minor'):
+- raise ValueError, "'%s' is not either 'minor' or 'major'" % arg
++ raise ValueError( "'%s' is not either 'minor' or 'major'" % arg)
+ return str(arg)
+
+ pattern_namespacedToken = re.compile(r'[0-9a-zA-Z_]+:[0-9a-zA-Z._\-]+')
+@@ -177,14 +183,14 @@ def cnv_namespacedToken(attribute, arg,
+ global pattern_namespacedToken
+
+ if not pattern_namespacedToken.match(arg):
+- raise ValueError, "'%s' is not a valid namespaced token" % arg
++ raise ValueError( "'%s' is not a valid namespaced token" % arg)
+ return __save_prefix(attribute, arg, element)
+
+ def cnv_NCName(attribute, arg, element):
+ """ NCName is defined in http://www.w3.org/TR/REC-xml-names/#NT-NCName
+ Essentially an XML name minus ':'
+ """
+- if type(arg) in types.StringTypes:
++ if (sys.version_info.major==3 and isinstance(arg, str)) or (sys.version_info.major==2 and type(arg) in types.StringTypes):
+ return make_NCName(arg)
+ else:
+ return arg.getAttrNS(STYLENS, 'name')
+@@ -221,7 +227,7 @@ pattern_percent = re.compile(r'-?([0-9]+
+ def cnv_percent(attribute, arg, element):
+ global pattern_percent
+ if not pattern_percent.match(arg):
+- raise ValueError, "'%s' is not a valid length" % arg
++ raise ValueError( "'%s' is not a valid length" % arg)
+ return arg
+
+ # Real one doesn't allow floating point values
+@@ -229,15 +235,15 @@ pattern_points = re.compile(r'-?[0-9]+,-
+ #pattern_points = re.compile(r'-?[0-9.]+,-?[0-9.]+([ ]+-?[0-9.]+,-?[0-9.]+)*')
+ def cnv_points(attribute, arg, element):
+ global pattern_points
+- if type(arg) in types.StringTypes:
++ if (sys.version_info.major==3 and isinstance(arg, str)) or (sys.version_info.major==2 and type(arg) in types.StringTypes):
+ if not pattern_points.match(arg):
+- raise ValueError, "x,y are separated by a comma and the points are separated by white spaces"
++ raise ValueError( "x,y are separated by a comma and the points are separated by white spaces")
+ return arg
+ else:
+ try:
+ strarg = ' '.join([ "%d,%d" % p for p in arg])
+ except:
+- raise ValueError, "Points must be string or [(0,0),(1,1)] - not %s" % arg
++ raise ValueError( "Points must be string or [(0,0),(1,1)] - not %s" % arg)
+ return strarg
+
+ def cnv_positiveInteger(attribute, arg, element):
+@@ -245,20 +251,23 @@ def cnv_positiveInteger(attribute, arg,
+
+ def cnv_rowOrCol(attribute, arg, element):
+ if str(arg) not in ("row","column"):
+- raise ValueError, "'%s' not allowed" % str(arg)
++ raise ValueError( "'%s' not allowed" % str(arg))
+ return str(arg)
+
+ def cnv_string(attribute, arg, element):
+- return unicode(arg)
++ if sys.version_info.major==2:
++ return unicode(arg)
++ else:
++ return str(arg)
+
+ def cnv_stroke_linecap(attribute, arg, element):
+ if str(arg) not in ("butt", "square", "round"):
+- raise ValueError, "'%s' not allowed" % str(arg)
++ raise ValueError( "'%s' not allowed" % str(arg))
+ return str(arg)
+
+ def cnv_textnoteclass(attribute, arg, element):
+ if str(arg) not in ("footnote", "endnote"):
+- raise ValueError, "'%s' not allowed" % str(arg)
++ raise ValueError( "'%s' not allowed" % str(arg))
+ return str(arg)
+
+ # Understand different time formats
+@@ -273,17 +282,17 @@ pattern_viewbox = re.compile(r'-?[0-9]+(
+ def cnv_viewbox(attribute, arg, element):
+ global pattern_viewbox
+ if not pattern_viewbox.match(arg):
+- raise ValueError, "viewBox must be four integers separated by whitespaces"
++ raise ValueError( "viewBox must be four integers separated by whitespaces")
+ return arg
+
+ def cnv_xlinkshow(attribute, arg, element):
+ if str(arg) not in ("new", "replace", "embed"):
+- raise ValueError, "'%s' not allowed" % str(arg)
++ raise ValueError( "'%s' not allowed" % str(arg))
+ return str(arg)
+
+ def cnv_xlinktype(attribute, arg, element):
+ if arg != "simple":
+- raise ValueError, "Value of '%s' must be 'simple'" % attribute[1]
++ raise ValueError( "Value of '%s' must be 'simple'" % attribute[1])
+ return arg
+
+
+@@ -1596,5 +1605,8 @@ class AttrConverters:
+ conversion = attrconverters.get((attribute, None), None)
+ if conversion is not None:
+ return conversion(attribute, value, element)
+- return unicode(value)
++ if sys.version_info.major==2:
++ return unicode(value)
++ else:
++ return str(value)
+
+Index: python-odf-1.2.0/odf/draw.py
+===================================================================
+--- python-odf-1.2.0.orig/odf/draw.py
++++ python-odf-1.2.0/odf/draw.py
+@@ -18,6 +18,8 @@
+ # Contributor(s):
+ #
+
++import sys, os.path
++sys.path.append(os.path.dirname(__file__))
+ from namespaces import DRAWNS, STYLENS, PRESENTATIONNS
+ from element import Element
+
+@@ -30,7 +32,7 @@ def StyleRefElement(stylename=None, clas
+ elif f == 'presentation':
+ qattrs[(PRESENTATIONNS,u'style-name')]= stylename
+ else:
+- raise ValueError, "Style's family must be either 'graphic' or 'presentation'"
++ raise ValueError( "Style's family must be either 'graphic' or 'presentation'")
+ if classnames is not None:
+ f = classnames[0].getAttrNS(STYLENS, 'family')
+ if f == 'graphic':
+@@ -38,12 +40,12 @@ def StyleRefElement(stylename=None, clas
+ elif f == 'presentation':
+ qattrs[(PRESENTATIONNS,u'class-names')]= classnames
+ else:
+- raise ValueError, "Style's family must be either 'graphic' or 'presentation'"
++ raise ValueError( "Style's family must be either 'graphic' or 'presentation'")
+ return Element(qattributes=qattrs, **args)
+
+ def DrawElement(name=None, **args):
+ e = Element(name=name, **args)
+- if not args.has_key('displayname'):
++ if 'displayname' not in args:
+ e.setAttrNS(DRAWNS,'display-name', name)
+ return e
+
+Index: python-odf-1.2.0/odf/element.py
+===================================================================
+--- python-odf-1.2.0.orig/odf/element.py
++++ python-odf-1.2.0/odf/element.py
+@@ -22,12 +22,17 @@
+ # Note: This script has copied a lot of text from xml.dom.minidom.
+ # Whatever license applies to that file also applies to this file.
+ #
++import sys, os.path
++sys.path.append(os.path.dirname(__file__))
+ import xml.dom
+ from xml.dom.minicompat import *
+ from namespaces import nsdict
+ import grammar
+ from attrconverters import AttrConverters
+
++if sys.version_info.major == 3:
++ unicode=str # unicode function does not exist
++
+ # The following code is pasted form xml.sax.saxutils
+ # Tt makes it possible to run the code without the xml sax package installed
+ # To make it possible to have <rubbish> in your text elements, it is necessary to escape the texts
+@@ -79,10 +84,11 @@ def _nssplit(qualifiedName):
+ def _nsassign(namespace):
+ return nsdict.setdefault(namespace,"ns" + str(len(nsdict)))
+
++
+ # Exceptions
+-class IllegalChild(StandardError):
++class IllegalChild(Exception):
+ """ Complains if you add an element to a parent where it is not allowed """
+-class IllegalText(StandardError):
++class IllegalText(Exception):
+ """ Complains if you add text or cdata to an element where it is not allowed """
+
+ class Node(xml.dom.Node):
+@@ -116,7 +122,7 @@ class Node(xml.dom.Node):
+ If refChild is null, insert newChild at the end of the list of children.
+ """
+ if newChild.nodeType not in self._child_node_types:
+- raise IllegalChild, "%s cannot be child of %s" % (newChild.tagName, self.tagName)
++ raise IllegalChild( "%s cannot be child of %s" % (newChild.tagName, self.tagName))
+ if newChild.parentNode is not None:
+ newChild.parentNode.removeChild(newChild)
+ if refChild is None:
+@@ -148,7 +154,7 @@ class Node(xml.dom.Node):
+ ### The DOM does not clearly specify what to return in this case
+ return newChild
+ if newChild.nodeType not in self._child_node_types:
+- raise IllegalChild, "<%s> is not allowed in %s" % ( newChild.tagName, self.tagName)
++ raise IllegalChild( "<%s> is not allowed in %s" % ( newChild.tagName, self.tagName))
+ if newChild.parentNode is not None:
+ newChild.parentNode.removeChild(newChild)
+ _append_child(self, newChild)
+@@ -245,7 +251,7 @@ class Text(Childless, Node):
+ self.data = data
+
+ def __str__(self):
+- return self.data.encode()
++ return self.data
+
+ def __unicode__(self):
+ return self.data
+@@ -253,9 +259,9 @@ class Text(Childless, Node):
+ def toXml(self,level,f):
+ """ Write XML in UTF-8 """
+ if self.data:
+- f.write(_escape(unicode(self.data).encode('utf-8')))
++ f.write(_escape(unicode(self.data)))
+
+-class CDATASection(Childless, Text):
++class CDATASection(Text, Childless):
+ nodeType = Node.CDATA_SECTION_NODE
+
+ def toXml(self,level,f):
+@@ -324,7 +330,7 @@ class Element(Node):
+ if required:
+ for r in required:
+ if self.getAttrNS(r[0],r[1]) is None:
+- raise AttributeError, "Required attribute missing: %s in <%s>" % (r[1].lower().replace('-',''), self.tagName)
++ raise AttributeError( "Required attribute missing: %s in <%s>" % (r[1].lower().replace('-',''), self.tagName))
+
+ def get_knownns(self, prefix):
+ """ Odfpy maintains a list of known namespaces. In some cases a prefix is used, and
+@@ -341,7 +347,7 @@ class Element(Node):
+ """
+ if namespace is None: namespace = ""
+ prefix = _nsassign(namespace)
+- if not self.namespaces.has_key(namespace):
++ if not namespace in self.namespaces:
+ self.namespaces[namespace] = prefix
+ return prefix
+
+@@ -360,7 +366,7 @@ class Element(Node):
+ """
+ if check_grammar and self.allowed_children is not None:
+ if element.qname not in self.allowed_children:
+- raise IllegalChild, "<%s> is not allowed in <%s>" % ( element.tagName, self.tagName)
++ raise IllegalChild( "<%s> is not allowed in <%s>" % ( element.tagName, self.tagName))
+ self.appendChild(element)
+ self._setOwnerDoc(element)
+ if self.ownerDocument:
+@@ -371,7 +377,7 @@ class Element(Node):
+ Setting check_grammar=False turns off grammar checking
+ """
+ if check_grammar and self.qname not in grammar.allows_text:
+- raise IllegalText, "The <%s> element does not allow text" % self.tagName
++ raise IllegalText( "The <%s> element does not allow text" % self.tagName)
+ else:
+ if text != '':
+ self.appendChild(Text(text))
+@@ -381,7 +387,7 @@ class Element(Node):
+ Setting check_grammar=False turns off grammar checking
+ """
+ if check_grammar and self.qname not in grammar.allows_text:
+- raise IllegalText, "The <%s> element does not allow text" % self.tagName
++ raise IllegalText( "The <%s> element does not allow text" % self.tagName)
+ else:
+ self.appendChild(CDATASection(cdata))
+
+@@ -393,12 +399,12 @@ class Element(Node):
+ prefix, localname = attr
+ self.removeAttrNS(prefix, localname)
+ else:
+- raise AttributeError, "Unable to add simple attribute - use (namespace, localpart)"
... 11667 lines suppressed ...
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-odf.git
More information about the Python-modules-commits
mailing list