##// END OF EJS Templates
hgweb: encode WSGI environment using the ISO-8859-1 codec...
hgweb: encode WSGI environment using the ISO-8859-1 codec The WSGI specification (PEP 3333) specifies that on Python 3 all strings passed by the server must be of type str with code points encodable using the ISO 8859-1 codec. For some reason, I introduced a bug in 2632c1ed8f34 by applying the reverse change. Maybe I got confused because PEP 3333 says that arbitrary operating system environment variables may be contained in the WSGI environment and therefore we need to handle the WSGI environment variables like we would handle operating system environment variables. The bug mentioned in the previous paragraph and fixed by this changeset manifested e.g. in the path of the URL being encoded in the wrong way. Browsers encode non-ASCII bytes with the percent-encoding. WSGI servers will decode the percent-encoded bytes and pass them to the application as strings where each byte is mapped to the corresponding code point with the same ordinal (i.e. it is decoded using the ISO-8859-1 codec). Mercurial uses the bytes type for these strings (which makes much more sense), so we need to encode it again using the ISO-8859-1 codec. If we use another codec, it can result in nonsense.

File last commit:

r46195:426294d0 default
r51713:9ed281bb stable
Show More
main.rs
39 lines | 1.4 KiB | application/rls-services+xml | RustLexer
Gregory Szorc
hgcli: add stub PyOxidizer project...
r45128 use pyembed::MainPythonInterpreter;
// Include an auto-generated file containing the default
// `pyembed::PythonConfig` derived by the PyOxidizer configuration file.
//
// If you do not want to use PyOxidizer to generate this file, simply
// remove this line and instantiate your own instance of
// `pyembed::PythonConfig`.
include!(env!("PYOXIDIZER_DEFAULT_PYTHON_CONFIG_RS"));
fn main() {
Martin von Zweigbergk
rust: move rustfmt.toml to repo root so it can be used by `hg fix`...
r46195 // The following code is in a block so the MainPythonInterpreter is
// destroyed in an orderly manner, before process exit.
Gregory Szorc
hgcli: add stub PyOxidizer project...
r45128 let code = {
Martin von Zweigbergk
rust: move rustfmt.toml to repo root so it can be used by `hg fix`...
r46195 // Load the default Python configuration as derived by the PyOxidizer
// config file used at build time.
Gregory Szorc
hgcli: add stub PyOxidizer project...
r45128 let config = default_python_config();
Martin von Zweigbergk
rust: move rustfmt.toml to repo root so it can be used by `hg fix`...
r46195 // Construct a new Python interpreter using that config, handling any
// errors from construction.
Gregory Szorc
hgcli: add stub PyOxidizer project...
r45128 match MainPythonInterpreter::new(config) {
Ok(mut interp) => {
Martin von Zweigbergk
rust: move rustfmt.toml to repo root so it can be used by `hg fix`...
r46195 // And run it using the default run configuration as specified
// by the configuration. If an uncaught Python
// exception is raised, handle it.
// This includes the special SystemExit, which is a request to
// terminate the process.
Gregory Szorc
hgcli: add stub PyOxidizer project...
r45128 interp.run_as_main()
}
Err(msg) => {
eprintln!("{}", msg);
1
}
}
};
// And exit the process according to code execution results.
std::process::exit(code);
}