File: remove_six.patch

package info (click to toggle)
python-xlib 0.33-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,040 kB
  • sloc: python: 23,022; awk: 89; makefile: 60; sh: 10
file content (264 lines) | stat: -rw-r--r-- 7,403 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
--- 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 @@
                 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:
--- 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 @@
 
         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
--- 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,7 @@
 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,15 +64,6 @@
                 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 = {}
--- a/Xlib/protocol/rq.py
+++ b/Xlib/protocol/rq.py
@@ -26,7 +26,9 @@
 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 +38,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 +454,7 @@
     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 +674,7 @@
         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:
--- a/Xlib/threaded.py
+++ b/Xlib/threaded.py
@@ -19,7 +19,7 @@
 #    Suite 330,
 #    Boston, MA 02111-1307 USA
 
-from six.moves import _thread
+import _thread
 
 # We change the allocate_lock function in Xlib.support.lock to
 # return a basic Python lock, instead of the default dummy lock
--- 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 @@
 
 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.maxint
 
 if options.match_re != None:
     re_obj = re.compile(options.match_re)
--- a/requirements.txt
+++ b/requirements.txt
@@ -1 +0,0 @@
-six>=1.10.0
--- a/setup.py
+++ b/setup.py
@@ -10,7 +10,6 @@
 
 
 setup(
-    install_requires=['six>=1.10.0'],
     setup_requires=['setuptools-scm'],
     packages=[
         'Xlib',
--- 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 @@
 
     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'))
--- 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 @@
                 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 @@
     (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', (