default CouchDB _design/_aut document
767675
function (newDoc, oldDoc, userCtx, secObj) {
    if (newDoc._deleted === true) {
      // allow deletes by admins and matching users
      // without checking the other fields
      if (userCtx.roles.indexOf('_admin') !== -1) {
        return;
      }
      throw ({forbidden: 'Only admins may delete other user docs.'});
    }

    var is_server_or_database_admin = function (userCtx, secObj) {
      // see if the user is a server admin
      if (userCtx.roles.indexOf('_admin') !== -1) {
        return true; // a server admin
      }

      // see if the user is a database admin specified by name
      if (secObj && secObj.admins && secObj.admins.names) {
        if (secObj.admins.names.indexOf(userCtx.name) !== -1) {
          return true; // database admin
        }
      }

      // see if the user is a database admin specified by role
      if (secObj && secObj.admins && secObj.admins.roles) {
        var db_roles = secObj.admins.roles;
        var idx;
        for (idx = 0; idx < userCtx.roles.length; idx++) {
          var user_role = userCtx.roles[idx];
          if (db_roles.indexOf(user_role) !== -1) {
            return true; // role matches!
          }
        }
      }

      return false; // default to no admin
    };

    if (!is_server_or_database_admin(userCtx, secObj)) {
      throw ({
        forbidden: 'You may only read documents.'
      });
    }
  }
128663
def doc():
    """"""
    kwdb = current_app.kwdb

    libraries = get_collections(kwdb, libtype="library")
    resource_files = get_collections(kwdb, libtype="resource")
    hierarchy = get_navpanel_data(kwdb)

    return flask.render_template("home.html",
                                 data={"libraries": libraries,
                                       "version": __version__,
                                       "libdoc": None,
                                       "hierarchy": hierarchy,
                                       "resource_files": resource_files
                                   })
164575
def get_default_config(self):
        
        config = super(MonitCollector, self).get_default_config()
        config.update({
            'host':         '127.0.0.1',
            'port':         2812,
            'user':         'monit',
            'passwd':       'monit',
            'path':         'monit',
            'byte_unit':    ['byte'],
            'send_totals':  False,
        })
        return config
579783
function (since, callback) {
      if (opts.aborted) {
        return;
      }
      params.since = since;
      // "since" can be any kind of json object in Coudant/CouchDB 2.x
      /* istanbul ignore next */
      if (typeof params.since === "object") {
        params.since = JSON.stringify(params.since);
      }

      if (opts.descending) {
        if (limit) {
          params.limit = leftToFetch;
        }
      } else {
        params.limit = (!limit || leftToFetch > batchSize) ?
          batchSize : leftToFetch;
      }

      // Set the options for the ajax call
      var xhrOpts = {
        method: method,
        url: genDBUrl(host, '_changes' + paramsToStr(params)),
        timeout: opts.timeout,
        body: body
      };
      lastFetchedSeq = since;

      /* istanbul ignore if */
      if (opts.aborted) {
        return;
      }

      // Get the changes
      setup().then(function () {
        xhr = ajax(opts, xhrOpts, callback);
      }).catch(callback);
    }
1372892
def _default_request_kwargs(self):
        """"""
        defaults = copy.deepcopy(super(Acls, self)._default_request_kwargs)
        defaults.setdefault('headers', {}).update({
            'X-Auth-Token': self._client.auth._token
        })
        return defaults
1148659
def url(self):
        
        if self._partition_key:
            base_url = self.design_doc.document_partition_url(
                self._partition_key)
        else:
            base_url = self.design_doc.document_url

        return '/'.join((
            base_url,
            '_view',
            self.view_name
        ))
1050448
def view_on db, view_name, query = {}, &block
      raise ArgumentError, "View query options must be set as symbols!" if query.keys.find{|k| k.is_a?(String)}
      view_name = view_name.to_s
      view_slug = "#{name}/#{view_name}"
      # Set the default query options
      query = view_defaults(view_name).merge(query)
      # Ensure reduce is set if dealing with a reduceable view
      # This is a requirement of CouchDB.
      query[:reduce] ||= false if can_reduce_view?(view_name)
      db.view(view_slug, query, &block)
    end
66714
def configure_mongodb(self):
        
        self._display_info("Trying default configuration")

        host = "localhost"
        database_name = "INGInious"

        should_ask = True
        if self.try_mongodb_opts(host, database_name):
            should_ask = self._ask_boolean(
                "Successfully connected to MongoDB. Do you want to edit the configuration anyway?", False)
        else:
            self._display_info("Cannot guess configuration for MongoDB.")

        while should_ask:
            self._display_question(
                "Please enter the MongoDB host. If you need to enter a password, here is the syntax:")
            self._display_question("mongodb://USERNAME:PASSWORD@HOST:PORT/AUTHENTIFICATION_DATABASE")
            host = self._ask_with_default("MongoDB host", host)
            database_name = self._ask_with_default("Database name", database_name)
            if not self.try_mongodb_opts(host, database_name):
                if self._ask_boolean("Cannot connect to MongoDB. Would you like to continue anyway?", False):
                    break
            else:
                self._display_info("Successfully connected to MongoDB")
                break

        return {"mongo_opt": {"host": host, "database": database_name}}
