Skip to content

Commit

Permalink
version 1.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lekma committed Sep 13, 2021
1 parent f16737c commit caec14a
Show file tree
Hide file tree
Showing 8 changed files with 309 additions and 176 deletions.
2 changes: 1 addition & 1 deletion mood/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

#
# Copyright © 2020 Malek Hadj-Ali
# Copyright © 2021 Malek Hadj-Ali
# All rights reserved.
#
# This file is part of mood.
Expand Down
88 changes: 45 additions & 43 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

#
# Copyright © 2020 Malek Hadj-Ali
# Copyright © 2021 Malek Hadj-Ali
# All rights reserved.
#
# This file is part of mood.
Expand All @@ -27,57 +27,59 @@


pkg_name = "mood.msgpack"
pkg_version = "1.5.0"
pkg_version = "1.5.1"
pkg_desc = "Python MessagePack implementation"

PKG_VERSION = ("PKG_VERSION", "\"{0}\"".format(pkg_version))


setup(
name=pkg_name,
version=pkg_version,
description=pkg_desc,
long_description=open(abspath("README.txt"), encoding="utf-8").read(),
long_description_content_type="text",
name=pkg_name,
version=pkg_version,
description=pkg_desc,
long_description=open(abspath("README.txt"), encoding="utf-8").read(),
long_description_content_type="text",

url="https://github.com/lekma/mood.msgpack",
download_url="https://github.com/lekma/mood.msgpack/releases",
project_urls={
"Bug Tracker": "https://github.com/lekma/mood.msgpack/issues"
},
author="Malek Hadj-Ali",
author_email="lekmalek@gmail.com",
license="GNU General Public License v3 (GPLv3)",
platforms=["POSIX"],
keywords="messagepack msgpack",
url="https://github.com/lekma/mood.msgpack",
download_url="https://github.com/lekma/mood.msgpack/releases",
project_urls={
"Bug Tracker": "https://github.com/lekma/mood.msgpack/issues"
},
author="Malek Hadj-Ali",
author_email="lekmalek@gmail.com",
license="GNU General Public License v3 (GPLv3)",
platforms=["POSIX"],
keywords="messagepack msgpack",

setup_requires = ["setuptools>=24.2.0"],
python_requires="~=3.8",
packages=find_packages(),
namespace_packages=["mood"],
zip_safe=False,
setup_requires = ["setuptools>=24.2.0"],
python_requires="~=3.8",
packages=find_packages(),
namespace_packages=["mood"],
zip_safe=False,

ext_package="mood",
ext_modules=[
Extension("msgpack",
[
"src/helpers/helpers.c",
"src/timestamp.c",
"src/pack.c",
"src/object.c",
"src/unpack.c",
"src/msgpack.c"
],
define_macros=[PKG_VERSION])
],
ext_package="mood",
ext_modules=[
Extension(
"msgpack",
[
"src/helpers/helpers.c",
"src/timestamp.c",
"src/pack.c",
"src/object.c",
"src/unpack.c",
"src/msgpack.c"
],
define_macros=[PKG_VERSION]
)
],

classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Operating System :: POSIX",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: Implementation :: CPython"
]
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
"Operating System :: POSIX",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: Implementation :: CPython"
]
)

