예제 #1
0
파일: cdatetime.py 프로젝트: njues/Sypy
def PyDateTime_FromTimestamp(space, w_args):
    """Create and return a new datetime.datetime object given an argument tuple
    suitable for passing to datetime.datetime.fromtimestamp().
    """
    w_datetime = PyImport_Import(space, space.wrap("datetime"))
    w_type = space.getattr(w_datetime, space.wrap("datetime"))
    w_method = space.getattr(w_type, space.wrap("fromtimestamp"))
    return space.call(w_method, w_args)
예제 #2
0
파일: cdatetime.py 프로젝트: sota/pypy-old
def PyDate_FromDate(space, year, month, day):
    """Return a datetime.date object with the specified year, month and day.
    """
    year = rffi.cast(lltype.Signed, year)
    month = rffi.cast(lltype.Signed, month)
    day = rffi.cast(lltype.Signed, day)
    w_datetime = PyImport_Import(space, space.wrap("datetime"))
    return space.call_method(w_datetime, "date", space.wrap(year),
                             space.wrap(month), space.wrap(day))
예제 #3
0
파일: cdatetime.py 프로젝트: zcxowwww/pypy
def _PyDateTime_Import(space):
    state = space.fromcache(State)
    if len(state.datetimeAPI) > 0:
        return state.datetimeAPI[0]
    datetimeAPI = lltype.malloc(PyDateTime_CAPI, flavor='raw',
                                track_allocation=False)

    w_datetime = PyImport_Import(space, space.newtext("datetime"))

    w_type = space.getattr(w_datetime, space.newtext("date"))
    datetimeAPI.c_DateType = rffi.cast(
        PyTypeObjectPtr, make_ref(space, w_type))
    # convenient place to modify this, needed since the make_typedescr attach
    # links the "wrong" struct to W_DateTime_Date, which in turn is needed
    # because datetime, with a tzinfo entry, inherits from date, without one
    datetimeAPI.c_DateType.c_tp_basicsize = rffi.sizeof(PyObject.TO)

    w_type = space.getattr(w_datetime, space.newtext("datetime"))
    datetimeAPI.c_DateTimeType = rffi.cast(
        PyTypeObjectPtr, make_ref(space, w_type))

    w_type = space.getattr(w_datetime, space.newtext("time"))
    datetimeAPI.c_TimeType = rffi.cast(
        PyTypeObjectPtr, make_ref(space, w_type))

    w_type = space.getattr(w_datetime, space.newtext("timedelta"))
    datetimeAPI.c_DeltaType = rffi.cast(
        PyTypeObjectPtr, make_ref(space, w_type))

    w_type = space.getattr(w_datetime, space.newtext("tzinfo"))
    datetimeAPI.c_TZInfoType = rffi.cast(
        PyTypeObjectPtr, make_ref(space, w_type))

    datetimeAPI.c_Date_FromDate = llhelper(
        _PyDate_FromDate.api_func.functype,
        _PyDate_FromDate.api_func.get_wrapper(space))
    datetimeAPI.c_Time_FromTime = llhelper(
        _PyTime_FromTime.api_func.functype,
        _PyTime_FromTime.api_func.get_wrapper(space))
    datetimeAPI.c_DateTime_FromDateAndTime = llhelper(
        _PyDateTime_FromDateAndTime.api_func.functype,
        _PyDateTime_FromDateAndTime.api_func.get_wrapper(space))
    datetimeAPI.c_Delta_FromDelta = llhelper(
        _PyDelta_FromDelta.api_func.functype,
        _PyDelta_FromDelta.api_func.get_wrapper(space))

    datetimeAPI.c_DateTime_FromTimestamp = llhelper(
        _PyDateTime_FromTimestamp.api_func.functype,
        _PyDateTime_FromTimestamp.api_func.get_wrapper(space))

    datetimeAPI.c_Date_FromTimestamp = llhelper(
        _PyDate_FromTimestamp.api_func.functype,
        _PyDate_FromTimestamp.api_func.get_wrapper(space))

    state.datetimeAPI.append(datetimeAPI)
    return state.datetimeAPI[0]
예제 #4
0
파일: cdatetime.py 프로젝트: sota/pypy-old
def PyTime_FromTime(space, hour, minute, second, usecond):
    """Return a ``datetime.time`` object with the specified hour, minute, second and
    microsecond."""
    hour = rffi.cast(lltype.Signed, hour)
    minute = rffi.cast(lltype.Signed, minute)
    second = rffi.cast(lltype.Signed, second)
    usecond = rffi.cast(lltype.Signed, usecond)
    w_datetime = PyImport_Import(space, space.wrap("datetime"))
    return space.call_method(w_datetime, "time", space.wrap(hour),
                             space.wrap(minute), space.wrap(second),
                             space.wrap(usecond))
