Run code quality checks on the odf package

This commit is contained in:
Kovid Goyal 2019-05-20 16:52:16 +05:30
parent 609892eb81
commit 8366df8637
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
18 changed files with 174 additions and 167 deletions

View File

@ -26,18 +26,19 @@ class Check(Command):
CACHE = 'check.json'
def get_files(self):
for x in os.walk(self.j(self.SRC, 'calibre')):
for f in x[-1]:
y = self.j(x[0], f)
if x[0].endswith('calibre/ebooks/markdown'):
continue
if (f.endswith('.py') and f not in (
'feedparser.py', 'markdown.py', 'BeautifulSoup.py', 'dict_data.py',
'unicodepoints.py', 'krcodepoints.py', 'jacodepoints.py', 'vncodepoints.py', 'zhcodepoints.py') and
'prs500/driver.py' not in y) and not f.endswith('_ui.py'):
yield y
if f.endswith('.coffee'):
yield y
for dname in ('odf', 'calibre'):
for x in os.walk(self.j(self.SRC, dname)):
for f in x[-1]:
y = self.j(x[0], f)
if x[0].endswith('calibre/ebooks/markdown'):
continue
if (f.endswith('.py') and f not in (
'feedparser.py', 'markdown.py', 'BeautifulSoup.py', 'dict_data.py',
'unicodepoints.py', 'krcodepoints.py', 'jacodepoints.py', 'vncodepoints.py', 'zhcodepoints.py') and
'prs500/driver.py' not in y) and not f.endswith('_ui.py'):
yield y
if f.endswith('.coffee'):
yield y
for x in os.walk(self.j(self.d(self.SRC), 'recipes')):
for f in x[-1]:

View File

