summaryrefslogtreecommitdiffstats
path: root/contrib/python/iniconfig
diff options
context:
space:
mode:
authorarcadia-devtools <[email protected]>2022-02-09 12:00:52 +0300
committerDaniil Cherednik <[email protected]>2022-02-10 15:58:17 +0300
commit8e1413fed79d1e8036e65228af6c93399ccf5502 (patch)
tree502c9df7b2614d20541c7a2d39d390e9a51877cc /contrib/python/iniconfig
parent6b813c17d56d1d05f92c61ddc347d0e4d358fe85 (diff)
intermediate changes
ref:614ed510ddd3cdf86a8c5dbf19afd113397e0172
Diffstat (limited to 'contrib/python/iniconfig')
-rw-r--r--contrib/python/iniconfig/.dist-info/METADATA78
-rw-r--r--contrib/python/iniconfig/.dist-info/top_level.txt1
-rw-r--r--contrib/python/iniconfig/LICENSE19
-rw-r--r--contrib/python/iniconfig/README.txt51
-rw-r--r--contrib/python/iniconfig/iniconfig/__init__.py173
-rw-r--r--contrib/python/iniconfig/iniconfig/__init__.pyi31
-rw-r--r--contrib/python/iniconfig/iniconfig/py.typed0
-rw-r--r--contrib/python/iniconfig/patches/01-arcadia.patch26
-rw-r--r--contrib/python/iniconfig/ya.make26
9 files changed, 405 insertions, 0 deletions
diff --git a/contrib/python/iniconfig/.dist-info/METADATA b/contrib/python/iniconfig/.dist-info/METADATA
new file mode 100644
index 00000000000..c078a7532fb
--- /dev/null
+++ b/contrib/python/iniconfig/.dist-info/METADATA
@@ -0,0 +1,78 @@
+Metadata-Version: 2.1
+Name: iniconfig
+Version: 1.1.1
+Summary: iniconfig: brain-dead simple config-ini parsing
+Home-page: http://github.com/RonnyPfannschmidt/iniconfig
+Author: Ronny Pfannschmidt, Holger Krekel
+License: MIT License
+Platform: unix
+Platform: linux
+Platform: osx
+Platform: cygwin
+Platform: win32
+Classifier: Development Status :: 4 - Beta
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: MIT License
+Classifier: Operating System :: POSIX
+Classifier: Operating System :: Microsoft :: Windows
+Classifier: Operating System :: MacOS :: MacOS X
+Classifier: Topic :: Software Development :: Libraries
+Classifier: Topic :: Utilities
+Classifier: Programming Language :: Python
+Classifier: Programming Language :: Python :: 2
+Classifier: Programming Language :: Python :: 3
+
+iniconfig: brain-dead simple parsing of ini files
+=======================================================
+
+iniconfig is a small and simple INI-file parser module
+having a unique set of features:
+
+* tested against Python2.4 across to Python3.2, Jython, PyPy
+* maintains order of sections and entries
+* supports multi-line values with or without line-continuations
+* supports "#" comments everywhere
+* raises errors with proper line-numbers
+* no bells and whistles like automatic substitutions
+* iniconfig raises an Error if two sections have the same name.
+
+If you encounter issues or have feature wishes please report them to:
+
+ http://github.com/RonnyPfannschmidt/iniconfig/issues
+
+Basic Example
+===================================
+
+If you have an ini file like this::
+
+ # content of example.ini
+ [section1] # comment
+ name1=value1 # comment
+ name1b=value1,value2 # comment
+
+ [section2]
+ name2=
+ line1
+ line2
+
+then you can do::
+
+ >>> import iniconfig
+ >>> ini = iniconfig.IniConfig("example.ini")
+ >>> ini['section1']['name1'] # raises KeyError if not exists
+ 'value1'
+ >>> ini.get('section1', 'name1b', [], lambda x: x.split(","))
+ ['value1', 'value2']
+ >>> ini.get('section1', 'notexist', [], lambda x: x.split(","))
+ []
+ >>> [x.name for x in list(ini)]
+ ['section1', 'section2']
+ >>> list(list(ini)[0].items())
+ [('name1', 'value1'), ('name1b', 'value1,value2')]
+ >>> 'section1' in ini
+ True
+ >>> 'inexistendsection' in ini
+ False
+
+
diff --git a/contrib/python/iniconfig/.dist-info/top_level.txt b/contrib/python/iniconfig/.dist-info/top_level.txt
new file mode 100644
index 00000000000..9dda53692d2
--- /dev/null
+++ b/contrib/python/iniconfig/.dist-info/top_level.txt
@@ -0,0 +1 @@
+iniconfig
diff --git a/contrib/python/iniconfig/LICENSE b/contrib/python/iniconfig/LICENSE
new file mode 100644
index 00000000000..31ecdfb1dbc
--- /dev/null
+++ b/contrib/python/iniconfig/LICENSE
@@ -0,0 +1,19 @@
+
+ Permission is hereby granted, free of charge, to any person obtaining a copy
+ of this software and associated documentation files (the "Software"), to deal
+ in the Software without restriction, including without limitation the rights
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the Software is
+ furnished to do so, subject to the following conditions:
+
+ The above copyright notice and this permission notice shall be included in all
+ copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ SOFTWARE.
+
diff --git a/contrib/python/iniconfig/README.txt b/contrib/python/iniconfig/README.txt
new file mode 100644
index 00000000000..6bbad9a8d96
--- /dev/null
+++ b/contrib/python/iniconfig/README.txt
@@ -0,0 +1,51 @@
+iniconfig: brain-dead simple parsing of ini files
+=======================================================
+
+iniconfig is a small and simple INI-file parser module
+having a unique set of features:
+
+* tested against Python2.4 across to Python3.2, Jython, PyPy
+* maintains order of sections and entries
+* supports multi-line values with or without line-continuations
+* supports "#" comments everywhere
+* raises errors with proper line-numbers
+* no bells and whistles like automatic substitutions
+* iniconfig raises an Error if two sections have the same name.
+
+If you encounter issues or have feature wishes please report them to:
+
+ http://github.com/RonnyPfannschmidt/iniconfig/issues
+
+Basic Example
+===================================
+
+If you have an ini file like this::
+
+ # content of example.ini
+ [section1] # comment
+ name1=value1 # comment
+ name1b=value1,value2 # comment
+
+ [section2]
+ name2=
+ line1
+ line2
+
+then you can do::
+
+ >>> import iniconfig
+ >>> ini = iniconfig.IniConfig("example.ini")
+ >>> ini['section1']['name1'] # raises KeyError if not exists
+ 'value1'
+ >>> ini.get('section1', 'name1b', [], lambda x: x.split(","))
+ ['value1', 'value2']
+ >>> ini.get('section1', 'notexist', [], lambda x: x.split(","))
+ []
+ >>> [x.name for x in list(ini)]
+ ['section1', 'section2']
+ >>> list(list(ini)[0].items())
+ [('name1', 'value1'), ('name1b', 'value1,value2')]
+ >>> 'section1' in ini
+ True
+ >>> 'inexistendsection' in ini
+ False
diff --git a/contrib/python/iniconfig/iniconfig/__init__.py b/contrib/python/iniconfig/iniconfig/__init__.py
new file mode 100644
index 00000000000..32098313628
--- /dev/null
+++ b/contrib/python/iniconfig/iniconfig/__init__.py
@@ -0,0 +1,173 @@
+""" brain-dead simple parser for ini-style files.
+(C) Ronny Pfannschmidt, Holger Krekel -- MIT licensed
+"""
+import os
+__all__ = ['IniConfig', 'ParseError']
+
+COMMENTCHARS = "#;"
+
+
+class ParseError(Exception):
+ def __init__(self, path, lineno, msg):
+ Exception.__init__(self, path, lineno, msg)
+ self.path = path
+ self.lineno = lineno
+ self.msg = msg
+
+ def __str__(self):
+ return "%s:%s: %s" % (self.path, self.lineno+1, self.msg)
+
+
+class SectionWrapper(object):
+ def __init__(self, config, name):
+ self.config = config
+ self.name = name
+
+ def lineof(self, name):
+ return self.config.lineof(self.name, name)
+
+ def get(self, key, default=None, convert=str):
+ return self.config.get(self.name, key,
+ convert=convert, default=default)
+
+ def __getitem__(self, key):
+ return self.config.sections[self.name][key]
+
+ def __iter__(self):
+ section = self.config.sections.get(self.name, [])
+
+ def lineof(key):
+ return self.config.lineof(self.name, key)
+ for name in sorted(section, key=lineof):
+ yield name
+
+ def items(self):
+ for name in self:
+ yield name, self[name]
+
+
+class IniConfig(object):
+ def __init__(self, path, data=None):
+ self.path = str(path) # convenience
+ if data is None:
+ if os.path.basename(self.path).startswith('pkg:'):
+ import io, pkgutil
+
+ _, package, resource = self.path.split(':')
+ content = pkgutil.get_data(package, resource)
+ f = io.StringIO(content.decode('utf-8'))
+ else:
+ f = open(self.path)
+ try:
+ tokens = self._parse(iter(f))
+ finally:
+ f.close()
+ else:
+ tokens = self._parse(data.splitlines(True))
+
+ self._sources = {}
+ self.sections = {}
+
+ for lineno, section, name, value in tokens:
+ if section is None:
+ self._raise(lineno, 'no section header defined')
+ self._sources[section, name] = lineno
+ if name is None:
+ if section in self.sections:
+ self._raise(lineno, 'duplicate section %r' % (section, ))
+ self.sections[section] = {}
+ else:
+ if name in self.sections[section]:
+ self._raise(lineno, 'duplicate name %r' % (name, ))
+ self.sections[section][name] = value
+
+ def _raise(self, lineno, msg):
+ raise ParseError(self.path, lineno, msg)
+
+ def _parse(self, line_iter):
+ result = []
+ section = None
+ for lineno, line in enumerate(line_iter):
+ name, data = self._parseline(line, lineno)
+ # new value
+ if name is not None and data is not None:
+ result.append((lineno, section, name, data))
+ # new section
+ elif name is not None and data is None:
+ if not name:
+ self._raise(lineno, 'empty section name')
+ section = name
+ result.append((lineno, section, None, None))
+ # continuation
+ elif name is None and data is not None:
+ if not result:
+ self._raise(lineno, 'unexpected value continuation')
+ last = result.pop()
+ last_name, last_data = last[-2:]
+ if last_name is None:
+ self._raise(lineno, 'unexpected value continuation')
+
+ if last_data:
+ data = '%s\n%s' % (last_data, data)
+ result.append(last[:-1] + (data,))
+ return result
+
+ def _parseline(self, line, lineno):
+ # blank lines
+ if iscommentline(line):
+ line = ""
+ else:
+ line = line.rstrip()
+ if not line:
+ return None, None
+ # section
+ if line[0] == '[':
+ realline = line
+ for c in COMMENTCHARS:
+ line = line.split(c)[0].rstrip()
+ if line[-1] == "]":
+ return line[1:-1], None
+ return None, realline.strip()
+ # value
+ elif not line[0].isspace():
+ try:
+ name, value = line.split('=', 1)
+ if ":" in name:
+ raise ValueError()
+ except ValueError:
+ try:
+ name, value = line.split(":", 1)
+ except ValueError:
+ self._raise(lineno, 'unexpected line: %r' % line)
+ return name.strip(), value.strip()
+ # continuation
+ else:
+ return None, line.strip()
+
+ def lineof(self, section, name=None):
+ lineno = self._sources.get((section, name))
+ if lineno is not None:
+ return lineno + 1
+
+ def get(self, section, name, default=None, convert=str):
+ try:
+ return convert(self.sections[section][name])
+ except KeyError:
+ return default
+
+ def __getitem__(self, name):
+ if name not in self.sections:
+ raise KeyError(name)
+ return SectionWrapper(self, name)
+
+ def __iter__(self):
+ for name in sorted(self.sections, key=self.lineof):
+ yield SectionWrapper(self, name)
+
+ def __contains__(self, arg):
+ return arg in self.sections
+
+
+def iscommentline(line):
+ c = line.lstrip()[:1]
+ return c in COMMENTCHARS
diff --git a/contrib/python/iniconfig/iniconfig/__init__.pyi b/contrib/python/iniconfig/iniconfig/__init__.pyi
new file mode 100644
index 00000000000..b6284bec3f6
--- /dev/null
+++ b/contrib/python/iniconfig/iniconfig/__init__.pyi
@@ -0,0 +1,31 @@
+from typing import Callable, Iterator, Mapping, Optional, Tuple, TypeVar, Union
+from typing_extensions import Final
+
+_D = TypeVar('_D')
+_T = TypeVar('_T')
+
+class ParseError(Exception):
+ # Private __init__.
+ path: Final[str]
+ lineno: Final[int]
+ msg: Final[str]
+
+class SectionWrapper:
+ # Private __init__.
+ config: Final[IniConfig]
+ name: Final[str]
+ def __getitem__(self, key: str) -> str: ...
+ def __iter__(self) -> Iterator[str]: ...
+ def get(self, key: str, default: _D = ..., convert: Callable[[str], _T] = ...) -> Union[_T, _D]: ...
+ def items(self) -> Iterator[Tuple[str, str]]: ...
+ def lineof(self, name: str) -> Optional[int]: ...
+
+class IniConfig:
+ path: Final[str]
+ sections: Final[Mapping[str, Mapping[str, str]]]
+ def __init__(self, path: str, data: Optional[str] = None): ...
+ def __contains__(self, arg: str) -> bool: ...
+ def __getitem__(self, name: str) -> SectionWrapper: ...
+ def __iter__(self) -> Iterator[SectionWrapper]: ...
+ def get(self, section: str, name: str, default: _D = ..., convert: Callable[[str], _T] = ...) -> Union[_T, _D]: ...
+ def lineof(self, section: str, name: Optional[str] = ...) -> Optional[int]: ...
diff --git a/contrib/python/iniconfig/iniconfig/py.typed b/contrib/python/iniconfig/iniconfig/py.typed
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/contrib/python/iniconfig/iniconfig/py.typed
diff --git a/contrib/python/iniconfig/patches/01-arcadia.patch b/contrib/python/iniconfig/patches/01-arcadia.patch
new file mode 100644
index 00000000000..16d9cd88a40
--- /dev/null
+++ b/contrib/python/iniconfig/patches/01-arcadia.patch
@@ -0,0 +1,26 @@
+--- contrib/python/iniconfig/iniconfig/__init__.py (index)
++++ contrib/python/iniconfig/iniconfig/__init__.py (working tree)
+@@ -1,6 +1,7 @@
+ """ brain-dead simple parser for ini-style files.
+ (C) Ronny Pfannschmidt, Holger Krekel -- MIT licensed
+ """
++import os
+ __all__ = ['IniConfig', 'ParseError']
+
+ COMMENTCHARS = "#;"
+@@ -49,7 +50,14 @@ class IniConfig(object):
+ def __init__(self, path, data=None):
+ self.path = str(path) # convenience
+ if data is None:
+- f = open(self.path)
++ if os.path.basename(self.path).startswith('pkg:'):
++ import io, pkgutil
++
++ _, package, resource = self.path.split(':')
++ content = pkgutil.get_data(package, resource)
++ f = io.StringIO(content.decode('utf-8'))
++ else:
++ f = open(self.path)
+ try:
+ tokens = self._parse(iter(f))
+ finally:
diff --git a/contrib/python/iniconfig/ya.make b/contrib/python/iniconfig/ya.make
new file mode 100644
index 00000000000..9121ccd0ab9
--- /dev/null
+++ b/contrib/python/iniconfig/ya.make
@@ -0,0 +1,26 @@
+# Generated by devtools/yamaker (pypi).
+
+PY3_LIBRARY()
+
+OWNER(g:python-contrib)
+
+VERSION(1.1.1)
+
+LICENSE(MIT)
+
+NO_LINT()
+
+PY_SRCS(
+ TOP_LEVEL
+ iniconfig/__init__.py
+ iniconfig/__init__.pyi
+)
+
+RESOURCE_FILES(
+ PREFIX contrib/python/iniconfig/
+ .dist-info/METADATA
+ .dist-info/top_level.txt
+ iniconfig/py.typed
+)
+
+END()