예제 #5
0
파일: cdatetime.py 프로젝트: sota/pypy-old
def PyDelta_FromDSU(space, days, seconds, useconds):
    """Return a datetime.timedelta object representing the given number of days,
    seconds and microseconds.  Normalization is performed so that the resulting
    number of microseconds and seconds lie in the ranges documented for
    datetime.timedelta objects.
    """
    days = rffi.cast(lltype.Signed, days)
    seconds = rffi.cast(lltype.Signed, seconds)
    useconds = rffi.cast(lltype.Signed, useconds)
    w_datetime = PyImport_Import(space, space.wrap("datetime"))
    return space.call_method(w_datetime, "timedelta", space.wrap(days),
                             space.wrap(seconds), space.wrap(useconds))
예제 #6
0
파일: cdatetime.py 프로젝트: sota/pypy-old
def PyDateTime_FromDateAndTime(space, year, month, day, hour, minute, second,
                               usecond):
    """Return a datetime.datetime object with the specified year, month, day, hour,
    minute, second and microsecond.
    """
    year = rffi.cast(lltype.Signed, year)
    month = rffi.cast(lltype.Signed, month)
    day = rffi.cast(lltype.Signed, day)
    hour = rffi.cast(lltype.Signed, hour)
    minute = rffi.cast(lltype.Signed, minute)
    second = rffi.cast(lltype.Signed, second)
    usecond = rffi.cast(lltype.Signed, usecond)
    w_datetime = PyImport_Import(space, space.wrap("datetime"))
    return space.call_method(w_datetime, "datetime", space.wrap(year),
                             space.wrap(month), space.wrap(day),
                             space.wrap(hour), space.wrap(minute),
                             space.wrap(second), space.wrap(usecond))
예제 #7
0
def PyErr_WarnEx(space, w_category, message_ptr, stacklevel):
    """Issue a warning message.  The category argument is a warning category (see
    below) or NULL; the message argument is a message string.  stacklevel is a
    positive number giving a number of stack frames; the warning will be issued from
    the  currently executing line of code in that stack frame.  A stacklevel of 1
    is the function calling PyErr_WarnEx(), 2 is  the function above that,
    and so forth.

    This function normally prints a warning message to sys.stderr; however, it is
    also possible that the user has specified that warnings are to be turned into
    errors, and in that case this will raise an exception.  It is also possible that
    the function raises an exception because of a problem with the warning machinery
    (the implementation imports the warnings module to do the heavy lifting).
    The return value is 0 if no exception is raised, or -1 if an exception
    is raised.  (It is not possible to determine whether a warning message is
    actually printed, nor what the reason is for the exception; this is
    intentional.)  If an exception is raised, the caller should do its normal
    exception handling (for example, Py_DECREF() owned references and return
    an error value).

    Warning categories must be subclasses of Warning; the default warning
    category is RuntimeWarning.  The standard Python warning categories are
    available as global variables whose names are PyExc_ followed by the Python
    exception name. These have the type PyObject*; they are all class
    objects. Their names are PyExc_Warning, PyExc_UserWarning,
    PyExc_UnicodeWarning, PyExc_DeprecationWarning,
    PyExc_SyntaxWarning, PyExc_RuntimeWarning, and
    PyExc_FutureWarning.  PyExc_Warning is a subclass of
    PyExc_Exception; the other warning categories are subclasses of
    PyExc_Warning.

    For information about warning control, see the documentation for the
    warnings module and the -W option in the command line
    documentation.  There is no C API for warning control."""
    if w_category is None:
        w_category = space.w_None
    w_message = space.newtext(rffi.charp2str(message_ptr))
    w_stacklevel = space.newint(rffi.cast(lltype.Signed, stacklevel))

    w_module = PyImport_Import(space, space.newtext("warnings"))
    w_warn = space.getattr(w_module, space.newtext("warn"))
    space.call_function(w_warn, w_message, w_category, w_stacklevel)
    return 0
