How to use the pydash.merge function in pydash

To help you get started, we’ve selected a few pydash examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dgilland / pydash / tests / test_objects.py View on Github external
def test_merge_no_link_dict():
    case1 = {'foo': {'bar': None}}
    case2 = {'foo': {'bar': False}}
    result = _.merge({}, case1, case2)
    result['foo']['bar'] = True

    assert case1 == {'foo': {'bar': None}}
    assert case2 == {'foo': {'bar': False}}
github sci-bots / microdrop / microdrop / bin / config.py View on Github external
# Create dictionary structure containing only the specified key
                # and value.
                nested_value = pydash.set_({}, key, new_value)
                # Merge nested value into existing configuration structure.
                pydash.merge(config.data, nested_value)
            else:
                # Action is a list action.

                if config_value is None:
                    # Create dictionary structure containing only empty list for
                    # specified key.
                    config_value = []
                    nested_value = pydash.set_({}, key, config_value)
                    # Merge nested value into existing configuration structure.
                    pydash.merge(config.data, nested_value)
                elif not isinstance(config_value, list):
                    print >> sys.stderr, 'Value at %s is not a list.' % key
                    raise SystemExit(1)

                if new_value in config_value:
                    # Remove value even if we are appending or prepending to
                    # avoid duplicate values.
                    config_value.remove(new_value)

                if args.append:
                    config_value.append(new_value)
                elif args.prepend:
                    config_value.insert(0, new_value)
        elif action == 'remove_key':
            key = getattr(args, action)
github sci-bots / microdrop / microdrop / bin / config.py View on Github external
if action in ('append', 'prepend', 'set', 'remove'):
            # Unpack key and new value.
            key, new_value = getattr(args, action)

            # Look up existing value.
            config_value = pydash.get(config.data, key)

            if action == 'set':
                # Set a key to a string value.

                # Create dictionary structure containing only the specified key
                # and value.
                nested_value = pydash.set_({}, key, new_value)
                # Merge nested value into existing configuration structure.
                pydash.merge(config.data, nested_value)
            else:
                # Action is a list action.

                if config_value is None:
                    # Create dictionary structure containing only empty list for
                    # specified key.
                    config_value = []
                    nested_value = pydash.set_({}, key, config_value)
                    # Merge nested value into existing configuration structure.
                    pydash.merge(config.data, nested_value)
                elif not isinstance(config_value, list):
                    print >> sys.stderr, 'Value at %s is not a list.' % key
                    raise SystemExit(1)

                if new_value in config_value:
                    # Remove value even if we are appending or prepending to
github mmcloughlin / finsky / finsky / client.py View on Github external
def request(self, endpoint, **kwargs):
        request_options_common = {
                'url': BASE_URL + endpoint,
                'headers': {
                    'Accept-Language': self.language,
                    'Authorization': 'GoogleLogin auth=' + self.auth_token,
                    'X-DFE-Device-Id': self.android_id,
                    'X-DFE-Client-Id': CLIENT_ID,
                    'User-Agent': self.user_agent(),
                    },
                'verify': False,
                }
        options = pydash.merge({},
                               self.request_options_base,
                               request_options_common,
                               kwargs,
                               )
        r = requests.get(**options)
        r.raise_for_status()
        data = r.content
        message = finsky.protos.response_pb2.ResponseWrapper.FromString(data)
        return message
github thealphadollar / Nephos / nephos / load_config.py View on Github external
Loads configurations from /config/ (Path relative to __nephos_dir__)

        Returns
        -------

        """

        # loading configuration
        self.logging_config = self.load_data("logging.yaml", True)
        self.maintenance_config = self.load_data("maintenance.yaml", True)
        self.modules_config = self.load_data("modules.yaml", True)

        # updating configuration as needed with manual data / environment variables
        config_update = list(self._config_update())
        pydash.merge(self.logging_config, config_update[0])
        pydash.merge(self.modules_config, config_update[1])
github mmcloughlin / finsky / finsky / client.py View on Github external
"""
        Download file at the given URL with an authentication cookie specified
        in the cookies dictionary. The authentication cookie is typically
        called "MarketDA", but the name is specified in the delivery response,
        so could in principle change.
        """
        download_request_options = {
                'url': url,
                'headers': {
                    'User-Agent': self.download_user_agent(),
                    'Accept-Encoding':  'identity',
                    },
                'cookies': cookies,
                'verify': False,
                }
        options = pydash.merge({},
                               self.request_options_base,
                               download_request_options,
                               )
        r = requests.get(**options)
        r.raise_for_status()
        return r.content

pydash

The kitchen sink of Python utility libraries for doing "stuff" in a functional way. Based on the Lo-Dash Javascript library.

MIT
Latest version published 4 days ago

Package Health Score

90 / 100
Full package analysis