Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def add_attachment(self, id, filename):
element = E.Binary(
E.Key(filename),
E.Value(Ref=str(id))
)
self._element.append(element)
return pykeepass.attachment.Attachment(element=element, kp=self._kp)
tree = self.tree
logger.debug(xpath_str)
elements = tree.xpath(
xpath_str, namespaces={'re': 'http://exslt.org/regular-expressions'}
)
res = []
for e in elements:
if history or e.getparent().tag != 'History':
if cast:
if e.tag == 'Entry':
res.append(Entry(element=e, kp=self))
elif e.tag == 'Group':
res.append(Group(element=e, kp=self))
elif e.tag == 'Binary' and e.getparent().tag == 'Entry':
res.append(Attachment(element=e, kp=self))
else:
raise Exception('Could not cast element {}'.format(e))
else:
res.append(e)
# return first object in list or None
if first:
res = res[0] if res else None
return res