@ -14,23 +14,8 @@ TEST_MODULES = frozenset('srv db polish opf css docx cfi matcher icu smartypants
class TestImports(unittest.TestCase):
def test_import_of_all_python_modules(self):
def base_check(self, base, exclude_packages, exclude_modules):
import importlib
exclude_modules = {'calibre.gui2.dbus_export.demo', 'calibre.gui2.dbus_export.gtk'}
exclude_packages = {'calibre.devices.mtp.unix.upstream'}
if not iswindows:
exclude_modules |= {'calibre.utils.iphlpapi', 'calibre.utils.open_with.windows', 'calibre.devices.winusb'}
exclude_packages |= {'calibre.utils.winreg'}
if not isosx:
exclude_modules.add('calibre.utils.open_with.osx')
if not islinux:
exclude_modules |= {
'calibre.utils.dbus_service', 'calibre.linux',
'calibre.utils.linux_trash', 'calibre.utils.open_with.linux',
'calibre.gui2.linux_file_dialogs'
}
exclude_packages.add('calibre.gui2.dbus_export')
base = os.path.join(SRC, 'calibre')
import_base = os.path.dirname(base)
count = 0
for root, dirs, files in os.walk(base):
@ -50,7 +35,26 @@ class TestImports(unittest.TestCase):
continue
importlib.import_module(full_module_name)
count += 1
self.assertGreater(count, 1000)
return count
def test_import_of_all_python_modules(self):
exclude_modules = {'calibre.gui2.dbus_export.demo', 'calibre.gui2.dbus_export.gtk'}
exclude_packages = {'calibre.devices.mtp.unix.upstream'}
if not iswindows:
exclude_modules |= {'calibre.utils.iphlpapi', 'calibre.utils.open_with.windows', 'calibre.devices.winusb'}
exclude_packages |= {'calibre.utils.winreg'}
if not isosx:
exclude_modules.add('calibre.utils.open_with.osx')
if not islinux:
exclude_modules |= {
'calibre.utils.dbus_service', 'calibre.linux',
'calibre.utils.linux_trash', 'calibre.utils.open_with.linux',
'calibre.gui2.linux_file_dialogs'
}
exclude_packages.add('calibre.gui2.dbus_export')
self.assertGreater(self.base_check(os.path.join(SRC, 'odf'), exclude_packages, exclude_modules), 10)
base = os.path.join(SRC, 'calibre')
self.assertGreater(self.base_check(base, exclude_packages, exclude_modules), 1000)
def find_tests(which_tests=None):

View File

@ -17,8 +17,14 @@
#
# Contributor(s):
#
from .namespaces import *
import re, types
import re
import types
from .namespaces import (
ANIMNS, CHARTNS, CONFIGNS, DR3DNS, DRAWNS, FONS, FORMNS, MANIFESTNS, METANS,
NUMBERNS, OFFICENS, PRESENTATIONNS, SCRIPTNS, SMILNS, STYLENS, SVGNS, TABLENS,
TEXTNS, XFORMSNS, XLINKNS
)
pattern_color = re.compile(r'#[0-9a-fA-F]{6}')
pattern_vector3D = re.compile(r'\([ ]*-?([0-9]+(\.[0-9]*)?|\.[0-9]+)([ ]+-?([0-9]+(\.[0-9]*)?|\.[0-9]+)){2}[ ]*\)')
@ -102,9 +108,8 @@ def __save_prefix(attribute, arg, element):
return type(u'')(arg)
namespace = element.get_knownns(prefix)
if namespace is None:
#raise ValueError, "'%s' is an unknown prefix" % str(prefix)
# raise ValueError, "'%s' is an unknown prefix" % str(prefix)
return type(u'')(arg)
p = element.get_nsprefix(namespace)
return type(u'')(arg)
@ -241,7 +246,7 @@ def cnv_percent(attribute, arg, element):
# Real one doesn't allow floating point values
pattern_points = re.compile(r'-?[0-9]+,-?[0-9]+([ ]+-?[0-9]+,-?[0-9]+)*')
#pattern_points = re.compile(r'-?[0-9.]+,-?[0-9.]+([ ]+-?[0-9.]+,-?[0-9.]+)*')
# pattern_points = re.compile(r'-?[0-9.]+,-?[0-9.]+([ ]+-?[0-9.]+,-?[0-9.]+)*')
def cnv_points(attribute, arg, element):
@ -310,7 +315,7 @@ attrconverters = {
((ANIMNS,u'name'), None): cnv_string,
((ANIMNS,u'sub-item'), None): cnv_string,
((ANIMNS,u'value'), None): cnv_string,
# ((DBNS,u'type'), None): cnv_namespacedToken,
# ((DBNS,u'type'), None): cnv_namespacedToken,
((CHARTNS,u'attached-axis'), None): cnv_string,
((CHARTNS,u'class'), (CHARTNS,u'grid')): cnv_major_minor,
((CHARTNS,u'class'), None): cnv_namespacedToken,
@ -532,8 +537,8 @@ attrconverters = {
((DRAWNS,u'handle-range-y-maximum'), None): cnv_string,
((DRAWNS,u'handle-range-y-minimum'), None): cnv_string,
((DRAWNS,u'handle-switched'), None): cnv_boolean,
# ((DRAWNS,u'id'), None): cnv_ID,
# ((DRAWNS,u'id'), None): cnv_nonNegativeInteger, # ?? line 6581 in RNG
# ((DRAWNS,u'id'), None): cnv_ID,
# ((DRAWNS,u'id'), None): cnv_nonNegativeInteger, # ?? line 6581 in RNG
((DRAWNS,u'id'), None): cnv_string,
((DRAWNS,u'image-opacity'), None): cnv_string,
((DRAWNS,u'kind'), None): cnv_string,
@ -556,7 +561,7 @@ attrconverters = {
((DRAWNS,u'mirror-vertical'), None): cnv_boolean,
((DRAWNS,u'modifiers'), None): cnv_string,
((DRAWNS,u'name'), None): cnv_NCName,
# ((DRAWNS,u'name'), None): cnv_string,
# ((DRAWNS,u'name'), None): cnv_string,
((DRAWNS,u'nav-order'), None): cnv_IDREF,
((DRAWNS,u'nohref'), None): cnv_string,
((DRAWNS,u'notify-on-update-of-ranges'), None): cnv_string,
@ -693,10 +698,10 @@ attrconverters = {
((FORMNS,u'convert-empty-to-null'), None): cnv_boolean,
((FORMNS,u'current-selected'), None): cnv_boolean,
((FORMNS,u'current-state'), None): cnv_string,
# ((FORMNS,u'current-value'), None): cnv_date,
# ((FORMNS,u'current-value'), None): cnv_double,
# ((FORMNS,u'current-value'), None): cnv_date,
# ((FORMNS,u'current-value'), None): cnv_double,
((FORMNS,u'current-value'), None): cnv_string,
# ((FORMNS,u'current-value'), None): cnv_time,
# ((FORMNS,u'current-value'), None): cnv_time,
((FORMNS,u'data-field'), None): cnv_string,
((FORMNS,u'datasource'), None): cnv_string,
((FORMNS,u'default-button'), None): cnv_boolean,
@ -721,15 +726,15 @@ attrconverters = {
((FORMNS,u'list-source-type'), None): cnv_string,
((FORMNS,u'master-fields'), None): cnv_string,
((FORMNS,u'max-length'), None): cnv_nonNegativeInteger,
# ((FORMNS,u'max-value'), None): cnv_date,
# ((FORMNS,u'max-value'), None): cnv_double,
# ((FORMNS,u'max-value'), None): cnv_date,
# ((FORMNS,u'max-value'), None): cnv_double,
((FORMNS,u'max-value'), None): cnv_string,
# ((FORMNS,u'max-value'), None): cnv_time,
# ((FORMNS,u'max-value'), None): cnv_time,
((FORMNS,u'method'), None): cnv_string,
# ((FORMNS,u'min-value'), None): cnv_date,
# ((FORMNS,u'min-value'), None): cnv_double,
# ((FORMNS,u'min-value'), None): cnv_date,
# ((FORMNS,u'min-value'), None): cnv_double,
((FORMNS,u'min-value'), None): cnv_string,
# ((FORMNS,u'min-value'), None): cnv_time,
# ((FORMNS,u'min-value'), None): cnv_time,
((FORMNS,u'multi-line'), None): cnv_boolean,
((FORMNS,u'multiple'), None): cnv_boolean,
((FORMNS,u'name'), None): cnv_string,
@ -751,10 +756,10 @@ attrconverters = {
((FORMNS,u'title'), None): cnv_string,
((FORMNS,u'toggle'), None): cnv_boolean,
((FORMNS,u'validation'), None): cnv_boolean,
# ((FORMNS,u'value'), None): cnv_date,
# ((FORMNS,u'value'), None): cnv_double,
# ((FORMNS,u'value'), None): cnv_date,
# ((FORMNS,u'value'), None): cnv_double,
((FORMNS,u'value'), None): cnv_string,
# ((FORMNS,u'value'), None): cnv_time,
# ((FORMNS,u'value'), None): cnv_time,
((FORMNS,u'visual-effect'), None): cnv_string,
((FORMNS,u'xforms-list-source'), None): cnv_string,
((FORMNS,u'xforms-submission'), None): cnv_string,
@ -1183,7 +1188,7 @@ attrconverters = {
((TABLENS,u'border-model'), None): cnv_string,
((TABLENS,u'buttons'), None): cnv_string,
((TABLENS,u'buttons'), None): cnv_string,
((TABLENS,u'case-sensitive'), None): cnv_boolean,
# ((TABLENS,u'case-sensitive'), None): cnv_boolean,
((TABLENS,u'case-sensitive'), None): cnv_string,
((TABLENS,u'cell-address'), None): cnv_string,
((TABLENS,u'cell-range-address'), None): cnv_string,
@ -1231,7 +1236,7 @@ attrconverters = {
((TABLENS,u'execute'), None): cnv_boolean,
((TABLENS,u'expression'), None): cnv_formula,
((TABLENS,u'field-name'), None): cnv_string,
((TABLENS,u'field-number'), None): cnv_nonNegativeInteger,
# ((TABLENS,u'field-number'), None): cnv_nonNegativeInteger,
((TABLENS,u'field-number'), None): cnv_string,
((TABLENS,u'filter-name'), None): cnv_string,
((TABLENS,u'filter-options'), None): cnv_string,
@ -1295,7 +1300,7 @@ attrconverters = {
((TABLENS,u'protection-key'), None): cnv_string,
((TABLENS,u'query-name'), None): cnv_string,
((TABLENS,u'range-usable-as'), None): cnv_string,
((TABLENS,u'refresh-delay'), None): cnv_boolean,
# ((TABLENS,u'refresh-delay'), None): cnv_boolean,
((TABLENS,u'refresh-delay'), None): cnv_duration,
((TABLENS,u'rejecting-change-id'), None): cnv_string,
((TABLENS,u'row'), None): cnv_integer,
@ -1303,7 +1308,7 @@ attrconverters = {
((TABLENS,u'search-criteria-must-apply-to-whole-cell'), None): cnv_boolean,
((TABLENS,u'selected-page'), None): cnv_string,
((TABLENS,u'show-details'), None): cnv_boolean,
((TABLENS,u'show-empty'), None): cnv_boolean,
# ((TABLENS,u'show-empty'), None): cnv_boolean,
((TABLENS,u'show-empty'), None): cnv_string,
((TABLENS,u'show-filter-button'), None): cnv_boolean,
((TABLENS,u'sort-mode'), None): cnv_string,
@ -1391,7 +1396,7 @@ attrconverters = {
((TEXTNS,u'database-name'), None): cnv_string,
((TEXTNS,u'date-adjust'), None): cnv_duration,
((TEXTNS,u'date-value'), None): cnv_date,
# ((TEXTNS,u'date-value'), None): cnv_dateTime,
# ((TEXTNS,u'date-value'), None): cnv_dateTime,
((TEXTNS,u'default-style-name'), None): cnv_StyleNameRef,
((TEXTNS,u'description'), None): cnv_string,
((TEXTNS,u'display'), None): cnv_string,
@ -1410,7 +1415,7 @@ attrconverters = {
((TEXTNS,u'global'), None): cnv_boolean,
((TEXTNS,u'howpublished'), None): cnv_string,
((TEXTNS,u'id'), None): cnv_ID,
# ((TEXTNS,u'id'), None): cnv_string,
# ((TEXTNS,u'id'), None): cnv_string,
((TEXTNS,u'identifier'), None): cnv_string,
((TEXTNS,u'ignore-case'), None): cnv_boolean,
((TEXTNS,u'increment'), None): cnv_nonNegativeInteger,
@ -1476,7 +1481,7 @@ attrconverters = {
((TEXTNS,u'sort-by-position'), None): cnv_boolean,
((TEXTNS,u'space-before'), None): cnv_string,
((TEXTNS,u'start-numbering-at'), None): cnv_string,
((TEXTNS,u'start-value'), None): cnv_nonNegativeInteger,
# ((TEXTNS,u'start-value'), None): cnv_nonNegativeInteger,
((TEXTNS,u'start-value'), None): cnv_positiveInteger,
((TEXTNS,u'string-value'), None): cnv_string,
((TEXTNS,u'string-value-if-false'), None): cnv_string,
@ -1488,7 +1493,7 @@ attrconverters = {
((TEXTNS,u'table-name'), None): cnv_string,
((TEXTNS,u'table-type'), None): cnv_string,
((TEXTNS,u'time-adjust'), None): cnv_duration,
((TEXTNS,u'time-value'), None): cnv_dateTime,
# ((TEXTNS,u'time-value'), None): cnv_dateTime,
((TEXTNS,u'time-value'), None): cnv_time,
((TEXTNS,u'title'), None): cnv_string,
((TEXTNS,u'track-changes'), None): cnv_boolean,

View File

@ -19,7 +19,6 @@
#
from .namespaces import DR3DNS
from .element import Element
from .draw import StyleRefElement
# Autogenerated
@ -33,7 +32,7 @@ def Extrude(**args):
return StyleRefElement(qname=(DR3DNS,'extrude'), **args)
def Light(Element):
def Light(Element, **args):
return StyleRefElement(qname=(DR3DNS,'light'), **args)

View File

@ -20,8 +20,8 @@
#
import re
from style import Style, TextProperties, ListLevelProperties
from text import ListStyle,ListLevelStyleNumber,ListLevelStyleBullet
from .style import ListLevelProperties
from .text import ListStyle,ListLevelStyleNumber,ListLevelStyleBullet
"""
Create a <text:list-style> element from a string or array.
@ -51,7 +51,6 @@ def styleFromList(styleName, specArray, spacing, showAllLevels):
bullet = ""
numPrefix = ""
numSuffix = ""
numberFormat = ""
cssLengthNum = 0
cssLengthUnits = ""
numbered = False
@ -60,7 +59,7 @@ def styleFromList(styleName, specArray, spacing, showAllLevels):
numFormatPattern = re.compile("([1IiAa])")
cssLengthPattern = re.compile("([^a-z]+)\\s*([a-z]+)?")
m = cssLengthPattern.search(spacing)
if (m != None):
if (m is not None):
cssLengthNum = float(m.group(1))
if (m.lastindex == 2):
cssLengthUnits = m.group(2)
@ -68,8 +67,7 @@ def styleFromList(styleName, specArray, spacing, showAllLevels):
while i < len(specArray):
specification = specArray[i]
m = numFormatPattern.search(specification)
if (m != None):
numberFormat = m.group(1)
if (m is not None):
numPrefix = specification[0:m.start(1)]
numSuffix = specification[m.end(1):]
bullet = ""
@ -82,7 +80,6 @@ def styleFromList(styleName, specArray, spacing, showAllLevels):
bullet = specification
numPrefix = ""
numSuffix = ""
numberFormat = ""
displayLevels = 1
numbered = False
if (numbered):

View File

@ -23,7 +23,7 @@
# Whatever license applies to that file also applies to this file.
#
import xml.dom
from xml.dom.minicompat import *
from xml.dom.minicompat import defproperty, EmptyNodeList
from .namespaces import nsdict
from . import grammar
from .attrconverters import AttrConverters
@ -315,8 +315,6 @@ class Element(Node):
self.addCDATA(cdata)
allowed_attrs = self.allowed_attributes()
if allowed_attrs is not None:
allowed_args = [a[1].lower().replace('-','') for a in allowed_attrs]
self.attributes={}
# Load the attributes from the 'attributes' argument
if attributes:
@ -407,7 +405,7 @@ class Element(Node):
""" Removes an attribute by name. """
allowed_attrs = self.allowed_attributes()
if allowed_attrs is None:
if type(attr) == type(()):
if isinstance(attr, tuple):
prefix, localname = attr
self.removeAttrNS(prefix, localname)
else:
@ -430,7 +428,7 @@ class Element(Node):
"""
allowed_attrs = self.allowed_attributes()
if allowed_attrs is None:
if type(attr) == type(()):
if isinstance(attr, tuple):
prefix, localname = attr
self.setAttrNS(prefix, localname, value)
else:
@ -450,15 +448,10 @@ class Element(Node):
It will not check that the attribute is legal according to the schema.
Must overwrite, If attribute already exists.
"""
allowed_attrs = self.allowed_attributes()
prefix = self.get_nsprefix(namespace)
# if allowed_attrs and (namespace, localpart) not in allowed_attrs:
# raise AttributeError, "Attribute %s:%s is not allowed in element <%s>" % ( prefix, localpart, self.tagName)
c = AttrConverters()
self.attributes[(namespace, localpart)] = c.convert((namespace, localpart), value, self)
def getAttrNS(self, namespace, localpart):
prefix = self.get_nsprefix(namespace)
return self.attributes.get((namespace, localpart))
def removeAttrNS(self, namespace, localpart):
@ -469,7 +462,7 @@ class Element(Node):
"""
allowed_attrs = self.allowed_attributes()
if allowed_attrs is None:
if type(attr) == type(()):
if isinstance(attr, tuple):
prefix, localname = attr
return self.getAttrNS(prefix, localname)
else:

View File

@ -19,7 +19,10 @@
# Contributor(s):
#
from .namespaces import *
from .namespaces import (
ANIMNS, CHARTNS, DR3DNS, DRAWNS, FORMNS, MANIFESTNS, METANS, NUMBERNS, OFFICENS,
PRESENTATIONNS, SCRIPTNS, STYLENS, SVGNS, TABLENS, TEXTNS
)
# Inline element don't cause a box
# They are analogous to the HTML elements SPAN, B, I etc.

View File

@ -23,7 +23,11 @@ Currently it contains the legal child elements of a given element.
To be used for validation check in the API
"""
from .namespaces import *
from .namespaces import (
ANIMNS, CHARTNS, CONFIGNS, DCNS, DR3DNS, DRAWNS, FORMNS, MANIFESTNS, MATHNS,
METANS, NUMBERNS, OFFICENS, PRESENTATIONNS, SCRIPTNS, STYLENS, SVGNS, TABLENS,
TEXTNS, XFORMSNS, XLINKNS, SMILNS, FONS
)
# The following code is generated from the RelaxNG schema with this notice:
@ -64,24 +68,24 @@ allowed_children = {
(DCNS,u'title') : (
),
# Completes Dublin Core start
# (DCNS,'contributor') : (
# ),
# (DCNS,'coverage') : (
# ),
# (DCNS,'format') : (
# ),
# (DCNS,'identifier') : (
# ),
# (DCNS,'publisher') : (
# ),
# (DCNS,'relation') : (
# ),
# (DCNS,'rights') : (
# ),
# (DCNS,'source') : (
# ),
# (DCNS,'type') : (
# ),
# (DCNS,'contributor') : (
# ),
# (DCNS,'coverage') : (
# ),
# (DCNS,'format') : (
# ),
# (DCNS,'identifier') : (
# ),
# (DCNS,'publisher') : (
# ),
# (DCNS,'relation') : (
# ),
# (DCNS,'rights') : (
# ),
# (DCNS,'source') : (
# ),
# (DCNS,'type') : (
# ),
# Completes Dublin Core end
(MATHNS,u'math') : None,
@ -981,15 +985,15 @@ allowed_children = {
(DCNS,u'subject'),
(DCNS,u'title'),
# Completes Dublin Core start
# (DCNS,'contributor'),
# (DCNS,'coverage'),
# (DCNS,'format'),
# (DCNS,'identifier'),
# (DCNS,'publisher'),
# (DCNS,'relation'),
# (DCNS,'rights'),
# (DCNS,'source'),
# (DCNS,'type'),
# (DCNS,'contributor'),
# (DCNS,'coverage'),
# (DCNS,'format'),
# (DCNS,'identifier'),
# (DCNS,'publisher'),
# (DCNS,'relation'),
# (DCNS,'rights'),
# (DCNS,'source'),
# (DCNS,'type'),
# Completes Dublin Core end
(METANS,u'auto-reload'),
(METANS,u'creation-date'),
@ -3245,15 +3249,15 @@ allows_text = (
(DCNS,u'subject'),
(DCNS,u'title'),
# Completes Dublin Core start
# (DCNS,'contributor'),
# (DCNS,'coverage'),
# (DCNS,'format'),
# (DCNS,'identifier'),
# (DCNS,'publisher'),
# (DCNS,'relation'),
# (DCNS,'rights'),
# (DCNS,'source'),
# (DCNS,'type'),
# (DCNS,'contributor'),
# (DCNS,'coverage'),
# (DCNS,'format'),
# (DCNS,'identifier'),
# (DCNS,'publisher'),
# (DCNS,'relation'),
# (DCNS,'rights'),
# (DCNS,'source'),
# (DCNS,'type'),
# Completes Dublin Core end
(FORMNS,u'item'),
(FORMNS,u'option'),
@ -4239,24 +4243,24 @@ allowed_attributes = {
(DCNS,u'title'):(
),
# Completes Dublin Core start
# (DCNS,'contributor') : (
# ),
# (DCNS,'coverage') : (
# ),
# (DCNS,'format') : (
# ),
# (DCNS,'identifier') : (
# ),
# (DCNS,'publisher') : (
# ),
# (DCNS,'relation') : (
# ),
# (DCNS,'rights') : (
# ),
# (DCNS,'source') : (
# ),
# (DCNS,'type') : (
# ),
# (DCNS,'contributor') : (
# ),
# (DCNS,'coverage') : (
# ),
# (DCNS,'format') : (
# ),
# (DCNS,'identifier') : (
# ),
# (DCNS,'publisher') : (
# ),
# (DCNS,'relation') : (
# ),
# (DCNS,'rights') : (
# ),
# (DCNS,'source') : (
# ),
# (DCNS,'type') : (
# ),
# Completes Dublin Core end
(MATHNS,u'math'): None,
(XFORMSNS,u'model'): None,

View File

@ -49,7 +49,7 @@ class LoadParser(handler.ContentHandler):
self.parse = False
def characters(self, data):
if self.parse == False:
if self.parse is False:
return
self.data.append(data)
@ -58,7 +58,7 @@ class LoadParser(handler.ContentHandler):
self.parse = True
if self.doc._parsing != "styles.xml" and tag == (OFFICENS, 'font-face-decls'):
self.parse = False
if self.parse == False:
if self.parse is False:
return
self.level = self.level + 1
@ -98,7 +98,7 @@ class LoadParser(handler.ContentHandler):
self.parent = e
def endElementNS(self, tag, qname):
if self.parse == False:
if self.parse is False:
return
self.level = self.level - 1
# Changed by Kovid to deal with <span> tags with only whitespace

View File

@ -24,7 +24,7 @@ CHARTNS = u"urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
CHARTOOONS = u"http://openoffice.org/2010/chart"
CONFIGNS = u"urn:oasis:names:tc:opendocument:xmlns:config:1.0"
CSS3TNS = u"http://www.w3.org/TR/css3-text/"
#DBNS = u"http://openoffice.org/2004/database"
# DBNS = u"http://openoffice.org/2004/database"
DBNS = u"urn:oasis:names:tc:opendocument:xmlns:database:1.0"
DCNS = u"http://purl.org/dc/elements/1.1/"
DOMNS = u"http://www.w3.org/2001/xml-events"

View File

@ -22,7 +22,7 @@
import zipfile, xml.dom.minidom
from .namespaces import nsdict
from .elementtypes import *
from .elementtypes import empty_elements, inline_elements
IGNORED_TAGS = [
'draw:a'
@ -186,11 +186,6 @@ class ODF2MoinMoin(object):
textProps = TextProps()
if parent:
parentProp = self.textStyles.get(parent, None)
if parentProp:
textProp = parentProp
textPropEl = style.getElementsByTagName("style:text-properties")
if not textPropEl:
return textProps
@ -274,8 +269,7 @@ class ODF2MoinMoin(object):
prop = ListProperties()
if style.hasChildNodes():
subitems = [el for el in style.childNodes
if el.nodeType == xml.dom.Node.ELEMENT_NODE
and el.tagName == "text:list-level-style-number"]
if el.nodeType == xml.dom.Node.ELEMENT_NODE and el.tagName == "text:list-level-style-number"]
if len(subitems) > 0:
prop.setOrdered(True)
@ -311,8 +305,7 @@ class ODF2MoinMoin(object):
for i in range(numLines):
if (lines[i].strip() or i == numLines-1 or i == 0 or
not (lines[i-1].startswith(" ")
and lines[i+1].startswith(" "))):
not (lines[i-1].startswith(" ") and lines[i+1].startswith(" "))):
buffer.append("\n" + lines[i])
return ''.join(buffer)

View File

@ -1638,7 +1638,7 @@ dl.notes dd:last-of-type { page-break-after: avoid }
else:
if addsuffix:
outputfile = outputfile + ".html"
outputfp = file(outputfile, "w")
outputfp = open(outputfile, "wb")
outputfp.write(self.xhtml().encode('us-ascii','xmlcharrefreplace'))
outputfp.close()

View File

@ -24,7 +24,6 @@ from __future__ import print_function
import zipfile
from xml.sax import make_parser,handler
from xml.sax.xmlreader import InputSource
import xml.sax.saxutils
import io
MANIFESTNS="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0"

View File

@ -20,16 +20,28 @@
__doc__="""Use OpenDocument to generate your documents."""
import zipfile, time, sys, mimetypes
from .namespaces import *
from . import manifest, meta, element
from .office import *
from .attrconverters import make_NCName
from xml.sax.xmlreader import InputSource
from .odfmanifest import manifestlist
import mimetypes
import sys
import time
import zipfile
from io import BytesIO
from xml.sax.xmlreader import InputSource
from polyglot.io import PolyglotBytesIO, PolyglotStringIO
from . import element, manifest, meta
from .attrconverters import make_NCName
from .namespaces import (
CHARTNS, DRAWNS, METANS, OFFICENS, PRESENTATIONNS, STYLENS, TABLENS, TEXTNS,
TOOLSVERSION
)
from .odfmanifest import manifestlist
from .office import (
AutomaticStyles, Body, Chart, Document, DocumentContent, DocumentMeta,
DocumentSettings, DocumentStyles, Drawing, FontFaceDecls, Image, MasterStyles,
Meta, Presentation, Scripts, Settings, Spreadsheet, Styles, Text
)
__version__= TOOLSVERSION
_XMLPROLOGUE = u"<?xml version='1.0' encoding='UTF-8'?>\n"
@ -160,7 +172,7 @@ class OpenDocument:
if not filename:
return xml.getvalue()
else:
f=file(filename,'wb')
f=open(filename,'wb')
f.write(xml.getvalue())
f.close()
@ -365,11 +377,9 @@ class OpenDocument:
return ".%s" % document.folder
def _savePictures(self, object, folder):
hasPictures = False
for arcname, picturerec in object.Pictures.items():
what_it_is, fileobj, mediatype = picturerec
self.manifest.addElement(manifest.FileEntry(fullpath="%s%s" % (folder ,arcname), mediatype=mediatype))
hasPictures = True
if what_it_is == IS_FILENAME:
self._z.write(fileobj, arcname, zipfile.ZIP_STORED)
else:
@ -516,7 +526,7 @@ class OpenDocument:
def createCDATASection(self, data):
""" Method to create a CDATA section """
return element.CDATASection(cdata)
return element.CDATASection(data)
def getMediaType(self):
""" Returns the media type """

View File

@ -24,7 +24,7 @@ from .element import Element
def StyleElement(**args):
e = Element(**args)
if args.get('check_grammar', True) == True:
if args.get('check_grammar', True) is True:
if 'displayname' not in args:
e.setAttrNS(STYLENS,'display-name', args.get('name'))
return e

View File

@ -20,7 +20,7 @@
from .namespaces import SVGNS
from .element import Element
from draw import DrawElement
from .draw import DrawElement
# Autogenerated

View File

@ -27,9 +27,8 @@ the appropriate <text:s>, <text:tab>, or <text:line-break>
elements. This module takes care of that problem.
"""
from odf.element import Node
import odf.opendocument
from odf.text import S,LineBreak,Tab
from .element import Node
from .text import S,LineBreak,Tab
class WhitespaceText(object):

View File

@ -424,6 +424,6 @@ def thumbnail():
if __name__ == "__main__":
icon = thumbnail()
f = file("thumbnail.png","wb")
f = open("thumbnail.png","wb")
f.write(icon)
f.close()