Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
examples/consolecallback.py | 2 +-
examples/dhcpleases.py | 2 +-
examples/dominfo.py | 2 +-
examples/domipaddrs.py | 2 +-
examples/domrestore.py | 2 +-
examples/domsave.py | 2 +-
examples/domstart.py | 2 +-
examples/esxlist.py | 2 +-
examples/event-test.py | 2 +-
examples/guest-vcpus/guest-vcpu-daemon.py | 2 +-
examples/guest-vcpus/guest-vcpu.py | 2 +-
examples/nodestats.py | 2 +-
examples/sparsestream.py | 2 +-
examples/topology.py | 2 +-
generator.py | 2 +-
libvirt-lxc-override.c | 51 ++-------
libvirt-override.c | 51 ++-------
libvirt-python.spec.in | 96 +---------------
libvirt-qemu-override.c | 51 ++-------
libvirt-utils.c | 17 +--
libvirt-utils.h | 6 +-
sanitytest.py | 2 +-
setup.py | 9 +-
typewrappers.c | 133 +++-------------------
typewrappers.h | 5 -
25 files changed, 71 insertions(+), 380 deletions(-)
diff --git a/examples/consolecallback.py b/examples/consolecallback.py
index c539a92..1347384 100644
--- a/examples/consolecallback.py
+++ b/examples/consolecallback.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# consolecallback - provide a persistent console that survives guest reboots
import sys, os, logging, libvirt, tty, termios, atexit
diff --git a/examples/dhcpleases.py b/examples/dhcpleases.py
index da51f52..f394541 100755
--- a/examples/dhcpleases.py
+++ b/examples/dhcpleases.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# netdhcpleases - print leases info for given virtual network
import libvirt
diff --git a/examples/dominfo.py b/examples/dominfo.py
index d3049cd..0a39f4c 100755
--- a/examples/dominfo.py
+++ b/examples/dominfo.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# dominfo - print some information about a domain
import libvirt
diff --git a/examples/domipaddrs.py b/examples/domipaddrs.py
index d6d5cac..bda308c 100755
--- a/examples/domipaddrs.py
+++ b/examples/domipaddrs.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# domipaddrs - print domain interfaces along with their MAC and IP addresses
import libvirt
diff --git a/examples/domrestore.py b/examples/domrestore.py
index 06fdfbc..96f4955 100755
--- a/examples/domrestore.py
+++ b/examples/domrestore.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# domstart - make sure a given domU is running, if not start it
import libvirt
diff --git a/examples/domsave.py b/examples/domsave.py
index 727217c..4940cce 100755
--- a/examples/domsave.py
+++ b/examples/domsave.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# domstart - make sure a given domU is running, if not start it
import libvirt
diff --git a/examples/domstart.py b/examples/domstart.py
index ce1b60c..7ff6cb9 100755
--- a/examples/domstart.py
+++ b/examples/domstart.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# domstart - make sure a given domU is running, if not start it
import libvirt
diff --git a/examples/esxlist.py b/examples/esxlist.py
index 0d47b00..d86e064 100755
--- a/examples/esxlist.py
+++ b/examples/esxlist.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# esxlist - list active domains of an ESX host and print some info.
# also demonstrates how to use the libvirt.openAuth() method
diff --git a/examples/event-test.py b/examples/event-test.py
index 4458e22..fddef64 100755
--- a/examples/event-test.py
+++ b/examples/event-test.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
#
#
#
diff --git a/examples/guest-vcpus/guest-vcpu-daemon.py
b/examples/guest-vcpus/guest-vcpu-daemon.py
index c7c08a8..30fcb9c 100755
--- a/examples/guest-vcpus/guest-vcpu-daemon.py
+++ b/examples/guest-vcpus/guest-vcpu-daemon.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
import libvirt
import threading
diff --git a/examples/guest-vcpus/guest-vcpu.py b/examples/guest-vcpus/guest-vcpu.py
index 8faba87..479ec40 100755
--- a/examples/guest-vcpus/guest-vcpu.py
+++ b/examples/guest-vcpus/guest-vcpu.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
import libvirt
import sys
diff --git a/examples/nodestats.py b/examples/nodestats.py
index c01dead..ae2a442 100755
--- a/examples/nodestats.py
+++ b/examples/nodestats.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# Print some host NUMA node statistics
#
# Authors:
diff --git a/examples/sparsestream.py b/examples/sparsestream.py
index e960c40..d7c09b7 100755
--- a/examples/sparsestream.py
+++ b/examples/sparsestream.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# Example of sparse streams usage
#
# Authors:
diff --git a/examples/topology.py b/examples/topology.py
index 191669c..197c87a 100755
--- a/examples/topology.py
+++ b/examples/topology.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
# Parse topology information from the capabilities XML and use
# them to calculate host topology
#
diff --git a/generator.py b/generator.py
index 3352521..cba9d47 100755
--- a/generator.py
+++ b/generator.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
#
# generate python wrappers from the XML API description
#
diff --git a/libvirt-lxc-override.c b/libvirt-lxc-override.c
index d7af154..138ba5b 100644
--- a/libvirt-lxc-override.c
+++ b/libvirt-lxc-override.c
@@ -4,13 +4,13 @@
* entry points where an automatically generated stub is
* unpractical
*
- * Copyright (C) 2012-2013 Red Hat, Inc.
+ * Copyright (C) 2012-2019 Red Hat, Inc.
*
* Daniel Veillard <veillard(a)redhat.com>
*/
/* Horrible kludge to work around even more horrible name-space pollution
- via Python.h. That file includes /usr/include/python2.5/pyconfig*.h,
+ via Python.h. That file includes /usr/include/python3.x/pyconfig*.h,
which has over 180 autoconf-style HAVE_* definitions. Shame on them. */
#undef HAVE_PTHREAD_H
@@ -21,18 +21,10 @@
#include "libvirt-utils.h"
#include "build/libvirt-lxc.h"
-#if PY_MAJOR_VERSION > 2
-# ifndef __CYGWIN__
+#ifndef __CYGWIN__
extern PyObject *PyInit_libvirtmod_lxc(void);
-# else
-extern PyObject *PyInit_cygvirtmod_lxc(void);
-# endif
#else
-# ifndef __CYGWIN__
-extern void initlibvirtmod_lxc(void);
-# else
-extern void initcygvirtmod_lxc(void);
-# endif
+extern PyObject *PyInit_cygvirtmod_lxc(void);
#endif
#if 0
@@ -107,14 +99,13 @@ static PyMethodDef libvirtLxcMethods[] = {
{NULL, NULL, 0, NULL}
};
-#if PY_MAJOR_VERSION > 2
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
-# ifndef __CYGWIN__
+#ifndef __CYGWIN__
"libvirtmod_lxc",
-# else
+#else
"cygvirtmod_lxc",
-# endif
+#endif
NULL,
-1,
libvirtLxcMethods,
@@ -125,11 +116,11 @@ static struct PyModuleDef moduledef = {
};
PyObject *
-# ifndef __CYGWIN__
+#ifndef __CYGWIN__
PyInit_libvirtmod_lxc
-# else
+#else
PyInit_cygvirtmod_lxc
-# endif
+#endif
(void)
{
PyObject *module;
@@ -141,25 +132,3 @@ PyInit_cygvirtmod_lxc
return module;
}
-#else /* ! PY_MAJOR_VERSION > 2 */
-void
-# ifndef __CYGWIN__
-initlibvirtmod_lxc
-# else
-initcygvirtmod_lxc
-# endif
-(void)
-{
- if (virInitialize() < 0)
- return;
-
- /* initialize the python extension module */
- Py_InitModule((char *)
-# ifndef __CYGWIN__
- "libvirtmod_lxc",
-# else
- "cygvirtmod_lxc",
-# endif
- libvirtLxcMethods);
-}
-#endif /* ! PY_MAJOR_VERSION > 2 */
diff --git a/libvirt-override.c b/libvirt-override.c
index 2e24d27..4e4c00a 100644
--- a/libvirt-override.c
+++ b/libvirt-override.c
@@ -4,13 +4,13 @@
* entry points where an automatically generated stub is
* unpractical
*
- * Copyright (C) 2005, 2007-2015 Red Hat, Inc.
+ * Copyright (C) 2005-2019 Red Hat, Inc.
*
* Daniel Veillard <veillard(a)redhat.com>
*/
/* Horrible kludge to work around even more horrible name-space pollution
- via Python.h. That file includes /usr/include/python2.5/pyconfig*.h,
+ via Python.h. That file includes /usr/include/python3.x/pyconfig*.h,
which has over 180 autoconf-style HAVE_* definitions. Shame on them. */
#undef HAVE_PTHREAD_H
@@ -25,18 +25,10 @@
#include "build/libvirt.h"
#include "libvirt-utils.h"
-#if PY_MAJOR_VERSION > 2
-# ifndef __CYGWIN__
+#ifndef __CYGWIN__
extern PyObject *PyInit_libvirtmod(void);
-# else
-extern PyObject *PyInit_cygvirtmod(void);
-# endif
#else
-# ifndef __CYGWIN__
-extern void initlibvirtmod(void);
-# else
-extern void initcygvirtmod(void);
-# endif
+extern PyObject *PyInit_cygvirtmod(void);
#endif
#if 0
@@ -10553,14 +10545,13 @@ static PyMethodDef libvirtMethods[] = {
{NULL, NULL, 0, NULL}
};
-#if PY_MAJOR_VERSION > 2
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
-# ifndef __CYGWIN__
+#ifndef __CYGWIN__
"libvirtmod",
-# else
+#else
"cygvirtmod",
-# endif
+#endif
NULL,
-1,
libvirtMethods,
@@ -10571,11 +10562,11 @@ static struct PyModuleDef moduledef = {
};
PyObject *
-# ifndef __CYGWIN__
+#ifndef __CYGWIN__
PyInit_libvirtmod
-# else
+#else
PyInit_cygvirtmod
-# endif
+#endif
(void)
{
PyObject *module;
@@ -10587,25 +10578,3 @@ PyInit_cygvirtmod
return module;
}
-#else /* ! PY_MAJOR_VERSION > 2 */
-void
-# ifndef __CYGWIN__
-initlibvirtmod
-# else
-initcygvirtmod
-# endif
-(void)
-{
- if (virInitialize() < 0)
- return;
-
- /* initialize the python extension module */
- Py_InitModule((char *)
-# ifndef __CYGWIN__
- "libvirtmod",
-# else
- "cygvirtmod",
-# endif
- libvirtMethods);
-}
-#endif /* ! PY_MAJOR_VERSION > 2 */
diff --git a/libvirt-python.spec.in b/libvirt-python.spec.in
index 8506840..1e92f3c 100644
--- a/libvirt-python.spec.in
+++ b/libvirt-python.spec.in
@@ -12,26 +12,7 @@
%define supported_platform 0
%endif
-%define _with_python2 1
-%if 0%{?fedora} > 30 || 0%{?rhel} > 7
-%define _with_python2 0
-%endif
-
-%define _with_python3 0
-%if 0%{?fedora} || 0%{?rhel} > 7
-%define _with_python3 1
-%endif
-
-# Whether py2 packages are assumed to have python2- name prefix
-%define py2_versioned_deps 0
-%if 0%{?fedora} || 0%{?rhel} > 7
-%define py2_versioned_deps 1
-%endif
-
-%{!?with_python2: %define with_python2 %{_with_python2}}
-%{!?with_python3: %define with_python3 %{_with_python3}}
-
-Summary: The libvirt virtualization API python2 binding
+Summary: The libvirt virtualization API python3 binding
Name: libvirt-python
Version: @PY_VERSION@
Release: 1%{?dist}
@@ -39,31 +20,13 @@ Source0:
http://libvirt.org/sources/python/%{name}-%{version}.tar.gz
Url:
http://libvirt.org
License: LGPLv2+
BuildRequires: libvirt-devel == %{version}
-%if %{with_python2}
-%if %{py2_versioned_deps}
-BuildRequires: python2-devel
-BuildRequires: python2-nose
-BuildRequires: python2-lxml
-%else
-BuildRequires: python-devel
-BuildRequires: python-nose
-BuildRequires: python-lxml
-%endif
-%endif
-%if %{with_python3}
BuildRequires: python3-devel
BuildRequires: python3-nose
BuildRequires: python3-lxml
-%endif
BuildRequires: gcc
# Don't want provides for python shared objects
-%if %{with_python2}
-%{?filter_provides_in: %filter_provides_in %{python2_sitearch}/.*\.so}
-%endif
-%if %{with_python3}
%{?filter_provides_in: %filter_provides_in %{python3_sitearch}/.*\.so}
-%endif
%{?filter_setup}
%description
@@ -72,23 +35,6 @@ written in the Python programming language to use the interface
supplied by the libvirt library to use the virtualization capabilities
of recent versions of Linux (and other OSes).
-%if %{with_python2}
-%package -n python2-libvirt
-Summary: The libvirt virtualization API python2 binding
-Url:
http://libvirt.org
-License: LGPLv2+
-%{?python_provide:%python_provide python2-libvirt}
-Provides: libvirt-python = %{version}-%{release}
-Obsoletes: libvirt-python <= 3.6.0-1%{?dist}
-
-%description -n python2-libvirt
-The python2-libvirt package contains a module that permits applications
-written in the Python programming language to use the interface
-supplied by the libvirt library to use the virtualization capabilities
-of recent versions of Linux (and other OSes).
-%endif
-
-%if %{with_python3}
%package -n python3-libvirt
Summary: The libvirt virtualization API python3 binding
Url:
http://libvirt.org
@@ -99,16 +45,15 @@ Obsoletes: libvirt-python3 <= 3.6.0-1%{?dist}
%description -n python3-libvirt
The python3-libvirt package contains a module that permits applications
-written in the Python programming language to use the interface
+written in the Python 3.x programming language to use the interface
supplied by the libvirt library to use the virtualization capabilities
of recent versions of Linux (and other OSes).
-%endif
%prep
%setup -q
# Unset execute bit for example scripts; it can introduce spurious
-# RPM dependencies, like /usr/bin/python which can pull in python2
+# RPM dependencies, like /usr/bin/python3
# for the -python3 package
find examples -type f -exec chmod 0644 \{\} \;
@@ -118,56 +63,22 @@ echo "This RPM requires either Fedora >= %{min_fedora} or
RHEL >= %{min_rhel}"
exit 1
%endif
-%if %{with_python2}
-%if 0%{?fedora} || 0%{?rhel} >= 8
-%py2_build
-%else
-CFLAGS="$RPM_OPT_FLAGS" %{__python2} setup.py build
-%endif
-%endif
-%if %{with_python3}
%if 0%{?fedora} || 0%{?rhel} >= 8
%py3_build
%else
CFLAGS="$RPM_OPT_FLAGS" %{__python3} setup.py build
%endif
-%endif
%install
-%if %{with_python2}
-%if 0%{?fedora} || 0%{?rhel} >= 8
-%py2_install
-%else
-%{__python2} setup.py install --skip-build --root=%{buildroot}
-%endif
-%endif
-%if %{with_python3}
%if 0%{?fedora} || 0%{?rhel} >= 8
%py3_install
%else
%{__python3} setup.py install --skip-build --root=%{buildroot}
%endif
-%endif
%check
-%if %{with_python2}
-%{__python2} setup.py test
-%endif
-%if %{with_python3}
%{__python3} setup.py test
-%endif
-%if %{with_python2}
-%files -n python2-libvirt
-%doc ChangeLog AUTHORS NEWS README COPYING COPYING.LESSER examples/
-%{python2_sitearch}/libvirt.py*
-%{python2_sitearch}/libvirt_qemu.py*
-%{python2_sitearch}/libvirt_lxc.py*
-%{python2_sitearch}/libvirtmod*
-%{python2_sitearch}/*egg-info
-%endif
-
-%if %{with_python3}
%files -n python3-libvirt
%doc ChangeLog AUTHORS NEWS README COPYING COPYING.LESSER examples/
%{python3_sitearch}/libvirt.py*
@@ -180,6 +91,5 @@ CFLAGS="$RPM_OPT_FLAGS" %{__python3} setup.py build
%{python3_sitearch}/__pycache__/libvirtaio.cpython-*.py*
%{python3_sitearch}/libvirtmod*
%{python3_sitearch}/*egg-info
-%endif
%changelog
diff --git a/libvirt-qemu-override.c b/libvirt-qemu-override.c
index f166f6e..6ae95b4 100644
--- a/libvirt-qemu-override.c
+++ b/libvirt-qemu-override.c
@@ -4,13 +4,13 @@
* entry points where an automatically generated stub is
* unpractical
*
- * Copyright (C) 2011-2014 Red Hat, Inc.
+ * Copyright (C) 2011-2019 Red Hat, Inc.
*
* Daniel Veillard <veillard(a)redhat.com>
*/
/* Horrible kludge to work around even more horrible name-space pollution
- via Python.h. That file includes /usr/include/python2.5/pyconfig*.h,
+ via Python.h. That file includes /usr/include/python3.x/pyconfig*.h,
which has over 180 autoconf-style HAVE_* definitions. Shame on them. */
#undef HAVE_PTHREAD_H
@@ -21,18 +21,10 @@
#include "libvirt-utils.h"
#include "build/libvirt-qemu.h"
-#if PY_MAJOR_VERSION > 2
-# ifndef __CYGWIN__
+#ifndef __CYGWIN__
extern PyObject *PyInit_libvirtmod_qemu(void);
-# else
-extern PyObject *PyInit_cygvirtmod_qemu(void);
-# endif
#else
-# ifndef __CYGWIN__
-extern void initlibvirtmod_qemu(void);
-# else
-extern void initcygvirtmod_qemu(void);
-# endif
+extern PyObject *PyInit_cygvirtmod_qemu(void);
#endif
#if 0
@@ -351,14 +343,13 @@ static PyMethodDef libvirtQemuMethods[] = {
{NULL, NULL, 0, NULL}
};
-#if PY_MAJOR_VERSION > 2
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
-# ifndef __CYGWIN__
+#ifndef __CYGWIN__
"libvirtmod_qemu",
-# else
+#else
"cygvirtmod_qemu",
-# endif
+#endif
NULL,
-1,
libvirtQemuMethods,
@@ -369,11 +360,11 @@ static struct PyModuleDef moduledef = {
};
PyObject *
-# ifndef __CYGWIN__
+#ifndef __CYGWIN__
PyInit_libvirtmod_qemu
-# else
+#else
PyInit_cygvirtmod_qemu
-# endif
+#endif
(void)
{
PyObject *module;
@@ -385,25 +376,3 @@ PyInit_cygvirtmod_qemu
return module;
}
-#else /* ! PY_MAJOR_VERSION > 2 */
-void
-# ifndef __CYGWIN__
-initlibvirtmod_qemu
-# else
-initcygvirtmod_qemu
-# endif
-(void)
-{
- if (virInitialize() < 0)
- return;
-
- /* initialize the python extension module */
- Py_InitModule((char *)
-# ifndef __CYGWIN__
- "libvirtmod_qemu",
-# else
- "cygvirtmod_qemu",
-# endif
- libvirtQemuMethods);
-}
-#endif /* ! PY_MAJOR_VERSION > 2 */
diff --git a/libvirt-utils.c b/libvirt-utils.c
index 78b94ca..d8ff11d 100644
--- a/libvirt-utils.c
+++ b/libvirt-utils.c
@@ -1,7 +1,7 @@
/*
* libvirt-utils.c: misc helper APIs for python binding
*
- * Copyright (C) 2013 Red Hat, Inc.
+ * Copyright (C) 2013-2019 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -274,11 +274,7 @@ setPyVirTypedParameter(PyObject *info,
int nparams)
{
PyObject *key, *value;
-#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION <= 4
- int pos = 0;
-#else
Py_ssize_t pos = 0;
-#endif
virTypedParameterPtr temp = NULL, ret = NULL;
Py_ssize_t size;
ssize_t i;
@@ -416,13 +412,6 @@ virPyDictToTypedParamOne(virTypedParameterPtr *params,
type = VIR_TYPED_PARAM_LLONG;
else
type = VIR_TYPED_PARAM_ULLONG;
-#if PY_MAJOR_VERSION < 3
- } else if (PyInt_Check(value)) {
- if (PyInt_AS_LONG(value) < 0)
- type = VIR_TYPED_PARAM_LLONG;
- else
- type = VIR_TYPED_PARAM_ULLONG;
-#endif
} else if (PyFloat_Check(value)) {
type = VIR_TYPED_PARAM_DOUBLE;
}
@@ -520,11 +509,7 @@ virPyDictToTypedParams(PyObject *dict,
{
PyObject *key;
PyObject *value;
-#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION <= 4
- int pos = 0;
-#else
Py_ssize_t pos = 0;
-#endif
virTypedParameterPtr params = NULL;
int n = 0;
int max = 0;
diff --git a/libvirt-utils.h b/libvirt-utils.h
index cc3d278..82f0af8 100644
--- a/libvirt-utils.h
+++ b/libvirt-utils.h
@@ -139,11 +139,7 @@ int virReallocN(void *ptrptr, size_t size, size_t count)
void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1);
-# if PY_MAJOR_VERSION > 2
-# define libvirt_PyString_Check PyUnicode_Check
-# else
-# define libvirt_PyString_Check PyString_Check
-# endif
+# define libvirt_PyString_Check PyUnicode_Check
#define VIR_N_ELEMENTS(array) (sizeof(array) / sizeof(*(array)))
diff --git a/sanitytest.py b/sanitytest.py
index 0b415fd..1bedd55 100644
--- a/sanitytest.py
+++ b/sanitytest.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
import sys
import lxml
diff --git a/setup.py b/setup.py
index 117f6ff..ea25dc0 100755
--- a/setup.py
+++ b/setup.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
from distutils.core import setup, Extension, Command
from distutils.command.build import build
@@ -17,6 +17,10 @@ import re
import shutil
import time
+if sys.version_info[0] != 3:
+ print("libvirt-python requires Python 3.x to build")
+ sys.exit(1)
+
MIN_LIBVIRT = "0.9.11"
MIN_LIBVIRT_LXC = "1.0.2"
@@ -341,7 +345,7 @@ setup(name = 'libvirt-python',
description = 'The libvirt virtualization API python binding',
long_description =
'''The libvirt-python package provides a module that permits
applications
-written in the Python programming language to call the interface
+written in the Python 3.x programming language to call the interface
supplied by the libvirt library, to manage the virtualization capabilities
of recent versions of Linux (and other OSes).''',
license = 'LGPLv2+',
@@ -362,7 +366,6 @@ of recent versions of Linux (and other OSes).''',
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU Lesser General Public License v2 or later
(LGPLv2+)",
"Programming Language :: Python",
- "Programming Language :: Python :: 2",
"Programming Language :: Python :: 3",
]
)
diff --git a/typewrappers.c b/typewrappers.c
index 2507859..3b1df87 100644
--- a/typewrappers.c
+++ b/typewrappers.c
@@ -2,141 +2,88 @@
* types.c: converter functions between the internal representation
* and the Python objects
*
- * Copyright (C) 2005, 2007, 2012 Red Hat, Inc.
+ * Copyright (C) 2005-2019 Red Hat, Inc.
*
* Daniel Veillard <veillard(a)redhat.com>
*/
/* Horrible kludge to work around even more horrible name-space pollution
- * via Python.h. That file includes /usr/include/python2.5/pyconfig*.h,
- * which has over 180 autoconf-style HAVE_* definitions. Shame on them. */
+ * via Python.h. That file includes /usr/include/python3.x/pyconfig*.h,
+ * which has over 180 autoconf-style HAVE_* definitions. Shame on them. */
#undef HAVE_PTHREAD_H
#include "typewrappers.h"
#include "libvirt-utils.h"
-#ifndef Py_CAPSULE_H
-typedef void(*PyCapsule_Destructor)(void *, void *);
-#endif
-
static PyObject *
libvirt_buildPyObject(void *cobj,
const char *name,
PyCapsule_Destructor destr)
{
- PyObject *ret;
-
-#ifdef Py_CAPSULE_H
- ret = PyCapsule_New(cobj, name, destr);
-#else
- ret = PyCObject_FromVoidPtrAndDesc(cobj, (void *) name, destr);
-#endif /* _TEST_CAPSULE */
-
- return ret;
+ return PyCapsule_New(cobj, name, destr);
}
PyObject *
libvirt_intWrap(int val)
{
- PyObject *ret;
-#if PY_MAJOR_VERSION > 2
- ret = PyLong_FromLong((long) val);
-#else
- ret = PyInt_FromLong((long) val);
-#endif
- return ret;
+ return PyLong_FromLong((long) val);
}
PyObject *
libvirt_uintWrap(uint val)
{
- PyObject *ret;
-#if PY_MAJOR_VERSION > 2
- ret = PyLong_FromLong((long) val);
-#else
- ret = PyInt_FromLong((long) val);
-#endif
- return ret;
+ return PyLong_FromLong((long) val);
}
PyObject *
libvirt_longWrap(long val)
{
- PyObject *ret;
- ret = PyLong_FromLong(val);
- return ret;
+ return PyLong_FromLong(val);
}
PyObject *
libvirt_ulongWrap(unsigned long val)
{
- PyObject *ret;
- ret = PyLong_FromLong(val);
- return ret;
+ return PyLong_FromLong(val);
}
PyObject *
libvirt_longlongWrap(long long val)
{
- PyObject *ret;
- ret = PyLong_FromLongLong(val);
- return ret;
+ return PyLong_FromLongLong(val);
}
PyObject *
libvirt_ulonglongWrap(unsigned long long val)
{
- PyObject *ret;
- ret = PyLong_FromUnsignedLongLong(val);
- return ret;
+ return PyLong_FromUnsignedLongLong(val);
}
PyObject *
libvirt_charPtrSizeWrap(char *str, Py_ssize_t size)
{
- PyObject *ret;
-
if (str == NULL) {
return VIR_PY_NONE;
}
-#if PY_MAJOR_VERSION > 2
- ret = PyBytes_FromStringAndSize(str, size);
-#else
- ret = PyString_FromStringAndSize(str, size);
-#endif
- return ret;
+ return PyBytes_FromStringAndSize(str, size);
}
PyObject *
libvirt_charPtrWrap(char *str)
{
- PyObject *ret;
-
if (str == NULL) {
return VIR_PY_NONE;
}
-#if PY_MAJOR_VERSION > 2
- ret = PyUnicode_FromString(str);
-#else
- ret = PyString_FromString(str);
-#endif
- return ret;
+ return PyUnicode_FromString(str);
}
PyObject *
libvirt_constcharPtrWrap(const char *str)
{
- PyObject *ret;
-
if (str == NULL) {
return VIR_PY_NONE;
}
-#if PY_MAJOR_VERSION > 2
- ret = PyUnicode_FromString(str);
-#else
- ret = PyString_FromString(str);
-#endif
- return ret;
+ return PyUnicode_FromString(str);
}
PyObject *
@@ -163,11 +110,7 @@ libvirt_intUnwrap(PyObject *obj,
* to C long type directly. If it is of PyLong_Type, PyInt_AsLong
* will call PyLong_AsLong() to deal with it automatically.
*/
-#if PY_MAJOR_VERSION > 2
long_val = PyLong_AsLong(obj);
-#else
- long_val = PyInt_AsLong(obj);
-#endif
if ((long_val == -1) && PyErr_Occurred())
return -1;
@@ -196,11 +139,7 @@ libvirt_uintUnwrap(PyObject *obj,
return -1;
}
-#if PY_MAJOR_VERSION > 2
long_val = PyLong_AsLong(obj);
-#else
- long_val = PyInt_AsLong(obj);
-#endif
if ((long_val == -1) && PyErr_Occurred())
return -1;
@@ -269,14 +208,7 @@ libvirt_longlongUnwrap(PyObject *obj,
return -1;
}
-#if PY_MAJOR_VERSION == 2
- /* If obj is of PyInt_Type, PyLong_AsLongLong
- * will call PyInt_AsLong() to handle it automatically.
- */
- if (PyInt_Check(obj) || PyLong_Check(obj))
-#else
if (PyLong_Check(obj))
-#endif
llong_val = PyLong_AsLongLong(obj);
else
PyErr_SetString(PyExc_TypeError, "an integer is required");
@@ -299,21 +231,7 @@ libvirt_ulonglongUnwrap(PyObject *obj,
return -1;
}
-#if PY_MAJOR_VERSION == 2
- /* The PyLong_AsUnsignedLongLong doesn't check the type of
- * obj, only accept argument of PyLong_Type, so we check it instead.
- */
- if (PyInt_Check(obj)) {
- long long llong_val = PyInt_AsLong(obj);
- if (llong_val < 0)
- PyErr_SetString(PyExc_OverflowError,
- "negative Python int cannot be converted to C unsigned
long long");
- else
- ullong_val = llong_val;
- } else if (PyLong_Check(obj)) {
-#else
if (PyLong_Check(obj)) {
-#endif
ullong_val = PyLong_AsUnsignedLongLong(obj);
} else {
PyErr_SetString(PyExc_TypeError, "an integer is required");
@@ -367,9 +285,7 @@ int
libvirt_charPtrUnwrap(PyObject *obj,
char **str)
{
-#if PY_MAJOR_VERSION > 2
PyObject *bytes;
-#endif
const char *ret;
*str = NULL;
if (!obj) {
@@ -377,21 +293,15 @@ libvirt_charPtrUnwrap(PyObject *obj,
return -1;
}
-#if PY_MAJOR_VERSION > 2
if (!(bytes = PyUnicode_AsUTF8String(obj)))
return -1;
ret = PyBytes_AsString(bytes);
-#else
- ret = PyString_AsString(obj);
-#endif
if (ret) {
*str = strdup(ret);
if (!*str)
PyErr_NoMemory();
}
-#if PY_MAJOR_VERSION > 2
Py_DECREF(bytes);
-#endif
return ret && *str ? 0 : -1;
}
@@ -400,10 +310,6 @@ libvirt_charPtrSizeUnwrap(PyObject *obj,
char **str,
Py_ssize_t *size)
{
- int ret;
-#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION <= 4
- int isize;
-#endif
*str = NULL;
*size = 0;
if (!obj) {
@@ -411,18 +317,7 @@ libvirt_charPtrSizeUnwrap(PyObject *obj,
return -1;
}
-#if PY_MAJOR_VERSION > 2
- ret = PyBytes_AsStringAndSize(obj, str, size);
-#else
-# if PY_MINOR_VERSION <= 4
- ret = PyString_AsStringAndSize(obj, str, &isize);
- *size = isize;
-# else
- ret = PyString_AsStringAndSize(obj, str, size);
-# endif
-#endif
-
- return ret;
+ return PyBytes_AsStringAndSize(obj, str, size);
}
PyObject *
diff --git a/typewrappers.h b/typewrappers.h
index 486017a..fc923bf 100644
--- a/typewrappers.h
+++ b/typewrappers.h
@@ -22,11 +22,6 @@
# define ATTRIBUTE_UNUSED
#endif
-/* Work around really old python. */
-#if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 5
-typedef ssize_t Py_ssize_t;
-#endif
-
#if !LIBVIR_CHECK_VERSION(4, 5, 0)
typedef struct _virNWFilterBinding *virNWFilterBindingPtr;
#endif
--
2.21.0