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

Commit ce52fed

Browse files
committedJan 2, 2010
- 'tagattributes' now just 'attributes' for brevity
1 parent 3459ab7 commit ce52fed

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed
 

‎docx.py

+31-31
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ def newdocument():
4747
document.append(makeelement('body'))
4848
return document
4949

50-
def makeelement(tagname,tagtext=None,nsprefix='w',tagattributes=None,attributenamespace=None):
50+
def makeelement(tagname,tagtext=None,nsprefix='w',attributes=None,attributenamespace=None):
5151
'''Create an element & return it'''
5252
namespace = '{'+nsprefixes[nsprefix]+'}'
5353
newelement = etree.Element(namespace+tagname)
5454
# Add attributes with namespaces
55-
if tagattributes:
55+
if attributes:
5656
# If they haven't bothered setting attribute namespace, use the same one as the tag
5757
if not attributenamespace:
5858
attributenamespace = namespace
59-
for tagattribute in tagattributes:
60-
newelement.set(attributenamespace+tagattribute, tagattributes[tagattribute])
59+
for tagattribute in attributes:
60+
newelement.set(attributenamespace+tagattribute, attributes[tagattribute])
6161
if tagtext:
6262
newelement.text = tagtext
6363
return newelement
@@ -73,7 +73,7 @@ def pagebreak(type='page', orient='portrait'):
7373
pagebreak = makeelement('p')
7474
if type == 'page':
7575
run = makeelement('r')
76-
br = makeelement('br',tagattributes={'type':type})
76+
br = makeelement('br',attributes={'type':type})
7777

7878
run.append(br)
7979
pagebreak.append(run)
@@ -82,9 +82,9 @@ def pagebreak(type='page', orient='portrait'):
8282
pPr = makeelement('pPr')
8383
sectPr = makeelement('sectPr')
8484
if orient == 'portrait':
85-
pgSz = makeelement('pgSz',tagattributes={'w':'12240','h':'15840'})
85+
pgSz = makeelement('pgSz',attributes={'w':'12240','h':'15840'})
8686
elif orient == 'landscape':
87-
pgSz = makeelement('pgSz',tagattributes={'h':'12240','w':'15840', 'orient':'landscape'})
87+
pgSz = makeelement('pgSz',attributes={'h':'12240','w':'15840', 'orient':'landscape'})
8888

8989
sectPr.append(pgSz)
9090
pPr.append(sectPr)
@@ -107,7 +107,7 @@ def paragraph(paratext,style='BodyText',breakbefore=False):
107107

108108
text = makeelement('t',tagtext=paratext)
109109
pPr = makeelement('pPr')
110-
pStyle = makeelement('pStyle',tagattributes={'val':style})
110+
pStyle = makeelement('pStyle',attributes={'val':style})
111111
pPr.append(pStyle)
112112

113113

