diff --git a/README.rst b/README.rst index ad040fe..0b59edd 100644 --- a/README.rst +++ b/README.rst @@ -24,8 +24,8 @@ GPL v2. Requirements ~~~~~~~~~~~~ -The Python X Library requires Python 2.7 or newer. It has been tested to -various extents with Python 2.7 and 3.3 through 3.6. +The Python X Library requires Python 3.6 or newer. It has been tested to +various extents with Python 3.6 through 3.12. The Python X Library will only work on systems that have an X server installed, such as most Linux distros, but will not work on Windows or MacOS. diff --git a/Xlib/display.py b/Xlib/display.py index 87b9aa6..4513920 100644 --- a/Xlib/display.py +++ b/Xlib/display.py @@ -22,9 +22,6 @@ # Python modules import types -# Python 2/3 compatibility. -from six import create_unbound_method - # Xlib modules from . import error from . import ext @@ -283,7 +280,7 @@ def extension_add_method(self, object, name, function): if hasattr(cls, name): raise AssertionError('attempting to replace %s method: %s' % (class_name, name)) - method = create_unbound_method(function, cls) + method = function # Maybe should check extension overrides too try: diff --git a/Xlib/ext/xinput.py b/Xlib/ext/xinput.py index f921806..d89900d 100644 --- a/Xlib/ext/xinput.py +++ b/Xlib/ext/xinput.py @@ -28,9 +28,6 @@ import array import struct -# Python 2/3 compatibility. -from six import integer_types - from Xlib.protocol import rq from Xlib import X @@ -218,7 +215,7 @@ def pack_value(self, val): mask_seq = array.array(rq.struct_to_array_codes['L']) - if isinstance(val, integer_types): + if isinstance(val, int): # We need to build a "binary mask" that (as far as I can tell) is # encoded in native byte order from end to end. The simple case is # with a single unsigned 32-bit value, for which we construct an diff --git a/Xlib/protocol/display.py b/Xlib/protocol/display.py index 0d910da..8af4401 100644 --- a/Xlib/protocol/display.py +++ b/Xlib/protocol/display.py @@ -29,8 +29,9 @@ import struct import sys -# Python 2/3 compatibility. -from six import PY3, byte2int, indexbytes +import operator +byte2int = operator.itemgetter(0) +indexbytes = operator.getitem # Xlib modules from .. import error @@ -42,9 +43,8 @@ from . import rq from . import event -if PY3: - class bytesview(object): +class bytesview: def __init__(self, data, offset=0, size=None): if size is None: @@ -65,16 +65,6 @@ def __getitem__(self, key): return bytes(self.view[key]) return self.view[key] -else: - - def bytesview(data, offset=0, size=None): - if not isinstance(data, (bytes, buffer)): - raise TypeError('unsupported type: {}'.format(type(data))) - if size is None: - size = len(data)-offset - return buffer(data, offset, size) - - class Display(object): extension_major_opcodes = {} error_classes = error.xerror_class.copy() diff --git a/Xlib/protocol/rq.py b/Xlib/protocol/rq.py index 8bc8205..2adc580 100644 --- a/Xlib/protocol/rq.py +++ b/Xlib/protocol/rq.py @@ -25,8 +25,9 @@ import struct from array import array -# Python 2/3 compatibility. -from six import PY3, binary_type, byte2int, indexbytes, iterbytes +import operator +byte2int = operator.itemgetter(0) +indexbytes = operator.getitem # Xlib modules from .. import X @@ -36,12 +37,8 @@ def decode_string(bs): return bs.decode('latin1') -if PY3: - def encode_array(a): - return a.tobytes() -else: - def encode_array(a): - return a.tostring() +def encode_array(a): + return a.tobytes() class BadDataError(Exception): pass @@ -456,7 +453,7 @@ def __init__(self, name, pad = 1): def pack_value(self, val): """Convert 8-byte string into 16-byte list""" if isinstance(val, bytes): - val = list(iterbytes(val)) + val = list(iter(val)) slen = len(val) @@ -676,7 +673,7 @@ def pack_value(self, value): if fmt not in (8, 16, 32): raise BadDataError('Invalid property data format {0}'.format(fmt)) - if isinstance(val, binary_type): + if isinstance(val, bytes): size = fmt // 8 vlen = len(val) if vlen % size: diff --git a/examples/childwin.py b/examples/childwin.py index 9a0cf6b..d63f7ab 100755 --- a/examples/childwin.py +++ b/examples/childwin.py @@ -22,9 +22,6 @@ # Suite 330, # Boston, MA 02111-1307 USA -# Python 2/3 compatibility. -from __future__ import print_function - import sys import os @@ -34,7 +31,7 @@ from Xlib import X, display, Xutil # Application window -class Window(object): +class Window: def __init__(self, display): self.d = display diff --git a/examples/eventthread.py b/examples/eventthread.py index da8cb50..8f03139 100755 --- a/examples/eventthread.py +++ b/examples/eventthread.py @@ -22,9 +22,6 @@ # Suite 330, # Boston, MA 02111-1307 USA -# Python 2/3 compatibility. -from __future__ import print_function - import sys import os diff --git a/examples/nvcontrol.py b/examples/nvcontrol.py index dece439..20187a7 100755 --- a/examples/nvcontrol.py +++ b/examples/nvcontrol.py @@ -21,10 +21,6 @@ # Suite 330, # Boston, MA 02111-1307 USA - -# Python 2/3 compatibility. -from __future__ import print_function - import sys import os diff --git a/examples/profilex.py b/examples/profilex.py index e8361fd..cae6989 100755 --- a/examples/profilex.py +++ b/examples/profilex.py @@ -3,10 +3,6 @@ # Program to generate profiling data. Run with one argument, # the profile stats file to generate. - -# Python 2/3 compatibility. -from __future__ import print_function - import sys import os diff --git a/examples/record_demo.py b/examples/record_demo.py index 25ed575..a4dc160 100755 --- a/examples/record_demo.py +++ b/examples/record_demo.py @@ -27,10 +27,6 @@ Not very much unlike the xmacrorec2 program in the xmacro package. ''' - -# Python 2/3 compatibility. -from __future__ import print_function - import sys import os diff --git a/examples/run_examples.py b/examples/run_examples.py index 9c834dc..5640462 100644 --- a/examples/run_examples.py +++ b/examples/run_examples.py @@ -21,9 +21,6 @@ # Suite 330, # Boston, MA 02111-1307 USA -# Python 2/3 compatibility. -from __future__ import print_function - import sys import os import subprocess diff --git a/examples/security.py b/examples/security.py index f95047e..6bb4188 100755 --- a/examples/security.py +++ b/examples/security.py @@ -22,9 +22,6 @@ # Suite 330, # Boston, MA 02111-1307 USA -# Python 2/3 compatibility. -from __future__ import print_function - import sys, os from optparse import OptionParser diff --git a/examples/shapewin.py b/examples/shapewin.py index 015a03c..14929fd 100755 --- a/examples/shapewin.py +++ b/examples/shapewin.py @@ -21,10 +21,6 @@ # Suite 330, # Boston, MA 02111-1307 USA - -# Python 2/3 compatibility. -from __future__ import print_function - import sys import os diff --git a/examples/threadtest.py b/examples/threadtest.py index 9732f57..9269adf 100755 --- a/examples/threadtest.py +++ b/examples/threadtest.py @@ -1,8 +1,5 @@ #!/usr/bin/python -# Python 2/3 compatibility. -from __future__ import print_function - import sys import os diff --git a/examples/xdamage.py b/examples/xdamage.py index 46cbab9..7b154a0 100644 --- a/examples/xdamage.py +++ b/examples/xdamage.py @@ -21,10 +21,6 @@ # Suite 330, # Boston, MA 02111-1307 USA - -# Python 2/3 compatibility. -from __future__ import print_function - import sys import os diff --git a/examples/xfixes-cursor-notify.py b/examples/xfixes-cursor-notify.py index cc443fe..ea3b208 100755 --- a/examples/xfixes-cursor-notify.py +++ b/examples/xfixes-cursor-notify.py @@ -23,9 +23,6 @@ # Suite 330, # Boston, MA 02111-1307 USA -# Python 2/3 compatibility. -from __future__ import print_function - import sys from Xlib.display import Display from Xlib.ext import xfixes diff --git a/examples/xfixes-selection-notify.py b/examples/xfixes-selection-notify.py index 20728fb..b5e39a8 100755 --- a/examples/xfixes-selection-notify.py +++ b/examples/xfixes-selection-notify.py @@ -23,9 +23,6 @@ # Suite 330, # Boston, MA 02111-1307 USA -# Python 2/3 compatibility. -from __future__ import print_function - import sys import os import time diff --git a/examples/xfixes.py b/examples/xfixes.py index 53c3714..a2790ba 100755 --- a/examples/xfixes.py +++ b/examples/xfixes.py @@ -22,9 +22,6 @@ # Suite 330, # Boston, MA 02111-1307 USA -# Python 2/3 compatibility. -from __future__ import print_function - import sys import os import time diff --git a/examples/xinerama.py b/examples/xinerama.py index 13419ba..bf1b0b4 100755 --- a/examples/xinerama.py +++ b/examples/xinerama.py @@ -21,10 +21,6 @@ # Suite 330, # Boston, MA 02111-1307 USA - -# Python 2/3 compatibility. -from __future__ import print_function - import sys import os import pprint @@ -36,7 +32,7 @@ from Xlib.ext import xinerama # Application window (only one) -class Window(object): +class Window: def __init__(self, display): self.d = display diff --git a/examples/xinput.py b/examples/xinput.py index ccfb27a..06573fe 100755 --- a/examples/xinput.py +++ b/examples/xinput.py @@ -22,9 +22,6 @@ # Suite 330, # Boston, MA 02111-1307 USA -# Python 2/3 compatibility. -from __future__ import print_function - import sys import os diff --git a/examples/xlsatoms.py b/examples/xlsatoms.py index 02a26f6..4ab4128 100755 --- a/examples/xlsatoms.py +++ b/examples/xlsatoms.py @@ -26,15 +26,9 @@ ''' -# Python 2/3 compatibility. -from __future__ import print_function - import sys import os -# Python 2/3 compatibility. -from six import PY2, MAXSIZE - # Change path so we find Xlib sys.path.append(os.path.join(os.path.dirname(__file__), '..')) @@ -42,12 +36,6 @@ from Xlib import display, error from optparse import OptionParser - -if PY2: - integer_type = long -else: - integer_type = int - parser = OptionParser() parser.add_option("-d","--display",dest="display",help="This option specifies the X server to which to connect",metavar="dpy",default=None) parser.add_option("-n","--name",dest="name",help="This option specifies the name of an atom to list. If the atom does not exist, a message will be printed on the standard error.",metavar="string",default=None) @@ -90,12 +78,12 @@ def list_atoms(d,re_obj,low,high): rangeVals = options.range.split("-") if rangeVals[0] != "": - low = integer_type(rangeVals[0]) + low = int(rangeVals[0]) if rangeVals[1] != "": - high = integer_type(rangeVals[1]) + high = int(rangeVals[1]) else: - high = MAXSIZE + high = sys.maxsize if options.match_re != None: re_obj = re.compile(options.match_re) diff --git a/examples/xrandr.py b/examples/xrandr.py index 5a64534..de5642b 100755 --- a/examples/xrandr.py +++ b/examples/xrandr.py @@ -21,10 +21,6 @@ # Suite 330, # Boston, MA 02111-1307 USA - -# Python 2/3 compatibility. -from __future__ import print_function - import sys import os import pprint diff --git a/requirements.txt b/requirements.txt index dde3933..e69de29 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +0,0 @@ -six>=1.10.0 diff --git a/runtests.py b/runtests.py index 4e77de8..0b6fb19 100755 --- a/runtests.py +++ b/runtests.py @@ -1,8 +1,5 @@ #!/usr/bin/env python -# Python 2/3 compatibility. -from __future__ import print_function - import os import signal import subprocess diff --git a/setup.cfg b/setup.cfg index 29a11ad..2fea1cf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -19,21 +19,17 @@ classifiers = Intended Audience :: Developers License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+) Operating System :: OS Independent - Programming Language :: Python :: 2.7 Programming Language :: Python :: 3 - Programming Language :: Python :: 3.3 - Programming Language :: Python :: 3.4 - Programming Language :: Python :: 3.5 - Programming Language :: Python :: 3.5 Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 + Programming Language :: Python :: 3.11 + Programming Language :: Python :: 3.12 Programming Language :: Python :: Implementation :: CPython Topic :: Software Development :: Libraries :: Python Modules Topic :: Software Development :: Libraries Topic :: Software Development :: User Interfaces -[bdist_wheel] -universal = 1 - # vim: list diff --git a/setup.py b/setup.py index 71bdb08..9674de7 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,6 @@ setup( - install_requires=['six>=1.10.0'], setup_requires=['setuptools-scm'], packages=[ 'Xlib', diff --git a/test/test_bytesview.py b/test/test_bytesview.py index 565793a..6b7af22 100644 --- a/test/test_bytesview.py +++ b/test/test_bytesview.py @@ -1,9 +1,6 @@ import unittest -# Python 2/3 compatibility. -from six import indexbytes, text_type - from Xlib.protocol.display import bytesview @@ -11,17 +8,17 @@ class BytesViewTest(unittest.TestCase): def test(self): with self.assertRaises(TypeError): - bytesview(text_type('foobar')) + bytesview('foobar') data = b'0123456789ABCDEF' view = bytesview(data) self.assertEqual(len(view), 16) self.assertEqual(view[:], data) self.assertIsInstance(view[:], bytes) self.assertEqual(view[5:-6], b'56789') - self.assertEqual(indexbytes(view, 7), ord('7')) + self.assertEqual(view[7], ord('7')) view = bytesview(view, 5) self.assertEqual(view[:], b'56789ABCDEF') - self.assertEqual(indexbytes(view, 4), ord('9')) + self.assertEqual(view[4], ord('9')) view = bytesview(view, 0, 5) self.assertEqual(view[:], b'56789') - self.assertEqual(indexbytes(view, 1), ord('6')) + self.assertEqual(view[1], ord('6')) diff --git a/test/test_struct.py b/test/test_struct.py index 47da4e5..0047148 100644 --- a/test/test_struct.py +++ b/test/test_struct.py @@ -5,8 +5,6 @@ import types import re -from six import binary_type, iterbytes - from Xlib.protocol import rq from . import DummyDisplay, TestCase @@ -85,7 +83,7 @@ def _struct_test(name, fields): values_in[field_name] = field_value_in if field_value_out is not None: values_out[field_name] = field_value_out - if isinstance(field_binary, binary_type): + if isinstance(field_binary, bytes): binary += field_binary elif isinstance(field_binary, (types.FunctionType, types.LambdaType, partial)): binary += field_binary(field_value_in) @@ -167,7 +165,7 @@ def _struct_test(name, fields): (None, lambda name: rq.LengthOf('s2', 2) , None , pack('H', 3) ), ('s1', lambda name: rq.String16(name, pad=0), (0, 1, 2), lambda s: struct.pack('>' + 'H' * len(s), *s)), # An 8-bits string is also allowed on input. - ('s2', lambda name: rq.String16(name, pad=0), b'\x03\x04\x05', lambda s: struct.pack('>' + 'H' * len(s), *iterbytes(s)), (3, 4, 5)), + ('s2', lambda name: rq.String16(name, pad=0), b'\x03\x04\x05', lambda s: struct.pack('>' + 'H' * len(s), *iter(s)), (3, 4, 5)), )) _struct_test('binary', ( diff --git a/tox.ini b/tox.ini index 360451f..0b7395e 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27,py33,py34,py35,py36 +envlist = py36,py37,py38,py39,py310,py311,py312 skip_missing_interpreters = true [testenv]