def read_properties_core(xml_source): """Read assorted file properties.""" properties = DocumentProperties() root = fromstring(xml_source) creator_node = root.find(QName(NAMESPACES['dc'], 'creator').text) if creator_node is not None: properties.creator = creator_node.text else: properties.creator = '' last_modified_by_node = root.find( QName(NAMESPACES['cp'], 'lastModifiedBy').text) if last_modified_by_node is not None: properties.last_modified_by = last_modified_by_node.text else: properties.last_modified_by = '' created_node = root.find(QName(NAMESPACES['dcterms'], 'created').text) if created_node is not None: properties.created = W3CDTF_to_datetime(created_node.text) else: properties.created = datetime.datetime.now() modified_node = root.find(QName(NAMESPACES['dcterms'], 'modified').text) if modified_node is not None: properties.modified = W3CDTF_to_datetime(modified_node.text) else: properties.modified = properties.created return properties
def test_write_properties_core(datadir): datadir.join("writer").chdir() prop = DocumentProperties() prop.creator = 'TEST_USER' prop.last_modified_by = 'SOMEBODY' prop.created = datetime(2010, 4, 1, 20, 30, 00) prop.modified = datetime(2010, 4, 5, 14, 5, 30) content = write_properties_core(prop) with open('core.xml') as expected: diff = compare_xml(content, expected.read()) assert diff is None
def read_properties_core(xml_source): """Read assorted file properties.""" properties = DocumentProperties() root = fromstring(xml_source) properties.creator = root.findtext('{%s}creator' % DCORE_NS, '') properties.last_modified_by = root.findtext('{%s}lastModifiedBy' % COREPROPS_NS, '') created_node = root.find('{%s}created' % DCTERMS_NS) if created_node is not None: properties.created = W3CDTF_to_datetime(created_node.text) else: properties.created = datetime.datetime.now() modified_node = root.find('{%s}modified' % DCTERMS_NS) if modified_node is not None: properties.modified = W3CDTF_to_datetime(modified_node.text) else: properties.modified = properties.created return properties
def read_properties_core(xml_source): """Read assorted file properties.""" properties = DocumentProperties() root = fromstring(xml_source) properties.creator = root.findtext('{%s}creator' % DCORE_NS, '') properties.last_modified_by = root.findtext( '{%s}lastModifiedBy' % COREPROPS_NS, '') created_node = root.find('{%s}created' % DCTERMS_NS) if created_node is not None: properties.created = W3CDTF_to_datetime(created_node.text) else: properties.created = datetime.datetime.now() modified_node = root.find('{%s}modified' % DCTERMS_NS) if modified_node is not None: properties.modified = W3CDTF_to_datetime(modified_node.text) else: properties.modified = properties.created return properties