"""EditorConfig file parser Based on code from ConfigParser.py file distributed with Python 2.6. Licensed under PSF License (see LICENSE.PSF file). Changes to original ConfigParser: - Special characters can be used in section names - Octothorpe can be used for comments (not just at beginning of line) - Only track INI options in sections that match target filename - Stop parsing files with when ``root = true`` is found """ import posixpath import re from codecs import open from collections import OrderedDict from os import sep from os.path import dirname, normpath from editorconfig.compat import u from editorconfig.exceptions import ParsingError from editorconfig.fnmatch import fnmatch __all__ = ["ParsingError", "EditorConfigParser"] MAX_SECTION_LENGTH = 4096 MAX_PROPERTY_LENGTH= 50 MAX_VALUE_LENGTH = 255 class EditorConfigParser(object): """Parser for EditorConfig-style configuration files Based on RawConfigParser from ConfigParser.py in Python 2.6. """ # Regular expressions for parsing section headers and options. # Allow ``]`` and escaped ``;`` and ``#`` characters in section headers SECTCRE = re.compile( r""" \s * # Optional whitespace \[ # Opening square brace (?P
# One or more characters excluding ( [^\#;] | \\\# | \\; ) + # unescaped # and ; characters ) \] # Closing square brace """, re.VERBOSE ) # Regular expression for parsing option name/values. # Allow any amount of whitespaces, followed by separator # (either ``:`` or ``=``), followed by any amount of whitespace and then # any characters to eol OPTCRE = re.compile( r""" \s * # Optional whitespace (?P