given a list of updates create a copy with the right update for HTML
427005
function fixUpdates(updates) {
  for (var
    update,
    i = 0,
    length = updates.length,
    out = [];
    i < length; i++
  ) {
    update = updates[i];
    out.push(update === getUpdateForHTML ? update.call(this) : update);
  }
  return out;
}
205636
def update(self, query, doc, *args, **kwargs):
        """"""
        if isinstance(doc, list):
            return [
                self.update_one(query, item, *args, **kwargs)
                for item in doc
            ]
        else:
            return self.update_one(query, doc, *args, **kwargs)
429090
def update(d, e):
    """"""
    res = copy.copy(d)
    res.update(e)
    return res
836870
def copy_and_update(dictionary, update):
    """"""
    newdict = dictionary.copy()
    newdict.update(update)
    return newdict
489727
def dict_update_overwrite_check(base, fresh):
    

    result = [
        (key, base[key], fresh[key])
        for key in set(base.keys()) & set(fresh.keys())
        if base[key] != fresh[key]
    ]
    base.update(fresh)
    return result
1021729
def print_new_versions(strict=False):
    """"""
    new_updates = []
    same_updates = []
    for req in everything_in(all_reqs):
        new_versions = []
        same_versions = []
        for ver_str in all_versions(req):
            if newer(ver_str_to_tuple(ver_str), min_versions[req], strict=True):
                new_versions.append(ver_str)
            elif not strict and newer(ver_str_to_tuple(ver_str), min_versions[req]):
                same_versions.append(ver_str)
        update_str = req + ": " + ver_tuple_to_str(min_versions[req]) + " -> " + ", ".join(
            new_versions + ["(" + v + ")" for v in same_versions],
        )
        if new_versions:
            new_updates.append(update_str)
        elif same_versions:
            same_updates.append(update_str)
    print("\n".join(new_updates + same_updates))
183645
def create_update():
    
    update = upkey("update").setResultsName("action")
    returns, none, all_, updated, old, new = map(
        upkey, ["returns", "none", "all", "updated", "old", "new"]
    )
    return_ = returns + Group(
        none | (all_ + old) | (all_ + new) | (updated + old) | (updated + new)
    ).setResultsName("returns")
    return (
        update
        + table
        + update_expr
        + Optional(keys_in)
        + Optional(where)
        + Optional(using)
        + Optional(return_)
        + Optional(throttle)
    )
1022102
function copyReplace( src, dest, replacements ){

        if ( replacements ){
            var source = grunt.file.read( src );
            for ( var s in replacements ){
                var r = replacements[s];
                var re = new RegExp( s, "g" );
                source = source.replace( re, r );
            }
            grunt.file.write( dest, source );
        }
        else{
            grunt.file.copy( src, dest );
        }

	}
340193
def apply_update(self, doc, update_spec):
        """"""

        # Helper to cast a key for a list or dict, or raise ValueError
        def _convert_or_raise(container, key):
            if isinstance(container, dict):
                return key
            elif isinstance(container, list):
                return int(key)
            else:
                raise ValueError

        # Helper to retrieve (and/or create)
        # a dot-separated path within a document.
        def _retrieve_path(container, path, create=False):
            looking_at = container
            for part in path:
                if isinstance(looking_at, dict):
                    if create and part not in looking_at:
                        looking_at[part] = {}
                    looking_at = looking_at[part]
                elif isinstance(looking_at, list):
                    index = int(part)
                    # Do we need to create additional space in the array?
                    if create and len(looking_at) <= index:
                        # Fill buckets with None up to the index we need.
                        looking_at.extend([None] * (index - len(looking_at)))
                        # Bucket we need gets the empty dictionary.
                        looking_at.append({})
                    looking_at = looking_at[index]
                else:
                    raise ValueError
            return looking_at

        def _set_field(doc, to_set, value):
            if "." in to_set:
                path = to_set.split(".")
                where = _retrieve_path(doc, path[:-1], create=True)
                index = _convert_or_raise(where, path[-1])
                wl = len(where)
                if isinstance(where, list) and index >= wl:
                    where.extend([None] * (index + 1 - wl))
                where[index] = value
            else:
                doc[to_set] = value

        def _unset_field(doc, to_unset):
            try:
                if "." in to_unset:
                    path = to_unset.split(".")
                    where = _retrieve_path(doc, path[:-1])
                    index_or_key = _convert_or_raise(where, path[-1])
                    if isinstance(where, list):
                        # Unset an array element sets it to null.
                        where[index_or_key] = None
                    else:
                        # Unset field removes it entirely.
                        del where[index_or_key]
                else:
                    del doc[to_unset]
            except (KeyError, IndexError, ValueError):
                source_version = get_mininum_mongodb_version()
                if source_version is None or source_version.at_least(2, 6):
                    raise
                # Ignore unset errors since MongoDB 2.4 records invalid
                # $unsets in the oplog.
                LOG.warning(
                    "Could not unset field %r from document %r. "
                    "This may be normal when replicating from "
                    "MongoDB 2.4 or the destination could be out of "
                    "sync." % (to_unset, doc)
                )

        # wholesale document replacement
        if "$set" not in update_spec and "$unset" not in update_spec:
            # update spec contains the new document in its entirety
            return update_spec
        else:
            try:
                # $set
                for to_set in update_spec.get("$set", []):
                    value = update_spec["$set"][to_set]
                    _set_field(doc, to_set, value)

                # $unset
                for to_unset in update_spec.get("$unset", []):
                    _unset_field(doc, to_unset)

            except (KeyError, ValueError, AttributeError, IndexError):
                exc_t, exc_v, exc_tb = sys.exc_info()
                msg = "Cannot apply update %r to %r" % (update_spec, doc)
                raise UpdateDoesNotApply(msg).with_traceback(exc_tb)
            return doc