30 changes: 19 additions & 11 deletions src/msgpack.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
#
# Copyright © 2020 Malek Hadj-Ali
# Copyright © 2021 Malek Hadj-Ali
# All rights reserved.
#
# This file is part of mood.
Expand Down Expand Up @@ -52,8 +52,10 @@ msgpack_register(PyObject *module, PyObject *obj)
{
module_state *state = NULL;

if (!(state = _PyModule_GetState(module)) ||
RegisterObject(state->registry, obj)) {
if (
!(state = _PyModule_GetState(module)) ||
RegisterObject(state->registry, obj)
) {
return NULL;
}
Py_RETURN_NONE;
Expand Down Expand Up @@ -81,12 +83,18 @@ msgpack_unpack(PyObject *module, PyObject *args)

/* msgpack_def.m_methods */
static PyMethodDef msgpack_m_methods[] = {
{"pack", (PyCFunction)msgpack_pack,
METH_O, msgpack_pack_doc},
{"register", (PyCFunction)msgpack_register,
METH_O, msgpack_register_doc},
{"unpack", (PyCFunction)msgpack_unpack,
METH_VARARGS, msgpack_unpack_doc},
{
"pack", (PyCFunction)msgpack_pack,
METH_O, msgpack_pack_doc
},
{
"register", (PyCFunction)msgpack_register,
METH_O, msgpack_register_doc
},
{
"unpack", (PyCFunction)msgpack_unpack,
METH_VARARGS, msgpack_unpack_doc
},
{NULL} /* Sentinel */
};

Expand Down Expand Up @@ -158,7 +166,7 @@ _module_state_init(PyObject *module)
!(state->registry = PyDict_New()) ||
RegisterObject(state->registry, Py_NotImplemented) ||
RegisterObject(state->registry, Py_Ellipsis)
) {
) {
return -1;
}
return 0;
Expand All @@ -172,7 +180,7 @@ _module_init(PyObject *module)
_module_state_init(module) ||
PyModule_AddStringConstant(module, "__version__", PKG_VERSION) ||
_PyModule_AddType(module, "Timestamp", &Timestamp_Type)
) {
) {
return -1;
}
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/msgpack.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
#
# Copyright © 2020 Malek Hadj-Ali
# Copyright © 2021 Malek Hadj-Ali
# All rights reserved.
#
# This file is part of mood.
Expand Down
102 changes: 66 additions & 36 deletions src/object.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
#
# Copyright © 2020 Malek Hadj-Ali
# Copyright © 2021 Malek Hadj-Ali
# All rights reserved.
#
# This file is part of mood.
Expand Down Expand Up @@ -38,9 +38,11 @@ __PyObject_UpdateDict(PyObject *self, PyObject *arg)
we should do that here. */
Py_INCREF(key);
if (!PyUnicode_Check(key)) {
PyErr_Format(PyExc_TypeError,
"expected state key to be unicode, not '%.200s'",
Py_TYPE(key)->tp_name);
PyErr_Format(
PyExc_TypeError,
"expected state key to be unicode, not '%.200s'",
Py_TYPE(key)->tp_name
);
Py_DECREF(key);
break;
}
Expand All @@ -64,10 +66,17 @@ __PyObject_SetState(PyObject *self, PyObject *arg)
_Py_IDENTIFIER(__setstate__);
PyObject *result = NULL;

