-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for datetime extensions
- Loading branch information
1 parent
2bbad7e
commit 215be9c
Showing
15 changed files
with
405 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from libc.stdint cimport uint64_t, uint32_t, uint16_t | ||
from libc.string cimport memcpy | ||
|
||
cdef inline uint64_t load_u64(const void * p): | ||
cdef: | ||
uint64_t res | ||
|
||
res = 0 | ||
memcpy(&res, p, sizeof(res)) | ||
return res | ||
|
||
cdef inline uint64_t load_u32(const void * p): | ||
cdef: | ||
uint32_t res | ||
|
||
res = 0 | ||
memcpy(&res, p, sizeof(res)) | ||
return res | ||
|
||
cdef inline uint64_t load_u16(const void * p): | ||
cdef: | ||
uint16_t res | ||
|
||
res = 0 | ||
memcpy(&res, p, sizeof(res)) | ||
return res | ||
|
||
cdef inline void store_u64(void * p, uint64_t v): | ||
memcpy(p, &v, sizeof(v)) | ||
|
||
cdef inline void store_u32(void * p, uint32_t v): | ||
memcpy(p, &v, sizeof(v)) | ||
|
||
cdef inline void store_u16(void * p, uint16_t v): | ||
memcpy(p, &v, sizeof(v)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,5 @@ DEF SCRAMBLE_SIZE = 20 | |
|
||
DEF SPACE_VSPACE = 281 | ||
DEF SPACE_VINDEX = 289 | ||
|
||
DEF DATETIME_TAIL_SZ = 4 + 2 + 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,31 @@ | ||
from libc.stdint cimport uint32_t, uint8_t | ||
from libc.stdint cimport uint32_t, uint8_t, int64_t, int32_t, int16_t | ||
from libc cimport math | ||
from cpython.datetime cimport datetime | ||
|
||
cdef inline uint32_t bcd_len(uint32_t digits_len): | ||
return <uint32_t> math.floor(digits_len / 2) + 1 | ||
|
||
cdef uint32_t decimal_len(int exponent, uint32_t digits_count) | ||
cdef char *decimal_encode(char *p, uint32_t digits_count, uint8_t sign, tuple digits, int exponent) | ||
cdef object decimal_decode(const char **p, uint32_t length) | ||
cdef char *decimal_encode(char *p, | ||
uint32_t digits_count, | ||
uint8_t sign, | ||
tuple digits, | ||
int exponent) except NULL | ||
cdef object decimal_decode(const char ** p, uint32_t length) | ||
|
||
cdef object uuid_decode(const char **p, uint32_t length) | ||
cdef object uuid_decode(const char ** p, uint32_t length) | ||
|
||
cdef struct IProtoDateTime: | ||
int64_t seconds | ||
int32_t nsec | ||
int16_t tzoffset | ||
int16_t tzindex | ||
|
||
cdef void datetime_zero(IProtoDateTime *dt) | ||
cdef uint32_t datetime_len(IProtoDateTime *dt) | ||
cdef char *datetime_encode(char *p, IProtoDateTime *dt) except NULL | ||
cdef int datetime_decode(const char ** p, | ||
uint32_t length, | ||
IProtoDateTime *dt) except -1 | ||
cdef void datetime_from_py(datetime ob, IProtoDateTime *dt) | ||
cdef object datetime_to_py(IProtoDateTime *dt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,76 @@ | ||
from cpython.version cimport PY_VERSION_HEX | ||
|
||
cdef extern from "Python.h": | ||
char *PyByteArray_AS_STRING(object obj) | ||
int Py_REFCNT(object obj) | ||
|
||
|
||
cdef extern from "datetime.h": | ||
""" | ||
/* Backport for Python 2.x */ | ||
#if PY_MAJOR_VERSION < 3 | ||
#ifndef PyDateTime_DELTA_GET_DAYS | ||
#define PyDateTime_DELTA_GET_DAYS(o) (((PyDateTime_Delta*)o)->days) | ||
#endif | ||
#ifndef PyDateTime_DELTA_GET_SECONDS | ||
#define PyDateTime_DELTA_GET_SECONDS(o) (((PyDateTime_Delta*)o)->seconds) | ||
#endif | ||
#ifndef PyDateTime_DELTA_GET_MICROSECONDS | ||
#define PyDateTime_DELTA_GET_MICROSECONDS(o) (((PyDateTime_Delta*)o)->microseconds) | ||
#endif | ||
#endif | ||
/* Backport for Python < 3.6 */ | ||
#if PY_VERSION_HEX < 0x030600a4 | ||
#ifndef PyDateTime_TIME_GET_FOLD | ||
#define PyDateTime_TIME_GET_FOLD(o) ((void)(o), 0) | ||
#endif | ||
#ifndef PyDateTime_DATE_GET_FOLD | ||
#define PyDateTime_DATE_GET_FOLD(o) ((void)(o), 0) | ||
#endif | ||
#endif | ||
/* Backport for Python < 3.6 */ | ||
#if PY_VERSION_HEX < 0x030600a4 | ||
#define __Pyx_DateTime_DateTimeWithFold(year, month, day, hour, minute, second, microsecond, tz, fold) \ | ||
((void)(fold), PyDateTimeAPI->DateTime_FromDateAndTime(year, month, day, hour, minute, second, \ | ||
microsecond, tz, PyDateTimeAPI->DateTimeType)) | ||
#define __Pyx_DateTime_TimeWithFold(hour, minute, second, microsecond, tz, fold) \ | ||
((void)(fold), PyDateTimeAPI->Time_FromTime(hour, minute, second, microsecond, tz, PyDateTimeAPI->TimeType)) | ||
#else /* For Python 3.6+ so that we can pass tz */ | ||
#define __Pyx_DateTime_DateTimeWithFold(year, month, day, hour, minute, second, microsecond, tz, fold) \ | ||
PyDateTimeAPI->DateTime_FromDateAndTimeAndFold(year, month, day, hour, minute, second, \ | ||
microsecond, tz, fold, PyDateTimeAPI->DateTimeType) | ||
#define __Pyx_DateTime_TimeWithFold(hour, minute, second, microsecond, tz, fold) \ | ||
PyDateTimeAPI->Time_FromTimeAndFold(hour, minute, second, microsecond, tz, fold, PyDateTimeAPI->TimeType) | ||
#endif | ||
/* Backport for Python < 3.7 */ | ||
#if PY_VERSION_HEX < 0x030700b1 | ||
#define __Pyx_TimeZone_UTC NULL | ||
#define __Pyx_TimeZone_FromOffset(offset) ((void)(offset), (PyObject*)NULL) | ||
#define __Pyx_TimeZone_FromOffsetAndName(offset, name) ((void)(offset), (void)(name), (PyObject*)NULL) | ||
#else | ||
#define __Pyx_TimeZone_UTC PyDateTime_TimeZone_UTC | ||
#define __Pyx_TimeZone_FromOffset(offset) PyTimeZone_FromOffset(offset) | ||
#define __Pyx_TimeZone_FromOffsetAndName(offset, name) PyTimeZone_FromOffsetAndName(offset, name) | ||
#endif | ||
/* Backport for Python < 3.10 */ | ||
#if PY_VERSION_HEX < 0x030a00a1 | ||
#ifndef PyDateTime_TIME_GET_TZINFO | ||
#define PyDateTime_TIME_GET_TZINFO(o) \ | ||
((((PyDateTime_Time*)o)->hastzinfo) ? ((PyDateTime_Time*)o)->tzinfo : Py_None) | ||
#endif | ||
#ifndef PyDateTime_DATE_GET_TZINFO | ||
#define PyDateTime_DATE_GET_TZINFO(o) \ | ||
((((PyDateTime_DateTime*)o)->hastzinfo) ? ((PyDateTime_DateTime*)o)->tzinfo : Py_None) | ||
#endif | ||
#endif | ||
""" | ||
|
||
# The above macros is Python 3.7+ so we use these instead | ||
object __Pyx_TimeZone_FromOffset(object offset) | ||
|
||
|
||
cdef inline object timezone_new(object offset): | ||
if PY_VERSION_HEX < 0x030700b1: | ||
from datetime import timezone | ||
return timezone(offset) | ||
return __Pyx_TimeZone_FromOffset(offset) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ Sphinx | |
sphinx_rtd_theme | ||
sphinxcontrib-asyncio | ||
coverage | ||
pytz | ||
python-dateutil |
Oops, something went wrong.