@@ -124,7 +124,7 @@ def heading(headingtext,headinglevel):
124124
# Make our elements
125125
paragraph = makeelement('p')
126126
pr = makeelement('pPr')
127-
pStyle = makeelement('pStyle',tagattributes={'val':'Heading'+str(headinglevel)})
127+
pStyle = makeelement('pStyle',attributes={'val':'Heading'+str(headinglevel)})
128128
run = makeelement('r')
129129
text = makeelement('t',tagtext=headingtext)
130130
# Add the text the run, and the run to the paragraph
@@ -142,29 +142,29 @@ def table(contents):
142142
columns = len(contents[0][0])
143143
# Table properties
144144
tableprops = makeelement('tblPr')
145-
tablestyle = makeelement('tblStyle',tagattributes={'val':'ColorfulGrid-Accent1'})
146-
tablewidth = makeelement('tblW',tagattributes={'w':'0','type':'auto'})
147-
tablelook = makeelement('tblLook',tagattributes={'val':'0400'})
145+
tablestyle = makeelement('tblStyle',attributes={'val':'ColorfulGrid-Accent1'})
146+
tablewidth = makeelement('tblW',attributes={'w':'0','type':'auto'})
147+
tablelook = makeelement('tblLook',attributes={'val':'0400'})
148148
for tableproperty in [tablestyle,tablewidth,tablelook]:
149149
tableprops.append(tableproperty)
150150
table.append(tableprops)
151151
# Table Grid
152152
tablegrid = makeelement('tblGrid')
153153
for _ in range(columns):
154-
tablegrid.append(makeelement('gridCol',tagattributes={'gridCol':'2390'}))
154+
tablegrid.append(makeelement('gridCol',attributes={'gridCol':'2390'}))
155155
table.append(tablegrid)
156156
# Heading Row
157157
row = makeelement('tr')
158158
rowprops = makeelement('trPr')
159-
cnfStyle = makeelement('cnfStyle',tagattributes={'val':'000000100000'})
159+
cnfStyle = makeelement('cnfStyle',attributes={'val':'000000100000'})
160160
rowprops.append(cnfStyle)
161161
row.append(rowprops)
162162
for heading in contents[0]:
163163
cell = makeelement('tc')
164164
# Cell properties
165165
cellprops = makeelement('tcPr')
166-
cellwidth = makeelement('tcW',tagattributes={'w':'2390','type':'dxa'})
167-
cellstyle = makeelement('shd',tagattributes={'val':'clear','color':'auto','fill':'548DD4','themeFill':'text2','themeFillTint':'99'})
166+
cellwidth = makeelement('tcW',attributes={'w':'2390','type':'dxa'})
167+
cellstyle = makeelement('shd',attributes={'val':'clear','color':'auto','fill':'548DD4','themeFill':'text2','themeFillTint':'99'})
168168
cellprops.append(cellwidth)
169169
cellprops.append(cellstyle)
170170
cell.append(cellprops)
@@ -179,7 +179,7 @@ def table(contents):
179179
cell = makeelement('tc')
180180
# Properties
181181
cellprops = makeelement('tcPr')
182-
cellwidth = makeelement('tcW',tagattributes={'type':'dxa'})
182+
cellwidth = makeelement('tcW',attributes={'type':'dxa'})
183183
cellprops.append(cellwidth)
184184
cell.append(cellprops)
185185
# Paragraph (Content)
@@ -193,29 +193,29 @@ def picture():
193193
# Word uses paragraphs to contain images
194194
# http://openxmldeveloper.org/articles/462.aspx
195195
#resourceid = rId5
196-
#newrelationship = makeelement('Relationship',tagattributes={'Id':resourceid,'Type':'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image'},Target=filename)
196+
#newrelationship = makeelement('Relationship',attributes={'Id':resourceid,'Type':'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image'},Target=filename)
197197

198198
# Now make drawing element
199199
#newpara = makeelement('deleteme',style='BodyText')
200200

201201

202202
blipfill = makeelement('blipFill',nsprefix='a')
203-
blipfill.append(makeelement('blip',nsprefix='a',tagattributes={'embed':'rId5'}))
203+
blipfill.append(makeelement('blip',nsprefix='a',attributes={'embed':'rId5'}))
204204
stretch = makeelement('stretch',nsprefix='a')
205205
stretch.append(makeelement('fillRect',nsprefix='a'))
206206
blipfill.append(stretch)
207207

208208
sppr = makeelement('spPr',nsprefix='pic')
209209
xfrm = makeelement('xfrm',nsprefix='a')
210-
xfrm.append(makeelement('off',nsprefix='a',tagattributes={'x':'0','y':'0'}))
211-
xfrm.append(makeelement('ext',nsprefix='a',tagattributes={'cx':'5486400','cy':'3429000'}))
212-
prstgeom = makeelement('prstGeom',nsprefix='a',tagattributes={'prst':'rect'})
210+
xfrm.append(makeelement('off',nsprefix='a',attributes={'x':'0','y':'0'}))
211+
xfrm.append(makeelement('ext',nsprefix='a',attributes={'cx':'5486400','cy':'3429000'}))
212+
prstgeom = makeelement('prstGeom',nsprefix='a',attributes={'prst':'rect'})
213213
prstgeom.append(makeelement('avLst',nsprefix='a'))
214214
sppr.append(xfrm)
215215
sppr.append(prstgeom)
216216

