diff --git a/src/docx/__init__.py b/src/docx/__init__.py index bbd7267c4..ba58680cf 100644 --- a/src/docx/__init__.py +++ b/src/docx/__init__.py @@ -13,7 +13,7 @@ if TYPE_CHECKING: from docx.opc.part import Part -__version__ = "1.0.0" +__version__ = "1.0.1-dev" __all__ = ["Document"] diff --git a/src/docx/opc/customprops.py b/src/docx/opc/customprops.py index 83eea5844..3b67ed82b 100644 --- a/src/docx/opc/customprops.py +++ b/src/docx/opc/customprops.py @@ -10,8 +10,7 @@ import numbers from lxml import etree - -NS_VT = "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes" +from docx.oxml.ns import nspfxmap, qn class CustomProperties(object): @@ -26,12 +25,12 @@ def __getitem__(self, item): prop = self.lookup(item) if prop is not None: elm = prop[0] - if elm.tag == f"{{{NS_VT}}}i4": + if elm.tag == qn("vt:i4"): try: return int(elm.text) except ValueError: return elm.text - elif elm.tag == f"{{{NS_VT}}}bool": + elif elm.tag == qn("vt:bool"): return True if elm.text == '1' else False return elm.text @@ -45,8 +44,8 @@ def __setitem__(self, key, value): elif isinstance(value, numbers.Number): elm_type = 'i4' value = str(int(value)) - prop = etree.SubElement(self._element, "property") - elm = etree.SubElement(prop, f"{{{NS_VT}}}{elm_type}", nsmap={'vt':NS_VT}) + prop = etree.SubElement(self._element, qn("op:property"), nsmap=nspfxmap("op")) + elm = etree.SubElement(prop, qn(f"vt:{elm_type}"), nsmap=nspfxmap("vt")) elm.text = value prop.set("name", key) # magic number "FMTID_UserDefinedProperties" @@ -55,9 +54,9 @@ def __setitem__(self, key, value): prop.set("pid", str(len(self._element) + 1)) else: elm = prop[0] - if elm.tag == f"{{{NS_VT}}}i4": + if elm.tag == qn("vt:i4"): elm.text = str(int(value)) - elif elm.tag == f"{{{NS_VT}}}bool": + elif elm.tag == qn("vt:bool"): elm.text = str(1 if value else 0) else: elm.text = str(value) diff --git a/src/docx/oxml/__init__.py b/src/docx/oxml/__init__.py index e385badd8..c1b3146e0 100644 --- a/src/docx/oxml/__init__.py +++ b/src/docx/oxml/__init__.py @@ -90,7 +90,7 @@ from .customprops import CT_CustomProperties # noqa -register_element_cls('cup:Properties', CT_CustomProperties) +register_element_cls('op:Properties', CT_CustomProperties) from .document import CT_Body, CT_Document # noqa diff --git a/src/docx/oxml/customprops.py b/src/docx/oxml/customprops.py index 506645289..6f1605a59 100644 --- a/src/docx/oxml/customprops.py +++ b/src/docx/oxml/customprops.py @@ -16,21 +16,19 @@ from docx.oxml import parse_xml - class CT_CustomProperties(BaseOxmlElement): """ ```` element, the root element of the Custom Properties part stored as ``/docProps/custom.xml``. String elements are limited in length to 255 unicode characters. """ - - _customProperties_tmpl = "\n" % nsdecls("cup", "vt") + _customProperties_tmpl = "\n" % nsdecls("op", "vt") _offset_pattern = re.compile("([+-])(\\d\\d):(\\d\\d)") @classmethod def new(cls): """ - Return a new ```` element + Return a new ```` element """ xml = cls._customProperties_tmpl custom_properties = parse_xml(xml) diff --git a/src/docx/oxml/ns.py b/src/docx/oxml/ns.py index f179f61fc..89afe8a37 100644 --- a/src/docx/oxml/ns.py +++ b/src/docx/oxml/ns.py @@ -8,7 +8,7 @@ "a": "http://schemas.openxmlformats.org/drawingml/2006/main", "c": "http://schemas.openxmlformats.org/drawingml/2006/chart", "cp": "http://schemas.openxmlformats.org/package/2006/metadata/core-properties", - "cup": "http://schemas.openxmlformats.org/officeDocument/2006/custom-properties", + "op": "http://schemas.openxmlformats.org/officeDocument/2006/custom-properties", "dc": "http://purl.org/dc/elements/1.1/", "dcmitype": "http://purl.org/dc/dcmitype/", "dcterms": "http://purl.org/dc/terms/",