1061729
def default(self):
        """"""

        import ambry.bundle.default_files as df
        import os

        path = os.path.join(os.path.dirname(df.__file__), self.file_name)

        if six.PY2:
            with open(path, 'rb') as f:
                return f.read()
        else:
            # py3
            with open(path, 'rt', encoding='utf-8') as f:
                return f.read()
1046226
def curl_couchdb(url, method='GET', base_url=BASE_URL, data=None):
    '''
        
    '''
    (username, password) = get_admin()
    if username is None:
        auth = None
    else:
        auth = (username, password)

    if method == 'PUT':
        req = requests.put('{}{}'.format(base_url, url), auth=auth, data=data)
    elif method == 'DELETE':
        req = requests.delete('{}{}'.format(base_url, url), auth=auth)
    else:
        req = requests.get('{}{}'.format(base_url, url), auth=auth)

    if req.status_code not in [200, 201]:
        raise HTTPError('{}: {}'.format(req.status_code, req.text))
    return req
95632
def default_formats(self, path):
        """"""
        formats = long_form_multiple_formats(self.default_jupytext_formats)
        for fmt in formats:
            try:
                base_path(path, fmt)
                return self.default_jupytext_formats
            except InconsistentPath:
                continue

        return None
1043027
def setdefault(obj, field, default):
    """"""
    setattr(obj, field, getattr(obj, field, default))
229573
def get_object_defaults(object_schema):
    
    default = {}
    for k, schema in object_schema.get('properties', {}).items():

        if schema.get('type') == 'object':
            if 'default' in schema:
                default[k] = schema['default']

            try:
                object_defaults = get_object_defaults(schema)
            except NoObjectDefaults:
                if 'default' not in schema:
                    raise NoObjectDefaults
            else:
                if 'default' not in schema:
                    default[k] = {}

                default[k].update(object_defaults)
        else:
            if 'default' in schema:
                default[k] = schema['default']

    if default:
        return default

    raise NoObjectDefaults
75730
function defaultAuthProviders(bson) {
  return {
    mongocr: new MongoCR(bson),
    x509: new X509(bson),
    plain: new Plain(bson),
    gssapi: new GSSAPI(bson),
    sspi: new SSPI(bson),
    'scram-sha-1': new ScramSHA1(bson),
    'scram-sha-256': new ScramSHA256(bson)
  };
}
616248
function pageDefaults() {
  return {
    path: canonicalPath(),
    referrer: document.referrer,
    search: location.search,
    title: document.title,
    url: canonicalUrl(location.search)
  };
}
1202337
def create_default_links(self):
        """"""
        self._plm.manage_aldb_record(0x40, 0xe2, 0x00, self.address,
                                     self.cat, self.subcat, self.product_key)
        self.manage_aldb_record(0x41, 0xa2, 0x00, self._plm.address,
                                self._plm.cat, self._plm.subcat,
                                self._plm.product_key)
        for link in self._stateList:
            state = self._stateList[link]
            if state.is_responder:
                # IM is controller
                self._plm.manage_aldb_record(0x40, 0xe2, link, self._address,
                                             0x00, 0x00, 0x00)
                # Device is responder
                self.manage_aldb_record(0x41, 0xa2, link, self._plm.address,
                                        state.linkdata1, state.linkdata2,
                                        state.linkdata3)
            if state.is_controller:
                # IM is responder
                self._plm.manage_aldb_record(0x41, 0xa2, link, self._address,
                                             0x00, 0x00, 0x00)
                # Device is controller
                self.manage_aldb_record(0x40, 0xe2, link, self._plm.address,
                                        0x00, 0x00, 0x00)
        self.read_aldb()
761915
def sphinx(self):
        """"""
        if callable(self.default):
            default_val = self.default()
            default_str = 'new instance of {}'.format(
                default_val.__class__.__name__
            )
        else:
            default_val = self.default
            default_str = '{}'.format(self.default)
        try:
            if default_val is None or default_val is undefined:
                default_str = ''
            elif len(default_val) == 0:                                        #pylint: disable=len-as-condition
                default_str = ''
            else:
                default_str = ', Default: {}'.format(default_str)
        except TypeError:
            default_str = ', Default: {}'.format(default_str)

        prop_doc = super(Property, self).sphinx()
        return '{doc}{default}'.format(doc=prop_doc, default=default_str)