88 absolute_import , division , print_function , unicode_literals
99)
1010
11+ from datetime import datetime , timedelta
1112import re
1213
13- from datetime import datetime , timedelta
14- from lxml import etree
15- from .ns import nsdecls , qn
16- from .xmlchemy import BaseOxmlElement , ZeroOrOne
17- from . import parse_xml
14+ from docx .oxml .ns import nsdecls , qn
15+ from docx .oxml .xmlchemy import BaseOxmlElement
16+ from docx .oxml import parse_xml
17+
1818
1919class CT_CustomProperties (BaseOxmlElement ):
2020 """
@@ -24,17 +24,18 @@ class CT_CustomProperties(BaseOxmlElement):
2424 """
2525
2626 _customProperties_tmpl = (
27- '<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties" %s/>\n ' % nsdecls ('vt' )
27+ '<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties" %s/>\n ' % nsdecls ('vt' )
2828 )
29+ _offset_pattern = re .compile ("([+-])(\\ d\\ d):(\\ d\\ d)" )
2930
3031 @classmethod
3132 def new (cls ):
3233 """
3334 Return a new ``<property>`` element
3435 """
3536 xml = cls ._customProperties_tmpl
36- customProperties = parse_xml (xml )
37- return customProperties
37+ custom_properties = parse_xml (xml )
38+ return custom_properties
3839
3940 def _datetime_of_element (self , property_name ):
4041 element = getattr (self , property_name )
@@ -75,8 +76,6 @@ def _offset_dt(cls, dt, offset_str):
7576 td = timedelta (hours = hours , minutes = minutes )
7677 return dt + td
7778
78- _offset_pattern = re .compile ('([+-])(\d\d):(\d\d)' )
79-
8079 @classmethod
8180 def _parse_W3CDTF_to_datetime (cls , w3cdtf_str ):
8281 # valid W3CDTF date cases:
@@ -102,8 +101,7 @@ def _parse_W3CDTF_to_datetime(cls, w3cdtf_str):
102101 except ValueError :
103102 continue
104103 if dt is None :
105- tmpl = "could not parse W3CDTF datetime string '%s'"
106- raise ValueError (tmpl % w3cdtf_str )
104+ raise ValueError ("could not parse W3CDTF datetime string '%s'" % {w3cdtf_str })
107105 if len (offset_str ) == 6 :
108106 return cls ._offset_dt (dt , offset_str )
109107 return dt
@@ -113,18 +111,15 @@ def _set_element_datetime(self, prop_name, value):
113111 Set date/time value of child element having *prop_name* to *value*.
114112 """
115113 if not isinstance (value , datetime ):
116- tmpl = (
117- "property requires <type 'datetime.datetime'> object, got %s"
118- )
119- raise ValueError (tmpl % type (value ))
114+ raise ValueError ("property requires <type 'datetime.datetime'> object, got %s" % type (value ))
120115 element = self ._get_or_add (prop_name )
121116 dt_str = value .strftime ('%Y-%m-%dT%H:%M:%SZ' )
122117 element .text = dt_str
123118 if prop_name in ('created' , 'modified' ):
124- # These two require an explicit 'xsi:type="dcterms:W3CDTF"'
125- # attribute. The first and last line are a hack required to add
119+ # These two require an explicit 'xsi:type="dcterms:W3CDTF"' attribute.
120+ # The first and last line are a hack required to add
126121 # the xsi namespace to the root element rather than each child
127- # element in which it is referenced
122+ # element in which it is referenced.
128123 self .set (qn ('xsi:foo' ), 'bar' )
129124 element .set (qn ('xsi:type' ), 'dcterms:W3CDTF' )
130125 del self .attrib [qn ('xsi:foo' )]
@@ -135,10 +130,7 @@ def _set_element_text(self, prop_name, value):
135130 """
136131 value = str (value )
137132 if len (value ) > 255 :
138- tmpl = (
139- "exceeded 255 char limit for property, got:\n \n '%s'"
140- )
141- raise ValueError (tmpl % value )
133+ raise ValueError ("exceeded 255 char limit for property, got:\n \n '%s'" % value )
142134 element = self ._get_or_add (prop_name )
143135 element .text = value
144136
@@ -153,4 +145,3 @@ def _text_of_element(self, property_name):
153145 if element .text is None :
154146 return ''
155147 return element .text
156-
0 commit comments