Skip to content
This repository has been archived by the owner on Jan 12, 2018. It is now read-only.

Added python 3 support and fixed small bug with picture appending #68

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
24 changes: 18 additions & 6 deletions docx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -474,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)

Expand Down Expand Up @@ -977,11 +984,16 @@ def appproperties():

"""
appprops = makeelement('Properties', nsprefix='ep')
appprops = etree.fromstring(
appprops_content = (
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?><Properties x'
'mlns="http://schemas.openxmlformats.org/officeDocument/2006/extended'
'-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocum'
'ent/2006/docPropsVTypes"></Properties>')
'ent/2006/docPropsVTypes"></Properties>'
)
try:
appprops = etree.fromstring(appprops_content)
except ValueError:
appprops = etree.fromstring(appprops_content.encode('utf-8'))
props =\
{'Template': 'Normal.dotm',
'TotalTime': '6',
Expand Down