<commit_before>// parseUri 1.2.2
// (c) <NAME> <<EMAIL>>
// MIT License
function parseUri (str) {
  var o = parseUri.options;
  var m = o.parser[o.strictMode ? "strict" : "loose"].exec(str);
  var uri = {};
  var i = 14;

  while (i--) uri[o.key[i]] = m[i] || "";

  uri[o.q.name] = {};
  uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
    if ($1) uri[o.q.name][$1] = $2;
  });

  return uri;
};

parseUri.options = {
  strictMode: false,
  key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
  q:   {
    name:   "queryKey",
    parser: /(?:^|&)([^&=]*)=?([^&]*)/g
  },
  parser: {
    strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
    loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
  }
};

function getHost(name) {
  if (/http:/.test(name)) {
    var uri = parseUri(name);
    uri.remote = true;
    uri.auth = {username: uri.user, password: uri.password};
    var parts = uri.path.replace(/(^\/|\/$)/g, '').split('/');
    uri.db = parts.pop();
    uri.path = parts.join('/');
    return uri;
  }
  return {host: '', path: '/', db: name, auth: false};
}

function genUrl(opts, path) {
  if (opts.remote) {
    var pathDel = !opts.path ? '' : '/';
    return opts.protocol + '://' + opts.host + ':' + opts.port + '/' + opts.path
      + pathDel + opts.db + '/' + path;
  }
  return '/' + opts.db + '/' + path;
};

function ajax(options, callback) {
  var defaults = {
    success: function (obj, _, xhr) {
      call(callback, null, obj, xhr);
    },
    error: function (err) {
      if (err) {
        call(callback, err);
      } else {
        call(callback, true);
      }
    },
    dataType: 'json',
    contentType: 'application/json'
  };
  options = $.extend({}, defaults, options);

  if (options.data && typeof options.data !== 'string') {
    options.data = JSON.stringify(options.data);
  }
  if (options.auth) {
    options.beforeSend = function(xhr) {
      var token = btoa(options.auth.username + ":" + options.auth.password);
      xhr.setRequestHeader("Authorization", "Basic " + token);
    }
  }
  return $.ajax(options);
};

var HttpPouch = function(opts, callback) {

  var host = getHost(opts.name);
  var db_url = genUrl(host, '');
  var api = {};

  ajax({auth: host.auth, type: 'PUT', url: db_url}, function(err, ret) {
    // the user may not have permission to PUT to a db url
    if (err && err.status === 401) {
      // test if the db already exists
      ajax({auth: host.auth, type: 'HEAD', url: db_url}, function (err, ret) {
        if (err) {
          // still can't access db
          call(callback, err);
        } else {
          // continue
          call(callback, null, api);
        }
      });
    } else if (!err || err.status === 412) {
      call(callback, null, api);
    }
  });

  api.id = function() {
    return genUrl(host, '');
  };

  api.info = function(callback) {
  };

  api.get = function(id, opts, callback) {
    if (opts instanceof Function) {
      callback = opts;
      opts = {};
    }
    var params = [];
    if (opts.revs) {
      params.push('revs=true');
    }
    if (opts.rev) {
      params.push('rev=' + opts.rev);
    }
    if (opts.conflicts) {
      params.push('conflicts=' + opts.conflicts);
    }
    params = params.join('&');
    params = params === '' ? '' : '?' + params;

    var options = {
      auth: host.auth,
      type: 'GET',
      url: genUrl(host, id + params)
    };

    if (/\//.test(id) && !/^_local/.test(id)) {
      options.dataType = false;
    }

    ajax(options, function(err, doc, xhr) {
      if (err) {
        return call(callback, Pouch.Errors.MISSING_DOC);
      }
      call(callback, null, doc, xhr);
    });
  };

  api.remove = function(doc, opts, callback) {
  };

  api.putAttachment = function(id, rev, doc, type, callback) {
    ajax({
      auth: host.auth,
      type:'PUT',
      url: genUrl(host, id) + '?rev=' + rev,
      headers: {'Content-Type': type},
      data: doc
    }, callback);
  };

  api.put = api.post = function(doc, opts, callback) {
    if (opts instanceof Function) {
      callback = opts;
      opts = {};
    }
    ajax({
      auth: host.auth,
      type:'PUT',
      url: genUrl(host, doc._id),
      data: doc
    }, callback);
  };

  api.bulkDocs = function(req, opts, callback) {
    if (opts instanceof Function) {
      callback = opts;
      opts = {};
    }
    if (typeof opts.new_edits !== 'undefined') {
      req.new_edits = opts.new_edits;
    }
    ajax({
      auth: host.auth,
      type:'POST',
      url: genUrl(host, '_bulk_docs'),
      data: req
    }, callback);
  };

  api.allDocs = function(opts, callback) {
    if (opts instanceof Function) {
      callback = opts;
      opts = {};
    }
    ajax({auth: host.auth, type:'GET', url: genUrl(host, '_all_docs')}, callback);
  };<commit_msg>Added info + remove support for the http adapter (and fixed post vs put)<commit_after>// parseUri 1.2.2
// (c) <NAME> <<EMAIL>>
// MIT License
function parseUri (str) {
  var o = parseUri.options;
  var m = o.parser[o.strictMode ? "strict" : "loose"].exec(str);
  var uri = {};
  var i = 14;

  while (i--) uri[o.key[i]] = m[i] || "";

  uri[o.q.name] = {};
  uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
    if ($1) uri[o.q.name][$1] = $2;
  });

  return uri;
};

