diff --git a/.gitignore b/.gitignore index bbcbead..094470d 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,5 @@ pip-log.txt #Translations *.mo +.virtualenv +tmp/ \ No newline at end of file diff --git a/INSTALL b/INSTALL index b076748..4b1b73b 100755 --- a/INSTALL +++ b/INSTALL @@ -1,7 +1,7 @@ Install Dependencies: - - python >= 2.6: http://www.python.org/ + - python >= 3.6: http://www.python.org/ - python setuptools: https://pypi.python.org/pypi/setuptools - - lxml >= 2.0: http://codespeak.net/lxml/ + - lxml >= 4.5: http://codespeak.net/lxml/ - recommanded : Python Imaging Library (PIL) Dependencies Packages: diff --git a/README.md b/README.md index 6ef62c2..fb6bf47 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -lpod-python +lpod-python3 =========== Python library implementing the ISO/IEC 26300 OpenDocument Format standard. @@ -18,12 +18,11 @@ Maintained branches are: The most recent version of this package is there: - https://github.com/lpod/lpod-python + https://github.com/gosha20777/lpod-python3 How to get the code with git: - git clone git://github.com/lpod/lpod-python.git - git checkout current + git clone https://github.com/gosha20777/lpod-python3.git Documentation: see the ./documentation/html folder. @@ -48,6 +47,6 @@ About the Lpod Project, see: http://lpod-project.net -Architect: Jean-Marie Gouarn� +Architect: Jean-Marie Gouarn� Coordinator: Luis Belmar-Letelier diff --git a/doc_make/conf.py b/doc_make/conf.py index ad42c1b..98379b8 100644 --- a/doc_make/conf.py +++ b/doc_make/conf.py @@ -21,7 +21,7 @@ try: import lpod except ImportError: - print "\nError: You must first install lpod on your python" + print("\nError: You must first install lpod on your python") exit(1) # If your extensions are in another directory, add it here. If the directory @@ -49,8 +49,8 @@ master_doc = 'index' # General information about the project. -project = u'lpOD-python' -copyright = u'2009-2013, lpOD team' +project = 'lpOD-python' +copyright = '2009-2013, lpOD team' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -187,8 +187,8 @@ # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, document class [howto/manual]). latex_documents = [ - ('index', 'lpod.tex', ur'LPOD-Python Documentation', - ur'LPOD team', 'manual'), + ('index', 'lpod.tex', r'LPOD-Python Documentation', + r'LPOD team', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of @@ -256,7 +256,7 @@ def setup(app): synopsis = "Lpod %s module" % module # And the save the file - print 'Make "%s" module autodoc' % module + print('Make "%s" module autodoc' % module) rst_file = open("autodocs/%s.rst" % module, "w") rst_file.write(template_module.format(module=module, synopsis=synopsis)) diff --git a/lpod/__init__.py b/lpod/__init__.py index 54a5ea6..195308f 100644 --- a/lpod/__init__.py +++ b/lpod/__init__.py @@ -27,30 +27,30 @@ # # Import from lpod -from utils import _get_abspath -from _version import __version__ +from .utils import _get_abspath +from ._version import __version__ __installation_path__ = _get_abspath('') # Constants at the first level -from const import * +from .const import * # Register element classes -import draw_page -import frame -import heading -import list -import note -import paragraph -import section -import shapes -import span -import style -import table -import toc -import tracked_changes +from . import draw_page +from . import frame +from . import heading +from . import list +from . import note +from . import paragraph +from . import section +from . import shapes +from . import span +from . import style +from . import table +from . import toc +from . import tracked_changes # Silent pyflakes draw_page, frame, heading, list, note, paragraph, section, shapes, span, diff --git a/lpod/bookmark.py b/lpod/bookmark.py index 04a3545..072112b 100644 --- a/lpod/bookmark.py +++ b/lpod/bookmark.py @@ -25,7 +25,7 @@ # # Import from lpod -from element import odf_create_element +from .element import odf_create_element def odf_create_bookmark(name): diff --git a/lpod/container.py b/lpod/container.py index 359fa95..5ce2d47 100644 --- a/lpod/container.py +++ b/lpod/container.py @@ -30,16 +30,16 @@ import sys import shutil from copy import deepcopy -from cStringIO import StringIO +from io import StringIO, BytesIO from zipfile import ZIP_DEFLATED, ZIP_STORED, ZipFile, BadZipfile # Import from lpod -from const import ODF_MIMETYPES, ODF_PARTS, ODF_TYPES, ODF_MANIFEST -from const import ODF_CONTENT, ODF_META, ODF_SETTINGS, ODF_STYLES -from const import ODF_EXTENSIONS -from manifest import odf_manifest -from utils import _get_abspath #, obsolete -from scriptutils import printwarn +from .const import ODF_MIMETYPES, ODF_PARTS, ODF_TYPES, ODF_MANIFEST +from .const import ODF_CONTENT, ODF_META, ODF_SETTINGS, ODF_STYLES +from .const import ODF_EXTENSIONS +from .manifest import odf_manifest +from .utils import _get_abspath #, obsolete +from .scriptutils import printwarn class odf_container(object): @@ -53,7 +53,7 @@ class odf_container(object): def __init__(self, path_or_file): want_folder = False - if isinstance(path_or_file, basestring): + if isinstance(path_or_file, str): # Path self.path = path = path_or_file if os.path.isdir(path): # opening a folder @@ -73,7 +73,7 @@ def __init__(self, path_or_file): printwarn ("corrupted or not an OpenDocument folder (missing mimetype)") mimetype = '' timestamp = None - if mimetype not in ODF_MIMETYPES: + if mimetype.decode() not in ODF_MIMETYPES: message = 'Document of unknown type "%s", trying with ODF_TEXT.' % mimetype printwarn(message) mimetype = ODF_EXTENSIONS['odt'] @@ -95,7 +95,7 @@ def __init__(self, path_or_file): except ValueError: raise ValueError("bad OpenDocument format") self.__packaging = 'flat' - if mimetype not in ODF_MIMETYPES: + if mimetype.decode() not in ODF_MIMETYPES: message = 'Document of unknown type "%s"' % mimetype raise ValueError(message) self.__parts = {'mimetype': mimetype} @@ -154,7 +154,7 @@ def __get_zipfile(self): if self.__zipfile is None: data = self.__get_data() # StringIO will not duplicate the string, how big it is - filelike = StringIO(data) + filelike = BytesIO(data) self.__zipfile = ZipFile(filelike) return self.__zipfile @@ -187,7 +187,7 @@ def __save_zip(self, file): compression = ZIP_STORED filezip = ZipFile(file, 'w', compression=compression) # Parts to save, except manifest at the end - part_names = parts.keys() + part_names = list(parts.keys()) try: part_names.remove(ODF_MANIFEST) except KeyError: @@ -276,23 +276,23 @@ def dump(path, content): file_name = os.path.join(folder, path) dir_name = os.path.dirname(file_name) if not os.path.exists(dir_name): - os.makedirs(dir_name, mode=0755) - if path.endswith(u'/') : # folder + os.makedirs(dir_name, mode=0o755) + if path.endswith('/') : # folder if not os.path.isdir(file_name): - os.makedirs(file_name.encode(encoding), mode=0777) + os.makedirs(file_name.encode(encoding), mode=0o777) else: - open(file_name.encode(encoding), 'wb', 0666).write(content) + open(file_name.encode(encoding), 'wb', 0o666).write(content) - if isinstance(folder, basestring) and not isinstance(folder, unicode): + if isinstance(folder, str) and not isinstance(folder, str): folder = folder.decode(encoding) # Parts were loaded by "save" parts = self.__parts # Parts to save, except manifest at the end - part_names = parts.keys() + part_names = list(parts.keys()) try: part_names.remove(ODF_MANIFEST) except KeyError: - printwarn(u"missing '%s'" % ODF_MANIFEST) + printwarn("missing '%s'" % ODF_MANIFEST) # "Pretty-save" parts in some order # mimetype requires to be first and uncompressed try: @@ -422,7 +422,7 @@ def save(self, target=None, packaging=None, backup=False): backup -- boolean """ - if isinstance(target, basestring) and not isinstance(target, unicode): + if isinstance(target, str) and not isinstance(target, str): encoding = sys.getfilesystemencoding() target = target.decode(encoding) parts = self.__parts @@ -443,13 +443,13 @@ def save(self, target=None, packaging=None, backup=False): close_after = False if target is None: target = self.path - if isinstance(target, basestring): + if isinstance(target, str): while target.endswith(os.sep): target = target[:-1] while target.endswith('.folder'): target = target.split('.folder', 1)[0] if packaging in ('zip', 'flat'): - if isinstance(target, basestring): + if isinstance(target, str): if backup: self._do_backup(target) dest_file = open(target, 'wb') @@ -457,7 +457,7 @@ def save(self, target=None, packaging=None, backup=False): else: dest_file = target if packaging == 'folder': - if not isinstance(target, basestring): + if not isinstance(target, str): raise ValueError("Saving in folder format requires a folder " "name, not %s." % target) if not target.endswith('.folder'): @@ -471,7 +471,7 @@ def save(self, target=None, packaging=None, backup=False): except Exception as e: printwarn(str(e)) - os.mkdir(target, 0777) + os.mkdir(target, 0o777) dest_file = target # Serialize if packaging == 'zip': @@ -503,7 +503,7 @@ def odf_new_container(path_or_file): # Return a copy of the template container clone = template_container.clone() # Change type from template to regular - mimetype = clone.get_part('mimetype').replace('-template', '') + mimetype = clone.get_part('mimetype').decode().replace('-template', '') clone.set_part('mimetype', mimetype) # Update the manifest manifest = odf_manifest(ODF_MANIFEST, clone) diff --git a/lpod/content.py b/lpod/content.py index df2247d..098845d 100644 --- a/lpod/content.py +++ b/lpod/content.py @@ -28,7 +28,7 @@ # Import from lpod #from utils import obsolete -from xmlpart import odf_xmlpart +from .xmlpart import odf_xmlpart class odf_content(odf_xmlpart): diff --git a/lpod/datatype.py b/lpod/datatype.py index bc5f1d5..5656e25 100644 --- a/lpod/datatype.py +++ b/lpod/datatype.py @@ -168,7 +168,7 @@ def encode(value): class Unit(object): def __init__(self, value, unit='cm'): - if isinstance(value, basestring): + if isinstance(value, str): digits = [] nondigits = [] for char in value: diff --git a/lpod/document.py b/lpod/document.py index 18e54f9..0187248 100644 --- a/lpod/document.py +++ b/lpod/document.py @@ -36,18 +36,18 @@ from uuid import uuid4 # Import from lpod -from __init__ import __version__ -from const import ODF_CONTENT, ODF_META, ODF_SETTINGS, ODF_STYLES -from const import ODF_MANIFEST -from container import odf_get_container, odf_new_container, odf_container -from content import odf_content -from manifest import odf_manifest -from meta import odf_meta -from style import odf_style, odf_master_page, odf_font_style, odf_page_layout -from style import registered_styles -from styles import odf_styles +from .__init__ import __version__ +from .const import ODF_CONTENT, ODF_META, ODF_SETTINGS, ODF_STYLES +from .const import ODF_MANIFEST +from .container import odf_get_container, odf_new_container, odf_container +from .content import odf_content +from .manifest import odf_manifest +from .meta import odf_meta +from .style import odf_style, odf_master_page, odf_font_style, odf_page_layout +from .style import registered_styles +from .styles import odf_styles #from utils import obsolete -from xmlpart import odf_xmlpart +from .xmlpart import odf_xmlpart underline_lvl = ['=', '-', ':', '`', "'", '"', '~', '^', '_', '*', '+'] @@ -70,8 +70,8 @@ def _show_styles(element, level=0): output[-1] += '\n' attrs = [] # Attributes - for key, value in attributes.iteritems(): - attrs.append(u'%s: %s' % (key, value)) + for key, value in attributes.items(): + attrs.append('%s: %s' % (key, value)) if attrs: attrs.sort() # Add a separation between attributes and children @@ -243,16 +243,16 @@ def get_formatted_text(self, rst_mode=False): # Separate text from notes if footnotes: if rst_mode: - result.append(u'\n') + result.append('\n') else: - result.append(u'----\n') + result.append('----\n') for citation, body in footnotes: if rst_mode: - result.append(u'.. [#] %s\n' % body) + result.append('.. [#] %s\n' % body) else: - result.append(u'[%s] %s\n' % (citation, body)) + result.append('[%s] %s\n' % (citation, body)) # Append a \n after the notes - result.append(u'\n') + result.append('\n') # Reset for the next paragraph context['footnotes'] = [] # Insert the annotations @@ -260,9 +260,9 @@ def get_formatted_text(self, rst_mode=False): # With a separation if annotations: if rst_mode: - result.append(u'\n') + result.append('\n') else: - result.append(u'----\n') + result.append('----\n') for annotation in annotations: if rst_mode: result.append('.. [#] %s\n' % annotation) @@ -272,29 +272,29 @@ def get_formatted_text(self, rst_mode=False): # Insert the images ref, only in rst mode images = context['images'] if images: - result.append(u'\n') + result.append('\n') for ref, filename, (width, height) in images: - result.append(u'.. %s image:: %s\n' % + result.append('.. %s image:: %s\n' % (ref, filename)) if width is not None: - result.append(u' :width: %s\n' % width) + result.append(' :width: %s\n' % width) if height is not None: - result.append(u' :height: %s\n' % height) - result.append(u'\n') + result.append(' :height: %s\n' % height) + result.append('\n') context['images'] = [] # Append the end notes endnotes = context['endnotes'] if endnotes: if rst_mode: - result.append(u'\n\n') + result.append('\n\n') else: - result.append(u'\n========\n') + result.append('\n========\n') for citation, body in endnotes: if rst_mode: - result.append(u'.. [*] %s\n' % body) + result.append('.. [*] %s\n' % body) else: - result.append(u'(%s) %s\n' % (citation, body)) - return u''.join(result) + result.append('(%s) %s\n' % (citation, body)) + return ''.join(result) def get_formated_meta(self): @@ -321,7 +321,7 @@ def print_info(name, value): # Statistic result.append("Statistic:") statistic = meta.get_statistic() - for name, value in statistic.iteritems(): + for name, value in statistic.items(): result.append(" - %s: %s" % ( name[5:].replace('-', ' ').capitalize(), value)) @@ -329,13 +329,13 @@ def print_info(name, value): # User defined metadata result.append("User defined metadata:") user_metadata = meta.get_user_defined_metadata() - for name, value in user_metadata.iteritems(): + for name, value in user_metadata.items(): result.append(" - %s: %s" % (name, value)) # And the description print_info("Description", meta.get_description()) - return u"\n".join(result) + '\n' + return "\n".join(result) + '\n' def add_file(self, path_or_file): @@ -354,7 +354,7 @@ def add_file(self, path_or_file): manifest = self.get_part(ODF_MANIFEST) medias = manifest.get_paths() - if type(path_or_file) is unicode or type(path_or_file) is str: + if type(path_or_file) is str or type(path_or_file) is str: path_or_file = path_or_file.encode('utf_8') handler = open(path_or_file, 'rb') name = path_or_file @@ -405,7 +405,7 @@ def clone(self): setattr(clone, name, self.container.clone()) elif name == '_odf_document__xmlparts': xmlparts = {} - for key, value in self.__xmlparts.iteritems(): + for key, value in self.__xmlparts.items(): xmlparts[key] = value.clone() setattr(clone, name, xmlparts) else: @@ -434,10 +434,10 @@ def save(self, target=None, packaging=None, pretty=False, backup=False): # Some advertising meta = self.get_part(ODF_META) if not meta._generator_modified: - meta.set_generator(u"lpOD Python %s" % __version__) + meta.set_generator("lpOD Python %s" % __version__) # Synchronize data with container container = self.container - for path, part in self.__xmlparts.iteritems(): + for path, part in self.__xmlparts.items(): if part is not None: container.set_part(path, part.serialize(pretty)) # Save the container @@ -634,35 +634,35 @@ def show_styles(self, automatic=True, common=True, properties=False): or not is_auto and common is False): continue is_used = bool(self.get_styled_elements(name)) - infos.append({'type': u"auto " if is_auto else u"common", - 'used': u"y" if is_used else u"n", - 'family': style.get_family() or u"", - 'parent': style.get_parent_style() or u"", - 'name': name or u"", + infos.append({'type': "auto " if is_auto else "common", + 'used': "y" if is_used else "n", + 'family': style.get_family() or "", + 'parent': style.get_parent_style() or "", + 'name': name or "", 'display_name': style.get_display_name(), 'properties': style.get_properties() if properties else None}) if not infos: - return u"" + return "" # Sort by family and name infos.sort(key=itemgetter('family', 'name')) # Show common and used first infos.sort(key=itemgetter('type', 'used'), reverse=True) - max_family = unicode(max([len(x['family']) for x in infos])) - max_parent = unicode(max([len(x['parent']) for x in infos])) - format = (u"%(type)s used:%(used)s family:%(family)-0" + max_family - + u"s parent:%(parent)-0" + max_parent + u"s name:%(name)s") + max_family = str(max([len(x['family']) for x in infos])) + max_parent = str(max([len(x['parent']) for x in infos])) + format = ("%(type)s used:%(used)s family:%(family)-0" + max_family + + "s parent:%(parent)-0" + max_parent + "s name:%(name)s") output = [] for info in infos: line = format % info if info['display_name']: - line += u' display_name:' + info['display_name'] + line += ' display_name:' + info['display_name'] output.append(line) if info['properties']: - for name, value in info['properties'].iteritems(): + for name, value in info['properties'].items(): output.append(" - %s: %s" % (name, value)) - output.append(u"") - return u"\n".join(output) + output.append("") + return "\n".join(output) def delete_styles(self): diff --git a/lpod/draw_page.py b/lpod/draw_page.py index 61807c0..2810756 100644 --- a/lpod/draw_page.py +++ b/lpod/draw_page.py @@ -25,9 +25,9 @@ # # Import from lpod -from element import register_element_class, odf_element, odf_create_element -from shapes import registered_shapes -from smil import odf_create_anim_par, odf_create_anim_transitionFilter +from .element import register_element_class, odf_element, odf_create_element +from .shapes import registered_shapes +from .smil import odf_create_anim_par, odf_create_anim_transitionFilter def odf_create_draw_page(page_id=None, name=None, master_page=None, @@ -144,10 +144,10 @@ def get_formatted_text(self, context): # and frames, that we already handle for child in element.get_children(): result.append(child.get_formatted_text(context)) - result.append(u"\n") + result.append("\n") result.append(element.get_formatted_text(context)) - result.append(u"\n") - return u"".join(result) + result.append("\n") + return "".join(result) diff --git a/lpod/element.py b/lpod/element.py index 6f69922..5490ba5 100644 --- a/lpod/element.py +++ b/lpod/element.py @@ -37,10 +37,10 @@ from lxml.etree import XPath # Import from lpod -from datatype import DateTime, Boolean -from utils import _get_abspath, _get_elements, _get_element -from utils import _get_style_tagname, get_value #, obsolete -from utils import _get_style_tagname, get_value +from .datatype import DateTime, Boolean +from .utils import _get_abspath, _get_elements, _get_element +from .utils import _get_style_tagname, get_value #, obsolete +from .utils import _get_style_tagname, get_value ODF_NAMESPACES = { @@ -79,7 +79,7 @@ } -FIRST_CHILD, LAST_CHILD, NEXT_SIBLING, PREV_SIBLING, STOPMARKER = range(5) +FIRST_CHILD, LAST_CHILD, NEXT_SIBLING, PREV_SIBLING, STOPMARKER = list(range(5)) ns_stripper = re.compile(r' xmlns:\w*="[\w:\-\/\.#]*"') @@ -111,7 +111,7 @@ def _decode_qname(qname): def _uri_to_prefix(uri): """Find the prefix associated to the given URI. """ - for key, value in ODF_NAMESPACES.iteritems(): + for key, value in ODF_NAMESPACES.items(): if value == uri: return key raise ValueError('uri "%s" not found' % uri) @@ -214,19 +214,24 @@ def _make_odf_element(native_element, cache=None): def odf_create_element(element_data, cache=None): if type(element_data) is str: pass - elif type(element_data) is unicode: - element_data = element_data.encode('utf-8') else: raise TypeError("element data is not str or unicode") element_data = element_data.strip() + #element_data = element_data.encode('utf-8') if not element_data: raise ValueError("element data is empty") if '<' not in element_data: # Qualified name # XXX don't build the element from scratch or lxml will pollute with # repeated namespace declarations - element_data = '<%s/>' % element_data + if type(element_data) is str: + element_data = element_data.encode() + element_data = f'<{element_data.decode()}/>' # XML fragment + if type(element_data) is str: + element_data = element_data.encode() + + t = element_data.decode() data = ns_document_data % element_data root = fromstring(data) element = root[0] @@ -240,7 +245,7 @@ def _debug_element(native_element): -class odf_text(unicode): +class odf_text(str): """Representation of an XML text node. Created to hide the specifics of lxml in searching text nodes using XPath. @@ -591,7 +596,7 @@ def _get_element_idx2(self, xpath_instance, idx): def get_attributes(self): attributes = {} element = self.__element - for key, value in element.attrib.iteritems(): + for key, value in element.attrib.items(): attributes[_get_prefixed_name(key)] = value # FIXME lxml has mixed bytestring and unicode return attributes @@ -607,7 +612,7 @@ def get_attribute(self, name): return None elif value in ('true', 'false'): return Boolean.decode(value) - return unicode(value) + return str(value) def set_attribute(self, name, value): @@ -648,11 +653,11 @@ def get_text(self, recursive=False): If recursive is True, all text contents of the subtree. """ if recursive: - return u''.join(self.__element.itertext()) + return ''.join(self.__element.itertext()) text = self.__element.text if text is None: return None - return unicode(text) + return str(text) def set_text(self, text): @@ -672,7 +677,7 @@ def get_tail(self): tail = self.__element.tail if tail is None: return None - return unicode(tail) + return str(tail) def set_tail(self, text): @@ -697,7 +702,7 @@ def search(self, pattern): """ if isinstance(pattern, str): # Fail properly if the pattern is an non-ascii bytestring - pattern = unicode(pattern) + pattern = str(pattern) text = self.get_text(recursive=True) match = re.search(pattern, text) if match is None: @@ -740,7 +745,7 @@ def replace(self, pattern, new=None): """ if isinstance(pattern, str): # Fail properly if the pattern is an non-ascii bytestring - pattern = unicode(pattern) + pattern = str(pattern) cpattern = re.compile(pattern) count = 0 for text in self.xpath('descendant::text()'): @@ -809,7 +814,7 @@ def get_text_content(self): text = [] for child in self.get_elements('descendant::text:p'): text.append(child.get_text(recursive=True)) - return u"\n".join(text) + return "\n".join(text) def _erase_text_content(self): @@ -1104,20 +1109,20 @@ def append(self, unicode_or_element): current = self.__element # Unicode ? - if isinstance(unicode_or_element, unicode): + if isinstance(unicode_or_element, str): # Has children ? children = current.getchildren() if children: # Append to tail of the last child last_child = children[-1] text = last_child.tail - text = text if text is not None else u"" + text = text if text is not None else "" text += unicode_or_element last_child.tail = text else: # Append to text of the element text = current.text - text = text if text is not None else u"" + text = text if text is not None else "" text += unicode_or_element current.text = text elif isinstance(unicode_or_element, odf_element): @@ -1267,7 +1272,7 @@ def _strip_tags(element, strip, protect, protected): return (element, False) element.clear() try: - for key, value in copy.get_attributes().iteritems(): + for key, value in copy.get_attributes().items(): element.set_attribute(key, value) except ValueError: sys.stderr.write("strip_tags(): bad attribute in %s\n" % copy) @@ -1377,7 +1382,7 @@ def replace_document_body(self, new_body): def get_formatted_text(self, context): """This function must return a beautiful version of the text """ - return u'' + return '' def get_styled_elements(self, name=True): diff --git a/lpod/experimental.py b/lpod/experimental.py index ae0393a..5574567 100644 --- a/lpod/experimental.py +++ b/lpod/experimental.py @@ -29,6 +29,6 @@ (aka experimental features) """ -import _flags +from . import _flags _flags.experimental.set(True) diff --git a/lpod/frame.py b/lpod/frame.py index d7bdf23..a163a36 100644 --- a/lpod/frame.py +++ b/lpod/frame.py @@ -26,12 +26,12 @@ # # Import from lpod -from element import odf_create_element, odf_element, register_element_class -from datatype import Unit -from image import odf_create_image -from paragraph import odf_create_paragraph -from style import odf_create_style -from utils import isiterable, DPI # , obsolete +from .element import odf_create_element, odf_element, register_element_class +from .datatype import Unit +from .image import odf_create_image +from .paragraph import odf_create_paragraph +from .style import odf_create_style +from .utils import isiterable, DPI # , obsolete @@ -202,7 +202,7 @@ def odf_create_text_frame(text_or_element=None, text_style=None, name=None, -def odf_create_frame_position_style(name=u"FramePosition", +def odf_create_frame_position_style(name="FramePosition", horizontal_pos="from-left", vertical_pos="from-top", horizontal_rel="paragraph", vertical_rel="paragraph"): """Helper style for positioning frames in desktop applications that need @@ -213,7 +213,7 @@ def odf_create_frame_position_style(name=u"FramePosition", Use the return value as the frame style or build a new graphic style with this style as the parent. """ - return odf_create_style('graphic', u"FramePositioning", + return odf_create_style('graphic', "FramePositioning", **{'style:horizontal-pos': "from-left", 'style:vertical-pos': "from-top", 'style:horizontal-rel': "paragraph", @@ -446,7 +446,7 @@ def set_text_box(self, text_or_element=None, text_style=None): if not isiterable(text_or_element): text_or_element = [text_or_element] for item in text_or_element: - if isinstance(item, unicode): + if isinstance(item, str): item = odf_create_paragraph(item, style=text_style) text_box.append(item) return text_box @@ -472,31 +472,31 @@ def get_formatted_text(self, context): # Insert or not ? if context['no_img_level']: context['img_counter'] += 1 - ref = u'|img%d|' % context['img_counter'] + ref = '|img%d|' % context['img_counter'] result.append(ref) context['images'].append( (ref, filename, (width, height) ) ) else: - result.append(u'\n.. image:: %s\n' % filename) + result.append('\n.. image:: %s\n' % filename) if width is not None: - result.append(u' :width: %s\n' % width) + result.append(' :width: %s\n' % width) if height is not None: - result.append(u' :height: %s\n' % height) + result.append(' :height: %s\n' % height) else: - result.append(u'[Image %s]\n' % + result.append('[Image %s]\n' % element.get_attribute('xlink:href')) elif tag == 'draw:text-box': - subresult = [u' '] + subresult = [' '] for element in element.get_children(): subresult.append(element.get_formatted_text(context)) - subresult = u''.join(subresult) - subresult = subresult.replace(u'\n', u'\n ') + subresult = ''.join(subresult) + subresult = subresult.replace('\n', '\n ') subresult.rstrip(' ') result.append(subresult) else: result.append(element.get_formatted_text(context)) - result.append(u'\n') - return u''.join(result) + result.append('\n') + return ''.join(result) diff --git a/lpod/future.py b/lpod/future.py index 888280d..85d7b9a 100644 --- a/lpod/future.py +++ b/lpod/future.py @@ -28,6 +28,6 @@ Loading his module activate the 'future' compatibility mode (aka versions 1.1+) """ -import _flags +from . import _flags _flags.future.set(True) diff --git a/lpod/heading.py b/lpod/heading.py index 7b934ad..da8ff8b 100644 --- a/lpod/heading.py +++ b/lpod/heading.py @@ -28,8 +28,8 @@ from re import sub # Import from lpod -from paragraph import odf_paragraph -from element import register_element_class, odf_create_element +from .paragraph import odf_paragraph +from .element import register_element_class, odf_create_element def odf_create_heading(level, text=None, restart_numbering=False, @@ -97,15 +97,15 @@ def get_formatted_text(self, context=None): # If here in rst_mode! # Get the level, max 5! - LEVEL_STYLES = u"#=-~`+^°'." + LEVEL_STYLES = "#=-~`+^°'." level = self.get_outline_level() if level > len(LEVEL_STYLES): - raise ValueError, "Too many levels of heading" + raise ValueError("Too many levels of heading") # And return the result - result = [u'\n', title, u'\n', LEVEL_STYLES[level - 1] * len(title), - u'\n'] - return u''.join(result) + result = ['\n', title, '\n', LEVEL_STYLES[level - 1] * len(title), + '\n'] + return ''.join(result) diff --git a/lpod/image.py b/lpod/image.py index 50c0a6c..056162c 100644 --- a/lpod/image.py +++ b/lpod/image.py @@ -25,7 +25,7 @@ # # Import from lpod -from element import odf_create_element, odf_element, register_element_class +from .element import odf_create_element, odf_element, register_element_class def odf_create_image(url, type='simple', show='embed', actuate='onLoad'): diff --git a/lpod/legacy.py b/lpod/legacy.py index cec51bd..1ea0882 100644 --- a/lpod/legacy.py +++ b/lpod/legacy.py @@ -28,7 +28,7 @@ Loading his module activate the 'legacy' compatibility mode (aka versions 0.9.x) """ -import _flags +from . import _flags _flags.legacy.set(True) diff --git a/lpod/link.py b/lpod/link.py index 3d735df..2f27e64 100644 --- a/lpod/link.py +++ b/lpod/link.py @@ -26,8 +26,8 @@ # # Import from lpod -from element import odf_element, odf_create_element, register_element_class -from paragraph import paragraph_base +from .element import odf_element, odf_create_element, register_element_class +from .paragraph import paragraph_base diff --git a/lpod/list.py b/lpod/list.py index ff3e012..e69a836 100644 --- a/lpod/list.py +++ b/lpod/list.py @@ -28,10 +28,10 @@ # Import from the Standard Library # Import from lpod -from element import register_element_class, odf_element, odf_create_element -from element import FIRST_CHILD, PREV_SIBLING, NEXT_SIBLING -from paragraph import odf_create_paragraph -from utils import _get_element, _get_elements, isiterable #, obsolete +from .element import register_element_class, odf_element, odf_create_element +from .element import FIRST_CHILD, PREV_SIBLING, NEXT_SIBLING +from .paragraph import odf_create_paragraph +from .utils import _get_element, _get_elements, isiterable #, obsolete def odf_create_list_item(text_or_element=None): @@ -49,12 +49,12 @@ def odf_create_list_item(text_or_element=None): Return: odf_element """ element = odf_create_element('text:list-item') - if type(text_or_element) is unicode: + if type(text_or_element) is str: element.set_text_content(text_or_element) elif isinstance(text_or_element, odf_element): element.append(text_or_element) elif text_or_element is not None: - raise TypeError, "expected unicode or odf_element" + raise TypeError("expected unicode or odf_element") return element @@ -140,7 +140,7 @@ def set_header(self, text_or_element): for element in self.get_elements('text:p'): self.delete(element) for paragraph in reversed(text_or_element): - if type(paragraph) is unicode: + if type(paragraph) is str: paragraph = odf_create_paragraph(paragraph) self.insert(paragraph, FIRST_CHILD) @@ -158,7 +158,7 @@ def insert_item(self, item, position=None, before=None, after=None): elif position is not None: self.insert(item, position=position) else: - raise ValueError, "position must be defined" + raise ValueError("position must be defined") def append_item(self, item): @@ -184,19 +184,19 @@ def get_formatted_text(self, context): # A title in a list is a bug return text elif tag == 'text:list': - if not text.lstrip().startswith(u'-'): + if not text.lstrip().startswith('-'): # If the list didn't indent, don't either # (inner title) return text textbuf.append(text) - textbuf = u''.join(textbuf) + textbuf = ''.join(textbuf) textbuf = textbuf.strip('\n') # Indent the text - textbuf = u'- %s\n' % textbuf.replace(u'\n', u'\n ') + textbuf = '- %s\n' % textbuf.replace('\n', '\n ') result.append(textbuf) if rst_mode: result.append('\n') - return u''.join(result) + return ''.join(result) diff --git a/lpod/manifest.py b/lpod/manifest.py index fa5f8fb..a98f7a5 100644 --- a/lpod/manifest.py +++ b/lpod/manifest.py @@ -26,9 +26,9 @@ # # Import from lpod -from element import odf_create_element +from .element import odf_create_element #from utils import obsolete -from xmlpart import odf_xmlpart +from .xmlpart import odf_xmlpart def odf_create_file_entry(full_path, media_type): diff --git a/lpod/meta.py b/lpod/meta.py index fe4bd87..adb2acd 100644 --- a/lpod/meta.py +++ b/lpod/meta.py @@ -29,11 +29,11 @@ # Import from the Standard Library from datetime import timedelta, date, datetime from decimal import Decimal -from datatype import DateTime, Duration, Boolean, Date +from .datatype import DateTime, Duration, Boolean, Date # Import from lpod -from element import odf_create_element -from xmlpart import odf_xmlpart +from .element import odf_create_element +from .xmlpart import odf_xmlpart class odf_meta(odf_xmlpart): @@ -157,13 +157,13 @@ def set_language(self, language): """ if type(language) is not str: message = 'language must be "xx-YY" lang-COUNTRY code (RFC3066)' - raise TypeError, message + raise TypeError(message) # FIXME test validity? element = self.get_element('//dc:language') if element is None: element = odf_create_element('dc:language') self.get_meta_body().append(element) - element.set_text(unicode(language)) + element.set_text(str(language)) def get_modification_date(self): @@ -336,7 +336,7 @@ def set_editing_duration(self, duration): duration -- timedelta """ if type(duration) is not timedelta: - raise TypeError, u"duration must be a timedelta" + raise TypeError("duration must be a timedelta") element = self.get_element('//meta:editing-duration') if element is None: element = odf_create_element('meta:editing-duration') @@ -366,9 +366,9 @@ def set_editing_cycles(self, cycles): cycles -- int """ if type(cycles) is not int: - raise TypeError, u"cycles must be an int" + raise TypeError("cycles must be an int") if cycles < 1: - raise ValueError, "cycles must be a positive int" + raise ValueError("cycles must be a positive int") element = self.get_element('//meta:editing-cycles') if element is None: element = odf_create_element('meta:editing-cycles') @@ -432,7 +432,7 @@ def get_statistic(self): if element is None: return None statistic = {} - for key, value in element.get_attributes().iteritems(): + for key, value in element.get_attributes().items(): statistic[key] = int(value) return statistic @@ -457,13 +457,13 @@ def set_statistic(self, statistic): >>> document.set_statistic(statistic) """ if type(statistic) is not dict: - raise TypeError, "statistic must be a dict" + raise TypeError("statistic must be a dict") element = self.get_element('//meta:document-statistic') - for key, value in statistic.iteritems(): + for key, value in statistic.items(): if type(key) is not str: - raise TypeError, "statistic key must be a str" + raise TypeError("statistic key must be a str") if type(value) is not int: - raise TypeError, "statistic value must be a int" + raise TypeError("statistic value must be a int") element.set_attribute(key, str(value)) @@ -510,26 +510,26 @@ def get_user_defined_metadata_of_name(self, keyname): def set_user_defined_metadata(self, name, value): if type(value) is bool: value_type = 'boolean' - value = u'true' if value else u'false' + value = 'true' if value else 'false' elif isinstance(value, (int, float, Decimal)): value_type = 'float' - value = unicode(value) + value = str(value) elif type(value) is date: value_type = 'date' - value = unicode(Date.encode(value)) + value = str(Date.encode(value)) elif type(value) is datetime: value_type = 'date' - value = unicode(DateTime.encode(value)) + value = str(DateTime.encode(value)) elif type(value) is str: value_type = 'string' - value = unicode(value) - elif type(value) is unicode: + value = str(value) + elif type(value) is str: value_type = 'string' elif type(value) is timedelta: value_type = 'time' - value = unicode(Duration.encode(value)) + value = str(Duration.encode(value)) else: - raise TypeError, 'unexpected type "%s" for value' % type(value) + raise TypeError('unexpected type "%s" for value' % type(value)) # Already the same element ? for metadata in self.get_elements('//meta:user-defined'): if metadata.get_attribute('meta:name') == name: diff --git a/lpod/note.py b/lpod/note.py index 55f426b..1ac41e8 100644 --- a/lpod/note.py +++ b/lpod/note.py @@ -31,7 +31,7 @@ from types import FunctionType # Import from lpod -from element import odf_create_element, odf_element, register_element_class +from .element import odf_create_element, odf_element, register_element_class def odf_create_note(note_class='footnote', note_id=None, citation=None, @@ -83,7 +83,7 @@ def get_unique_office_name(element=None): used.extend(element.get_office_names()) i = 1 while True: - name = u'__Fieldmark__lpod_%s' % i + name = '__Fieldmark__lpod_%s' % i if name in used: i += 1 continue @@ -189,7 +189,7 @@ def get_body(self): def set_body(self, text_or_element): note_body = self.get_element('text:note-body') - if type(text_or_element) is unicode: + if type(text_or_element) is str: note_body.set_text_content(text_or_element) elif isinstance(text_or_element, odf_element): note_body.clear() @@ -219,7 +219,7 @@ def get_body(self): def set_body(self, text_or_element): - if type(text_or_element) is unicode: + if type(text_or_element) is str: self.set_text_content(text_or_element) elif isinstance(text_or_element, odf_element): self.clear() @@ -278,7 +278,7 @@ def get_annotated(self, as_text=False, no_header=True, clean=True): end = self.get_end() if end is None: if as_text: - return u'' + return '' return None body = self.get_document_body() if not body: diff --git a/lpod/paragraph.py b/lpod/paragraph.py index 004c762..a0cd732 100644 --- a/lpod/paragraph.py +++ b/lpod/paragraph.py @@ -32,21 +32,21 @@ from functools import wraps # for keeping trace of docstring with decorators # Import from lpod -from bookmark import odf_create_bookmark, odf_create_bookmark_start -from bookmark import odf_create_bookmark_end -from element import FIRST_CHILD, NEXT_SIBLING -from element import register_element_class, odf_element, odf_create_element -from paragraph_base import paragraph_base -from paragraph_base import odf_create_spaces -from paragraph_base import odf_create_tabulation -from paragraph_base import odf_create_line_break +from .bookmark import odf_create_bookmark, odf_create_bookmark_start +from .bookmark import odf_create_bookmark_end +from .element import FIRST_CHILD, NEXT_SIBLING +from .element import register_element_class, odf_element, odf_create_element +from .paragraph_base import paragraph_base +from .paragraph_base import odf_create_spaces +from .paragraph_base import odf_create_tabulation +from .paragraph_base import odf_create_line_break -from note import odf_create_note -from note import odf_create_annotation, odf_create_annotation_end -from reference import odf_create_reference_mark, odf_create_reference_mark_start -from reference import odf_create_reference_mark_end, odf_create_reference -from style import odf_style -from link import odf_create_link +from .note import odf_create_note +from .note import odf_create_annotation, odf_create_annotation_end +from .reference import odf_create_reference_mark, odf_create_reference_mark_start +from .reference import odf_create_reference_mark_end, odf_create_reference +from .style import odf_style +from .link import odf_create_link @@ -152,7 +152,7 @@ def wrapper(element, *args, **kwargs): upper.insert(result, position=index + 1) return if regex: - pattern = re.compile(unicode(regex), re.UNICODE) + pattern = re.compile(str(regex), re.UNICODE) for text in element.xpath('descendant::text()'): # Static information about the text node container = text.get_parent() @@ -208,7 +208,7 @@ def insert_note(self, note_element=None, after=None, if body: note_element.set_body(body) note_element.check_validity() - if type(after) is unicode: + if type(after) is str: self._insert(note_element, after=after, main_text=True) elif isinstance(after, odf_element): after.insert(note_element, FIRST_CHILD) @@ -339,7 +339,7 @@ def insert_annotation_end(self, annotation_element, before=None, if annotation_element is None: raise ValueError - if annotation_element.get_tag() != u'office:annotation': + if annotation_element.get_tag() != 'office:annotation': raise ValueError("Not a 'office:annotation' element") # remove existing end tag @@ -457,12 +457,12 @@ def set_reference_mark_end(self, reference_mark, before=None, position -- int """ - if reference_mark.get_tag() not in (u'text:reference-mark', - u'text:reference-mark-start'): + if reference_mark.get_tag() not in ('text:reference-mark', + 'text:reference-mark-start'): raise ValueError( "Not a 'text:reference-mark or text:reference-mark-start' element") name = reference_mark.get_name() - if reference_mark.get_tag() == u'text:reference-mark': + if reference_mark.get_tag() == 'text:reference-mark': # change it to a range reference: reference_mark._set_tag_raw('text:reference-mark-start') @@ -620,7 +620,7 @@ def insert_reference(self, name, ref_format='', before=None, after=None, if mark: display = mark.get_referenced_text() if not display: - display = u' ' + display = ' ' reference.set_text(display) if isinstance(after, odf_element): after.insert(reference, FIRST_CHILD) diff --git a/lpod/paragraph_base.py b/lpod/paragraph_base.py index d0e2fae..75a0023 100644 --- a/lpod/paragraph_base.py +++ b/lpod/paragraph_base.py @@ -31,12 +31,12 @@ import re # Import from lpod -from element import odf_text -from element import odf_element, odf_create_element +from .element import odf_text +from .element import odf_element, odf_create_element -_rsplitter = re.compile(u'(\n|\t| +)', re.UNICODE) -_rspace = re.compile(u'^ +$', re.UNICODE) +_rsplitter = re.compile('(\n|\t| +)', re.UNICODE) +_rspace = re.compile('^ +$', re.UNICODE) @@ -143,11 +143,11 @@ def _get_formatted_text(element, context, with_text=True): body = obj.get_body() container.append((citation, body)) if rst_mode: - marker = {'footnote': u" [#]_ ", - 'endnote': u" [*]_ "}[note_class] + marker = {'footnote': " [#]_ ", + 'endnote': " [*]_ "}[note_class] else: - marker = {'footnote': u"[{citation}]", - 'endnote': u"({citation})"}[note_class] + marker = {'footnote': "[{citation}]", + 'endnote': "({citation})"}[note_class] result.append(marker.format(citation=citation)) # Annotations elif tag == 'office:annotation': @@ -158,16 +158,16 @@ def _get_formatted_text(element, context, with_text=True): result.append('[*]') # Tabulation elif tag == 'text:tab': - result.append(u'\t') + result.append('\t') # Line break elif tag == 'text:line-break': if rst_mode: - result.append(u"\n|") + result.append("\n|") else: - result.append(u"\n") + result.append("\n") else: result.append(obj.get_formatted_text(context)) - return u''.join(result) + return ''.join(result) @@ -260,11 +260,11 @@ def get_formatted_text(self, context=None, simple=False): return content + '\n\n' - def append_plain_text(self, text=u'', encoding=None): + def append_plain_text(self, text='', encoding=None): """Append unicode plain text to the paragraph, replacing , and multiple spaces by ODF corresponding tags. """ - if not isinstance(text, unicode): + if not isinstance(text, str): if encoding: text = text.decode(encoding) else: @@ -273,15 +273,15 @@ def append_plain_text(self, text=u'', encoding=None): for b in blocs: if not b: continue - if b == u'\n': + if b == '\n': self.append(odf_create_line_break()) continue - if b == u'\t': + if b == '\t': self.append(odf_create_tabulation()) continue if _rspace.match(b): # follow ODF standard : n spaces => one space + spacer(n-1) - self.append(u' ') + self.append(' ') self.append(odf_create_spaces(len(b) - 1)) continue # standard piece of text: diff --git a/lpod/reference.py b/lpod/reference.py index 3d9c1a8..58b8940 100644 --- a/lpod/reference.py +++ b/lpod/reference.py @@ -26,7 +26,7 @@ # # Import from lpod -from element import odf_element, odf_create_element, register_element_class +from .element import odf_element, odf_create_element, register_element_class def _get_referenced(body, start, end, no_header, clean, as_xml, as_list): @@ -68,7 +68,7 @@ def set_name(self, name): def get_referenced_text(self): "Only usefull for for subclasses." - return u'' + return '' @@ -82,9 +82,9 @@ def get_referenced_text(self): """ name = self.get_name() args = {'name': name} - request = (u"//text()" - u"[preceding::text:reference-mark-start[@text:name='%(name)s'] " - u"and following::text:reference-mark-end[@text:name='%(name)s']]" + request = ("//text()" + "[preceding::text:reference-mark-start[@text:name='%(name)s'] " + "and following::text:reference-mark-end[@text:name='%(name)s']]" ) % args result = ' '.join(self.xpath(request)) return result @@ -115,7 +115,7 @@ def delete(self, child=None, keep_tail=True): name = self.get_name() parent = self.get_parent() if parent is None: - raise ValueError, "cannot delete the root element" + raise ValueError("cannot delete the root element") body = self.get_document_body() if not body: body = parent @@ -154,7 +154,7 @@ def get_referenced(self, no_header=False, clean=True, as_xml=False, name = self.get_name() parent = self.get_parent() if parent is None: - raise ValueError, "need some upper document part" + raise ValueError("need some upper document part") body = self.get_document_body() if not body: body = parent diff --git a/lpod/rst2odt.py b/lpod/rst2odt.py index 6e1e809..95a06c4 100644 --- a/lpod/rst2odt.py +++ b/lpod/rst2odt.py @@ -36,21 +36,21 @@ from PIL import Image # Import from lpod -from document import odf_new_document -from frame import odf_create_image_frame, odf_create_text_frame -from heading import odf_create_heading -from link import odf_create_link -from list import odf_create_list, odf_create_list_item -from note import odf_create_note -from paragraph import odf_create_paragraph, odf_create_line_break -from paragraph import odf_create_spaces -from span import odf_create_span -from scriptutils import printwarn -from style import odf_create_style -from table import odf_create_cell, odf_create_table, odf_create_row -from table import odf_create_column, odf_create_header_rows -from toc import odf_create_toc -from utils import DPI +from .document import odf_new_document +from .frame import odf_create_image_frame, odf_create_text_frame +from .heading import odf_create_heading +from .link import odf_create_link +from .list import odf_create_list, odf_create_list_item +from .note import odf_create_note +from .paragraph import odf_create_paragraph, odf_create_line_break +from .paragraph import odf_create_spaces +from .span import odf_create_span +from .scriptutils import printwarn +from .style import odf_create_style +from .table import odf_create_cell, odf_create_table, odf_create_row +from .table import odf_create_column, odf_create_header_rows +from .toc import odf_create_toc +from .utils import DPI @@ -269,7 +269,7 @@ def convert_literal_block(node, context): for c in text: if c == '\n': if tmp: - tmp = u"".join(tmp) + tmp = "".join(tmp) paragraph.append(tmp) tmp = [] spaces = 0 @@ -284,7 +284,7 @@ def convert_literal_block(node, context): else: if spaces >= 2: if tmp: - tmp = u"".join(tmp) + tmp = "".join(tmp) paragraph.append(tmp) tmp = [] paragraph.append(' ') @@ -296,7 +296,7 @@ def convert_literal_block(node, context): spaces = 0 tmp.append(c) if tmp: - tmp = u"".join(tmp) + tmp = "".join(tmp) paragraph.append(tmp) @@ -319,13 +319,13 @@ def _get_term_style(context): # Reuse template style if any doc = context['doc'] term_style = doc.get_style('paragraph', - u"Definition_20_List_20_Term") + "Definition_20_List_20_Term") if term_style is None: # Create default one term_style = odf_create_style('paragraph', - name=u"Definition_20_List_20_Term", - display_name=u"Definition List Term", parent="Standard", - font_weight=u"bold", area='text') + name="Definition_20_List_20_Term", + display_name="Definition List Term", parent="Standard", + font_weight="bold", area='text') doc.insert_style(term_style, automatic=False) styles['term'] = term_style return term_style @@ -340,15 +340,15 @@ def _get_definition_style(context): # Reuse template style if any doc = context['doc'] definition_style = doc.get_style('paragraph', - u"Definition_20_List_20_Definition") + "Definition_20_List_20_Definition") if definition_style is None: # Create default one definition_style = odf_create_style('paragraph', - name=u"Definition_20_List_20_Definition", - display_name=u"Definition List Definition", - parent="Standard", margin_left=u"0.5cm", - margin_right=u"0cm", text_indent=u"0cm", - **{'style:auto-text-indent': u"false"}) + name="Definition_20_List_20_Definition", + display_name="Definition List Definition", + parent="Standard", margin_left="0.5cm", + margin_right="0cm", text_indent="0cm", + **{'style:auto-text-indent': "false"}) doc.insert_style(definition_style, automatic=False) styles['definition'] = definition_style return definition_style @@ -401,12 +401,12 @@ def _get_caption_style(context): caption_style = styles.get('caption') if caption_style is not None: return caption_style - caption_style = odf_create_style('graphic', parent=u"Frame", - **{'style:wrap': u"none", 'style:vertical-pos': u"top", - 'style:vertical-rel': u"paragraph-content", - 'style:horizontal-pos': u"center", - 'style:horizontal-rel': u"paragraph-content", - 'fo:padding': u"0.25cm", 'fo:border': u"0cm solid #000000"}) + caption_style = odf_create_style('graphic', parent="Frame", + **{'style:wrap': "none", 'style:vertical-pos': "top", + 'style:vertical-rel': "paragraph-content", + 'style:horizontal-pos': "center", + 'style:horizontal-rel': "paragraph-content", + 'fo:padding': "0.25cm", 'fo:border': "0cm solid #000000"}) context['doc'].insert_style(caption_style, automatic=True) styles['caption'] = caption_style return caption_style @@ -419,8 +419,8 @@ def _get_image_style(context): if image_style is not None: return image_style image_style = odf_create_style('graphic', parent="Graphics", - **{'style:horizontal-pos': u"center", - 'style:horizontal-rel': u"paragraph"}) + **{'style:horizontal-pos': "center", + 'style:horizontal-rel': "paragraph"}) context['doc'].insert_style(image_style, automatic=True) styles['image'] = image_style return image_style @@ -433,7 +433,7 @@ def _add_image(image, caption, context, width=None, height=None): try: image_file = open(image.encode(encoding), 'rb') image_object = Image.open(image_file) - except (UnicodeEncodeError, IOError, OverflowError), e: + except (UnicodeEncodeError, IOError, OverflowError) as e: printwarn('unable to insert the image "%s": %s' % (image, e)) return size = image_object.size @@ -443,19 +443,19 @@ def _add_image(image, caption, context, width=None, height=None): try: width = int(width.replace('px', '')) except ValueError: - raise NotImplementedError, 'only pixel units supported' + raise NotImplementedError('only pixel units supported') if height: try: height = int(height.replace('px', '')) except ValueError: - raise NotImplementedError, 'only pixel units supported' + raise NotImplementedError('only pixel units supported') else: height = int(width / (float(size[0]) / float(size[1]))) elif height: try: height = int(height.replace('px', '')) except ValueError: - raise NotImplementedError, 'only pixel units supported' + raise NotImplementedError('only pixel units supported') width = int(height * (float(size[0]) / float(size[1]))) else: # If the information is not present, we assume a width of 640 px @@ -570,8 +570,8 @@ def _get_cell_style(context): if cell_style is not None: return cell_style # Give borders to cells - cell_style = odf_create_style('table-cell', u"odf_table.A1", - padding=u"0.049cm", border=u"0.002cm solid #000000") + cell_style = odf_create_style('table-cell', "odf_table.A1", + padding="0.049cm", border="0.002cm solid #000000") context['doc'].insert_style(cell_style, automatic=True) styles['cell'] = cell_style return cell_style @@ -658,7 +658,7 @@ def convert_node(node, context): return convert_method(node, context) message = "node not supported: %s" % tagname if context['strict']: - raise ValueError, message + raise ValueError(message) printwarn(message) diff --git a/lpod/scriptutils.py b/lpod/scriptutils.py index a4e9dcf..1d11b0c 100644 --- a/lpod/scriptutils.py +++ b/lpod/scriptutils.py @@ -27,7 +27,7 @@ # Import from the Standard Library from mimetypes import guess_type from os.path import exists, isfile -from StringIO import StringIO +from io import StringIO from sys import stdin, stdout, stderr # Import from lpod diff --git a/lpod/section.py b/lpod/section.py index 57107b6..8083dca 100644 --- a/lpod/section.py +++ b/lpod/section.py @@ -26,7 +26,7 @@ # # Import from lpod -from element import register_element_class, odf_element, odf_create_element +from .element import register_element_class, odf_element, odf_create_element @@ -62,8 +62,8 @@ def get_formatted_text(self, context): result = [] for element in self.get_children(): result.append(element.get_formatted_text(context)) - result.append(u'\n') - return u''.join(result) + result.append('\n') + return ''.join(result) diff --git a/lpod/shapes.py b/lpod/shapes.py index 1c91cab..f1820e5 100644 --- a/lpod/shapes.py +++ b/lpod/shapes.py @@ -26,7 +26,7 @@ # # Import from lpod -from element import odf_element, odf_create_element, register_element_class +from .element import odf_element, odf_create_element, register_element_class def _odf_create_shape(type, style=None, text_style=None, shape_id=None, @@ -301,8 +301,8 @@ def get_formatted_text(self, context): result = [] for child in self.get_children(): result.append(child.get_formatted_text(context)) - result.append(u"\n") - return u"".join(result) + result.append("\n") + return "".join(result) diff --git a/lpod/smil.py b/lpod/smil.py index f546ebd..0f51d55 100644 --- a/lpod/smil.py +++ b/lpod/smil.py @@ -30,7 +30,7 @@ """ # Import from lpod -from element import odf_create_element +from .element import odf_create_element diff --git a/lpod/span.py b/lpod/span.py index 32bf2d3..5e3585d 100644 --- a/lpod/span.py +++ b/lpod/span.py @@ -31,6 +31,6 @@ ######## ######## -from paragraph import _odf_create_span +from .paragraph import _odf_create_span odf_create_span = _odf_create_span diff --git a/lpod/style.py b/lpod/style.py index 7b50e0c..9aaecf1 100644 --- a/lpod/style.py +++ b/lpod/style.py @@ -25,11 +25,11 @@ # # Import from lpod -from datatype import Boolean -from element import register_element_class, odf_create_element, odf_element -from image import odf_image -from utils import _get_style_tagname, _expand_properties, _merge_dicts -from utils import _get_element, isiterable #, obsolete +from .datatype import Boolean +from .element import register_element_class, odf_create_element, odf_element +from .image import odf_image +from .utils import _get_style_tagname, _expand_properties, _merge_dicts +from .utils import _get_element, isiterable #, obsolete # from CSS3 color map @@ -196,7 +196,7 @@ def hex2rgb(color): """ code = color[1:] if not (len(color) == 7 and color[0] == '#' and code.isalnum()): - raise ValueError, '"%s" is not a valid color' % color + raise ValueError('"%s" is not a valid color' % color) red = int(code[:2], 16) green = int(code[2:4], 16) blue = int(code[4:6], 16) @@ -224,16 +224,16 @@ def rgb2hex(color): try: code = COLORMAP[color.lower()] except KeyError: - raise KeyError, 'color "%s" is unknown' % color + raise KeyError('color "%s" is unknown' % color) elif type(color) is tuple: if len(color) != 3: - raise ValueError, "color must be a 3-tuple" + raise ValueError("color must be a 3-tuple") code = color else: - raise TypeError, "invalid color" + raise TypeError("invalid color") for channel in code: if channel < 0 or channel > 255: - raise ValueError, "color code must be between 0 and 255" + raise ValueError("color code must be between 0 and 255") return '#%02X%02X%02X' % code @@ -242,8 +242,8 @@ def __make_color_string(color=None): color_default = "#000000" if color is None: color_string = color_default - elif isinstance(color, (str, unicode)): - if isinstance(color, unicode): + elif isinstance(color, str): + if isinstance(color, str): color = color.encode("utf-8") color = color.strip() if not color: @@ -255,7 +255,7 @@ def __make_color_string(color=None): elif isinstance(color, tuple): color_string = rgb2hex(color) else: - raise ValueError, "Color must be None for default or color string, or RGB tuple" + raise ValueError("Color must be None for default or color string, or RGB tuple") return color_string @@ -274,8 +274,8 @@ def make_table_cell_border_string(thick=None, line=None, color=None): line_default = "solid" if thick is None: thick_string = thick_default - elif isinstance(thick, (str, unicode)): - if isinstance(thick, unicode): + elif isinstance(thick, str): + if isinstance(thick, str): thick = thick.encode("utf-8") thick = thick.strip() if thick: @@ -287,11 +287,11 @@ def make_table_cell_border_string(thick=None, line=None, color=None): elif isinstance(thick, int): thick_string = "%.2fpt" % (thick / 100.0) else: - raise ValueError, "Thickness must be None for default or float value (pt)" + raise ValueError("Thickness must be None for default or float value (pt)") if line is None: line_string = line_default - elif isinstance(line, (str, unicode)): - if isinstance(line, unicode): + elif isinstance(line, str): + if isinstance(line, str): line = line.encode("utf-8") line = line.strip() if line: @@ -299,7 +299,7 @@ def make_table_cell_border_string(thick=None, line=None, color=None): else: line_string = line_default else: - raise ValueError, "Line style must be None for default or string" + raise ValueError("Line style must be None for default or string") color_string = __make_color_string(color) border = " ".join((thick_string, line_string, color_string)) return border @@ -417,7 +417,7 @@ def odf_create_style(family, name=None, display_name=None, parent=None, min_height=None, # For family 'font-face' font_name=None, font_family=None, font_family_generic=None, - font_pitch=u"variable", + font_pitch="variable", # Every other property **kw): """Create a style of the given family. The name is not mandatory at this @@ -608,8 +608,8 @@ def get_family(self): family = self.get_attribute('style:family') # Where the family is known from the tag, it must be defined if family is None: - raise ValueError, 'family undefined in %s "%s"' % (self, - self.get_name()) + raise ValueError('family undefined in %s "%s"' % (self, + self.get_name())) return family @@ -686,7 +686,7 @@ def set_properties(self, properties={}, style=None, area=None, **kw): properties = style.get_properties(area=area) if properties is None: return - for key, value in properties.iteritems(): + for key, value in properties.items(): if value is None: element.del_attribute(key) else: @@ -710,7 +710,7 @@ def del_properties(self, properties=[], area=None, *args): area = self.get_family() element = self.get_element('style:%s-properties' % area) if element is None: - raise ValueError, "properties element is inexistent" + raise ValueError("properties element is inexistent") for key in _expand_properties(properties): element.del_attribute(key) @@ -751,9 +751,9 @@ def set_background(self, color=None, url=None, position='center', family = self.get_family() if family not in ('text', 'paragraph', 'page-layout', 'section', 'table', 'table-row', 'table-cell', 'graphic'): - raise TypeError, 'no background support for this family' + raise TypeError('no background support for this family') if url is not None and family == 'text': - raise TypeError, 'no background image for text styles' + raise TypeError('no background image for text styles') properties = self.get_element('style:%s-properties' % family) if properties is None: bg_image = None @@ -857,7 +857,7 @@ def set_level_style(self, level, num_format=None, bullet_char=None, elif clone is not None: level_style_name = clone.get_tag() else: - raise ValueError, "unknown level style type" + raise ValueError("unknown level style type") was_created = False # Cloning or reusing an existing element if clone is not None: @@ -917,7 +917,7 @@ def get_family(self): def set_family(self): - raise ValueError, 'family is read-only' + raise ValueError('family is read-only') def get_header_style(self): @@ -951,7 +951,7 @@ class odf_master_page(odf_style): XXX to verify """ def __set_header_or_footer(self, text_or_element, name='header', - style=u"Header"): + style="Header"): if name == 'header': header_or_footer = self.get_header() else: @@ -970,9 +970,9 @@ def __set_header_or_footer(self, text_or_element, name='header', return text_or_element = [text_or_element] # FIXME cyclic import - from paragraph import odf_create_paragraph + from .paragraph import odf_create_paragraph for item in text_or_element: - if type(item) is unicode: + if type(item) is str: paragraph = odf_create_paragraph(item, style=style) header_or_footer.append(paragraph) elif isinstance(item, odf_element): @@ -988,7 +988,7 @@ def get_family(self): def set_family(self): - raise ValueError, 'family is read-only' + raise ValueError('family is read-only') def get_page_layout(self): @@ -1049,7 +1049,7 @@ def set_footer(self, text_or_element): text_or_element -- unicode or odf_element or a list of them """ return self.__set_header_or_footer(text_or_element, name='footer', - style=u"Footer") + style="Footer") class odf_font_style(odf_style): @@ -1059,7 +1059,7 @@ def get_family(self): def set_font(self, name, family=None, family_generic=None, - pitch=u"variable"): + pitch="variable"): self.set_attribute('style:name', name) if family is None: family = name diff --git a/lpod/styles.py b/lpod/styles.py index 513d82d..94c6672 100644 --- a/lpod/styles.py +++ b/lpod/styles.py @@ -26,8 +26,8 @@ # # Import from lpod -from xmlpart import odf_xmlpart -from utils import _get_elements, _get_element #, obsolete +from .xmlpart import odf_xmlpart +from .utils import _get_elements, _get_element #, obsolete @@ -68,7 +68,7 @@ def _get_style_contexts(self, family, automatic=False): self.get_element('//office:font-face-decls')) queries = context_mapping.get(family) if queries is None: - raise ValueError, "unknown family: " + family + raise ValueError("unknown family: " + family) return [self.get_element(query) for query in queries] diff --git a/lpod/table.py b/lpod/table.py index 37b5339..7caab95 100644 --- a/lpod/table.py +++ b/lpod/table.py @@ -28,17 +28,17 @@ # # Import from the Standard Library -from cStringIO import StringIO +from io import StringIO from csv import reader, Sniffer from textwrap import wrap from bisect import bisect_left, insort import string # Import from lpod -from datatype import Boolean, Date, DateTime, Duration -from element import odf_create_element, register_element_class, odf_element -from element import _xpath_compile -from utils import get_value, _set_value_and_type, isiterable #, obsolete +from .datatype import Boolean, Date, DateTime, Duration +from .element import odf_create_element, register_element_class, odf_element +from .element import _xpath_compile +from .utils import get_value, _set_value_and_type, isiterable #, obsolete @@ -52,19 +52,19 @@ def _table_name_check(name): - if not isinstance(name, basestring): - raise ValueError, "String required." + if not isinstance(name, str): + raise ValueError("String required.") name = name.strip() if not name : - raise ValueError, "Empty name not allowed." + raise ValueError("Empty name not allowed.") for character in ('\n', '/', '\\', "'") : if character in name: - raise ValueError, 'Character %s not allowed.' % character + raise ValueError('Character %s not allowed.' % character) return name _forbidden_in_named_range = [x for x in string.printable if x not in - string.letters and x not in + string.ascii_letters and x not in string.digits and x !='_'] @@ -74,7 +74,7 @@ def _alpha_to_digit(alpha): if type(alpha) is int: return alpha if not alpha.isalpha(): - raise ValueError, 'column name "%s" is malformed' % str(alpha) + raise ValueError('column name "%s" is malformed' % str(alpha)) column = 0 for c in alpha.lower(): v = ord(c) - ord('a') + 1 @@ -87,7 +87,7 @@ def _digit_to_alpha(digit): if type(digit) is str and digit.isalpha(): return digit if not type(digit) is int: - raise ValueError, 'column number "%s" is invalid' % str(digit) + raise ValueError('column number "%s" is invalid' % str(digit)) digit += 1 column = '' while digit: @@ -99,7 +99,7 @@ def _digit_to_alpha(digit): def _coordinates_to_alpha_area(coord): # assuming : either (x,y) or (x,y,z,t), with positive values - if isinstance(coord, basestring): + if isinstance(coord, str): # either A1 or A1:B2, returns A1:A1 if needed parts = coord.strip().split(':') if len(parts) == 1: @@ -142,8 +142,8 @@ def _convert_coordinates(obj): if isiterable(obj): return tuple(obj) # Or by 'B3' notation ? - if not isinstance(obj, basestring): - raise ValueError, 'bad coordinates type: "%s"' % type(obj) + if not isinstance(obj, str): + raise ValueError('bad coordinates type: "%s"' % type(obj)) coordinates = [] for coord in [x.strip() for x in obj.split(':', 1)]: # First "A" @@ -168,7 +168,7 @@ def _convert_coordinates(obj): # maybe 'A:C' row coordinates line = None if line and line <= 0: - raise ValueError, 'coordinates "%s" malformed' % obj + raise ValueError('coordinates "%s" malformed' % obj) coordinates.append(line) return tuple(coordinates) @@ -178,7 +178,7 @@ def _get_python_value(data, encoding): """Try and guess the most appropriate Python type to load the data, with regard to ODF types. """ - data = unicode(data, encoding) + data = str(data, encoding) # An int ? try: return int(data) @@ -501,7 +501,7 @@ def odf_create_row(width=None, repeated=None, style=None, cache=None): """ element = odf_create_element('table:table-row', cache) if width is not None: - for i in xrange(width): + for i in range(width): element.append(odf_create_cell()) if repeated: element.set_repeated(repeated) @@ -526,7 +526,7 @@ def odf_create_row_group(height=None, width=None): """ element = odf_create_row_group(' 2 (couting from 0) - if isinstance(y, basestring): + if isinstance(y, str): _, y = _convert_coordinates(y) if y and y < 0: return _increment(y, self.get_height()) @@ -1782,7 +1782,7 @@ def _translate_cell_coordinates(self, coord): elif len(coord) == 4: x, y, z, t = coord else: - raise ValueError, "ValueError %s" % str(coord) + raise ValueError("ValueError %s" % str(coord)) if x and x < 0: x = _increment(x, self.get_width()) if y and y < 0: @@ -1818,13 +1818,13 @@ def __get_formatted_text_normal(self, context): value = [] for element in cell.get_children(): value.append(element.get_formatted_text(context)) - value = u''.join(value) + value = ''.join(value) else: - value = unicode(value) + value = str(value) result.append(value) - result.append(u'\n') - result.append(u'\n') - return u''.join(result) + result.append('\n') + result.append('\n') + return ''.join(result) def __get_formatted_text_rst(self, context): @@ -1847,9 +1847,9 @@ def __get_formatted_text_rst(self, context): value = [] for element in cell.get_children(): value.append(element.get_formatted_text(context)) - value = u''.join(value) + value = ''.join(value) else: - value = unicode(value) + value = str(value) value = value.strip() # Strip the empty columns if value: @@ -1862,10 +1862,10 @@ def __get_formatted_text_rst(self, context): # Nothing ? if cols_nb == 0: - return u'' + return '' # Prevent a crash with empty columns (by example with images) - for col, size in cols_size.iteritems(): + for col, size in cols_size.items(): if size == 0: cols_size[col] = 1 @@ -1892,13 +1892,13 @@ def __get_formatted_text_rst(self, context): cols_size[i] = new_size # Convert ! - result = [u''] + result = [''] # Construct the first/last line line = [] for i in range(cols_nb): - line.append(u'=' * cols_size[i]) - line.append(u' ') - line = u''.join(line) + line.append('=' * cols_size[i]) + line.append(' ') + line = ''.join(line) # Add the lines result.append(line) @@ -1933,23 +1933,23 @@ def __get_formatted_text_rst(self, context): # An empty cell ? if len(values) - 1 < j or not values[j]: if i == 0 and j == 0: - txt_row.append(u'..') - txt_row.append(u' ' * (cols_size[i] - 1)) + txt_row.append('..') + txt_row.append(' ' * (cols_size[i] - 1)) else: - txt_row.append(u' ' * (cols_size[i] + 1)) + txt_row.append(' ' * (cols_size[i] + 1)) continue # Not empty value = values[j] txt_row.append(value) - txt_row.append(u' ' * (cols_size[i] - len(value) + 1)) - txt_row = u''.join(txt_row) + txt_row.append(' ' * (cols_size[i] - len(value) + 1)) + txt_row = ''.join(txt_row) result.append(txt_row) result.append(line) - result.append(u'') - result.append(u'') - result = u'\n'.join(result) + result.append('') + result.append('') + result = '\n'.join(result) context['no_img_level'] -= 1 return result @@ -2324,7 +2324,7 @@ def transpose(self, coord=None): if coord is None: for row in self.traverse(): data.append([cell for cell in row.traverse()]) - transposed_data = map(None, *data) + transposed_data = list(*data) self.clear() new_rows = [] for row_cells in transposed_data: @@ -2354,7 +2354,7 @@ def transpose(self, coord=None): t = min(t, self.get_height() - 1) for row in self.traverse(start=y, end=t): data.append([cell for cell in row.traverse(start=x, end=z)]) - transposed_data = map(None, *data) + transposed_data = list(*data) # clear locally w = z - x + 1 h = t -y + 1 @@ -2420,7 +2420,7 @@ def traverse(self, start=None, end=None): self._indexes['_tmap'][idx] = row repeated = juska - before before = juska - for i in xrange(repeated or 1): + for i in range(repeated or 1): # Return a copy without the now obsolete repetition row = row.clone() row.y = y @@ -2454,7 +2454,7 @@ def traverse(self, start=None, end=None): self._indexes['_tmap'][idx] = row repeated = juska - before before = juska - for i in xrange(repeated or 1): + for i in range(repeated or 1): if y <= end: row = row.clone() row.y = y @@ -3041,11 +3041,11 @@ def set_cell_image(self, coord, image_frame, type=None): if type is None: body = self.get_document_body() if body is None: - raise ValueError, "document type not found" + raise ValueError("document type not found") type = {'office:spreadsheet': 'spreadsheet', 'office:text': 'text'}.get(body.get_tag()) if type is None: - raise ValueError, "document type not supported for images" + raise ValueError("document type not supported for images") # We need the end address of the image x, y = self._translate_cell_coordinates(coord) cell = self.get_cell((x, y)) @@ -3061,14 +3061,14 @@ def set_cell_image(self, coord, image_frame, type=None): image_frame.set_attribute('table:end-x', width) image_frame.set_attribute('table:end-y', height) # FIXME what happens when the address changes? - address = u"%s.%s%s" % (self.get_name(), + address = "%s.%s%s" % (self.get_name(), _digit_to_alpha(x), y + 1) image_frame.set_attribute('table:end-cell-address', address) # The frame is directly in the cell cell.append(image_frame) elif type == 'text': # The frame must be in a paragraph - cell.set_value(u"") + cell.set_value("") paragraph = cell.get_element('text:p') paragraph.append(image_frame) self.set_cell(coord, cell) @@ -3199,7 +3199,7 @@ def traverse_columns(self, start=None, end=None): self._indexes['_cmap'][idx] = column repeated = juska - before before = juska - for i in xrange(repeated or 1): + for i in range(repeated or 1): # Return a copy without the now obsolete repetition column = column.clone() column.x = x @@ -3233,7 +3233,7 @@ def traverse_columns(self, start=None, end=None): self._indexes['_cmap'][idx] = column repeated = juska - before before = juska - for i in xrange(repeated or 1): + for i in range(repeated or 1): if x <= end: column = column.clone() column.x = x @@ -3560,10 +3560,10 @@ def set_column_cells(self, x, cells): """ height = self.get_height() if len(cells) != height: - raise ValueError, "col mismatch: %s cells expected" % height + raise ValueError("col mismatch: %s cells expected" % height) cells = iter(cells) for y, row in enumerate(self.traverse()): - row.set_cell(x, cells.next()) + row.set_cell(x, next(cells)) self.set_row(y, row) @@ -3636,12 +3636,12 @@ def get_named_ranges(self, table_name=None): if not table_name: return all_named_ranges filter = [] - if isinstance(table_name, basestring): + if isinstance(table_name, str): filter.append(table_name) elif isiterable(table_name): filter.extend(table_name) else: - raise ValueError, "table_name must be string or Iterable, not %s" % type(table_name) + raise ValueError("table_name must be string or Iterable, not %s" % type(table_name)) return [nr for nr in all_named_ranges if nr.table_name in filter] @@ -3659,7 +3659,7 @@ def get_named_range(self, name): """ body = self.get_document_body() if not body: - raise ValueError, "Table is not inside a document" + raise ValueError("Table is not inside a document") return body.get_named_range(name) @@ -3680,9 +3680,9 @@ def set_named_range(self, name, crange, table_name=None, usage=None): """ body = self.get_document_body() if not body: - raise ValueError, "Table is not inside a document" + raise ValueError("Table is not inside a document") if not name: - raise ValueError, "Name required." + raise ValueError("Name required.") if table_name is None: table_name = self.get_name() named_range = odf_create_named_range(name, crange, table_name, usage) @@ -3700,10 +3700,10 @@ def delete_named_range(self, name): """ name = name.strip() if not name: - raise ValueError, "Name required." + raise ValueError("Name required.") body = self.get_document_body() if not body: - raise ValueError, "Table is not inside a document." + raise ValueError("Table is not inside a document.") body.delete_named_range(name) @@ -3782,9 +3782,9 @@ def set_span(self, area, merge=False): continue val = cell.get_value() if val is not None: - if isinstance(val, basestring): + if isinstance(val, str): val.strip() - if val !=u'': + if val !='': val_list.append(val) cell.clear() if val_list: @@ -3880,7 +3880,7 @@ def to_csv(self, path_or_file=None, delimiter=',', quotechar='"', if path_or_file is None: file = StringIO() # Path - elif type(path_or_file) is str or type(path_or_file) is unicode: + elif type(path_or_file) is str or type(path_or_file) is str: file = open(path_or_file, 'wb') close_after = True # Open file @@ -3891,7 +3891,7 @@ def to_csv(self, path_or_file=None, delimiter=',', quotechar='"', line = [] for value in values: # Also testing lxml.etree._ElementUnicodeResult - if type(value) is unicode: + if type(value) is str: value = value.encode(encoding) if type(value) is str: value = value.strip() @@ -3984,13 +3984,13 @@ def set_name(self, name): """ name = name.strip() if not name: - raise ValueError, "Name required." + raise ValueError("Name required.") for x in name: if x in _forbidden_in_named_range: - raise ValueError, "Character forbidden '%s' " % x + raise ValueError("Character forbidden '%s' " % x) step = '' for x in name: - if x in string.letters and step in ('', 'A'): + if x in string.ascii_letters and step in ('', 'A'): step = 'A' continue elif step in ('A', 'A1') and x in string.digits: @@ -4000,7 +4000,7 @@ def set_name(self, name): step = '' break if step == 'A1': - raise ValueError, "Name of the type 'ABC123' is not allowed." + raise ValueError("Name of the type 'ABC123' is not allowed.") try: body = self.get_document_body() named_range = body.get_named_range(name) @@ -4088,7 +4088,7 @@ def get_values(self, cell_type=None, complete=True, """ body = self.get_document_body() if not body: - raise ValueError, "Table is not inside a document." + raise ValueError("Table is not inside a document.") table = body.get_table(name = self.table_name) return table.get_values(self.crange, cell_type, complete, get_type, flat) @@ -4100,7 +4100,7 @@ def get_value(self, get_type=False): """ body = self.get_document_body() if not body: - raise ValueError, "Table is not inside a document." + raise ValueError("Table is not inside a document.") table = body.get_table(name = self.table_name) return table.get_value(self.start, get_type) @@ -4112,7 +4112,7 @@ def set_values(self, values, style=None, cell_type=None, """ body = self.get_document_body() if not body: - raise ValueError, "Table is not inside a document." + raise ValueError("Table is not inside a document.") table = body.get_table(name = self.table_name) return table.set_values(values, coord=self.crange, style=style, cell_type=cell_type, currency=currency) @@ -4125,7 +4125,7 @@ def set_value(self, value, cell_type=None, currency=None, """ body = self.get_document_body() if not body: - raise ValueError, "Table is not inside a document." + raise ValueError("Table is not inside a document.") table = body.get_table(name = self.table_name) return table.set_value(coord=self.start, value=value, cell_type=cell_type, diff --git a/lpod/templates/test_template.py b/lpod/templates/test_template.py index e1a1283..e1b6cc7 100755 --- a/lpod/templates/test_template.py +++ b/lpod/templates/test_template.py @@ -14,27 +14,27 @@ def get_namespace(homme=False): - return {u"titre": u"Test de STL no 1", - u"date": date.today().strftime(u"%d/%m/%Y"), - u"homme": homme, - u"genre": u"M." if homme else u"Mme", - u"nom": u"Michu", - u"enum1": {'label': u"Revenu", 'value': 1234.56}, - u"enum2": {'label': u"Âge", 'value': 65}, - u"couleur": u"rouge", - u"gras": u"gras comme un moine", - u"élément": odf_create_span(u"élément", style='T2')} + return {"titre": "Test de STL no 1", + "date": date.today().strftime("%d/%m/%Y"), + "homme": homme, + "genre": "M." if homme else "Mme", + "nom": "Michu", + "enum1": {'label': "Revenu", 'value': 1234.56}, + "enum2": {'label': "Âge", 'value': 65}, + "couleur": "rouge", + "gras": "gras comme un moine", + "élément": odf_create_span("élément", style='T2')} if __name__ == '__main__': try: output = argv[1] except IndexError: - print >>stderr, "Usage: %s " % argv[0] + print("Usage: %s " % argv[0], file=stderr) exit(1) document = odf_new_document('test_template.ott') stl_odf(document, get_namespace()) if exists(output): remove(output) document.save(output) - print 'Document "%s" generated.' % output + print('Document "%s" generated.' % output) diff --git a/lpod/toc.py b/lpod/toc.py index a0462c4..5d285e7 100644 --- a/lpod/toc.py +++ b/lpod/toc.py @@ -25,16 +25,16 @@ # # Import from lpod -from element import FIRST_CHILD -from element import register_element_class, odf_create_element, odf_element -from paragraph import odf_create_paragraph -from style import odf_create_style +from .element import FIRST_CHILD +from .element import register_element_class, odf_create_element, odf_element +from .paragraph import odf_create_paragraph +from .style import odf_create_style #from utils import obsolete -def odf_create_toc(title=u"Table of Contents", name=None, protected=True, - outline_level=None, style=None, title_style=u"Contents_20_Heading", - entry_style=u"Contents_20_%d"): +def odf_create_toc(title="Table of Contents", name=None, protected=True, + outline_level=None, style=None, title_style="Contents_20_Heading", + entry_style="Contents_20_%d"): """Create a table of contents. Default parameters are what most people use: Protected from manual modifications and not limited in title levels. @@ -63,7 +63,7 @@ def odf_create_toc(title=u"Table of Contents", name=None, protected=True, element = odf_create_element('text:table-of-content') # XXX if name is None: - name = u"%s1" % title + name = "%s1" % title element.set_name(name) element.set_protected(protected) if style: @@ -81,7 +81,7 @@ def odf_create_toc(title=u"Table of Contents", name=None, protected=True, def odf_create_toc_source(title=None, outline_level=10, - title_style=u"Contents_20_Heading", entry_style=u"Contents_20_%d"): + title_style="Contents_20_Heading", entry_style="Contents_20_%d"): element = odf_create_element('text:table-of-content-source') element.set_outline_level(outline_level) if title: @@ -133,7 +133,7 @@ def odf_create_index_title(title=None, name=None, style=None, return element -TOC_ENTRY_STYLE_PATTERN = u"lpod_toc_level%d" +TOC_ENTRY_STYLE_PATTERN = "lpod_toc_level%d" # Base style for a TOC entry base_tab_stop = odf_create_element(' level for l in range(level + 1, 11): - if level_indexes.has_key(l): + if l in level_indexes: del level_indexes[l] - number = u'.'.join(number) + u'.' + number = '.'.join(number) + '.' # Make the title with "1.2.3. Title" format - title = u"%s %s" % (number, heading.get_text()) + title = "%s %s" % (number, heading.get_text()) paragraph = odf_create_paragraph(title) if use_default_styles: paragraph.set_text_style(TOC_ENTRY_STYLE_PATTERN % level) diff --git a/lpod/tracked_changes.py b/lpod/tracked_changes.py index b5b2427..4034e3d 100644 --- a/lpod/tracked_changes.py +++ b/lpod/tracked_changes.py @@ -28,13 +28,13 @@ # Import from the Standard Library from datetime import datetime -from datatype import DateTime +from .datatype import DateTime # Import from lpod -from element import register_element_class, odf_element, odf_create_element -from element import FIRST_CHILD, LAST_CHILD -from paragraph import odf_paragraph, odf_create_paragraph -from utils import _get_elements, _get_element +from .element import register_element_class, odf_element, odf_create_element +from .element import FIRST_CHILD, LAST_CHILD +from .paragraph import odf_paragraph, odf_create_paragraph +from .utils import _get_elements, _get_element @@ -60,7 +60,7 @@ def set_dc_creator(self, creator=None): element = odf_create_element('dc:creator') self.insert(element, xmlposition=FIRST_CHILD) if not creator: - creator = u'Unknown' + creator = 'Unknown' element.set_text(creator) @@ -102,7 +102,7 @@ def get_comments(self, joined=True): return text - def set_comments(self, text=u'', replace=True): + def set_comments(self, text='', replace=True): """Set the text content of the comments. If replace is True (default), the new text replace old comments, else it is added at the end. @@ -134,7 +134,7 @@ def get_deleted(self, as_text=False, no_header=False): """Return: None. """ if as_text: - return u'' + return '' return None @@ -305,7 +305,7 @@ def get_inserted(self, as_text=False, no_header=False, clean=True): """Return None (or u''). """ if as_text: - return u'' + return '' return None @@ -557,7 +557,7 @@ def get_inserted(self, as_text=False, no_header=False, clean=True): end = self.get_end() if end is None or start is None: if as_text: - return u'' + return '' return None body = self.get_document_body() if not body: diff --git a/lpod/utils.py b/lpod/utils.py index 12bbaf7..d0602e6 100644 --- a/lpod/utils.py +++ b/lpod/utils.py @@ -36,7 +36,7 @@ from warnings import warn # Import from lpod -from datatype import Boolean, Date, DateTime, Duration +from .datatype import Boolean, Date, DateTime, Duration CELL_TYPES = ('boolean', 'currency', 'date', 'float', 'percentage', 'string', @@ -145,9 +145,9 @@ def _make_xpath_query(element_name, family=None, text_style=None, for qname in sorted(attributes): value = attributes[qname] if value is True: - query.append(u'[@%s]' % qname) + query.append('[@%s]' % qname) else: - query.append(u'[@%s="%s"]' % (qname, unicode(value))) + query.append('[@%s="%s"]' % (qname, str(value))) query = ''.join(query) if position is not None: # A position argument that mimics the behaviour of a python's list @@ -157,7 +157,7 @@ def _make_xpath_query(element_name, family=None, text_style=None, position = 'last()' else: position = 'last()-%d' % (abs(position) - 1) - query = u'(%s)[%s]' % (query, position) + query = '(%s)[%s]' % (query, position) return query @@ -191,12 +191,12 @@ def _make_xpath_query(element_name, family=None, text_style=None, def _get_style_tagname(family): if family not in family_mapping: - raise ValueError, "unknown family: " + family + raise ValueError("unknown family: " + family) return family_mapping[family] def _get_style_family(name): - for family, (tagname, famattr) in family_mapping.iteritems(): + for family, (tagname, famattr) in family_mapping.items(): if tagname == name: return family return None @@ -245,7 +245,7 @@ def map_key(key): if type(properties) is dict: expanded = {} - for key, value in properties.iteritems(): + for key, value in properties.items(): key = map_key(key) expanded[key] = value elif type(properties) is list: @@ -337,34 +337,34 @@ def _set_value_and_type(element, value=None, value_type=None, text=None, if value_type is None: value_type = 'boolean' if text is None: - text = u'true' if value else u'false' + text = 'true' if value else 'false' value = Boolean.encode(value) - elif isinstance(value, (int, float, long, dec)): + elif isinstance(value, (int, float, dec)): if value_type is 'percentage': text = "%d %%" % int(value * 100) if value_type is None: value_type = 'float' if text is None: - text = unicode(value) + text = str(value) value = str(value) elif type(value) is date: if value_type is None: value_type = 'date' if text is None: - text = unicode(Date.encode(value)) + text = str(Date.encode(value)) value = Date.encode(value) elif type(value) is datetime: if value_type is None: value_type = 'date' if text is None: - text = unicode(DateTime.encode(value)) + text = str(DateTime.encode(value)) value = DateTime.encode(value) elif type(value) is str: if value_type is None: value_type = 'string' if text is None: - text = unicode(value) - elif type(value) is unicode: + text = str(value) + elif type(value) is str: if value_type is None: value_type = 'string' if text is None: @@ -373,10 +373,10 @@ def _set_value_and_type(element, value=None, value_type=None, text=None, if value_type is None: value_type = 'time' if text is None: - text = unicode(Duration.encode(value)) + text = str(Duration.encode(value)) value = Duration.encode(value) elif value is not None: - raise TypeError, 'type "%s" is unknown' % type(value) + raise TypeError('type "%s" is unknown' % type(value)) if value_type is not None: element.set_attribute('office:value-type', value_type) @@ -436,16 +436,16 @@ def get_value(element, value_type=None, try_get_text=True, get_type=False): value = element.get_attribute('office:string-value') if value is not None: if get_type: - return (unicode(value), value_type) - return unicode(value) + return (str(value), value_type) + return str(value) if try_get_text: value = [] for para in element.get_elements('text:p'): value.append(para.get_text(recursive=True)) if value: if get_type: - return (u"\n".join(value), value_type) - return u"\n".join(value) + return ("\n".join(value), value_type) + return "\n".join(value) if get_type: return (None, value_type) return None @@ -459,7 +459,7 @@ def get_value(element, value_type=None, try_get_text=True, get_type=False): return (None, None) return None - raise ValueError, 'unexpected value type "%s"' % value_type + raise ValueError('unexpected value type "%s"' % value_type) @@ -492,7 +492,7 @@ def set_value(element, value): element.set_attribute('text:name', name) return # Else => error - raise ValueError, 'set_value: unexpected element "%s"' % tag + raise ValueError('set_value: unexpected element "%s"' % tag) @@ -543,7 +543,7 @@ def decorate(*dec_args, **dec_kw): def isiterable(obj): - if isinstance(obj, basestring): + if isinstance(obj, str): return False try: iter(obj) diff --git a/lpod/variable.py b/lpod/variable.py index a668c22..bd22c51 100644 --- a/lpod/variable.py +++ b/lpod/variable.py @@ -26,10 +26,10 @@ # # Import from lpod -from datatype import Date, DateTime, Duration -from const import ODF_META -from utils import _set_value_and_type -from element import odf_create_element +from .datatype import Date, DateTime, Duration +from .const import ODF_META +from .utils import _set_value_and_type +from .element import odf_create_element diff --git a/lpod/xmlpart.py b/lpod/xmlpart.py index f357748..54e4174 100644 --- a/lpod/xmlpart.py +++ b/lpod/xmlpart.py @@ -27,13 +27,13 @@ # Import from the Standard Library from copy import deepcopy -from cStringIO import StringIO +from io import StringIO, BytesIO # Import from lxml from lxml.etree import parse, tostring # Import from lpod -from element import _make_odf_element +from .element import _make_odf_element #from utils import obsolete @@ -54,7 +54,7 @@ def __get_tree(self): if self.__tree is None: container = self.container part = container.get_part(self.part_name) - self.__tree = parse(StringIO(part)) + self.__tree = parse(BytesIO(part)) return self.__tree @@ -117,5 +117,5 @@ def serialize(self, pretty=False): # Lxml with pretty_print is adding a empty line if pretty: tree = tree.strip() - data.append(tree) + data.append(tree.decode()) return '\n'.join(data) diff --git a/release.py b/release.py index 48aff3d..492258e 100755 --- a/release.py +++ b/release.py @@ -89,6 +89,6 @@ def get_git_files(): if __name__ == '__main__': try: - print get_release() + print(get_release()) except: printerr('%s: unable to read info' % basename(argv[0])) diff --git a/scripts/lpod-budapest-demo.py b/scripts/lpod-budapest-demo.py index 929dc79..ed4e9d9 100644 --- a/scripts/lpod-budapest-demo.py +++ b/scripts/lpod-budapest-demo.py @@ -29,9 +29,9 @@ # Import from the standard library from optparse import OptionParser from sys import exit, stderr -from urllib2 import urlopen, HTTPPasswordMgrWithDefaultRealm -from urllib2 import HTTPBasicAuthHandler, build_opener -from urlparse import urlsplit, urlunsplit +from urllib.request import urlopen, HTTPPasswordMgrWithDefaultRealm +from urllib.request import HTTPBasicAuthHandler, build_opener +from urllib.parse import urlsplit, urlunsplit # Import from lpod from lpod import __version__, ODF_META, ODF_STYLES, ODF_MANIFEST @@ -95,13 +95,13 @@ def get_graphic_frame(master_page): output_document = odf_new_document('presentation') output_meta = output_document.get_part(ODF_META) - output_meta.set_title(u"Interop Budapest Demo") + output_meta.set_title("Interop Budapest Demo") # Styles styles = output_document.get_part(ODF_STYLES) first_master_page = styles.get_master_page() if first_master_page is None: - raise ValueError, "no master page found" + raise ValueError("no master page found") for i, filename in enumerate(filenames): # TODO folders and collections @@ -127,23 +127,23 @@ def get_graphic_frame(master_page): file = urlopen(filename) input_document = odf_get_document(file) # Page - page = odf_create_draw_page(name=u"page%d" % (i + 1), + page = odf_create_draw_page(name="page%d" % (i + 1), master_page=first_master_page) # Title Frame title_frame = get_title_frame(first_master_page) - name = unicode(filename.split('/')[-1]) - source = u"filesystem" if not scheme else scheme - title_frame.set_text_content(u"%s (%s)" % (name, source)) + name = str(filename.split('/')[-1]) + source = "filesystem" if not scheme else scheme + title_frame.set_text_content("%s (%s)" % (name, source)) page.append(title_frame) # Get info info = [] input_meta = input_document.get_part(ODF_META) - info.append(u"Title: %s" % input_meta.get_title()) + info.append("Title: %s" % input_meta.get_title()) stats = input_meta.get_statistic() - info.append(u"# pages: %s" % stats['meta:page-count']) + info.append("# pages: %s" % stats['meta:page-count']) input_body = input_document.get_body() - info.append(u"# images: %s" % len(input_body.get_images())) - info.append(u"# tables: %s" % len(input_body.get_tables())) + info.append("# images: %s" % len(input_body.get_images())) + info.append("# tables: %s" % len(input_body.get_tables())) # Outline Frame info_list = odf_create_list(info) outline_frame = get_outline_frame(first_master_page) @@ -182,5 +182,5 @@ def get_graphic_frame(master_page): output_body.append(page) output_document.save(target, pretty=True) - print >> stderr - print >> stderr, "%s generated" % target + print(file=stderr) + print("%s generated" % target, file=stderr) diff --git a/scripts/lpod-clean.py b/scripts/lpod-clean.py index c47f9f2..12176bb 100644 --- a/scripts/lpod-clean.py +++ b/scripts/lpod-clean.py @@ -53,6 +53,6 @@ indoc = odf_get_document(args[0]) outdoc, error_nb = clean_document(indoc) if error_nb != 0: - print '%d error(s) fixed.' % error_nb + print('%d error(s) fixed.' % error_nb) outdoc.save(target=args[1]) diff --git a/scripts/lpod-convert.py b/scripts/lpod-convert.py index ef9450e..e4857db 100644 --- a/scripts/lpod-convert.py +++ b/scripts/lpod-convert.py @@ -74,7 +74,7 @@ def spreadsheet_to_text(indoc, outdoc): formula = oooc_to_ooow(formula) else: # Found an OpenFormula test case - raise NotImplementedError, formula + raise NotImplementedError(formula) cell.set_formula(formula) outrow.append(cell) outtable.append_row(outrow) @@ -346,13 +346,13 @@ def write_presentation_para(para, outdoc, encoding): # XXX continue else: - print child.serialize() - raise NotImplementedError, tag + print(child.serialize()) + raise NotImplementedError(tag) outdoc.write('') outdoc.write(get_string(child.get_tail(), encoding)) else: - print para.serialize() - raise NotImplementedError, tag + print(para.serialize()) + raise NotImplementedError(tag) text = get_string(para.get_text(recursive=True), encoding) outdoc.write('