583797
function mergeForVersions(versions, opts) {
    opts = _.defaults(opts || {}, {
        includeTag: true
    });

    return _.chain(versions)
        .reduce(function(prev, version) {
            if (!version.notes) return prev;

            // Include tag as title
            if (opts.includeTag) {
                prev = prev + '## ' + version.tag + '\n';
            }

            // Include notes
            prev = prev + version.notes + '\n';

            // New lines
            if (opts.includeTag) {
                prev = prev + '\n';
            }

            return prev;
        }, '')
        .value();
}
1234279
def update_one(self, update):
        
        self.__bulk.add_update(self.__selector,
                               update, multi=False, upsert=True,
                               collation=self.__collation)
1248417
def patch(attrs, updates):
    """"""
    orig = {}
    for attr, value in updates:
        orig[attr] = attrs[attr]
        attrs[attr] = value
    return orig
378432
function (collection, settings, html, oldIndex, newIndex, oldKey, newKey) {
            var toReplace = new RegExp(pregQuote(settings.name_prefix + '[' + oldKey + ']'), 'g');
            var replaceWith = settings.name_prefix + '[' + newKey + ']';
            html = html.replace(toReplace, replaceWith);

            toReplace = new RegExp(pregQuote(collection.attr('id') + '_' + oldIndex), 'g');
            replaceWith = collection.attr('id') + '_' + newIndex;
            html = html.replace(toReplace, replaceWith);

            return html;
        }
756960
def update_file(filename, items):
    '''
    '''
    # TODO: Implement something in the templates to denote whether the value
    # being replaced is an XML attribute or a value. Perhaps move to dyanmic
    # XML tree building rather than string replacement.
    should_escape = filename.endswith('addon.xml')

    with open(filename, 'r') as inp:
        text = inp.read()

    for key, val in items.items():
        if should_escape:
            val = saxutils.quoteattr(val)
        text = text.replace('{%s}' % key, val)
    output = text

    with open(filename, 'w') as out:
        out.write(output)
472857
function ($ul, collection, updater, refresh) {
            var ul = ($ul.length ? $ul[0] : $ul);
            var i = 0;
            // var li = $ul.find('li');
            var li = ul.childNodes;

            // Update existing
            while (i < collection.length && i < li.length) {
                updater.setLi(li[i], collection[i]);
                ++i;
            }
            // Add new
            while (i < collection.length) {
                $(ul).append(updater.newLi(collection[i]));
                ++i;
            }
            // Remove extra
            var j = li.length - 1;
            while (j >= i) {
                ul.removeChild(li[j]);
                --j;
            }
            if (refresh !== false) {
                $(ul).listview('refresh');
            }
        }
