text stringlengths 120 399k | repository stringclasses 82
values | revision stringclasses 96
values | path stringlengths 10 294 | language stringclasses 17
values | source_url stringlengths 85 373 | license_id stringclasses 5
values | license_evidence_url stringclasses 96
values | content_sha256 stringlengths 64 64 | token_count_fluqxo128k int64 25 217k |
|---|---|---|---|---|---|---|---|---|---|
# Express examples
This page contains list of examples using Express.
- [auth](./auth) - Authentication with login and password
- [content-negotiation](./content-negotiation) - HTTP content negotiation
- [cookie-sessions](./cookie-sessions) - Working with cookie-based sessions
- [cookies](./cookies) - Working with co... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/README.md | Markdown | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/README.md | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 93d778625ad19379ca60d8534a2aaa72bb6c808310539def136a2e50fa7ca379 | 409 |
'use strict'
/**
* Module dependencies.
*/
var db = require('../../db');
exports.name = 'pet';
exports.prefix = '/user/:user_id';
exports.create = function(req, res, next){
var id = req.params.user_id;
var user = db.users[id];
var body = req.body;
if (!user) return next('route');
var pet = { name: body.... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/mvc/controllers/user-pet/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/mvc/controllers/user-pet/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 397ff04667f5c7e564b1e6a55e5e9245761051565afa2f869bb6560deb2fd125 | 142 |
'use strict'
/**
* Module dependencies.
*/
var escapeHtml = require('escape-html');
var express = require('../..');
var fs = require('node:fs');
var marked = require('marked');
var path = require('node:path');
var app = module.exports = express();
// register .md as an engine in express view system
app.engine('m... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/markdown/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/markdown/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 3a2005b5bc1ea0393783c1a97da58dc81c751e0f5a6dc301cc84ba0c061500ff | 287 |
/*!
* express
* Copyright(c) 2009-2013 TJ Holowaychuk
* Copyright(c) 2014-2015 Douglas Christopher Wilson
* MIT Licensed
*/
'use strict';
/**
* Module dependencies.
* @api private
*/
var { METHODS } = require('node:http');
var contentType = require('content-type');
var etag = require('etag');
var mime = requ... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | lib/utils.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/lib/utils.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 4bd3bf9c911e086d1911954708de7a6c384ed924360e3fd1d4a43c98bd68b112 | 1,453 |
'use strict'
// faux database
var pets = exports.pets = [];
pets.push({ name: 'Tobi', id: 0 });
pets.push({ name: 'Loki', id: 1 });
pets.push({ name: 'Jane', id: 2 });
pets.push({ name: 'Raul', id: 3 });
var users = exports.users = [];
users.push({ name: 'TJ', pets: [pets[0], pets[1], pets[2]], id: 0 });
users.pu... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/mvc/db.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/mvc/db.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 7b8c2e632192310a3bdee3cc22238bfc41d6fea7d7195d2e8a3fb0e9d891ab12 | 159 |
'use strict'
/**
* Module dependencies.
*/
var express = require('../..');
var logger = require('morgan');
var session = require('express-session');
// pass the express to the connect redis module
// allowing it to inherit from session.Store
var RedisStore = require('connect-redis')(session);
var app = express();... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/session/redis.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/session/redis.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | c882d4d0e3abe61b9bd64570f9157cbd5ff1c35ba3bf2825076a50ec633945ba | 250 |
'use strict'
/**
* Module dependencies.
*/
var express = require('../..');
var logger = require('morgan');
var vhost = require('vhost');
/*
edit /etc/hosts:
127.0.0.1 foo.example.com
127.0.0.1 bar.example.com
127.0.0.1 example.com
*/
// Main server app
var main = express();
if (!module.parent... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/vhost/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/vhost/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 57dc34057c96830eba5318c8705dd8b77b42dc3fe4c6b7805a97222cabf756b2 | 295 |
'use strict'
/**
* Module dependencies.
*/
var https = require('node:https');
var path = require('node:path');
var extname = path.extname;
/**
* Expose `GithubView`.
*/
module.exports = GithubView;
/**
* Custom view that fetches and renders
* remove github templates. You could
* render templates from a data... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/view-constructor/github-view.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/view-constructor/github-view.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 936416302ea3d704cc603f63787ec3121204b3720153fcb2a99e5ec151432a2e | 290 |
'use strict'
/**
* Module dependencies.
*/
var express = require('../..');
var logger = require('morgan');
var path = require('node:path');
var session = require('express-session');
var methodOverride = require('method-override');
var app = module.exports = express();
// set our default template engine to "ejs"
/... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/mvc/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/mvc/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 7ee423b13b0661c6a3f02534e79529b305ac52d6448f0aaf66b97650b9c22b18 | 598 |
'use strict'
/**
* Module dependencies.
*/
var express = require('../..');
var path = require('node:path');
var User = require('./user');
var app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
// filter ferrets only
function ferrets(user) {
return user.species === ... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/view-locals/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/view-locals/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | a49cdf21100cb68afec4020e12715b329fc34c4ee4c1f259ff3102e684e8cfb9 | 838 |
'use strict'
/**
* Module dependencies.
*/
var db = require('../../db');
exports.engine = 'hbs';
exports.before = function(req, res, next){
var id = req.params.user_id;
if (!id) return next();
// pretend to query a database...
process.nextTick(function(){
req.user = db.users[id];
// can't find tha... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/mvc/controllers/user/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/mvc/controllers/user/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 462e5a7457f7f73673adef1e878eb87ec66d8baf6f9fde9785264bb81a36e2ba | 244 |
'use strict'
var express = require('../../..');
var apiv1 = express.Router();
apiv1.get('/', function(req, res) {
res.send('Hello from APIv1 root route.');
});
apiv1.get('/users', function(req, res) {
res.send('List of APIv1 users.');
});
module.exports = apiv1;
| expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/multi-router/controllers/api_v1.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/multi-router/controllers/api_v1.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 7220ce1de1ad06db1879030a1037f201dbc0d4c4ce58bd47273acd50b7480abe | 85 |
'use strict'
/**
* Module dependencies.
*/
var express = require('../../');
var app = module.exports = express();
// create an error with .status. we
// can then use the property in our
// custom error handler (Connect respects this prop as well)
function error(status, msg) {
var err = new Error(msg);
err.st... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/web-service/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/web-service/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 726532ea16b88e64d1c492f1cd058ffeba04121887c866ab8257f318fd7ba101 | 853 |
'use strict'
module.exports = User;
// faux model
function User(name, age, species) {
this.name = name;
this.age = age;
this.species = species;
}
User.all = function(fn){
// process.nextTick makes sure this function API
// behaves in an asynchronous manner, like if it
// was a real DB query to read all ... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/view-locals/user.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/view-locals/user.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | e2aceca879f0a5bdf0107056f5c6c3f7fcd1f12b48700332242f38b977ae454a | 215 |
/*!
* express
* Copyright(c) 2009-2013 TJ Holowaychuk
* Copyright(c) 2013 Roman Shtylman
* Copyright(c) 2014-2015 Douglas Christopher Wilson
* MIT Licensed
*/
'use strict';
/**
* Module dependencies.
* @private
*/
var finalhandler = require('finalhandler');
var debug = require('debug')('express:application'... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | lib/application.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/lib/application.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 6d7e08355025786982d17042fc0355b6a5e9339545dc27e2782b3aaa28a7bc04 | 3,730 |
'use strict'
/**
* Module dependencies.
*/
var express = require('../../');
var logger = require('morgan');
var app = module.exports = express();
var test = app.get('env') === 'test'
if (!test) app.use(logger('dev'));
// error handling middleware have an arity of 4
// instead of the typical (req, res, next),
// o... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/error/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/error/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | a82e4d69a686e9ebc5802d45a6491d7365d5f79185d82ddf871489cfdb56fbdb | 342 |
'use strict'
var express = require('../../..');
var apiv2 = express.Router();
apiv2.get('/', function(req, res) {
res.send('Hello from APIv2 root route.');
});
apiv2.get('/users', function(req, res) {
res.send('List of APIv2 users.');
});
module.exports = apiv2;
| expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/multi-router/controllers/api_v2.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/multi-router/controllers/api_v2.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 0bc369adc101e2e301406a7860cff8059a1025adc85d05ee2a160e468af136bb | 85 |
'use strict'
/**
* Module dependencies.
*/
var express = require('../../lib/express');
var app = express();
// Example requests:
// curl http://localhost:3000/user/0
// curl http://localhost:3000/user/0/edit
// curl http://localhost:3000/user/1
// curl http://localhost:3000/user/1/edit (unauthoriz... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/route-middleware/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/route-middleware/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 8bbd84ce25e3be1e943d83d2dfe4a8fddc99358c0b7dc454a4df39b7597c26bb | 671 |
'use strict'
var users = require('./db');
exports.html = function(req, res){
res.send('<ul>' + users.map(function(user){
return '<li>' + user.name + '</li>';
}).join('') + '</ul>');
};
exports.text = function(req, res){
res.send(users.map(function(user){
return ' - ' + user.name + '\n';
}).join(''));... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/content-negotiation/users.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/content-negotiation/users.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 9943db10754f61f8cee9488649e73b9a244a7f940ff0c3596af97924bcfcd234 | 112 |
'use strict'
// install redis first:
// https://redis.io/
// then:
// $ npm install redis
// $ redis-server
/**
* Module dependencies.
*/
var express = require('../..');
var path = require('node:path');
var redis = require('redis');
var db = redis.createClient();
var app = express();
app.use(express.static(path... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/search/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/search/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 4fc4dfd87b9b0ef4757b12d3a16ac8fbb54277252e92f4c27dafc9522536a56e | 439 |
'use strict'
/**
* Module dependencies.
*/
var express = require('../..');
var path = require('node:path');
var app = express();
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var methodOverride = require('method-override');
var site = require('./site');
var post = require('./post');
v... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/route-separation/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/route-separation/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 65c2270263e0c0bc1725c0a17232ea7359b52e3edb868d64557a7ded87c56669 | 312 |
'use strict'
// Fake posts database
var posts = [
{ title: 'Foo', body: 'some foo bar' },
{ title: 'Foo bar', body: 'more foo bar' },
{ title: 'Foo bar baz', body: 'more foo bar baz' }
];
exports.list = function(req, res){
res.render('posts', { title: 'Posts', posts: posts });
};
| expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/route-separation/post.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/route-separation/post.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 74b691649f50f97ad163c55f5517e1a9d6d856cf51f0c1641ecf81634ddaac82 | 93 |
/*!
* express
* Copyright(c) 2009-2013 TJ Holowaychuk
* Copyright(c) 2014-2015 Douglas Christopher Wilson
* MIT Licensed
*/
'use strict';
/**
* Module dependencies.
* @private
*/
var contentDisposition = require('content-disposition');
var createError = require('http-errors')
var deprecate = require('depd')(... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | lib/response.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/lib/response.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | efe24afe2978d0bf2ad52d5b163a7af0d25d965e5dfc75979c4fcc883c60a510 | 6,812 |
'use strict'
/**
* Module dependencies.
*/
var express = require('../../');
var path = require('node:path');
var app = module.exports = express();
// path to where the files are stored on disk
var FILES_DIR = path.join(__dirname, 'files')
app.get('/', function(req, res){
res.send('<ul>' +
'<li>Download <a ... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/downloads/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/downloads/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 0b826b327815c7deacc109b1445a9ec7ea06b4e3ea9ed5dce7af3b0f108714d0 | 364 |
'use strict'
/**
* Module dependencies.
*/
var express = require('../..');
var hash = require('pbkdf2-password')()
var path = require('node:path');
var session = require('express-session');
var app = module.exports = express();
// config
app.set('view engine', 'ejs');
app.set('views', path.join(__dirname, 'views... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/auth/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/auth/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 4acca9f794d50f57c41967b471031f7410cc61a2b979c86ad0f264567f06e69b | 959 |
'use strict'
var express = require('../../');
var app = module.exports = express()
app.get('/', function(req, res){
res.send('Hello World');
});
/* istanbul ignore next */
if (!module.parent) {
app.listen(3000);
console.log('Express started on port 3000');
}
| expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/hello-world/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/hello-world/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | ab0bb8d99209070fa5ad9f6f37a05730bbf6388ff512954d251d30eff4946686 | 73 |
'use strict'
/**
* Module dependencies.
*/
var express = require('../../');
var app = module.exports = express();
var logger = require('morgan');
var cookieParser = require('cookie-parser');
// custom log format
if (process.env.NODE_ENV !== 'test') app.use(logger(':method :url'))
// parses request cookies, popula... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/cookies/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/cookies/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | d91ed906721c1ad0ee2743ea9fcdd41c37bbf07f1474b6970841cc0254f8a160 | 359 |
'use strict'
var users = [];
users.push({ name: 'Tobi' });
users.push({ name: 'Loki' });
users.push({ name: 'Jane' });
module.exports = users;
| expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/content-negotiation/db.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/content-negotiation/db.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 508014d6735d509d7943753343b8351a989df0dd56dda025257da686d23a0175 | 50 |
'use strict'
// install redis first:
// https://redis.io/
// then:
// $ npm install redis
// $ redis-server
var express = require('../..');
var session = require('express-session');
var app = express();
// Populates req.session
app.use(session({
resave: false, // don't save session if unmodified
saveUninitiali... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/session/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/session/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 62dd5bf84224c3e6a1437f20833c4b8bfb7c9f73b0f142abeaac4af17149614f | 229 |
'use strict'
/**
* Module dependencies.
*/
var cookieSession = require('cookie-session');
var express = require('../../');
var app = module.exports = express();
// add req.session cookie support
app.use(cookieSession({ secret: 'manny is cool' }));
// do something with the session
app.get('/', function (req, res)... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/cookie-sessions/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/cookie-sessions/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 4db8212bfb73efd9294673bf1699d4f7c649da9355c0651f43ae39febb19d318 | 147 |
'use strict'
var search = document.querySelector('[type=search]');
var code = document.querySelector('pre');
search.addEventListener('keyup', function(){
var xhr = new XMLHttpRequest;
xhr.open('GET', '/search/' + search.value, true);
xhr.onreadystatechange = function(){
if (xhr.readyState === 4) {
cod... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/search/public/client.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/search/public/client.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 611bead77cfe54a99e75c38604c3428ddb4afa11271706f8d6e30929edf44b4f | 109 |
'use strict'
/**
* Module dependencies.
*/
var express = require('../..');
var logger = require('morgan');
var path = require('node:path');
var app = express();
// log requests
app.use(logger('dev'));
// express on its own has no notion
// of a "file". The express.static()
// middleware checks for a file matching... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/static-files/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/static-files/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 63605ce73f514c145edbf390d4401111e905e7b205a9531149fd39915ada6d91 | 350 |
/*!
* express
* Copyright(c) 2009-2013 TJ Holowaychuk
* Copyright(c) 2013 Roman Shtylman
* Copyright(c) 2014-2015 Douglas Christopher Wilson
* MIT Licensed
*/
'use strict';
/**
* Module dependencies.
* @private
*/
var debug = require('debug')('express:view');
var path = require('node:path');
var fs = requir... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | lib/view.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/lib/view.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 74f4171b66263e22481820bc5975708f7dd8a61484f570aac7c5b4ab77ecbd79 | 1,065 |
'use strict'
/**
* Module dependencies.
*/
var express = require('../../');
var app = module.exports = express();
// Ad-hoc example resource method
app.resource = function(path, obj) {
this.get(path, obj.index);
this.get(path + '/:a..:b{.:format}', function(req, res){
var a = parseInt(req.params.a, 10);
... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/resource/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/resource/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | df0a7101b8e7624a134a4c660be2e8c26450579b0bce1ce725f0a47662bd8c3c | 706 |
'use strict'
// install redis first:
// https://redis.io/
// then:
// $ npm install redis online
// $ redis-server
/**
* Module dependencies.
*/
var express = require('../..');
var online = require('online');
var redis = require('redis');
var db = redis.createClient();
// online
online = online(db);
// app
va... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/online/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/online/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 2e952f14143390d6cc41055a8fe0852b275fa36fecacb02adb03e151795735b1 | 290 |
/*!
* express
* Copyright(c) 2009-2013 TJ Holowaychuk
* Copyright(c) 2013 Roman Shtylman
* Copyright(c) 2014-2015 Douglas Christopher Wilson
* MIT Licensed
*/
'use strict';
/**
* Module dependencies.
*/
var bodyParser = require('body-parser')
var EventEmitter = require('node:events').EventEmitter;
var mixin ... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | lib/express.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/lib/express.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 4f35e8273a5e78c35e778d14e4a8c80a81ca3e1fc8047dc87d2077b860404572 | 430 |
'use strict'
/**
* Module dependencies.
*/
var express = require('../../');
var path = require('node:path');
var app = module.exports = express();
var logger = require('morgan');
var silent = process.env.NODE_ENV === 'test'
// general config
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', '... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/error-pages/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/error-pages/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | af04ae3ba25a70070f350c08a154086da232afe2a68a4bb1f5229d37d059e674 | 702 |
'use strict'
// Fake user database
var users = [
{ name: 'TJ', email: 'tj@vision-media.ca' },
{ name: 'Tobi', email: 'tobi@vision-media.ca' }
];
exports.list = function(req, res){
res.render('users', { title: 'Users', users: users });
};
exports.load = function(req, res, next){
var id = req.params.id;
req... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/route-separation/user.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/route-separation/user.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | c02d2ef35011297a2cc459052acaece64b00ae826afeff551bf49d65872b83a4 | 300 |
'use strict'
/**
* Module dependencies.
*/
var db = require('../../db');
exports.engine = 'ejs';
exports.before = function(req, res, next){
var pet = db.pets[req.params.pet_id];
if (!pet) return next('route');
req.pet = pet;
next();
};
exports.show = function(req, res, next){
res.render('show', { pet: ... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/mvc/controllers/pet/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/mvc/controllers/pet/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | f4798e50906220321f0a0d7a0c97532802903c1089b4dba8228ec4e0364d177c | 181 |
'use strict'
var express = require('../../');
var app = module.exports = express();
var users = require('./db');
// so either you can deal with different types of formatting
// for expected response in index.js
app.get('/', function(req, res){
res.format({
html: function(){
res.send('<ul>' + users.map(fun... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/content-negotiation/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/content-negotiation/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | fadf6827e28bcb0271c03bb8059a67d2dca3d051f4243f6bd507ee036612a3b7 | 260 |
'use strict'
var express = require('../..');
var app = module.exports = express();
app.use('/api/v1', require('./controllers/api_v1'));
app.use('/api/v2', require('./controllers/api_v2'));
app.get('/', function(req, res) {
res.send('Hello from root route.')
});
/* istanbul ignore next */
if (!module.parent) {
... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/multi-router/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/multi-router/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 2dd63ace2545575c3349d61b6c2660c46336de29290b5d20da0088f30a67cb55 | 110 |
'use strict'
/**
* Module dependencies.
*/
var express = require('../../');
var path = require('node:path');
var app = module.exports = express();
// Register ejs as .html. If we did
// not call this, we would need to
// name our views foo.ejs instead
// of foo.html. The __express method
// is simply a function t... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/ejs/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/ejs/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 48d2ca08efdcfb2a5917de7ce2299a2f223ea67855d09cf7e67c5b87cc8ec371 | 380 |
'use strict'
/**
* Module dependencies.
*/
var escapeHtml = require('escape-html')
var express = require('../../lib/express');
var verbose = process.env.NODE_ENV !== 'test'
var app = module.exports = express();
app.map = function(a, route){
route = route || '';
for (var key in a) {
switch (typeof a[key])... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/route-map/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/route-map/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | 4b921380a34e14e3da551e74520e3807a068fefd7adf2013df5caf5fc8b7a0f4 | 396 |
'use strict'
/**
* Module dependencies.
*/
var express = require('../../');
var GithubView = require('./github-view');
var md = require('marked').parse;
var app = module.exports = express();
// register .md as an engine in express view system
app.engine('md', function(str, options, fn){
try {
var html = md(... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/view-constructor/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/view-constructor/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | eaeb509d4eb6afec5585f341315d7db08bfbd548db58ad09ee047e6cdbe0fd40 | 314 |
'use strict'
/**
* Module dependencies.
*/
var createError = require('http-errors')
var express = require('../../');
var app = module.exports = express();
// Faux database
var users = [
{ name: 'tj' }
, { name: 'tobi' }
, { name: 'loki' }
, { name: 'jane' }
, { name: 'bandit' }
];
// Convert :to and :f... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/params/index.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/params/index.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | f381d9199eace049b8048d03362010765cf17374a72c2c6656e2757236c9b301 | 423 |
/*!
* express
* Copyright(c) 2009-2013 TJ Holowaychuk
* Copyright(c) 2013 Roman Shtylman
* Copyright(c) 2014-2015 Douglas Christopher Wilson
* MIT Licensed
*/
'use strict';
/**
* Module dependencies.
* @private
*/
var accepts = require('accepts');
var isIP = require('node:net').isIP;
var typeis = require('t... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | lib/request.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/lib/request.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | a9fda39c4472aeaa4d696f4324f58cc1d036f84ed04145d6d56a12a59578e751 | 3,408 |
'use strict'
/**
* Module dependencies.
*/
var express = require('../../..');
var fs = require('node:fs');
var path = require('node:path');
module.exports = function(parent, options){
var dir = path.join(__dirname, '..', 'controllers');
var verbose = options.verbose;
fs.readdirSync(dir).forEach(function(name... | expressjs/express | 43fca52d28a422c8be48fd489cbd4f2d6152bab6 | examples/mvc/lib/boot.js | JavaScript | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/examples/mvc/lib/boot.js | MIT | https://github.com/expressjs/express/blob/43fca52d28a422c8be48fd489cbd4f2d6152bab6/LICENSE | fd7eb252663f1c365606b180aad645b9b65632070d1f07824e3fca22640bd068 | 577 |
from __future__ import annotations
import typing as t
from threading import local
if t.TYPE_CHECKING:
from .core import Context
_local = local()
@t.overload
def get_current_context(silent: t.Literal[False] = False) -> Context: ...
@t.overload
def get_current_context(silent: bool = ...) -> Context | None: ...... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | src/click/globals.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/src/click/globals.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | 80cf8d87a0383341c1fd2824685e4ce2770618c0c773f7e51d7bbdfe88781845 | 472 |
# This module is based on the excellent work by Adam Bartoš who
# provided a lot of what went into the implementation here in
# the discussion to issue1602 in the Python bug tracker.
#
# There are some general differences in regards to how this works
# compared to the original patches as we do not need to patch
# the e... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | src/click/_winconsole.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/src/click/_winconsole.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | a6f0d49ef0be806a9730bd64a2e5b373a95d49de91fd7728595ff31d773f2db7 | 2,145 |
from __future__ import annotations
import collections.abc as cabc
import typing as t
from gettext import gettext as _
from gettext import ngettext
from ._compat import get_text_stderr
from .globals import resolve_color_default
from .utils import echo
from .utils import format_filename
if t.TYPE_CHECKING:
from .c... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | src/click/exceptions.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/src/click/exceptions.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | 1ef498df81b86ae8ff6d8451f3e4fc094f09c2aff5f8e72c454e1ecdfa337849 | 2,741 |
from __future__ import annotations
import inspect
import typing as t
from functools import update_wrapper
from gettext import gettext as _
from .core import Argument
from .core import Command
from .core import Context
from .core import Group
from .core import Option
from .core import Parameter
from .globals import ge... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | src/click/decorators.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/src/click/decorators.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | f4d01d31413df715c3573d4879ab82fd280ef048fc4ffdacf093c6c506ee6965 | 5,232 |
from __future__ import annotations
import collections.abc as cabc
from contextlib import contextmanager
from gettext import gettext as _
from ._compat import term_len
from .parser import _split_opt
# Can force a width. This is used by the test system
FORCED_WIDTH: int | None = None
def measure_table(rows: cabc.It... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | src/click/formatting.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/src/click/formatting.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | 421994c476e0108d521f7c20da7a407a28425dd81afbfe8298bf59d3faf6580f | 2,463 |
"""
Click is a simple Python module inspired by the stdlib optparse to make
writing command line scripts fun. Unlike other modules, it's based
around a simple API that does not come with too much magic and is
composable.
"""
from __future__ import annotations
from .core import Argument as Argument
from .core import C... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | src/click/__init__.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/src/click/__init__.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | 5abfc54d37d47cc788b7e7a05e9514787f8c5a0b7db429d0f24d748ac89964ca | 1,123 |
import configparser
import os
import click
class Config:
"""The config in this example only holds aliases."""
def __init__(self):
self.path = os.getcwd()
self.aliases = {}
def add_alias(self, alias, cmd):
self.aliases.update({alias: cmd})
def read_config(self, filename):
... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | examples/aliases/aliases.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/examples/aliases/aliases.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | ce8e75f58d7a61c9390c5e8734b24caa83e37447d283ce121dc07a61f4801340 | 963 |
import os
import posixpath
import sys
import click
class Repo:
def __init__(self, home):
self.home = home
self.config = {}
self.verbose = False
def set_config(self, key, value):
self.config[key] = value
if self.verbose:
click.echo(f" config[{key}] = {valu... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | examples/repo/repo.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/examples/repo/repo.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | cef5766bc59330ff9342f7c6a7eabfe89716ab46a7f719d84a7b97d3b12f5f09 | 1,177 |
import os
import sys
import click
CONTEXT_SETTINGS = dict(auto_envvar_prefix="COMPLEX")
class Environment:
def __init__(self):
self.verbose = False
self.home = os.getcwd()
def log(self, msg, *args):
"""Logs a message to stderr."""
if args:
msg %= args
cl... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | examples/complex/complex/cli.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/examples/complex/complex/cli.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | 2042ffdb1e77f0f937036f3f0a33c67bacbad90477873d7576cc297674a55de7 | 381 |
from functools import update_wrapper
from PIL import Image
from PIL import ImageEnhance
from PIL import ImageFilter
import click
@click.group(chain=True)
def cli():
"""This script processes a bunch of images through pillow in a unix
pipe. One commands feeds into the next.
Example:
\b
imag... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | examples/imagepipe/imagepipe.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/examples/imagepipe/imagepipe.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | eaf679fc90b988c938b2a32ff4d716d25127fe63a8c3804222628ffe8ec46dc2 | 2,077 |
from __future__ import annotations
import collections.abc as cabc
import contextlib
import io
import os
import pdb
import shlex
import sys
import tempfile
import typing as t
from types import TracebackType
from . import _compat
from . import formatting
from . import termui
from . import utils
from ._compat import _fi... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | src/click/testing.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/src/click/testing.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | e95823823bf2aa65739c2b064778c2893608eaec46080fcd7b7787adf9489b37 | 6,844 |
from __future__ import annotations
import codecs
import collections.abc as cabc
import io
import os
import re
import sys
import typing as t
from types import TracebackType
from weakref import WeakKeyDictionary
CYGWIN = sys.platform.startswith("cygwin")
WIN = sys.platform.startswith("win")
# One CSI escape sequence pe... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | src/click/_compat.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/src/click/_compat.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | 43e898c7291c1c37f91484f838d8d474081754d83726d0444d06ae7ca68a6a69 | 4,414 |
from __future__ import annotations
import collections.abc as cabc
import inspect
import io
import itertools
import os
import re
import sys
import typing as t
from contextlib import AbstractContextManager
from contextlib import redirect_stdout
from gettext import gettext as _
from . import _compat
from ._compat import... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | src/click/termui.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/src/click/termui.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | 16f6546b36d647d191788fc912e32d93e8b64289517f004e6d9604f4896ad1ca | 8,766 |
from complex.cli import pass_environment
import click
@click.command("status", short_help="Shows file changes.")
@pass_environment
def cli(ctx):
"""Shows file changes in the current working directory."""
ctx.log("Changed files: none")
ctx.vlog("bla bla bla, debug info")
| pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | examples/complex/complex/commands/cmd_status.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/examples/complex/complex/commands/cmd_status.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | 22bbe1f58b41c89b12ce6b74a3b95932bf607c73cdec9d0ef82e9f948a06803d | 70 |
"""
This module started out as largely a copy paste from the stdlib's
optparse module with the features removed that we do not need from
optparse because we implement them in Click on a higher level (for
instance type handling, help formatting and a lot more).
The plan is to remove more and more from here over time.
... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | src/click/parser.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/src/click/parser.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | a09f9f53fde6bf1ba022e36d1da0804d9e7a9601261d18208c9892a84818ae30 | 4,434 |
from __future__ import annotations
import collections.abc as cabc
import textwrap
from contextlib import contextmanager
from ._compat import term_len
class TextWrapper(textwrap.TextWrapper):
"""``textwrap.TextWrapper`` variant that measures widths by visible
character count.
ANSI escape sequences embed... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | src/click/_textwrap.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/src/click/_textwrap.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | c526ca64bbe24d08f054b164fb2b37f6f65c62ca4e05848d51bc68d8e00e86d9 | 700 |
from __future__ import annotations
import collections.abc as cabc
import os
import re
import typing as t
from gettext import gettext as _
from .core import Argument
from .core import Command
from .core import Context
from .core import Group
from .core import Option
from .core import Parameter
from .core import Parame... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | src/click/shell_completion.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/src/click/shell_completion.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | c5fcba42d9c50bf90367b21a7a80c32fb43f6dda55d0847c7e357b4c95f4e71a | 6,213 |
import click
@click.command()
@click.argument("input", type=click.File("rb"), nargs=-1)
@click.argument("output", type=click.File("wb"))
def cli(input, output):
"""This script works similar to the Unix `cat` command but it writes
into a specific file (which could be the standard output as denoted by
the `... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | examples/inout/inout.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/examples/inout/inout.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | f0a15c4c3d331111841605298951dd281f5b8df116119e331094880704159e35 | 179 |
import click
@click.group()
@click.version_option()
def cli():
"""Naval Fate.
This is the docopt example adopted to Click but with some actual
commands implemented and not just the empty parsing which really
is not all that interesting.
"""
@cli.group()
def ship():
"""Manages ships."""
@s... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | examples/naval/naval.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/examples/naval/naval.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | a8d3748eeaa204012b1794ea77be6dd23dfdb141c2d5940332c06c73b266a0c1 | 482 |
from urllib import parse as urlparse
import click
def validate_count(ctx, param, value):
if value < 0 or value % 2 != 0:
raise click.BadParameter("Should be a positive, even integer.")
return value
class URL(click.ParamType[urlparse.ParseResult]):
name = "url"
def convert(self, value, para... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | examples/validation/validation.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/examples/validation/validation.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | 246c4962fff19bbf12cf620e141a904ac9059698f0002c11833bb882f492786f | 343 |
from __future__ import annotations
import abc
import collections.abc as cabc
import enum
import os
import stat
import sys
import typing as t
import uuid
from datetime import datetime
from gettext import gettext as _
from gettext import ngettext
from ._compat import _get_argv_encoding
from ._compat import open_stream
... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | src/click/types.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/src/click/types.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | 896fe567765a5e978ee0930513049c8b6d008b67a87ac0e53f656f8b560ed434 | 11,154 |
import math
import random
import time
import click
@click.group()
def cli():
"""This script showcases different terminal UI helpers in Click."""
pass
@cli.command()
def colordemo():
"""Demonstrates ANSI color support."""
for color in "red", "green", "blue":
click.echo(click.style(f"I am col... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | examples/termui/termui.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/examples/termui/termui.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | cc79721d0e7250c9aa23cfafb4f897cd1fd25711371ae58aab616760be47381d | 1,039 |
from __future__ import annotations
import collections.abc as cabc
import os
import re
import sys
import typing as t
from functools import update_wrapper
from gettext import gettext as _
from types import ModuleType
from types import TracebackType
from ._compat import _default_text_stderr
from ._compat import _default... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | src/click/utils.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/src/click/utils.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | dab1b69abdfbc42c1efbb76890bbb12ff00fe152846c0f4176253c32df5eca21 | 5,199 |
from complex.cli import pass_environment
import click
@click.command("init", short_help="Initializes a repo.")
@click.argument("path", required=False, type=click.Path(resolve_path=True))
@pass_environment
def cli(ctx, path):
"""Initializes a repository."""
if path is None:
path = ctx.home
ctx.log... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | examples/complex/complex/commands/cmd_init.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/examples/complex/complex/commands/cmd_init.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | 6068f21b5874685d6e4d467f24bc45ddf2cc28457cd27b1b2dc2aadef24ddde4 | 92 |
"""
This module contains implementations for the termui module. To keep the
import time of Click down, some infrequently used functionality is
placed in this module and only imported as needed.
"""
from __future__ import annotations
import collections.abc as cabc
import contextlib
import math
import os
import shlex
i... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | src/click/_termui_impl.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/src/click/_termui_impl.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | 90145b0d068e9a0f595e2c212aa162a185c7de24738bca854cf523f54c1a1687 | 7,730 |
import os
import click
from click.shell_completion import CompletionItem
@click.group()
def cli():
pass
@cli.command()
@click.option("--dir", type=click.Path(file_okay=False))
def ls(dir):
click.echo("\n".join(os.listdir(dir)))
def get_env_vars(ctx, param, incomplete):
# Returning a list of values is... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | examples/completion/completion.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/examples/completion/completion.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | ceeb4f35fa92d4abcc537e0759624cb404e5b1600690467a099c8552a4b7bff2 | 360 |
from __future__ import annotations
import collections.abc as cabc
import enum
import errno
import inspect
import os
import sys
import typing as t
from abc import ABC
from abc import abstractmethod
from collections import abc
from collections import Counter
from contextlib import AbstractContextManager
from contextlib ... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | src/click/core.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/src/click/core.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | cce257121e530d9fea502f0f4b0a7b7e2ebbf2294fab8d97eaa253d9d5672d77 | 33,982 |
from __future__ import annotations
import enum
import typing as t
class Sentinel(enum.Enum):
"""Enum used to define sentinel values.
.. seealso::
`PEP 661 - Sentinel Values <https://peps.python.org/pep-0661/>`_.
"""
UNSET = object()
FLAG_NEEDS_VALUE = object()
def __repr__(self) -... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | src/click/_utils.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/src/click/_utils.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | 949dcaa99b4242a55df29613a36adc1c30092f55b14f63fe09cf35bc9ba585f5 | 303 |
import click
all_colors = (
"black",
"red",
"green",
"yellow",
"blue",
"magenta",
"cyan",
"white",
"bright_black",
"bright_red",
"bright_green",
"bright_yellow",
"bright_blue",
"bright_magenta",
"bright_cyan",
"bright_white",
)
@click.command()
def cli... | pallets/click | 08b803cf32ceb2ae6a772c62d5da42757a897d44 | examples/colors/colors.py | Python | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/examples/colors/colors.py | BSD-3-Clause | https://github.com/pallets/click/blob/08b803cf32ceb2ae6a772c62d5da42757a897d44/LICENSE.txt | 674b6442b8cd39319a9448fe67c9badbcbe512da7280985065aa51b8839e9614 | 251 |
Deploy to Production
====================
This part of the tutorial assumes you have a server that you want to
deploy your application to. It gives an overview of how to create the
distribution file and install it, but won't go into specifics about
what server or software to use. You can set up a new environment on yo... | pallets/flask | 49943b5a94413a530761350f04e896f76e8d620e | docs/tutorial/deploy.rst | reStructuredText | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/docs/tutorial/deploy.rst | BSD-3-Clause | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/LICENSE.txt | 20293623ad985fe72e06523a8f851bb253beccb84c0362708284ec484ca7be97 | 958 |
Class-based Views
=================
.. currentmodule:: flask.views
This page introduces using the :class:`View` and :class:`MethodView`
classes to write class-based views.
A class-based view is a class that acts as a view function. Because it
is a class, different instances of the class can be created with
different... | pallets/flask | 49943b5a94413a530761350f04e896f76e8d620e | docs/views.rst | reStructuredText | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/docs/views.rst | BSD-3-Clause | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/LICENSE.txt | 225deb1feed5e285a23c151c1ffd9ae7be3106b436f94d2f3f179c2b438b01d6 | 2,409 |
.. currentmodule:: flask
Command Line Interface
======================
Installing Flask installs the ``flask`` script, a `Click`_ command line
interface, in your virtualenv. Executed from the terminal, this script gives
access to built-in, extension, and application-defined commands. The ``--help``
option will give m... | pallets/flask | 49943b5a94413a530761350f04e896f76e8d620e | docs/cli.rst | reStructuredText | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/docs/cli.rst | BSD-3-Clause | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/LICENSE.txt | e8e5e9b220a5159e9c9c8b413de499aa5a51cd0ca487681e2352bbdf6f9b0cda | 4,160 |
Large Applications as Packages
==============================
Imagine a simple flask application structure that looks like this::
/yourapplication
yourapplication.py
/static
style.css
/templates
layout.html
index.html
login.html
.... | pallets/flask | 49943b5a94413a530761350f04e896f76e8d620e | docs/patterns/packages.rst | reStructuredText | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/docs/patterns/packages.rst | BSD-3-Clause | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/LICENSE.txt | 230814a0edf6512b81e94442924fbadc7299d4b3a09d9ae70e95bfbd6f352f8c | 974 |
Handling Application Errors
===========================
Applications fail, servers fail. Sooner or later you will see an exception
in production. Even if your code is 100% correct, you will still see
exceptions from time to time. Why? Because everything else involved will
fail. Here are some situations where perfectly... | pallets/flask | 49943b5a94413a530761350f04e896f76e8d620e | docs/errorhandling.rst | reStructuredText | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/docs/errorhandling.rst | BSD-3-Clause | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/LICENSE.txt | 3c08c58a19769fe920325fd0e56efc34d6841d1c228ce4ad1b264ec305550df5 | 4,187 |
Flask Extension Development
===========================
.. currentmodule:: flask
Extensions are extra packages that add functionality to a Flask
application. While `PyPI`_ contains many Flask extensions, you may not
find one that fits your need. If this is the case, you can create your
own, and publish it for others ... | pallets/flask | 49943b5a94413a530761350f04e896f76e8d620e | docs/extensiondev.rst | reStructuredText | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/docs/extensiondev.rst | BSD-3-Clause | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/LICENSE.txt | 581655635ec8eabd90b379f70554528c3b11148196763182eebb8556e43b53db | 2,889 |
Testing Flask Applications
==========================
Flask provides utilities for testing an application. This documentation
goes over techniques for working with different parts of the application
in tests.
We will use the `pytest`_ framework to set up and run our tests.
.. code-block:: text
$ pip install pyt... | pallets/flask | 49943b5a94413a530761350f04e896f76e8d620e | docs/testing.rst | reStructuredText | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/docs/testing.rst | BSD-3-Clause | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/LICENSE.txt | 756a677ef4d1443cc9415787be2077e49d6a611f904b69e1160dd38b4502a066 | 2,390 |
nginx
=====
`nginx`_ is a fast, production level HTTP server. When serving your
application with one of the WSGI servers listed in :doc:`index`, it is
often good or necessary to put a dedicated HTTP server in front of it.
This "reverse proxy" can handle incoming requests, TLS, and other
security and performance concer... | pallets/flask | 49943b5a94413a530761350f04e896f76e8d620e | docs/deploying/nginx.rst | reStructuredText | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/docs/deploying/nginx.rst | BSD-3-Clause | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/LICENSE.txt | baae442b157057d9f331ef8c2de16065cf3de2e5d6f9b0448e8f74912612e666 | 568 |
from __future__ import annotations
import collections.abc as cabc
import logging
import os
import sys
import typing as t
from datetime import timedelta
from itertools import chain
from werkzeug.exceptions import Aborter
from werkzeug.exceptions import BadRequest
from werkzeug.exceptions import BadRequestKeyError
from... | pallets/flask | 49943b5a94413a530761350f04e896f76e8d620e | src/flask/sansio/app.py | Python | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/src/flask/sansio/app.py | BSD-3-Clause | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/LICENSE.txt | cf5df9f2972be7cad9878df7ea321804617d769f47823984abbe0a9b1cbc460b | 8,832 |
Adding a favicon
================
A "favicon" is an icon used by browsers for tabs and bookmarks. This helps
to distinguish your website and to give it a unique brand.
A common question is how to add a favicon to a Flask application. First, of
course, you need an icon. It should be 16 × 16 pixels and in the ICO file
... | pallets/flask | 49943b5a94413a530761350f04e896f76e8d620e | docs/patterns/favicon.rst | reStructuredText | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/docs/patterns/favicon.rst | BSD-3-Clause | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/LICENSE.txt | e05bec2581b68fb72e992de5fbde3203bfc75e4a71611eb1fab8eb1cdda5f69b | 511 |
.. _async_await:
Using ``async`` and ``await``
=============================
.. versionadded:: 2.0
Routes, error handlers, before request, after request, and teardown
functions can all be coroutine functions if Flask is installed with the
``async`` extra (``pip install flask[async]``). This allows views to be
define... | pallets/flask | 49943b5a94413a530761350f04e896f76e8d620e | docs/async-await.rst | reStructuredText | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/docs/async-await.rst | BSD-3-Clause | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/LICENSE.txt | 3bd27302f2664390c705b0f72bc4f84787bb7011ef81a298d65caf2e2789af29 | 1,047 |
.. currentmodule:: flask
Blog Blueprint
==============
You'll use the same techniques you learned about when writing the
authentication blueprint to write the blog blueprint. The blog should
list all posts, allow logged in users to create posts, and allow the
author of a post to edit or delete it.
As you implement e... | pallets/flask | 49943b5a94413a530761350f04e896f76e8d620e | docs/tutorial/blog.rst | reStructuredText | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/docs/tutorial/blog.rst | BSD-3-Clause | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/LICENSE.txt | 7098cddfcfec1e5b85e7cdbac518dc5846687caaf524eb76ae47e03c78955a11 | 2,815 |
Security Considerations
=======================
Web applications face many types of potential security problems, and it can be
hard to get everything right, or even to know what "right" is in general. Flask
tries to solve a few of these things by default, but there are other parts you
may have to take care of yourself... | pallets/flask | 49943b5a94413a530761350f04e896f76e8d620e | docs/web-security.rst | reStructuredText | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/docs/web-security.rst | BSD-3-Clause | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/LICENSE.txt | 75044a9c1f605be3b1914094c019fd4e89316e56fa60f7fcd11929d9b5da3acc | 3,071 |
ASGI
====
If you'd like to use an ASGI server you will need to utilise WSGI to
ASGI middleware. The asgiref
`WsgiToAsgi <https://github.com/django/asgiref#wsgi-to-asgi-adapter>`_
adapter is recommended as it integrates with the event loop used for
Flask's :ref:`async_await` support. You can use the adapter by
wrapping... | pallets/flask | 49943b5a94413a530761350f04e896f76e8d620e | docs/deploying/asgi.rst | reStructuredText | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/docs/deploying/asgi.rst | BSD-3-Clause | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/LICENSE.txt | 794272b10a80d1ff9e700b19c365ae969c94043d0aff2c0555c8fb78c9e837fe | 207 |
from __future__ import annotations
import collections.abc as cabc
import inspect
import os
import sys
import typing as t
import weakref
from datetime import timedelta
from functools import update_wrapper
from inspect import iscoroutinefunction
from itertools import chain
from types import TracebackType
from urllib.par... | pallets/flask | 49943b5a94413a530761350f04e896f76e8d620e | src/flask/app.py | Python | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/src/flask/app.py | BSD-3-Clause | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/LICENSE.txt | 7aa83b45da812d20cdde46e8a84ec7919c6fa222197965f924496d4594f76150 | 14,480 |
# Sans-IO
This folder contains code that can be used by alternative Flask
implementations, for example Quart. The code therefore cannot do any
IO, nor be part of a likely IO path. Finally this code cannot use the
Flask globals.
| pallets/flask | 49943b5a94413a530761350f04e896f76e8d620e | src/flask/sansio/README.md | Markdown | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/src/flask/sansio/README.md | BSD-3-Clause | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/LICENSE.txt | 86d131556c111d01ca60ea07b5d99d0bc2af464f36043a1df63f0b647f3f9c37 | 54 |
Lazily Loading Views
====================
Flask is usually used with the decorators. Decorators are simple and you
have the URL right next to the function that is called for that specific
URL. However there is a downside to this approach: it means all your code
that uses decorators has to be imported upfront or Flas... | pallets/flask | 49943b5a94413a530761350f04e896f76e8d620e | docs/patterns/lazyloading.rst | reStructuredText | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/docs/patterns/lazyloading.rst | BSD-3-Clause | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/LICENSE.txt | cddcdbf43a1c32ff59d890672cf568770e837f53ff8879f62a5796f3e34c5087 | 883 |
from __future__ import annotations
import contextvars
import typing as t
from functools import update_wrapper
from types import TracebackType
from werkzeug.exceptions import HTTPException
from werkzeug.routing import MapAdapter
from . import typing as ft
from .globals import _cv_app
from .helpers import _CollectErro... | pallets/flask | 49943b5a94413a530761350f04e896f76e8d620e | src/flask/ctx.py | Python | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/src/flask/ctx.py | BSD-3-Clause | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/LICENSE.txt | e21952d044159438765eb27848b0fe4c75f83faee8645181a09a1eccb1d5cab7 | 4,150 |
JavaScript, ``fetch``, and JSON
===============================
You may want to make your HTML page dynamic, by changing data without
reloading the entire page. Instead of submitting an HTML ``<form>`` and
performing a redirect to re-render the template, you can add
`JavaScript`_ that calls |fetch|_ and replaces conte... | pallets/flask | 49943b5a94413a530761350f04e896f76e8d620e | docs/patterns/javascript.rst | reStructuredText | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/docs/patterns/javascript.rst | BSD-3-Clause | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/LICENSE.txt | 0390a0d5266b77f82a7efa16a9824b6ce62f1a49001b8ab6004e246ac7a2e689 | 2,173 |
Modular Applications with Blueprints
====================================
.. currentmodule:: flask
.. versionadded:: 0.7
Flask uses a concept of *blueprints* for making application components and
supporting common patterns within an application or across applications.
Blueprints can greatly simplify how large applic... | pallets/flask | 49943b5a94413a530761350f04e896f76e8d620e | docs/blueprints.rst | reStructuredText | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/docs/blueprints.rst | BSD-3-Clause | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/LICENSE.txt | 5e5c3e70b8837c02c446e90ff0ba75e213d2490549f26bd6e8217cc4f499001e | 2,750 |
Waitress
========
`Waitress`_ is a pure Python WSGI server.
* It is easy to configure.
* It supports Windows directly.
* It is easy to install as it does not require additional dependencies
or compilation.
* It does not support streaming requests, full request data is always
buffered.
* It uses a si... | pallets/flask | 49943b5a94413a530761350f04e896f76e8d620e | docs/deploying/waitress.rst | reStructuredText | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/docs/deploying/waitress.rst | BSD-3-Clause | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/LICENSE.txt | 7b8969c54e098fba0166cff4b0942f8d1b97764f7a9a55c6b56415137bb9bdbe | 615 |
Using URL Processors
====================
.. versionadded:: 0.7
Flask 0.7 introduces the concept of URL processors. The idea is that you
might have a bunch of resources with common parts in the URL that you
don't always explicitly want to provide. For instance you might have a
bunch of URLs that have the language c... | pallets/flask | 49943b5a94413a530761350f04e896f76e8d620e | docs/patterns/urlprocessors.rst | reStructuredText | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/docs/patterns/urlprocessors.rst | BSD-3-Clause | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/LICENSE.txt | 816aa72b588023fbed0f46986cd413132040b8d0a144596781cd3c2fd2a865e5 | 999 |
from __future__ import annotations
import collections.abc as cabc
import typing as t
if t.TYPE_CHECKING: # pragma: no cover
from _typeshed.wsgi import WSGIApplication # noqa: F401
from werkzeug.datastructures import Headers # noqa: F401
from werkzeug.sansio.response import Response # noqa: F401
# The... | pallets/flask | 49943b5a94413a530761350f04e896f76e8d620e | src/flask/typing.py | Python | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/src/flask/typing.py | BSD-3-Clause | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/LICENSE.txt | ac3b0f12bf2a89e10c6b8f04d142b6103f9f1495030b8ff2c559d9952e060a00 | 803 |
import time
from celery import shared_task
from celery import Task
@shared_task(ignore_result=False)
def add(a: int, b: int) -> int:
return a + b
@shared_task()
def block() -> None:
time.sleep(5)
@shared_task(bind=True, ignore_result=False)
def process(self: Task, total: int) -> object:
for i in rang... | pallets/flask | 49943b5a94413a530761350f04e896f76e8d620e | examples/celery/src/task_app/tasks.py | Python | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/examples/celery/src/task_app/tasks.py | BSD-3-Clause | https://github.com/pallets/flask/blob/49943b5a94413a530761350f04e896f76e8d620e/LICENSE.txt | d2c365c8ed2f5abf0b5b109361ebe58941559b7d67e57f96d6a6b7bd69970364 | 137 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.