if (!(result = _PyObject_CallMethodIdObjArgs(self, &PyId___setstate__,
arg, NULL))) {
if (PyErr_ExceptionMatches(PyExc_AttributeError) &&
PyDict_Check(arg)) {
if (
!(
result = _PyObject_CallMethodIdObjArgs(
self, &PyId___setstate__, arg, NULL
)
)
) {
if (
PyErr_ExceptionMatches(PyExc_AttributeError) &&
PyDict_Check(arg)
) {
PyErr_Clear();
return __PyObject_UpdateDict(self, arg);
}
Expand All @@ -88,15 +97,17 @@ __PyObject_InPlaceConcatOrAdd(PyObject *self, PyObject *arg)
PyObject *result = NULL;
int res = -1;

if ((seq_methods = type->tp_as_sequence) &&
seq_methods->sq_inplace_concat) {
if (
(seq_methods = type->tp_as_sequence) && seq_methods->sq_inplace_concat
) {
if ((result = seq_methods->sq_inplace_concat(self, arg))) {
res = 0;
Py_DECREF(result);
}
}
else if ((num_methods = type->tp_as_number) &&
num_methods->nb_inplace_add) {
else if (
(num_methods = type->tp_as_number) && num_methods->nb_inplace_add
) {
if ((result = num_methods->nb_inplace_add(self, arg))) {
if (result != Py_NotImplemented) {
res = 0;
Expand All @@ -105,8 +116,9 @@ __PyObject_InPlaceConcatOrAdd(PyObject *self, PyObject *arg)
}
}
if (res && !PyErr_Occurred()) {
PyErr_Format(PyExc_TypeError,
"cannot extend '%.200s' objects", type->tp_name);
PyErr_Format(
PyExc_TypeError, "cannot extend '%.200s' objects", type->tp_name
);
}
return res;
}
Expand All @@ -117,8 +129,13 @@ __PyObject_Extend(PyObject *self, PyObject *arg)
_Py_IDENTIFIER(extend);
PyObject *result = NULL;

if (!(result = _PyObject_CallMethodIdObjArgs(self, &PyId_extend,
arg, NULL))) {
if (
!(
result = _PyObject_CallMethodIdObjArgs(
self, &PyId_extend, arg, NULL
)
)
) {
if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
PyErr_Clear();
return __PyObject_InPlaceConcatOrAdd(self, arg);
Expand All @@ -136,10 +153,11 @@ __PySequence_Fast(PyObject *obj, Py_ssize_t len, const char *message)
{
PyObject *result = NULL;

if ((result = PySequence_Fast(obj, message)) &&
(PySequence_Fast_GET_SIZE(result) != len)) {
PyErr_Format(PyExc_ValueError,
"expected a sequence of len %zd", len);
if (
(result = PySequence_Fast(obj, message)) &&
(PySequence_Fast_GET_SIZE(result) != len)
) {
PyErr_Format(PyExc_ValueError, "expected a sequence of len %zd", len);
Py_CLEAR(result);
}
return result;
Expand All @@ -151,10 +169,14 @@ __PyObject_MergeFromIter(PyObject *self, PyObject *iter)
PyObject *item = NULL, *fast = NULL;

while ((item = PyIter_Next(iter))) {
if (!(fast = __PySequence_Fast(item, 2, "not a sequence")) ||
PyObject_SetItem(self,
PySequence_Fast_GET_ITEM(fast, 0),
PySequence_Fast_GET_ITEM(fast, 1))) {
if (
!(fast = __PySequence_Fast(item, 2, "not a sequence")) ||
PyObject_SetItem(
self,
PySequence_Fast_GET_ITEM(fast, 0),
PySequence_Fast_GET_ITEM(fast, 1)
)
) {
Py_XDECREF(fast);
Py_DECREF(item);
break;
Expand Down Expand Up @@ -196,8 +218,13 @@ __PyObject_Update(PyObject *self, PyObject *arg)
_Py_IDENTIFIER(update);
PyObject *result = NULL;

if (!(result = _PyObject_CallMethodIdObjArgs(self, &PyId_update,
arg, NULL))) {
if (
!(
result = _PyObject_CallMethodIdObjArgs(
self, &PyId_update, arg, NULL
)
)
) {
if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
PyErr_Clear();
return __PyObject_Merge(self, arg);
Expand All @@ -217,9 +244,10 @@ __PyCallable_Check(PyObject *arg, void *addr)
*(PyObject **)addr = arg;
return 1;
}
PyErr_Format(PyExc_TypeError,
"argument 1 must be a callable, not %.200s",
Py_TYPE(arg)->tp_name);
PyErr_Format(
PyExc_TypeError, "argument 1 must be a callable, not %.200s",
Py_TYPE(arg)->tp_name
);
return 0;
}

Expand All @@ -231,16 +259,18 @@ __PyObject_New(PyObject *reduce)
PyObject *self = NULL;

if (
PyArg_ParseTuple(reduce, "O&O!|OOO",
__PyCallable_Check, &callable, &PyTuple_Type, &args,
&setstatearg, &extendarg, &updatearg) &&
PyArg_ParseTuple(
reduce, "O&O!|OOO",
__PyCallable_Check, &callable, &PyTuple_Type, &args,
&setstatearg, &extendarg, &updatearg
) &&
(self = PyObject_CallObject(callable, args)) &&
(
(setstatearg != Py_None && __PyObject_SetState(self, setstatearg)) ||
(extendarg != Py_None && __PyObject_Extend(self, extendarg)) ||
(updatearg != Py_None && __PyObject_Update(self, updatearg))
(setstatearg != Py_None && __PyObject_SetState(self, setstatearg)) ||
(extendarg != Py_None && __PyObject_Extend(self, extendarg)) ||
(updatearg != Py_None && __PyObject_Update(self, updatearg))
)
) {
) {
Py_CLEAR(self);
}
return self;
Expand Down
Loading

0 comments on commit caec14a

Please sign in to comment.