Usiamo grep
per entrare nell'arena. Non ho intenzione di preoccuparmi di cercare default
perché otterrò troppi risultati, ma proverò Type "Help"
, che non dovrebbe apparire troppe volte. Se è una stringa C, le virgolette saranno sfuggite. Dovremmo cercare le stringhe C prima e le stringhe Python in seguito.
Python $ grep 'Type \\"help\\"' . -Ir
./Modules/main.c: "Type \"help\", \"copyright\", \"credits\" or \"license\" " \
E 'in Modules/main.c
, in Py_Main()
. Più scavo ci dà questa linea:
fprintf(stderr, "Python %s on %s\n",
Py_GetVersion(), Py_GetPlatform());
Perché "on" è nella stringa di formato, Py_GetPlatform()
deve essere linux
e Py_GetVersion()
deve dare la stringa che vogliamo ...
Python $ grep Py_GetVersion . -Irl
...
./Python/getversion.c
...
Questo sembra essere molto promettente. ..
PyOS_snprintf(version, sizeof(version), "%.80s (%.80s) %.80s",
PY_VERSION, Py_GetBuildInfo(), Py_GetCompiler());
Dobbiamo volere Py_GetBuildInfo()
, perché è all'interno delle parentesi ...
Python $ grep Py_GetBuildInfo . -Irl
...
./Modules/getbuildinfo.c
...
Questo sembra un po 'troppo ovvio.
const char *
Py_GetBuildInfo(void)
{
static char buildinfo[50 + sizeof(HGVERSION) +
((sizeof(HGTAG) > sizeof(HGBRANCH)) ?
sizeof(HGTAG) : sizeof(HGBRANCH))];
const char *revision = _Py_hgversion();
const char *sep = *revision ? ":" : "";
const char *hgid = _Py_hgidentifier();
if (!(*hgid))
hgid = "default";
PyOS_snprintf(buildinfo, sizeof(buildinfo),
"%s%s%s, %.20s, %.9s", hgid, sep, revision,
DATE, TIME);
return buildinfo;
}
Quindi, default
è il nome del ramo Mercurial. Esaminando i makefile, possiamo capire che questo proviene dalla macro HGTAG
. Una variabile makefile denominata HGTAG
produce la variabile e tale variabile viene eseguita come un comando. Così,
Soluzione semplice
Quando si costruisce Python,
Python $ ./configure
Python $ make HGTAG='echo awesome'
Python $ ./python
Python 3.2.3 (awesome, May 1 2013, 21:33:27)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
Probabilmente si potrebbe ack per '__DATE__' o' __TIME__' per ottenere il codice relativo. –
Puoi usare questo codice per cambiare ciò che mostra l'interprete - python -ic 'import sys; sys.ps1 = "$"; sys.ps2 = "" ' – fixxxer