Loading six.py→collections.py +71 −0 Original line number Diff line number Diff line Loading @@ -16,18 +16,56 @@ # You should have received a copy of the GNU Lesser General Public License # along with Ammsml. If not, see <http://www.gnu.org/licenses/>. from collections.abc import Sequence def with_metaclass(meta, *bases): """Create a base class with a metaclass.""" # This requires a bit of explanation: the basic idea is to make a dummy # metaclass for one level of class instantiation that replaces itself with # the actual metaclass. class metaclass(type): def __new__(cls, name, this_bases, d): return meta(name, bases, d) def is_string(seq): """Identify whether the input has a string-like type.""" return isinstance(seq, str) @classmethod def __prepare__(cls, name, this_bases): return meta.__prepare__(name, bases) return type.__new__(metaclass, 'temporary_class', (), {}) def is_iterable(seq, include_strings=False): """Identify whether the input is an iterable.""" if not include_strings and is_string(seq): return False try: iter(seq) return True except TypeError: return False def is_sequence(seq, include_strings=False): """ Identify whether the input is a sequence. Strings are not sequences here, unless ``include_string`` is ``True``. Non-indexable things are never of a sequence type. """ if not include_strings and is_string(seq): return False return isinstance(seq, Sequence) def count(seq): """ Returns a dictionary with the number of appearances of each element of the iterable. Resembles the `collections.Counter` class functionality, which is deprecated since version 3.3, will be removed in version 3.9 It is meant to be replaced when the we find something equivalent in maybe collections.abc this code also runs on Python 2.6.* where collections.Counter is not available. """ if not is_iterable(seq): raise Exception('Argument provided is not an iterable') if not is_iterable(seq): raise Exception('Argument provided is not an iterable') counters = dict() for elem in seq: counters[elem] = counters.get(elem, 0) + 1 return counters display.py +1 −2 Original line number Diff line number Diff line Loading @@ -31,9 +31,8 @@ from termios import TIOCGWINSZ from ammsml.utils.color import stringc from ammsml.utils.parsing import to_text from ammsml.utils.errors import AMMSMLError from ammsml.utils.singleton import Singleton from ammsml.utils.singleton import Singleton, with_metaclass from ammsml.config import constants as C from ammsml.utils.six import with_metaclass from ammsml.utils.wrap import wrap_var Loading git.py +17 −0 Original line number Diff line number Diff line # GNU Lesser General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/lgpl-3.0.txt) # (c) 2019, Christof Schulze <christof.schulze@fau.de> # # This file is part of Ammsml # # Ammsml is free software: you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ammsml is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with Ammsml. If not, see <http://www.gnu.org/licenses/>. import os import time Loading parsing/__init__.py +0 −1 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ # You should have received a copy of the GNU Lesser General Public License # along with Ammsml. If not, see <http://www.gnu.org/licenses/>. BOOLEANS_TRUE = frozenset(('y', 'yes', 'on', '1', 'true', 't', 1, 1.0, True)) BOOLEANS_FALSE = frozenset(('n', 'no', 'off', '0', 'false', 'f', 0, 0.0, False)) BOOLEANS = BOOLEANS_TRUE.union(BOOLEANS_FALSE) Loading parsing/yaml/dumper.py +18 −1 Original line number Diff line number Diff line import yaml # GNU Lesser General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/lgpl-3.0.txt) # (c) 2019, Christof Schulze <christof.schulze@fau.de> # # This file is part of Ammsml # # Ammsml is free software: you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ammsml is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with Ammsml. If not, see <http://www.gnu.org/licenses/>. import yaml # from ammsml.vars.hostvars import HostVars, HostVarsVars from ammsml.utils.parsing.yaml.objects import AMMSMLUnicode, AMMSMLSequence, AMMSMLMapping Loading Loading
six.py→collections.py +71 −0 Original line number Diff line number Diff line Loading @@ -16,18 +16,56 @@ # You should have received a copy of the GNU Lesser General Public License # along with Ammsml. If not, see <http://www.gnu.org/licenses/>. from collections.abc import Sequence def with_metaclass(meta, *bases): """Create a base class with a metaclass.""" # This requires a bit of explanation: the basic idea is to make a dummy # metaclass for one level of class instantiation that replaces itself with # the actual metaclass. class metaclass(type): def __new__(cls, name, this_bases, d): return meta(name, bases, d) def is_string(seq): """Identify whether the input has a string-like type.""" return isinstance(seq, str) @classmethod def __prepare__(cls, name, this_bases): return meta.__prepare__(name, bases) return type.__new__(metaclass, 'temporary_class', (), {}) def is_iterable(seq, include_strings=False): """Identify whether the input is an iterable.""" if not include_strings and is_string(seq): return False try: iter(seq) return True except TypeError: return False def is_sequence(seq, include_strings=False): """ Identify whether the input is a sequence. Strings are not sequences here, unless ``include_string`` is ``True``. Non-indexable things are never of a sequence type. """ if not include_strings and is_string(seq): return False return isinstance(seq, Sequence) def count(seq): """ Returns a dictionary with the number of appearances of each element of the iterable. Resembles the `collections.Counter` class functionality, which is deprecated since version 3.3, will be removed in version 3.9 It is meant to be replaced when the we find something equivalent in maybe collections.abc this code also runs on Python 2.6.* where collections.Counter is not available. """ if not is_iterable(seq): raise Exception('Argument provided is not an iterable') if not is_iterable(seq): raise Exception('Argument provided is not an iterable') counters = dict() for elem in seq: counters[elem] = counters.get(elem, 0) + 1 return counters
display.py +1 −2 Original line number Diff line number Diff line Loading @@ -31,9 +31,8 @@ from termios import TIOCGWINSZ from ammsml.utils.color import stringc from ammsml.utils.parsing import to_text from ammsml.utils.errors import AMMSMLError from ammsml.utils.singleton import Singleton from ammsml.utils.singleton import Singleton, with_metaclass from ammsml.config import constants as C from ammsml.utils.six import with_metaclass from ammsml.utils.wrap import wrap_var Loading
git.py +17 −0 Original line number Diff line number Diff line # GNU Lesser General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/lgpl-3.0.txt) # (c) 2019, Christof Schulze <christof.schulze@fau.de> # # This file is part of Ammsml # # Ammsml is free software: you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ammsml is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with Ammsml. If not, see <http://www.gnu.org/licenses/>. import os import time Loading
parsing/__init__.py +0 −1 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ # You should have received a copy of the GNU Lesser General Public License # along with Ammsml. If not, see <http://www.gnu.org/licenses/>. BOOLEANS_TRUE = frozenset(('y', 'yes', 'on', '1', 'true', 't', 1, 1.0, True)) BOOLEANS_FALSE = frozenset(('n', 'no', 'off', '0', 'false', 'f', 0, 0.0, False)) BOOLEANS = BOOLEANS_TRUE.union(BOOLEANS_FALSE) Loading
parsing/yaml/dumper.py +18 −1 Original line number Diff line number Diff line import yaml # GNU Lesser General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/lgpl-3.0.txt) # (c) 2019, Christof Schulze <christof.schulze@fau.de> # # This file is part of Ammsml # # Ammsml is free software: you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ammsml is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with Ammsml. If not, see <http://www.gnu.org/licenses/>. import yaml # from ammsml.vars.hostvars import HostVars, HostVarsVars from ammsml.utils.parsing.yaml.objects import AMMSMLUnicode, AMMSMLSequence, AMMSMLMapping Loading