Example #1
0
def _get_inttime(space, w_seconds):
    # w_seconds can be a wrapped None (it will be automatically wrapped
    # in the callers, so we never get a real None here).
    if space.is_w(w_seconds, space.w_None):
        seconds = pytime.time()
    else:
        seconds = space.float_w(w_seconds)
    try:
        ovfcheck_float_to_int(seconds)
    except OverflowError:
        raise OperationError(space.w_ValueError,
                             space.wrap("time argument too large"))
    return rffi.r_time_t(seconds)
def _get_inttime(space, w_seconds):
    # w_seconds can be a wrapped None (it will be automatically wrapped
    # in the callers, so we never get a real None here).
    if space.is_w(w_seconds, space.w_None):
        seconds = pytime.time()
    else:
        seconds = space.float_w(w_seconds)
    try:
        ovfcheck_float_to_int(seconds)
    except OverflowError:
        raise OperationError(space.w_ValueError,
                             space.wrap("time argument too large"))
    return rffi.r_time_t(seconds)
Example #3
0
def _gettmarg(space, w_tup, allowNone=True):
    if allowNone and space.is_w(w_tup, space.w_None):
        # default to the current local time
        tt = rffi.r_time_t(pytime.time())
        t_ref = lltype.malloc(rffi.TIME_TP.TO, 1, flavor='raw')
        t_ref[0] = tt
        pbuf = c_localtime(t_ref)
        lltype.free(t_ref, flavor='raw')
        if not pbuf:
            raise OperationError(space.w_ValueError,
                                 space.wrap(_get_error_msg()))
        return pbuf

    tup_w = space.unpackiterable(w_tup)
    if len(tup_w) != 9:
        raise OperationError(
            space.w_TypeError,
            space.wrap("argument must be sequence of "
                       "length 9, not %d" % len(tup_w)))

    y = space.int_w(tup_w[0])
    rffi.setintfield(glob_buf, 'c_tm_mon', space.int_w(tup_w[1]))
    rffi.setintfield(glob_buf, 'c_tm_mday', space.int_w(tup_w[2]))
    rffi.setintfield(glob_buf, 'c_tm_hour', space.int_w(tup_w[3]))
    rffi.setintfield(glob_buf, 'c_tm_min', space.int_w(tup_w[4]))
    rffi.setintfield(glob_buf, 'c_tm_sec', space.int_w(tup_w[5]))
    rffi.setintfield(glob_buf, 'c_tm_wday', space.int_w(tup_w[6]))
    rffi.setintfield(glob_buf, 'c_tm_yday', space.int_w(tup_w[7]))
    rffi.setintfield(glob_buf, 'c_tm_isdst', space.int_w(tup_w[8]))
    if _POSIX:
        # actually never happens, but makes annotator happy
        glob_buf.c_tm_zone = lltype.nullptr(rffi.CCHARP.TO)
        rffi.setintfield(glob_buf, 'c_tm_gmtoff', 0)

    w_accept2dyear = _get_module_object(space, "accept2dyear")
    accept2dyear = space.int_w(w_accept2dyear)

    if y < 1900:
        if not accept2dyear:
            raise OperationError(space.w_ValueError,
                                 space.wrap("year >= 1900 required"))

        if 69 <= y <= 99:
            y += 1900
        elif 0 <= y <= 68:
            y += 2000
        else:
            raise OperationError(space.w_ValueError,
                                 space.wrap("year out of range"))

    if rffi.getintfield(glob_buf, 'c_tm_wday') < 0:
        raise OperationError(space.w_ValueError,
                             space.wrap("day of week out of range"))

    rffi.setintfield(glob_buf, 'c_tm_year', y - 1900)
    rffi.setintfield(glob_buf, 'c_tm_mon',
                     rffi.getintfield(glob_buf, 'c_tm_mon') - 1)
    rffi.setintfield(glob_buf, 'c_tm_wday',
                     (rffi.getintfield(glob_buf, 'c_tm_wday') + 1) % 7)
    rffi.setintfield(glob_buf, 'c_tm_yday',
                     rffi.getintfield(glob_buf, 'c_tm_yday') - 1)

    return glob_buf
Example #4
0
def _gettmarg(space, w_tup, allowNone=True):
    if allowNone and space.is_w(w_tup, space.w_None):
        # default to the current local time
        tt = rffi.r_time_t(int(pytime.time()))
        t_ref = lltype.malloc(rffi.TIME_TP.TO, 1, flavor="raw")
        t_ref[0] = tt
        pbuf = c_localtime(t_ref)
        lltype.free(t_ref, flavor="raw")
        if not pbuf:
            raise OperationError(space.w_ValueError, space.wrap(_get_error_msg()))
        return pbuf

    tup_w = space.fixedview(w_tup)
    if len(tup_w) != 9:
        raise operationerrfmt(space.w_TypeError, "argument must be sequence of " "length 9, not %d", len(tup_w))

    y = space.int_w(tup_w[0])
    tm_mon = space.int_w(tup_w[1])
    if tm_mon == 0:
        tm_mon = 1
    tm_mday = space.int_w(tup_w[2])
    if tm_mday == 0:
        tm_mday = 1
    tm_yday = space.int_w(tup_w[7])
    if tm_yday == 0:
        tm_yday = 1
    rffi.setintfield(glob_buf, "c_tm_mon", tm_mon)
    rffi.setintfield(glob_buf, "c_tm_mday", tm_mday)
    rffi.setintfield(glob_buf, "c_tm_hour", space.int_w(tup_w[3]))
    rffi.setintfield(glob_buf, "c_tm_min", space.int_w(tup_w[4]))
    rffi.setintfield(glob_buf, "c_tm_sec", space.int_w(tup_w[5]))
    rffi.setintfield(glob_buf, "c_tm_wday", space.int_w(tup_w[6]))
    rffi.setintfield(glob_buf, "c_tm_yday", tm_yday)
    rffi.setintfield(glob_buf, "c_tm_isdst", space.int_w(tup_w[8]))
    if _POSIX:
        # actually never happens, but makes annotator happy
        glob_buf.c_tm_zone = lltype.nullptr(rffi.CCHARP.TO)
        rffi.setintfield(glob_buf, "c_tm_gmtoff", 0)

    w_accept2dyear = _get_module_object(space, "accept2dyear")
    accept2dyear = space.int_w(w_accept2dyear)

    if y < 1900:
        if not accept2dyear:
            raise OperationError(space.w_ValueError, space.wrap("year >= 1900 required"))

        if 69 <= y <= 99:
            y += 1900
        elif 0 <= y <= 68:
            y += 2000
        else:
            raise OperationError(space.w_ValueError, space.wrap("year out of range"))

    if rffi.getintfield(glob_buf, "c_tm_wday") < 0:
        raise OperationError(space.w_ValueError, space.wrap("day of week out of range"))

    rffi.setintfield(glob_buf, "c_tm_year", y - 1900)
    rffi.setintfield(glob_buf, "c_tm_mon", rffi.getintfield(glob_buf, "c_tm_mon") - 1)
    rffi.setintfield(glob_buf, "c_tm_wday", (rffi.getintfield(glob_buf, "c_tm_wday") + 1) % 7)
    rffi.setintfield(glob_buf, "c_tm_yday", rffi.getintfield(glob_buf, "c_tm_yday") - 1)

    return glob_buf