Skip to content

attempt to support modern Python3 versions #276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 1 addition & 4 deletions Xlib/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions Xlib/ext/xinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
18 changes: 4 additions & 14 deletions Xlib/protocol/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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()
Expand Down
17 changes: 7 additions & 10 deletions Xlib/protocol/rq.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions examples/childwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
# Suite 330,
# Boston, MA 02111-1307 USA

# Python 2/3 compatibility.
from __future__ import print_function

import sys
import os

Expand All @@ -34,7 +31,7 @@
from Xlib import X, display, Xutil

# Application window
class Window(object):
class Window:
def __init__(self, display):
self.d = display

Expand Down
3 changes: 0 additions & 3 deletions examples/eventthread.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
# Suite 330,
# Boston, MA 02111-1307 USA

# Python 2/3 compatibility.
from __future__ import print_function

import sys
import os

Expand Down
4 changes: 0 additions & 4 deletions examples/nvcontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
# Suite 330,
# Boston, MA 02111-1307 USA


# Python 2/3 compatibility.
from __future__ import print_function

import sys
import os

Expand Down
4 changes: 0 additions & 4 deletions examples/profilex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 0 additions & 4 deletions examples/record_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 0 additions & 3 deletions examples/run_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions examples/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 0 additions & 4 deletions examples/shapewin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
# Suite 330,
# Boston, MA 02111-1307 USA


# Python 2/3 compatibility.
from __future__ import print_function

import sys
import os

Expand Down
3 changes: 0 additions & 3 deletions examples/threadtest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/usr/bin/python

# Python 2/3 compatibility.
from __future__ import print_function

import sys
import os

Expand Down
4 changes: 0 additions & 4 deletions examples/xdamage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
# Suite 330,
# Boston, MA 02111-1307 USA


# Python 2/3 compatibility.
from __future__ import print_function

import sys
import os

Expand Down
3 changes: 0 additions & 3 deletions examples/xfixes-cursor-notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions examples/xfixes-selection-notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions examples/xfixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions examples/xinerama.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
3 changes: 0 additions & 3 deletions examples/xinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
# Suite 330,
# Boston, MA 02111-1307 USA

# Python 2/3 compatibility.
from __future__ import print_function

import sys
import os

Expand Down
18 changes: 3 additions & 15 deletions examples/xlsatoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,16 @@

'''

# 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__), '..'))

import re
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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions examples/xrandr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
six>=1.10.0
3 changes: 0 additions & 3 deletions runtests.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/usr/bin/env python

# Python 2/3 compatibility.
from __future__ import print_function

import os
import signal
import subprocess
Expand Down
12 changes: 4 additions & 8 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading