custom patch method to support django-reversion
425446
def patch(self, request, *args, **kwargs):
        
        with reversion.create_revision():
            reversion.set_user(request.user)
            reversion.set_comment('changed through the RESTful API from ip %s' % request.META['REMOTE_ADDR'])
            kwargs['partial'] = True
            return self.update(request, *args, **kwargs)
508207
def reverse(self):
        
        tmp_list = RedisList(
            randint(0, 100000000), prefix=self.key_prefix,
            client=self._client, serializer=self.serializer,
            serialized=self.serialized)
        cursor = '0'
        count = 1000
        start = (-1 * count)
        stop = -1
        _loads = self._loads
        while cursor:
            cursor = self._client.lrange(self.key_prefix, start, stop)
            if cursor:
                tmp_list.extend(map(_loads, reversed(cursor)))
            start -= count
            stop -= count
        self._client.rename(tmp_list.key_prefix, self.key_prefix)
        tmp_list.clear()
255514
def reverse(self, viewname, args=None, kwargs=None):
        
        # TODO: django-fluent-pages needs a public API to get the current page.
        current_page = getattr(self.request, '_current_fluent_page', None)
        return blog_reverse(viewname, args=args, kwargs=kwargs, current_page=current_page)
500777
def opt_restore(prefix, opts):
    

    return {prefix + name: value for name, value in opts.items()}
531999
def patch_constructor(model):
    
    old_init = model.__init__

    def new_init(self, *args, **kwargs):
        self._mt_init = True
        populate_translation_fields(self.__class__, kwargs)
        for key, val in list(kwargs.items()):
            new_key = rewrite_lookup_key(model, key)
            # Old key is intentionally left in case old_init wants to play with it
            kwargs.setdefault(new_key, val)
        old_init(self, *args, **kwargs)
    model.__init__ = new_init
656149
def monkey_patch_bson(bson=None):
  ''''''
  if not bson:
    import bson

  if not hasattr(bson, 'loads'):
    bson.loads = lambda bsondoc: bson.BSON(bsondoc).decode()

  if not hasattr(bson, 'dumps'):
    bson.dumps = lambda document: bson.BSON.encode(document)
160526
def _FetchRemapping(type_name, mapping_type, python_name=None, json_name=None,
                    mappings=None):
    """"""
    if python_name and json_name:
        raise exceptions.InvalidDataError(
            'Cannot specify both python_name and json_name '
            'for %s remapping' % mapping_type)
    if not (python_name or json_name):
        raise exceptions.InvalidDataError(
            'Must specify either python_name or json_name for %s remapping' % (
                mapping_type,))
    field_remappings = mappings.get(type_name, {})
    if field_remappings:
        if python_name:
            return field_remappings.get(python_name)
        elif json_name:
            if json_name in list(field_remappings.values()):
                return [k for k in field_remappings
                        if field_remappings[k] == json_name][0]
    return None
126467
function patchHooks(hooks) {
  var original = {};
  var restore;

  hookTypes.map(function(key) {
    original[key] = global[key];

    global[key] = function(title, fn) {
      // Hooks accept an optional title, though they're
      // ignored here for simplicity
      if (!fn) fn = title;
      hooks[key] = createWrapper(fn);
    };
  });

  restore = function() {
    hookTypes.forEach(function(key) {
      global[key] = original[key];
    });
  };

  return restore;
}
393853
def patched_model():
    """"""

    patched = ('__reduce__', '__getstate__', '__setstate__')
    originals = {}
    for patch in patched:
        try:
            originals[patch] = getattr(models.Model, patch)
        except:
            pass

    try:
        # Patch various parts of the model
        models.Model.__reduce__ = _reduce
        try:
            del models.Model.__getstate__
        except:
            pass
        try:
            del models.Model.__setstate__
        except:  # pragma: no cover
            pass

        yield

    finally:
        # Restore the model
        for patch in patched:
            try:
                setattr(models.Model, patch, originals[patch])
            except KeyError:
                try:
                    delattr(models.Model, patch)
                except AttributeError:
                    pass
532455
def patched_function(self, *args, **kwargs):
        
        self.validate(*args, **kwargs)
        return self.function(*args, **kwargs)
866283
def js_reverse_inline(context):
    
    if 'request' in context:
        default_urlresolver = get_resolver(getattr(context['request'], 'urlconf', None))
    else:
        default_urlresolver = get_resolver(None)
    return mark_safe(generate_js(default_urlresolver))
337595
def monkey_patch_override_method(klass):
    
    def perform_override(override_fn):
        fn_name = override_fn.__name__
        original_fn_name = '_original_' + fn_name
        # Override class method, if it hasn't already been done
        if not hasattr(klass, original_fn_name):
            original_fn = getattr(klass, fn_name)
            setattr(klass, original_fn_name, original_fn)
            setattr(klass, fn_name, override_fn)
    return perform_override
1314890
def applied_patches_inverse
      result = {}
      applied_patches.each do |name, sig|
        raise DuplicateError, [result[sig], name] if result.key?(sig)
        result[sig] = name
      end
      result
    end
560114
def batch_reverse(self, points, **kwargs):
        
        fields = ",".join(kwargs.pop("fields", []))
        response = self._req(
            "post", verb="reverse", params={"fields": fields}, data=json_points(points)
        )
        if response.status_code != 200:
            return error_response(response)

        logger.debug(response)
        return LocationCollection(response.json()["results"])
1103549
def patch(self, instance, errors):
        
        if errors:
            return self.errors(errors)
        return self.updated(instance)
763854
function patch(patchURI, patch, callback) {

  util.patch(patchURI, patch, function(err, res) {
    if (err) {
      callback(err)
    } else {
      callback(null, res)
    }
  })
}
552443
def _reverse(viewname, args=None, kwargs=None, request=None, format=None, **extra):
    
    if format is not None:
        kwargs = kwargs or {}
        kwargs['format'] = format
    url = django_reverse(viewname, args=args, kwargs=kwargs, **extra)
    if request:
        return request.build_absolute_uri(url)
    return url