예제 #8
0
def _PyDateTime_Import(space):
    datetimeAPI = lltype.malloc(PyDateTime_CAPI,
                                flavor='raw',
                                track_allocation=False)

    w_datetime = PyImport_Import(space, space.newtext("datetime"))

    w_type = space.getattr(w_datetime, space.newtext("date"))
    datetimeAPI.c_DateType = rffi.cast(PyTypeObjectPtr,
                                       make_ref(space, w_type))

    w_type = space.getattr(w_datetime, space.newtext("datetime"))
    datetimeAPI.c_DateTimeType = rffi.cast(PyTypeObjectPtr,
                                           make_ref(space, w_type))

    w_type = space.getattr(w_datetime, space.newtext("time"))
    datetimeAPI.c_TimeType = rffi.cast(PyTypeObjectPtr,
                                       make_ref(space, w_type))

    w_type = space.getattr(w_datetime, space.newtext("timedelta"))
    datetimeAPI.c_DeltaType = rffi.cast(PyTypeObjectPtr,
                                        make_ref(space, w_type))

    w_type = space.getattr(w_datetime, space.newtext("tzinfo"))
    datetimeAPI.c_TZInfoType = rffi.cast(PyTypeObjectPtr,
                                         make_ref(space, w_type))

    datetimeAPI.c_Date_FromDate = llhelper(
        _PyDate_FromDate.api_func.functype,
        _PyDate_FromDate.api_func.get_wrapper(space))
    datetimeAPI.c_Time_FromTime = llhelper(
        _PyTime_FromTime.api_func.functype,
        _PyTime_FromTime.api_func.get_wrapper(space))
    datetimeAPI.c_DateTime_FromDateAndTime = llhelper(
        _PyDateTime_FromDateAndTime.api_func.functype,
        _PyDateTime_FromDateAndTime.api_func.get_wrapper(space))
    datetimeAPI.c_Delta_FromDelta = llhelper(
        _PyDelta_FromDelta.api_func.functype,
        _PyDelta_FromDelta.api_func.get_wrapper(space))

    return datetimeAPI
예제 #9
0
파일: cdatetime.py 프로젝트: njues/Sypy
def _PyDateTime_Import(space):
    datetimeAPI = lltype.malloc(PyDateTime_CAPI, flavor='raw',
                                track_allocation=False)

    w_datetime = PyImport_Import(space, space.wrap("datetime"))

    w_type = space.getattr(w_datetime, space.wrap("date"))
    datetimeAPI.c_DateType = rffi.cast(
        PyTypeObjectPtr, make_ref(space, w_type))

    w_type = space.getattr(w_datetime, space.wrap("datetime"))
    datetimeAPI.c_DateTimeType = rffi.cast(
        PyTypeObjectPtr, make_ref(space, w_type))

    w_type = space.getattr(w_datetime, space.wrap("time"))
    datetimeAPI.c_TimeType = rffi.cast(
        PyTypeObjectPtr, make_ref(space, w_type))

    w_type = space.getattr(w_datetime, space.wrap("timedelta"))
    datetimeAPI.c_DeltaType = rffi.cast(
        PyTypeObjectPtr, make_ref(space, w_type))

    return datetimeAPI
예제 #10
0
def fill_Py_buffer(space, buf, view):
    # c_buf, c_obj have been filled in
    ndim = buf.getndim()
    view.c_len = buf.getlength()
    view.c_itemsize = buf.getitemsize()
    rffi.setintfield(view, 'c_ndim', ndim)
    view.c_format = rffi.cast(rffi.CCHARP, view.c__format)
    fmt = buf.getformat()
    n = Py_MAX_FMT - 1  # NULL terminated buffer
    if len(fmt) > n:
        w_message = space.newbytes(
            "PyPy specific Py_MAX_FMT is %d which is too "
            "small for buffer format, %d needed" % (Py_MAX_FMT, len(fmt)))
        w_stacklevel = space.newint(1)
        w_module = PyImport_Import(space, space.newbytes("warnings"))
        w_warn = space.getattr(w_module, space.newbytes("warn"))
        space.call_function(w_warn, w_message, space.w_None, w_stacklevel)
    else:
        n = len(fmt)
    for i in range(n):
        view.c_format[i] = fmt[i]
    view.c_format[n] = '\x00'
    if ndim > 0:
        view.c_shape = rffi.cast(Py_ssize_tP, view.c__shape)
        view.c_strides = rffi.cast(Py_ssize_tP, view.c__strides)
        shape = buf.getshape()
        strides = buf.getstrides()
        for i in range(ndim):
            view.c_shape[i] = shape[i]
            view.c_strides[i] = strides[i]
    else:
        view.c_shape = lltype.nullptr(Py_ssize_tP.TO)
        view.c_strides = lltype.nullptr(Py_ssize_tP.TO)
    view.c_suboffsets = lltype.nullptr(Py_ssize_tP.TO)
    view.c_internal = lltype.nullptr(rffi.VOIDP.TO)
    return 0