parseUri.options = {
  strictMode: false,
  key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
  q:   {
    name:   "queryKey",
    parser: /(?:^|&)([^&=]*)=?([^&]*)/g
  },
  parser: {
    strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
    loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
  }
};

function getHost(name) {
  if (/http:/.test(name)) {
    var uri = parseUri(name);
    uri.remote = true;
    uri.auth = {username: uri.user, password: <PASSWORD>};
    var parts = uri.path.replace(/(^\/|\/$)/g, '').split('/');
    uri.db = parts.pop();
    uri.path = parts.join('/');
    return uri;
  }
  return {host: '', path: '/', db: name, auth: false};
}

function genUrl(opts, path) {
  if (opts.remote) {
    var pathDel = !opts.path ? '' : '/';
    return opts.protocol + '://' + opts.host + ':' + opts.port + '/' + opts.path
      + pathDel + opts.db + '/' + path;
  }
  return '/' + opts.db + '/' + path;
};

function ajax(options, callback) {
  var defaults = {
    success: function (obj, _, xhr) {
      call(callback, null, obj, xhr);
    },
    error: function (err) {
      if (err) {
        call(callback, err);
      } else {
        call(callback, true);
      }
    },
    dataType: 'json',
    contentType: 'application/json'
  };
  options = $.extend({}, defaults, options);

  if (options.data && typeof options.data !== 'string') {
    options.data = JSON.stringify(options.data);
  }
  if (options.auth) {
    options.beforeSend = function(xhr) {
      var token = btoa(options.auth.username + ":" + options.auth.password);
      xhr.setRequestHeader("Authorization", "Basic " + token);
    }
  }
  return $.ajax(options);
};

var HttpPouch = function(opts, callback) {

  var host = getHost(opts.name);
  var db_url = genUrl(host, '');
  var api = {};

  ajax({auth: host.auth, type: 'PUT', url: db_url}, function(err, ret) {
    // the user may not have permission to PUT to a db url
    if (err && err.status === 401) {
      // test if the db already exists
      ajax({auth: host.auth, type: 'HEAD', url: db_url}, function (err, ret) {
        if (err) {
          // still can't access db
          call(callback, err);
        } else {
          // continue
          call(callback, null, api);
        }
      });
    } else if (!err || err.status === 412) {
      call(callback, null, api);
    }
  });

  api.id = function() {
    return genUrl(host, '');
  };

  api.info = function(callback) {
    ajax({
      auth: host.auth,
      type:'GET',
      url: genUrl(host, ''),
    }, callback);
  };

  api.get = function(id, opts, callback) {
    if (opts instanceof Function) {
      callback = opts;
      opts = {};
    }
    var params = [];
    if (opts.revs) {
      params.push('revs=true');
    }
    if (opts.revs_info) {
      params.push('revs_info=true');
    }
    if (opts.rev) {
      params.push('rev=' + opts.rev);
    }
    if (opts.conflicts) {
      params.push('conflicts=' + opts.conflicts);
    }
    params = params.join('&');
    params = params === '' ? '' : '?' + params;

    var options = {
      auth: host.auth,
      type: 'GET',
      url: genUrl(host, id + params)
    };

    if (/\//.test(id) && !/^_local/.test(id)) {
      options.dataType = false;
    }

    ajax(options, function(err, doc, xhr) {
      if (err) {
        return call(callback, Pouch.Errors.MISSING_DOC);
      }
      call(callback, null, doc, xhr);
    });
  };

  api.remove = function(doc, opts, callback) {
    if (opts instanceof Function) {
      callback = opts;
      opts = {};
    }
    ajax({
      auth: host.auth,
      type:'DELETE',
      url: genUrl(host, doc._id) + '?rev=' + doc._rev
    }, callback);
  };

  api.putAttachment = function(id, rev, doc, type, callback) {
    ajax({
      auth: host.auth,
      type:'PUT',
      url: genUrl(host, id) + '?rev=' + rev,
      headers: {'Content-Type': type},
      data: doc
    }, callback);
  };

  api.put = function(doc, opts, callback) {
    if (opts instanceof Function) {
      callback = opts;
      opts = {};
    }
    ajax({
      auth: host.auth,
      type: 'PUT',
      url: genUrl(host, doc._id),
      data: doc
    }, callback);
  };


  api.post = function(doc, opts, callback) {
    if (opts instanceof Function) {
      callback = opts;
      opts = {};
    }
    ajax({
      auth: host.auth,
      type: 'POST',
      url: genUrl(host, ''),
      data: doc
    }, callback);
  };

  api.bulkDocs = function(req, opts, callback) {
    if (opts instanceof Function) {
      callback = opts;
      opts = {};
    }
    if (typeof opts.new_edits !== 'undefined') {
      req.new_edits = opts.new_edits;
    }
    ajax({
      auth: host.auth,
      type:'POST',
      url: genUrl(host, '_bulk_docs'),
      data: req
    }, callback);
  };

  api.allDocs = function(opts, callback) {
    if (opts instanceof Function) {
      callback = opts;
      opts = {};
    }
    ajax({auth: host.auth, type:'GET', url: genUrl(host, '_all_docs')}, callback);
  };
{'fraction_non_alphanumeric': 0.24183365358221245, 'fraction_numerical': 0.003476987830542593, 'mean_word_length': 2.4209702660406887, 'pattern_counts': {'":': 2, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4523346', 'n_tokens_mistral': 4092, 'n_tokens_neox': 3957, 'n_words': 824}