Create a container.

    Reports extra keys as well as missing ones.
    Thanks to habnabit for the idea!
339165
def make(cls, **kwargs):
    
    cls_attrs = {f.name: f for f in attr.fields(cls)}

    unknown = {k: v for k, v in kwargs.items() if k not in cls_attrs}
    if len(unknown) > 0:
        _LOGGER.warning(
            "Got unknowns for %s: %s - please create an issue!", cls.__name__, unknown
        )

    missing = [k for k in cls_attrs if k not in kwargs]

    data = {k: v for k, v in kwargs.items() if k in cls_attrs}

    # initialize missing values to avoid passing default=None
    # for the attrs attribute definitions
    for m in missing:
        default = cls_attrs[m].default
        if isinstance(default, attr.Factory):
            if not default.takes_self:
                data[m] = default.factory()
            else:
                raise NotImplementedError
        else:
            _LOGGER.debug("Missing key %s with no default for %s", m, cls.__name__)
            data[m] = None

    # initialize and store raw data for debug purposes
    inst = cls(**data)
    setattr(inst, "raw", kwargs)

    return inst
440625
function addToContainer(container, key, val) {
  if (container instanceof Array) {
    container.push(val);
  } else if (container instanceof Object) {
    container[key] = val;
  }
}
528326
def extra(self):
        
        return dict([(key, val) for key, val in
                     self._dict.items() if key not in self.c_param])
59280
private HashMap<SecretKey, SecureContainer> retrieveContainers() {
        HashMap<SecretKey, SecureContainer> containers = null;
        String workingDir = getMain().getFileSystemManager().getSystemDataLocation().getAbsolutePath();
        final String containerFile = workingDir + File.separator
                + "containers.ser";
        try {
            FileInputStream fileIn = new FileInputStream(containerFile);
            ObjectInputStream in = new ObjectInputStream(fileIn);
            Object o = in.readObject();
            if (o instanceof HashMap) {
                containers = (HashMap) o;
            }
            in.close();
            fileIn.close();
        } catch (FileNotFoundException e) {
            return null;
        } catch(IOException | ClassNotFoundException e) {
            logger.error("Unable to retrieve containers from file", e);
        }

        return containers;
    }
14508
def file_items(container, iterable):
    

    # container._value = copy(iterable)

    container.nodes = set()
    container.variables = set()
    container.deterministics = set()
    container.stochastics = set()
    container.potentials = set()
    container.observed_stochastics = set()

    # containers needs to be a list to hold unhashable items.
    container.containers = []

    i = -1

    for item in iterable:

        # If this is a dictionary, switch from key to item.
        if isinstance(iterable, (dict, dict_proxy_type)):
            key = item
            item = iterable[key]
        # Item counter
        else:
            i += 1

        # If the item isn't iterable, file it away.
        if isinstance(item, Variable):
            container.variables.add(item)
            if isinstance(item, StochasticBase):
                if item.observed or not getattr(item, 'mask', None) is None:
                    container.observed_stochastics.add(item)
                if not item.observed:
                    container.stochastics.add(item)
            elif isinstance(item, DeterministicBase):
                container.deterministics.add(item)
        elif isinstance(item, PotentialBase):
            container.potentials.add(item)

        elif isinstance(item, ContainerBase):
            container.assimilate(item)
            container.containers.append(item)

        # Wrap internal containers
        elif hasattr(item, '__iter__'):

            # If this is a non-object-valued ndarray, don't container-ize it.
            if isinstance(item, ndarray):
                if item.dtype != dtype('object'):
                    continue

            # If the item is iterable, wrap it in a container. Replace the item
            # with the wrapped version.
            try:
                new_container = Container(item)
            except:
                continue

            # Update all of container's variables, potentials, etc. with the new wrapped
            # iterable's. This process recursively unpacks nested iterables.
            container.assimilate(new_container)

            if isinstance(container, dict):
                container.replace(key, new_container)
            elif isinstance(container, tuple):
                return container[:i] + (new_container,) + container[i + 1:]
            else:
                container.replace(item, new_container, i)

    container.nodes = container.potentials | container.variables

    # 'Freeze' markov blanket, moral neighbors, coparents of all constituent stochastics
    # for future use
    for attr in ['moral_neighbors', 'markov_blanket', 'coparents']:
        setattr(container, attr, {})
    for s in container.stochastics:
        for attr in ['moral_neighbors', 'markov_blanket', 'coparents']:
            getattr(container, attr)[s] = getattr(s, attr)