\n') @@ -370,11 +370,11 @@ def write_presentation_list(liste, outdoc, encoding): elif tag == 'text:p': write_presentation_para(child, outdoc, encoding) else: - print item.serialize() - raise NotImplementedError, tag + print(item.serialize()) + raise NotImplementedError(tag) continue elif tag != 'text:list-item': - raise NotImplementedError, tag + raise NotImplementedError(tag) outdoc.write('
  • \n') for child in item.get_children(): tag = child.get_tag() @@ -383,8 +383,8 @@ def write_presentation_list(liste, outdoc, encoding): elif tag == 'text:p': write_presentation_para(child, outdoc, encoding) else: - print item.serialize() - raise NotImplementedError, tag + print(item.serialize()) + raise NotImplementedError(tag) outdoc.write('
  • \n') outdoc.write('\n') @@ -403,8 +403,8 @@ def write_presentation_text(frame, outdoc, encoding): elif tag == 'draw:enhanced-geometry': continue else: - print text_box.serialize() - raise NotImplementedError, tag + print(text_box.serialize()) + raise NotImplementedError(tag) @@ -516,7 +516,7 @@ def get_extension(filename): try: mimetype = ODF_EXTENSIONS[extension] except KeyError: - raise ValueError, ("output filename not recognized: " + + raise ValueError("output filename not recognized: " + extension) outtype = mimetype[mimetype.rindex('.') + 1:] if '-template' in outtype: @@ -525,7 +525,7 @@ def get_extension(filename): # Convert function converter = locals().get('%s_to_%s' % (intype, outtype)) if converter is None: - raise NotImplementedError, "unsupported combination" + raise NotImplementedError("unsupported combination") # Remove output file if not target_file_checked: check_target_file(outfile) diff --git a/scripts/lpod-diff.py b/scripts/lpod-diff.py index 87f29f4..ee29fef 100644 --- a/scripts/lpod-diff.py +++ b/scripts/lpod-diff.py @@ -71,14 +71,14 @@ # Make the diff ! if options.ndiff: result = ndiff(text1, text2, None, None) - result = [ line for line in result if not line.startswith(u' ') ] + result = [ line for line in result if not line.startswith(' ') ] else: fromdate = ctime(stat(args[0]).st_mtime) todate = ctime(stat(args[1]).st_mtime) result = unified_diff(text1, text2, args[0], args[1], fromdate, todate) - result = u''.join(result) + result = ''.join(result) encoding = stdout.encoding if stdout.encoding is not None else 'utf-8' result = result.encode(encoding) # And print it ! - print result + print(result) diff --git a/scripts/lpod-folder.py b/scripts/lpod-folder.py index ca21519..c2726d2 100644 --- a/scripts/lpod-folder.py +++ b/scripts/lpod-folder.py @@ -55,6 +55,6 @@ elif os.path.isdir(args[0]): out_packaging = 'zip' else: - raise ValueError, "no File or folder ?" + raise ValueError("no File or folder ?") doc = odf_get_document(args[0]) doc.save(packaging = out_packaging, pretty=True) diff --git a/scripts/lpod-highlight.py b/scripts/lpod-highlight.py index 9aa83ec..cb82609 100644 --- a/scripts/lpod-highlight.py +++ b/scripts/lpod-highlight.py @@ -40,17 +40,17 @@ def highlight(odf_file_url, pattern, color=None, background_color=None, italic=False, bold=False, target=None, pretty=True): # Make display_name and name - display_name = [u"Highlight"] + display_name = ["Highlight"] if color and color != 'none': - display_name.append(unicode(color).capitalize()) + display_name.append(str(color).capitalize()) if background_color and background_color != 'none': - display_name.append(unicode(background_color).capitalize()) + display_name.append(str(background_color).capitalize()) if italic: - display_name.append(u"Italic") + display_name.append("Italic") if bold: - display_name.append(u"Bold") - display_name = u" ".join(display_name) - name = display_name.replace(u" ", u"_20_") + display_name.append("Bold") + display_name = " ".join(display_name) + name = display_name.replace(" ", "_20_") # Is our style already installed? style = document.get_style('text', name) @@ -113,7 +113,7 @@ def highlight(odf_file_url, pattern, color=None, background_color=None, parser.print_help() exit(1) odf_file_url, pattern = args - pattern = unicode(pattern, stdin.encoding) + pattern = str(pattern, stdin.encoding) document = odf_get_document(odf_file_url) highlight(document, pattern, options.color, options.background, options.italic, options.bold, target=options.output) diff --git a/scripts/lpod-merge.py b/scripts/lpod-merge.py index 2bfae6c..95ed47f 100644 --- a/scripts/lpod-merge.py +++ b/scripts/lpod-merge.py @@ -58,7 +58,7 @@ def init_doc(filename, mimetype): output_doc = odf_new_document('spreadsheet') add_csv(filename, output_doc) else: - raise NotImplementedError, mimetype + raise NotImplementedError(mimetype) return output_doc @@ -99,13 +99,13 @@ def add_odt(filename, output_doc): def _get_table_name(name, output_body): if isinstance(name, str): encoding = stdout.encoding or 'utf8' - name = unicode(name, encoding) + name = str(name, encoding) already_names = set([ table.get_name() for table in output_body.get_tables() ]) if name in already_names: i = 1 while True: - new_name = u"%s_%d" % (name, i) + new_name = "%s_%d" % (name, i) if new_name not in already_names: return new_name i += 1 @@ -159,7 +159,7 @@ def add_odp(filename, output_doc): if name in already_names: i = 1 while True: - new_name = u"%s_%d" % (name, i) + new_name = "%s_%d" % (name, i) if new_name not in already_names: name = new_name break diff --git a/scripts/lpod-meta.py b/scripts/lpod-meta.py index 4ab0233..54e9490 100644 --- a/scripts/lpod-meta.py +++ b/scripts/lpod-meta.py @@ -59,7 +59,7 @@ def set_metadata(doc, set_list): date = DateTime.decode(value) else: date = Date.decode(value) - except ValueError, error: + except ValueError as error: printerr('Bad argument -s "%s": %s' % (set_info, error)) exit(1) func = meta.__getattribute__('set_' + name) @@ -102,4 +102,4 @@ def set_metadata(doc, set_list): set_metadata(doc, options.set_list) else: # Dump - print doc.get_formated_meta().encode('utf-8') + print(doc.get_formated_meta().encode('utf-8')) diff --git a/scripts/lpod-mm2odt.py b/scripts/lpod-mm2odt.py index 794f97c..d22a339 100644 --- a/scripts/lpod-mm2odt.py +++ b/scripts/lpod-mm2odt.py @@ -111,4 +111,4 @@ def make_document(structure, body): # Save the document document.save(outname, pretty=True) # Feed back to the user - print "`%s' created from `%s'" % (outname, inname) + print("`%s' created from `%s'" % (outname, inname)) diff --git a/scripts/lpod-show.py b/scripts/lpod-show.py index 96e5731..e65cda3 100644 --- a/scripts/lpod-show.py +++ b/scripts/lpod-show.py @@ -44,7 +44,7 @@ def clean_filename(filename): filename = filename.encode('utf-8') - allowed_characters = set([u'.', u'-', u'_', u'@']) + allowed_characters = set(['.', '-', '_', '@']) result = [] for c in filename: if c not in allowed_characters and not c.isalnum(): @@ -142,8 +142,8 @@ def spreadsheet_to_csv(document, target): if doc_type == 'text': result = test_document(document) if result is not True: - print 'This file is malformed: %s' % result - print 'Please use lpod-clean.py to fix it' + print('This file is malformed: %s' % result) + print('Please use lpod-clean.py to fix it') exit(1) if options.output: target = options.output diff --git a/scripts/lpod-test.py b/scripts/lpod-test.py index 18a926b..367e863 100644 --- a/scripts/lpod-test.py +++ b/scripts/lpod-test.py @@ -51,4 +51,4 @@ document = args[0] # Finish me :-) - print _run_command(["odflint", document]) + print(_run_command(["odflint", document])) diff --git a/scriptutils.py b/scriptutils.py index a4e9dcf..1d11b0c 100644 --- a/scriptutils.py +++ b/scriptutils.py @@ -27,7 +27,7 @@ # Import from the Standard Library from mimetypes import guess_type from os.path import exists, isfile -from StringIO import StringIO +from io import StringIO from sys import stdin, stdout, stderr # Import from lpod diff --git a/setup.py b/setup.py index 37a29bf..ad45045 100644 --- a/setup.py +++ b/setup.py @@ -35,7 +35,7 @@ from release import has_git, get_release g = {} -execfile(os.path.join('lpod', '_version.py'), g) +exec(compile(open(os.path.join('lpod', '_version.py'), "rb").read(), os.path.join('lpod', '_version.py'), 'exec'), g) lpod_version = g['__version__'] #if has_git(): @@ -52,7 +52,7 @@ setup(description='lpOD Library', license='GPLv3 + Apache v2', - name='lpod-python', + name='lpod-python3', package_data={'': ['templates/*']}, package_dir={'lpod': 'lpod'}, scripts=scripts, diff --git a/test/network_test.py b/test/network_test.py index f1280fb..aded01f 100644 --- a/test/network_test.py +++ b/test/network_test.py @@ -26,10 +26,10 @@ # Import from the Standard Library import os -from cStringIO import StringIO +from io import StringIO from ftplib import FTP from unittest import TestCase, main -from urllib import urlopen +from urllib.request import urlopen # Import from lpod from lpod.const import ODF_EXTENSIONS diff --git a/test/test_bookmark.py b/test/test_bookmark.py index 8cba109..6878395 100644 --- a/test/test_bookmark.py +++ b/test/test_bookmark.py @@ -43,34 +43,34 @@ def setUp(self): def test_create_bookmark(self): - bookmark = odf_create_bookmark(u'你好 Zoé') + bookmark = odf_create_bookmark('你好 Zoé') expected = ('' % - convert_unicode(u'你好 Zoé')) + convert_unicode('你好 Zoé')) self.assertEqual(bookmark.serialize(), expected) def test_create_bookmark_start(self): - bookmark_start = odf_create_bookmark_start(u'你好 Zoé') + bookmark_start = odf_create_bookmark_start('你好 Zoé') expected = ('' % - convert_unicode(u'你好 Zoé')) + convert_unicode('你好 Zoé')) self.assertEqual(bookmark_start.serialize(), expected) def test_create_bookmark_end(self): - bookmark_end = odf_create_bookmark_end(u'你好 Zoé') + bookmark_end = odf_create_bookmark_end('你好 Zoé') expected = ('' % - convert_unicode(u'你好 Zoé')) + convert_unicode('你好 Zoé')) self.assertEqual(bookmark_end.serialize(), expected) def test_get_bookmark(self): body = self.body para = self.body.get_paragraph() - bookmark = odf_create_bookmark(u'你好 Zoé') + bookmark = odf_create_bookmark('你好 Zoé') para.append(bookmark) - get = body.get_bookmark(name=u'你好 Zoé') + get = body.get_bookmark(name='你好 Zoé') expected = ('' % - convert_unicode(u'你好 Zoé')) + convert_unicode('你好 Zoé')) self.assertEqual(get.serialize(), expected) @@ -86,43 +86,43 @@ def test_get_bookmark_list(self): def test_get_bookmark_start(self): body = self.body para = self.body.get_paragraph() - bookmark_start = odf_create_bookmark_start(u'你好 Zoé') + bookmark_start = odf_create_bookmark_start('你好 Zoé') para.append(bookmark_start) - get = body.get_bookmark_start(name=u'你好 Zoé') + get = body.get_bookmark_start(name='你好 Zoé') expected = ('' % - convert_unicode(u'你好 Zoé')) + convert_unicode('你好 Zoé')) self.assertEqual(get.serialize(), expected) def test_get_bookmark_start_list(self): - bookmark_start = odf_create_bookmark_start(u'你好 Zoé') + bookmark_start = odf_create_bookmark_start('你好 Zoé') para = self.body.get_paragraph() para.append(bookmark_start) get = self.body.get_bookmark_starts()[0] expected = ('' % - convert_unicode(u'你好 Zoé')) + convert_unicode('你好 Zoé')) self.assertEqual(get.serialize(), expected) def test_get_bookmark_end(self): body = self.body para = self.body.get_paragraph() - bookmark_end = odf_create_bookmark_end(u'你好 Zoé') + bookmark_end = odf_create_bookmark_end('你好 Zoé') para.append(bookmark_end) - get = body.get_bookmark_end(name=u'你好 Zoé') + get = body.get_bookmark_end(name='你好 Zoé') expected = ('' % - convert_unicode(u'你好 Zoé')) + convert_unicode('你好 Zoé')) self.assertEqual(get.serialize(), expected) def test_get_bookmark_end_list(self): body = self.body - bookmark_end = odf_create_bookmark_end(u'你好 Zoé') + bookmark_end = odf_create_bookmark_end('你好 Zoé') para = self.body.get_paragraph() para.append(bookmark_end) get = body.get_bookmark_ends()[0] expected = ('' % - convert_unicode(u'你好 Zoé')) + convert_unicode('你好 Zoé')) self.assertEqual(get.serialize(), expected) @@ -135,7 +135,7 @@ def test_set_bookmark_simple(self): def test_set_bookmark_with_after_without_position(self): - paragraph = odf_create_paragraph(u"aa bb aa aa cc aa dd") + paragraph = odf_create_paragraph("aa bb aa aa cc aa dd") paragraph.set_span(style="style", regex="bb aa aa") paragraph.set_span(style="style", regex="dd") paragraph.set_bookmark("bookmark", after="aa") @@ -148,7 +148,7 @@ def test_set_bookmark_with_after_without_position(self): def test_set_bookmark_with_before(self): - paragraph = odf_create_paragraph(u"aa bb aa aa cc aa dd") + paragraph = odf_create_paragraph("aa bb aa aa cc aa dd") paragraph.set_span(style="style", regex="bb aa aa") paragraph.set_span(style="style", regex="dd") paragraph.set_bookmark("bookmark", before="aa", position=1) @@ -162,7 +162,7 @@ def test_set_bookmark_with_before(self): def test_set_bookmark_with_after(self): - paragraph = odf_create_paragraph(u"aa bb aa aa cc aa dd") + paragraph = odf_create_paragraph("aa bb aa aa cc aa dd") paragraph.set_span(style="style", regex="bb aa aa") paragraph.set_span(style="style", regex="dd") paragraph.set_bookmark("bookmark", after="aa", position=1) @@ -176,13 +176,13 @@ def test_set_bookmark_with_after(self): def test_set_bookmark_with_position(self): - paragraph = odf_create_paragraph(u"aa bb aa aa cc aa dd") + paragraph = odf_create_paragraph("aa bb aa aa cc aa dd") paragraph.set_span(style="style", regex="bb aa aa") paragraph.set_span(style="style", regex="dd") paragraph.set_bookmark("bookmark1", position=0) paragraph.set_bookmark("bookmark2", position=2) paragraph.set_bookmark("bookmark3", - position=len(u"aa bb aa aa cc aa dd")) + position=len("aa bb aa aa cc aa dd")) expected = ('aa' ' ' 'bb aa aa' @@ -193,7 +193,7 @@ def test_set_bookmark_with_position(self): def test_set_bookmark_with_end(self): - paragraph = odf_create_paragraph(u"aa bb aa aa cc aa dd") + paragraph = odf_create_paragraph("aa bb aa aa cc aa dd") paragraph.set_span(style="style", regex="bb aa aa") paragraph.set_span(style="style", regex="dd") paragraph.set_bookmark("bookmark1", after="cc", position=-1) @@ -210,7 +210,7 @@ def test_set_bookmark_with_end(self): def test_set_bookmark_with_role(self): - paragraph = odf_create_paragraph(u"aa") + paragraph = odf_create_paragraph("aa") paragraph.set_bookmark("bookmark", role="start") paragraph.set_bookmark("bookmark", role="end", position=-1) expected = ('' @@ -222,7 +222,7 @@ def test_set_bookmark_with_role(self): def test_set_bookmark_with_content(self): - paragraph = odf_create_paragraph(u"aa bb bb aa") + paragraph = odf_create_paragraph("aa bb bb aa") paragraph.set_bookmark("bookmark", content="bb", position=1) expected = ('aa bb ' '' @@ -234,7 +234,7 @@ def test_set_bookmark_with_content(self): def test_set_bookmark_with_limits(self): - paragraph = odf_create_paragraph(u"aa bb bb aa") + paragraph = odf_create_paragraph("aa bb bb aa") paragraph.set_bookmark("bookmark", position=(6, 8)) expected = ('aa bb ' '' diff --git a/test/test_container.py b/test/test_container.py index 7e6884c..77c1c31 100644 --- a/test/test_container.py +++ b/test/test_container.py @@ -29,12 +29,12 @@ # Import from the Standard Library import os -from cStringIO import StringIO +from io import StringIO from ftplib import FTP from os import mkdir from shutil import rmtree from unittest import TestCase, main -from urllib import urlopen +from urllib.request import urlopen # Import from lpod from lpod.const import ODF_EXTENSIONS, ODF_CONTENT, ODF_META @@ -136,7 +136,7 @@ def test_clone(self): def test_get_part_xml(self): container = odf_get_container('samples/example.odt') content = container.get_part(ODF_CONTENT) - self.assert_('')) + self.assertTrue(meta.startswith('')) def test_set_part(self): @@ -227,7 +227,7 @@ def test_load_folder(self): container.save('trash/example_f.odt', packaging='folder') new_container = odf_get_container('trash/example_f.odt.folder') content = new_container.get_part(ODF_CONTENT) - self.assert_('') root = element.get_root() - self.assert_(root.get_parent() is None) + self.assertTrue(root.get_parent() is None) def test_clone(self): @@ -188,7 +188,7 @@ def test_get_attribute(self): def test_get_attribute_namespace(self): element = self.paragraph_element text = element.get_attribute('text:style-name') - self.assert_(isinstance(text, unicode)) + self.assertTrue(isinstance(text, str)) self.assertEqual(text, "Text_20_body") @@ -252,13 +252,13 @@ def setUp(self): def test_get_text(self): element = self.paragraph_element text = element.get_text() - self.assertEqual(text, u"This is the first paragraph.") + self.assertEqual(text, "This is the first paragraph.") def test_set_text(self): element = self.paragraph_element old_text = element.get_text() - new_text = u'A test' + new_text = 'A test' element.set_text(new_text) self.assertEqual(element.get_text(), new_text) element.set_text(old_text) @@ -276,14 +276,14 @@ def test_set_text_special(self): def test_get_text_content(self): element = self.annotation_element text = element.get_text_content() - self.assertEqual(text, u"This is an annotation.\n" - u"With diacritical signs: éè") + self.assertEqual(text, "This is an annotation.\n" + "With diacritical signs: éè") def test_set_text_content(self): element = self.annotation_element old_text = element.get_text_content() - text = u"Have a break" + text = "Have a break" element.set_text_content(text) self.assertEqual(element.get_text_content(), text) element.set_text_content(old_text) @@ -377,11 +377,11 @@ def test_get_children(self): def test_append_element(self): element = odf_create_element("text:p") - element.append(u"f") - element.append(u"oo1") + element.append("f") + element.append("oo1") element.append(odf_create_element("text:line-break")) - element.append(u"f") - element.append(u"oo2") + element.append("f") + element.append("oo2") self.assertEqual(element.serialize(), "foo1foo2") @@ -399,35 +399,35 @@ def setUp(self): def test_search_paragraph(self): """Search text in a paragraph. """ - pos = self.paragraph.search(u'ère') + pos = self.paragraph.search('ère') return self.assertEqual(pos, 4) def test_match_span(self): """Search text in a span. """ - pos = self.span.search(u'moust') + pos = self.span.search('moust') return self.assertEqual(pos, 0) def test_match_inner_span(self): """Search text in a span from the parent paragraph. """ - pos = self.paragraph.search(u'roug') + pos = self.paragraph.search('roug') return self.assertEqual(pos, 29) def test_simple_regex(self): """Search a simple regex. """ - pos = self.paragraph.search(u'che roug') + pos = self.paragraph.search('che roug') return self.assertEqual(pos, 25) def test_intermediate_regex(self): """Search an intermediate regex. """ - pos = self.paragraph.search(u'moustache (blanche|rouge)') + pos = self.paragraph.search('moustache (blanche|rouge)') return self.assertEqual(pos, 19) @@ -436,14 +436,14 @@ def test_complex_regex(self): """ # The (?<=...) part is pointless as we don't try to get groups from # a MatchObject. However, it's a valid regex expression. - pos = self.paragraph.search(ur'(?<=m)(ou)\w+(che) (blan\2|r\1ge)') + pos = self.paragraph.search(r'(?<=m)(ou)\w+(che) (blan\2|r\1ge)') return self.assertEqual(pos, 20) def test_compiled_regex(self): """Search with a compiled pattern. """ - pattern = compile(ur'moustache') + pattern = compile(r'moustache') pos = self.paragraph.search(pattern) return self.assertEqual(pos, 19) @@ -451,8 +451,8 @@ def test_compiled_regex(self): def test_failing_match(self): """Test a regex that doesn't match. """ - pos = self.paragraph.search(u'Le Père moustache') - return self.assert_(pos is None) + pos = self.paragraph.search('Le Père moustache') + return self.assertTrue(pos is None) @@ -468,35 +468,35 @@ def setUp(self): def test_match_paragraph(self): """Match text in a paragraph. """ - match = self.paragraph.match(u'ère') + match = self.paragraph.match('ère') return self.assertTrue(match) def test_match_span(self): """Match text in a span. """ - match = self.span.match(u'moust') + match = self.span.match('moust') return self.assertTrue(match) def test_match_inner_span(self): """Match text in a span from the parent paragraph. """ - match = self.paragraph.match(u'roug') + match = self.paragraph.match('roug') return self.assertTrue(match) def test_simple_regex(self): """Match a simple regex. """ - match = self.paragraph.match(u'che roug') + match = self.paragraph.match('che roug') return self.assertTrue(match) def test_intermediate_regex(self): """Match an intermediate regex. """ - match = self.paragraph.match(u'moustache (blanche|rouge)') + match = self.paragraph.match('moustache (blanche|rouge)') return self.assertTrue(match) @@ -505,14 +505,14 @@ def test_complex_regex(self): """ # The (?<=...) part is pointless as we don't try to get groups from # a MatchObject. However, it's a valid regex expression. - match = self.paragraph.match(ur'(?<=m)(ou)\w+(che) (blan\2|r\1ge)') + match = self.paragraph.match(r'(?<=m)(ou)\w+(che) (blan\2|r\1ge)') return self.assertTrue(match) def test_compiled_regex(self): """Match with a compiled pattern. """ - pattern = compile(ur'moustache') + pattern = compile(r'moustache') match = self.paragraph.match(pattern) return self.assertTrue(match) @@ -520,7 +520,7 @@ def test_compiled_regex(self): def test_failing_match(self): """Test a regex that doesn't match. """ - match = self.paragraph.match(u'Le Père moustache') + match = self.paragraph.match('Le Père moustache') return self.assertFalse(match) @@ -537,7 +537,7 @@ def setUp(self): def test_count(self): paragraph = self.paragraph expected = paragraph.serialize() - count = paragraph.replace(u"ou") + count = paragraph.replace("ou") self.assertEqual(count, 2) # Ensure the orignal was not altered self.assertEqual(paragraph.serialize(), expected) @@ -546,9 +546,9 @@ def test_count(self): def test_replace(self): paragraph = self.paragraph clone = paragraph.clone() - count = clone.replace(u"moustache", u"barbe") + count = clone.replace("moustache", "barbe") self.assertEqual(count, 1) - expected = u"Le Père Noël a une barbe rouge." + expected = "Le Père Noël a une barbe rouge." self.assertEqual(clone.get_text(recursive=True), expected) # Ensure the orignal was not altered self.assertNotEqual(clone.serialize(), paragraph.serialize()) @@ -556,13 +556,13 @@ def test_replace(self): def test_across_span(self): paragraph = self.paragraph - count = paragraph.replace(u"moustache rouge") + count = paragraph.replace("moustache rouge") self.assertEqual(count, 0) def test_missing(self): paragraph = self.paragraph - count = paragraph.replace(u"barbe") + count = paragraph.replace("barbe") self.assertEqual(count, 0) @@ -585,25 +585,25 @@ class dummy_element(odf_element): def test_register(self): register_element_class('office:dummy1', self.dummy_element) element = odf_create_element('office:dummy1') - self.assert_(type(element) is self.dummy_element) + self.assertTrue(type(element) is self.dummy_element) def test_unregistered(self): element = odf_create_element('office:dummy2') - self.assert_(type(element) is odf_element) + self.assertTrue(type(element) is odf_element) def test_register_family(self): register_element_class('office:dummy3', self.dummy_element, family='graphics') element = odf_create_element('') - self.assert_(type(element) is odf_element) + self.assertTrue(type(element) is odf_element) element = odf_create_element('') - self.assert_(type(element) is self.dummy_element) + self.assertTrue(type(element) is self.dummy_element) element = odf_create_element('') - self.assert_(type(element) is odf_element) + self.assertTrue(type(element) is odf_element) diff --git a/test/test_frame.py b/test/test_frame.py index eefea7d..df804b4 100644 --- a/test/test_frame.py +++ b/test/test_frame.py @@ -42,7 +42,7 @@ def setUp(self): def test_create_frame(self): - frame = odf_create_frame(u"A Frame", size=('10cm', '10cm'), + frame = odf_create_frame("A Frame", size=('10cm', '10cm'), style='Graphics') expected = ('' '' '' @@ -152,7 +152,7 @@ def test_create_text_frame(self): def test_create_text_frame_element(self): - heading = odf_create_heading(1, u"Zoé") + heading = odf_create_heading(1, "Zoé") frame = odf_create_text_frame(heading) expected = ('' @@ -178,7 +178,7 @@ def setUp(self): def test_get_frame(self): body = self.body frame = body.get_frame() - self.assert_(isinstance(frame, odf_frame)) + self.assertTrue(isinstance(frame, odf_frame)) def test_get_frame_size(self): diff --git a/test/test_heading.py b/test/test_heading.py index 6d5d261..2bc0767 100644 --- a/test/test_heading.py +++ b/test/test_heading.py @@ -45,7 +45,7 @@ def test_get_heading_list(self): self.assertEqual(len(headings), 3) second = headings[1] text = second.get_text() - self.assertEqual(text, u'Level 2 Title') + self.assertEqual(text, 'Level 2 Title') def test_get_heading_list_style(self): @@ -54,7 +54,7 @@ def test_get_heading_list_style(self): self.assertEqual(len(headings), 1) heading = headings[0] text = heading.get_text() - self.assertEqual(text, u'Level 2 Title') + self.assertEqual(text, 'Level 2 Title') def test_get_heading_list_level(self): @@ -63,7 +63,7 @@ def test_get_heading_list_level(self): self.assertEqual(len(headings), 1) heading = headings[0] text = heading.get_text() - self.assertEqual(text, u'Level 2 Title') + self.assertEqual(text, 'Level 2 Title') def test_get_heading_list_style_level(self): @@ -72,7 +72,7 @@ def test_get_heading_list_style_level(self): self.assertEqual(len(headings), 1) heading = headings[0] text = heading.get_text() - self.assertEqual(text, u'Level 2 Title') + self.assertEqual(text, 'Level 2 Title') def test_get_heading_list_context(self): @@ -82,36 +82,36 @@ def test_get_heading_list_context(self): self.assertEqual(len(headings), 1) heading = headings[0] text = heading.get_text() - self.assertEqual(text, u"First Title of the Second Section"); + self.assertEqual(text, "First Title of the Second Section"); def test_odf_heading(self): body = self.body heading = body.get_heading() - self.assert_(isinstance(heading, odf_heading)) + self.assertTrue(isinstance(heading, odf_heading)) def test_get_heading(self): body = self.body heading = body.get_heading(position=1) text = heading.get_text() - self.assertEqual(text, u'Level 2 Title') + self.assertEqual(text, 'Level 2 Title') def test_get_heading_level(self): body = self.body heading = body.get_heading(outline_level=2) text = heading.get_text() - self.assertEqual(text, u'Level 2 Title') + self.assertEqual(text, 'Level 2 Title') def test_insert_heading(self): body = self.body.clone() - heading = odf_create_heading(2, u'An inserted heading', + heading = odf_create_heading(2, 'An inserted heading', style='Heading_20_2') body.append(heading) last_heading = body.get_headings()[-1] - self.assertEqual(last_heading.get_text(), u'An inserted heading') + self.assertEqual(last_heading.get_text(), 'An inserted heading') diff --git a/test/test_image.py b/test/test_image.py index 4fab06e..8c67edf 100644 --- a/test/test_image.py +++ b/test/test_image.py @@ -60,7 +60,7 @@ def test_get_image_list(self): def test_get_image_by_name(self): body = self.body - element = body.get_image(name=u"Logo") + element = body.get_image(name="Logo") # Searched by frame but got the inner image with no name self.assertEqual(element.get_attribute('xlink:href'), self.path) @@ -81,11 +81,11 @@ def test_insert_image(self): body = self.body.clone() path = 'a/path' image = odf_create_image(path) - frame = odf_create_frame(u"Image Frame", size=('0cm', '0cm'), + frame = odf_create_frame("Image Frame", size=('0cm', '0cm'), style='Graphics') frame.append(image) body.get_frame().insert(frame, NEXT_SIBLING) - element = body.get_image(name=u"Image Frame") + element = body.get_image(name="Image Frame") self.assertEqual(element.get_attribute('xlink:href'), path) element = body.get_image(position=1) self.assertEqual(element.get_attribute('xlink:href'), path) diff --git a/test/test_link.py b/test/test_link.py index e0e053e..31578b3 100644 --- a/test/test_link.py +++ b/test/test_link.py @@ -49,7 +49,7 @@ def test_create_link1(self): def test_create_link2(self): - link = odf_create_link('http://example.com/', name=u'link2', + link = odf_create_link('http://example.com/', name='link2', target_frame='_blank', style='style1', visited_style='style2') expected = ('') self.assertEqual(element.serialize(), expected) @@ -122,13 +122,13 @@ def test_get_link_list_href(self): paragraph.append(link1) paragraph.append(link2) # url - elements = self.body.get_links(url=ur'\.com') + elements = self.body.get_links(url=r'\.com') self.assertEqual(len(elements), 2) def test_href_from_existing_document(self): body = self.body - links = body.get_links(url=ur'lpod') + links = body.get_links(url=r'lpod') self.assertEqual(len(links), 1) @@ -149,17 +149,17 @@ def test_get_link_list_name_and_title(self): def test_get_link_by_href(self): body = self.body - link = body.get_link(url=ur'lpod') + link = body.get_link(url=r'lpod') url = link.get_attribute('xlink:href') - self.assertEqual(url, u'http://lpod-project.net/') + self.assertEqual(url, 'http://lpod-project.net/') def test_get_link_by_path_context(self): body = self.body section2 = body.get_section(position=1) - link = section2.get_link(url=ur'\.net') + link = section2.get_link(url=r'\.net') url = link.get_url() - self.assertEqual(url, u'http://lpod-project.net/') + self.assertEqual(url, 'http://lpod-project.net/') def test_get_link_list_not_found(self): @@ -180,7 +180,7 @@ class TestInsertLink(object): #TestCase): def test_insert_link_simple(self): paragraph = odf_create_element('toto tata titi') - paragraph.insert_link("http://", from_=u"tata", to=u"tata") + paragraph.insert_link("http://", from_="tata", to="tata") expected = ('toto ' 'tata ' 'titi') @@ -190,7 +190,7 @@ def test_insert_link_simple(self): def test_insert_link_medium(self): paragraph = odf_create_element('toto ' 'tata titi') - paragraph.insert_link("http://", from_=u"tata", to=u"tata") + paragraph.insert_link("http://", from_="tata", to="tata") expected = ('toto ' 'tata ' 'titi') @@ -201,7 +201,7 @@ def test_insert_link_complex(self): paragraph = odf_create_element('toto ' ' tata ' 'titi') - paragraph.insert_link("http://", from_=u"tata", to=u"titi") + paragraph.insert_link("http://", from_="tata", to="titi") expected = ('toto ' '' 'tata titi' @@ -214,7 +214,7 @@ def test_insert_link_horrible(self): paragraph = odf_create_element('toto ' 'tata titi' ' tutu ') - paragraph.insert_link("http://", from_=u"titi", to=u"tutu") + paragraph.insert_link("http://", from_="titi", to="tutu") expected = ('toto tata ' '' 'titi tutu' @@ -228,7 +228,7 @@ def test_insert_link_hideous(self): 'tata titi' ' tutu tyty' '') - paragraph.insert_link("http://", from_=u"titi", to=u"tutu") + paragraph.insert_link("http://", from_="titi", to="tutu") expected = ('toto tata ' '' 'titi ' diff --git a/test/test_list.py b/test/test_list.py index 5be504a..2333d9c 100644 --- a/test/test_list.py +++ b/test/test_list.py @@ -55,12 +55,12 @@ def test_create_item(self): def test_create_list(self): item = odf_create_list_item() - a_list = odf_create_list([u'你好 Zoé']) + a_list = odf_create_list(['你好 Zoé']) expected = (('' '' '%s' '' - '') % convert_unicode(u'你好 Zoé')) + '') % convert_unicode('你好 Zoé')) self.assertEqual(a_list.serialize(), expected) @@ -81,9 +81,9 @@ def test_insert_list(self): def test_insert_item(self): breakfast = odf_create_list() - breakfast.insert_item(u'spam', 1) - breakfast.insert_item(u'eggs', 2) - item = odf_create_list_item(u'ham') + breakfast.insert_item('spam', 1) + breakfast.insert_item('eggs', 2) + item = odf_create_list_item('ham') breakfast.insert_item(item, -1) expected = ('' @@ -104,9 +104,9 @@ def test_insert_item(self): def test_append_item(self): breakfast = odf_create_list() - breakfast.append_item(u'spam') - breakfast.append_item(u'ham') - item = odf_create_list_item(u'eggs') + breakfast.append_item('spam') + breakfast.append_item('ham') + item = odf_create_list_item('eggs') breakfast.append_item(item) expected = ('' @@ -126,9 +126,9 @@ def test_append_item(self): def test_insert_sub_item(self): - spam = odf_create_list([u'spam']) - ham = odf_create_list([u'ham']) - eggs = odf_create_list([u'eggs']) + spam = odf_create_list(['spam']) + ham = odf_create_list(['ham']) + eggs = odf_create_list(['eggs']) spam.insert_item(ham, 1) ham.insert_item(eggs, 1) @@ -158,9 +158,9 @@ def test_insert_sub_item(self): def test_append_sub_item(self): - spam = odf_create_list([u'spam']) - ham = odf_create_list([u'ham']) - eggs = odf_create_list([u'eggs']) + spam = odf_create_list(['spam']) + ham = odf_create_list(['ham']) + eggs = odf_create_list(['eggs']) spam.append_item(ham) ham.append_item(eggs) @@ -191,11 +191,11 @@ def test_append_sub_item(self): def test_nested_list(self): breakfast = odf_create_list() - spam = odf_create_list_item(u'spam') - ham = odf_create_list_item(u'ham') - eggs = odf_create_list_item(u'eggs') + spam = odf_create_list_item('spam') + ham = odf_create_list_item('ham') + eggs = odf_create_list_item('eggs') # First way: a list in an item, right next to a paragraph - spam.append(odf_create_list([u'thé', u'café', u'chocolat'])) + spam.append(odf_create_list(['thé', 'café', 'chocolat'])) breakfast.append_item(spam) breakfast.append_item(ham) breakfast.append_item(eggs) @@ -255,10 +255,10 @@ def test_nested_list(self): def test_insert_before(self): breakfast = odf_create_list() - breakfast.append_item(u'spam') - eggs = odf_create_list_item(u'eggs') + breakfast.append_item('spam') + eggs = odf_create_list_item('eggs') breakfast.append_item(eggs) - ham = odf_create_list_item(u'ham') + ham = odf_create_list_item('ham') breakfast.insert_item(ham, before=eggs) expected = ('' @@ -279,10 +279,10 @@ def test_insert_before(self): def test_insert_after(self): breakfast = odf_create_list() - breakfast.append_item(u'spam') - ham = odf_create_list_item(u'ham') + breakfast.append_item('spam') + ham = odf_create_list_item('ham') breakfast.append_item(ham) - eggs = odf_create_list_item(u'eggs') + eggs = odf_create_list_item('eggs') breakfast.insert_item(eggs, after=ham) expected = ('' @@ -303,9 +303,9 @@ def test_insert_after(self): def test_get_item_by_content(self): # Create the items - spam = odf_create_list_item(u'spam') - ham = odf_create_list_item(u'ham') - eggs = odf_create_list_item(u'eggs') + spam = odf_create_list_item('spam') + ham = odf_create_list_item('ham') + eggs = odf_create_list_item('eggs') # Create the corresponding lists spam_list = odf_create_list() ham_list = odf_create_list() @@ -318,7 +318,7 @@ def test_get_item_by_content(self): spam.append(ham_list) ham.append(eggs_list) - item = spam_list.get_item(content=ur'spam') + item = spam_list.get_item(content=r'spam') expected = ('\n' ' spam\n' ' \n' @@ -333,7 +333,7 @@ def test_get_item_by_content(self): ' \n' '\n') self.assertEqual(item.serialize(pretty=True), expected) - item = spam_list.get_item(content=ur'ham') + item = spam_list.get_item(content=r'ham') expected = ('\n' ' ham\n' ' \n' @@ -343,7 +343,7 @@ def test_get_item_by_content(self): ' \n' '\n') self.assertEqual(item.serialize(pretty=True), expected) - item = spam_list.get_item(content=ur'eggs') + item = spam_list.get_item(content=r'eggs') expected = ('\n' ' eggs\n' '\n') @@ -352,15 +352,15 @@ def test_get_item_by_content(self): def test_get_formatted_text(self): # Create the items - spam = odf_create_list_item(u'In this picture, there are 47 people;\n' - u'none of them can be seen.') - ham = odf_create_list_item(u'In this film, we hope to show you the\n' - u'value of not being seen.\n') - eggs = odf_create_list_item(u'Here is Mr. Bagthorpe of London, ' - u'SE14.\n') - foo = odf_create_list_item(u'He cannot be seen.') - bar = odf_create_list_item(u'Now I am going to ask him to stand up.') - baz = odf_create_list_item(u'Mr. Bagthorpe, will you stand up please?') + spam = odf_create_list_item('In this picture, there are 47 people;\n' + 'none of them can be seen.') + ham = odf_create_list_item('In this film, we hope to show you the\n' + 'value of not being seen.\n') + eggs = odf_create_list_item('Here is Mr. Bagthorpe of London, ' + 'SE14.\n') + foo = odf_create_list_item('He cannot be seen.') + bar = odf_create_list_item('Now I am going to ask him to stand up.') + baz = odf_create_list_item('Mr. Bagthorpe, will you stand up please?') # Create the lists how_not_to_be_seen1 = odf_create_list() how_not_to_be_seen2 = odf_create_list() @@ -385,16 +385,16 @@ def test_get_formatted_text(self): 'endnotes': [], 'annotations': [], 'rst_mode': False} - expected = (u'- In this picture, there are 47 people;\n' - u' none of them can be seen.\n' - u' \n' - u' - In this film, we hope to show you the\n' - u' value of not being seen.\n' - u' - Here is Mr. Bagthorpe of London, SE14.\n' - u' - He cannot be seen.\n' - u' \n' - u' - Now I am going to ask him to stand up.\n' - u' - Mr. Bagthorpe, will you stand up please?\n') + expected = ('- In this picture, there are 47 people;\n' + ' none of them can be seen.\n' + ' \n' + ' - In this film, we hope to show you the\n' + ' value of not being seen.\n' + ' - Here is Mr. Bagthorpe of London, SE14.\n' + ' - He cannot be seen.\n' + ' \n' + ' - Now I am going to ask him to stand up.\n' + ' - Mr. Bagthorpe, will you stand up please?\n') self.assertEqual(how_not_to_be_seen1.get_formatted_text(context), expected) diff --git a/test/test_manifest.py b/test/test_manifest.py index 0039fa6..90d49f5 100644 --- a/test/test_manifest.py +++ b/test/test_manifest.py @@ -43,7 +43,7 @@ def setUp(self): def test_get_manifest(self): - self.assert_(type(self.manifest) is odf_manifest) + self.assertTrue(type(self.manifest) is odf_manifest) def test_get_path_list(self): @@ -72,7 +72,7 @@ def test_get_media_type_other(self): def test_get_media_type_missing(self): - self.assert_(self.manifest.get_media_type('LpOD') is None) + self.assertTrue(self.manifest.get_media_type('LpOD') is None) def test_set_media_type(self): @@ -90,7 +90,7 @@ def test_set_media_type_missing(self): def test_add_full_path(self): manifest = self.manifest.clone() - self.assert_(manifest.get_media_type('LpOD') is None) + self.assertTrue(manifest.get_media_type('LpOD') is None) manifest.add_full_path('LpOD', '') self.assertEqual(manifest.get_media_type('LpOD'), '') @@ -108,7 +108,7 @@ def test_del_full_path(self): path = self.image_path self.assertEqual(manifest.get_media_type(path), 'image/png') manifest.del_full_path(path) - self.assert_(manifest.get_media_type(path) is None) + self.assertTrue(manifest.get_media_type(path) is None) diff --git a/test/test_meta.py b/test/test_meta.py index f9457e0..40a6e9f 100644 --- a/test/test_meta.py +++ b/test/test_meta.py @@ -50,14 +50,14 @@ def tearDown(self): def test_get_title(self): meta = self.meta title = meta.get_title() - expected = u"Intitulé" + expected = "Intitulé" self.assertEqual(title, expected) def test_set_title(self): meta = self.meta clone = meta.clone() - title = u"Nouvel intitulé" + title = "Nouvel intitulé" clone.set_title(title) self.assertEqual(clone.get_title(), title) @@ -65,14 +65,14 @@ def test_set_title(self): def test_get_description(self): meta = self.meta description = meta.get_description() - expected = u"Comments\nCommentaires\n评论" + expected = "Comments\nCommentaires\n评论" self.assertEqual(description, expected) def test_set_description(self): meta = self.meta clone = meta.clone() - description = u"评论\nnCommentaires\nComments" + description = "评论\nnCommentaires\nComments" clone.set_description(description) self.assertEqual(clone.get_description(), description) @@ -80,14 +80,14 @@ def test_set_description(self): def test_get_subject(self): meta = self.meta subject = meta.get_subject() - expected = u"Sujet de sa majesté" + expected = "Sujet de sa majesté" self.assertEqual(subject, expected) def test_set_subject(self): meta = self.meta clone = meta.clone() - subject = u"Θέμα" + subject = "Θέμα" clone.set_subject(subject) self.assertEqual(clone.get_subject(), subject) @@ -110,7 +110,7 @@ def test_set_language(self): def test_set_bad_language(self): meta = self.meta clone = meta.clone() - language = u"English" + language = "English" self.assertRaises(TypeError, clone.set_language, language) @@ -168,7 +168,7 @@ def test_get_initial_creator(self): def test_set_initial_creator(self): meta = self.meta clone = meta.clone() - creator = u"Hervé" + creator = "Hervé" clone.set_initial_creator(creator) self.assertEqual(clone.get_initial_creator(), creator) @@ -176,14 +176,14 @@ def test_set_initial_creator(self): def test_get_keywords(self): meta = self.meta keywords = meta.get_keywords() - expected = u"Mots-clés" + expected = "Mots-clés" self.assertEqual(keywords, expected) def test_set_keywords(self): meta = self.meta clone = meta.clone() - keywords = u"Nouveaux mots-clés" + keywords = "Nouveaux mots-clés" clone.set_keywords(keywords) self.assertEqual(clone.get_keywords(), keywords) @@ -235,15 +235,15 @@ def test_set_bad_editing_cycles(self): def test_get_generator(self): meta = self.meta generator = meta.get_generator() - expected = (u"OpenOffice.org/3.1$Unix " - u"OpenOffice.org_project/310m11$Build-9399") + expected = ("OpenOffice.org/3.1$Unix " + "OpenOffice.org_project/310m11$Build-9399") self.assertEqual(generator, expected) def test_set_generator(self): meta = self.meta clone = meta.clone() - generator = u"lpOD Project" + generator = "lpOD Project" clone.set_generator(generator) self.assertEqual(clone.get_generator(), generator) @@ -278,10 +278,10 @@ def test_set_statistic(self): def test_get_user_defined_metadata(self): meta = self.meta metadata = meta.get_user_defined_metadata() - expected = {u"Achevé à la date": datetime(2009, 7, 31), - u"Numéro du document": Decimal("3"), - u"Référence": True, - u"Vérifié par": u"Moi-même"} + expected = {"Achevé à la date": datetime(2009, 7, 31), + "Numéro du document": Decimal("3"), + "Référence": True, + "Vérifié par": "Moi-même"} self.assertEqual(metadata, expected) @@ -291,24 +291,24 @@ def test_set_user_defined_metadata(self): # A new value meta.set_user_defined_metadata('Prop5', 1) # Change a value - meta.set_user_defined_metadata(u"Référence", False) - expected = {u"Achevé à la date": datetime(2009, 7, 31), - u"Numéro du document": Decimal("3"), - u"Référence": False, - u"Vérifié par": u"Moi-même", - u'Prop5': Decimal('1')} + meta.set_user_defined_metadata("Référence", False) + expected = {"Achevé à la date": datetime(2009, 7, 31), + "Numéro du document": Decimal("3"), + "Référence": False, + "Vérifié par": "Moi-même", + 'Prop5': Decimal('1')} metadata = meta.get_user_defined_metadata() self.assertEqual(metadata, expected) def test_get_user_defined_metadata_of_name(self): meta = self.meta - ref = u'Référence' + ref = 'Référence' metadata = meta.get_user_defined_metadata_of_name(ref) expected = {'name': ref, - 'text': u'true', + 'text': 'true', 'value': True, - 'value_type': u'boolean'} + 'value_type': 'boolean'} self.assertEqual(metadata, expected) if __name__ == '__main__': diff --git a/test/test_note.py b/test/test_note.py index 607c964..77a4d38 100644 --- a/test/test_note.py +++ b/test/test_note.py @@ -56,8 +56,8 @@ def setUp(self): def test_create_note1(self): # With an odf_element - note_body = odf_create_paragraph(u'a footnote', style='Standard') - note = odf_create_note(note_id='note1', citation=u'1', + note_body = odf_create_paragraph('a footnote', style='Standard') + note = odf_create_note(note_id='note1', citation='1', body=note_body) expected = self.expected.replace('', '') @@ -66,8 +66,8 @@ def test_create_note1(self): def test_create_note2(self): # With an unicode object - note = odf_create_note(note_id='note1', citation=u'1', - body=u'a footnote') + note = odf_create_note(note_id='note1', citation='1', + body='a footnote') self.assertEqual(note.serialize(), self.expected) @@ -138,10 +138,10 @@ def test_get_note_by_class_endnote(self): def test_insert_note(self): - note = odf_create_note(note_id='note1', citation=u"1", - body=u"élément pertubateur") - paragraph = odf_create_paragraph(u"Un paragraphe") - paragraph.insert_note(note, after=u"para") + note = odf_create_note(note_id='note1', citation="1", + body="élément pertubateur") + paragraph = odf_create_paragraph("Un paragraphe") + paragraph.insert_note(note, after="para") expected = ('Un para' '' @@ -155,11 +155,11 @@ def test_insert_note(self): def test_insert_note_inside_span(self): - note = odf_create_note(note_id='note1', citation=u"1", - body=u"élément pertubateur") + note = odf_create_note(note_id='note1', citation="1", + body="élément pertubateur") data = "Un paragraphe" paragraph = odf_create_element(data) - paragraph.insert_note(note, after=u"para") + paragraph.insert_note(note, after="para") expected = ('Un para' '' @@ -173,11 +173,11 @@ def test_insert_note_inside_span(self): def test_insert_note_after_span(self): - note = odf_create_note(note_id='note1', citation=u"1", - body=u"élément pertubateur") + note = odf_create_note(note_id='note1', citation="1", + body="élément pertubateur") data = "Un paragraphe." paragraph = odf_create_element(data) - paragraph.insert_note(note, after=u"graphe") + paragraph.insert_note(note, after="graphe") expected = ('Un paragraphe' '' @@ -197,15 +197,15 @@ def test_get_formatted_text(self): list_with_note = odf_create_list() list_with_note.append_item(paragraph) body.append(list_with_note) - expected = (u"- Un paragraphe[1] d'apparence(i) banale[*].\n" - u"----\n" - u"[1] C'est-à-dire l'élément « text:p ».\n" - u"\n" - u"----\n" - u"[*] Sauf qu'il est commenté !\n" - u"\n" - u"========\n" - u"(i) Les apparences sont trompeuses !\n") + expected = ("- Un paragraphe[1] d'apparence(i) banale[*].\n" + "----\n" + "[1] C'est-à-dire l'élément « text:p ».\n" + "\n" + "----\n" + "[*] Sauf qu'il est commenté !\n" + "\n" + "========\n" + "(i) Les apparences sont trompeuses !\n") self.assertEqual(document.get_formatted_text(), expected) @@ -219,7 +219,7 @@ def setUp(self): def test_create_annotation(self): # Create - annotation = odf_create_annotation(u"Lost Dialogs", creator=u"Plato", + annotation = odf_create_annotation("Lost Dialogs", creator="Plato", date=datetime(2009, 6, 22, 17, 18, 42)) expected = ('' '' @@ -237,23 +237,23 @@ def test_get_annotation_list(self): self.assertEqual(len(annotations), 1) annotation = annotations[0] creator = annotation.get_dc_creator() - self.assertEqual(creator, u"Auteur inconnu") + self.assertEqual(creator, "Auteur inconnu") date = annotation.get_dc_date() self.assertEqual(date, datetime(2009, 8, 3, 12, 9, 45)) text = annotation.get_text_content() - self.assertEqual(text, u"Sauf qu'il est commenté !") + self.assertEqual(text, "Sauf qu'il est commenté !") def test_get_annotation_list_author(self): body = self.body - creator = u"Auteur inconnu" + creator = "Auteur inconnu" annotations = body.get_annotations(creator=creator) self.assertEqual(len(annotations), 1) def test_get_annotation_list_bad_author(self): body = self.body - creator = u"Plato" + creator = "Plato" annotations = body.get_annotations(creator=creator) self.assertEqual(len(annotations), 0) @@ -306,7 +306,7 @@ def test_get_annotation_list_bad_start_date_end_date(self): def test_get_annotation_list_author_start_date_end_date(self): body = self.body - creator = u"Auteur inconnu" + creator = "Auteur inconnu" start_date = datetime(2009, 8, 1, 0, 0, 0) end_date = datetime(2009, 9, 1, 0, 0, 0) annotations = body.get_annotations(creator=creator, @@ -317,7 +317,7 @@ def test_get_annotation_list_author_start_date_end_date(self): def test_get_annotation_list_bad_author_start_date_end_date(self): body = self.body - creator = u"Plato" + creator = "Plato" start_date = datetime(2009, 6, 1, 0, 0, 0) end_date = datetime(2009, 7, 1, 0, 0, 0) annotations = body.get_annotations(creator=creator, @@ -328,7 +328,7 @@ def test_get_annotation_list_bad_author_start_date_end_date(self): def test_get_annotation_list_author_bad_start_date_end_date(self): body = self.body - creator = u"Auteur inconnu" + creator = "Auteur inconnu" start_date = datetime(2009, 6, 23, 0, 0, 0) end_date = datetime(2009, 7, 1, 0, 0, 0) annotations = body.get_annotations(creator=creator, @@ -338,12 +338,12 @@ def test_get_annotation_list_author_bad_start_date_end_date(self): def test_insert_annotation(self): - text = u"It's like you're in a cave." - creator = u"Plato" + text = "It's like you're in a cave." + creator = "Plato" date = datetime(2009, 8, 19) annotation = odf_create_annotation(text, creator=creator, date=date) - paragraph = odf_create_paragraph(u"Un paragraphe") - paragraph.insert_annotation(annotation, after=u"para") + paragraph = odf_create_paragraph("Un paragraphe") + paragraph.insert_annotation(annotation, after="para") expected = ('Un para' '' 'It\'s like you\'re in a cave.' diff --git a/test/test_paragraph.py b/test/test_paragraph.py index 537b4b0..7cb0a16 100644 --- a/test/test_paragraph.py +++ b/test/test_paragraph.py @@ -73,25 +73,25 @@ def test_get_paragraph_list_context(self): def test_get_paragraph_by_content(self): body = self.body - regex = ur'(first|second|a) paragraph' + regex = r'(first|second|a) paragraph' paragraph = body.get_paragraph(content=regex) text = paragraph.get_text() - self.assertEqual(text, u'This is the first paragraph.') + self.assertEqual(text, 'This is the first paragraph.') def test_get_paragraph_by_content_context(self): body = self.body section2 = body.get_section(position=1) - regex = ur'([Ff]irst|second|a) paragraph' + regex = r'([Ff]irst|second|a) paragraph' paragraph = section2.get_paragraph(content=regex) text = paragraph.get_text() - self.assertEqual(text, u'First paragraph of the second section.') + self.assertEqual(text, 'First paragraph of the second section.') def test_odf_paragraph(self): body = self.body paragraph = body.get_paragraph() - self.assert_(isinstance(paragraph, odf_paragraph)) + self.assertTrue(isinstance(paragraph, odf_paragraph)) def test_get_paragraph(self): @@ -104,11 +104,11 @@ def test_get_paragraph(self): def test_insert_paragraph(self): body = self.body.clone() - paragraph = odf_create_paragraph(u'An inserted test', + paragraph = odf_create_paragraph('An inserted test', style='Text_20_body') body.append(paragraph) last_paragraph = body.get_paragraphs()[-1] - self.assertEqual(last_paragraph.get_text(), u'An inserted test') + self.assertEqual(last_paragraph.get_text(), 'An inserted test') def test_get_paragraph_missed(self): @@ -151,7 +151,7 @@ def test_create_line_break(self): def test_append_plain_text_unicode(self): - txt = u'A test,\n \twith \n\n some é and \t and 5 spaces.' + txt = 'A test,\n \twith \n\n some é and \t and 5 spaces.' para = odf_create_paragraph() para.append_plain_text(txt) expected = ('A test, ' @@ -197,9 +197,9 @@ def test_append_plain_text_guess_iso(self): class TestSetSpan(TestCase): def test_text(self): - text = u"Le Père Noël a une moustache rouge." + text = "Le Père Noël a une moustache rouge." paragraph = odf_create_paragraph(text) - paragraph.set_span(u"highlight", regex=u"rouge") + paragraph.set_span("highlight", regex="rouge") expected = ('Le Père Noël a une moustache ' 'rouge.' @@ -208,10 +208,10 @@ def test_text(self): def test_tail(self): - data = (u"Le Père Noël a une " - u"moustache rouge.") + data = ("Le Père Noël a une " + "moustache rouge.") paragraph = odf_create_element(data) - paragraph.set_span(u"highlight", regex=u"rouge") + paragraph.set_span("highlight", regex="rouge") expected = ('Le Père Noël a une ' 'moustache ' 'Le Père ' 'rouge ' @@ -235,10 +235,10 @@ def test_text_several(self): def test_tail_several(self): - data = (u"Le Père rouge a une " - u"moustache rouge.") + data = ("Le Père rouge a une " + "moustache rouge.") paragraph = odf_create_element(data) - paragraph.set_span(u"highlight", regex=u"rouge") + paragraph.set_span("highlight", regex="rouge") expected = ('Le Père ' 'rouge ' @@ -250,9 +250,9 @@ def test_tail_several(self): def test_offset(self): - text = u"Le Père Noël a une moustache rouge." + text = "Le Père Noël a une moustache rouge." paragraph = odf_create_paragraph(text) - paragraph.set_span(u"highlight", offset=text.index(u"moustache")) + paragraph.set_span("highlight", offset=text.index("moustache")) expected = ('Le Père Noël a une ' 'moustache ' 'rouge.' @@ -261,10 +261,10 @@ def test_offset(self): def test_offset_length(self): - text = u"Le Père Noël a une moustache rouge." + text = "Le Père Noël a une moustache rouge." paragraph = odf_create_paragraph(text) - paragraph.set_span(u"highlight", offset=text.index(u"moustache"), - length=len(u"moustache")) + paragraph.set_span("highlight", offset=text.index("moustache"), + length=len("moustache")) expected = ('Le Père Noël a une ' 'moustache' ' rouge.' @@ -283,84 +283,84 @@ def setUp(self): def test_set_reference_mark_single(self): body = self.body para = body.get_paragraph() - para.set_reference_mark(u'one', position=0) - expected = (u'' - u'' - u'This is the first paragraph.') + para.set_reference_mark('one', position=0) + expected = ('' + '' + 'This is the first paragraph.') self.assertEqual(para.serialize(), expected) def test_set_reference_mark_single_2(self): body = self.body para = body.get_paragraph() - para.set_reference_mark(u'one', position=2) - expected = (u'' - u'Th' - u'' - u'is is the first paragraph.') + para.set_reference_mark('one', position=2) + expected = ('' + 'Th' + '' + 'is is the first paragraph.') self.assertEqual(para.serialize(), expected) def test_set_reference_mark_content(self): body = self.body para = body.get_paragraph() - para.set_reference_mark(u'one', content=para) - expected = (u'' - u'' - u'This is the first paragraph.' - u'' - u'') + para.set_reference_mark('one', content=para) + expected = ('' + '' + 'This is the first paragraph.' + '' + '') self.assertEqual(para.serialize(), expected) def test_set_reference_mark_content_pos(self): body = self.body para = body.get_paragraph() - para.set_reference_mark(u'one', position=(2, 4)) - expected = (u'' - u'Th' - u'' - u'is' - u'' - u' is the first paragraph.' - u'') + para.set_reference_mark('one', position=(2, 4)) + expected = ('' + 'Th' + '' + 'is' + '' + ' is the first paragraph.' + '') self.assertEqual(para.serialize(), expected) def test_set_reference_mark_content_2(self): body = self.body para = body.get_paragraph() - para.set_reference_mark(u'one', content=u'first paragraph.') - expected = (u'' - u'This is the ' - u'' - u'first paragraph.' - u'' - u'') + para.set_reference_mark('one', content='first paragraph.') + expected = ('' + 'This is the ' + '' + 'first paragraph.' + '' + '') self.assertEqual(para.serialize(), expected) def test_set_reference_mark_after(self): body = self.body para = body.get_paragraph() - para.set_reference_mark(u'one', after=u'first') - expected = (u'' - u'This is the first' - u'' - u' paragraph.' - u'') + para.set_reference_mark('one', after='first') + expected = ('' + 'This is the first' + '' + ' paragraph.' + '') self.assertEqual(para.serialize(), expected) def test_set_reference_mark_before(self): body = self.body para = body.get_paragraph() - para.set_reference_mark(u'one', before=u'first') - expected = (u'' - u'This is the ' - u'' - u'first paragraph.' - u'') + para.set_reference_mark('one', before='first') + expected = ('' + 'This is the ' + '' + 'first paragraph.' + '') self.assertEqual(para.serialize(), expected) diff --git a/test/test_reference.py b/test/test_reference.py index 8162af7..fba34b5 100644 --- a/test/test_reference.py +++ b/test/test_reference.py @@ -45,56 +45,56 @@ def setUp(self): def test_create_reference_mark(self): - reference_mark = odf_create_reference_mark(u'你好 Zoé') + reference_mark = odf_create_reference_mark('你好 Zoé') expected = ('' % - convert_unicode(u'你好 Zoé')) + convert_unicode('你好 Zoé')) self.assertEqual(reference_mark.serialize(), expected) def test_create_reference_mark_start(self): - reference_mark_start = odf_create_reference_mark_start(u'你好 Zoé') + reference_mark_start = odf_create_reference_mark_start('你好 Zoé') expected = ('' % - convert_unicode(u'你好 Zoé')) + convert_unicode('你好 Zoé')) self.assertEqual(reference_mark_start.serialize(), expected) def test_create_reference_mark_end(self): - reference_mark_end = odf_create_reference_mark_end(u'你好 Zoé') + reference_mark_end = odf_create_reference_mark_end('你好 Zoé') expected = ('' % - convert_unicode(u'你好 Zoé')) + convert_unicode('你好 Zoé')) self.assertEqual(reference_mark_end.serialize(), expected) def test_get_reference_mark_single(self): body = self.body para = body.get_paragraph() - reference_mark = odf_create_reference_mark(u'你好 Zoé') + reference_mark = odf_create_reference_mark('你好 Zoé') para.append(reference_mark) - get = body.get_reference_mark_single(name=u'你好 Zoé') + get = body.get_reference_mark_single(name='你好 Zoé') expected = ('' % - convert_unicode(u'你好 Zoé')) + convert_unicode('你好 Zoé')) self.assertEqual(get.serialize(), expected) def test_get_reference_mark_single_list(self): body = self.body para = body.get_paragraph() - reference_mark = odf_create_reference_mark(u'你好 Zoé') + reference_mark = odf_create_reference_mark('你好 Zoé') para.append(reference_mark) get = body.get_reference_marks_single()[0] expected = ('' % - convert_unicode(u'你好 Zoé')) + convert_unicode('你好 Zoé')) self.assertEqual(get.serialize(), expected) def test_get_reference_mark_start(self): body = self.body para = body.get_paragraph() - reference_mark_start = odf_create_reference_mark_start(u'你好 Zoé') + reference_mark_start = odf_create_reference_mark_start('你好 Zoé') para.append(reference_mark_start) - get = body.get_reference_mark_start(name=u'你好 Zoé') + get = body.get_reference_mark_start(name='你好 Zoé') expected = ('' % - convert_unicode(u'你好 Zoé')) + convert_unicode('你好 Zoé')) self.assertEqual(get.serialize(), expected) @@ -111,11 +111,11 @@ def test_get_reference_mark_start_list(self): def test_get_reference_mark_end(self): body = self.body para = body.get_paragraph() - reference_mark_end = odf_create_reference_mark_end(u'你好 Zoé') + reference_mark_end = odf_create_reference_mark_end('你好 Zoé') para.append(reference_mark_end) - get = body.get_reference_mark_end(name=u'你好 Zoé') + get = body.get_reference_mark_end(name='你好 Zoé') expected = ('' % - convert_unicode(u'你好 Zoé')) + convert_unicode('你好 Zoé')) self.assertEqual(get.serialize(), expected) @@ -131,140 +131,140 @@ def test_get_reference_mark_end_list(self): def test_get_referenced_1_odf(self): body = self.body2 - para = body.get_paragraph(content=u'of the second title') - para.set_reference_mark(u'one', - content=u'paragraph of the second title') - ref = body.get_reference_mark(name=u'one') + para = body.get_paragraph(content='of the second title') + para.set_reference_mark('one', + content='paragraph of the second title') + ref = body.get_reference_mark(name='one') referenced = ref.get_referenced() - expected = (u'' - u'paragraph of the second title') + expected = ('' + 'paragraph of the second title') self.assertEqual(referenced.serialize(), expected) def test_get_referenced_1_xml(self): body = self.body2 - para = body.get_paragraph(content=u'of the second title') - para.set_reference_mark(u'one', - content=u'paragraph of the second title') - ref = body.get_reference_mark(name=u'one') + para = body.get_paragraph(content='of the second title') + para.set_reference_mark('one', + content='paragraph of the second title') + ref = body.get_reference_mark(name='one') referenced = ref.get_referenced(as_xml=True) - expected = (u'' - u'paragraph of the second title') + expected = ('' + 'paragraph of the second title') self.assertEqual(referenced, expected) def test_get_referenced_1_list(self): body = self.body2 - para = body.get_paragraph(content=u'of the second title') - para.set_reference_mark(u'one', - content=u'paragraph of the second title') - ref = body.get_reference_mark(name=u'one') + para = body.get_paragraph(content='of the second title') + para.set_reference_mark('one', + content='paragraph of the second title') + ref = body.get_reference_mark(name='one') referenced = ref.get_referenced(as_list=True) self.assertEqual(isinstance(referenced, list), True) self.assertEqual(len(referenced), 1) - expected = (u'' - u'paragraph of the second title') + expected = ('' + 'paragraph of the second title') self.assertEqual(referenced[0].serialize(), expected) def test_get_referenced_multi_odf(self): body = self.body2 - para = body.get_paragraph(content=u'of the second title') - para.set_reference_mark(u'one', + para = body.get_paragraph(content='of the second title') + para.set_reference_mark('one', content=para) - para.set_reference_mark(u'two', + para.set_reference_mark('two', position=(0, 7)) - ref = body.get_reference_mark(name=u'two') + ref = body.get_reference_mark(name='two') referenced = ref.get_referenced() - expected = (u'' - u'' - u'This is' - u'') + expected = ('' + '' + 'This is' + '') self.assertEqual(referenced.serialize(), expected) def test_get_referenced_multi_xml_dirty(self): body = self.body2 - para = body.get_paragraph(content=u'of the second title') - para.set_reference_mark(u'one', + para = body.get_paragraph(content='of the second title') + para.set_reference_mark('one', content=para) - para.set_reference_mark(u'two', + para.set_reference_mark('two', position=(0, 7)) - ref = body.get_reference_mark(name=u'one') + ref = body.get_reference_mark(name='one') referenced = ref.get_referenced(as_xml=True, clean=False) - expected = (u'' - u'' - u'' - u'This is' - u' the first paragraph of the second title.' - u'' - u'') + expected = ('' + '' + '' + 'This is' + ' the first paragraph of the second title.' + '' + '') self.assertEqual(referenced, expected) def test_get_referenced_multi_xml_clean(self): body = self.body2 - para = body.get_paragraph(content=u'of the second title') - para.set_reference_mark(u'one', + para = body.get_paragraph(content='of the second title') + para.set_reference_mark('one', content=para) - para.set_reference_mark(u'two', + para.set_reference_mark('two', position=(0, 7)) - ref = body.get_reference_mark(name=u'one') + ref = body.get_reference_mark(name='one') referenced = ref.get_referenced(as_xml=True, clean=True) - expected = (u'' - u'' - u'This is' - u' the first paragraph of the second title.' - u'' - u'') + expected = ('' + '' + 'This is' + ' the first paragraph of the second title.' + '' + '') self.assertEqual(referenced, expected) def test_get_referenced_mix_xml(self): body = self.body2 para = body.get_paragraph() - para.set_reference_mark(u'one', - content=u'first paragraph.') - para.set_reference_mark(u'two', + para.set_reference_mark('one', + content='first paragraph.') + para.set_reference_mark('two', position=(0, 17)) - ref = body.get_reference_mark(name=u'two') + ref = body.get_reference_mark(name='two') referenced = ref.get_referenced(as_xml=True) - expected = (u'' - u'' - u'This is the first' - u'' - u'') + expected = ('' + '' + 'This is the first' + '' + '') self.assertEqual(referenced, expected) def test_get_referenced_header(self): body = self.body2 head = body.get_heading() - head.set_reference_mark(u'one', + head.set_reference_mark('one', content=head) - ref = body.get_reference_mark(name=u'one') + ref = body.get_reference_mark(name='one') referenced = ref.get_referenced(as_xml=True) - expected = (u'' - u'' - u'LpOD Test Case Document' + expected = ('' + '' + 'LpOD Test Case Document' '' - u'') + '') self.assertEqual(referenced, expected) def test_get_referenced_no_header(self): body = self.body2 head = body.get_heading() - head.set_reference_mark(u'one', + head.set_reference_mark('one', content=head) - ref = body.get_reference_mark(name=u'one') + ref = body.get_reference_mark(name='one') referenced = ref.get_referenced(as_xml=True, no_header=True) - expected = (u'' - u'' - u'LpOD Test Case Document' + expected = ('' + '' + 'LpOD Test Case Document' '' - u'') + '') self.assertEqual(referenced, expected) diff --git a/test/test_shapes.py b/test/test_shapes.py index b3ee2b2..2940bbd 100644 --- a/test/test_shapes.py +++ b/test/test_shapes.py @@ -129,28 +129,28 @@ def test_get_draw_line_list(self): def test_get_draw_line_list_regex(self): body = self.content.get_body() page = body.get_draw_page() - lines = page.get_draw_lines(content=ur'èche*') + lines = page.get_draw_lines(content=r'èche*') self.assertEqual(len(lines), 1) def test_get_draw_line_list_draw_style(self): body = self.content.get_body() page = body.get_draw_page() - lines = page.get_draw_lines(draw_style=ur'gr2') + lines = page.get_draw_lines(draw_style=r'gr2') self.assertEqual(len(lines), 1) def test_get_draw_line_list_draw_text_style(self): body = self.content.get_body() page = body.get_draw_page() - lines = page.get_draw_lines(draw_text_style=ur'P1') + lines = page.get_draw_lines(draw_text_style=r'P1') self.assertEqual(len(lines), 2) def test_get_draw_line_by_content(self): body = self.content.get_body() page = body.get_draw_page() - line = page.get_draw_line(content=ur'Ligne') + line = page.get_draw_line(content=r'Ligne') expected = ('\n') self.assertEqual(rectangle.serialize(pretty=True), expected) @@ -238,28 +238,28 @@ def test_get_draw_ellipse_list(self): def test_get_draw_ellipse_list_regex(self): body = self.content.get_body() page = body.get_draw_page() - ellipses = page.get_draw_ellipses(content=ur'rcle') + ellipses = page.get_draw_ellipses(content=r'rcle') self.assertEqual(len(ellipses), 1) def test_get_draw_ellipse_list_draw_style(self): body = self.content.get_body() page = body.get_draw_page() - ellipses = page.get_draw_ellipses(draw_style=ur'gr1') + ellipses = page.get_draw_ellipses(draw_style=r'gr1') self.assertEqual(len(ellipses), 1) def test_get_draw_ellipse_list_draw_text_style(self): body = self.content.get_body() page = body.get_draw_page() - ellipses = page.get_draw_ellipses(draw_text_style=ur'P1') + ellipses = page.get_draw_ellipses(draw_text_style=r'P1') self.assertEqual(len(ellipses), 1) def test_get_draw_ellipse_by_content(self): body = self.content.get_body() page = body.get_draw_page() - ellipse = page.get_draw_ellipse(content=ur'Cerc') + ellipse = page.get_draw_ellipse(content=r'Cerc') expected = ('\n') self.assertEqual(ellipse.serialize(pretty=True), expected) @@ -293,28 +293,28 @@ def test_get_draw_connector_list(self): def test_get_draw_connector_list_regex(self): body = self.content.get_body() page = body.get_draw_page() - connectors = page.get_draw_connectors(content=ur'Con') + connectors = page.get_draw_connectors(content=r'Con') self.assertEqual(len(connectors), 1) def test_get_draw_connector_list_draw_style(self): body = self.content.get_body() page = body.get_draw_page() - connectors = page.get_draw_connectors(draw_style=ur'gr4') + connectors = page.get_draw_connectors(draw_style=r'gr4') self.assertEqual(len(connectors), 1) def test_get_draw_connector_list_draw_text_style(self): body = self.content.get_body() page = body.get_draw_page() - connectors = page.get_draw_connectors(draw_text_style=ur'P1') + connectors = page.get_draw_connectors(draw_text_style=r'P1') self.assertEqual(len(connectors), 1) def test_get_draw_connector_by_content(self): body = self.content.get_body() page = body.get_draw_page() - connector = page.get_draw_connector(content=ur'ecteur') + connector = page.get_draw_connector(content=r'ecteur') expected = ('' 'my text' '') @@ -80,7 +80,7 @@ def test_get_span(self): def test_insert_span(self): body = self.body.clone() - span = odf_create_span('my_style', u'my text') + span = odf_create_span('my_style', 'my text') paragraph = body.get_paragraph(position=0) paragraph.append(span) diff --git a/test/test_style.py b/test/test_style.py index c59596d..0934504 100644 --- a/test/test_style.py +++ b/test/test_style.py @@ -129,7 +129,7 @@ def test_border_bold(self): def test_border_bold2(self): expected = '0.30pt solid #000000' - self.assertEqual(make_table_cell_border_string(thick=u"0.30pt"), expected) + self.assertEqual(make_table_cell_border_string(thick="0.30pt"), expected) def test_border_int(self): expected = '0.06pt solid #000000' @@ -234,14 +234,14 @@ def test_create_style_master_page(self): def test_create_style_display_name(self): - style = odf_create_style('paragraph', display_name=u"Heading 1") + style = odf_create_style('paragraph', display_name="Heading 1") expected = ('') self.assertEqual(style.serialize(), expected) def test_create_style_parent(self): - style = odf_create_style('paragraph', parent=u"Heading 1") + style = odf_create_style('paragraph', parent="Heading 1") expected = ('') self.assertEqual(style.serialize(), expected) @@ -285,7 +285,7 @@ def test_get_styles_family(self): def test_get_style_automatic(self): content = self.content - style = content.get_style('paragraph', u'P1') + style = content.get_style('paragraph', 'P1') self.assertNotEqual(style, None) @@ -301,7 +301,7 @@ def test_insert_style(self): '' '') - get1 = content.get_style('paragraph', u'style1') + get1 = content.get_style('paragraph', 'style1') self.assertEqual(get1.serialize(), expected) @@ -318,13 +318,13 @@ def setUp(self): def test_odf_style(self): style = self.style_element - self.assert_(isinstance(style, odf_style)) + self.assertTrue(isinstance(style, odf_style)) def test_get_style_properties(self): style = self.style_element properties = style.get_properties() - self.assert_(isinstance(properties, dict)) + self.assertTrue(isinstance(properties, dict)) self.assertEqual(len(properties), 12) self.assertEqual(properties['fo:margin-left'], "0cm") @@ -332,7 +332,7 @@ def test_get_style_properties(self): def test_get_style_properties_area(self): style = self.style_element properties = style.get_properties(area='text') - self.assert_(isinstance(properties, dict)) + self.assertTrue(isinstance(properties, dict)) self.assertEqual(len(properties), 1) self.assertEqual(properties['fo:hyphenate'], "false") @@ -453,13 +453,13 @@ def setUp(self): def test_get_level_style(self): level_style = self.style.get_level_style(1) - self.assert_(level_style is None) + self.assertTrue(level_style is None) def test_set_level_style(self): self.style.set_level_style(1, num_format='1') level_style = self.style.get_level_style(1) - self.assert_(level_style is not None) + self.assertTrue(level_style is not None) def test_set_level_style_number_missing_format(self): @@ -468,15 +468,15 @@ def test_set_level_style_number_missing_format(self): def test_set_level_style_number(self): level_style = self.style.set_level_style(1, num_format='1') - self.assert_(type(level_style) is odf_list_level_style_number) + self.assertTrue(type(level_style) is odf_list_level_style_number) expected = ('') self.assertEqual(level_style.serialize(), expected) def test_set_level_style_bullet(self): - level_style = self.style.set_level_style(2, bullet_char=u"·") - self.assert_(type(level_style) is odf_style) + level_style = self.style.set_level_style(2, bullet_char="·") + self.assertTrue(type(level_style) is odf_style) expected = ('') self.assertEqual(level_style.serialize(), expected) @@ -484,7 +484,7 @@ def test_set_level_style_bullet(self): def test_set_level_style_image(self): level_style = self.style.set_level_style(3, url='bullet.png') - self.assert_(type(level_style) is odf_style) + self.assertTrue(type(level_style) is odf_style) expected = ('') self.assertEqual(level_style.serialize(), expected) @@ -492,8 +492,8 @@ def test_set_level_style_image(self): def test_set_level_style_full(self): level_style = self.style.set_level_style(3, num_format='1', - prefix=u" ", suffix=u".", display_levels=3, start_value=2, - style=u'MyList') + prefix=" ", suffix=".", display_levels=3, start_value=2, + style='MyList') expected = ('\n' '\n') - get1 = styles.get_style('paragraph', u'style1') + get1 = styles.get_style('paragraph', 'style1') self.assertEqual(get1.serialize(pretty=True), expected) @@ -112,9 +112,9 @@ def setUp(self): def test_insert_common_style(self): doc = self.doc - style = odf_create_style('paragraph', u'MyStyle') + style = odf_create_style('paragraph', 'MyStyle') doc.insert_style(style) - inserted_style = doc.get_style('paragraph', u'MyStyle') + inserted_style = doc.get_style('paragraph', 'MyStyle') self.assertEqual(style.serialize(), inserted_style.serialize()) @@ -122,7 +122,7 @@ def test_insert_common_style(self): def test_insert_default_style(self): doc = self.doc - style = odf_create_style('paragraph', u'MyStyle') + style = odf_create_style('paragraph', 'MyStyle') doc.insert_style(style, default=True) inserted_style = doc.get_style('paragraph') @@ -142,7 +142,7 @@ def test_insert_automatic_style(self): def test_insert_with_error(self): doc = self.doc - style = odf_create_style('paragraph', u'MyStyle') + style = odf_create_style('paragraph', 'MyStyle') self.assertRaises(AttributeError, doc.insert_style, style=style, automatic=True, default=True) @@ -150,10 +150,10 @@ def test_insert_with_error(self): def test_insert_master_page_style(self): doc = self.doc - style = odf_create_style('master-page', u'MyPageStyle') + style = odf_create_style('master-page', 'MyPageStyle') doc.insert_style(style) - inserted_style = doc.get_style('master-page', u'MyPageStyle') + inserted_style = doc.get_style('master-page', 'MyPageStyle') self.assertEqual(style.serialize(), inserted_style.serialize()) diff --git a/test/test_table.py b/test/test_table.py index 7871dce..b696d21 100644 --- a/test/test_table.py +++ b/test/test_table.py @@ -30,7 +30,7 @@ # Import from the Standard Library from datetime import date, datetime, timedelta from decimal import Decimal as dec -from cStringIO import StringIO +from io import StringIO from unittest import TestCase, main # Import from lpod @@ -164,7 +164,7 @@ def test_bool(self): def test_bool_repr(self): - cell = odf_create_cell(True, text=u"VRAI") + cell = odf_create_cell(True, text="VRAI") expected = ('' 'VRAI' @@ -182,7 +182,7 @@ def test_int(self): def test_int_repr(self): - cell = odf_create_cell(23, text=u"00023") + cell = odf_create_cell(23, text="00023") expected = ('' '00023' @@ -200,7 +200,7 @@ def test_float(self): def test_float_repr(self): - cell = odf_create_cell(3.141592654, text=u"3,14") + cell = odf_create_cell(3.141592654, text="3,14") expected = ('' '3,14' @@ -218,7 +218,7 @@ def test_decimal(self): def test_decimal_repr(self): - cell = odf_create_cell(dec('2.718281828'), text=u"2,72") + cell = odf_create_cell(dec('2.718281828'), text="2,72") expected = ('' '2,72' @@ -236,7 +236,7 @@ def test_date(self): def test_date_repr(self): - cell = odf_create_cell(date(2009, 6, 30), text=u"30/6/2009") + cell = odf_create_cell(date(2009, 6, 30), text="30/6/2009") expected = ('' '30/6/2009' @@ -255,7 +255,7 @@ def test_datetime(self): def test_datetime_repr(self): cell = odf_create_cell(datetime(2009, 6, 30, 17, 33, 18), - text=u"30/6/2009 17:33") + text="30/6/2009 17:33") expected = ('' '30/6/2009 17:33' @@ -273,7 +273,7 @@ def test_str(self): def test_str_repr(self): - cell = odf_create_cell('red', text=u"Red") + cell = odf_create_cell('red', text="Red") expected = ('' 'Red' @@ -282,7 +282,7 @@ def test_str_repr(self): def test_unicode(self): - cell = odf_create_cell(u"Plato") + cell = odf_create_cell("Plato") expected = ('' 'Plato' @@ -291,7 +291,7 @@ def test_unicode(self): def test_unicode_repr(self): - cell = odf_create_cell(u"Plato", text=u"P.") + cell = odf_create_cell("Plato", text="P.") expected = ('' 'P.' @@ -309,7 +309,7 @@ def test_timedelta(self): def test_timedelta_repr(self): - cell = odf_create_cell(timedelta(0, 8), text=u"00:00:08") + cell = odf_create_cell(timedelta(0, 8), text="00:00:08") expected = ('' '00:00:08' @@ -327,7 +327,7 @@ def test_percentage(self): def test_percentage_repr(self): - cell = odf_create_cell(90, text=u"9000 %", cell_type='percentage') + cell = odf_create_cell(90, text="9000 %", cell_type='percentage') expected = ('' '9000 %' @@ -345,7 +345,7 @@ def test_currency(self): def test_currency_repr(self): - cell = odf_create_cell(1.54, text=u"1,54 €", cell_type='currency', + cell = odf_create_cell(1.54, text="1,54 €", cell_type='currency', currency='EUR') expected = ('' @@ -355,7 +355,7 @@ def test_currency_repr(self): def test_style(self): - cell = odf_create_cell(style=u"Monétaire") + cell = odf_create_cell(style="Monétaire") expected = '' self.assertEqual(cell.serialize(), expected) @@ -386,13 +386,13 @@ def test_repeated(self): def test_style(self): - row = odf_create_row(style=u"ro1") + row = odf_create_row(style="ro1") expected = '' self.assertEqual(row.serialize(), expected) def test_all(self): - row = odf_create_row(1, repeated=3, style=u"ro1") + row = odf_create_row(1, repeated=3, style="ro1") expected = ('' '' @@ -410,20 +410,20 @@ def test_default(self): def test_default_cell_style(self): - column = odf_create_column(default_cell_style=u"A Style") + column = odf_create_column(default_cell_style="A Style") expected = ('') self.assertEqual(column.serialize(), expected) def test_style(self): - column = odf_create_column(style=u"A Style") + column = odf_create_column(style="A Style") expected = '' self.assertEqual(column.serialize(), expected) def test_all(self): - column = odf_create_column(style=u"co1", + column = odf_create_column(style="co1", default_cell_style="Standard", repeated=3) expected = ('' '' '' @@ -472,49 +472,49 @@ def test_width_height(self): def test_protected_no_key(self): - self.assertRaises(ValueError, odf_create_table, u"Protected", + self.assertRaises(ValueError, odf_create_table, "Protected", protected=True) def test_protected(self): # TODO self.assertRaises(NotImplementedError, odf_create_table, - u"Protected", protected=True, protection_key='1234') + "Protected", protected=True, protection_key='1234') def test_display(self): - table = odf_create_table(u"Displayed") + table = odf_create_table("Displayed") expected = '' self.assertEqual(table.serialize(), expected) def test_display_false(self): - table = odf_create_table(u"Hidden", display=False) + table = odf_create_table("Hidden", display=False) expected = '' self.assertEqual(table.serialize(), expected) def test_print(self): - table = odf_create_table(u"Printable") + table = odf_create_table("Printable") expected = '' self.assertEqual(table.serialize(), expected) def test_print_false(self): - table = odf_create_table(u"Hidden", printable=False) + table = odf_create_table("Hidden", printable=False) expected = '' self.assertEqual(table.serialize(), expected) def test_print_ranges_str(self): - table = odf_create_table(u"Ranges", print_ranges='E6:K12 P6:R12') + table = odf_create_table("Ranges", print_ranges='E6:K12 P6:R12') expected = ('') self.assertEqual(table.serialize(), expected) def test_print_ranges_list(self): - table = odf_create_table(u"Ranges", + table = odf_create_table("Ranges", print_ranges=['E6:K12', 'P6:R12']) expected = ('') @@ -522,7 +522,7 @@ def test_print_ranges_list(self): def test_style(self): - table = odf_create_table(u"A Table", style=u"A Style") + table = odf_create_table("A Table", style="A Style") expected = ('') self.assertEqual(table.serialize(), expected) @@ -532,7 +532,7 @@ def test_style(self): class TestCell(TestCase): def setUp(self): - self.cell = odf_create_cell(1, repeated=3, style=u"ce1") + self.cell = odf_create_cell(1, repeated=3, style="ce1") def test_get_cell_value(self): @@ -542,16 +542,16 @@ def test_get_cell_value(self): def test_set_cell_value(self): cell = self.cell.clone() - cell.set_value(u"€") - self.assertEqual(cell.get_value(), u"€") + cell.set_value("€") + self.assertEqual(cell.get_value(), "€") self.assertEqual(cell.get_type(), 'string') - self.assertEqual(cell.get_value(get_type=True), (u"€", 'string') ) + self.assertEqual(cell.get_value(get_type=True), ("€", 'string') ) def test_get_cell_type(self): cell = self.cell.clone() self.assertEqual(cell.get_type(), 'float') - cell.set_value(u"€") + cell.set_value("€") self.assertEqual(cell.get_type(), 'string') @@ -607,13 +607,13 @@ def test_set_cell_repeated(self): def test_get_cell_style(self): - self.assertEqual(self.cell.get_style(), u"ce1") + self.assertEqual(self.cell.get_style(), "ce1") def test_set_cell_style(self): cell = self.cell.clone() - cell.set_style(u"ce2") - self.assertEqual(cell.get_style(), u"ce2") + cell.set_style("ce2") + self.assertEqual(cell.get_style(), "ce2") cell.set_style(None) self.assertEqual(cell.get_style(), None) @@ -622,11 +622,11 @@ def test_set_cell_style(self): class TestRow(TestCase): def setUp(self): - row = odf_create_row(width=2, repeated=3, style=u"ro1") + row = odf_create_row(width=2, repeated=3, style="ro1") # Add repeated cell row.append(odf_create_cell(1, repeated=2)) # Add regular cell - row.append(odf_create_cell(style=u"ce1")) + row.append(odf_create_cell(style="ce1")) self.row = row @@ -647,7 +647,7 @@ def test_set_row_repeated(self): def test_get_row_style(self): - self.assertEqual(self.row.get_style(), u"ro1") + self.assertEqual(self.row.get_style(), "ro1") def test_get_row_width(self): @@ -679,7 +679,7 @@ def test_rstrip(self): row.set_value(0, 1) row.set_value(1, 2) row.set_value(2, 3) - row.set_cell(3, odf_create_cell(style=u"ce1")) + row.set_cell(3, odf_create_cell(style="ce1")) row.rstrip() self.assertEqual(row.get_width(), 4) @@ -696,7 +696,7 @@ class TestRowCell(TestCase): def setUp(self): document = odf_get_document('samples/simple_table.ods') body = document.get_body() - table = body.get_table(name=u"Example1").clone() + table = body.get_table(name="Example1").clone() self.row_repeats = table.get_row(0) self.row = table.get_row(1) @@ -758,14 +758,14 @@ def test_get_cells_coord(self): def test_get_cells_regex(self): - coordinates = [cell.x for cell in self.row.get_cells(content=ur'3')] + coordinates = [cell.x for cell in self.row.get_cells(content=r'3')] expected = [4, 5, 6] self.assertEqual(coordinates, expected) def test_get_cells_style(self): coordinates = [cell.x - for cell in self.row.get_cells(style=ur"ce1")] + for cell in self.row.get_cells(style=r"ce1")] expected = [1, 5] self.assertEqual(coordinates, expected) @@ -834,9 +834,9 @@ def test_get_cell_alpha(self): row = self.row cell_5 = row.get_cell('F') self.assertEqual(cell_5.get_value(), 3) - self.assertEqual(cell_5.get_text_content(), u"3") + self.assertEqual(cell_5.get_text_content(), "3") self.assertEqual(cell_5.get_type(), 'float') - self.assertEqual(cell_5.get_style(), u"ce1") + self.assertEqual(cell_5.get_style(), "ce1") self.assertEqual(cell_5.x, 5) self.assertEqual(cell_5.y, 1) @@ -845,9 +845,9 @@ def test_get_cell_int(self): row = self.row cell_5 = row.get_cell(5) self.assertEqual(cell_5.get_value(), 3) - self.assertEqual(cell_5.get_text_content(), u"3") + self.assertEqual(cell_5.get_text_content(), "3") self.assertEqual(cell_5.get_type(), 'float') - self.assertEqual(cell_5.get_style(), u"ce1") + self.assertEqual(cell_5.get_style(), "ce1") def test_get_cell_coord(self): @@ -878,7 +878,7 @@ def test_get_value_coord(self): row = self.row.clone() row.append_cell(odf_create_cell("Appended")) value = row.get_value(-1) - self.assertEqual(value, u'Appended') + self.assertEqual(value, 'Appended') value = row.get_value(-3) self.assertEqual(value, 3) value = row.get_value(-4) @@ -886,9 +886,9 @@ def test_get_value_coord(self): value = row.get_value(-5) self.assertEqual(value, 2) value = row.get_value(-1 - 8) - self.assertEqual(value, u'Appended') + self.assertEqual(value, 'Appended') value = row.get_value(7) - self.assertEqual(value, u'Appended') + self.assertEqual(value, 'Appended') value = row.get_value(8) self.assertEqual(value, None) value = row.get_value(1000) @@ -899,17 +899,17 @@ def test_get_value_coord_with_get_type(self): row = self.row.clone() row.append_cell(odf_create_cell("Appended")) value = row.get_value(-1, get_type=True) - self.assertEqual(value, (u'Appended', u'string')) + self.assertEqual(value, ('Appended', 'string')) value = row.get_value(-3, get_type=True) - self.assertEqual(value, (3, u'float')) + self.assertEqual(value, (3, 'float')) value = row.get_value(-4, get_type=True) - self.assertEqual(value, (3, u'float')) + self.assertEqual(value, (3, 'float')) value = row.get_value(-5, get_type=True) - self.assertEqual(value, (2, u'float')) + self.assertEqual(value, (2, 'float')) value = row.get_value(-1 - 8, get_type=True) - self.assertEqual(value, (u'Appended', u'string')) + self.assertEqual(value, ('Appended', 'string')) value = row.get_value(7, get_type=True) - self.assertEqual(value, (u'Appended', u'string')) + self.assertEqual(value, ('Appended', 'string')) value = row.get_value(8, get_type=True) self.assertEqual(value, (None, None)) value = row.get_value(1000, get_type=True) @@ -956,17 +956,17 @@ def test_set_cell_repeat_repeat(self): def test_insert(self): row = self.row.clone() cell = row.insert_cell(3) - self.assert_(type(cell) is odf_cell) + self.assertTrue(type(cell) is odf_cell) self.assertEqual(cell.x, 3) self.assertEqual(cell.y, 1) def test_insert_cell(self): row = self.row.clone() - cell = row.insert_cell(3, odf_create_cell(u"Inserted")) + cell = row.insert_cell(3, odf_create_cell("Inserted")) self.assertEqual(row.get_width(), 8) self.assertEqual(row.get_values(), - [1, 1, 1, u"Inserted", 2, 3, 3, 3]) + [1, 1, 1, "Inserted", 2, 3, 3, 3]) # Test repetitions are synchronized self.assertEqual(row.get_width(), 8) self.assertEqual(cell.x, 3) @@ -975,9 +975,9 @@ def test_insert_cell(self): def test_insert_cell_repeat(self): row = self.row_repeats.clone() - cell = row.insert_cell(6, odf_create_cell(u"Inserted")) + cell = row.insert_cell(6, odf_create_cell("Inserted")) self.assertEqual(row.get_values(), - [1, 1, 1, 2, 3, 3, u"Inserted", 3]) + [1, 1, 1, 2, 3, 3, "Inserted", 3]) # Test repetitions are synchronized self.assertEqual(row.get_width(), 8) self.assertEqual(cell.x, 6) @@ -986,9 +986,9 @@ def test_insert_cell_repeat(self): def test_insert_cell_repeat_repeat(self): row = self.row_repeats.clone() - cell = row.insert_cell(6, odf_create_cell(u"Inserted", repeated=3)) + cell = row.insert_cell(6, odf_create_cell("Inserted", repeated=3)) self.assertEqual(row.get_values(), - [1, 1, 1, 2, 3, 3, u"Inserted", u"Inserted", u"Inserted", 3]) + [1, 1, 1, 2, 3, 3, "Inserted", "Inserted", "Inserted", 3]) # Test repetitions are synchronized self.assertEqual(row.get_width(), 10) self.assertEqual(cell.x, 6) @@ -997,9 +997,9 @@ def test_insert_cell_repeat_repeat(self): def test_insert_cell_repeat_repeat_bis(self): row = self.row_repeats.clone() - cell = row.insert_cell(1, odf_create_cell(u"Inserted", repeated=2)) + cell = row.insert_cell(1, odf_create_cell("Inserted", repeated=2)) self.assertEqual(row.get_values(), - [1, u"Inserted", u"Inserted", 1, 1, 2, 3, 3, 3]) + [1, "Inserted", "Inserted", 1, 1, 2, 3, 3, 3]) # Test repetitions are synchronized self.assertEqual(row.get_width(), 9) self.assertEqual(cell.x, 1) @@ -1009,16 +1009,16 @@ def test_insert_cell_repeat_repeat_bis(self): def test_append_cell(self): row = self.row.clone() cell = row.append_cell() - self.assert_(type(cell) is odf_cell) + self.assertTrue(type(cell) is odf_cell) self.assertEqual(cell.x, self.row.get_width() ) self.assertEqual(cell.y, 1) def test_append_cell2(self): row = self.row.clone() - cell = row.append_cell(odf_create_cell(u"Appended")) + cell = row.append_cell(odf_create_cell("Appended")) self.assertEqual(row.get_values(), - [1, 1, 1, 2, 3, 3, 3, u"Appended"]) + [1, 1, 1, 2, 3, 3, 3, "Appended"]) # Test repetitions are synchronized self.assertEqual(row.get_width(), 8) self.assertEqual(cell.x, self.row.get_width() ) @@ -1203,38 +1203,38 @@ def test_set_values_empty(self): def test_set_values_on_row(self): row = self.row.clone() - row.set_values([10, 20, 30, u'4']) + row.set_values([10, 20, 30, '4']) self.assertEqual(row.get_width(), 7) - self.assertEqual(row.get_values(), [10, 20, 30, u'4', 3, 3, 3]) + self.assertEqual(row.get_values(), [10, 20, 30, '4', 3, 3, 3]) def test_set_values_on_row2(self): row = self.row.clone() - row.set_values([10, 20, 30, u'4'], start = 2) + row.set_values([10, 20, 30, '4'], start = 2) self.assertEqual(row.get_width(), 7) - self.assertEqual(row.get_values(), [1, 1, 10, 20, 30, u'4', 3]) + self.assertEqual(row.get_values(), [1, 1, 10, 20, 30, '4', 3]) def test_set_values_on_row3(self): row = self.row.clone() - row.set_values([10, 20, 30, u'4'], start = 2) + row.set_values([10, 20, 30, '4'], start = 2) self.assertEqual(row.get_width(), 7) - self.assertEqual(row.get_values(), [1, 1, 10, 20, 30, u'4', 3]) + self.assertEqual(row.get_values(), [1, 1, 10, 20, 30, '4', 3]) def test_set_values_on_row4(self): row = self.row.clone() - row.set_values([10, 20, 30, u'4'], start = -2) + row.set_values([10, 20, 30, '4'], start = -2) self.assertEqual(row.get_width(), 9) - self.assertEqual(row.get_values(), [1, 1, 1, 2, 3, 10, 20, 30, u'4']) + self.assertEqual(row.get_values(), [1, 1, 1, 2, 3, 10, 20, 30, '4']) def test_set_values_on_row5(self): row = self.row.clone() - row.set_values([10, 20, 30, u'4'], start = 8) + row.set_values([10, 20, 30, '4'], start = 8) self.assertEqual(row.get_width(), 7 + 1 + 4) self.assertEqual(row.get_values(), [1, 1, 1, 2, 3, 3, 3, None, - 10, 20, 30, u'4']) + 10, 20, 30, '4']) def test_set_values_on_row6(self): row = self.row.clone() @@ -1249,7 +1249,7 @@ def test_set_values_on_row_percentage(self): self.assertEqual(row.get_width(), 7) self.assertEqual(row.get_values(), [1, 1, 1, 2, 10, 20, 3]) self.assertEqual(row.get_values(get_type=True, cell_type='percentage'), - [(10, u'percentage'), (20, u'percentage')]) + [(10, 'percentage'), (20, 'percentage')]) def test_set_values_on_row_style(self): @@ -1257,16 +1257,16 @@ def test_set_values_on_row_style(self): row.set_values([10, 20], start=3, style='bold') self.assertEqual(row.get_width(), 7) self.assertEqual(row.get_values(), [1, 1, 1, 10, 20, 3, 3]) - self.assertEqual(row.get_cell(4).get_style(), u'bold') + self.assertEqual(row.get_cell(4).get_style(), 'bold') def test_set_values_on_row_curency(self): row = self.row.clone() row.set_values([10, 20], start=3, - cell_type=u'currency', currency=u'EUR') + cell_type='currency', currency='EUR') self.assertEqual(row.get_width(), 7) self.assertEqual(row.get_values(), [1, 1, 1, 10, 20, 3, 3]) - self.assertEqual(row.get_cell(4).get_value(get_type=True), (20, u'currency')) + self.assertEqual(row.get_cell(4).get_value(get_type=True), (20, 'currency')) self.assertEqual(row.get_cell(4).get_currency(), 'EUR') @@ -1282,7 +1282,7 @@ class TestRowCellGetValues(TestCase): def setUp(self): document = odf_get_document('samples/simple_table.ods') body = document.get_body() - table = body.get_table(name=u"Example1").clone() + table = body.get_table(name="Example1").clone() self.row_repeats = table.get_row(0) self.row = table.get_row(1) @@ -1349,7 +1349,7 @@ def test_get_values_cell_type2(self): row.append_cell(odf_create_cell(value="bob2"), clone=False) values = row.get_values(cell_type='all') self.assertEqual(len(values), 7 + 3 ) - self.assertEqual(values, [1, 1, 1, 2, 3, 3, 3, u"bob", 14, u"bob2"]) + self.assertEqual(values, [1, 1, 1, 2, 3, 3, 3, "bob", 14, "bob2"]) values = row.get_values(cell_type='float') self.assertEqual(len(values), 7) self.assertEqual(values, [1, 1, 1, 2, 3, 3, 3]) @@ -1358,7 +1358,7 @@ def test_get_values_cell_type2(self): self.assertEqual(values, [14]) values = row.get_values(cell_type='string') self.assertEqual(len(values), 2) - self.assertEqual(values, [u"bob", u"bob2"]) + self.assertEqual(values, ["bob", "bob2"]) def test_get_values_cell_type2_with_hole(self): @@ -1369,12 +1369,12 @@ def test_get_values_cell_type2_with_hole(self): row.set_cell(12, odf_create_cell(value="far"), clone=False) values = row.get_values(cell_type='all') # aka all non empty self.assertEqual(len(values), 11 ) - self.assertEqual(values, [1, 1, 1, 2, 3, 3, 3, u"bob", 14, u"bob2", - u"far"]) + self.assertEqual(values, [1, 1, 1, 2, 3, 3, 3, "bob", 14, "bob2", + "far"]) values = row.get_values() # difference when requestion everything self.assertEqual(len(values), 13 ) - self.assertEqual(values, [1, 1, 1, 2, 3, 3, 3, u"bob", 14, u"bob2", - None, None, u"far"]) + self.assertEqual(values, [1, 1, 1, 2, 3, 3, 3, "bob", 14, "bob2", + None, None, "far"]) values = row.get_values(cell_type='float') self.assertEqual(len(values), 7) self.assertEqual(values, [1, 1, 1, 2, 3, 3, 3]) @@ -1383,11 +1383,11 @@ def test_get_values_cell_type2_with_hole(self): self.assertEqual(values, [14]) values = row.get_values(cell_type='string') self.assertEqual(len(values), 3) - self.assertEqual(values, [u"bob", u"bob2", u"far"]) + self.assertEqual(values, ["bob", "bob2", "far"]) values = row.get_values(":") # requesting everything self.assertEqual(len(values), 13 ) - self.assertEqual(values, [1, 1, 1, 2, 3, 3, 3, u"bob", 14, u"bob2", - None, None, u"far"]) + self.assertEqual(values, [1, 1, 1, 2, 3, 3, 3, "bob", 14, "bob2", + None, None, "far"]) values = row.get_values(cell_type='float') self.assertEqual(len(values), 7) self.assertEqual(values, [1, 1, 1, 2, 3, 3, 3]) @@ -1396,11 +1396,11 @@ def test_get_values_cell_type2_with_hole(self): self.assertEqual(values, [14]) values = row.get_values(cell_type='string') self.assertEqual(len(values), 3) - self.assertEqual(values, [u"bob", u"bob2", u"far"]) + self.assertEqual(values, ["bob", "bob2", "far"]) values = row.get_values(":") # requesting everything self.assertEqual(len(values), 13 ) - self.assertEqual(values, [1, 1, 1, 2, 3, 3, 3, u"bob", 14, u"bob2", - None, None, u"far"]) + self.assertEqual(values, [1, 1, 1, 2, 3, 3, 3, "bob", 14, "bob2", + None, None, "far"]) values = row.get_values(cell_type='float') self.assertEqual(len(values), 7) self.assertEqual(values, [1, 1, 1, 2, 3, 3, 3]) @@ -1409,11 +1409,11 @@ def test_get_values_cell_type2_with_hole(self): self.assertEqual(values, [14]) values = row.get_values(cell_type='string') self.assertEqual(len(values), 3) - self.assertEqual(values, [u"bob", u"bob2", u"far"]) + self.assertEqual(values, ["bob", "bob2", "far"]) values = row.get_values("") # requesting everything 2 self.assertEqual(len(values), 13 ) - self.assertEqual(values, [1, 1, 1, 2, 3, 3, 3, u"bob", 14, u"bob2", - None, None, u"far"]) + self.assertEqual(values, [1, 1, 1, 2, 3, 3, 3, "bob", 14, "bob2", + None, None, "far"]) values = row.get_values(cell_type='float') self.assertEqual(len(values), 7) self.assertEqual(values, [1, 1, 1, 2, 3, 3, 3]) @@ -1422,7 +1422,7 @@ def test_get_values_cell_type2_with_hole(self): self.assertEqual(values, [14]) values = row.get_values(cell_type='string') self.assertEqual(len(values), 3) - self.assertEqual(values, [u"bob", u"bob2", u"far"]) + self.assertEqual(values, ["bob", "bob2", "far"]) def test_get_values_cell_type2_with_hole_and_get_type(self): row = self.row.clone() @@ -1433,34 +1433,34 @@ def test_get_values_cell_type2_with_hole_and_get_type(self): values = row.get_values(cell_type='all', # aka all non empty get_type=True) self.assertEqual(len(values), 11 ) - self.assertEqual(values, [(1, u"float"), (1, u"float"), (1, u"float"), - (2, u"float"), (3, u"float"), - (3, u"float"), (3, u"float"), - (u"bob", u"string"), (14, u"percentage"), - (u"bob2", u"string"), - (u"far", u"string")]) + self.assertEqual(values, [(1, "float"), (1, "float"), (1, "float"), + (2, "float"), (3, "float"), + (3, "float"), (3, "float"), + ("bob", "string"), (14, "percentage"), + ("bob2", "string"), + ("far", "string")]) values = row.get_values(get_type=True) # difference when everything self.assertEqual(len(values), 13 ) - self.assertEqual(values, [(1, u"float"), (1, u"float"), (1, u"float"), - (2, u"float"), (3, u"float"), - (3, u"float"), (3, u"float"), - (u"bob", u"string"), (14, u"percentage"), - (u"bob2", u"string"), + self.assertEqual(values, [(1, "float"), (1, "float"), (1, "float"), + (2, "float"), (3, "float"), + (3, "float"), (3, "float"), + ("bob", "string"), (14, "percentage"), + ("bob2", "string"), (None, None), (None,None), - (u"far", u"string")]) + ("far", "string")]) values = row.get_values(cell_type='float' ,get_type=True) self.assertEqual(len(values), 7) - self.assertEqual(values, [(1, u"float"), (1, u"float"), (1, u"float"), - (2, u"float"), (3, u"float"), - (3, u"float"), (3, u"float")]) + self.assertEqual(values, [(1, "float"), (1, "float"), (1, "float"), + (2, "float"), (3, "float"), + (3, "float"), (3, "float")]) values = row.get_values(cell_type='percentage', get_type=True) self.assertEqual(len(values), 1) - self.assertEqual(values, [(14, u"percentage")]) + self.assertEqual(values, [(14, "percentage")]) values = row.get_values(cell_type='string', get_type=True) self.assertEqual(len(values), 3) - self.assertEqual(values, [(u"bob", u"string"), - (u"bob2", u"string"), - (u"far", u"string")]) + self.assertEqual(values, [("bob", "string"), + ("bob2", "string"), + ("far", "string")]) def test_get_values_cell_type2_complete(self): @@ -1471,8 +1471,8 @@ def test_get_values_cell_type2_complete(self): row.set_cell(12, odf_create_cell(value="far"), clone=False) values = row.get_values(cell_type='ALL', complete=True) self.assertEqual(len(values), 13 ) - self.assertEqual(values, [1, 1, 1, 2, 3, 3, 3, u"bob", 14, u"bob2", - None, None, u"far"]) + self.assertEqual(values, [1, 1, 1, 2, 3, 3, 3, "bob", 14, "bob2", + None, None, "far"]) values = row.get_values(cell_type='FLOAT', complete=True) self.assertEqual(len(values), 13) self.assertEqual(values, [1, 1, 1, 2, 3, 3, 3, None, None, None, @@ -1484,7 +1484,7 @@ def test_get_values_cell_type2_complete(self): values = row.get_values(cell_type='string', complete=True) self.assertEqual(len(values), 13) self.assertEqual(values, [None, None, None, None, None, None, None, - u"bob", None, u"bob2", None, None, u"far"]) + "bob", None, "bob2", None, None, "far"]) def test_get_values_cell_type_and_coord(self): @@ -1535,15 +1535,15 @@ def test_get_values_cell_type_and_coord_and_get_type(self): values = row.get_values(coord=(0, 5), cell_type='all', get_type=True) self.assertEqual(len(values), 6) - self.assertEqual(values, [(1, u"float"), (1, u"float"), - (1, u"float"), (2, u"float"), - (3, u"float"), (3, u"float")]) + self.assertEqual(values, [(1, "float"), (1, "float"), + (1, "float"), (2, "float"), + (3, "float"), (3, "float")]) values = row.get_values(coord=(0, 5), cell_type='float', get_type=True) self.assertEqual(len(values), 6) - self.assertEqual(values, [(1, u"float"), (1, u"float"), - (1, u"float"), (2, u"float"), - (3, u"float"), (3, u"float")]) + self.assertEqual(values, [(1, "float"), (1, "float"), + (1, "float"), (2, "float"), + (3, "float"), (3, "float")]) values = row.get_values(coord=(0, 5), cell_type='percentage', get_type=True) self.assertEqual(len(values), 0) @@ -1581,12 +1581,12 @@ def test_get_values_cell_type_and_coord2_and_complete(self): values = row.get_values(coord=(2, 20), cell_type='all', complete=True) self.assertEqual(len(values), 11) - self.assertEqual(values, [1, 2, 3, 3, 3, u"bob", 14, u"bob2", - None, None, u"far"]) + self.assertEqual(values, [1, 2, 3, 3, 3, "bob", 14, "bob2", + None, None, "far"]) values = row.get_values(coord=(2, 11), cell_type='all', complete=True) self.assertEqual(len(values), 10) - self.assertEqual(values, [1, 2, 3, 3, 3, u"bob", 14, u"bob2", + self.assertEqual(values, [1, 2, 3, 3, 3, "bob", 14, "bob2", None, None]) values = row.get_values(coord=(3, 12), cell_type='float', complete=True) @@ -1608,13 +1608,13 @@ def test_get_values_cell_type_and_coord2_and_complete(self): values = row.get_values(coord=(6, 12), cell_type='string', complete=True) self.assertEqual(len(values), 7) - self.assertEqual(values, [None, u"bob", None, u"bob2", - None, None, u"far"]) + self.assertEqual(values, [None, "bob", None, "bob2", + None, None, "far"]) values = row.get_values(coord=(8, 20), cell_type='string', complete=True) self.assertEqual(len(values), 5) - self.assertEqual(values, [None, u"bob2", - None, None, u"far"]) + self.assertEqual(values, [None, "bob2", + None, None, "far"]) def test_get_values_cell_type_and_coord2_and_complete_and_get_type(self): @@ -1626,25 +1626,25 @@ def test_get_values_cell_type_and_coord2_and_complete_and_get_type(self): values = row.get_values(coord=(2, 20), cell_type='all', complete=True, get_type=True) self.assertEqual(len(values), 11) - self.assertEqual(values, [(1, u"float"), (2, u"float"), (3, u"float"), - (3, u"float"), (3, u"float"), - (u"bob", u"string"), (14, u"percentage"), - (u"bob2", u"string"), + self.assertEqual(values, [(1, "float"), (2, "float"), (3, "float"), + (3, "float"), (3, "float"), + ("bob", "string"), (14, "percentage"), + ("bob2", "string"), (None, None), (None,None), - (u"far", u"string")]) + ("far", "string")]) values = row.get_values(coord=(2, 11), cell_type='all', complete=True, get_type=True) self.assertEqual(len(values), 10) - self.assertEqual(values, [(1, u"float"), (2, u"float"), (3, u"float"), - (3, u"float"), (3, u"float"), - (u"bob", u"string"), (14, u"percentage"), - (u"bob2", u"string"), + self.assertEqual(values, [(1, "float"), (2, "float"), (3, "float"), + (3, "float"), (3, "float"), + ("bob", "string"), (14, "percentage"), + ("bob2", "string"), (None, None), (None,None)]) values = row.get_values(coord=(3, 12), cell_type='float', complete=True, get_type=True) self.assertEqual(len(values), 10) - self.assertEqual(values, [(2, u"float"), (3, u"float"), - (3, u"float"), (3, u"float"), + self.assertEqual(values, [(2, "float"), (3, "float"), + (3, "float"), (3, "float"), (None, None), (None,None), (None, None), (None,None), (None, None), (None,None)]) @@ -1664,30 +1664,30 @@ def test_get_values_cell_type_and_coord2_and_complete_and_get_type(self): complete=True, get_type=True) self.assertEqual(len(values), 7) self.assertEqual(values, [(None, None), (None,None), - (None, None), (14, u"percentage"), (None,None), + (None, None), (14, "percentage"), (None,None), (None, None), (None,None)]) values = row.get_values(coord=(6, 12), cell_type='string', complete=True, get_type=True) self.assertEqual(len(values), 7) - self.assertEqual(values, [(None, None), (u"bob", u"string"), - (None, None), (u"bob2", u"string"), + self.assertEqual(values, [(None, None), ("bob", "string"), + (None, None), ("bob2", "string"), (None, None), (None, None), - (u"far", u"string")]) + ("far", "string")]) values = row.get_values(coord=(8, 20), cell_type='string', complete=True, get_type=True) self.assertEqual(len(values), 5) - self.assertEqual(values, [(None, None), (u"bob2", u"string"), + self.assertEqual(values, [(None, None), ("bob2", "string"), (None, None), (None, None), - (u"far", u"string")]) + ("far", "string")]) def test_get_cell_alpha(self): row = self.row cell_5 = row.get_cell('F') self.assertEqual(cell_5.get_value(), 3) - self.assertEqual(cell_5.get_text_content(), u"3") + self.assertEqual(cell_5.get_text_content(), "3") self.assertEqual(cell_5.get_type(), 'float') - self.assertEqual(cell_5.get_style(), u"ce1") + self.assertEqual(cell_5.get_style(), "ce1") self.assertEqual(cell_5.x, 5) self.assertEqual(cell_5.y, 1) @@ -1696,9 +1696,9 @@ def test_get_cell_int(self): row = self.row cell_5 = row.get_cell(5) self.assertEqual(cell_5.get_value(), 3) - self.assertEqual(cell_5.get_text_content(), u"3") + self.assertEqual(cell_5.get_text_content(), "3") self.assertEqual(cell_5.get_type(), 'float') - self.assertEqual(cell_5.get_style(), u"ce1") + self.assertEqual(cell_5.get_style(), "ce1") def test_get_cell_coord(self): @@ -1729,7 +1729,7 @@ def test_get_value_coord(self): row = self.row.clone() row.append_cell(odf_create_cell("Appended")) value = row.get_value(-1) - self.assertEqual(value, u'Appended') + self.assertEqual(value, 'Appended') value = row.get_value(-3) self.assertEqual(value, 3) value = row.get_value(-4) @@ -1737,9 +1737,9 @@ def test_get_value_coord(self): value = row.get_value(-5) self.assertEqual(value, 2) value = row.get_value(-1 - 8) - self.assertEqual(value, u'Appended') + self.assertEqual(value, 'Appended') value = row.get_value(7) - self.assertEqual(value, u'Appended') + self.assertEqual(value, 'Appended') value = row.get_value(8) self.assertEqual(value, None) value = row.get_value(1000) @@ -1750,17 +1750,17 @@ def test_get_value_coord_with_get_type(self): row = self.row.clone() row.append_cell(odf_create_cell("Appended")) value = row.get_value(-1, get_type=True) - self.assertEqual(value, (u'Appended', u'string')) + self.assertEqual(value, ('Appended', 'string')) value = row.get_value(-3, get_type=True) - self.assertEqual(value, (3, u'float')) + self.assertEqual(value, (3, 'float')) value = row.get_value(-4, get_type=True) - self.assertEqual(value, (3, u'float')) + self.assertEqual(value, (3, 'float')) value = row.get_value(-5, get_type=True) - self.assertEqual(value, (2, u'float')) + self.assertEqual(value, (2, 'float')) value = row.get_value(-1 - 8, get_type=True) - self.assertEqual(value, (u'Appended', u'string')) + self.assertEqual(value, ('Appended', 'string')) value = row.get_value(7, get_type=True) - self.assertEqual(value, (u'Appended', u'string')) + self.assertEqual(value, ('Appended', 'string')) value = row.get_value(8, get_type=True) self.assertEqual(value, (None, None)) value = row.get_value(1000, get_type=True) @@ -1771,18 +1771,18 @@ def test_get_value_coord_with_get_type(self): class TestColumn(TestCase): def setUp(self): - self.column = odf_create_column(default_cell_style=u"ce1", - repeated=7, style=u"co1") + self.column = odf_create_column(default_cell_style="ce1", + repeated=7, style="co1") def test_get_column_default_cell_style(self): - self.assertEqual(self.column.get_default_cell_style(), u"ce1") + self.assertEqual(self.column.get_default_cell_style(), "ce1") def test_set_column_default_cell_style(self): column = self.column.clone() - column.set_default_cell_style(u"ce2") - self.assertEqual(column.get_default_cell_style(), u"ce2") + column.set_default_cell_style("ce2") + self.assertEqual(column.get_default_cell_style(), "ce2") column.set_default_cell_style(None) self.assertEqual(column.get_default_cell_style(), None) @@ -1804,13 +1804,13 @@ def test_set_column_repeated(self): def test_get_column_style(self): - self.assertEqual(self.column.get_style(), u"co1") + self.assertEqual(self.column.get_style(), "co1") def test_set_column_style(self): column = self.column.clone() - column.set_style(u"co2") - self.assertEqual(column.get_style(), u"co2") + column.set_style("co2") + self.assertEqual(column.get_style(), "co2") column.set_style(None) self.assertEqual(column.get_style(), None) @@ -1826,7 +1826,7 @@ class TestTable(TestCase): def setUp(self): document = odf_get_document('samples/simple_table.ods') self.body = body = document.get_body() - self.table = body.get_table(name=u"Example1") + self.table = body.get_table(name="Example1") def test_get_table_list(self): @@ -1836,12 +1836,12 @@ def test_get_table_list(self): def test_get_table_list_style(self): body = self.body - self.assertEqual(len(body.get_tables(style=u"ta1")), 3) + self.assertEqual(len(body.get_tables(style="ta1")), 3) def test_get_table_by_name(self): body = self.body.clone() - name = u"New Table" + name = "New Table" body.append(odf_create_table(name)) table = body.get_table(name=name) self.assertEqual(table.get_name(), name) @@ -1849,13 +1849,13 @@ def test_get_table_by_name(self): def test_get_table_by_position(self): body = self.body.clone() - body.append(odf_create_table(u"New Table")) + body.append(odf_create_table("New Table")) table = body.get_table(position=3) - self.assertEqual(table.get_name(), u"New Table") + self.assertEqual(table.get_name(), "New Table") def test_get_table_style(self): - self.assertEqual(self.table.get_style(), u"ta1") + self.assertEqual(self.table.get_style(), "ta1") def test_get_table_printable(self): @@ -1875,12 +1875,12 @@ def test_get_table_size(self): def test_get_table_size_empty(self): - table = odf_create_table(u"Empty") + table = odf_create_table("Empty") self.assertEqual(table.get_size(), (0, 0)) def test_get_table_width_after(self): - table = odf_create_table(u"Empty") + table = odf_create_table("Empty") self.assertEqual(table.get_width(), 0) self.assertEqual(table.get_height(), 0) # The first row creates the columns @@ -1903,10 +1903,10 @@ def test_get_values(self): def test_set_table_values_with_clear(self): table = self.table.clone() - values = [[u"a", u"b", u"c", u"d", u"e", u"f", u"g"], - [u"h", u"i", u"j", u"k", u"l", u"m", u"n"], - [u"o", u"p", u"q", u"r", u"s", u"t", u"u"], - [u"v", u"w", u"x", u"y", u"z", u"aa", u"ab"]] + values = [["a", "b", "c", "d", "e", "f", "g"], + ["h", "i", "j", "k", "l", "m", "n"], + ["o", "p", "q", "r", "s", "t", "u"], + ["v", "w", "x", "y", "z", "aa", "ab"]] table.clear() table.set_values(values) self.assertEqual(table.get_values(), values) @@ -1914,14 +1914,14 @@ def test_set_table_values_with_clear(self): def test_set_table_values_big(self): table = self.table.clone() - values = [[u"a", u"b", u"c", u"d", u"e", u"f", u"g"], - [u"h", u"i", u"j", u"k", u"l", u"m", u"n"], - [u"o", u"p", u"q", u"r", u"s", u"t", u"u"], - [u"o", u"p", u"q", u"r", u"s", u"t", u"u"], - [u"o", u"p", u"q", u"r", u"s", u"t", u"u"], - [u"o", u"p", u"q", u"r", u"s", u"t", u"u"], - [u"v", u"w", u"x", u"y", u"z", u"aa", u"ab"], - [u"v", u"w", u"x", u"y", u"z", u"aa", u"ab"]] + values = [["a", "b", "c", "d", "e", "f", "g"], + ["h", "i", "j", "k", "l", "m", "n"], + ["o", "p", "q", "r", "s", "t", "u"], + ["o", "p", "q", "r", "s", "t", "u"], + ["o", "p", "q", "r", "s", "t", "u"], + ["o", "p", "q", "r", "s", "t", "u"], + ["v", "w", "x", "y", "z", "aa", "ab"], + ["v", "w", "x", "y", "z", "aa", "ab"]] table.set_values(values) self.assertEqual(table.get_values(), values) self.assertEqual(table.get_size(), (7, 8)) @@ -1929,37 +1929,37 @@ def test_set_table_values_big(self): def test_set_table_values_small(self): table = self.table.clone() - values = [[u"a", u"b", u"c"], - [u"h", u"i", u"j", u"k", u"l", u"m", u"n"], - [u"o", u"p", None, None, u"s", u"t", u"u"]] + values = [["a", "b", "c"], + ["h", "i", "j", "k", "l", "m", "n"], + ["o", "p", None, None, "s", "t", "u"]] table.set_values(values) self.assertEqual(table.get_size(), (7, 4)) self.assertEqual(table.get_values(), - [[u'a', u'b', u'c', 2, 3, 3, 3], - [u'h', u'i', u'j', u'k', u'l', u'm', u'n'], - [u'o', u'p', None, None, u's', u't', u'u'], + [['a', 'b', 'c', 2, 3, 3, 3], + ['h', 'i', 'j', 'k', 'l', 'm', 'n'], + ['o', 'p', None, None, 's', 't', 'u'], [1, 2, 3, 4, 5, 6, 7]]) def test_set_table_values_small_coord(self): table = self.table.clone() - values = [[u"a", u"b", u"c"], - [u"h", u"i", u"j", u"k", u"l", u"m", u"n"], - [u"o", u"p", None, None, u"s", u"t", u"u"]] + values = [["a", "b", "c"], + ["h", "i", "j", "k", "l", "m", "n"], + ["o", "p", None, None, "s", "t", "u"]] table.set_values(values, coord=("c2")) self.assertEqual(table.get_size(), (9, 4)) self.assertEqual(table.get_values(), [[1, 1, 1, 2, 3, 3, 3, None, None], - [1, 1, u'a', u'b', u'c', 3, 3, None, None], - [1, 1, u'h', u'i', u'j', u'k', u'l', u'm', u'n'], - [1, 2, u'o', u'p', None, None, u's', u't', u'u']]) + [1, 1, 'a', 'b', 'c', 3, 3, None, None], + [1, 1, 'h', 'i', 'j', 'k', 'l', 'm', 'n'], + [1, 2, 'o', 'p', None, None, 's', 't', 'u']]) def test_set_table_values_small_coord_far(self): table = self.table.clone() - values = [[u"a", u"b", u"c"], - [u"h", None ], - [u"o" ]] + values = [["a", "b", "c"], + ["h", None ], + ["o" ]] table.set_values(values, coord=("J6")) self.assertEqual(table.get_size(), (12, 8)) self.assertEqual(table.get_values(), @@ -1970,11 +1970,11 @@ def test_set_table_values_small_coord_far(self): [None, None, None, None, None, None, None, None, None, None, None, None], [None, None, None, None, None, None, None, None, None, - u'a', u'b', u'c'], + 'a', 'b', 'c'], [None, None, None, None, None, None, None, None, None, - u'h', None, None], + 'h', None, None], [None, None, None, None, None, None, None, None, None, - u'o', None, None]]) + 'o', None, None]]) def test_set_table_values_small_type(self): @@ -1990,17 +1990,17 @@ def test_set_table_values_small_type(self): [1, 2, 10, None, 30, 6, 7], [None, None, None, 40, None, None, None]]) self.assertEqual(table.get_values(coord='4:', get_type=True), - [[(1, u'float'), (2, u'float'), - (10, u'percentage'), (None, None), (30, u'percentage'), - (6, u'float'), (7, u'float')], + [[(1, 'float'), (2, 'float'), + (10, 'percentage'), (None, None), (30, 'percentage'), + (6, 'float'), (7, 'float')], [(None, None), (None, None), (None, None), - (40, u'percentage'), (None, None), (None, None), + (40, 'percentage'), (None, None), (None, None), (None, None)]]) def test_rstrip_table(self): document = odf_get_document('samples/styled_table.ods') - table = document.get_body().get_table(name=u'Feuille1').clone() + table = document.get_body().get_table(name='Feuille1').clone() table.rstrip() self.assertEqual(table.get_size(), (5, 9)) @@ -2067,7 +2067,7 @@ class TestTableCellSpan(TestCase): def setUp(self): document = odf_get_document('samples/simple_table.ods') self.body = body = document.get_body() - self.table = body.get_table(name=u"Example1") + self.table = body.get_table(name="Example1") self.table2 = self.table.clone() self.table2.set_value('a1', 'a') self.table2.set_value('b1', 'b') @@ -2107,8 +2107,8 @@ def test_span_sp1_merge(self): table.set_span('a1:a2', merge = True) # span change only display self.assertEqual(table.get_values(), - [[u'a 1', u'b', 1, u'd', 3, 3, 3], - [None, u'', u'C', u'', 3, 3, 3], + [['a 1', 'b', 1, 'd', 3, 3, 3], + [None, '', 'C', '', 3, 3, 3], [1, 1, 1, 2, 3, 3, 3], [1, 2, 3, 4, 5, 6, 7]]) for coord in ('a1', 'a2'): @@ -2163,8 +2163,8 @@ def test_span_sp2_merge(self): table.set_span(zone, merge = True) # span change only display self.assertEqual(table.get_values(), - [[u'a b 1 1 1' , None, 1, u'd', 3, 3, 3], - [None, None, u'C', u'', 3, 3, 3], + [['a b 1 1 1' , None, 1, 'd', 3, 3, 3], + [None, None, 'C', '', 3, 3, 3], [None, None, 1, 2, 3, 3, 3], [1, 2, 3, 4, 5, 6, 7]]) res = [] @@ -2238,8 +2238,8 @@ def test_span_sp3_merge(self): table.set_span(zone, merge = True) # span change only display self.assertEqual(table.get_values(), - [[u'a', u'b', u'1 C 1', u'd', 3, 3, 3], - [1, u'', None, u'', 3, 3, 3], + [['a', 'b', '1 C 1', 'd', 3, 3, 3], + [1, '', None, '', 3, 3, 3], [1, 1, None, 2, 3, 3, 3], [1, 2, 3, 4, 5, 6, 7]]) res = [] @@ -2308,8 +2308,8 @@ def test_span_sp4(self): table.set_span(zone, merge = True) # span change only display self.assertEqual(table.get_values(), - [[u'a', u'b', 1, u'd', 3, 3, u'3 3 3 7'], - [1, u'', u'C', u'', 3, 3, None], + [['a', 'b', 1, 'd', 3, 3, '3 3 3 7'], + [1, '', 'C', '', 3, 3, None], [1, 1, 1, 2, 3, 3, None], [1, 2, 3, 4, 5, 6, None]]) res = [] @@ -2378,9 +2378,9 @@ def test_span_sp5_merge(self): table.set_span(zone, merge = True) # span change only display self.assertEqual(table.get_values(), - [[u'a', u'b', 1, u'd', 3, 3, 3], - [1, u'', u'C', u'', 3, 3, 3], - [u'1 1 1 1 2 3', None, None, 2, 3, 3, 3], + [['a', 'b', 1, 'd', 3, 3, 3], + [1, '', 'C', '', 3, 3, 3], + ['1 1 1 1 2 3', None, None, 2, 3, 3, 3], [None, None, None, 4, 5, 6, 7]]) res = [] for r in table.get_cells(): @@ -2681,7 +2681,7 @@ class TestTableGetValues(TestCase): def setUp(self): document = odf_get_document('samples/simple_table.ods') body = document.get_body() - self.table = body.get_table(name=u"Example1").clone() + self.table = body.get_table(name="Example1").clone() self.row_repeats = self.table.get_row(0) self.row = self.table.get_row(1) @@ -2889,7 +2889,7 @@ def test_get_values_cell_type2_with_hole(self): [1, 1, 1, 2, 3, 3, 3, None, None, None, None, None, None], [1, 1, 1, 2, 3, 3, 3, None, None, None, None, None, None], [1, 2, 3, 4, 5, 6, 7, None, None, None, None, None, None], - [1, 1, 1, 2, 3, 3, 3, u'bob', 14, u'bob2', None, None, u'far']] + [1, 1, 1, 2, 3, 3, 3, 'bob', 14, 'bob2', None, None, 'far']] self.assertEqual(table.get_values(), result ) self.assertEqual(table.get_values('A4:z4'), [result[3]] ) self.assertEqual(table.get_values('5:5'), [result[4]] ) @@ -2907,7 +2907,7 @@ def test_get_values_cell_type2_with_hole_no_comp(self): [1, 1, 1, 2, 3, 3, 3], [1, 1, 1, 2, 3, 3, 3], [1, 2, 3, 4, 5, 6, 7], - [1, 1, 1, 2, 3, 3, 3, u'bob', 14, u'bob2', None, None, u'far']] + [1, 1, 1, 2, 3, 3, 3, 'bob', 14, 'bob2', None, None, 'far']] self.assertEqual(table.get_values(complete=False), result ) self.assertEqual(table.get_values('A4:z4', complete=False), [result[3]] ) @@ -2927,10 +2927,10 @@ def test_get_values_cell_type2_with_hole_no_comp_flat(self): 1, 1, 1, 2, 3, 3, 3, 1, 1, 1, 2, 3, 3, 3, 1, 2, 3, 4, 5, 6, 7, - 1, 1, 1, 2, 3, 3, 3, u'bob', 14, u'bob2', None, None, u'far'] + 1, 1, 1, 2, 3, 3, 3, 'bob', 14, 'bob2', None, None, 'far'] result2 = [1, 2, 3, 4, 5, 6, 7] - result3 = [ 1, 1, 1, 2, 3, 3, 3, u'bob', 14, u'bob2', None, None, - u'far'] + result3 = [ 1, 1, 1, 2, 3, 3, 3, 'bob', 14, 'bob2', None, None, + 'far'] self.assertEqual(table.get_values(complete=False, flat=True,),result) self.assertEqual(table.get_values('A4:z4', flat=True, complete=False), result2 ) @@ -2947,43 +2947,43 @@ def test_get_values_cell_type2_with_hole_get_type(self): table = self.table.clone() table.append_row(row) result1 = [[1, 1, 1, 2, 3, 3, 3, None, None, None, None, None, None]] - result2 = [[None, None, None, None, None, None, None, u'bob', None, - u'bob2', None, None, u'far']] + result2 = [[None, None, None, None, None, None, None, 'bob', None, + 'bob2', None, None, 'far']] self.assertEqual(table.get_values('5:5', cell_type='string'), result2 ) self.assertEqual(table.get_values('5:5', cell_type='string', complete=False, flat=True), - [u'bob', - u'bob2', - u'far'] ) + ['bob', + 'bob2', + 'far'] ) self.assertEqual(table.get_values('5:5', cell_type='string', complete=False, flat=True, get_type=True), - [(u'bob', 'string'), - (u'bob2', 'string'), - (u'far', 'string')] ) + [('bob', 'string'), + ('bob2', 'string'), + ('far', 'string')] ) self.assertEqual(table.get_values( coord='4:5', cell_type='All', get_type=True), - [[ (1, u'float'), (2, u'float'), (3, u'float'), (4, u'float'), - (5, u'float'), (6, u'float'), (7, u'float'),(None, None), + [[ (1, 'float'), (2, 'float'), (3, 'float'), (4, 'float'), + (5, 'float'), (6, 'float'), (7, 'float'),(None, None), (None, None), (None, None), (None, None), (None, None), (None, None)], - [(1, u'float'), (1, u'float'), (1, u'float'), (2, u'float'), - (3, u'float'), (3, u'float'), (3, u'float'), (u'bob', u'string'), - (14, u'percentage'), (u'bob2', u'string'), (None, None), (None, None), - (u'far', u'string')]] ) + [(1, 'float'), (1, 'float'), (1, 'float'), (2, 'float'), + (3, 'float'), (3, 'float'), (3, 'float'), ('bob', 'string'), + (14, 'percentage'), ('bob2', 'string'), (None, None), (None, None), + ('far', 'string')]] ) self.assertEqual(table.get_values( coord='4:5', cell_type='All', get_type=True, complete=False), - [[ (1, u'float'), (2, u'float'), (3, u'float'), (4, u'float'), - (5, u'float'), (6, u'float'), (7, u'float') ], - [(1, u'float'), (1, u'float'), (1, u'float'), (2, u'float'), - (3, u'float'), (3, u'float'), (3, u'float'), (u'bob', u'string'), - (14, u'percentage'), (u'bob2', u'string'), - (u'far', u'string')]] ) + [[ (1, 'float'), (2, 'float'), (3, 'float'), (4, 'float'), + (5, 'float'), (6, 'float'), (7, 'float') ], + [(1, 'float'), (1, 'float'), (1, 'float'), (2, 'float'), + (3, 'float'), (3, 'float'), (3, 'float'), ('bob', 'string'), + (14, 'percentage'), ('bob2', 'string'), + ('far', 'string')]] ) self.assertEqual(table.get_values( coord='4:5', cell_type='string', get_type=True), @@ -2992,19 +2992,19 @@ def test_get_values_cell_type2_with_hole_get_type(self): (None, None), (None, None), (None, None), (None, None), (None, None)], [(None, None), (None, None), (None, None), (None, None), - (None, None), (None, None), (None, None),(u'bob', u'string'), - (None, None), (u'bob2', u'string'), (None, None), (None, None), - (u'far', u'string')]] ) + (None, None), (None, None), (None, None),('bob', 'string'), + (None, None), ('bob2', 'string'), (None, None), (None, None), + ('far', 'string')]] ) self.assertEqual(table.get_values( coord='4:5', cell_type='string', get_type=True, complete=False), - [ [ ], [(u'bob', u'string'), (u'bob2', u'string'), (u'far', u'string')]] ) + [ [ ], [('bob', 'string'), ('bob2', 'string'), ('far', 'string')]] ) self.assertEqual(table.get_values( coord='4:J5', cell_type='string', get_type=True, complete=False), - [ [ ], [(u'bob', u'string'), (u'bob2', u'string'), ]] ) + [ [ ], [('bob', 'string'), ('bob2', 'string'), ]] ) @@ -3013,7 +3013,7 @@ class TestTableCache(TestCase): def setUp(self): document = odf_get_document('samples/simple_table.ods') self.body = body = document.get_body() - self.table = body.get_table(name=u"Example1") + self.table = body.get_table(name="Example1") def test_empty_row_repeat(self): @@ -3103,7 +3103,7 @@ def test_lonely_cell_add_cache(self): self.assertEqual(cell.get_value(), 1) def test_basic_spreadsheet_case(self): - table = odf_create_table(u"Table", width = 20, height = 3) + table = odf_create_table("Table", width = 20, height = 3) for r in range(2): table.append_row() self.assertEqual(len(table.get_rows()), 5) @@ -3114,7 +3114,7 @@ def test_basic_spreadsheet_case(self): last_row = table.get_row(-1) for r in range(3): for c in range(10): - table.set_value((c, r), u"cell %s %s"%(c, r)) + table.set_value((c, r), "cell %s %s"%(c, r)) for r in range(3, 5): for c in range(10): table.set_value((c, r), c * 100 + r) @@ -3129,7 +3129,7 @@ class TestTableRow(TestCase): def setUp(self): document = odf_get_document('samples/simple_table.ods') - self.table = document.get_body().get_table(name=u"Example1") + self.table = document.get_body().get_table(name="Example1") def test_traverse_rows(self): @@ -3146,7 +3146,7 @@ def test_get_row_list(self): def test_get_row_list_regex(self): - coordinates = [row.y for row in self.table.get_rows(content=ur'4')] + coordinates = [row.y for row in self.table.get_rows(content=r'4')] self.assertEqual(coordinates, [3]) @@ -3154,8 +3154,8 @@ def test_get_row_list_style(self): table = self.table.clone() # Set a different style manually row = table.get_elements('table:table-row')[2] - row.set_style(u"A Style") - coordinates = [row.y for row in table.get_rows(style=ur'A Style')] + row.set_style("A Style") + coordinates = [row.y for row in table.get_rows(style=r'A Style')] self.assertEqual(coordinates, [2]) @@ -3177,11 +3177,11 @@ def test_get_row_repeat(self): def test_set_row(self): table = self.table.clone() row = table.get_row(3) - row.set_value(3, u"Changed") + row.set_value(3, "Changed") row_back = table.set_row(1, row) self.assertEqual(table.get_values(), [[1, 1, 1, 2, 3, 3, 3], - [1, 2, 3, u"Changed", 5, 6, 7], + [1, 2, 3, "Changed", 5, 6, 7], [1, 1, 1, 2, 3, 3, 3], [1, 2, 3, 4, 5, 6, 7]]) # test columns are synchronized @@ -3194,12 +3194,12 @@ def test_set_row_repeat(self): # Set a repetition manually table.get_elements('table:table-row')[2].set_repeated(3) row = table.get_row(5) - row.set_value(3, u"Changed") + row.set_value(3, "Changed") table.set_row(2, row) self.assertEqual(table.get_values(), [[1, 1, 1, 2, 3, 3, 3], [1, 1, 1, 2, 3, 3, 3], - [1, 2, 3, u"Changed", 5, 6, 7], + [1, 2, 3, "Changed", 5, 6, 7], [1, 1, 1, 2, 3, 3, 3], [1, 1, 1, 2, 3, 3, 3], [1, 2, 3, 4, 5, 6, 7]]) @@ -3222,7 +3222,7 @@ def test_set_row_bigger(self): def test_insert(self): table = self.table.clone() row = table.insert_row(2) - self.assert_(type(row) is odf_row) + self.assertTrue(type(row) is odf_row) self.assertEqual(row.y, 2) @@ -3276,7 +3276,7 @@ def test_insert_row_bigger(self): def test_append(self): table = self.table.clone() row = table.append_row() - self.assert_(type(row) is odf_row) + self.assertTrue(type(row) is odf_row) def test_append_row(self): @@ -3333,14 +3333,14 @@ def test_delete_row_repeat(self): def test_is_row_empty(self): - table = odf_create_table(u"Empty", width=10, height=20) - for y in xrange(20): + table = odf_create_table("Empty", width=10, height=20) + for y in range(20): self.assertEqual(table.is_row_empty(y), True) def test_is_row_empty_no(self): - table = odf_create_table(u"Not Empty", width=10, height=20) - table.set_value((4, 9), u"Bouh !") + table = odf_create_table("Not Empty", width=10, height=20) + table.set_value((4, 9), "Bouh !") self.assertEqual(table.is_row_empty(9), False) @@ -3350,16 +3350,16 @@ class TestTableCell(TestCase): def setUp(self): document = odf_get_document('samples/simple_table.ods') body = document.get_body() - self.table = body.get_table(name=u"Example1").clone() + self.table = body.get_table(name="Example1").clone() def test_get_cell_alpha(self): table = self.table cell = table.get_cell('D3') self.assertEqual(cell.get_value(), 2) - self.assertEqual(cell.get_text_content(), u"2") + self.assertEqual(cell.get_text_content(), "2") self.assertEqual(cell.get_type(), 'float') - self.assertEqual(cell.get_style(), u"ce1") + self.assertEqual(cell.get_style(), "ce1") self.assertEqual(cell.x, 3) self.assertEqual(cell.y, 2) @@ -3368,20 +3368,20 @@ def test_get_cell_tuple(self): table = self.table cell = table.get_cell((3, 2)) self.assertEqual(cell.get_value(), 2) - self.assertEqual(cell.get_text_content(), u"2") + self.assertEqual(cell.get_text_content(), "2") self.assertEqual(cell.get_type(), 'float') - self.assertEqual(cell.get_style(), u"ce1") + self.assertEqual(cell.get_style(), "ce1") self.assertEqual(cell.x, 3) self.assertEqual(cell.y, 2) def test_set_cell_value(self): table = self.table.clone() - table.set_value('D3', u"Changed") + table.set_value('D3', "Changed") self.assertEqual(table.get_values(), [[1, 1, 1, 2, 3, 3, 3], [1, 1, 1, 2, 3, 3, 3], - [1, 1, 1, u"Changed", 3, 3, 3], + [1, 1, 1, "Changed", 3, 3, 3], [1, 2, 3, 4, 5, 6, 7]]) @@ -3392,7 +3392,7 @@ def test_get_cell_list(self): def test_get_cell_list_regex(self): table = self.table coordinates = [(cell.x, cell.y) - for cell in table.get_cells(content=ur'3', flat=True)] + for cell in table.get_cells(content=r'3', flat=True)] expected = [(4, 0), (5, 0), (6, 0), (4, 1), (5, 1), (6, 1), (4, 2), (5, 2), (6, 2), (2, 3)] self.assertEqual(coordinates, expected) @@ -3401,7 +3401,7 @@ def test_get_cell_list_regex(self): def test_get_cell_list_style(self): table = self.table coordinates = [(cell.x, cell.y) - for cell in table.get_cells(style=ur"ce1", flat=True)] + for cell in table.get_cells(style=r"ce1", flat=True)] expected = [(1, 1), (5, 1), (3, 2)] self.assertEqual(coordinates, expected) @@ -3409,18 +3409,18 @@ def test_get_cell_list_style(self): def test_insert(self): table = self.table.clone() cell = table.insert_cell('B3') - self.assert_(type(cell) is odf_cell) + self.assertTrue(type(cell) is odf_cell) self.assertEqual(cell.x, 1) self.assertEqual(cell.y, 2) def test_insert_cell(self): table = self.table.clone() - cell = table.insert_cell('B3', odf_create_cell(u"Inserted")) + cell = table.insert_cell('B3', odf_create_cell("Inserted")) self.assertEqual(table.get_values(), [[1, 1, 1, 2, 3, 3, 3, None], [1, 1, 1, 2, 3, 3, 3, None], - [1, u"Inserted", 1, 1, 2, 3, 3, 3], + [1, "Inserted", 1, 1, 2, 3, 3, 3], [1, 2, 3, 4, 5, 6, 7, None]]) # Test columns are synchronized self.assertEqual(table.get_width(), 8) @@ -3431,16 +3431,16 @@ def test_insert_cell(self): def test_append(self): table = self.table.clone() cell = table.append_cell(1) - self.assert_(type(cell) is odf_cell) + self.assertTrue(type(cell) is odf_cell) self.assertEqual(cell.x, table.get_width() -1) def test_append_cell(self): table = self.table.clone() - cell = table.append_cell(1, odf_create_cell(u"Appended")) + cell = table.append_cell(1, odf_create_cell("Appended")) self.assertEqual(table.get_values(), [[1, 1, 1, 2, 3, 3, 3, None], - [1, 1, 1, 2, 3, 3, 3, u"Appended"], + [1, 1, 1, 2, 3, 3, 3, "Appended"], [1, 1, 1, 2, 3, 3, 3, None], [1, 2, 3, 4, 5, 6, 7, None]]) # Test columns are synchronized @@ -3468,9 +3468,9 @@ def setUp(self): document2 = odf_get_document('samples/simple_table_named_range.ods') self.body = document.get_body() # no clones ! - self.table = self.body.get_table(name=u"Example1") + self.table = self.body.get_table(name="Example1") self.body2 = document2.get_body() - self.table2 = self.body2.get_table(name=u"Example1") + self.table2 = self.body2.get_table(name="Example1") def test_create_bad_nr(self): @@ -3523,21 +3523,21 @@ def test_create_bad_nr_10(self): def test_create_nr(self): - nr = odf_create_named_range(u'nr_name_ù', 'A1:C2', u'table name é', + nr = odf_create_named_range('nr_name_ù', 'A1:C2', 'table name é', usage = 'filter') result="""""" self.assertEqual(nr.serialize(), result) def test_usage_1(self): - nr = odf_create_named_range(u'a123a', 'A1:C2', u'tablename') + nr = odf_create_named_range('a123a', 'A1:C2', 'tablename') self.assertEqual(nr.usage, None) nr.set_usage('blob') self.assertEqual(nr.usage, None) def test_usage_2(self): - nr = odf_create_named_range(u'nr_name', 'A1:C2', u'tablename') + nr = odf_create_named_range('nr_name', 'A1:C2', 'tablename') nr.set_usage('filter') self.assertEqual(nr.usage, 'filter') nr.set_usage('blob') @@ -3545,7 +3545,7 @@ def test_usage_2(self): def test_usage_3(self): - nr = odf_create_named_range(u'nr_name', 'A1:C2', u'tablename') + nr = odf_create_named_range('nr_name', 'A1:C2', 'tablename') nr.set_usage('Print-Range') self.assertEqual(nr.usage, 'print-range') nr.set_usage(None) @@ -3553,84 +3553,84 @@ def test_usage_3(self): def test_usage_4(self): - nr = odf_create_named_range(u'nr_name', 'A1:C2', u'tablename') - nr.set_usage(u'repeat-column') + nr = odf_create_named_range('nr_name', 'A1:C2', 'tablename') + nr.set_usage('repeat-column') self.assertEqual(nr.usage, 'repeat-column') def test_usage_5(self): - nr = odf_create_named_range(u'nr_name', 'A1:C2', u'tablename') + nr = odf_create_named_range('nr_name', 'A1:C2', 'tablename') nr.set_usage('repeat-row') self.assertEqual(nr.usage, 'repeat-row') def test_name_1(self): - nr = odf_create_named_range(u'nr_name', 'A1:C2', u'tablename') + nr = odf_create_named_range('nr_name', 'A1:C2', 'tablename') self.assertEqual(nr.name, 'nr_name') def test_name_2(self): - nr = odf_create_named_range(u'nr_name', 'A1:C2', u'tablename') - nr.set_name(u' New_Name_ô ') - self.assertEqual(nr.name, u'New_Name_ô') + nr = odf_create_named_range('nr_name', 'A1:C2', 'tablename') + nr.set_name(' New_Name_ô ') + self.assertEqual(nr.name, 'New_Name_ô') def test_name_3(self): - nr = odf_create_named_range(u'nr_name', 'A1:C2', u'tablename') + nr = odf_create_named_range('nr_name', 'A1:C2', 'tablename') self.assertRaises(ValueError, nr.set_name, ' ') def test_table_name_1(self): - nr = odf_create_named_range(u'nr_name', 'A1:C2', u'tablename') + nr = odf_create_named_range('nr_name', 'A1:C2', 'tablename') self.assertEqual(nr.table_name, 'tablename') def test_table_name_2(self): - nr = odf_create_named_range(u'nr_name', 'A1:C2', u'tablename') + nr = odf_create_named_range('nr_name', 'A1:C2', 'tablename') nr.set_table_name(' new name ') self.assertEqual(nr.table_name, 'new name') def test_table_name_3(self): - nr = odf_create_named_range(u'nr_name', 'A1:C2', u'tablename') + nr = odf_create_named_range('nr_name', 'A1:C2', 'tablename') self.assertRaises(ValueError, nr.set_table_name, ' ') def test_range_1(self): - nr = odf_create_named_range(u'nr_name', 'A1:C2', u'tablename') + nr = odf_create_named_range('nr_name', 'A1:C2', 'tablename') self.assertRaises(ValueError, nr.set_range, ' ') def test_range_2(self): - nr = odf_create_named_range(u'nr_name', 'A1:C2', u'tablename') + nr = odf_create_named_range('nr_name', 'A1:C2', 'tablename') self.assertEqual(nr.crange, (0, 0, 2, 1)) self.assertEqual(nr.start, (0, 0)) self.assertEqual(nr.end, (2, 1)) def test_range_3(self): - nr = odf_create_named_range(u'nr_name', 'A1', u'tablename') + nr = odf_create_named_range('nr_name', 'A1', 'tablename') self.assertEqual(nr.crange, (0, 0, 0, 0)) self.assertEqual(nr.start, (0, 0)) self.assertEqual(nr.end, (0, 0)) def test_range_4(self): - nr = odf_create_named_range(u'nr_name', (1, 2, 3, 4), u'tablename') + nr = odf_create_named_range('nr_name', (1, 2, 3, 4), 'tablename') self.assertEqual(nr.crange, (1, 2, 3, 4)) self.assertEqual(nr.start, (1, 2)) self.assertEqual(nr.end, (3, 4)) def test_range_5(self): - nr = odf_create_named_range(u'nr_name', (5, 6), u'tablename') + nr = odf_create_named_range('nr_name', (5, 6), 'tablename') self.assertEqual(nr.crange, (5, 6, 5, 6)) self.assertEqual(nr.start, (5, 6)) self.assertEqual(nr.end, (5, 6)) def test_range_6(self): - nr = odf_create_named_range(u'nr_name', 'A1:C2', u'tablename') + nr = odf_create_named_range('nr_name', 'A1:C2', 'tablename') nr.set_range('B3') self.assertEqual(nr.crange, (1, 2, 1, 2)) self.assertEqual(nr.start, (1, 2)) @@ -3638,7 +3638,7 @@ def test_range_6(self): def test_range_7(self): - nr = odf_create_named_range(u'nr_name', 'A1:C2', u'tablename') + nr = odf_create_named_range('nr_name', 'A1:C2', 'tablename') nr.set_range('B3:b10') self.assertEqual(nr.crange, (1, 2, 1, 9)) self.assertEqual(nr.start, (1, 2)) @@ -3646,7 +3646,7 @@ def test_range_7(self): def test_range_8(self): - nr = odf_create_named_range(u'nr_name', 'A1:C2', u'tablename') + nr = odf_create_named_range('nr_name', 'A1:C2', 'tablename') nr.set_range((1,5,0,9)) self.assertEqual(nr.crange, (1, 5, 0, 9)) self.assertEqual(nr.start, (1, 5)) @@ -3654,7 +3654,7 @@ def test_range_8(self): def test_range_9(self): - nr = odf_create_named_range(u'nr_name', 'A1:C2', u'tablename') + nr = odf_create_named_range('nr_name', 'A1:C2', 'tablename') nr.set_range((0,9)) self.assertEqual(nr.crange, (0, 9, 0, 9)) self.assertEqual(nr.start, (0, 9)) @@ -3662,22 +3662,22 @@ def test_range_9(self): def test_value_bad_1(self): - nr = odf_create_named_range(u'nr_name', 'A1:C2', u'tablename') + nr = odf_create_named_range('nr_name', 'A1:C2', 'tablename') self.assertRaises(ValueError, nr.get_values) def test_value_bad_2(self): - nr = odf_create_named_range(u'nr_name', 'A1:C2', u'tablename') + nr = odf_create_named_range('nr_name', 'A1:C2', 'tablename') self.assertRaises(ValueError, nr.get_value) def test_value_bad_3(self): - nr = odf_create_named_range(u'nr_name', 'A1:C2', u'tablename') + nr = odf_create_named_range('nr_name', 'A1:C2', 'tablename') self.assertRaises(ValueError, nr.set_values, [[1, 2]]) def test_value_bad_4(self): - nr = odf_create_named_range(u'nr_name', 'A1:C2', u'tablename') + nr = odf_create_named_range('nr_name', 'A1:C2', 'tablename') self.assertRaises(ValueError, nr.set_value, 42) @@ -3852,7 +3852,7 @@ class TestTableColumn(TestCase): def setUp(self): document = odf_get_document('samples/simple_table.ods') body = document.get_body() - self.table = body.get_table(name=u"Example1").clone() + self.table = body.get_table(name="Example1").clone() def test_traverse_columns(self): @@ -3865,17 +3865,17 @@ def test_get_column_list(self): def test_get_column_list_style(self): table = self.table - coordinates = [col.x for col in table.get_columns(style=ur"co2")] + coordinates = [col.x for col in table.get_columns(style=r"co2")] self.assertEqual(coordinates, [2, 3]) def test_get_column(self): table = self.table column = table.get_column(3) - self.assertEqual(column.get_style(), u"co2") + self.assertEqual(column.get_style(), "co2") self.assertEqual(column.x, 3) column = table.get_column(4) - self.assertEqual(column.get_style(), u"co1") + self.assertEqual(column.get_style(), "co1") self.assertEqual(column.x, 4) @@ -3886,13 +3886,13 @@ def test_set_column(self): self.assertEqual(column_back.x, 4) column = table.get_column(4) self.assertEqual(column.x, 4) - self.assertEqual(column.get_style(), u"co2") + self.assertEqual(column.get_style(), "co2") def test_insert(self): table = self.table.clone() column = table.insert_column(3) - self.assert_(type(column) is odf_column) + self.assertTrue(type(column) is odf_column) self.assertEqual(column.x, 3) @@ -3907,7 +3907,7 @@ def test_insert_column(self): def test_append(self): table = self.table.clone() column = table.append_column() - self.assert_(type(column) is odf_column) + self.assertTrue(type(column) is odf_column) self.assertEqual(column.x, table.get_width() - 1) @@ -3918,7 +3918,7 @@ def test_append_column(self): self.assertEqual(table.get_row(0).get_width(), 7) self.assertEqual(column.x, table.get_width() - 1) # The column must be inserted between the columns and the rows - self.assert_(type(table.get_children()[-1]) is not odf_column) + self.assertTrue(type(table.get_children()[-1]) is not odf_column) def test_delete_column(self): @@ -3934,23 +3934,23 @@ def test_get_column_cell_values(self): def test_set_column_cell_values(self): table = self.table.clone() - table.set_column_values(5, [u"a", u"b", u"c", u"d"]) + table.set_column_values(5, ["a", "b", "c", "d"]) self.assertEqual(table.get_values(), - [[1, 1, 1, 2, 3, u"a", 3], - [1, 1, 1, 2, 3, u"b", 3], - [1, 1, 1, 2, 3, u"c", 3], - [1, 2, 3, 4, 5, u"d", 7]]) + [[1, 1, 1, 2, 3, "a", 3], + [1, 1, 1, 2, 3, "b", 3], + [1, 1, 1, 2, 3, "c", 3], + [1, 2, 3, 4, 5, "d", 7]]) def test_is_column_empty(self): - table = odf_create_table(u"Empty", width=10, height=20) - for x in xrange(10): + table = odf_create_table("Empty", width=10, height=20) + for x in range(10): self.assertEqual(table.is_column_empty(x), True) def test_is_column_empty_no(self): - table = odf_create_table(u"Not Empty", width=10, height=20) - table.set_value((4, 9), u"Bouh !") + table = odf_create_table("Not Empty", width=10, height=20) + table.set_value((4, 9), "Bouh !") self.assertEqual(table.is_column_empty(4), False) @@ -3958,7 +3958,7 @@ def test_is_column_empty_no(self): class TestCSV(TestCase): def setUp(self): - self.table = import_from_csv(StringIO(csv_data), u"From CSV") + self.table = import_from_csv(StringIO(csv_data), "From CSV") def test_import_from_csv(self): diff --git a/test/test_text.py b/test/test_text.py index 2a085d9..5af5fbf 100644 --- a/test/test_text.py +++ b/test/test_text.py @@ -43,21 +43,21 @@ def test_nodes(self): def test_type(self): - self.assert_(type(self.results[0]) is odf_text) + self.assertTrue(type(self.results[0]) is odf_text) def test_text(self): text = self.results[0] - self.assertEqual(text, u"text") - self.assert_(text.is_text() is True) - self.assert_(text.is_tail() is False) + self.assertEqual(text, "text") + self.assertTrue(text.is_text() is True) + self.assertTrue(text.is_tail() is False) def test_tail(self): tail = self.results[1] - self.assertEqual(tail, u"tail") - self.assert_(tail.is_text() is False) - self.assert_(tail.is_tail() is True) + self.assertEqual(tail, "tail") + self.assertTrue(tail.is_text() is False) + self.assertTrue(tail.is_tail() is True) diff --git a/test/test_toc.py b/test/test_toc.py index 00360cd..f3c4c47 100644 --- a/test/test_toc.py +++ b/test/test_toc.py @@ -43,28 +43,28 @@ class TOCTest(TestCase): def setUp(self): self.document = odf_get_document("samples/toc.odt") self.expected = [ - u"Table des matières", - u"1. Level 1 title 1", - u"1.1. Level 2 title 1", - u"2. Level 1 title 2", - u"2.1.1. Level 3 title 1", - u"2.2. Level 2 title 2", - u"3. Level 1 title 3", - u"3.1. Level 2 title 1", - u"3.1.1. Level 3 title 1", - u"3.1.2. Level 3 title 2", - u"3.2. Level 2 title 2", - u"3.2.1. Level 3 title 1", - u"3.2.2. Level 3 title 2"] + "Table des matières", + "1. Level 1 title 1", + "1.1. Level 2 title 1", + "2. Level 1 title 2", + "2.1.1. Level 3 title 1", + "2.2. Level 2 title 2", + "3. Level 1 title 3", + "3.1. Level 2 title 1", + "3.1.1. Level 3 title 1", + "3.1.2. Level 3 title 2", + "3.2. Level 2 title 2", + "3.2.1. Level 3 title 1", + "3.2.2. Level 3 title 2"] def test_toc_fill_unattached(self): - toc = odf_create_toc(u"Table des matières") + toc = odf_create_toc("Table des matières") self.assertRaises(ValueError, toc.fill) def test_toc_fill_unattached_document(self): - toc = odf_create_toc(u"Table des matières") + toc = odf_create_toc("Table des matières") toc.fill(self.document) toc_lines = get_toc_lines(toc) self.assertEqual(toc_lines, self.expected) @@ -72,7 +72,7 @@ def test_toc_fill_unattached_document(self): def test_toc_fill_attached(self): document = self.document.clone() - toc = odf_create_toc(u"Table des matières") + toc = odf_create_toc("Table des matières") document.get_body().append(toc) toc.fill() toc_lines = get_toc_lines(toc) diff --git a/test/test_tracked_changes.py b/test/test_tracked_changes.py index a3803da..68b832c 100644 --- a/test/test_tracked_changes.py +++ b/test/test_tracked_changes.py @@ -44,7 +44,7 @@ def setUp(self): def test_get_tracked_changes(self): tracked_changes = self.body.get_tracked_changes() - self.assert_(isinstance(tracked_changes, odf_tracked_changes)) + self.assertTrue(isinstance(tracked_changes, odf_tracked_changes)) @@ -62,7 +62,7 @@ def test_get_changed_region_list(self): def test_get_changed_region_list_creator(self): - creator = u'Romain Gauthier' + creator = 'Romain Gauthier' tracked_changes = self.tracked_changes regions = tracked_changes.get_changed_regions(creator=creator) expected = ('\n' @@ -95,7 +95,7 @@ def test_get_changed_region_list_date(self): def test_get_changed_region_list_regex(self): tracked_changes = self.tracked_changes - regions = tracked_changes.get_changed_regions(content=ur'amis') + regions = tracked_changes.get_changed_regions(content=r'amis') expected = ('\n' ' \n' ' \n' @@ -123,7 +123,7 @@ def test_get_changed_region_by_id(self): def test_get_changed_region_by_creator(self): - creator = u'David Versmisse' + creator = 'David Versmisse' tracked_changes = self.tracked_changes region = tracked_changes.get_changed_region(creator=creator) expected = ('\n' @@ -155,7 +155,7 @@ def test_get_changed_region_by_date(self): def test_get_changed_region_by_content(self): tracked_changes = self.tracked_changes - region = tracked_changes.get_changed_region(content=ur'les') + region = tracked_changes.get_changed_region(content=r'les') expected = ('\n' ' \n' ' \n' @@ -178,7 +178,7 @@ def setUp(self): def test_get_changes_ids(self): - paragraph = self.body.get_paragraph(content=ur'Bonjour') + paragraph = self.body.get_paragraph(content=r'Bonjour') changes_ids = paragraph.get_changes_ids() expected = ['ct-1371898904', 'ct-1371898680', 'ct-1371898456'] self.assertEqual(changes_ids, expected) diff --git a/test/test_utils.py b/test/test_utils.py index fc227d0..0797831 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -45,14 +45,14 @@ def test_element(self): def test_attribute(self): query = _make_xpath_query('descendant::text:p', - text_style=u"Standard") + text_style="Standard") self.assertEqual(query, 'descendant::text:p[@text:style-name="Standard"]') def test_two_attributes(self): query = _make_xpath_query('descendant::text:h', - text_style=u"Standard", outline_level=1) + text_style="Standard", outline_level=1) expected = ('descendant::text:h[@text:outline-level="1"]' '[@text:style-name="Standard"]') self.assertEqual(query, expected) @@ -65,14 +65,14 @@ def test_position(self): def test_attribute_position(self): query = _make_xpath_query('descendant::text:p', - text_style=u"Standard", position=1) + text_style="Standard", position=1) self.assertEqual(query, '(descendant::text:p[@text:style-name="Standard"])[2]') def test_two_attributes_position(self): query = _make_xpath_query('descendant::text:h', - text_style=u"Standard", outline_level=1, position=1) + text_style="Standard", outline_level=1, position=1) expected = ('(descendant::text:h[@text:outline-level="1"]' '[@text:style-name="Standard"])[2]') self.assertEqual(query, expected) @@ -89,12 +89,12 @@ def test_with_cell(self): def test_with_variable(self): - variable_set = odf_create_variable_set(u'你好 Zoé', 42) + variable_set = odf_create_variable_set('你好 Zoé', 42) self.assertEqual(get_value(variable_set), 42) def test_with_user_field(self): - user_field_decl = odf_create_user_field_decl(u'你好 Zoé', 42) + user_field_decl = odf_create_user_field_decl('你好 Zoé', 42) self.assertEqual(get_value(user_field_decl), 42) @@ -103,35 +103,35 @@ class Set_Get_ValueTestCase(TestCase): def test_with_cell(self): cell = odf_create_cell(42) - set_value(cell, u'你好 Zoé') + set_value(cell, '你好 Zoé') expected = ('' '' '%s' '' '') % ( - (convert_unicode(u'你好 Zoé'),) * 2) + (convert_unicode('你好 Zoé'),) * 2) self.assertEqual(cell.serialize(), expected) def test_with_variable(self): - variable_set = odf_create_variable_set(u'你好 Zoé', 42) - set_value(variable_set, u'你好 Zoé') + variable_set = odf_create_variable_set('你好 Zoé', 42) + set_value(variable_set, '你好 Zoé') expected = ('' '%s' '') % ( - (convert_unicode(u'你好 Zoé'),) * 3) + (convert_unicode('你好 Zoé'),) * 3) self.assertEqual(variable_set.serialize(), expected) def test_with_user_field(self): - user_field_decl = odf_create_user_field_decl(u'你好 Zoé', 42) - set_value(user_field_decl, u'你好 Zoé') + user_field_decl = odf_create_user_field_decl('你好 Zoé', 42) + set_value(user_field_decl, '你好 Zoé') expected = (('') % - ((convert_unicode(u'你好 Zoé'),) * 2)) + ((convert_unicode('你好 Zoé'),) * 2)) self.assertEqual(user_field_decl.serialize(), expected) @@ -145,19 +145,19 @@ def setUp(self): def test_first(self): last_paragraph = self.body.get_paragraph(position=0) - expected = u"This is the first paragraph." + expected = "This is the first paragraph." self.assertEqual(last_paragraph.get_text(recursive=True), expected) def test_next_to_last(self): last_paragraph = self.body.get_paragraph(position=-2) - expected = u"This is an annotation." + expected = "This is an annotation." self.assertEqual(last_paragraph.get_text(recursive=True), expected) def test_last(self): last_paragraph = self.body.get_paragraph(position=-1) - expected = u"With diacritical signs: éè" + expected = "With diacritical signs: éè" self.assertEqual(last_paragraph.get_text(recursive=True), expected) @@ -190,7 +190,7 @@ def test_str(self): def test_unicode(self): - self.assertFalse(isiterable(u"unicode")) + self.assertFalse(isiterable("unicode")) def test_list(self): diff --git a/test/test_variable.py b/test/test_variable.py index 50fa98e..2b413e0 100644 --- a/test/test_variable.py +++ b/test/test_variable.py @@ -60,66 +60,66 @@ def setUp(self): def test_create_variable_decl(self): - variable_decl = odf_create_variable_decl(u'你好 Zoé', 'float') + variable_decl = odf_create_variable_decl('你好 Zoé', 'float') expected = ('') % convert_unicode(u'你好 Zoé') + 'text:name="%s"/>') % convert_unicode('你好 Zoé') self.assertEqual(variable_decl.serialize(), expected) def test_create_variable_set_float(self): - variable_set = odf_create_variable_set(u'你好 Zoé', value=42) + variable_set = odf_create_variable_set('你好 Zoé', value=42) expected = ('') % convert_unicode(u'你好 Zoé') + 'text:display="none"/>') % convert_unicode('你好 Zoé') self.assertEqual(variable_set.serialize(), expected) def test_create_variable_set_datetime(self): date = datetime(2009, 5, 17, 23, 23, 00) - variable_set = odf_create_variable_set(u'你好 Zoé', value=date, + variable_set = odf_create_variable_set('你好 Zoé', value=date, display=True) expected = ('' '2009-05-17T23:23:00' - '') % convert_unicode(u'你好 Zoé') + '') % convert_unicode('你好 Zoé') self.assertEqual(variable_set.serialize(), expected) def test_create_variable_get(self): - variable_get = odf_create_variable_get(u'你好 Zoé', value=42) + variable_get = odf_create_variable_get('你好 Zoé', value=42) expected = ('' '42' - '') % convert_unicode(u'你好 Zoé') + '') % convert_unicode('你好 Zoé') self.assertEqual(variable_get.serialize(), expected) def test_get_variable_decl(self): clone = self.document.clone() body = clone.get_body() - variable_decl = body.get_variable_decl(u"Variabilité") + variable_decl = body.get_variable_decl("Variabilité") expected = ('' % convert_unicode(u"Variabilité")) + 'text:name="%s"/>' % convert_unicode("Variabilité")) self.assertEqual(variable_decl.serialize(), expected) def test_get_variable_set(self): clone = self.document.clone() body = clone.get_body() - variable_sets = body.get_variable_sets(u"Variabilité") + variable_sets = body.get_variable_sets("Variabilité") self.assertEqual(len(variable_sets), 1) expected = ('123' % - convert_unicode(u"Variabilité")) + convert_unicode("Variabilité")) self.assertEqual(variable_sets[0].serialize(), expected) def test_get_variable_get(self): document = self.document.clone() body = document.get_body() - value = body.get_variable_set_value(u"Variabilité") + value = body.get_variable_set_value("Variabilité") self.assertEqual(value, 123) @@ -131,45 +131,45 @@ def setUp(self): def test_create_user_field_decl(self): - user_field_decl = odf_create_user_field_decl(u'你好 Zoé', 42) + user_field_decl = odf_create_user_field_decl('你好 Zoé', 42) expected = (('') % - convert_unicode(u'你好 Zoé')) + convert_unicode('你好 Zoé')) self.assertEqual(user_field_decl.serialize(), expected) def test_create_user_field_get(self): - user_field_get = odf_create_user_field_get(u'你好 Zoé', value=42) + user_field_get = odf_create_user_field_get('你好 Zoé', value=42) expected = ('' '42' - '') % convert_unicode(u'你好 Zoé') + '') % convert_unicode('你好 Zoé') self.assertEqual(user_field_get.serialize(), expected) def test_create_user_field_input(self): - user_field_input = odf_create_user_field_input(u'你好 Zoé', value=42) + user_field_input = odf_create_user_field_input('你好 Zoé', value=42) expected = ('' '42' - '') % convert_unicode(u'你好 Zoé') + '') % convert_unicode('你好 Zoé') self.assertEqual(user_field_input.serialize(), expected) def test_get_user_field_decl(self): clone = self.document.clone() body = clone.get_body() - user_field_decl = body.get_user_field_decl(u"Champêtre") + user_field_decl = body.get_user_field_decl("Champêtre") expected = ('' % - convert_unicode(u"Champêtre")) + convert_unicode("Champêtre")) self.assertEqual(user_field_decl.serialize(), expected) def test_get_user_field_get(self): clone = self.document.clone() body = clone.get_body() - value = body.get_user_field_value(u"Champêtre") + value = body.get_user_field_value("Champêtre") self.assertEqual(value, True) @@ -182,9 +182,9 @@ def setUp(self): def test_create_user_defined_1(self): - element = odf_create_user_defined(u'unknown_in_meta', + element = odf_create_user_defined('unknown_in_meta', value=42, - value_type=u'float', + value_type='float', text=None, style=None, from_document=self.document) @@ -195,10 +195,10 @@ def test_create_user_defined_1(self): def test_create_user_defined_2(self): - element = odf_create_user_defined(u'unknown_in_meta2', + element = odf_create_user_defined('unknown_in_meta2', value=datetime(2013, 12, 30), - value_type=u'date', - text=u'2013-12-30', + value_type='date', + text='2013-12-30', style=None, from_document=self.document) expected = ('' - 'true') % convert_unicode(u'Référence') + 'true') % convert_unicode('Référence') self.assertEqual(element.serialize(), expected) def test_create_user_defined_4_existing(self): - element = odf_create_user_defined(u'Référence', + element = odf_create_user_defined('Référence', value=False, # default value if not existing - value_type=u'boolean', + value_type='boolean', from_document=self.document) expected = ( '' - 'true') % convert_unicode(u'Référence') + 'true') % convert_unicode('Référence') self.assertEqual(element.serialize(), expected) def test_create_user_defined_5_nodoc(self): - element = odf_create_user_defined(u'Référence', + element = odf_create_user_defined('Référence', value=False, # default value if not existing - value_type=u'boolean', + value_type='boolean', from_document=None) expected = ( '' - 'false') % convert_unicode(u'Référence') + 'false') % convert_unicode('Référence') self.assertEqual(element.serialize(), expected) def test_get_user_defined(self): - element = odf_create_user_defined(u'Référence', + element = odf_create_user_defined('Référence', value=False, # default value if not existing - value_type=u'boolean', + value_type='boolean', from_document=self.document) body = self.document.get_body() para = body.get_paragraph() para.append(element) - user_defined = body.get_user_defined(u'Référence') + user_defined = body.get_user_defined('Référence') expected = ( '' - 'true') % convert_unicode(u'Référence') + 'true') % convert_unicode('Référence') self.assertEqual(user_defined.serialize(), expected) def test_get_user_defined_list(self): - element = odf_create_user_defined(u'Référence', + element = odf_create_user_defined('Référence', value=False, # default value if not existing - value_type=u'boolean', + value_type='boolean', from_document=self.document) body = self.document.get_body() para = body.get_paragraph() para.append(element) - element2 = odf_create_user_defined(u'unknown_in_meta2', + element2 = odf_create_user_defined('unknown_in_meta2', value=datetime(2013, 12, 30), - value_type=u'date', - text=u'2013-12-30', + value_type='date', + text='2013-12-30', style=None, from_document=None) para.append(element2) @@ -296,23 +296,23 @@ def test_get_user_defined_list(self): def test_get_user_defined_value(self): - element = odf_create_user_defined(u'Référence', + element = odf_create_user_defined('Référence', value=False, # default value if not existing - value_type=u'boolean', + value_type='boolean', from_document=self.document) body = self.document.get_body() para = body.get_paragraph() para.append(element) - element2 = odf_create_user_defined(u'unknown_in_meta2', + element2 = odf_create_user_defined('unknown_in_meta2', value=datetime(2013, 12, 30), - value_type=u'date', - text=u'2013-12-30', + value_type='date', + text='2013-12-30', style=None, from_document=None) para.append(element2) - value = body.get_user_defined_value(u'Référence') + value = body.get_user_defined_value('Référence') self.assertEqual(value, True) - value = body.get_user_defined_value(u'unknown_in_meta2') + value = body.get_user_defined_value('unknown_in_meta2') self.assertEqual(value, datetime(2013, 12, 30)) @@ -366,7 +366,7 @@ def test_create_date_fixed(self): def test_create_date_text(self): date_elt = odf_create_date_variable(datetime(2009, 7, 20), - text=u'20 juil. 09') + text='20 juil. 09') expected = ('' '20 juil. 09' '') @@ -394,7 +394,7 @@ def test_create_time_fixed(self): def test_create_time_text(self): - time_elt = odf_create_time_variable(time(19, 30), text=u'19h30') + time_elt = odf_create_time_variable(time(19, 30), text='19h30') expected = ('' '19h30' '') diff --git a/test/test_xmlpart.py b/test/test_xmlpart.py index 28e5a08..e67c6d8 100644 --- a/test/test_xmlpart.py +++ b/test/test_xmlpart.py @@ -59,14 +59,14 @@ def test_tree(self): # Testing a private but important method content = odf_xmlpart(ODF_CONTENT, self.container) tree = content._odf_xmlpart__get_tree() - self.assert_(isinstance(tree, _ElementTree)) + self.assertTrue(isinstance(tree, _ElementTree)) self.assertNotEqual(content._odf_xmlpart__tree, None) def test_root(self): content = odf_xmlpart(ODF_CONTENT, self.container) root = content.get_root() - self.assert_(isinstance(root, odf_element)) + self.assertTrue(isinstance(root, odf_element)) self.assertEqual(root.get_tag(), "office:document-content") self.assertNotEqual(content._odf_xmlpart__root, None) diff --git a/test/use_case1.py b/test/use_case1.py index 27a4741..2ae2f31 100644 --- a/test/use_case1.py +++ b/test/use_case1.py @@ -47,11 +47,11 @@ # Hello messages -print 'lpod installation test' -print ' Version : %s' % __version__ -print ' Installation path : %s' % __installation_path__ -print -print 'Generating test_output/use_case1.odt ...' +print('lpod installation test') +print(' Version : %s' % __version__) +print(' Installation path : %s' % __installation_path__) +print() +print('Generating test_output/use_case1.odt ...') # Go @@ -60,7 +60,7 @@ for numero, filename in enumerate(listdir('samples')): # Heading - heading = odf_create_heading(1, text=unicode(filename, 'utf-8')) + heading = odf_create_heading(1, text=str(filename, 'utf-8')) body.append(heading) path = join('samples', filename) mimetype, _ = guess_type(path) @@ -85,7 +85,7 @@ container = document.container container.set_part(internal_name, open(path).read()) elif mimetype in ('text/csv', 'text/comma-separated-values'): - table = odf_create_table(u"table %d" % numero, style=u"Standard") + table = odf_create_table("table %d" % numero, style="Standard") csv = reader(open(path)) for line in csv: size = len(line) @@ -94,13 +94,13 @@ cell = odf_create_cell(value) row.append_cell(cell) table.append_row(row) - for i in xrange(size): - column = odf_create_column(style=u"Standard") + for i in range(size): + column = odf_create_column(style="Standard") table.insert(column, FIRST_CHILD) body.append(table) else: - paragraph = odf_create_paragraph(u"Not image / csv", - style=u"Standard") + paragraph = odf_create_paragraph("Not image / csv", + style="Standard") body.append(paragraph) if not exists('test_output'): diff --git a/test/use_case2.py b/test/use_case2.py index 3df624a..6e3305b 100644 --- a/test/use_case2.py +++ b/test/use_case2.py @@ -55,11 +55,11 @@ # Hello messages -print 'lpod installation test' -print ' Version : %s' % __version__ -print ' Installation path : %s' % __installation_path__ -print -print 'Generating test_output/use_case2.odt ...' +print('lpod installation test') +print(' Version : %s' % __version__) +print(' Installation path : %s' % __installation_path__) +print() +print('Generating test_output/use_case2.odt ...') # Go document = odf_new_document('text') @@ -69,7 +69,7 @@ # ------------ image = Image.open('samples/image.png') width, height = image.size -paragraph = odf_create_paragraph(style=u"Standard") +paragraph = odf_create_paragraph(style="Standard") # 72 ppp frame = odf_create_frame('frame1', 'Graphics', str(width / 72.0) + 'in', @@ -87,35 +87,35 @@ # 1- Congratulations (=> style on paragraph) # ------------------------------------------ -heading = odf_create_heading(1, text=u'Congratulations !') +heading = odf_create_heading(1, text='Congratulations !') body.append(heading) # The style -style = odf_create_style('paragraph', u"style1", parent=u"Standard", +style = odf_create_style('paragraph', "style1", parent="Standard", area='text', color=rgb2hex('blue'), background_color=rgb2hex('red')) document.insert_style(style) # The paragraph -text = u'This document has been generated by the lpOD installation test.' -paragraph = odf_create_paragraph(text, style=u"style1") +text = 'This document has been generated by the lpOD installation test.' +paragraph = odf_create_paragraph(text, style="style1") body.append(paragraph) # 2- Your environment (=> a table) # -------------------------------- -heading = odf_create_heading(1, text=u'Your environment') +heading = odf_create_heading(1, text='Your environment') body.append(heading) data = [] # lpOD Version -data.append([u'lpOD library version', __version__]) +data.append(['lpOD library version', __version__]) # Python version -data.append([u'Python version', '%d.%d.%d' % version_info[:3]]) +data.append(['Python version', '%d.%d.%d' % version_info[:3]]) # Creation / Insertion -table = odf_create_table(u'table1', width=2, height=2, style=u"Standard") +table = odf_create_table('table1', width=2, height=2, style="Standard") table.set_values(data) body.append(table) @@ -123,28 +123,28 @@ # 3- Description (=> footnote & => highlight) # ------------------------------------------- -heading = odf_create_heading(1, text=u'Description') +heading = odf_create_heading(1, text='Description') body.append(heading) # A paragraph with a note -text = u'The lpOD project is made to generate easily OpenDocuments.' -paragraph = odf_create_paragraph(text, style=u"Standard") -paragraph.insert_note(after=u"lpOD project", note_id='note1', - citation=u'1', body=u'http://lpod-project.net/') +text = 'The lpOD project is made to generate easily OpenDocuments.' +paragraph = odf_create_paragraph(text, style="Standard") +paragraph.insert_note(after="lpOD project", note_id='note1', + citation='1', body='http://lpod-project.net/') body.append(paragraph) # A paragraph with a highlighted word # The style -style = odf_create_style('text', u"style2", parent=u"Standard", area='text', +style = odf_create_style('text', "style2", parent="Standard", area='text', background_color=rgb2hex('yellow')) document.insert_style(style) # The paragraph -text = (u'The office document file format OpenDocument Format (ODF) ' - u'is an ISO standard ISO 26300 used by many applications.') -paragraph = odf_create_paragraph(text, u"Standard") -paragraph.set_span(u"style2", regex=u"ISO standard") +text = ('The office document file format OpenDocument Format (ODF) ' + 'is an ISO standard ISO 26300 used by many applications.') +paragraph = odf_create_paragraph(text, "Standard") +paragraph.set_span("style2", regex="ISO standard") body.append(paragraph) @@ -157,23 +157,23 @@ variable_decl = odf_create_variable_decl('spam', value_type) # Insert -heading = odf_create_heading(1, text=u'A variable') +heading = odf_create_heading(1, text='A variable') body.append(heading) decl = body.get_variable_decls() decl.append(variable_decl) -text = u'Set of spam.' -paragraph = odf_create_paragraph(text, style=u"Standard") +text = 'Set of spam.' +paragraph = odf_create_paragraph(text, style="Standard") body.append(paragraph) -paragraph._insert_between(variable_set, u"Set", u"spam.") +paragraph._insert_between(variable_set, "Set", "spam.") -text = u'The value of spam is: ' +text = 'The value of spam is: ' value = body.get_variable_set_value('spam') variable_get = odf_create_variable_get('spam', value) -paragraph = odf_create_paragraph(text, style=u"Standard") +paragraph = odf_create_paragraph(text, style="Standard") body.append(paragraph) -paragraph.insert_variable(variable_get, u"is: ") +paragraph.insert_variable(variable_get, "is: ") # 5- An user field @@ -183,120 +183,120 @@ user_field_decl = odf_create_user_field_decl('pi5', value=3.14159) # Insert -heading = odf_create_heading(1, text=u'An user field') +heading = odf_create_heading(1, text='An user field') body.append(heading) decl = body.get_user_field_decls() decl.append(user_field_decl) -text = u'The value of pi5 is: ' +text = 'The value of pi5 is: ' value = body.get_user_field_value('pi5') user_field_get = odf_create_user_field_get('pi5', value) -paragraph = odf_create_paragraph(text, style=u"Standard") +paragraph = odf_create_paragraph(text, style="Standard") body.append(paragraph) -paragraph._insert_between(user_field_get, u"The", u"is: ") +paragraph._insert_between(user_field_get, "The", "is: ") # 6- Page number # -------------- -heading = odf_create_heading(1, text=u'Page number') +heading = odf_create_heading(1, text='Page number') body.append(heading) -text1 = u'The current page is: ' -text2 = u'The previous page is: ' -text3 = u'The next page is: ' -text4 = u'The total page number is: ' +text1 = 'The current page is: ' +text2 = 'The previous page is: ' +text3 = 'The next page is: ' +text4 = 'The total page number is: ' -paragraph = odf_create_paragraph(text1, style=u"Standard") +paragraph = odf_create_paragraph(text1, style="Standard") body.append(paragraph) -paragraph.insert_variable(odf_create_page_number_variable(), u"is: ") +paragraph.insert_variable(odf_create_page_number_variable(), "is: ") -paragraph = odf_create_paragraph(text2, style=u"Standard") +paragraph = odf_create_paragraph(text2, style="Standard") body.append(paragraph) paragraph.insert_variable(odf_create_page_number_variable(select_page='previous'), - u"is: ") + "is: ") -paragraph = odf_create_paragraph(text3, style=u"Standard") +paragraph = odf_create_paragraph(text3, style="Standard") body.append(paragraph) paragraph.insert_variable(odf_create_page_number_variable(select_page='next'), - u"is: ") + "is: ") -paragraph = odf_create_paragraph(text4, style=u"Standard") +paragraph = odf_create_paragraph(text4, style="Standard") body.append(paragraph) -paragraph.insert_variable(odf_create_page_count_variable(), u"is: ") +paragraph.insert_variable(odf_create_page_count_variable(), "is: ") # 7- Date # ------- -heading = odf_create_heading(1, text=u'Date insertion') +heading = odf_create_heading(1, text='Date insertion') body.append(heading) -text1 = u'A fixed date: ' -text2 = u'Today: ' +text1 = 'A fixed date: ' +text2 = 'Today: ' -paragraph = odf_create_paragraph(text1, style=u"Standard") +paragraph = odf_create_paragraph(text1, style="Standard") body.append(paragraph) paragraph.insert_variable(odf_create_date_variable(date(2009, 7, 20), - fixed=True), u"date: ") + fixed=True), "date: ") -paragraph = odf_create_paragraph(text2, style=u"Standard") +paragraph = odf_create_paragraph(text2, style="Standard") body.append(paragraph) paragraph.insert_variable(odf_create_date_variable(date(2009, 7, 20)), - u"Today: ") + "Today: ") # 8- Time # -------- -heading = odf_create_heading(1, text=u'Time insertion') +heading = odf_create_heading(1, text='Time insertion') body.append(heading) -text1 = u'A fixed time: ' -text2 = u'Now: ' -text3 = u'In 1 hour: ' +text1 = 'A fixed time: ' +text2 = 'Now: ' +text3 = 'In 1 hour: ' -paragraph = odf_create_paragraph(text1, style=u"Standard") +paragraph = odf_create_paragraph(text1, style="Standard") body.append(paragraph) paragraph.insert_variable(odf_create_time_variable(time(19, 30), fixed=True), - u"time: ") + "time: ") -paragraph = odf_create_paragraph(text2, style=u"Standard") +paragraph = odf_create_paragraph(text2, style="Standard") body.append(paragraph) -paragraph.insert_variable(odf_create_time_variable(time(19, 30)), u"Now: ") +paragraph.insert_variable(odf_create_time_variable(time(19, 30)), "Now: ") -paragraph = odf_create_paragraph(text3, style=u"Standard") +paragraph = odf_create_paragraph(text3, style="Standard") body.append(paragraph) paragraph.insert_variable(odf_create_time_variable(time(19, 30), - time_adjust=timedelta(hours=1)), u"hour: ") + time_adjust=timedelta(hours=1)), "hour: ") # 9- Chapter # ----------- -heading = odf_create_heading(1, text=u'Chapter') +heading = odf_create_heading(1, text='Chapter') body.append(heading) -text = u'The current chapter is: ' +text = 'The current chapter is: ' -paragraph = odf_create_paragraph(text, style=u"Standard") +paragraph = odf_create_paragraph(text, style="Standard") body.append(paragraph) paragraph.insert_variable(odf_create_chapter_variable(display='number-and-name'), - u"is: ") + "is: ") # 10- Filename # ------------ -heading = odf_create_heading(1, text=u'Filename') +heading = odf_create_heading(1, text='Filename') body.append(heading) -text = u'The current file name is: ' +text = 'The current file name is: ' -paragraph = odf_create_paragraph(text, style=u"Standard") +paragraph = odf_create_paragraph(text, style="Standard") body.append(paragraph) -paragraph._insert_between(odf_create_filename_variable(), u"The", u"is: ") +paragraph._insert_between(odf_create_filename_variable(), "The", "is: ") diff --git a/test/use_case3.py b/test/use_case3.py index c746563..4c163d4 100644 --- a/test/use_case3.py +++ b/test/use_case3.py @@ -38,20 +38,20 @@ from lpod.style import odf_create_style, rgb2hex # Hello messages -print 'lpod installation test' -print ' Version : %s' % __version__ -print ' Installation path : %s' % __installation_path__ -print -print 'Generating test_output/use_case3.ods ...' +print('lpod installation test') +print(' Version : %s' % __version__) +print(' Installation path : %s' % __installation_path__) +print() +print('Generating test_output/use_case3.ods ...') document = odf_new_document('spreadsheet') body = document.get_body() -table = odf_create_table(u'use_case3') +table = odf_create_table('use_case3') -for y in xrange(0, 256, 8): +for y in range(0, 256, 8): row = odf_create_row() - for x in xrange(0, 256, 32): + for x in range(0, 256, 32): cell_value = (x, y, (x+y) % 256 ) border_rl = make_table_cell_border_string( thick = '0.20cm', diff --git a/test/use_case_perf.py b/test/use_case_perf.py index c820f74..3a7ed6d 100755 --- a/test/use_case_perf.py +++ b/test/use_case_perf.py @@ -18,27 +18,27 @@ def __init__(self, lines = 100, cols = 100): self.rnd_col = self.do_rnd_order(cols) self.py_table0 = self.populate_order() self.py_table = self.populate() - print "-" * 50 + print("-" * 50) def do_rnd_order(self, length): random.seed(42) - order = range(length) + order = list(range(length)) random.shuffle(order) return order def populate(self): random.seed(42) - base = range(self.cols) + base = list(range(self.cols)) tab = [] - for dummy in xrange(self.lines): + for dummy in range(self.lines): random.shuffle(base) tab.append(base[:]) return tab def populate_order(self): - base = range(self.cols) + base = list(range(self.cols)) tab = [] - for r in xrange(self.lines): + for r in range(self.lines): tab.append([r * self.cols + base[c] for c in base ]) return tab @@ -48,7 +48,7 @@ def __init__(self): def delta(self): t1 = time.time() - print "%.1f sec" % (t1-self.t0) + print("%.1f sec" % (t1-self.t0)) def value(self): return t1-self.t0 @@ -57,71 +57,71 @@ def ratio(self, base): return self.value() / base def test_append_rows(D): - print "Test append_row", D.lines, "rows", D.cols, "cols" - table = odf_create_table(u"Table") + print("Test append_row", D.lines, "rows", D.cols, "cols") + table = odf_create_table("Table") C = chrono() - for line in xrange(D.lines): + for line in range(D.lines): row = odf_create_row() row.set_values(D.py_table0[line]) table.append_row(row) C.delta() - print "Size of table :", table.get_size() + print("Size of table :", table.get_size()) if DEBUG: - print table.to_csv() - print "-" * 50 + print(table.to_csv()) + print("-" * 50) def test_set_rows(D): - print "Test random set_row", D.lines, "rows", D.cols, "cols" - table = odf_create_table(u"Table") + print("Test random set_row", D.lines, "rows", D.cols, "cols") + table = odf_create_table("Table") C = chrono() - for line in xrange(D.lines): + for line in range(D.lines): row = odf_create_row() row.set_values(D.py_table0[line]) if DEBUG: - print D.rnd_line[line], "=>", D.py_table0[line] + print(D.rnd_line[line], "=>", D.py_table0[line]) table.set_row(D.rnd_line[line], row) if DEBUG: - print table.to_csv() + print(table.to_csv()) C.delta() - print "Size of table :", table.get_size() + print("Size of table :", table.get_size()) if DEBUG: - print table.to_csv() - print "-" * 50 + print(table.to_csv()) + print("-" * 50) return table def test_swap(D, table_ini): - print "Test swap rows/cols from table", D.lines, "rows", D.cols, "cols" - table = odf_create_table(u"swapped", D.lines, D.cols) + print("Test swap rows/cols from table", D.lines, "rows", D.cols, "cols") + table = odf_create_table("swapped", D.lines, D.cols) C = chrono() - for col in xrange(D.cols): + for col in range(D.cols): values = table_ini.get_column_values(col) table.set_row_values(col, values) C.delta() - print "Size of swapped table :", table.get_size() + print("Size of swapped table :", table.get_size()) if DEBUG: - print table.to_csv() - print "-" * 50 + print(table.to_csv()) + print("-" * 50) def test_swap_transpose(D, table_ini): - print "Test swap rows/cols with transpose ", D.lines, "rows", D.cols, "cols" + print("Test swap rows/cols with transpose ", D.lines, "rows", D.cols, "cols") if not hasattr(table_ini, 'transpose'): - print "method not available" - print "-" * 50 + print("method not available") + print("-" * 50) return table = table_ini.clone() C = chrono() table.transpose() C.delta() - print "Size of swapped table :", table.get_size() + print("Size of swapped table :", table.get_size()) if DEBUG: - print table.to_csv() - print "-" * 50 + print(table.to_csv()) + print("-" * 50) def test_random_set_value(D): - print "Test random set_value", D.lines, "rows", D.cols, "cols" - table = odf_create_table(u"Table") + print("Test random set_value", D.lines, "rows", D.cols, "cols") + table = odf_create_table("Table") cpt = 0 C = chrono() for line in D.rnd_line: @@ -129,15 +129,15 @@ def test_random_set_value(D): table.set_value((col, line), cpt) cpt += 1 C.delta() - print cpt, "values entered" - print "Size of table :", table.get_size() + print(cpt, "values entered") + print("Size of table :", table.get_size()) if DEBUG: - print table.to_csv() - print "-" * 50 + print(table.to_csv()) + print("-" * 50) return table def test_random_get_value(D, table_ini): - print "Test read random get_value", D.lines, "rows", D.cols, "cols" + print("Test read random get_value", D.lines, "rows", D.cols, "cols") vals = [] cpt = 0 C = chrono() @@ -146,16 +146,16 @@ def test_random_get_value(D, table_ini): vals.append(table_ini.get_value((col, line))) cpt += 1 C.delta() - print cpt, "values read" + print(cpt, "values read") if DEBUG: - print vals - print "-" * 50 + print(vals) + print("-" * 50) def test_repeated(D): - print "test random repeated lines", D.lines, "rows", D.cols, "cols" - table = odf_create_table(u"Table") + print("test random repeated lines", D.lines, "rows", D.cols, "cols") + table = odf_create_table("Table") C = chrono() - for line in xrange(D.lines): + for line in range(D.lines): row = odf_create_row() row.set_values([(line * 10 + x) for x in range(D.cols)]) row.set_repeated(line) @@ -163,15 +163,15 @@ def test_repeated(D): # print D.rnd_line[line], "=>", row.get_values(), row.get_repeated() table.set_row(D.rnd_line[line], row) C.delta() - print "Size of table :", table.get_size() + print("Size of table :", table.get_size()) if DEBUG: - print table.to_csv() - print "-" * 50 + print(table.to_csv()) + print("-" * 50) return table if __name__=="__main__": - print version + print(version) total = chrono() #for r,c in [(10,8)]: for r,c in [(10,10), (100, 10), (100,100), (1000,10)]: @@ -184,5 +184,5 @@ def test_repeated(D): t = test_random_set_value(D) test_random_get_value(D, t) test_repeated(D) - print "Total", + print("Total", end=' ') total.delta()