2021-03-12 04:17:19 +00:00
|
|
|
# Authors: see git history
|
|
|
|
#
|
|
|
|
# Copyright (c) 2010 Authors
|
|
|
|
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
|
|
|
|
|
2021-03-04 17:40:53 +00:00
|
|
|
from inkex import NSS
|
|
|
|
from lxml import etree
|
2019-02-26 00:49:38 +00:00
|
|
|
|
2018-05-31 00:10:11 +00:00
|
|
|
from ..utils import cache
|
2018-03-31 00:37:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
@cache
|
2019-02-23 03:07:15 +00:00
|
|
|
def get_document(node):
|
|
|
|
return node.getroottree().getroot()
|
2018-05-27 01:26:40 +00:00
|
|
|
|
2018-05-31 00:10:11 +00:00
|
|
|
|
2024-02-10 19:17:36 +00:00
|
|
|
def generate_unique_id(document_or_element, prefix="path", blocklist=None):
|
2019-03-09 01:50:48 +00:00
|
|
|
if isinstance(document_or_element, etree._ElementTree):
|
|
|
|
document = document_or_element.getroot()
|
|
|
|
else:
|
|
|
|
document = get_document(document_or_element)
|
|
|
|
|
2024-02-10 19:17:36 +00:00
|
|
|
new_id = document.get_unique_id(prefix, blacklist=blocklist)
|
2018-05-31 00:10:11 +00:00
|
|
|
|
2019-02-23 03:07:15 +00:00
|
|
|
return new_id
|
2020-05-16 21:01:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
def find_elements(node, xpath):
|
|
|
|
document = get_document(node)
|
|
|
|
elements = document.xpath(xpath, namespaces=NSS)
|
|
|
|
return elements
|