181309
function replaceAt(items, item, index) {
  var copy = items.slice();
  copy.splice(index, 1, item);
  return copy;
}
1056681
function updateDOM(source,target,scope,actions,view=target,template=source) {
		Object.defineProperty(target,"view",{enumerable:false,configurable:true,writable:true,value:view});
		Object.assign(scope,{"$source":source,
												"$target":target,
												"$template":template.children ? (template.children.length> 1 ? template.children : template.children[0]) : template,
												"$view":view.children.length> 1 ? view.children : view.children[0]});
		// if source and target are text
		if(typeof(source)==="string") {
			const value = (resolve(source,scope,actions)+""),
					doc = new DOMParser().parseFromString(value, "text/html"),
		  		children = slice(doc.body.childNodes);
		  if(children.some(node => node.nodeType === 1)) {
		  	updateDOM(toVDOM(doc.body),doc.body,scope,actions,view,template);
		  	let parent;
		  	if(target.nodeType===3) {
			  	parent = target.parentElement;
			  	parent.removeChild(target);
		  	} else if(target.nodeType===1) {
		  		parent = target;
		  		while(parent.lastChild) parent.removeChild(parent.lastChild);
		  	}
		  	slice(doc.body.childNodes).forEach(child => parent.appendChild(child));
		  } else if(target.data!==value) {
		  	target.data = value;
		  }
		  return view;
		}
		target.view.template = target.view.innerHTML;
		// if tags aren't the same
		if(source.tagName!==target.tagName) {
			// replace the target with the source
			if(target.parentNode) {
				const el = document.createElement(source.tagName);
				target.parentNode.replaceChild(el,target);
				target = el;
			}
		}
		// loop through target attributes, remove where does not exist in source
			slice(target.attributes).forEach(attribute => source.attributes[attribute.name]!==null || target.removeAttribute(attribute.name));
			// loop through source attributes
			let directed;
			Object.keys(source.attributes).forEach(aname => {
				let value = source.attributes[aname],
				 type = typeof(value),
				 currentview = CURRENTVIEW;
				CURRENTVIEW = target;
				const dname = resolve(aname.split(":")[0],scope,actions),
					directive = directives[dname]||tlx.directives[dname];
				value = resolve(value,scope,actions);
				CURRENTVIEW = currentview;
				type = typeof(value);
				// replace different
				if(value==null) {
					target.removeAttribute(aname);
					delete target[aname];
				} else if(["boolean","number","string"].includes(type)) {
					if(value!==target.getAttribute(aname)) {
						try {
							target.setAttribute(aname,value);
							if(aname==="value") target.value = value;
						} catch(e) {
							; // just ignore, may be an attribute with an unresolved argument, e.g. t-bind:${aname}
						}
					}
				} else {
						const pname = toPropertyName(aname);
						if(value!==target[pname]) target[pname] = value;
				}
				if(directive) { 
					while(target.lastChild) target.removeChild(target.lastChild); 
					const render = (scope,actions) => {
						source.children.forEach(child => {
							if(typeof(child)==="string") target.appendChild(new Text(child));
							else target.appendChild(document.createElement(child.tagName));
							updateDOM(child,target.lastChild,scope,actions,view,template);
						});
						return target;
					};
					const result = directive(value,scope,actions,render,{element:target,raw:aname,resolved:aname.indexOf("${")>=0 ? resolve(aname,scope,actions) : aname}),
						rtype = typeof(result);
					if(result==null) {
						target.parentElement.removeChild(target);
					} else if(rtype==="string") {
							directed = true;
							target.innerHTML = result;
					} else if(rtype==="object" && result instanceof HTMLElement) {
						directed = true;
						if(result!==target) target.parentElement.replaceChild(result,target);
					}
				}
			});
			if(!directed) {
				// remove extra children
				let remove = target.childNodes.length-source.children.length;
				while(remove-->0) !target.lastChild || target.removeChild(target.lastChild);
				// handle the child nodes
				let targets = slice(target.childNodes,0,source.children.length);
				if(targets.length===0) {
					const shadow = target.shadowRoot;
					if(shadow) targets = slice(shadow.childNodes,0,source.children.length);
				}
				source.children.forEach((child,i) => {
					// update if in range
					if(i<targets.length) {
						updateDOM(child,targets[i],scope,actions,view,template);
						return;
					}
					if(typeof(child)==="string") target.appendChild(new Text());
					else target.appendChild(document.createElement(child.tagName));
					updateDOM(child,target.lastChild,scope,actions,view,template);
				});
			}
		
		return view;
	}