Esempio n. 1
0
def gettimeofday(interp, as_float=False):

    space = interp.space

    void = lltype.nullptr(rffi.VOIDP.TO)
    timeval = lltype.malloc(timelib.timeval, flavor='raw')

    timelib.c_gettimeofday(timeval, void)

    if as_float:
        return space.wrap(
            intmask(timeval.c_tv_sec) +
            intmask(timeval.c_tv_usec) / 1000000.00)

    timelib_timezone = interp.get_default_timezone(
        "gettimeofday").timelib_timezone
    offset = timelib.timelib_get_time_zone_info(timeval.c_tv_sec,
                                                timelib_timezone)

    return space.new_array_from_pairs([
        (space.wrap('sec'), space.wrap(intmask(timeval.c_tv_sec))),
        (space.wrap('usec'), space.wrap(intmask(timeval.c_tv_usec))),
        (space.wrap('minuteswest'),
         space.wrap(-intmask(offset.c_offset) / 60)),
        (space.wrap('dsttime'), space.wrap(intmask(offset.c_is_dst))),
    ])
Esempio n. 2
0
def uniqid(space, prefix='', more_entropy=False):
    """ Generate a unique ID"""

    timeval = lltype.malloc(timelib.timeval, flavor='raw')
    void = lltype.nullptr(rffi.VOIDP.TO)
    timelib.c_gettimeofday(timeval, void)
    sec = intmask(timeval.c_tv_sec)
    usec = intmask(timeval.c_tv_usec)
    builder = StringBuilder()
    if prefix:
        builder.append(prefix)
    builder.append(_zero_pad(hex(sec)[2:], 8))
    builder.append(_zero_pad(hex(usec)[2:], 5))
    if more_entropy:
        builder.append(".")
        builder.append(str(_random.random())[2:11])
    return space.newstr(builder.build())
Esempio n. 3
0
def uniqid(space, prefix='', more_entropy=False):
    """ Generate a unique ID"""

    timeval = lltype.malloc(timelib.timeval, flavor='raw')
    void = lltype.nullptr(rffi.VOIDP.TO)
    timelib.c_gettimeofday(timeval, void)
    sec = intmask(timeval.c_tv_sec)
    usec = intmask(timeval.c_tv_usec)
    builder = StringBuilder()
    if prefix:
        builder.append(prefix)
    builder.append(_zero_pad(hex(sec)[2:], 8))
    builder.append(_zero_pad(hex(usec)[2:], 5))
    if more_entropy:
        builder.append(".")
        builder.append(str(_random.random())[2:11])
    return space.newstr(builder.build())
Esempio n. 4
0
def gettimeofday(interp, as_float=False):

    space = interp.space

    void = lltype.nullptr(rffi.VOIDP.TO)
    timeval = lltype.malloc(timelib.timeval, flavor='raw')

    timelib.c_gettimeofday(timeval, void)

    if as_float:
        return space.wrap(intmask(timeval.c_tv_sec) + intmask(timeval.c_tv_usec) / 1000000.00)

    timelib_timezone = interp.get_default_timezone("gettimeofday").timelib_timezone
    offset = timelib.timelib_get_time_zone_info(timeval.c_tv_sec, timelib_timezone)

    return space.new_array_from_pairs([
            (space.wrap('sec'), space.wrap(intmask(timeval.c_tv_sec))),
            (space.wrap('usec'), space.wrap(intmask(timeval.c_tv_usec))),
            (space.wrap('minuteswest'), space.wrap(-intmask(offset.c_offset) / 60)),
            (space.wrap('dsttime'), space.wrap(intmask(offset.c_is_dst))),
        ])