让我们使用grep
进入大球场。我不打算搜索default
,因为我会得到太多结果,但我会尝试Type "Help"
,这不应该出现太多次。如果它是C字符串,则引号将被转义。我们应该首先查找C字符串,然后再查找Python字符串。
Python $ grep 'Type \\"help\\"' . -Ir
./Modules/main.c: "Type \"help\", \"copyright\", \"credits\" or \"license\" " \
它在Modules/main.c
,在Py_Main()
。更多挖给了我们这一行:
fprintf(stderr, "Python %s on %s\n",
Py_GetVersion(), Py_GetPlatform());
因为“的”为格式字符串,Py_GetPlatform()
必须linux
和Py_GetVersion()
必须给我们想要的字符串......
Python $ grep Py_GetVersion . -Irl
...
./Python/getversion.c
...
这看起来很有希望。 ..
PyOS_snprintf(version, sizeof(version), "%.80s (%.80s) %.80s",
PY_VERSION, Py_GetBuildInfo(), Py_GetCompiler());
我们必须要Py_GetBuildInfo()
,因为它的括号内...
Python $ grep Py_GetBuildInfo . -Irl
...
./Modules/getbuildinfo.c
...
这看起来有点太明显。
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;
}
因此,default
是Mercurial分支的名称。通过检查makefiles,我们可以发现这是来自宏HGTAG
。一个名为HGTAG
的makefile变量产生变量,并且该变量作为命令运行。所以,
简单的解决方案
当构建的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.
>>>
您可能需要查看'__DATE__'或'__TIME__'来获取相关的代码。 – 2013-05-02 04:06:47
您可以使用此代码来更改解释器显示的内容 - python -ic'import sys; sys.ps1 =“$”; sys.ps2 =“”' – fixxxer 2013-05-02 04:09:44