diff --git a/bdisk/utils.py b/bdisk/utils.py index fa5605a..aaffd36 100644 --- a/bdisk/utils.py +++ b/bdisk/utils.py @@ -34,7 +34,11 @@ crypt_map = {'sha512': crypt.METHOD_SHA512, 'des': crypt.METHOD_CRYPT} class XPathFmt(string.Formatter): + def __init__(self): + print('foo') + def get_field(self, field_name, args, kwargs): + # custom arg to specify if it's a regex pattern or not vals = self.get_value(field_name, args, kwargs), field_name if not vals[0]: vals = ('{{{0}}}'.format(vals[1]), vals[1]) @@ -426,10 +430,14 @@ class xml_supplicant(object): xmlroot = lxml.etree.fromstring(raw) self.btags = {'xpath': {}, 'regex': {}} + self.fmt = XPathFmt() self.max_recurse = max_recurse - self.ptrn = re.compile('(?<=(?', _re) + # We use a native python object + self.btags['regex'][item] = re.compile(_re) d[item] = xpath_expr except ValueError: return(None) diff --git a/docs/examples/single_profile.xml b/docs/examples/single_profile.xml index f0ce144..dee8e60 100644 --- a/docs/examples/single_profile.xml +++ b/docs/examples/single_profile.xml @@ -48,7 +48,8 @@ http://archlinux.mirror.domain.tld /iso/latest - {xpath%../mirror/text()}{xpath%../webroot/text()}/{regex%archlinux-bootstrap-[0-9]{4}\.[0-9]{2}\.[0-9]{2}-x86_64\.tar\.gz} + {xpath%../mirror/text()}{xpath%../webroot/text()}/{regex%archlinux-bootstrap-[0-9]{{4}}\.[0-9]{{2}}\.[0-9]{{2}}-x86_64\.tar\.gz} + {xpath%../mirror/text()}{xpath%../webroot/text()}/sha1sums.txt http://archlinux32.mirror.domain.tld /iso/latest - {xpath%../mirror/text()}/{xpath%../webroot/text()}/{regex%archlinux-bootstrap-[0-9]{4}\.[0-9]{2}\.[0-9]{2}-i686\.tar\.gz} + {xpath%../mirror/text()}/{xpath%../webroot/text()}/{regex%archlinux-bootstrap-[0-9]{{4}}\.[0-9]{{2}}\.[0-9]{{2}}-i686\.tar\.gz} + cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e {xpath%../tarball/text()}.sig