~bennabiy/+junk/python-xlib

« back to all changes in this revision

Viewing changes to Xlib/protocol/display.py

  • Committer: Package Import Robot
  • Author(s): Andrew Shadura, Ramkumar Ramachandra, Andrew Shadura
  • Date: 2015-08-13 08:14:19 UTC
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: package-import@ubuntu.com-20150813081419-4akiw3kto323ls9m
[ Ramkumar Ramachandra ]
* Remove useless debugging output (Closes: #565996)

[ Andrew Shadura ]
* Switch to 3.0 (quilt) format.
* Rename patches.
* Use debhelper 9 in its short form.
* Use pybuild.
* Bump Standards-Version.
* Don't build or install PostScript documentation and info files.
* Use system-provided texi2html instead of a shipped version
  (Closes: #795057).
* Update debian/copyright (Closes: #795057).
* Don't install Makefile or texi2html with the documentation.
* Set executable bit for examples.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
from Xlib.support import lock, connect
32
32
 
33
33
# Xlib.protocol modules
34
 
import rq
35
 
import event
 
34
from Xlib.protocol import rq, event
 
35
 
 
36
# in Python 3, bytes are an actual array; in python 2, bytes are still
 
37
# string-like, so in order to get an array element we need to call ord()
 
38
if sys.version[0] >= '3':
 
39
    def _bytes_item(x):
 
40
        return x
 
41
else:
 
42
    def _bytes_item(x):
 
43
        return ord(x)
 
44
 
36
45
 
37
46
class Display:
38
47
    resource_classes = {}
83
92
        # Data used by the send-and-recieve loop
84
93
        self.sent_requests = []
85
94
        self.request_length = 0
86
 
        self.data_send = ''
87
 
        self.data_recv = ''
 
95
        self.data_send = b''
 
96
        self.data_recv = b''
88
97
        self.data_sent_bytes = 0
89
98
 
90
99
        # Resource ID structures
227
236
        self.resource_id_lock.acquire()
228
237
        try:
229
238
            i = self.last_resource_id
230
 
            while self.resource_ids.has_key(i):
 
239
            while i in self.resource_ids:
231
240
                i = i + 1
232
241
                if i > self.info.resource_id_mask:
233
242
                    i = 0
503
512
 
504
513
            # Ignore errors caused by a signal recieved while blocking.
505
514
            # All other errors are re-raised.
506
 
            except select.error, err:
 
515
            except select.error as err:
507
516
                if err[0] != errno.EINTR:
508
517
                    raise err
509
518
 
518
527
            if ws:
519
528
                try:
520
529
                    i = self.socket.send(self.data_send)
521
 
                except socket.error, err:
 
530
                except socket.error as err:
522
531
                    self.close_internal('server: %s' % err[1])
523
532
                    raise self.socket_error
524
533
 
533
542
                # We're the recieving thread, parse the data
534
543
                if recieving:
535
544
                    try:
536
 
                        bytes_recv = self.socket.recv(2048)
537
 
                    except socket.error, err:
 
545
                        bytes_recv = self.socket.recv(4096)
 
546
                    except socket.error as err:
538
547
                        self.close_internal('server: %s' % err[1])
539
548
                        raise self.socket_error
540
549
 
640
649
                return gotreq
641
650
 
642
651
            # Check the first byte to find out what kind of response it is
643
 
            rtype = ord(self.data_recv[0])
 
652
            rtype = _bytes_item(self.data_recv[0])
644
653
 
645
654
            # Error resposne
646
655
            if rtype == 0:
660
669
 
661
670
    def parse_error_response(self, request):
662
671
        # Code is second byte
663
 
        code = ord(self.data_recv[1])
 
672
        code = _bytes_item(self.data_recv[1])
664
673
 
665
674
        # Fetch error class
666
675
        estruct = self.error_classes.get(code, error.XError)
667
676
 
668
677
        e = estruct(self, self.data_recv[:32])
669
 
        self.data_recv = buffer(self.data_recv, 32)
 
678
        self.data_recv = self.data_recv[32:]
670
679
 
671
680
        # print 'recv Error:', e
672
681
 
720
729
        req._parse_response(self.data_recv[:self.request_length])
721
730
        # print 'recv Request:', req
722
731
 
723
 
        self.data_recv = buffer(self.data_recv, self.request_length)
 
732
        self.data_recv = self.data_recv[self.request_length:]
724
733
        self.request_length = 0
725
734
 
726
735
 
745
754
 
746
755
        e = estruct(display = self, binarydata = self.data_recv[:32])
747
756
 
748
 
        self.data_recv = buffer(self.data_recv, 32)
 
757
        self.data_recv = self.data_recv[32:]
749
758
 
750
759
        # Drop all requests having an error handler,
751
760
        # but which obviously succeded.
967
976
 
968
977
 
969
978
    def __init__(self, display, *args, **keys):
970
 
        self._binary = apply(self._request.to_binary, args, keys)
 
979
        self._binary = self._request.to_binary(*args, **keys)
971
980
        self._data = None
972
981
 
973
982
        # Don't bother about locking, since no other threads have