Skip to content
This repository was archived by the owner on Feb 11, 2024. It is now read-only.

python3 compartable #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ pip-log.txt
#Translations
*.mo

.virtualenv
tmp/
4 changes: 2 additions & 2 deletions INSTALL
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
lpod-python
lpod-python3
===========

Python library implementing the ISO/IEC 26300 OpenDocument Format standard.
Expand All @@ -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.
Expand All @@ -48,6 +47,6 @@ About the Lpod Project, see:
http://lpod-project.net


Architect: Jean-Marie Gouarn� <[email protected]>
Architect: Jean-Marie Gouarn� <[email protected]>

Coordinator: Luis Belmar-Letelier <[email protected]>
12 changes: 6 additions & 6 deletions doc_make/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
32 changes: 16 additions & 16 deletions lpod/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lpod/bookmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#

# Import from lpod
from element import odf_create_element
from .element import odf_create_element


def odf_create_bookmark(name):
Expand Down
50 changes: 25 additions & 25 deletions lpod/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -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']
Expand All @@ -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}
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -443,21 +443,21 @@ 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')
close_after = True
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'):
Expand All @@ -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':
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lpod/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion lpod/datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading