Backport for Rails 3.2
965500
def using_single_table_inheritance?(klass, record)
      inheritance_column = klass.inheritance_column
      record[inheritance_column].present? && record.has_attribute?(inheritance_column)
    end
1019324
def rails_root
      if defined?(::Rails.root)
        return ::Rails.root.to_s if ::Rails.root
        raise "ERROR: Rails.root is nil!"
      end
      return RAILS_ROOT.to_s if defined?(RAILS_ROOT)
      nil
    end
171351
def list_backends(_):
    """"""
    backends = [b.__name__ for b in available_backends()]
    print('\n'.join(backends))
248907
def _load_backend(self, backend_uri, context):
        
        parsed = parse.urlparse(backend_uri)
        options = dict(parse.parse_qsl(parsed.query))

        try:
            backend = self._entry_points[self.BACKENDS_ENTRY_POINT][parsed.scheme].load()
        except KeyError:
            raise BackendNotFoundError(
                "The requested backend `%s` could not be found in the "
                "registered entry points. Perhaps you forgot to install the "
                "corresponding backend package?" % parsed.scheme
            )

        password = (parse.unquote(parsed.password)
                    if parsed.password
                    else parsed.password)

        return backend(
            username=parsed.username, password=password,
            hostname=parsed.hostname, port=parsed.port,
            path=parsed.path, options=options, context=context,
        )
656845
function RedisBackend(port, hostname, opts)
{
	if(!(this instanceof RedisBackend)){
		return new RedisBackend(port, hostname, opts);
	}

	opts = opts || {};
	port = port || 6379;
	hostname = hostname || 'localhost';

	this.redis = redis.createClient(port, hostname, opts);
	this.publish = redis.createClient(port, hostname, opts);

	this.prefix = opts.prefix + '';

	this.baseKey = baseKey(this.prefix);
}
1317392
def update_backends(cls, id_mapping, custom_trees, backend=None):
        
        backend = Store.current_backend if backend is None else backend
        # Update the custom option entries for the current backend
        Store.custom_options(backend=backend).update(custom_trees)

        # Propagate option ids for non-selected backends
        for b in Store.loaded_backends():
            if b == backend:
                continue
            backend_trees = Store._custom_options[b]
            for (old_id, new_id) in id_mapping:
                tree = backend_trees.get(old_id, None)
                if tree is not None:
                    backend_trees[new_id] = tree
1313784
def method_missing(name, *args)
      groupname = (args[0] or raise "Database configuration group not specified for #{name}")
      dbname = (args[1] or raise "Database entry name not specified for #{name}")
      n = name.to_s
      begin
        unseparated_yaml(n => self[groupname, dbname])
      rescue Bcdatabase::Error => e
        if ENV['RAILS_ENV'] == n
          raise e
        else
          # Not using that configuration right now, so return a dummy instead
          # of throwing an exception
          unseparated_yaml(n => { 'error' => e.message })
        end
      end
    end
1244518
def default_backend=(value)
      raise ArgumentError, "default_backend must be a symbol!" unless value.is_a? Symbol

      unless @backends.keys.include? value
        raise ArgumentError, "Unregistered backend cannot be set as default!"
      end

      @default_backend = value
    end
1255446
def backend_from_fobj(f):
    """"""
    if magic is None:
        warn("magic lib is not installed; assuming mime type %r" % (
            DEFAULT_MIME))
        return backend_from_mime(DEFAULT_MIME)
    else:
        offset = f.tell()
        try:
            f.seek(0)
            chunk = f.read(MAGIC_BUFFER_SIZE)
            mime = magic.from_buffer(chunk, mime=True)
            return backend_from_mime(mime)
        finally:
            f.seek(offset)
1043695
def get_handler(preferred_handler_name = nil)
      servers = %w[puma mongrel thin webrick]
      servers.unshift(preferred_handler_name) if preferred_handler_name
      
      handler = nil
      while((server_name = servers.shift) && handler === nil) do 
        begin
          handler = ::Rack::Handler.get(server_name)
        rescue LoadError
        rescue NameError
        end
      end
            
      if preferred_handler_name && server_name != preferred_handler_name
        puts "Handler '#{preferred_handler_name}' not found, using fallback ('#{server_name}')."
      end
      handler
    end
42733
def get_available_backends():
    
    backends = get_config().get('BACKENDS', {})

    if backends:
        return backends

    # Try to get backend settings from old style
    # POST_OFFICE = {
    #     'EMAIL_BACKEND': 'mybackend'
    # }
    backend = get_config().get('EMAIL_BACKEND')
    if backend:
        warnings.warn('Please use the new POST_OFFICE["BACKENDS"] settings',
                      DeprecationWarning)

        backends['default'] = backend
        return backends

    # Fall back to Django's EMAIL_BACKEND definition
    backends['default'] = getattr(
        settings, 'EMAIL_BACKEND',
        'django.core.mail.backends.smtp.EmailBackend')

    # If EMAIL_BACKEND is set to use PostOfficeBackend
    # and POST_OFFICE_BACKEND is not set, fall back to SMTP
    if 'post_office.EmailBackend' in backends['default']:
        backends['default'] = 'django.core.mail.backends.smtp.EmailBackend'

    return backends
1214675
def get_spam_checker(backend_path):
    
    try:
        backend_module = import_module(backend_path)
        backend = getattr(backend_module, 'backend')
    except (ImportError, AttributeError):
        warnings.warn('%s backend cannot be imported' % backend_path,
                      RuntimeWarning)
        backend = None
    except ImproperlyConfigured as e:
        warnings.warn(str(e), RuntimeWarning)
        backend = None

    return backend
1252362
def default_options
        if Object.const_defined?('Rails')
          {
            :file   => Rails.root.join('config', 'config.yml'),
            :reload => Rails.env.development?,
            :env    => Rails.env
          }
        else
          {
            :file   => File.expand_path("config.yml"),
            :reload => false,
            :env    => "development"
          }
        end
      end
1367974
def set_default_backend(name: str):
    """"""
    global _default_backend
    if name == "bokeh":
        raise RuntimeError("Support for bokeh has been discontinued. At some point, we may return to support holoviews.")
    if not name in backends:
        raise RuntimeError("Backend {0} is not supported and cannot be set as default.".format(name))
    _default_backend = name
1262055
def get_backend_cls(self):
        """"""
        backend_cls = self.backend_cls
        if not backend_cls or isinstance(backend_cls, basestring):
            backend_cls = get_backend_cls(backend_cls)
        return backend_cls
580464
def get_backend(name):
    """"""

    for backend in _BACKENDS:
        if backend.NAME == name:
            return backend
    raise KeyError("Backend %r not available" % name)
979791
def backend_from_fname(name):
    """"""
    ext = splitext(name)[1]

    try:
        mime = EXTS_TO_MIMETYPES[ext]

    except KeyError:
        try:
            f = open(name, 'rb')

        except IOError as e:
            # The file may not exist, we are being asked to determine it's type
            # from it's name. Other errors are unexpected.
            if e.errno != errno.ENOENT:
                raise

            # We will have to fall back upon the default backend.
            msg = "No handler for %r, defaulting to %r" % (ext, DEFAULT_MIME)
            if 'FULLTEXT_TESTING' in os.environ:
                warn(msg)
            else:
                LOGGER.debug(msg)

            mod_name = MIMETYPE_TO_BACKENDS[DEFAULT_MIME]

        else:
            with f:
                return backend_from_fobj(f)

    else:
        mod_name = MIMETYPE_TO_BACKENDS[mime]

    mod = import_mod(mod_name)
    return mod