286505
def create_container(self, conf, detach, tty):
        """"""

        name = conf.name
        image_name = conf.image_name
        if conf.tag is not NotSpecified:
            image_name = conf.image_name_with_tag
        container_name = conf.container_name

        with conf.assumed_role():
            env = dict(e.pair for e in conf.env)

        binds = conf.volumes.binds
        command = conf.formatted_command
        volume_names = conf.volumes.volume_names
        volumes_from = list(conf.volumes.share_with_names)
        no_tty_option = conf.no_tty_option

        ports = [p.container_port.port_pair for p in conf.ports]
        port_bindings = self.exposed(conf.ports)

        uncreated = []
        for name in binds:
            if not os.path.exists(name):
                log.info("Making volume for mounting\tvolume=%s", name)
                try:
                    os.makedirs(name)
                except OSError as error:
                    uncreated.append((name, error))
        if uncreated:
            raise BadOption("Failed to create some volumes on the host", uncreated=uncreated)

        log.info("Creating container from %s\timage=%s\tcontainer_name=%s\ttty=%s", image_name, name, container_name, tty)
        if binds:
            log.info("\tUsing volumes\tvolumes=%s", volume_names)
        if env:
            log.info("\tUsing environment\tenv=%s", sorted(env.keys()))
        if ports:
            log.info("\tUsing ports\tports=%s", ports)
        if port_bindings:
            log.info("\tPort bindings: %s", port_bindings)
        if volumes_from:
            log.info("\tVolumes from: %s", volumes_from)

        host_config = conf.harpoon.docker_api.create_host_config(
              binds = binds
            , volumes_from = volumes_from
            , port_bindings = port_bindings

            , devices = conf.devices
            , lxc_conf = conf.lxc_conf
            , privileged = conf.privileged
            , restart_policy = conf.restart_policy

            , dns = conf.network.dns
            , dns_search = conf.network.dns_search
            , extra_hosts = conf.network.extra_hosts
            , network_mode = conf.network.network_mode
            , publish_all_ports = conf.network.publish_all_ports

            , cap_add = conf.cpu.cap_add
            , cap_drop = conf.cpu.cap_drop
            , mem_limit = conf.cpu.mem_limit
            , cpu_shares = conf.cpu.cpu_shares
            , cpuset_cpus = conf.cpu.cpuset_cpus
            , cpuset_mems = conf.cpu.cpuset_mems
            , memswap_limit = conf.cpu.memswap_limit

            , ulimits = conf.ulimits
            , read_only = conf.read_only_rootfs
            , log_config = conf.log_config
            , security_opt = conf.security_opt

            , **conf.other_options.host_config
            )

        container_id = conf.harpoon.docker_api.create_container(image_name
            , name=container_name
            , detach=detach
            , command=command
            , volumes=volume_names
            , environment=env

            , tty = False if no_tty_option else tty
            , user = conf.user
            , ports = ports
            , stdin_open = tty

            , hostname = conf.network.hostname
            , domainname = conf.network.domainname
            , network_disabled = conf.network.disabled

            , host_config = host_config

            , **conf.other_options.create
            )

        if isinstance(container_id, dict):
            if "errorDetail" in container_id:
                raise BadImage("Failed to create container", image=name, error=container_id["errorDetail"])
            container_id = container_id["Id"]

        return container_id
334419
def add_keys(*additional_keys)
      additional_keys = additional_keys.flatten.compact
      @opts[:keys] ||= []
      @opts[:keys] += additional_keys
      @opts[:keys].uniq!
      @boxes.each do |box|
        box.add_keys *additional_keys
      end
      self
    end
83321
def unhandled_keys(self, size, key):
        
        if key == " ":
            if not self.flagged:
                self.display.new_files.append(self.get_node().get_value())
            else:
                self.display.new_files.remove(self.get_node().get_value())
            self.flagged = not self.flagged
            self.update_w()
            self.display.update_status()
        else:
            return key
1028447
def _construct_new_key(name, units=None):
    """"""
    to_replace = ["/", "\\", "*", "^", "#", " ", "\n", "\t", ",", ".", ")", "(", "'", "`", "-"]
    to_remove = ["$", "{", "}"]

    cat = name
    if units:
        cat = "_".join([name, units])
    for c in to_replace:
       cat = cat.replace(c, "_")
    for c in to_remove:
       cat = cat.replace(c, "")

    cat = re.sub('_+','_', cat)

    return cat
1154553
def missing_hash_entries(the_hash, *keys)
    # Support passing either an Array or multiple args:
    if keys.size == 1 && keys.first.is_a?(Array)
      keys = keys.first
    end

    keys - the_hash.keys
  end
761395
def include(self, *keys):
        
        if len(keys) == 1 and isinstance(keys[0], (list, tuple)):
            keys = keys[0]
        self._include += keys
        return self
1337950
def add(self, key, val):
        
        key_lower = key.lower()
        new_vals = [key, val]
        # Keep the common case aka no item present as fast as possible
        vals = self._container.setdefault(key_lower, new_vals)
        if new_vals is not vals:
            vals.append(val)
335038
def _add_to_dict(t, container, name, value):
    

    if name in container:
        raise Exception("%s '%s' already exists" % (t, name))
    else:
        container[name] = value
34432
protected function createContainer() {

		\Pressbooks\Utility\put_contents(
			$this->tmpDir . '/mimetype',
			utf8_decode( 'application/epub+zip' )
		);

		mkdir( $this->tmpDir . '/META-INF' );
		mkdir( $this->tmpDir . '/OEBPS' );
		mkdir( $this->tmpDir . '/OEBPS/assets' );

		\Pressbooks\Utility\put_contents(
			$this->tmpDir . '/META-INF/container.xml',
			$this->loadTemplate( $this->dir . '/templates/epub201/container.php' )
		);

		\Pressbooks\Utility\put_contents(
			$this->tmpDir . '/META-INF/com.apple.ibooks.display-options.xml',
			$this->loadTemplate( $this->dir . '/templates/epub201/ibooks.php' )
		);

	}
662814
def calculate_extra_keys(self, buffer):
        
        extraBs = len(self.inputStack) - len(buffer)
        if extraBs > 0:
            extraKeys = ''.join(self.inputStack[len(buffer)])
        else:
            extraBs = 0
            extraKeys = ''
        return extraBs, extraKeys
655715
def add_key(self, key, first=False):
        
        if first:
            self.keys = [key] + self.keys
        else:
            self.keys.append(key)
        if isinstance(key, VSpaceKey):
            self.space = key
1074742
def get_extra_keys(schema, data)
      extra = data.keys - schema.properties.keys

      if schema.pattern_properties
        schema.pattern_properties.keys.each do |pattern|
          extra -= extra.select { |k| k =~ pattern }
        end
      end

      extra
    end