From 5bcf178fce4b0e501376f5a0d5b53c799147b512 Mon Sep 17 00:00:00 2001 From: Abakar Ibragimov Date: Mon, 9 Jun 2014 00:47:01 +0400 Subject: [PATCH 1/2] python 3 support --- docx.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/docx.py b/docx.py index 9d3f6e6..6f6f74e 100755 --- a/docx.py +++ b/docx.py @@ -27,7 +27,11 @@ except ImportError: TAGS = {} -from exceptions import PendingDeprecationWarning +try: + from exceptions import PendingDeprecationWarning +except ImportError: + pass + from warnings import warn import logging @@ -349,7 +353,10 @@ def table(contents, heading=True, colw=None, cwunit='dxa', tblw=0, k = 'all' if 'all' in borders.keys() else b attrs = {} for a in borders[k].keys(): - attrs[a] = unicode(borders[k][a]) + try: + attrs[a] = unicode(borders[k][a]) + except NameError: + attrs[a] = str(borders[k][a]) borderelem = makeelement(b, attributes=attrs) tableborders.append(borderelem) tableprops.append(tableborders) @@ -977,11 +984,16 @@ def appproperties(): """ appprops = makeelement('Properties', nsprefix='ep') - appprops = etree.fromstring( + appprops_content = ( '') + 'ent/2006/docPropsVTypes">' + ) + try: + appprops = etree.fromstring(appprops_content) + except ValueError: + appprops = etree.fromstring(appprops_content.encode('utf-8')) props =\ {'Template': 'Normal.dotm', 'TotalTime': '6', From 39432c47d4e446d09dea4b518f0f1f0fcabbca3a Mon Sep 17 00:00:00 2001 From: Abakar Ibragimov Date: Mon, 9 Jun 2014 00:54:27 +0400 Subject: [PATCH 2/2] fixed bug with appending picture --- docx.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docx.py b/docx.py index 6f6f74e..b1cf8a1 100755 --- a/docx.py +++ b/docx.py @@ -481,13 +481,13 @@ def picture( relationshiplist.append([ 'http://schemas.openxmlformats.org/officeDocument/2006/relations' - 'hips/image', 'media/' + picname + 'hips/image', 'media/' + basename(picname) ]) media_dir = join(template_dir, 'word', 'media') if not os.path.isdir(media_dir): os.mkdir(media_dir) - shutil.copyfile(picname, join(media_dir, picname)) + shutil.copyfile(picname, join(media_dir, basename(picname))) image = Image.open(picpath)