easy_install.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:micro-blog 作者: nickChenyx 项目源码 文件源码
def get_script_header(script_text, executable=sys_executable, wininst=False):
    """Create a #! line, getting options (if any) from script_text"""
    from distutils.command.build_scripts import first_line_re

    # first_line_re in Python >=3.1.4 and >=3.2.1 is a bytes pattern.
    if not isinstance(first_line_re.pattern, str):
        first_line_re = re.compile(first_line_re.pattern.decode())

    first = (script_text+'\n').splitlines()[0]
    match = first_line_re.match(first)
    options = ''
    if match:
        options = match.group(1) or ''
        if options: options = ' '+options
    if wininst:
        executable = "python.exe"
    else:
        executable = nt_quote_arg(executable)
    hdr = "#!%(executable)s%(options)s\n" % locals()
    if not isascii(hdr):
        # Non-ascii path to sys.executable, use -x to prevent warnings
        if options:
            if options.strip().startswith('-'):
                options = ' -x'+options.strip()[1:]
            # else: punt, we can't do it, let the warning happen anyway
        else:
            options = ' -x'
    executable = fix_jython_executable(executable, options)
    hdr = "#!%(executable)s%(options)s\n" % locals()
    return hdr
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号