Browse Source

Export python deepmerge library instead of mergedeep to github.com/ydb-platform/ydb for support python2
98bbe613ba94337077da6f6bb9b519768fdef800

rekby 6 months ago
parent
commit
f23ace9b7c

+ 80 - 0
contrib/python/deepmerge/py2/.dist-info/METADATA

@@ -0,0 +1,80 @@
+Metadata-Version: 2.1
+Name: deepmerge
+Version: 1.1.0
+Summary: a toolset to deeply merge python dictionaries.
+Home-page: http://deepmerge.readthedocs.io/en/latest/
+Classifier: Development Status :: 5 - Production/Stable
+Classifier: License :: OSI Approved :: MIT License
+Classifier: Programming Language :: Python :: 3
+License-File: LICENSE
+
+=========
+deepmerge
+=========
+
+.. image:: https://github.com/toumorokoshi/deepmerge/actions/workflows/python-package.yaml/badge.svg
+    :target: https://github.com/toumorokoshi/deepmerge/actions/workflows/python-package.yaml
+
+A tools to handle merging of
+nested data structures in python.
+
+------------
+Installation
+------------
+
+deepmerge is available on `pypi <https://pypi.python.org/>`_:
+
+.. code-block:: bash
+
+   pip install deepmerge
+
+-------
+Example
+-------
+
+**Generic Strategy**
+
+.. code-block:: python
+
+    from deepmerge import always_merger
+
+    base = {"foo": ["bar"]}
+    next = {"foo": ["baz"]}
+
+    expected_result = {'foo': ['bar', 'baz']}
+    result = always_merger.merge(base, next)
+
+    assert expected_result == result
+
+
+**Custom Strategy**
+
+.. code-block:: python
+
+    from deepmerge import Merger
+
+    my_merger = Merger(
+        # pass in a list of tuple, with the
+        # strategies you are looking to apply
+        # to each type.
+        [
+            (list, ["append"]),
+            (dict, ["merge"]),
+            (set, ["union"])
+        ],
+        # next, choose the fallback strategies,
+        # applied to all other types:
+        ["override"],
+        # finally, choose the strategies in
+        # the case where the types conflict:
+        ["override"]
+    )
+    base = {"foo": ["bar"]}
+    next = {"bar": "baz"}
+    my_merger.merge(base, next)
+    assert base == {"foo": ["bar"], "bar": "baz"}
+
+
+You can also pass in your own merge functions, instead of a string.
+
+For more information, see the `docs <https://deepmerge.readthedocs.io/en/latest/>`_

+ 1 - 0
contrib/python/deepmerge/py2/.dist-info/top_level.txt

@@ -0,0 +1 @@
+deepmerge

+ 6 - 6
contrib/python/mergedeep/LICENSE → contrib/python/deepmerge/py2/LICENSE

@@ -1,6 +1,6 @@
-The MIT License (MIT)
+MIT License
 
