def _parse_dap_config(self, config_str=None):
        """
        Read the DAP_CONFIG file and extract the parts not controlled 
        by esgf-pyclient.

        :return: (preamble, managed, postamble), three strings of 
            configuration lines before, within and after the esgf-pyclient 
            controlled block.

        """
        if config_str is None:
            if not op.exists(self.dap_config):
                return ('', '', '')
            config_str = open(self.dap_config).read()

        #!NOTE: The flags keyword argument to re.split was introduced in Python2.7
        #   Keep with call non-keyword arguments for compatibility with Python2.6
        sections = re.split(r'^# (?:BEGIN|END) {0}$\n'.format(DAP_CONFIG_MARKER), 
                            config_str, re.M)

        if len(sections) < 2:
            preamble, managed, postamble = sections[0], '', ''
        elif len(sections) == 2:
            preamble, managed, postamble = sections + ['']
        elif len(sections) == 3:
            preamble, managed, postamble = sections
        else:
            # In odd circumstances there might be more than 3 parts of the config 
            # so assume the final config is the one to keep
            managed, unmanaged = [], []
            sections.reverse()
            while sections:
                unmanaged.append(sections.pop())
                if sections:
                    managed.append(sections.pop())

            preamble = '\n'.join(unmanaged[:-1])
            postamble = unmanaged[-1]
            managed = managed[-1]


        return preamble.strip(), managed.strip(), postamble.strip()
dataset/ETHPy150Open stephenpascoe/esgf-pyclient/pyesgf/logon.py/LogonManager._parse_dap_config/original