Skip to content

Commit 802c8dc

Browse files
behrmannkeszybz
authored andcommitted
treewide: remove python 2 support and assume we have python 3.3+
1 parent 7e3313a commit 802c8dc

File tree

9 files changed

+10
-211
lines changed

9 files changed

+10
-211
lines changed

systemd/_daemon.c

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,9 @@ static PyObject* notify(PyObject *self, PyObject *args, PyObject *keywds) {
8989
"fds",
9090
NULL,
9191
};
92-
#if PY_MAJOR_VERSION >=3 && PY_MINOR_VERSION >= 3
9392
if (!PyArg_ParseTupleAndKeywords(args, keywds, "s|piO:notify",
9493
(char**) kwlist, &msg, &unset, &_pid, &fds))
9594
return NULL;
96-
#else
97-
PyObject *obj = NULL;
98-
if (!PyArg_ParseTupleAndKeywords(args, keywds, "s|OiO:notify",
99-
(char**) kwlist, &msg, &obj, &_pid, &fds))
100-
return NULL;
101-
if (obj)
102-
unset = PyObject_IsTrue(obj);
103-
if (unset < 0)
104-
return NULL;
105-
#endif
10695
pid = _pid;
10796
if (pid < 0 || pid != _pid) {
10897
PyErr_SetString(PyExc_OverflowError, "Bad pid_t");
@@ -176,20 +165,9 @@ static PyObject* listen_fds(PyObject *self, PyObject *args, PyObject *keywds) {
176165
int unset = true;
177166

178167
static const char* const kwlist[] = {"unset_environment", NULL};
179-
#if PY_MAJOR_VERSION >=3 && PY_MINOR_VERSION >= 3
180168
if (!PyArg_ParseTupleAndKeywords(args, keywds, "|p:_listen_fds",
181169
(char**) kwlist, &unset))
182170
return NULL;
183-
#else
184-
PyObject *obj = NULL;
185-
if (!PyArg_ParseTupleAndKeywords(args, keywds, "|O:_listen_fds",
186-
(char**) kwlist, &obj))
187-
return NULL;
188-
if (obj)
189-
unset = PyObject_IsTrue(obj);
190-
if (unset < 0)
191-
return NULL;
192-
#endif
193171

194172
r = sd_listen_fds(unset);
195173
if (set_error(r, NULL, NULL) < 0)
@@ -223,20 +201,9 @@ static PyObject* listen_fds_with_names(PyObject *self, PyObject *args, PyObject
223201
PyObject *tpl, *item;
224202

225203
static const char* const kwlist[] = {"unset_environment", NULL};
226-
#if PY_MAJOR_VERSION >=3 && PY_MINOR_VERSION >= 3
227204
if (!PyArg_ParseTupleAndKeywords(args, keywds, "|p:_listen_fds_with_names",
228205
(char**) kwlist, &unset))
229206
return NULL;
230-
#else
231-
PyObject *obj = NULL;
232-
if (!PyArg_ParseTupleAndKeywords(args, keywds, "|O:_listen_fds_with_names",
233-
(char**) kwlist, &obj))
234-
return NULL;
235-
if (obj != NULL)
236-
unset = PyObject_IsTrue(obj);
237-
if (unset < 0)
238-
return NULL;
239-
#endif
240207

241208
#if HAVE_SD_LISTEN_FDS_WITH_NAMES
242209
r = sd_listen_fds_with_names(unset, &names);
@@ -284,17 +251,12 @@ static PyObject* is_fifo(PyObject *self, PyObject *args) {
284251
int fd;
285252
const char *path = NULL;
286253

287-
#if PY_MAJOR_VERSION >=3 && PY_MINOR_VERSION >= 1
288254
_cleanup_Py_DECREF_ PyObject *_path = NULL;
289255
if (!PyArg_ParseTuple(args, "i|O&:_is_fifo",
290256
&fd, Unicode_FSConverter, &_path))
291257
return NULL;
292258
if (_path)
293259
path = PyBytes_AsString(_path);
294-
#else
295-
if (!PyArg_ParseTuple(args, "i|z:_is_fifo", &fd, &path))
296-
return NULL;
297-
#endif
298260

299261
r = sd_is_fifo(fd, path);
300262
if (set_error(r, path, NULL) < 0)
@@ -315,17 +277,12 @@ static PyObject* is_mq(PyObject *self, PyObject *args) {
315277
int fd;
316278
const char *path = NULL;
317279

318-
#if PY_MAJOR_VERSION >=3 && PY_MINOR_VERSION >= 1
319280
_cleanup_Py_DECREF_ PyObject *_path = NULL;
320281
if (!PyArg_ParseTuple(args, "i|O&:_is_mq",
321282
&fd, Unicode_FSConverter, &_path))
322283
return NULL;
323284
if (_path)
324285
path = PyBytes_AsString(_path);
325-
#else
326-
if (!PyArg_ParseTuple(args, "i|z:_is_mq", &fd, &path))
327-
return NULL;
328-
#endif
329286

330287
r = sd_is_mq(fd, path);
331288
if (set_error(r, path, NULL) < 0)
@@ -451,7 +408,6 @@ static PyObject* is_socket_unix(PyObject *self, PyObject *args) {
451408
char* path = NULL;
452409
Py_ssize_t length = 0;
453410

454-
#if PY_MAJOR_VERSION >=3 && PY_MINOR_VERSION >= 1
455411
_cleanup_Py_DECREF_ PyObject *_path = NULL;
456412
if (!PyArg_ParseTuple(args, "i|iiO&:_is_socket_unix",
457413
&fd, &type, &listening, Unicode_FSConverter, &_path))
@@ -461,11 +417,6 @@ static PyObject* is_socket_unix(PyObject *self, PyObject *args) {
461417
if (PyBytes_AsStringAndSize(_path, &path, &length))
462418
return NULL;
463419
}
464-
#else
465-
if (!PyArg_ParseTuple(args, "i|iiz#:_is_socket_unix",
466-
&fd, &type, &listening, &path, &length))
467-
return NULL;
468-
#endif
469420

470421
r = sd_is_socket_unix(fd, type, listening, path, length);
471422
if (set_error(r, path, NULL) < 0)
@@ -490,23 +441,6 @@ static PyMethodDef methods[] = {
490441
{} /* Sentinel */
491442
};
492443

493-
#if PY_MAJOR_VERSION < 3
494-
495-
DISABLE_WARNING_MISSING_PROTOTYPES;
496-
PyMODINIT_FUNC init_daemon(void) {
497-
PyObject *m;
498-
499-
m = Py_InitModule3("_daemon", methods, module__doc__);
500-
if (!m)
501-
return;
502-
503-
PyModule_AddIntConstant(m, "LISTEN_FDS_START", SD_LISTEN_FDS_START);
504-
PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION);
505-
}
506-
REENABLE_WARNING;
507-
508-
#else
509-
510444
static struct PyModuleDef module = {
511445
PyModuleDef_HEAD_INIT,
512446
.m_name = "_daemon", /* name of module */
@@ -532,5 +466,3 @@ PyMODINIT_FUNC PyInit__daemon(void) {
532466
return m;
533467
}
534468
REENABLE_WARNING;
535-
536-
#endif

systemd/_journal.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,6 @@ static PyMethodDef methods[] = {
113113
{} /* Sentinel */
114114
};
115115

116-
#if PY_MAJOR_VERSION < 3
117-
118-
DISABLE_WARNING_MISSING_PROTOTYPES;
119-
PyMODINIT_FUNC init_journal(void) {
120-
PyObject *m;
121-
122-
m = Py_InitModule("_journal", methods);
123-
if (!m)
124-
return;
125-
126-
PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION);
127-
}
128-
REENABLE_WARNING;
129-
130-
#else
131-
132116
static struct PyModuleDef module = {
133117
PyModuleDef_HEAD_INIT,
134118
.m_name = "_journal", /* name of module */
@@ -152,5 +136,3 @@ PyMODINIT_FUNC PyInit__journal(void) {
152136
return m;
153137
}
154138
REENABLE_WARNING;
155-
156-
#endif

systemd/_reader.c

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ PyDoc_STRVAR(module__doc__,
7171
"Class to reads the systemd journal similar to journalctl.");
7272

7373

74-
#if PY_MAJOR_VERSION >= 3
7574
static PyTypeObject MonotonicType;
7675

7776
PyDoc_STRVAR(MonotonicType__doc__,
@@ -89,24 +88,19 @@ static PyStructSequence_Desc Monotonic_desc = {
8988
MonotonicType_fields,
9089
2,
9190
};
92-
#endif
9391

9492
/**
9593
* Convert a str or bytes object into a C-string path.
9694
* Returns NULL on error.
9795
*/
9896
static char* str_converter(PyObject *str, PyObject **bytes) {
99-
#if PY_MAJOR_VERSION >=3 && PY_MINOR_VERSION >= 1
10097
int r;
10198

10299
r = PyUnicode_FSConverter(str, bytes);
103100
if (r == 0)
104101
return NULL;
105102

106103
return PyBytes_AsString(*bytes);
107-
#else
108-
return PyString_AsString(str);
109-
#endif
110104
}
111105

112106
/**
@@ -706,25 +700,16 @@ static PyObject* Reader_get_monotonic(Reader *self, PyObject *args) {
706700
assert_cc(sizeof(unsigned long long) == sizeof(timestamp));
707701
monotonic = PyLong_FromUnsignedLongLong(timestamp);
708702
bootid = PyBytes_FromStringAndSize((const char*) &id.bytes, sizeof(id.bytes));
709-
#if PY_MAJOR_VERSION >= 3
710703
tuple = PyStructSequence_New(&MonotonicType);
711-
#else
712-
tuple = PyTuple_New(2);
713-
#endif
714704
if (!monotonic || !bootid || !tuple) {
715705
Py_XDECREF(monotonic);
716706
Py_XDECREF(bootid);
717707
Py_XDECREF(tuple);
718708
return NULL;
719709
}
720710

721-
#if PY_MAJOR_VERSION >= 3
722711
PyStructSequence_SET_ITEM(tuple, 0, monotonic);
723712
PyStructSequence_SET_ITEM(tuple, 1, bootid);
724-
#else
725-
PyTuple_SET_ITEM(tuple, 0, monotonic);
726-
PyTuple_SET_ITEM(tuple, 1, bootid);
727-
#endif
728713

729714
return tuple;
730715
}
@@ -1353,41 +1338,27 @@ static PyMethodDef methods[] = {
13531338
{} /* Sentinel */
13541339
};
13551340

1356-
#if PY_MAJOR_VERSION >= 3
13571341
static PyModuleDef module = {
13581342
PyModuleDef_HEAD_INIT,
13591343
.m_name = "_reader",
13601344
.m_doc = module__doc__,
13611345
.m_size = -1,
13621346
.m_methods = methods,
13631347
};
1364-
#endif
1365-
1366-
#if PY_MAJOR_VERSION >= 3
13671348
static bool initialized = false;
1368-
#endif
13691349

13701350
DISABLE_WARNING_MISSING_PROTOTYPES;
13711351

13721352
PyMODINIT_FUNC
1373-
#if PY_MAJOR_VERSION >= 3
13741353
PyInit__reader(void)
1375-
#else
1376-
init_reader(void)
1377-
#endif
13781354
{
13791355
PyObject* m;
13801356

13811357
PyDateTime_IMPORT;
13821358

13831359
if (PyType_Ready(&ReaderType) < 0)
1384-
#if PY_MAJOR_VERSION >= 3
13851360
return NULL;
1386-
#else
1387-
return;
1388-
#endif
13891361

1390-
#if PY_MAJOR_VERSION >= 3
13911362
m = PyModule_Create(&module);
13921363
if (!m)
13931364
return NULL;
@@ -1396,20 +1367,11 @@ init_reader(void)
13961367
PyStructSequence_InitType(&MonotonicType, &Monotonic_desc);
13971368
initialized = true;
13981369
}
1399-
#else
1400-
m = Py_InitModule3("_reader", methods, module__doc__);
1401-
if (!m)
1402-
return;
1403-
#endif
14041370

14051371
Py_INCREF(&ReaderType);
1406-
#if PY_MAJOR_VERSION >= 3
14071372
Py_INCREF(&MonotonicType);
1408-
#endif
14091373
if (PyModule_AddObject(m, "_Reader", (PyObject *) &ReaderType) ||
1410-
#if PY_MAJOR_VERSION >= 3
14111374
PyModule_AddObject(m, "Monotonic", (PyObject*) &MonotonicType) ||
1412-
#endif
14131375
PyModule_AddIntConstant(m, "NOP", SD_JOURNAL_NOP) ||
14141376
PyModule_AddIntConstant(m, "APPEND", SD_JOURNAL_APPEND) ||
14151377
PyModule_AddIntConstant(m, "INVALIDATE", SD_JOURNAL_INVALIDATE) ||
@@ -1420,15 +1382,11 @@ init_reader(void)
14201382
PyModule_AddIntConstant(m, "CURRENT_USER", SD_JOURNAL_CURRENT_USER) ||
14211383
PyModule_AddIntConstant(m, "OS_ROOT", SD_JOURNAL_OS_ROOT) ||
14221384
PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION)) {
1423-
#if PY_MAJOR_VERSION >= 3
14241385
Py_DECREF(m);
14251386
return NULL;
1426-
#endif
14271387
}
14281388

1429-
#if PY_MAJOR_VERSION >= 3
14301389
return m;
1431-
#endif
14321390
}
14331391

14341392
REENABLE_WARNING;

systemd/id128.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -161,26 +161,6 @@ static int add_id(PyObject *module, const char* name, sd_id128_t id) {
161161
return PyModule_AddObject(module, name, obj);
162162
}
163163

164-
#if PY_MAJOR_VERSION < 3
165-
166-
DISABLE_WARNING_MISSING_PROTOTYPES;
167-
PyMODINIT_FUNC initid128(void) {
168-
PyObject *m;
169-
170-
m = Py_InitModule3("id128", methods, module__doc__);
171-
if (!m)
172-
return;
173-
174-
/* a series of lines like 'add_id() ;' follow */
175-
#define JOINER ;
176-
#include "id128-constants.h"
177-
#undef JOINER
178-
PyModule_AddStringConstant(m, "__version__", PACKAGE_VERSION);
179-
}
180-
REENABLE_WARNING;
181-
182-
#else
183-
184164
static struct PyModuleDef module = {
185165
PyModuleDef_HEAD_INIT,
186166
.m_name = "id128", /* name of module */
@@ -209,5 +189,3 @@ PyMODINIT_FUNC PyInit_id128(void) {
209189
return m;
210190
}
211191
REENABLE_WARNING;
212-
213-
#endif

systemd/journal.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,9 @@
3434
LOCAL_ONLY, RUNTIME_ONLY,
3535
SYSTEM, SYSTEM_ONLY, CURRENT_USER,
3636
OS_ROOT,
37-
_get_catalog)
37+
_get_catalog, Monotonic)
3838
from . import id128 as _id128
3939

40-
if _sys.version_info >= (3,):
41-
from ._reader import Monotonic
42-
else:
43-
Monotonic = tuple
44-
4540

4641
def _convert_monotonic(m):
4742
return Monotonic((_datetime.timedelta(microseconds=m[0]),
@@ -66,11 +61,10 @@ def _convert_timestamp(s):
6661
def _convert_trivial(x):
6762
return x
6863

69-
if _sys.version_info >= (3,):
70-
def _convert_uuid(s):
71-
return _uuid.UUID(s.decode())
72-
else:
73-
_convert_uuid = _uuid.UUID
64+
65+
def _convert_uuid(s):
66+
return _uuid.UUID(s.decode())
67+
7468

7569
DEFAULT_CONVERTERS = {
7670
'MESSAGE_ID': _convert_uuid,
@@ -222,9 +216,6 @@ def __next__(self):
222216
else:
223217
raise StopIteration()
224218

225-
if _sys.version_info < (3,):
226-
next = __next__
227-
228219
def add_match(self, *args, **kwargs):
229220
"""Add one or more matches to the filter journal log entries.
230221

0 commit comments

Comments
 (0)