コード例 #1
0
ファイル: importer.py プロジェクト: mtmiller/hy
def write_hy_as_pyc(fname):
    with open(fname, 'U') as f:
        try:
            st = os.fstat(f.fileno())
        except AttributeError:
            st = os.stat(fname)
        timestamp = long_type(st.st_mtime)

    _ast = import_file_to_ast(fname,
                              os.path.basename(os.path.splitext(fname)[0]))
    code = ast_compile(_ast, fname, "exec")
    cfile = "%s.pyc" % fname[:-len(".hy")]

    open_ = builtins.open

    with open_(cfile, 'wb') as fc:
        if PY3:
            fc.write(b'\0\0\0\0')
        else:
            fc.write('\0\0\0\0')
        wr_long(fc, timestamp)
        if PY33:
            wr_long(fc, st.st_size)
        marshal.dump(code, fc)
        fc.flush()
        fc.seek(0, 0)
        fc.write(MAGIC)
コード例 #2
0
ファイル: importer.py プロジェクト: mtmiller/hy
def write_hy_as_pyc(fname):
    with open(fname, 'U') as f:
        try:
            st = os.fstat(f.fileno())
        except AttributeError:
            st = os.stat(fname)
        timestamp = long_type(st.st_mtime)

    _ast = import_file_to_ast(fname,
                              os.path.basename(os.path.splitext(fname)[0]))
    code = ast_compile(_ast, fname, "exec")
    cfile = "%s.pyc" % fname[:-len(".hy")]

    open_ = builtins.open

    with open_(cfile, 'wb') as fc:
        if PY3:
            fc.write(b'\0\0\0\0')
        else:
            fc.write('\0\0\0\0')
        wr_long(fc, timestamp)
        if PY33:
            wr_long(fc, st.st_size)
        marshal.dump(code, fc)
        fc.flush()
        fc.seek(0, 0)
        fc.write(MAGIC)
コード例 #3
0
def write_code_as_pyc(fname, code):
    st = os.stat(fname)
    timestamp = long_type(st.st_mtime)

    cfile = get_bytecode_path(fname)
    try:
        os.makedirs(os.path.dirname(cfile))
    except (IOError, OSError):
        pass

    with builtins.open(cfile, 'wb') as fc:
        fc.write(MAGIC)
        wr_long(fc, timestamp)
        if PY3:
            wr_long(fc, st.st_size)
        marshal.dump(code, fc)
コード例 #4
0
ファイル: importer.py プロジェクト: Tritlo/hy
def write_code_as_pyc(fname, code):
    st = os.stat(fname)
    timestamp = long_type(st.st_mtime)

    cfile = get_bytecode_path(fname)
    try:
        os.makedirs(os.path.dirname(cfile))
    except (IOError, OSError):
        pass

    with builtins.open(cfile, 'wb') as fc:
        fc.write(MAGIC)
        wr_long(fc, timestamp)
        if PY3:
            wr_long(fc, st.st_size)
        marshal.dump(code, fc)
コード例 #5
0
ファイル: importer.py プロジェクト: waigx/hy
def write_code_as_pyc(fname, code):
    st = os.stat(fname)
    timestamp = long_type(st.st_mtime)

    cfile = get_bytecode_path(fname)
    try:
        os.makedirs(os.path.dirname(cfile))
    except (IOError, OSError):
        pass

    with builtins.open(cfile, 'wb') as fc:
        fc.write(MAGIC)
        if PY37:
            # With PEP 552, the header structure has a new flags field
            # that we need to fill in. All zeros preserve the legacy
            # behaviour, but should we implement reproducible builds,
            # this is where we'd add the information.
            wr_long(fc, 0)
        wr_long(fc, timestamp)
        if PY3:
            wr_long(fc, st.st_size)
        marshal.dump(code, fc)
コード例 #6
0
ファイル: importer.py プロジェクト: tuturto/hy
def write_code_as_pyc(fname, code):
    st = os.stat(fname)
    timestamp = long_type(st.st_mtime)

    cfile = get_bytecode_path(fname)
    try:
        os.makedirs(os.path.dirname(cfile))
    except (IOError, OSError):
        pass

    with builtins.open(cfile, 'wb') as fc:
        fc.write(MAGIC)
        if PY37:
            # With PEP 552, the header structure has a new flags field
            # that we need to fill in. All zeros preserve the legacy
            # behaviour, but should we implement reproducible builds,
            # this is where we'd add the information.
            wr_long(fc, 0)
        wr_long(fc, timestamp)
        if PY3:
            wr_long(fc, st.st_size)
        marshal.dump(code, fc)