mirror of
https://github.com/kovidgoyal/calibre.git
synced 2026-05-27 01:02:34 -04:00
Fix syntax errors
Command used: futurize --no-diffs -f libfuturize.fixes.fix_print_with_import -f lib2to3.fixes.fix_throw -f lib2to3.fixes.fix_numliterals -f lib2to3.fixes.fix_except -f lib2to3.fixes.fix_exec -f lib2to3.fixes.fix_raise -f lib2to3.fixes.fix_tuple_params -f lib2to3.fixes.fix_ne -j20 -w -n setup recipes src manual setup.py recipes/*.recipe And manual adjustments of print((...)) -> print(...)
This commit is contained in:
committed by
Kovid Goyal
parent
2aacfeffa5
commit
0889ee85ec
+15
-15
@@ -48,12 +48,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
|
||||
@@ -79,7 +79,7 @@ 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):
|
||||
@@ -112,7 +112,7 @@ def cnv_integer(attribute, arg, element):
|
||||
|
||||
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))')
|
||||
@@ -123,7 +123,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):
|
||||
@@ -133,17 +133,17 @@ def cnv_lengthorpercent(attribute, arg, element):
|
||||
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_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)
|
||||
|
||||
pattern_namespacedToken = re.compile(r'[0-9a-zA-Z_]+:[0-9a-zA-Z._\-]+')
|
||||
|
||||
@@ -151,7 +151,7 @@ def cnv_namespacedToken(attribute, arg, element):
|
||||
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):
|
||||
@@ -195,7 +195,7 @@ pattern_percent = re.compile(r'-?([0-9]+(\.[0-9]*)?|\.[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
|
||||
@@ -205,13 +205,13 @@ def cnv_points(attribute, arg, element):
|
||||
global pattern_points
|
||||
if 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):
|
||||
@@ -222,7 +222,7 @@ def cnv_string(attribute, arg, element):
|
||||
|
||||
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
|
||||
@@ -237,12 +237,12 @@ pattern_viewbox = re.compile(r'-?[0-9]+([ ]+-?[0-9]+){3}$')
|
||||
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)
|
||||
|
||||
|
||||
|
||||
+2
-2
@@ -30,7 +30,7 @@ def StyleRefElement(stylename=None, classnames=None, **args):
|
||||
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,7 +38,7 @@ def StyleRefElement(stylename=None, classnames=None, **args):
|
||||
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):
|
||||
|
||||
+11
-11
@@ -116,7 +116,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 +148,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)
|
||||
@@ -324,7 +324,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
|
||||
@@ -360,7 +360,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 +371,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 +381,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 +393,12 @@ class Element(Node):
|
||||
prefix, localname = attr
|
||||
self.removeAttrNS(prefix, localname)
|
||||
else:
|
||||
raise AttributeError, "Unable to add simple attribute - use (namespace, localpart)"
|
||||
raise AttributeError("Unable to add simple attribute - use (namespace, localpart)")
|
||||
else:
|
||||
# Construct a list of allowed arguments
|
||||
allowed_args = [ a[1].lower().replace('-','') for a in allowed_attrs]
|
||||
if check_grammar and attr not in allowed_args:
|
||||
raise AttributeError, "Attribute %s is not allowed in <%s>" % ( attr, self.tagName)
|
||||
raise AttributeError("Attribute %s is not allowed in <%s>" % ( attr, self.tagName))
|
||||
i = allowed_args.index(attr)
|
||||
self.removeAttrNS(allowed_attrs[i][0], allowed_attrs[i][1])
|
||||
|
||||
@@ -416,12 +416,12 @@ class Element(Node):
|
||||
prefix, localname = attr
|
||||
self.setAttrNS(prefix, localname, value)
|
||||
else:
|
||||
raise AttributeError, "Unable to add simple attribute - use (namespace, localpart)"
|
||||
raise AttributeError("Unable to add simple attribute - use (namespace, localpart)")
|
||||
else:
|
||||
# Construct a list of allowed arguments
|
||||
allowed_args = [ a[1].lower().replace('-','') for a in allowed_attrs]
|
||||
if check_grammar and attr not in allowed_args:
|
||||
raise AttributeError, "Attribute %s is not allowed in <%s>" % ( attr, self.tagName)
|
||||
raise AttributeError("Attribute %s is not allowed in <%s>" % ( attr, self.tagName))
|
||||
i = allowed_args.index(attr)
|
||||
self.setAttrNS(allowed_attrs[i][0], allowed_attrs[i][1], value)
|
||||
|
||||
@@ -455,7 +455,7 @@ class Element(Node):
|
||||
prefix, localname = attr
|
||||
return self.getAttrNS(prefix, localname)
|
||||
else:
|
||||
raise AttributeError, "Unable to get simple attribute - use (namespace, localpart)"
|
||||
raise AttributeError("Unable to get simple attribute - use (namespace, localpart)")
|
||||
else:
|
||||
# Construct a list of allowed arguments
|
||||
allowed_args = [ a[1].lower().replace('-','') for a in allowed_attrs]
|
||||
|
||||
+3
-2
@@ -25,6 +25,7 @@
|
||||
# the structure again.
|
||||
|
||||
from xml.sax import handler
|
||||
from __future__ import print_function
|
||||
from element import Element
|
||||
from namespaces import OFFICENS
|
||||
|
||||
@@ -71,8 +72,8 @@ class LoadParser(handler.ContentHandler):
|
||||
try:
|
||||
e = Element(qname = tag, qattributes=attrdict, check_grammar=False)
|
||||
self.curr = e
|
||||
except AttributeError, v:
|
||||
print "Error: %s" % v
|
||||
except AttributeError as v:
|
||||
print("Error: %s" % v)
|
||||
|
||||
if tag == (OFFICENS, 'automatic-styles'):
|
||||
e = self.doc.automaticstyles
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
# This script lists the content of the manifest.xml file
|
||||
import zipfile
|
||||
from __future__ import print_function
|
||||
from xml.sax import make_parser,handler
|
||||
from xml.sax.xmlreader import InputSource
|
||||
import xml.sax.saxutils
|
||||
@@ -112,5 +113,5 @@ if __name__ == "__main__":
|
||||
import sys
|
||||
result = odfmanifest(sys.argv[1])
|
||||
for file in result.values():
|
||||
print "%-40s %-40s" % (file['media-type'], file['full-path'])
|
||||
print("%-40s %-40s" % (file['media-type'], file['full-path']))
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ __version__= TOOLSVERSION
|
||||
|
||||
_XMLPROLOGUE = u"<?xml version='1.0' encoding='UTF-8'?>\n"
|
||||
|
||||
UNIXPERMS = 0100644 << 16L # -rw-r--r--
|
||||
UNIXPERMS = 0o100644 << 16 # -rw-r--r--
|
||||
|
||||
IS_FILENAME = 0
|
||||
IS_IMAGE = 1
|
||||
@@ -601,7 +601,7 @@ def __loadxmlparts(z, manifest, doc, objectpath):
|
||||
parser.setFeature(handler.feature_external_ges, False) # Changed by Kovid to ignore external DTDs
|
||||
parser.parse(inpsrc)
|
||||
del doc._parsing
|
||||
except KeyError, v: pass
|
||||
except KeyError as v: pass
|
||||
|
||||
def load(odffile):
|
||||
""" Load an ODF file into memory
|
||||
|
||||
Reference in New Issue
Block a user