217217
nvpicpr = makeelement('nvPicPr',nsprefix='a')
218-
cnvpr = makeelement('cNvPr',nsprefix='a',tagattributes={'id':'0','name':'aero_glow_v2_1920x1200.png'})
218+
cnvpr = makeelement('cNvPr',nsprefix='a',attributes={'id':'0','name':'aero_glow_v2_1920x1200.png'})
219219
cnvpicpr = makeelement('cNvPicPr')
220220
nvpicpr.append(cnvpicpr)
221221
nvpicpr.append(cnvpr)
@@ -226,21 +226,21 @@ def picture():
226226
pic.append(nvpicpr)
227227

228228

229-
graphicdata = makeelement('graphicData',nsprefix='a',tagattributes={'uri':'http://schemas.openxmlformats.org/drawingml/2006/picture'})
229+
graphicdata = makeelement('graphicData',nsprefix='a',attributes={'uri':'http://schemas.openxmlformats.org/drawingml/2006/picture'})
230230
graphicdata.append(pic)
231231

232232
graphic = makeelement('graphic',nsprefix='a')
233233
graphic.append(graphicdata)
234234

235235
framepr = makeelement('cNvGraphicFramePr',nsprefix='a')
236-
framelocks = makeelement('graphicFrameLocks',nsprefix='a',tagattributes={'noChangeAspect':'1'})
236+
framelocks = makeelement('graphicFrameLocks',nsprefix='a',attributes={'noChangeAspect':'1'})
237237
framepr.append(framelocks)
238238

239239
makeelement('drawing')
240-
inline = makeelement('inline',tagattributes={'distT':"0",'distB':"0",'distL':"0",'distR':"0"},nsprefix='wp')
241-
extent = makeelement('extent',nsprefix='a',tagattributes={'cx':'5486400','cy':'3429000'})
242-
effectextent = makeelement('effectExtent',nsprefix='a',tagattributes={'l':'25400','t':'0','r':'0','b':'0'})
243-
docpr = makeelement('docPr',nsprefix='a',tagattributes={'id':'1','name':'Picture 0','descr':'aero_glow_v2_1920x1200.png'})
240+
inline = makeelement('inline',attributes={'distT':"0",'distB':"0",'distL':"0",'distR':"0"},nsprefix='wp')
241+
extent = makeelement('extent',nsprefix='a',attributes={'cx':'5486400','cy':'3429000'})
242+
effectextent = makeelement('effectExtent',nsprefix='a',attributes={'l':'25400','t':'0','r':'0','b':'0'})
243+
docpr = makeelement('docPr',nsprefix='a',attributes={'id':'1','name':'Picture 0','descr':'aero_glow_v2_1920x1200.png'})
244244
inline.append(extent)
245245
inline.append(effectextent)
246246
inline.append(docpr)
@@ -347,9 +347,9 @@ def docproperties(title,subject,creator,keywords,lastmodifiedby=None):
347347
<dcterms:modified xsi:type="dcterms:W3CDTF">2010-01-01T21:20:00Z</dcterms:modified>
348348
currenttime'''
349349
#docprops.append(makeelement('created',nsprefix='dcterms',
350-
#tagattributes={'type':'dcterms:W3CDTF'},tagtext='2010-01-01T21:07:00Z',attributenamespace='xsi'))
350+
#attributes={'type':'dcterms:W3CDTF'},tagtext='2010-01-01T21:07:00Z',attributenamespace='xsi'))
351351
#docprops.append(makeelement('modified',nsprefix='dcterms',
352-
#tagattributes={'type':'dcterms:W3CDTF'},tagtext='2010-01-01T21:07:00Z',attributenamespace='xsi'))
352+
#attributes={'type':'dcterms:W3CDTF'},tagtext='2010-01-01T21:07:00Z',attributenamespace='xsi'))
353353
return docprops
354354

355355

0 commit comments

Comments
 (0)
This repository has been archived.