import copy import re import os import utils import validators import lxml.etree from urllib.parse import urlparse etree = lxml.etree class Conf(object): def __init__(self, cfg, profile = None): """ A configuration object. Read a configuration file, parse it, and make it available to the rest of BDisk. Args: cfg The configuration. Can be a filesystem path, a string, bytes, or a stream. If bytes or a bytestream, it must be in UTF-8 format. profile (optional) A sub-profile in the configuration. If None is provided, we'll first look for the first profile named 'default' (case-insensitive). If one isn't found, then the first profile found will be used. Can be a string (in which we'll automatically search for the given value in the "name" attribute) or a dict for more fine-grained profile identification, such as: {'name': 'PROFILE_NAME', 'id': 1, 'uuid': '00000000-0000-0000-0000-000000000000'} You can provide any combination of these (e.g. "profile={'id': 2, 'name' = 'some_profile'}"). """ self.raw = _detect_cfg(cfg) self.profile = profile self.xml = None self.profile = None # Mad props to https://stackoverflow.com/a/12728199/733214 self.xpath_re = re.compile('(?<=(?