示例#1
0
文件: integer.py 项目: FMNSSun/hy
 def __new__(cls, number, *args, **kwargs):
     if isinstance(number, str_type):
         bases = {"0x": 16, "0o": 8, "0b": 2}
         for leader, base in bases.items():
             if number.startswith(leader):
                 # We've got a string, known leader, set base.
                 number = long_type(number, base=base)
                 break
         else:
             # We've got a string, no known leader; base 10.
             number = long_type(number, base=10)
     else:
         # We've got a non-string; convert straight.
         number = long_type(number)
     return super(HyInteger, cls).__new__(cls, number)
示例#2
0
 def __new__(cls, number, *args, **kwargs):
     if isinstance(number, str_type):
         bases = {"0x": 16, "0o": 8, "0b": 2}
         for leader, base in bases.items():
             if number.startswith(leader):
                 # We've got a string, known leader, set base.
                 number = long_type(number, base=base)
                 break
         else:
             # We've got a string, no known leader; base 10.
             number = long_type(number, base=10)
     else:
         # We've got a non-string; convert straight.
         number = long_type(number)
     return super(HyInteger, cls).__new__(cls, number)
示例#3
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)
示例#4
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)
示例#5
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)
示例#6
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)
示例#7
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)
示例#8
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)
示例#9
0
文件: test_models.py 项目: Tritlo/hy
def test_replace_long_type():
    """ Test replacing integers."""
    replaced = replace_hy_obj(long_type(0), HyInteger(13))
    assert replaced == HyInteger(0)
示例#10
0
文件: test_models.py 项目: Tritlo/hy
def test_wrap_nested_expr():
    """ Test conversion of HyExpressions with embedded non-HyObjects."""
    wrapped = wrap_value(HyExpression([long_type(0)]))
    assert type(wrapped) == HyExpression
    assert type(wrapped[0]) == HyInteger
    assert wrapped == HyExpression([HyInteger(0)])
示例#11
0
def test_replace_tuple():
    """ Test replacing tuples."""
    replaced = replace_hy_obj((long_type(0), ), HyInteger(13))
    assert type(replaced) == HyList
    assert type(replaced[0]) == HyInteger
    assert replaced == HyList([HyInteger(0)])
示例#12
0
def test_wrap_nested_expr():
    """ Test conversion of HyExpressions with embedded non-HyObjects."""
    wrapped = wrap_value(HyExpression([long_type(0)]))
    assert type(wrapped) == HyExpression
    assert type(wrapped[0]) == HyInteger
    assert wrapped == HyExpression([HyInteger(0)])
示例#13
0
def test_wrap_long_type():
    """ Test conversion of integers."""
    wrapped = wrap_value(long_type(0))
    assert type(wrapped) == HyInteger
示例#14
0
文件: integer.py 项目: mtmiller/hy
 def __new__(cls, number, *args, **kwargs):
     number = long_type(number)
     return super(HyInteger, cls).__new__(cls, number)
示例#15
0
文件: integer.py 项目: Foxboron/hy
 def __new__(cls, number, *args, **kwargs):
     number = long_type(number)
     return super(HyInteger, cls).__new__(cls, number)
示例#16
0
文件: test_models.py 项目: Tritlo/hy
def test_replace_tuple():
    """ Test replacing tuples."""
    replaced = replace_hy_obj((long_type(0), ), HyInteger(13))
    assert type(replaced) == HyList
    assert type(replaced[0]) == HyInteger
    assert replaced == HyList([HyInteger(0)])
示例#17
0
文件: test_models.py 项目: Tritlo/hy
def test_wrap_long_type():
    """ Test conversion of integers."""
    wrapped = wrap_value(long_type(0))
    assert type(wrapped) == HyInteger
示例#18
0
def test_replace_long_type():
    """ Test replacing integers."""
    replaced = replace_hy_obj(long_type(0), HyInteger(13))
    assert replaced == HyInteger(0)