-Copyright (c) 2019 Travis Clarke <travis.m.clarke@gmail.com> (https://www.travismclarke.com/)
+Copyright (c) 2016 Yusuke Tsutsumi
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
@@ -9,13 +9,13 @@ 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 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.
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.

+ 70 - 0
contrib/python/deepmerge/py2/README.rst

@@ -0,0 +1,70 @@
+=========
+deepmerge
+=========
+
+.. image:: https://github.com/toumorokoshi/deepmerge/actions/workflows/python-package.yaml/badge.svg
+    :target: https://github.com/toumorokoshi/deepmerge/actions/workflows/python-package.yaml
+
+A tools to handle merging of
+nested data structures in python.
+
+------------
+Installation
+------------
+
+deepmerge is available on `pypi <https://pypi.python.org/>`_:
+
+.. code-block:: bash
+
+   pip install deepmerge
+
+-------
+Example
+-------
+
+**Generic Strategy**
+
+.. code-block:: python
+
+    from deepmerge import always_merger
+
+    base = {"foo": ["bar"]}
+    next = {"foo": ["baz"]}
+
+    expected_result = {'foo': ['bar', 'baz']}
+    result = always_merger.merge(base, next)
+
+    assert expected_result == result
+
+
+**Custom Strategy**
+
+.. code-block:: python
+
+    from deepmerge import Merger
+
+    my_merger = Merger(
+        # pass in a list of tuple, with the
+        # strategies you are looking to apply
+        # to each type.
+        [
+            (list, ["append"]),
+            (dict, ["merge"]),
+            (set, ["union"])
+        ],
+        # next, choose the fallback strategies,
+        # applied to all other types:
+        ["override"],
+        # finally, choose the strategies in
+        # the case where the types conflict:
+        ["override"]
+    )
+    base = {"foo": ["bar"]}
+    next = {"bar": "baz"}
+    my_merger.merge(base, next)
+    assert base == {"foo": ["bar"], "bar": "baz"}
+
+
+You can also pass in your own merge functions, instead of a string.
+
+For more information, see the `docs <https://deepmerge.readthedocs.io/en/latest/>`_

+ 34 - 0
contrib/python/deepmerge/py2/deepmerge/__init__.py

@@ -0,0 +1,34 @@
+from .merger import Merger
+from .strategy.core import STRATEGY_END  # noqa
+
+# some standard mergers available
+
+DEFAULT_TYPE_SPECIFIC_MERGE_STRATEGIES = [
+    (list, "append"),
+    (dict, "merge"),
+    (set, "union"),
+]
+
+# this merge will never raise an exception.
+# in the case of type mismatches,
+# the value from the second object
+# will override the previous one.
+always_merger = Merger(
+    DEFAULT_TYPE_SPECIFIC_MERGE_STRATEGIES, ["override"], ["override"]
+)
+
+# this merge strategies attempts
+# to merge (append for list, unify for dicts)
+# if possible, but raises an exception
+# in the case of type conflicts.
+merge_or_raise = Merger(DEFAULT_TYPE_SPECIFIC_MERGE_STRATEGIES, [], [])
+
+# a conservative merge tactic:
+# for data structures with a specific
+# strategy, keep the existing value.
+# similar to always_merger but instead
+# keeps existing values when faced
+# with a type conflict.
+conservative_merger = Merger(
+    DEFAULT_TYPE_SPECIFIC_MERGE_STRATEGIES, ["use_existing"], ["use_existing"]
+)

+ 5 - 0
contrib/python/deepmerge/py2/deepmerge/_version.py

@@ -0,0 +1,5 @@
+# coding: utf-8
+# file generated by setuptools_scm
+# don't change, don't track in version control
+__version__ = version = '1.1.0'
+__version_tuple__ = version_tuple = (1, 1, 0)

+ 4 - 0
contrib/python/deepmerge/py2/deepmerge/compat.py

@@ -0,0 +1,4 @@
+try:
+    string_type = basestring
+except:
+    string_type = str

+ 18 - 0
contrib/python/deepmerge/py2/deepmerge/exception.py

@@ -0,0 +1,18 @@
+class DeepMergeException(Exception):
+    pass
+
+
+class StrategyNotFound(DeepMergeException):
+    pass
+
+
+class InvalidMerge(DeepMergeException):
+    def __init__(self, strategy_list_name, merge_args, merge_kwargs):
+        super(InvalidMerge, self).__init__(
+            "no more strategies found for {0} and arguments {1}, {2}".format(
+                strategy_list_name, merge_args, merge_kwargs
+            )
+        )
+        self.strategy_list_name = strategy_list_name
+        self.merge_args = merge_args
+        self.merge_kwargs = merge_kwargs

+ 25 - 0
contrib/python/deepmerge/py2/deepmerge/extended_set.py

@@ -0,0 +1,25 @@
+class ExtendedSet(set):
+    """
+    ExtendedSet is an extension of set, which allows for usage
+    of types that are typically not allowed in a set
+    (e.g. unhashable).
+
+    The following types that cannot be used in a set are supported:
+
+    - unhashable types
+    """
+
+    def __init__(self, elements):
+        self._values_by_hash = {self._hash(e): e for e in elements}
+
+    def _insert(self, element):
+        self._values_by_hash[self._hash(element)] = element
+
+    def _hash(self, element):
+        if getattr(element, "__hash__") is not None:
+            return hash(element)
+        else:
+            return hash(str(element))
+
+    def __contains__(self, obj):
+        return self._hash(obj) in self._values_by_hash

+ 44 - 0
contrib/python/deepmerge/py2/deepmerge/merger.py

@@ -0,0 +1,44 @@
+from .strategy.list import ListStrategies
+from .strategy.dict import DictStrategies
+from .strategy.set import SetStrategies
+from .strategy.type_conflict import TypeConflictStrategies
+from .strategy.fallback import FallbackStrategies
+
+
+class Merger(object):
+    """
+    :param type_strategies, List[Tuple]: a list of (Type, Strategy) pairs
+           that should be used against incoming types. For example: (dict, "override").
+    """
+
+    PROVIDED_TYPE_STRATEGIES = {
+        list: ListStrategies,
+        dict: DictStrategies,
+        set: SetStrategies,
+    }
+
+    def __init__(self, type_strategies, fallback_strategies, type_conflict_strategies):
+        self._fallback_strategy = FallbackStrategies(fallback_strategies)
+
+        expanded_type_strategies = []
+        for typ, strategy in type_strategies:
+            if typ in self.PROVIDED_TYPE_STRATEGIES:
+                strategy = self.PROVIDED_TYPE_STRATEGIES[typ](strategy)
+            expanded_type_strategies.append((typ, strategy))
+        self._type_strategies = expanded_type_strategies
+
+        self._type_conflict_strategy = TypeConflictStrategies(type_conflict_strategies)
+
+    def merge(self, base, nxt):
+        return self.value_strategy([], base, nxt)
+
+    def type_conflict_strategy(self, *args):
+        return self._type_conflict_strategy(self, *args)
+
+    def value_strategy(self, path, base, nxt):
+        if not (isinstance(base, type(nxt)) or isinstance(nxt, type(base))):
+            return self.type_conflict_strategy(path, base, nxt)
+        for typ, strategy in self._type_strategies:
+            if isinstance(nxt, typ):
+                return strategy(self, path, base, nxt)
+        return self._fallback_strategy(self, path, base, nxt)

Some files were not shown because too many files changed in this diff