Python ConfigParser.MissingSectionHeaderError() Examples
The following are 30
code examples of ConfigParser.MissingSectionHeaderError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
ConfigParser
, or try the search function
.
Example #1
Source File: config.py From IndicoIo-python with MIT License | 6 votes |
def __init__(self, *args, **kwargs): """ files: filepaths or open file objects """ self.files = kwargs.pop("files") configparser.ConfigParser.__init__(self, *args, **kwargs) for fd in self.files: try: self.read_file(fd) except AttributeError: # python 2 try: self.readfp(fd) except AttributeError: self.read(fd) except configparser.MissingSectionHeaderError: self.read(fd) self.auth_settings = self.get_section("auth") self.private_cloud_settings = self.get_section("private_cloud")
Example #2
Source File: simple_config.py From encompass with GNU General Public License v3.0 | 6 votes |
def read_system_config(path=SYSTEM_CONFIG_PATH): """Parse and return the system config settings in /etc/encompass.conf.""" result = {} if os.path.exists(path): try: import ConfigParser except ImportError: print "cannot parse encompass.conf. please install ConfigParser" return p = ConfigParser.ConfigParser() try: p.read(path) for k, v in p.items('client'): result[k] = v except (ConfigParser.NoSectionError, ConfigParser.MissingSectionHeaderError): pass return result
Example #3
Source File: test_cfgparser.py From oss-ftp with MIT License | 5 votes |
def test_missingsectionheadererror(self): import pickle e1 = ConfigParser.MissingSectionHeaderError('filename', 123, 'line') pickled = pickle.dumps(e1) e2 = pickle.loads(pickled) self.assertEqual(e1.message, e2.message) self.assertEqual(e1.args, e2.args) self.assertEqual(e1.line, e2.line) self.assertEqual(e1.filename, e2.filename) self.assertEqual(e1.lineno, e2.lineno) self.assertEqual(repr(e1), repr(e2))
Example #4
Source File: test_cfgparser.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_missingsectionheadererror(self): import pickle e1 = ConfigParser.MissingSectionHeaderError('filename', 123, 'line') pickled = pickle.dumps(e1) e2 = pickle.loads(pickled) self.assertEqual(e1.message, e2.message) self.assertEqual(e1.args, e2.args) self.assertEqual(e1.line, e2.line) self.assertEqual(e1.filename, e2.filename) self.assertEqual(e1.lineno, e2.lineno) self.assertEqual(repr(e1), repr(e2))
Example #5
Source File: test_cfgparser.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_parse_errors(self): self.newconfig() self.parse_error(ConfigParser.ParsingError, "[Foo]\n extra-spaces: splat\n") self.parse_error(ConfigParser.ParsingError, "[Foo]\n extra-spaces= splat\n") self.parse_error(ConfigParser.ParsingError, "[Foo]\n:value-without-option-name\n") self.parse_error(ConfigParser.ParsingError, "[Foo]\n=value-without-option-name\n") self.parse_error(ConfigParser.MissingSectionHeaderError, "No Section!\n")
Example #6
Source File: configfile.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def _read_config(filename): """Returns a RawConfigParser that has parsed the config file specified by the passed filename.""" # check for bad config files p = RawConfigParser() fp = None try: fp = open(filename) except IOError: pass if fp is not None: try: p.readfp(fp, filename=filename) except MissingSectionHeaderError: fp.close() del fp bad_config(filename) except ParsingError: fp.close() del fp bad_config(filename) else: fp.close() return p
Example #7
Source File: test_cfgparser.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_parse_errors(self): self.newconfig() self.parse_error(ConfigParser.ParsingError, "[Foo]\n extra-spaces: splat\n") self.parse_error(ConfigParser.ParsingError, "[Foo]\n extra-spaces= splat\n") self.parse_error(ConfigParser.ParsingError, "[Foo]\noption-without-value\n") self.parse_error(ConfigParser.ParsingError, "[Foo]\n:value-without-option-name\n") self.parse_error(ConfigParser.ParsingError, "[Foo]\n=value-without-option-name\n") self.parse_error(ConfigParser.MissingSectionHeaderError, "No Section!\n")
Example #8
Source File: test_cfgparser.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_missingsectionheadererror(self): import pickle e1 = ConfigParser.MissingSectionHeaderError('filename', 123, 'line') pickled = pickle.dumps(e1) e2 = pickle.loads(pickled) self.assertEqual(e1.message, e2.message) self.assertEqual(e1.args, e2.args) self.assertEqual(e1.line, e2.line) self.assertEqual(e1.filename, e2.filename) self.assertEqual(e1.lineno, e2.lineno) self.assertEqual(repr(e1), repr(e2))
Example #9
Source File: test_cfgparser.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_parse_errors(self): self.newconfig() self.parse_error(ConfigParser.ParsingError, "[Foo]\n extra-spaces: splat\n") self.parse_error(ConfigParser.ParsingError, "[Foo]\n extra-spaces= splat\n") self.parse_error(ConfigParser.ParsingError, "[Foo]\n:value-without-option-name\n") self.parse_error(ConfigParser.ParsingError, "[Foo]\n=value-without-option-name\n") self.parse_error(ConfigParser.MissingSectionHeaderError, "No Section!\n")
Example #10
Source File: simple_config.py From Uwallet with MIT License | 5 votes |
def read_system_config(path=SYSTEM_CONFIG_PATH): """Parse and return the system config settings in /etc/uwallet.conf.""" result = {} if os.path.exists(path): p = ConfigParser.ConfigParser() try: p.read(path) for k, v in p.items('client'): result[k] = v except (ConfigParser.NoSectionError, ConfigParser.MissingSectionHeaderError): pass return result
Example #11
Source File: newdoc.py From tools with GNU General Public License v3.0 | 5 votes |
def get_config(): """ Tries to find config options in the platform-specific user config file, otherwise falls back to defaults. """ config_dir = get_config_dir() config_file = os.path.join(config_dir, "newdoc.ini") # Copy default options to start with: options = DEFAULT_OPTIONS # Search for matching keys in the config file; if found, # update the options dict with them if os.path.isfile(config_file): config = cp.ConfigParser() try: config.read(config_file) except cp.MissingSectionHeaderError: print("Error: The [newdoc] section is required in the configuration file.") exit(1) for k in options.keys(): # The configparser library is different in Python 2 and 3. # This si the only 2/3-compatible way I've found for optional keys. try: options[k] = config.get("newdoc", k) except cp.NoOptionError: pass return options # def convert_title_to_id(title: str, doc_type: str) -> str:
Example #12
Source File: configreader.py From p2ptv-pi with MIT License | 5 votes |
def testConfig(self, goodconfig, newline, passes = 0): if newline: testconfig = goodconfig + newline + '\r\n' newfile = StringIO(testconfig) try: testparser = ConfigParser() testparser.readfp(newfile) return testconfig except MissingSectionHeaderError: if passes > 0: return goodconfig else: return self.testConfig(goodconfig + '[' + self.section + ']\n', newline, passes=1) except ParsingError: return goodconfig
Example #13
Source File: configreader.py From p2ptv-pi with MIT License | 5 votes |
def __init__(self, filename, section, defaults = None): if defaults is None: defaults = {} ConfigParser.__init__(self) self.defaults = defaults self.defaultvalues = {'string': '', 'int': 0, 'float': 0.0, 'boolean': False, 'color': None, 'bencode-list': [], 'bencode-string': '', 'bencode-fontinfo': {'name': None, 'size': None, 'style': None, 'weight': None}} self.filename = filename self.section = section dirname = os.path.dirname(self.filename) if not os.access(dirname, os.F_OK): os.makedirs(dirname) if filename.endswith('abc.conf') and not os.access(filename, os.F_OK): defaults['minport'] = str(DEFAULTPORT) try: self.read(self.filename) except MissingSectionHeaderError: oldfile = open(self.filename, 'r') oldconfig = oldfile.readlines() oldfile.close() newfile = open(self.filename, 'w') newfile.write('[' + self.section + ']\n') newfile.writelines(oldconfig) newfile.close() self.read(self.filename) except ParsingError: self.tryRepair() self.read(self.filename)
Example #14
Source File: fusesocconfigparser.py From fusesoc with BSD 2-Clause "Simplified" License | 5 votes |
def __init__(self, config_file): if sys.version[0] == "2": CP.__init__(self) else: super().__init__() if not os.path.exists(config_file): raise Exception("Could not find " + config_file) f = open(config_file) id_string = f.readline().split("=") if id_string[0].strip().upper() in ["CAPI", "SAPI"]: self.type = id_string[0] else: raise SyntaxError("Could not find API type in " + config_file) try: self.version = int(id_string[1].strip()) except ValueError: raise SyntaxError("Unknown version '{}'".format(id_string[1].strip())) except IndexError: raise SyntaxError("Could not find API version in " + config_file) if sys.version[0] == "2": exceptions = (configparser.ParsingError, configparser.DuplicateSectionError) else: exceptions = ( configparser.ParsingError, configparser.DuplicateSectionError, configparser.DuplicateOptionError, ) try: if sys.version[0] == "2": self.readfp(f) else: self.read_file(f) except configparser.MissingSectionHeaderError: raise SyntaxError("Missing section header") except exceptions as e: raise SyntaxError(e.message)
Example #15
Source File: test_cfgparser.py From oss-ftp with MIT License | 5 votes |
def test_parse_errors(self): self.newconfig() self.parse_error(ConfigParser.ParsingError, "[Foo]\n extra-spaces: splat\n") self.parse_error(ConfigParser.ParsingError, "[Foo]\n extra-spaces= splat\n") self.parse_error(ConfigParser.ParsingError, "[Foo]\n:value-without-option-name\n") self.parse_error(ConfigParser.ParsingError, "[Foo]\n=value-without-option-name\n") self.parse_error(ConfigParser.MissingSectionHeaderError, "No Section!\n")
Example #16
Source File: test_cfgparser.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_parse_errors(self): self.newconfig() self.parse_error(ConfigParser.ParsingError, "[Foo]\n extra-spaces: splat\n") self.parse_error(ConfigParser.ParsingError, "[Foo]\n extra-spaces= splat\n") self.parse_error(ConfigParser.ParsingError, "[Foo]\n:value-without-option-name\n") self.parse_error(ConfigParser.ParsingError, "[Foo]\n=value-without-option-name\n") self.parse_error(ConfigParser.MissingSectionHeaderError, "No Section!\n")
Example #17
Source File: test_cfgparser.py From BinderFilter with MIT License | 5 votes |
def test_missingsectionheadererror(self): import pickle e1 = ConfigParser.MissingSectionHeaderError('filename', 123, 'line') pickled = pickle.dumps(e1) e2 = pickle.loads(pickled) self.assertEqual(e1.message, e2.message) self.assertEqual(e1.args, e2.args) self.assertEqual(e1.line, e2.line) self.assertEqual(e1.filename, e2.filename) self.assertEqual(e1.lineno, e2.lineno) self.assertEqual(repr(e1), repr(e2))
Example #18
Source File: test_cfgparser.py From BinderFilter with MIT License | 5 votes |
def test_parse_errors(self): self.newconfig() self.parse_error(ConfigParser.ParsingError, "[Foo]\n extra-spaces: splat\n") self.parse_error(ConfigParser.ParsingError, "[Foo]\n extra-spaces= splat\n") self.parse_error(ConfigParser.ParsingError, "[Foo]\n:value-without-option-name\n") self.parse_error(ConfigParser.ParsingError, "[Foo]\n=value-without-option-name\n") self.parse_error(ConfigParser.MissingSectionHeaderError, "No Section!\n")
Example #19
Source File: openshift_facts.py From origin-ci-tool with Apache License 2.0 | 5 votes |
def get_local_facts_from_file(filename): """ Retrieve local facts from fact file Args: filename (str): local facts file Returns: dict: the retrieved facts """ local_facts = dict() try: # Handle conversion of INI style facts file to json style ini_facts = ConfigParser.SafeConfigParser() ini_facts.read(filename) for section in ini_facts.sections(): local_facts[section] = dict() for key, value in ini_facts.items(section): local_facts[section][key] = value except (ConfigParser.MissingSectionHeaderError, ConfigParser.ParsingError): try: with open(filename, 'r') as facts_file: local_facts = json.load(facts_file) except (ValueError, IOError): pass return local_facts
Example #20
Source File: openshift_facts.py From origin-ci-tool with Apache License 2.0 | 5 votes |
def get_local_facts_from_file(filename): """ Retrieve local facts from fact file Args: filename (str): local facts file Returns: dict: the retrieved facts """ local_facts = dict() try: # Handle conversion of INI style facts file to json style ini_facts = ConfigParser.SafeConfigParser() ini_facts.read(filename) for section in ini_facts.sections(): local_facts[section] = dict() for key, value in ini_facts.items(section): local_facts[section][key] = value except (ConfigParser.MissingSectionHeaderError, ConfigParser.ParsingError): try: with open(filename, 'r') as facts_file: local_facts = json.load(facts_file) except (ValueError, IOError): pass return local_facts
Example #21
Source File: openshift_facts.py From origin-ci-tool with Apache License 2.0 | 5 votes |
def get_local_facts_from_file(filename): """ Retrieve local facts from fact file Args: filename (str): local facts file Returns: dict: the retrieved facts """ local_facts = dict() try: # Handle conversion of INI style facts file to json style ini_facts = ConfigParser.SafeConfigParser() ini_facts.read(filename) for section in ini_facts.sections(): local_facts[section] = dict() for key, value in ini_facts.items(section): local_facts[section][key] = value except (ConfigParser.MissingSectionHeaderError, ConfigParser.ParsingError): try: with open(filename, 'r') as facts_file: local_facts = json.load(facts_file) except (ValueError, IOError): pass return local_facts
Example #22
Source File: openshift_facts.py From origin-ci-tool with Apache License 2.0 | 5 votes |
def get_local_facts_from_file(filename): """ Retrieve local facts from fact file Args: filename (str): local facts file Returns: dict: the retrieved facts """ local_facts = dict() try: # Handle conversion of INI style facts file to json style ini_facts = ConfigParser.SafeConfigParser() ini_facts.read(filename) for section in ini_facts.sections(): local_facts[section] = dict() for key, value in ini_facts.items(section): local_facts[section][key] = value except (ConfigParser.MissingSectionHeaderError, ConfigParser.ParsingError): try: with open(filename, 'r') as facts_file: local_facts = json.load(facts_file) except (ValueError, IOError): pass return local_facts
Example #23
Source File: __init__.py From faces with GNU General Public License v2.0 | 5 votes |
def __init__(self, defaults=None, confFile=None, *args, **kwds): """Initialize the parser. *defaults* -- defaults values. *confFile* -- the file (or list of files) to parse.""" ConfigParser.ConfigParser.__init__(self, defaults=defaults) if confFile is None: dotFileName = '.' + confFileName # Current and home directory. confFile = [os.path.join(os.getcwd(), confFileName), os.path.join(os.getcwd(), dotFileName), os.path.join(os.path.expanduser('~'), confFileName), os.path.join(os.path.expanduser('~'), dotFileName)] if os.name == 'posix': sep = getattr(os.path, 'sep', '/') # /etc/ and /etc/conf.d/ confFile.append(os.path.join(sep, 'etc', confFileName)) confFile.append(os.path.join(sep, 'etc', 'conf.d', confFileName)) else: # etc subdirectory of sys.prefix, for non-unix systems. confFile.append(os.path.join(sys.prefix, 'etc', confFileName)) for fname in confFile: try: self.read(fname) except (ConfigParser.MissingSectionHeaderError, ConfigParser.ParsingError), e: _aux_logger.warn('Troubles reading config file: %s' % e) # Stop at the first valid file. if self.has_section('imdbpy'): break
Example #24
Source File: test_cfgparser.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_missingsectionheadererror(self): import pickle e1 = ConfigParser.MissingSectionHeaderError('filename', 123, 'line') for proto in range(pickle.HIGHEST_PROTOCOL + 1): pickled = pickle.dumps(e1, proto) e2 = pickle.loads(pickled) self.assertEqual(e1.message, e2.message) self.assertEqual(e1.args, e2.args) self.assertEqual(e1.line, e2.line) self.assertEqual(e1.filename, e2.filename) self.assertEqual(e1.lineno, e2.lineno) self.assertEqual(repr(e1), repr(e2))
Example #25
Source File: test_cfgparser.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_parse_errors(self): self.newconfig() self.parse_error(ConfigParser.ParsingError, "[Foo]\n extra-spaces: splat\n") self.parse_error(ConfigParser.ParsingError, "[Foo]\n extra-spaces= splat\n") self.parse_error(ConfigParser.ParsingError, "[Foo]\n:value-without-option-name\n") self.parse_error(ConfigParser.ParsingError, "[Foo]\n=value-without-option-name\n") self.parse_error(ConfigParser.MissingSectionHeaderError, "No Section!\n")
Example #26
Source File: test_cfgparser.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_missingsectionheadererror(self): import pickle e1 = ConfigParser.MissingSectionHeaderError('filename', 123, 'line') pickled = pickle.dumps(e1) e2 = pickle.loads(pickled) self.assertEqual(e1.message, e2.message) self.assertEqual(e1.args, e2.args) self.assertEqual(e1.line, e2.line) self.assertEqual(e1.filename, e2.filename) self.assertEqual(e1.lineno, e2.lineno) self.assertEqual(repr(e1), repr(e2))
Example #27
Source File: OAuth2Util.py From praw-OAuth2Util with MIT License | 4 votes |
def __init__(self, reddit, app_key=None, app_secret=None, scope=None, refreshable=None, configfile=DEFAULT_CONFIG, print_log=False, server_mode=None): """ Create a new instance. The app info can also be read from a config file. """ self.r = reddit self.server = None self._print = print_log self.log = get_logger() self.configfile = configfile self.config = configparser.ConfigParser() needMigration = None try: self.config.read(configfile) if len(self.config.sections()) == 0: if os.path.isfile("oauth.txt"): needMigration = "oauth.txt" else: raise FNFError("File " + configfile + " not found") except configparser.MissingSectionHeaderError: needMigration = configfile if needMigration is not None: self._migrate_config(needMigration, configfile) self.config.read(configfile) if not self.config.has_section(CONFIGKEY_SERVER_MODE[0]): self.config.add_section(CONFIGKEY_SERVER_MODE[0]) try: self._get_value(CONFIGKEY_SERVER_MODE) except KeyError: self.config.set(CONFIGKEY_SERVER_MODE[0], CONFIGKEY_SERVER_MODE[1], str(False)) if app_key is not None: self.config.set(CONFIGKEY_APP_KEY[0], CONFIGKEY_APP_KEY[1], str(app_key)) if app_secret is not None: self.config.set(CONFIGKEY_APP_SECRET[0], CONFIGKEY_APP_SECRET[1], str(app_secret)) if scope is not None: self.config.set(CONFIGKEY_SCOPE[0], CONFIGKEY_SCOPE[1], str(scope)) if refreshable is not None: self.config.set(CONFIGKEY_REFRESHABLE[0], CONFIGKEY_REFRESHABLE[1], str(refreshable)) if server_mode is not None: self.config.set(CONFIGKEY_SERVER_MODE[0], CONFIGKEY_SERVER_MODE[1], str(server_mode)) global SERVER_URL, SERVER_PORT, SERVER_REDIRECT_PATH, SERVER_LINK_PATH SERVER_URL = self._get_value(CONFIGKEY_SERVER_URL, exception_default=SERVER_URL) SERVER_PORT = self._get_value(CONFIGKEY_SERVER_PORT, int, exception_default=SERVER_PORT) SERVER_REDIRECT_PATH = self._get_value(CONFIGKEY_SERVER_REDIRECT_PATH, exception_default=SERVER_REDIRECT_PATH) SERVER_LINK_PATH = self._get_value(CONFIGKEY_SERVER_LINK_PATH, exception_default=SERVER_LINK_PATH) self._set_app_info() self.refresh() self.set_access_credentials()
Example #28
Source File: options_parser.py From mysql-utilities with GNU General Public License v2.0 | 4 votes |
def read(self, filenames): """Read and parse a filename or a list of filenames. Overridden from ConfigParser and modified so as to allow options which are not inside any section header filenames[in] The file names to read. Return list of successfully read files. """ # Get python version since we must use str() to read strings from # the file for older, 2.6 versions of Python py26 = check_python_version((2, 6, 0), (2, 6, 99), False, None, False, False, False) if isinstance(filenames, str): filenames = [filenames] read_ok = [] for priority, filename in enumerate(filenames): try: out_file = io.StringIO() for line in codecs.open(filename, encoding='utf-8'): line = line.strip() match_obj = self.OPTCRE.match(line) if not self.SECTCRE.match(line) and match_obj: optname, delimiter, optval = match_obj.group('option', 'vi', 'value') if optname and not optval and not delimiter: out_file.write(line + "=\n") else: out_file.write(line + '\n') else: out_file.write(line + '\n') out_file.seek(0) self._read(out_file, filename) except IOError: continue try: self._read(out_file, filename) for group in self._sections.keys(): try: self._options_dict[group] except KeyError: self._options_dict[group] = {} for option, value in self._sections[group].items(): if py26: self._options_dict[group][option] = (str(value), priority) else: self._options_dict[group][option] = (value, priority) self._sections = self._dict() except MissingSectionHeaderError: self._read(out_file, filename) out_file.close() read_ok.append(filename) return read_ok
Example #29
Source File: optionfiles.py From plugin.video.netflix with MIT License | 4 votes |
def read(self, filenames): # pylint: disable=W0221 """Read and parse a filename or a list of filenames. Overridden from ConfigParser and modified so as to allow options which are not inside any section header Return list of successfully read files. """ if isinstance(filenames, str): filenames = [filenames] read_ok = [] for priority, filename in enumerate(filenames): try: out_file = io.StringIO() for line in codecs.open(filename, encoding='utf-8'): line = line.strip() match_obj = self.OPTCRE.match(line) if not self.SECTCRE.match(line) and match_obj: optname, delimiter, optval = match_obj.group('option', 'vi', 'value') if optname and not optval and not delimiter: out_file.write(line + "=\n") else: out_file.write(line + '\n') else: out_file.write(line + '\n') out_file.seek(0) except IOError: continue try: self._read(out_file, filename) for group in self._sections.keys(): try: self._options_dict[group] except KeyError: self._options_dict[group] = {} for option, value in self._sections[group].items(): self._options_dict[group][option] = (value, priority) self._sections = self._dict() except MissingSectionHeaderError: self._read(out_file, filename) out_file.close() read_ok.append(filename) return read_ok
Example #30
Source File: optionfiles.py From python-mysql-pool with MIT License | 4 votes |
def read(self, filenames): # pylint: disable=W0221 """Read and parse a filename or a list of filenames. Overridden from ConfigParser and modified so as to allow options which are not inside any section header Return list of successfully read files. """ if isinstance(filenames, str): filenames = [filenames] read_ok = [] for priority, filename in enumerate(filenames): try: out_file = io.StringIO() for line in codecs.open(filename, encoding='utf-8'): line = line.strip() match_obj = self.OPTCRE.match(line) if not self.SECTCRE.match(line) and match_obj: optname, delimiter, optval = match_obj.group('option', 'vi', 'value') if optname and not optval and not delimiter: out_file.write(line + "=\n") else: out_file.write(line + '\n') else: out_file.write(line + '\n') out_file.seek(0) except IOError: continue try: self._read(out_file, filename) for group in self._sections.keys(): try: self._options_dict[group] except KeyError: self._options_dict[group] = {} for option, value in self._sections[group].items(): self._options_dict[group][option] = (value, priority) self._sections = self._dict() except MissingSectionHeaderError: self._read(out_file, filename) out_file.close() read_ok.append(filename) return read_ok