diff --git a/.gitignore b/.gitignore index 7d440988..d8efd36c 100644 --- a/.gitignore +++ b/.gitignore @@ -57,3 +57,11 @@ docs/_build/ # PyBuilder target/ + +# IntelliJ +.idea/ + +# Visual Studio Code +.vscode/ + +/.mypy_cache/ diff --git a/.landscape.yml b/.landscape.yml new file mode 100644 index 00000000..2c3de431 --- /dev/null +++ b/.landscape.yml @@ -0,0 +1,4 @@ +python-targets: [2, 3] + +mccabe: + run: false diff --git a/.travis.yml b/.travis.yml index 32362068..e7b949f0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,22 +1,43 @@ language: python python: - - "2.6" - "2.7" - - "3.3" - "3.4" - "3.5" + - "3.6" + - "3.7" + - "3.8" + - "3.9" # command to install dependencies -install: pip install -r dev-requirements.txt - -before_script: - - "export DISPLAY=:99.0" - - "sh -e /etc/init.d/xvfb start" - - sleep 3 # give xvfb some time to start +install: + - pip install -r requirements.txt + - pip install -r dev-requirements.txt # command to run tests -script: nosetests --with-xunit --with-coverage --cover-html --cover-html-dir=Coverage_report --verbosity=3 test/testall.py +script: + python -W all runtests.py --with-coverage --cover-html --cover-html-dir=Coverage_report after_success: - - codecov \ No newline at end of file + - codecov + +before_deploy: + # Generate source distribution. + # Note: only do this with Python 3.5 because the contents + # of the distribution are the same for all versions. + - case "$TRAVIS_PYTHON_VERSION" in 3.5) python setup.py sdist --formats=bztar;; esac + # Generate wheel distribution. + # Note: only do this once, since we create a universal wheel. + - case "$TRAVIS_PYTHON_VERSION" in 3.5) python setup.py bdist_wheel;; esac + +deploy: + - provider: releases + api_key: + secure: "kZHDE09hKehX8bFRWa5qM56J3ujc3Stl5j2u9KfdXwmZyYlremZTJ5J9gdiLqqRrTI1jF5n+3miacYSdups1VSqgXYsGzoz99HurtcoMfkFxWkkeCnd6ORwvTXYFN28t2CcjWXV6jCyUABPaEv8TCK3/+LeFfuf30O5Hxg/KiUfpqBwXj6sWaht0whhay45r6D5nYb8omhqa7n4DDLlrStRqkp1SB895EElessFFuHjn/jkxlyEUjGjQ+x79h8JKiXVozYRcyb4eC75xIaE6+yeA6q2ZxMrNRdBnWbRrFBNYsx4QbMCe9vq2m0IQMkrh0kk5N53eA6/8Yy6ZpDUNAb/Alvql8+y/qWwVQl3TYwcMGd0PctmfGH6rElByiOIVV9Zv52hTK9jXky0ab+avLufXlL8tUDVSNReXR7En37vbxlq+AU+xNhHN3girkJJ7jU6saQpj1tROGBpPkLIIHQFh3dbubfgw9qdW5qYBZyLHK9yKNnlzFIr7yktqJvJ/jGz/YDER12UdlCzaoWtVdw8Ogm9faAFlMUvzExYt5BIneDYUe13GtoDw69aLiuq5YGcFKClsgDIqBqYYBTVIHwAS9kTV4CZV0L4C15ylmUIP68LFxZ/stufXW0MJxvhIaJ7gJ9d9LyCK1a0u0j5a78cX/OUx9RfqjOMCuVbGTys=" + file_glob: true + file: + - dist/*.tar.* + - dist/*.whl + on: + tags: true + skip_cleanup: true diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..74eb66b1 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,543 @@ +NEWS for Python X Library + +Version 0.33 +============ + +Bug Fixes +--------- + +- Removed unused imports (thanks @Avasam). +- Avoid to use fcntl module on some environments (thanks @i2y). +- Change a test behavior for `unix_connect.get_socket` (thanks @i2y). +- Fix accidental data change (thanks @Avasam). +- Prefer `bool` over `Literal[0, 1, None]` (thanks @Avasam). +- Change parentheses to brackets in LICENSE (thanks @mtelka). + +--- +Version 0.32 +============ + +Bug Fixes +--------- + +- Use archived link for X documentation resource (thanks @yaxollum). +- Fix for auth entry having no display number (thanks @Majiir). +- Fix return type inconsistency with the `pack_value` for class `Object` (thanks @allfro). +- Rename `add_extension_error` method to `extension_add_error` (thanks @mattalexx). + +Extensions +-------------------- + +- screensaver: fix screensaver protocol mismatch (thanks @yut23). +- XRandr: add version 1.5 support for RRSetMonitor RRGetMonitors and RRDeleteMonitors (thanks @allfro and @jklong). + +--- +Version 0.31 +============ + +Extensions +-------------------- + +- XInput: add event methods (thanks @dd4e). + +--- +Version 0.30 +============ + +Extensions +-------------------- + +- XResource: first implementation (thanks @alebastr). +- XRandr: add missing parameters to delete_output_mode function (thanks @jimmy-loyola). + +--- +Version 0.29 +============ + +Extensions +-------------------- + +- Drawable & XInput: Avoid using array.array.tostring() which wiil be removed in Python 3.9 (thanks @t-wissmann). + +--- +Version 0.28 +============ + +Extensions +-------------------- + +- DPMS: Display Power Management Signaling (by @thiagokokada) + +--- +Version 0.27 +============ + +Bug Fixes +--------- + +- fix TypeError in socket.error exception handling for Python 3.x (by @t-wissmann) + +Extensions +-------------------- + +- NV-CONTROL: set offset for all perf levels (by @Sporif) + +--- +Version 0.26 +============ + +Bug Fixes +--------- + +- support legacy X servers like RealVNC's one (by @Gerardwx) + +Extensions +-------------------- + +- enrich XFixes extension with XFixesSelectionNotify events (by @acrisci) +- add example xfixes-selection-notify.py (by @acrisci) +- fix two issues in NV-CONTROL extension (by @leinardi) +- add method get_clock_info into NV-CONTROL extension (by @leinardi) +- add default client version into Composite extension (by @jakogut) +- add Damage extension with the example (by @mgarg1 and @jakogut) + +--- +Version 0.25 +============ + +Bug Fixes +--------- + +- fix increasing memory usage on display instantiation + +NV-CONTROL extension +-------------------- + +- add first implementation by Roberto Leinardi (@leinardi) + +--- +Version 0.24 +============ + +Bug Fixes +--------- + +- fix protocol handling: correctly support explicit Unix + connections and fix support fox macOS +- improve Python 3 support: fix events sub-code handling + and possible crashes when unpacking text data +- add support for error handlers to the Composite extension + +Misc +---- + +- fix `xfixes` example +- fix a bunch of typos in the code / documentation + +--- +Version 0.23 +============ + +Bug Fixes +--------- + +- fix strings decoding: use Latin-1 + +--- +Version 0.22 +============ + +Bug Fixes +--------- + +- fix `Display.change_pointer_control` implementation +- fix `Drawable.put_pil_image` implementation + +--- +Version 0.21 +============ + +Bug Fixes +--------- + +- fix use under Windows Subsystem for Linux: when DISPLAY does not + specify a protocol, and the implicit Unix socket connection fails, + fallback to TCP (mimicking XCB's behavior). + +Misc +---- + +- don't bundle a copy of texi2html to build the HTML documentation, + but use the currently installed version instead. + +--- +Version 0.20 +============ + +Bug Fixes +--------- + +- fix unclosed file in Xauth implementation +- fix support for `Window.set_wm_transient_for` +- fix support for `Drawable.put_image` / `Drawable.get_image` +- use ASCII for decoding strings in Python 3 (same as Python 2) +- fix Python 3 warnings about `array.tostring()` (deprecated) + +Misc +---- + +Improve response processing performance: reduce the number of +`socket.recv` calls needed to receive a full response. + +--- +Version 0.19 +============ + +Bug Fixes +--------- + +- don't throw an exception if `$XAUTHFILE` / `~/.Xauthority` is missing +- fix authentication work-around for SSH forwarding under Python 3 +- improve `$DISPLAY` handling: support optional protocol prefix, and + correctly handle `unix:0.0` as `:0.0` + +--- +Version 0.18 +============ + +Bug Fixes +--------- + +- fix Python 3 buffer abstraction +- fix interrupted select handling for Python 3.3/3.4 +- fix Unix socket support when only an abstract address is available + +--- +Version 0.17 +============ + +Bug Fixes +--------- + +- fix Xauth handling when using Python 2 and DISPLAY contains a remote IP +- fix String16 request field handling when using Python 3 +- fix RECORD extension and example when using Python 3 +- fix handling of properties: use byte strings for all X11 8-bits + strings, as not all of them are text properties (the window + getters/setters for `wm_name`, `wm_icon_name`, `wm_class`, and + `wm_client_machine` still return/expect Unicode strings) + +API Changes +----------- + +Core: + +- new window getter/setter for text properties: `get_full_text_property` + and `change_text_property`; with automatic conversion to/from Unicode + when the property type encoding is supported (`STRING` and + `UTF8_STRING`) + +Composite extension: + +- support for `GetOverlayWindow` request + +--- +Version 0.16 +============ + +Licensing +--------- + +The project is now licensed under the GNU Lesser General Public License +v2.1 or later (see the LICENSE file for details). + +Compatibility +------------- + +Support for Python versions older than 2.7 has been dropped. Support for +Python 3 (3.3, 3.4 and 3.5) has been added. Note that Python-Xlib now +depends on the six package (>=1.10) for combined Python 2 / 3 support. + +API Changes +----------- + +With the change of license, and no way to contact the original author of +the SHAPE extension, the code had to be rewritten from scratch. This +resulted in a few minor API changes (see [examples/shapewin.py](examples/shapewin.py)). + +Partial support for the SECURITY. XInput, and XFIXES extensions has been +added. + +Bug Fixes +--------- + +- fix RECORD extension +- fixed OS X socket path +- fix handling of generic events +- fix handling of KeymapNotify events +- several fixes for the RandR extension + +--- +Version 0.15rc1 - 14 Nov 2009 +============================= + +Improved support for newer versions of Mac OS X, a couple of new +extensions, and several bugfixes. + +Composite extension +------------------- + +Support for the composite extension, used to implement a composition +manager (added for plcm work in plwm). + +By itself this extension is not very useful, it is intended to be used +together with the DAMAGE and XFIXES extensions. Typically you would also +need RENDER or glX or some similar method of creating fancy graphics. + +XF86 special function keysyms +----------------------------- + +Keysym definitions for special function keys found on modern keyboards, +e.g. raise and lower volume, start specific applications, etc. Have a +look in [Xlib/keysymdef/xf86.py](Xlib/keysymdef/xf86.py) to see what +there are and experiment with xev to see what your keyboard generates. +These definitions aren't brought in by default, so you must do this +after importing `Xlib.XK`: + +```python +Xlib.XK.load_keysym_group('xf86') +``` + +RANDR extension +--------------- + +The RANDR extension complements XINERAMA as a way of getting data about +the physical screens making up a virtual screen in X. An example of +usage can be found in [examples/xrandr.py](examples/xrandr.py). + +--- +Version 0.14 - 1 Oct 2007 (trialed as 0.14rc1 on 10 Jun 2007) +============================================================= + +A couple of new extensions, a Python 2.5 fix and a couple of aliases +(`Display.get_atom()` now uses the internal cache and added +`Window.raise_window()`). Tabs converted to spaces (SF id: 1559082). + +RECORD extension (SF id: 1538663) +--------------------------------- + +Alex Badea contributed a RECORD extension module, allowing Python Xlib +programs to capture mouse and keyboard events (or all other core or +extension events) easily. A demo is in the examples directory. See + for more +information. + +XINERAMA extension +------------------ + +Mike Meyer contributed a Xinerama extension module, allowing Python Xlib +programs to interrogate the X server about positions and sizes of +multiple screens. Specifications are a bit tricky to find - + has some older specs and the +source code of the xorg project (libs & server code) has "definitive" +information. + +Python 2.5 fix (SF id: 1623900) +------------------------------- + +Bugfix to correct handling of XAuthority file parsing under Python 2.5 +causing failed authentication. + +--- +Version 0.13 - 6 Aug 2006 (trialed as 0.13pre1 on 22 Jul 2006) +============================================================== + +A small release to incorporate a number of minor corrections and bug +fixes, including small changes to keysym handling, `.Xauthority` +parsing, several fixes to sending/receiving/flushing data, addition of +`WithdrawnState` to `WMHints`. petli completed documentation for +`Display` objects. + +--- +Version 0.12 - 29 Mar 2002 +========================== + +SHAPE extension +--------------- + +Jeffrey Boser contributed a SHAPE extension module, allowing Python Xlib +programs to use shaped windows. Take a look at examples/shapewin.py for +ideas on how to use it. For more information on shaped windows, see + + +Python 2.2 fix +-------------- + +In Python 2.2 `FCNTL.FD_CLOEXEC` has disappeared and `FCNTL` on the whole +is deprecated, so that had to be dealt with to make the Xlib work with +that version. + +--- +Version 0.11 - 23 Feb 2002 +========================== + +Regression tests for the protocol definition +-------------------------------------------- + +Regressions tests have been created for all requests, replies and +events. The tests use PyUnit, and the old resource database test has +been updated to use it too. + +A lot of protocol bugfixes +-------------------------- + +The bugs discovered by the regression tests have been fixed. +Additionally, a subtle bug in the core engine which could cause a +"can't happen"-error has also been found and fixed. + +--- +Version 0.10 - 16 Dec 2001 +========================== + +Event bugfix +------------ + +The xlib failed to parse the type code of events sent from other clients +using `SendEvent`. This has been fixed, adding the field `send_event' to +all event objects. + +Event documentation +------------------- + +The section "Event Types" in the manual has been written, detailing +all event types in the core protocol. The manual is now ten pages +thicker. + +Basic support for GetImage/PutImage +----------------------------------- + +The Drawable methods `put_image()` and `get_image()` have been +implemented, but handling image data is still up to the user. There is +however, thanks to Ilpo Nyyssönen, a trivial method `put_pil_image()` +that will work on some combinations of image and drawable depth. It's +not perfect, but it's a start. + +--- +Version 0.9 - 4 Dec 2001 +======================== + +Documentation improved +---------------------- + +The documentation has been augmented with a chapter about event +handling, and a chapter listing all X objects and their methods provided +by the library. They are not described in any detail, though. + +Keysym handling improved +------------------------ + +The module `Xlib.XK`, which listed all keysyms, have been split up into +several sub-modules providing different sets of keysyms. By importing +`Xlib.XK` only the miscellany and latin1 sets are loaded, thus removing +some unnecessary clutter. + +`Xlib.display.Display` has two new methods (`lookup_string()` and +`rebind_string()`) for translating keysyms into characters. + +Small changes to library interface +---------------------------------- + +The order of the `Xlib.display.Display` method `send_event()` parameters +`event_mask` and propagate has changed. + +Some of the class names in `Xlib.protocol.event` have changed, to have +the same name as the corresponding event type constant. + +A few bugfixes +-------------- + +If a display has more than one screen, the default screen was always set +to the highest numbered one, irrespective of what the user specified in +`$DISPLAY`. + +Some response attributes in `Xlib.protocol.request` accidentally included +a comma. + +--- +Version 0.8 - 12 Jan 2001 +========================= + +Uses distutils +-------------- + +Python Xlib now uses distutils to make installation and distribution +building easier. + +Tested with Python 2.0 +---------------------- + +A few incompatibilities with Python 2.0 has been fixed. + +--- +Version 0.7 - 8 Jan 2001 +======================== + +Fixed the 64-bit platform fix. +------------------------------ + +As it turns out, the attempted fix for 64-bit platforms in v0.6 didn't +really work. Close study of structmodules.c gave the answer why, and now +it really should work. Yeah. + +Optimizations of core protocol engine +------------------------------------- + +Python Xlib is now at least 25% faster after the core of the protocol +engine has been rewritten. This is some quite cute code: tailor-made +methods are generated for all structures, resulting in a 650% speed-up +in generating binary data, and a 75% speed-up in parsing binary data. + +Interested Python hackers are recommended to take a look at the Struct +class in `Xlib/protocol/rq.py`. + +--- +Version 0.6 - 29 Dec 2000 +========================= + +Fix to make python-xlib work on 64-bytes architectures. +------------------------------------------------------- + +The struct and array modules uses `sizeof(long)` to determine the number +of bytes used when representing the type code 'l'. On Intel and VAX, +this is 32 bits as expected. On Alpha, it's 64 bits. python-xlib now +probes how large each type code is to avoid this problem. + +--- +Version 0.5 - 28 Dec 2000 +========================= + +- Functions implemented to get and set all ICCCM WM properties on Window + objects. + +- Keymap cache implemented, with external `Xlib.display.Display` methods + `keycode_to_keysym`, `keysym_to_keycode`, `keysym_to_keycodes` and + `refresh_keyboard_mapping`. + +- Two utils for debugging X traffic implemented. `utils/tcpbug.py` + forwards a TCP connection and outputs the communication between the + client and the server. This output can then be fed into + `utils/parsexbug.py`, which will output all requests, responses, + errors and events in a readable format. + +--- +Version 0.4 - 4 Oct 2000 +======================== + +- Thread support completed, but not really stress-tested yet. + +- A framework for handling different platforms has been implemented, + together with generic Unix code and some simple VMS code. + +- Some documentation has been written. + +- The usual bunch of bugfixes. diff --git a/LICENSE b/LICENSE index 19e30718..d762d815 100644 --- a/LICENSE +++ b/LICENSE @@ -6,9 +6,9 @@ Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. -(This is the first released version of the Lesser GPL. It also counts +[This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.) + the version number 2.1.] Preamble diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 8a7138c3..00000000 --- a/MANIFEST.in +++ /dev/null @@ -1,18 +0,0 @@ -include MANIFEST.in -include README COPYING NEWS TODO - -global-include .cvsignore - -recursive-include doc Makefile -include doc/src/*.texi -include doc/info/python-xlib.info doc/info/python-xlib.info-*[0-9] -include doc/html/index.html doc/html/python-xlib_toc.html -include doc/html/python-xlib_*.html doc/html/texi2html -include doc/ps/python-xlib.ps - -include utils/tcpbug.py utils/parsexbug.py - -include examples/draw.py examples/draw-proto.py examples/profilex.py -include examples/shapewin.py -include examples/threadtest.py - diff --git a/NEWS b/NEWS deleted file mode 100644 index 4498eee8..00000000 --- a/NEWS +++ /dev/null @@ -1,236 +0,0 @@ --*-outline-*- - - NEWS for Python X Library - -* Version 0.15rc1 - 14 Nov 2009 - -Improved support for newer versions of Mac OS X, a couple of new -extensions, and several bugfixes. - -** Composite extension - -Support for the composite extension, used to implement a composition -manager (added for plcm work in plwm). - -By itself this extension is not very useful, it is intended to be used -together with the DAMAGE and XFIXES extensions. Typically you would -also need RENDER or glX or some similar method of creating fancy -graphics. - -** XF86 special function keysyms - -Keysym definitions for special function keys found on modern -keyboards, e.g. raise and lower volume, start specific applications, -etc. Have a look in Xlib/keysymdef/xf86.py to see what there are and -experiment with xev to see what your keyboard generates. These -definitions aren't brought in by default, so you must do this after -importing Xlib.XK: - -Xlib.XK.load_keysym_group('xf86') - -** RANDR extension - -The RANDR extension complements XINERAMA as a way of getting data about the -physical screens making up a virtual screen in X. An example of usage can -be found in examples/xrandr.py. - - -* Version 0.14 - 1 Oct 2007 (trialed as 0.14rc1 on 10 Jun 2007) - -A couple of new extensions, a Python 2.5 fix and a couple of aliases -(Display.get_atom() now uses the internal cache and added -Window.raise_window()). Tabs converted to spaces (SF id: 1559082). - -** RECORD extension (SF id: 1538663) - -Alex Badea contributed a RECORD extension module, allowing Python Xlib -programs to capture mouse and keyboard events (or all other core or -extension events) easily. A demo is in the examples directory. See -http://refspecs.freestandards.org/X11/recordlib.pdf for more information. - -** XINERAMA extension - -Mike Meyer contributed a Xinerama extension module, allowing Python Xlib -programs to interrogate the X server about positions and sizes of -multiple screens. Specifications are a bit tricky to find - -http://sourceforge.net/projects/xinerama/ has some older specs and the -source code of the xorg project (libs & server code) has "definitive" -information. - -** Python 2.5 fix (SF id: 1623900) - -Bugfix to correct handling of XAuthority file parsing under Python 2.5 -causing failed authentication. - - -* Version 0.13 - 6 Aug 2006 (trialed as 0.13pre1 on 22 Jul 2006) - -A small release to incorporate a number of minor corrections and bug -fixes, including small changes to keysym handling, .Xauthority parsing, -several fixes to sending/receiving/flushing data, addition of -WithdrawnState to WMHints. petli completed documentation for Display -objects. - - -* Version 0.12 - 29 Mar 2002 - -** SHAPE extension - -Jeffrey Boser contributed a SHAPE extension module, allowing Python -Xlib programs to use shaped windows. Take a look at -examples/shapewin.py for ideas on how to use it. For more information -on shaped windows, see -http://ftp.x.org/pub/R6.6/xc/doc/hardcopy/Xext/shape.PS.gz - -** Python 2.2 fix - -In Python 2.2 FCNTL.FD_CLOEXEC has disappeared and FCNTL on the whole -is deprecated, so that had to be dealt with to make the Xlib work with -that version. - - -* Version 0.11 - 23 Feb 2002 - -** Regression tests for the protocol definition - -Regressions tests have been created for all requests, replies and -events. The tests use PyUnit, and the old resource database test has -been updated to use it too. - -** A lot of protocol bugfixes - -The bugs discovered by the regression tests have been fixed. -Additionally, a subtle bug in the core engine which could cause a -"can't happen"-error has also been found and fixed. - - -* Version 0.10 - 16 Dec 2001 - -** Event bugfix - -The xlib failed to parse the type code of events sent from other -clients using SendEvent. This has been fixed, adding the field -`send_event' to all event objects. - -** Event documentation - -The section "Event Types" in the manual has been written, detailing -all event types in the core protocol. The manual is now ten pages -thicker. - -** Basic support for GetImage/PutImage - -The Drawable methods put_image() and get_image() have been -implemented, but handling image data is still up to the user. There -is however, thanks to Ilpo Nyyssönen, a trivial method put_pil_image() -that will work on some combinations of image and drawable depth. It's -not perfect, but it's a start. - - -* Version 0.9 - 4 Dec 2001 - -** Documentation improved - -The documentation has been augmented with a chapter about event -handling, and a chapter listing all X objects and their methods -provided by the library. They are not described in any detail, -though. - -** Keysym handling improved - -The module Xlib.XK, which listed all keysyms, have been split up into -several sub-modules providing different sets of keysyms. By importing -Xlib.XK only the miscellany and latin1 sets are loaded, thus removing -some unnecessary clutter. - -Xlib.display.Display has two new methods (lookup_string() and -rebind_string()) for translating keysyms into characters. - -** Small changes to library interface - -The order of the Xlib.display.Display method send_event() parameters -event_mask and propagate has changed. - -Some of the class names in Xlib.protocol.event have changed, to have -the same namse as the corresponding. event type constant. - -** A few bugfixes - -If a display has more than one screen, the default screen was always -set to the highest numbered one, irrespective of what the user -specified in $DISPLAY. - -Some response attributes in Xlib.protocol.request accidentally -included a comma. - - - -* Version 0.8 - 12 Jan 2001 - -** Uses distutils - -Python Xlib now uses distutils to make installation and distribution -building easier. - -** Tested with Python 2.0 - -A few incompatibilities with Python 2.0 has been fixed. - - -* Version 0.7 - 8 Jan 2001 - -** Fixed the 64-bit platform fix. - -As it turns out, the attempted fix for 64-bit platforms in v0.6 didn't -really work. Close study of structmodules.c gave the answer why, and -now it really should work. Yeah. - -** Optimizations of core protocol engine - -Python Xlib is now at least 25% faster after the core of the protocol -engine has been rewritten. This is some quite cute code: tailor-made -methods are generated for all structures, resulting in a 650% speed-up -in generating binary data, and a 75% speed-up in parsing binary data. - -Interested Python hackers are recommended to take a look at the Struct -class in Xlib/protocol/rq.py. - - - -* Version 0.6 - 29 Dec 2000 - -** Fix to make python-xlib work on 64-bytes architectures. - -The struct and array modules uses sizeof(long) to determine the number -of bytes used when representing the type code 'l'. On Intel and VAX, -this is 32 bits as expected. On Alpha, it's 64 bits. python-xlib now -probes how large each type code is to avoid this problem. - - -* Version 0.5 - 28 Dec 2000 - -** Functions implemented to get and set all ICCCM WM properties on -Window objects. - -** Keymap cache implemented, with external Xlib.display.Display -methods keycode_to_keysym, keysym_to_keycode, keysym_to_keycodes and -refresh_keyboard_mapping. - -** Two utils for debugging X traffic implemented. -utils/tcpbug.py forwards a TCP connection and outputs the -communication between the client and the server. This output can then -be fed into utils/parsexbug.py, which will output all requests, -responses, errors and events in a readable format. - - -* Version 0.4 - 4 Oct 2000 - -** Thread support completed, but not really stresstested yet. - -** A framework for handling different platforms has been implemented, -together with generic Unix code and some simple VMS code. - -** Some documentation has been written. - -** The usual bunch of bugfixes. - diff --git a/README.md b/README.md deleted file mode 100644 index 69fa4e5c..00000000 --- a/README.md +++ /dev/null @@ -1,108 +0,0 @@ -[![Build Status](https://travis-ci.org/python-xlib/python-xlib.svg?branch=master)](https://travis-ci.org/python-xlib/python-xlib) -[![codecov.io](https://codecov.io/github/python-xlib/python-xlib/coverage.svg?branch=master)](https://codecov.io/github/python-xlib/python-xlib?branch=master) -[![Code Health](https://landscape.io/github/python-xlib/python-xlib/master/landscape.svg?style=flat)](https://landscape.io/github/python-xlib/python-xlib/master) - -# The Python X Library - -### Copyright - -The main part of the code is - - Copyright (C) 2000-2002 Peter Liljenberg - -Some contributed code is copyrighted by [the contributors](https://github.com/python-xlib/python-xlib/graphs/contributors), in these cases that is indicated in the source files in question. - -The Python X Library is released under LGPL v2.1 or later (since 2016), see the file LICENSE for details. -0.15rc1 and before were released under GPL v2. - -### Requirements - -The Python X Library requires Python 1.5.2 or newer. It has been -tested to various extents with Python 1.5.2 and 2.0 through 2.7. - - -### Installation - -The Python Xlib uses the standard distutils to make installation -easy. Distutils is shipped with Python 1.6 and newer. Python 1.5.2 -users must download and install distutils before Python Xlib can be -installed. Distutils can be downloaded from -http://www.python.org/sigs/distutils-sig/. - -Install Python Xlib by running this command: -``` -python setup.py install -``` -Installation can be modified with the normal install options, see the -documentation of distutils for details. - -Alternatively, you can run programs from the distribution directory, -or changing the module path in programs. - -There's a simple example program, implemented twice using both the -high-level interface and the low-level protocol. - - -### Introduction - -The Python X Library is intended to be a fully functional X client -library for Python programs. It is written entirely in Python, in -contrast to earlier X libraries for Python (the ancient X extension -and the newer plxlib) which were interfaces to the C Xlib. - -This is possible to do since X client programs communicate with the X -server via the X protocol. The communication takes place over TCP/IP, -Unix sockets, DECnet or any other streaming network protocol. The C -Xlib is merely an interface to this protocol, providing functions -suitable for a C environment. - -There are three advantages of implementing a pure Python library: - - * Integration: The library can make use of the wonderful object - system in Python, providing an easy-to-use class hierarchy. - - * Portability: The library will be usable on (almost) any computer - which have Python installed. A C interface could be problematic to - port to non-Unix systems, such as MS Windows or OpenVMS. - - * Maintainability: It is much easier to develop and debug native - Python modules than modules written in C. - - -### Project status - -The low-level protocol is complete, implementing client-side X11R6. -The high-level object oriented interface is also fully functional. -It is possible to write client applications with the library. -Currently, the only real application using Python Xlib is the window -manager PLWM, starting with version 2.0. - -There is a resource database implementation, ICCCM support and a -framework for adding X extension code. Several extensions have been -implemented; (RECORD, SHAPE, Xinerama, Composite, RANDR, and XTEST) -patches for additions are very welcome. - -There are most likely still bugs, but the library is at least stable -enough to run PLWM. A continuously bigger part of the library is -covered by regression tests, improving stability. - -The documentation is still quite rudimentary, but should be of some -help for people programming with the Xlib. X beginners should first -find some general texts on X. A very good starting point is -http://www.rahul.net/kenton/xsites.html - -See the file TODO for a detailed list of what is missing, -approximately ordered by importance. - - -### Contact information - -Author email: Peter Liljenberg - -Mailing list: http://sourceforge.net/mail/?group_id=10350 - -The Python X Library is a SourceForged project (currently migrating to GitHub). The project page is http://sourceforge.net/projects/python-xlib/. Source is available from that page as zip archive and from the [releases list](https://github.com/python-xlib/python-xlib/releases). - -There isn't any real web page yet, only a derivative of this file. It -is located at http://python-xlib.sourceforge.net/. It now also -features the documentation for downloading or browsing. diff --git a/README.rst b/README.rst new file mode 100644 index 00000000..ad040fe4 --- /dev/null +++ b/README.rst @@ -0,0 +1,125 @@ +The Python X Library +==================== + +|Build Status| |codecov.io| |Code Health| + +`Homepage`_ | `Releases`_ | `Changelog`_ + +Copyright +~~~~~~~~~ + +The main part of the code is + +:: + + Copyright (C) 2000-2002 Peter Liljenberg + +Some contributed code is copyrighted by `the contributors `_, +in these cases that is indicated in the source files in question. + +The Python X Library is released under LGPL v2.1 or later (since 2016), +see the file LICENSE for details. 0.15rc1 and before were released under +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 will only work on systems that have an X server installed, +such as most Linux distros, but will not work on Windows or MacOS. + +Installation +~~~~~~~~~~~~ + +The Python Xlib uses the standard setuptools package, to install run +this command: + +:: + + python setup.py install + +See the command help for details: ``python setup.py install -h``. + +Alternatively, you can run programs from the distribution directory, or +change the module path in programs. + +There's a simple example program, implemented twice using both the +high-level interface and the low-level protocol. + +Introduction +~~~~~~~~~~~~ + +The Python X Library is intended to be a fully functional X client +library for Python programs. It is written entirely in Python, in +contrast to earlier X libraries for Python (the ancient X extension and +the newer plxlib) which were interfaces to the C Xlib. + +This is possible to do since X client programs communicate with the X +server via the X protocol. The communication takes place over TCP/IP, +Unix sockets, DECnet or any other streaming network protocol. The C Xlib +is merely an interface to this protocol, providing functions suitable +for a C environment. + +There are three advantages of implementing a pure Python library: + +- Integration: The library can make use of the wonderful object system + in Python, providing an easy-to-use class hierarchy. + +- Portability: The library will be usable on (almost) any computer + which have Python installed. A C interface could be problematic to + port to non-Unix systems, such as MS Windows or OpenVMS. + +- Maintainability: It is much easier to develop and debug native Python + modules than modules written in C. + +Documentation +~~~~~~~~~~~~~ + +The reference manual is not finished by far, but is probably still useful. It +can be `browsed online `__. + +There are also some `example programs `_ and, of course, +`the standard X11 documentation `__ applies. + + +Project status +~~~~~~~~~~~~~~ + +The low-level protocol is complete, implementing client-side X11R6. The +high-level object oriented interface is also fully functional. It is +possible to write client applications with the library. Currently, the +only real application using Python Xlib is the window manager PLWM, +starting with version 2.0. + +There is a resource database implementation, ICCCM support and a +framework for adding X extension code. Several extensions have been +implemented (RECORD, SHAPE, Xinerama, Composite, RANDR, DAMAGE, +Generic Event, SECURITY, XFIXES, XInput, XTEST, NV-CONTROL, DPMS and XRes); +patches for additions are very welcome. + +There are most likely still bugs, but the library is at least stable +enough to run PLWM. A continuously bigger part of the library is covered +by regression tests, improving stability. + +The documentation is still quite rudimentary, but should be of some help +for people programming with the Xlib. X beginners should first find some +general texts on X. A very good starting point is +http://www.rahul.net/kenton/xsites.html + +See the file TODO for a detailed list of what is missing, approximately +ordered by importance. + +.. _Homepage: https://github.com/python-xlib/python-xlib +.. _Releases: https://github.com/python-xlib/python-xlib/releases +.. _Changelog: https://github.com/python-xlib/python-xlib/tree/master/CHANGELOG.md +.. _Contributors: https://github.com/python-xlib/python-xlib/graphs/contributors +.. _Examples: https://github.com/python-xlib/python-xlib/tree/master/examples + +.. |Build Status| image:: https://travis-ci.org/python-xlib/python-xlib.svg?branch=master + :target: https://travis-ci.org/python-xlib/python-xlib +.. |codecov.io| image:: https://codecov.io/github/python-xlib/python-xlib/coverage.svg?branch=master + :target: https://codecov.io/github/python-xlib/python-xlib?branch=master +.. |Code Health| image:: https://landscape.io/github/python-xlib/python-xlib/master/landscape.svg?style=flat + :target: https://landscape.io/github/python-xlib/python-xlib/master diff --git a/Xlib/X.py b/Xlib/X.py index 27ea3ec3..1a09e392 100644 --- a/Xlib/X.py +++ b/Xlib/X.py @@ -2,19 +2,22 @@ # # Copyright (C) 2000 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA # Avoid overwriting None if doing "from Xlib.X import *" NONE = 0 @@ -194,6 +197,8 @@ FamilyInternet = 0 FamilyDECnet = 1 FamilyChaos = 2 +FamilyServerInterpreted = 5 +FamilyInternetV6 = 6 PropertyNewValue = 0 PropertyDelete = 1 ColormapUninstalled = 0 diff --git a/Xlib/XK.py b/Xlib/XK.py index 56e3a334..7603ccd0 100644 --- a/Xlib/XK.py +++ b/Xlib/XK.py @@ -2,25 +2,28 @@ # # Copyright (C) 2000 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA # # This module defines some functions for working with X keysyms as well # as a modular keysym definition and loading mechanism. See the keysym # definition modules in the Xlib/keysymdef directory. -from X import NoSymbol +from Xlib.X import NoSymbol def string_to_keysym(keysym): '''Return the (16 bit) numeric code of keysym. diff --git a/Xlib/Xatom.py b/Xlib/Xatom.py index a8f0b3c2..b0137779 100644 --- a/Xlib/Xatom.py +++ b/Xlib/Xatom.py @@ -2,19 +2,22 @@ # # Copyright (C) 2000 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA PRIMARY = 1 SECONDARY = 2 diff --git a/Xlib/Xcursorfont.py b/Xlib/Xcursorfont.py index c0dadef4..19919438 100644 --- a/Xlib/Xcursorfont.py +++ b/Xlib/Xcursorfont.py @@ -2,19 +2,22 @@ # # Copyright (C) 2000 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA num_glyphs = 154 X_cursor = 0 diff --git a/Xlib/Xutil.py b/Xlib/Xutil.py index 33cf099d..768c5e2f 100644 --- a/Xlib/Xutil.py +++ b/Xlib/Xutil.py @@ -2,19 +2,22 @@ # # Copyright (C) 2000 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA NoValue = 0x0000 diff --git a/Xlib/__init__.py b/Xlib/__init__.py index 68f81232..28a0e017 100644 --- a/Xlib/__init__.py +++ b/Xlib/__init__.py @@ -2,23 +2,26 @@ # # Copyright (C) 2000-2002 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA -__version__ = (0, 15) +__version__ = (0, 33) -__version_extra__ = 'rc1' +__version_extra__ = '' __version_string__ = '.'.join(map(str, __version__)) + __version_extra__ diff --git a/Xlib/display.py b/Xlib/display.py index 71a49d24..87b9aa61 100644 --- a/Xlib/display.py +++ b/Xlib/display.py @@ -2,23 +2,29 @@ # # Copyright (C) 2000 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA # Python modules import types +# Python 2/3 compatibility. +from six import create_unbound_method + # Xlib modules from . import error from . import ext @@ -56,16 +62,16 @@ } class _BaseDisplay(protocol_display.Display): - resource_classes = _resource_baseclasses.copy() # Implement a cache of atom names, used by Window objects when # dealing with some ICCCM properties not defined in Xlib.Xatom def __init__(self, *args, **keys): - protocol_display.Display.__init__(*(self, ) + args, **keys) + self.resource_classes = _resource_baseclasses.copy() + protocol_display.Display.__init__(self, *args, **keys) self._atom_cache = {} - def get_atom(self, atomname, only_if_exists=0): + def get_atom(self, atomname, only_if_exists=False): if atomname in self._atom_cache: return self._atom_cache[atomname] @@ -124,16 +130,11 @@ def __init__(self, display = None): # Finalize extensions by creating new classes - for type, dict in self.class_extension_dicts.items(): - origcls = self.display.resource_classes[type] - if hasattr(types, 'ClassType'): - self.display.resource_classes[type] = types.ClassType(origcls.__name__, - (origcls,), - dict) - else: - self.display.resource_classes[type] = types.new_class(origcls.__name__, - (origcls,), - dict) + for class_name, dictionary in self.class_extension_dicts.items(): + origcls = self.display.resource_classes[class_name] + self.display.resource_classes[class_name] = type(origcls.__name__, + (origcls,), + dictionary) # Problem: we have already created some objects without the # extensions: the screen roots and default colormaps. @@ -221,7 +222,7 @@ class directly, since any X extensions dynamically added by the def __getattr__(self, attr): try: function = self.display_extension_methods[attr] - return types.MethodType(function, self, self.__class__) + return types.MethodType(function, self) except KeyError: raise AttributeError(attr) @@ -276,19 +277,19 @@ def extension_add_method(self, object, name, function): self.display_extension_methods[name] = function else: - types_ = (object, ) + _resource_hierarchy.get(object, ()) - for type in types_: - cls = _resource_baseclasses[type] + class_list = (object, ) + _resource_hierarchy.get(object, ()) + for class_name in class_list: + cls = _resource_baseclasses[class_name] if hasattr(cls, name): - raise AssertionError('attempting to replace %s method: %s' % (type, name)) + raise AssertionError('attempting to replace %s method: %s' % (class_name, name)) - method = types.MethodType(function, None, cls) + method = create_unbound_method(function, cls) # Maybe should check extension overrides too try: - self.class_extension_dicts[type][name] = method + self.class_extension_dicts[class_name][name] = method except KeyError: - self.class_extension_dicts[type] = { name: method } + self.class_extension_dicts[class_name] = { name: method } def extension_add_event(self, code, evt, name = None): """extension_add_event(code, evt, [name]) @@ -302,12 +303,8 @@ def extension_add_event(self, code, evt, name = None): extension_event. """ - if hasattr(types, 'ClassType'): - newevt = types.ClassType(evt.__name__, evt.__bases__, - evt.__dict__.copy()) - else: - newevt = types.new_class(evt.__name__, evt.__bases__, - evt.__dict__.copy()) + newevt = type(evt.__name__, evt.__bases__, + evt.__dict__.copy()) newevt._code = code self.display.add_extension_event(code, newevt) @@ -330,12 +327,8 @@ def extension_add_subevent(self, code, subcode, evt, name = None): extension_event. """ - if hasattr(types, 'ClassType'): - newevt = types.ClassType(evt.__name__, evt.__bases__, - evt.__dict__.copy()) - else: - newevt = types.new_class(evt.__name__, evt.__bases__, - evt.__dict__.copy()) + newevt = type(evt.__name__, evt.__bases__, + evt.__dict__.copy()) newevt._code = code self.display.add_extension_event(code, newevt, subcode) @@ -347,8 +340,8 @@ def extension_add_subevent(self, code, subcode, evt, name = None): # extension dict maintained in the display object setattr(self.extension_event, name, (code,subcode)) - def add_extension_error(self, code, err): - """add_extension_error(code, err) + def extension_add_error(self, code, err): + """extension_add_error(code, err) Add an extension error. CODE is the numeric code, and ERR is the error class. @@ -480,7 +473,7 @@ def rebind_string(self, keysym, newstring): ### X requests ### - def intern_atom(self, name, only_if_exists = 0): + def intern_atom(self, name, only_if_exists = False): """Intern the string name, returning its atom number. If only_if_exists is true and the atom does not already exist, it will not be created and X.NONE is returned.""" @@ -489,7 +482,7 @@ def intern_atom(self, name, only_if_exists = 0): only_if_exists = only_if_exists) return r.atom - def get_atom(self, atom, only_if_exists = 0): + def get_atom(self, atom, only_if_exists = False): """Alias for intern_atom, using internal cache""" return self.display.get_atom(atom, only_if_exists) @@ -508,7 +501,7 @@ def get_selection_owner(self, selection): selection = selection) return r.owner - def send_event(self, destination, event, event_mask = 0, propagate = 0, + def send_event(self, destination, event, event_mask = 0, propagate = False, onerror = None): """Send a synthetic event to the window destination which can be a window object, or X.PointerWindow or X.InputFocus. event is the @@ -524,7 +517,7 @@ def send_event(self, destination, event, event_mask = 0, propagate = 0, event = event) def ungrab_pointer(self, time, onerror = None): - """elease a grabbed pointer and any queued events. See + """Release a grabbed pointer and any queued events. See XUngrabPointer(3X11).""" request.UngrabPointer(display = self.display, onerror = onerror, @@ -668,7 +661,7 @@ def list_fonts_with_info(self, pattern, max_names): font_ascent font_descent replies_hint - See the descripton of XFontStruct in XGetFontProperty(3X11) + See the description of XFontStruct in XGetFontProperty(3X11) for details on these values. properties A list of properties. Each entry has two attributes: @@ -821,7 +814,7 @@ def change_pointer_control(self, accel = None, threshold = None, onerror = None) request.ChangePointerControl(display = self.display, onerror = onerror, do_accel = do_accel, - do_thres = do_threshold, + do_thresh = do_threshold, accel_num = accel_num, accel_denum = accel_denum, threshold = threshold) @@ -856,7 +849,8 @@ def get_screen_saver(self): def change_hosts(self, mode, host_family, host, onerror = None): """mode is either X.HostInsert or X.HostDelete. host_family is - one of X.FamilyInternet, X.FamilyDECnet or X.FamilyChaos. + one of X.FamilyInternet, X.FamilyDECnet, X.FamilyChaos, + X.FamilyServerInterpreted or X.FamilyInternetV6. host is a list of bytes. For the Internet family, it should be the four bytes of an IPv4 address.""" @@ -875,7 +869,7 @@ def list_hosts(self): The hosts on the access list. Each entry has the following attributes: family - X.FamilyInternet, X.FamilyDECnet, or X.FamilyChaos. + X.FamilyInternet, X.FamilyDECnet, X.FamilyChaos, X.FamilyServerInterpreted or X.FamilyInternetV6. name A list of byte values, the coding depends on family. For the Internet family, it is the 4 bytes of an IPv4 address. diff --git a/Xlib/error.py b/Xlib/error.py index 92ac60cb..3b6e13f8 100644 --- a/Xlib/error.py +++ b/Xlib/error.py @@ -2,19 +2,22 @@ # # Copyright (C) 2000 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA # Xlib modules from . import X @@ -67,7 +70,7 @@ class XError(rq.GetAttrData, Exception): ) def __init__(self, display, data): - self._data, data = self._fields.parse_binary(data, display, rawdict = 1) + self._data, _ = self._fields.parse_binary(data, display, rawdict = True) def __str__(self): s = [] diff --git a/Xlib/ext/__init__.py b/Xlib/ext/__init__.py index cd0de782..37229bac 100644 --- a/Xlib/ext/__init__.py +++ b/Xlib/ext/__init__.py @@ -2,19 +2,22 @@ # # Copyright (C) 2000 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA # __extensions__ is a list of tuples: (extname, extmod) # extname is the name of the extension according to the X @@ -33,6 +36,11 @@ ('XFIXES', 'xfixes'), ('SECURITY', 'security'), ('XInputExtension', 'xinput'), + ('NV-CONTROL', 'nvcontrol'), + ('DAMAGE', 'damage'), + ('DPMS', 'dpms'), + ('X-Resource', 'res'), + ('MIT-SCREEN-SAVER', 'screensaver'), ] __all__ = map(lambda x: x[1], __extensions__) diff --git a/Xlib/ext/composite.py b/Xlib/ext/composite.py index bdc37db2..5909b31e 100644 --- a/Xlib/ext/composite.py +++ b/Xlib/ext/composite.py @@ -4,19 +4,22 @@ # # Copyright (C) 2007 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA """Composite extension, allowing windows to be rendered to off-screen storage. @@ -30,7 +33,6 @@ graphics. """ -from Xlib import X from Xlib.protocol import rq from Xlib.xobject import drawable @@ -62,6 +64,8 @@ def query_version(self): return QueryVersion( display = self.display, opcode = self.display.get_extension_major(extname), + major_version=0, + minor_version=4 ) @@ -75,11 +79,12 @@ class RedirectWindow(rq.Request): rq.Pad(3), ) -def redirect_window(self, update): +def redirect_window(self, update, onerror = None): """Redirect the hierarchy starting at this window to off-screen storage. """ RedirectWindow(display = self.display, + onerror = onerror, opcode = self.display.get_extension_major(extname), window = self, update = update, @@ -96,11 +101,12 @@ class RedirectSubwindows(rq.Request): rq.Pad(3), ) -def redirect_subwindows(self, update): +def redirect_subwindows(self, update, onerror = None): """Redirect the hierarchies starting at all current and future children to this window to off-screen storage. """ RedirectSubwindows(display = self.display, + onerror = onerror, opcode = self.display.get_extension_major(extname), window = self, update = update, @@ -117,10 +123,11 @@ class UnredirectWindow(rq.Request): rq.Pad(3), ) -def unredirect_window(self, update): +def unredirect_window(self, update, onerror = None): """Stop redirecting this window hierarchy. """ UnredirectWindow(display = self.display, + onerror = onerror, opcode = self.display.get_extension_major(extname), window = self, update = update, @@ -137,10 +144,11 @@ class UnredirectSubindows(rq.Request): rq.Pad(3), ) -def unredirect_subwindows(self, update): +def unredirect_subwindows(self, update, onerror = None): """Stop redirecting the hierarchies of children to this window. """ RedirectWindow(display = self.display, + onerror = onerror, opcode = self.display.get_extension_major(extname), window = self, update = update, @@ -156,14 +164,15 @@ class CreateRegionFromBorderClip(rq.Request): rq.Window('window'), ) -def create_region_from_border_clip(self): +def create_region_from_border_clip(self, onerror = None): """Create a region of the border clip of the window, i.e. the area that is not clipped by the parent and any sibling windows. """ - + rid = self.display.allocate_resource_id() CreateRegionFromBorderClip( display = self.display, + onerror = onerror, opcode = self.display.get_extension_major(extname), region = rid, window = self, @@ -182,7 +191,7 @@ class NameWindowPixmap(rq.Request): rq.Pixmap('pixmap'), ) -def name_window_pixmap(self): +def name_window_pixmap(self, onerror = None): """Create a new pixmap that refers to the off-screen storage of the window, including its border. @@ -195,6 +204,7 @@ def name_window_pixmap(self): pid = self.display.allocate_resource_id() NameWindowPixmap(display = self.display, + onerror = onerror, opcode = self.display.get_extension_major(extname), window = self, pixmap = pid, @@ -202,7 +212,30 @@ def name_window_pixmap(self): cls = self.display.get_resource_class('pixmap', drawable.Pixmap) return cls(self.display, pid, owner = 1) - + +class GetOverlayWindow(rq.ReplyRequest): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(7), + rq.RequestLength(), + rq.Window('window') + ) + _reply = rq.Struct( + rq.ReplyCode(), + rq.Pad(1), + rq.Card16('sequence_number'), + rq.ReplyLength(), + rq.Window('overlay_window'), + rq.Pad(20), + ) + +def get_overlay_window(self): + """Return the overlay window of the root window. + """ + + return GetOverlayWindow(display = self.display, + opcode = self.display.get_extension_major(extname), + window = self) def init(disp, info): disp.extension_add_method('display', @@ -232,3 +265,7 @@ def init(disp, info): disp.extension_add_method('window', 'composite_name_window_pixmap', name_window_pixmap) + + disp.extension_add_method('window', + 'composite_get_overlay_window', + get_overlay_window) diff --git a/Xlib/ext/damage.py b/Xlib/ext/damage.py new file mode 100644 index 00000000..126d8507 --- /dev/null +++ b/Xlib/ext/damage.py @@ -0,0 +1,181 @@ +# Xlib.ext.damage -- DAMAGE extension module +# +# Copyright (C) 2018 Joseph Kogut +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA + + +from Xlib import X +from Xlib.protocol import rq, structs +from Xlib.error import XError + +extname = 'DAMAGE' + +# Event codes # +DamageNotifyCode = 0 + +# Error codes # +BadDamageCode = 0 + +class BadDamageError(XError): + pass + +# DamageReportLevel options +DamageReportRawRectangles = 0 +DamageReportDeltaRectangles = 1 +DamageReportBoundingBox = 2 +DamageReportNonEmpty = 3 + +DamageReportLevel = ( + DamageReportRawRectangles, + DamageReportDeltaRectangles, + DamageReportBoundingBox, + DamageReportNonEmpty, +) + +DAMAGE = rq.Card32 + +# Methods + +class QueryVersion(rq.ReplyRequest): + _request = rq.Struct(rq.Card8('opcode'), + rq.Opcode(0), + rq.RequestLength(), + rq.Card32('major_version'), + rq.Card32('minor_version'), + ) + + _reply = rq.Struct(rq.ReplyCode(), + rq.Pad(1), + rq.Card16('sequence_number'), + rq.ReplyLength(), + rq.Card32('major_version'), + rq.Card32('minor_version'), + rq.Pad(16), + ) + +def query_version(self): + return QueryVersion(display=self.display, + opcode=self.display.get_extension_major(extname), + major_version=1, + minor_version=1) + +class DamageCreate(rq.Request): + _request = rq.Struct(rq.Card8('opcode'), + rq.Opcode(1), + rq.RequestLength(), + DAMAGE('damage'), + rq.Drawable('drawable'), + rq.Set('level', 1, DamageReportLevel), + rq.Pad(3), + ) + +def damage_create(self, level): + did = self.display.allocate_resource_id() + DamageCreate(display=self.display, + opcode=self.display.get_extension_major(extname), + damage=did, + drawable=self.id, + level=level, + ) + return did + +class DamageDestroy(rq.Request): + _request = rq.Struct(rq.Card8('opcode'), + rq.Opcode(2), + rq.RequestLength(), + DAMAGE('damage') + ) + +def damage_destroy(self, damage): + DamageDestroy(display=self.display, + opcode=self.display.get_extension_major(extname), + damage=damage, + ) + + self.display.free_resource_id(damage) + +class DamageSubtract(rq.Request): + _request = rq.Struct(rq.Card8('opcode'), + rq.Opcode(3), + rq.RequestLength(), + DAMAGE('damage'), + rq.Card32('repair'), + rq.Card32('parts') + ) + +def damage_subtract(self, damage, repair=X.NONE, parts=X.NONE): + DamageSubtract(display=self.display, + opcode=self.display.get_extension_major(extname), + damage=damage, + repair=repair, + parts=parts) + +class DamageAdd(rq.Request): + _request = rq.Struct(rq.Card8('opcode'), + rq.Opcode(4), + rq.RequestLength(), + rq.Card32('repair'), + rq.Card32('parts'), + ) + +def damage_add(self, repair, parts): + DamageAdd(display=self.display, + opcode=self.display.get_extension_major(extname), + repair=repair, + parts=parts) + +# Events # + +class DamageNotify(rq.Event): + _code = None + _fields = rq.Struct( + rq.Card8('type'), + rq.Card8('level'), + rq.Card16('sequence_number'), + rq.Drawable('drawable'), + DAMAGE('damage'), + rq.Card32('timestamp'), + rq.Object('area', structs.Rectangle), + rq.Object('drawable_geometry', structs.Rectangle) + ) + +def init(disp, info): + disp.extension_add_method('display', + 'damage_query_version', + query_version) + + disp.extension_add_method('drawable', + 'damage_create', + damage_create) + + disp.extension_add_method('display', + 'damage_destroy', + damage_destroy) + + disp.extension_add_method('display', + 'damage_subtract', + damage_subtract) + + disp.extension_add_method('drawable', + 'damage_add', + damage_add) + + disp.extension_add_event(info.first_event + DamageNotifyCode, DamageNotify) + + disp.extension_add_error(code=BadDamageCode, err=BadDamageError) diff --git a/Xlib/ext/dpms.py b/Xlib/ext/dpms.py new file mode 100644 index 00000000..20b570bc --- /dev/null +++ b/Xlib/ext/dpms.py @@ -0,0 +1,232 @@ +# Xlib.ext.dpms -- X Display Power Management Signaling +# +# Copyright (C) 2020 Thiago Kenji Okada +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA + +''' +This extension provides X Protocol control over the VESA Display +Power Management Signaling (DPMS) characteristics of video boards +under control of the X Window System. + +Documentation: https://www.x.org/releases/X11R7.7/doc/xextproto/dpms.html +''' + +from Xlib.protocol import rq + +extname = 'DPMS' + + +# DPMS Extension Power Levels +# 0 DPMSModeOn In use +# 1 DPMSModeStandby Blanked, low power +# 2 DPMSModeSuspend Blanked, lower power +# 3 DPMSModeOff Shut off, awaiting activity +DPMSModeOn = 0 +DPMSModeStandby = 1 +DPMSModeSuspend = 2 +DPMSModeOff = 3 + +DPMSPowerLevel = ( + DPMSModeOn, + DPMSModeStandby, + DPMSModeSuspend, + DPMSModeOff, +) + + +class DPMSGetVersion(rq.ReplyRequest): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(0), + rq.RequestLength(), + rq.Card16('major_version'), + rq.Card16('minor_version'), + ) + + _reply = rq.Struct( + rq.ReplyCode(), + rq.Pad(1), + rq.Card16('sequence_number'), + rq.ReplyLength(), + rq.Card16('major_version'), + rq.Card16('minor_version'), + rq.Pad(20), + ) + + +def get_version(self): + return DPMSGetVersion(display=self.display, + opcode=self.display.get_extension_major(extname), + major_version=1, + minor_version=1) + + +class DPMSCapable(rq.ReplyRequest): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(1), + rq.RequestLength(), + ) + + _reply = rq.Struct( + rq.ReplyCode(), + rq.Pad(1), + rq.Card16('sequence_number'), + rq.ReplyLength(), + rq.Bool('capable'), + rq.Pad(23), + ) + + +def capable(self): + return DPMSCapable(display=self.display, + opcode=self.display.get_extension_major(extname), + major_version=1, + minor_version=1) + + +class DPMSGetTimeouts(rq.ReplyRequest): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(2), + rq.RequestLength(), + ) + + _reply = rq.Struct( + rq.ReplyCode(), + rq.Pad(1), + rq.Card16('sequence_number'), + rq.ReplyLength(), + rq.Card16('standby_timeout'), + rq.Card16('suspend_timeout'), + rq.Card16('off_timeout'), + rq.Pad(18), + ) + + +def get_timeouts(self): + return DPMSGetTimeouts(display=self.display, + opcode=self.display.get_extension_major(extname), + major_version=1, + minor_version=1) + + +class DPMSSetTimeouts(rq.Request): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(3), + rq.RequestLength(), + rq.Card16('standby_timeout'), + rq.Card16('suspend_timeout'), + rq.Card16('off_timeout'), + rq.Pad(2) + ) + + +def set_timeouts(self, standby_timeout, suspend_timeout, off_timeout): + return DPMSSetTimeouts(display=self.display, + opcode=self.display.get_extension_major(extname), + major_version=1, + minor_version=1, + standby_timeout=standby_timeout, + suspend_timeout=suspend_timeout, + off_timeout=off_timeout) + + +class DPMSEnable(rq.Request): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(4), + rq.RequestLength(), + ) + + +def enable(self): + return DPMSEnable(display=self.display, + opcode=self.display.get_extension_major(extname), + major_version=1, + minor_version=1) + + +class DPMSDisable(rq.Request): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(5), + rq.RequestLength(), + ) + + +def disable(self): + return DPMSDisable(display=self.display, + opcode=self.display.get_extension_major(extname), + major_version=1, + minor_version=1) + + +class DPMSForceLevel(rq.Request): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(6), + rq.RequestLength(), + rq.Resource('power_level', DPMSPowerLevel), + ) + + +def force_level(self, power_level): + return DPMSForceLevel(display=self.display, + opcode=self.display.get_extension_major(extname), + major_version=1, + minor_version=1, + power_level=power_level) + + +class DPMSInfo(rq.ReplyRequest): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(7), + rq.RequestLength(), + ) + + _reply = rq.Struct( + rq.ReplyCode(), + rq.Pad(1), + rq.Card16('sequence_number'), + rq.ReplyLength(), + rq.Card16('power_level'), + rq.Bool('state'), + rq.Pad(21), + ) + + +def info(self): + return DPMSInfo(display=self.display, + opcode=self.display.get_extension_major(extname), + major_version=1, + minor_version=1) + + +def init(disp, _info): + disp.extension_add_method('display', 'dpms_get_version', get_version) + disp.extension_add_method('display', 'dpms_capable', capable) + disp.extension_add_method('display', 'dpms_get_timeouts', get_timeouts) + disp.extension_add_method('display', 'dpms_set_timeouts', set_timeouts) + disp.extension_add_method('display', 'dpms_enable', enable) + disp.extension_add_method('display', 'dpms_disable', disable) + disp.extension_add_method('display', 'dpms_force_level', force_level) + disp.extension_add_method('display', 'dpms_info', info) diff --git a/Xlib/ext/ge.py b/Xlib/ext/ge.py index 749ace60..291ffa9a 100644 --- a/Xlib/ext/ge.py +++ b/Xlib/ext/ge.py @@ -3,19 +3,22 @@ # Copyright (C) 2012 Outpost Embedded, LLC # Forest Bond # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA ''' ge - Generic Event Extension diff --git a/Xlib/ext/nvcontrol.py b/Xlib/ext/nvcontrol.py new file mode 100644 index 00000000..7a21826c --- /dev/null +++ b/Xlib/ext/nvcontrol.py @@ -0,0 +1,5393 @@ +# Xlib.ext.nvcontrol -- NV-CONTROL extension module +# +# Copyright (C) 2019 Roberto Leinardi +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA + + +"""NV-CONTROL - provide access to the NV-CONTROL extension information.""" + +from Xlib.protocol import rq + +extname = 'NV-CONTROL' + + +def query_target_count(self, target): + """Return the target count""" + reply = NVCtrlQueryTargetCountReplyRequest(display=self.display, + opcode=self.display.get_extension_major(extname), + target_type=target.type()) + return int(reply._data.get('count')) + + +def query_int_attribute(self, target, display_mask, attr): + """Return the value of an integer attribute""" + reply = NVCtrlQueryAttributeReplyRequest(display=self.display, + opcode=self.display.get_extension_major(extname), + target_id=target.id(), + target_type=target.type(), + display_mask=display_mask, + attr=attr) + if not reply._data.get('flags'): + return None + return int(reply._data.get('value')) + + +def set_int_attribute(self, target, display_mask, attr, value): + """Set the value of an integer attribute""" + reply = NVCtrlSetAttributeAndGetStatusReplyRequest(display=self.display, + opcode=self.display.get_extension_major(extname), + target_id=target.id(), + target_type=target.type(), + display_mask=display_mask, + attr=attr, + value=value) + return reply._data.get('flags') != 0 + + +def query_string_attribute(self, target, display_mask, attr): + """Return the value of a string attribute""" + reply = NVCtrlQueryStringAttributeReplyRequest(display=self.display, + opcode=self.display.get_extension_major(extname), + target_id=target.id(), + target_type=target.type(), + display_mask=display_mask, + attr=attr) + if not reply._data.get('flags'): + return None + return str(reply._data.get('string')).strip('\0') + + +def query_valid_attr_values(self, target, display_mask, attr): + """Return the value of an integer attribute""" + reply = NVCtrlQueryValidAttributeValuesReplyRequest(display=self.display, + opcode=self.display.get_extension_major(extname), + target_id=target.id(), + target_type=target.type(), + display_mask=display_mask, + attr=attr) + if not reply._data.get('flags'): + return None + return int(reply._data.get('min')), int(reply._data.get('max')) + + +def query_binary_data(self, target, display_mask, attr): + """Return binary data""" + reply = NVCtrlQueryBinaryDataReplyRequest(display=self.display, + opcode=self.display.get_extension_major(extname), + target_id=target.id(), + target_type=target.type(), + display_mask=display_mask, + attr=attr) + if not reply._data.get('flags'): + return None + return reply._data.get('data') + + +def get_coolers_used_by_gpu(self, target): + reply = NVCtrlQueryListCard32ReplyRequest(display=self.display, + opcode=self.display.get_extension_major(extname), + target_id=target.id(), + target_type=target.type(), + display_mask=0, + attr=NV_CTRL_BINARY_DATA_COOLERS_USED_BY_GPU) + if not reply._data.get('flags'): + return None + fans = reply._data.get('list') + if len(fans) > 1: + return fans[1:] + else: + return None + + +def get_gpu_count(self): + """Return the number of GPU's present in the system.""" + return int(query_target_count(self, Gpu())) + + +def get_name(self, target): + """Return the GPU product name on which the specified X screen is running""" + return query_string_attribute(self, target, 0, NV_CTRL_STRING_PRODUCT_NAME) + + +def get_driver_version(self, target): + """Return the NVIDIA (kernel level) driver version for the specified screen or GPU""" + return query_string_attribute(self, target, 0, NV_CTRL_STRING_NVIDIA_DRIVER_VERSION) + + +def get_vbios_version(self, target): + """Return the version of the VBIOS for the specified screen or GPU""" + return query_string_attribute(self, target, 0, NV_CTRL_STRING_VBIOS_VERSION) + + +def get_gpu_uuid(self, target): + return query_string_attribute(self, target, 0, NV_CTRL_STRING_GPU_UUID) + + +def get_utilization_rates(self, target): + string = query_string_attribute(self, target, 0, NV_CTRL_STRING_GPU_UTILIZATION) + result = {} + if string is not None and string != '': + for line in string.split(','): + [key, value] = line.split('=')[:2] + result[key.strip()] = int(value) if value.isdigit() else value + return result + + +def get_performance_modes(self, target): + string = query_string_attribute(self, target, 0, NV_CTRL_STRING_PERFORMANCE_MODES) + result = [] + if string is not None and string != '': + for perf in string.split(';'): + perf_dict = {} + for line in perf.split(','): + [key, value] = line.split('=')[:2] + perf_dict[key.strip()] = int(value) if value.isdigit() else value + result.append(perf_dict) + return result + + +def get_clock_info(self, target): + string = query_string_attribute(self, target, 0, NV_CTRL_STRING_GPU_CURRENT_CLOCK_FREQS) + result = {} + if string is not None and string != '': + for line in string.split(','): + [key, value] = line.split('=')[:2] + result[key.strip()] = int(value) if value.isdigit() else value + return result + + +def get_vram(self, target): + return query_int_attribute(self, target, 0, NV_CTRL_VIDEO_RAM) + + +def get_irq(self, target): + """Return the interrupt request line used by the GPU driving the screen""" + return query_int_attribute(self, target, 0, NV_CTRL_IRQ) + + +def supports_framelock(self, target): + """Return whether the underlying GPU supports Frame Lock. + + All of the other frame lock attributes are only applicable if this returns True. + """ + return query_int_attribute(self, target, 0, NV_CTRL_FRAMELOCK) == 1 + + +def gvo_supported(self, screen): + """Return whether this X screen supports GVO + + If this screen does not support GVO output, then all other GVO attributes are unavailable. + """ + return query_int_attribute(self, screen, [], NV_CTRL_GVO_SUPPORTED) + + +def get_core_temp(self, target): + """Return the current core temperature of the GPU driving the X screen.""" + return query_int_attribute(self, target, 0, NV_CTRL_GPU_CORE_TEMPERATURE) + + +def get_core_threshold(self, target): + """Return the current GPU core slowdown threshold temperature. + + It reflects the temperature at which the GPU is throttled to prevent overheating. + """ + return query_int_attribute(self, target, 0, NV_CTRL_GPU_CORE_THRESHOLD) + + +def get_default_core_threshold(self, target): + """Return the default core threshold temperature.""" + return query_int_attribute(self, target, 0, NV_CTRL_GPU_DEFAULT_CORE_THRESHOLD) + + +def get_max_core_threshold(self, target): + """Return the maximum core threshold temperature.""" + return query_int_attribute(self, target, 0, NV_CTRL_GPU_MAX_CORE_THRESHOLD) + + +def get_ambient_temp(self, target): + """Return the current temperature in the immediate neighbourhood of the GPU driving the X screen.""" + return query_int_attribute(self, target, 0, NV_CTRL_AMBIENT_TEMPERATURE) + + +def get_cuda_cores(self, target): + return query_int_attribute(self, target, 0, NV_CTRL_GPU_CORES) + + +def get_memory_bus_width(self, target): + return query_int_attribute(self, target, 0, NV_CTRL_GPU_MEMORY_BUS_WIDTH) + + +def get_total_dedicated_gpu_memory(self, target): + return query_int_attribute(self, target, 0, NV_CTRL_TOTAL_DEDICATED_GPU_MEMORY) + + +def get_used_dedicated_gpu_memory(self, target): + return query_int_attribute(self, target, 0, NV_CTRL_USED_DEDICATED_GPU_MEMORY) + + +def get_curr_pcie_link_width(self, target): + return query_int_attribute(self, target, 0, NV_CTRL_GPU_PCIE_CURRENT_LINK_WIDTH) + + +def get_max_pcie_link_width(self, target): + return query_int_attribute(self, target, 0, NV_CTRL_GPU_PCIE_MAX_LINK_WIDTH) + + +def get_curr_pcie_link_generation(self, target): + return query_int_attribute(self, target, 0, NV_CTRL_GPU_PCIE_GENERATION) + + +def get_encoder_utilization(self, target): + return query_int_attribute(self, target, 0, NV_CTRL_VIDEO_ENCODER_UTILIZATION) + + +def get_decoder_utilization(self, target): + return query_int_attribute(self, target, 0, NV_CTRL_VIDEO_DECODER_UTILIZATION) + + +def get_current_performance_level(self, target): + return query_int_attribute(self, target, 0, NV_CTRL_GPU_CURRENT_PERFORMANCE_LEVEL) + + +def get_gpu_nvclock_offset(self, target, perf_level): + return query_int_attribute(self, target, perf_level, NV_CTRL_GPU_NVCLOCK_OFFSET) + + +def set_gpu_nvclock_offset(self, target, perf_level, offset): + return set_int_attribute(self, target, perf_level, NV_CTRL_GPU_NVCLOCK_OFFSET, offset) + + +def set_gpu_nvclock_offset_all_levels(self, target, offset): + return set_int_attribute(self, target, 0, NV_CTRL_GPU_NVCLOCK_OFFSET_ALL_PERFORMANCE_LEVELS, offset) + + +def get_gpu_nvclock_offset_range(self, target, perf_level): + return query_valid_attr_values(self, target, perf_level, NV_CTRL_GPU_NVCLOCK_OFFSET) + + +def get_mem_transfer_rate_offset(self, target, perf_level): + return query_int_attribute(self, target, perf_level, NV_CTRL_GPU_MEM_TRANSFER_RATE_OFFSET) + + +def set_mem_transfer_rate_offset(self, target, perf_level, offset): + return set_int_attribute(self, target, perf_level, NV_CTRL_GPU_MEM_TRANSFER_RATE_OFFSET, offset) + + +def set_mem_transfer_rate_offset_all_levels(self, target, offset): + return set_int_attribute(self, target, 0, NV_CTRL_GPU_MEM_TRANSFER_RATE_OFFSET_ALL_PERFORMANCE_LEVELS, offset) + + +def get_mem_transfer_rate_offset_range(self, target, perf_level): + return query_valid_attr_values(self, target, perf_level, NV_CTRL_GPU_MEM_TRANSFER_RATE_OFFSET) + + +def get_cooler_manual_control_enabled(self, target): + return query_int_attribute(self, target, 0, NV_CTRL_GPU_COOLER_MANUAL_CONTROL) + + +def set_cooler_manual_control_enabled(self, target, enabled): + return set_int_attribute(self, target, 0, NV_CTRL_GPU_COOLER_MANUAL_CONTROL, 1 if enabled else 0) == 1 + + +def get_fan_duty(self, target): + return query_int_attribute(self, target, 0, NV_CTRL_THERMAL_COOLER_CURRENT_LEVEL) + + +def set_fan_duty(self, cooler, speed): + return set_int_attribute(self, cooler, 0, NV_CTRL_THERMAL_COOLER_LEVEL, speed) + + +def get_fan_rpm(self, target): + return query_int_attribute(self, target, 0, NV_CTRL_THERMAL_COOLER_SPEED) + + +def get_max_displays(self, target): + """Return the maximum number of display devices that can be driven simultaneously on a GPU. + + Note that this does not indicate the maximum number of bits that can be set in + NV_CTRL_CONNECTED_DISPLAYS, because more display devices can be connected than are actively + in use. + """ + return query_int_attribute(self, target, 0, NV_CTRL_MAX_DISPLAYS) + + +def _displaystr2num(st): + """Return a display number from a string""" + num = None + for s, n in [('DFP-', 16), ('TV-', 8), ('CRT-', 0)]: + if st.startswith(s): + try: + curnum = int(st[len(s):]) + if 0 <= curnum <= 7: + num = n + curnum + break + except Exception: + pass + if num is not None: + return num + else: + raise ValueError('Unrecognised display name: ' + st) + + +def _displays2mask(displays): + """Return a display mask from an array of display numbers.""" + mask = 0 + for d in displays: + mask += (1 << _displaystr2num(d)) + return mask + + +def init(disp, info): + disp.extension_add_method('display', 'nvcontrol_query_target_count', query_target_count) + disp.extension_add_method('display', 'nvcontrol_query_int_attribute', query_int_attribute) + disp.extension_add_method('display', 'nvcontrol_query_string_attribute', query_string_attribute) + disp.extension_add_method('display', 'nvcontrol_query_valid_attr_values', query_valid_attr_values) + disp.extension_add_method('display', 'nvcontrol_query_binary_data', query_binary_data) + disp.extension_add_method('display', 'nvcontrol_get_gpu_count', get_gpu_count) + disp.extension_add_method('display', 'nvcontrol_get_vram', get_vram) + disp.extension_add_method('display', 'nvcontrol_get_irq', get_irq) + disp.extension_add_method('display', 'nvcontrol_supports_framelock', supports_framelock) + disp.extension_add_method('display', 'nvcontrol_get_core_temp', get_core_temp) + disp.extension_add_method('display', 'nvcontrol_get_core_threshold', get_core_threshold) + disp.extension_add_method('display', 'nvcontrol_get_default_core_threshold', get_default_core_threshold) + disp.extension_add_method('display', 'nvcontrol_get_max_core_threshold', get_max_core_threshold) + disp.extension_add_method('display', 'nvcontrol_get_ambient_temp', get_ambient_temp) + disp.extension_add_method('display', 'nvcontrol_get_cuda_cores', get_cuda_cores) + disp.extension_add_method('display', 'nvcontrol_get_memory_bus_width', get_memory_bus_width) + disp.extension_add_method('display', 'nvcontrol_get_total_dedicated_gpu_memory', get_total_dedicated_gpu_memory) + disp.extension_add_method('display', 'nvcontrol_get_used_dedicated_gpu_memory', get_used_dedicated_gpu_memory) + disp.extension_add_method('display', 'nvcontrol_get_curr_pcie_link_width', get_curr_pcie_link_width) + disp.extension_add_method('display', 'nvcontrol_get_max_pcie_link_width', get_max_pcie_link_width) + disp.extension_add_method('display', 'nvcontrol_get_curr_pcie_link_generation', get_curr_pcie_link_generation) + disp.extension_add_method('display', 'nvcontrol_get_encoder_utilization', get_encoder_utilization) + disp.extension_add_method('display', 'nvcontrol_get_decoder_utilization', get_decoder_utilization) + disp.extension_add_method('display', 'nvcontrol_get_current_performance_level', get_current_performance_level) + disp.extension_add_method('display', 'nvcontrol_get_gpu_nvclock_offset', get_gpu_nvclock_offset) + disp.extension_add_method('display', 'nvcontrol_set_gpu_nvclock_offset', set_gpu_nvclock_offset) + disp.extension_add_method('display', 'nvcontrol_set_gpu_nvclock_offset_all_levels', set_gpu_nvclock_offset_all_levels) + disp.extension_add_method('display', 'nvcontrol_get_mem_transfer_rate_offset', get_mem_transfer_rate_offset) + disp.extension_add_method('display', 'nvcontrol_set_mem_transfer_rate_offset', set_mem_transfer_rate_offset) + disp.extension_add_method('display', 'nvcontrol_set_mem_transfer_rate_offset_all_levels', set_mem_transfer_rate_offset_all_levels) + disp.extension_add_method('display', 'nvcontrol_get_cooler_manual_control_enabled', + get_cooler_manual_control_enabled) + disp.extension_add_method('display', 'nvcontrol_get_fan_duty', get_fan_duty) + disp.extension_add_method('display', 'nvcontrol_set_fan_duty', set_fan_duty) + disp.extension_add_method('display', 'nvcontrol_get_fan_rpm', get_fan_rpm) + disp.extension_add_method('display', 'nvcontrol_get_coolers_used_by_gpu', get_coolers_used_by_gpu) + disp.extension_add_method('display', 'nvcontrol_get_max_displays', get_max_displays) + disp.extension_add_method('display', 'nvcontrol_get_name', get_name) + disp.extension_add_method('display', 'nvcontrol_get_driver_version', get_driver_version) + disp.extension_add_method('display', 'nvcontrol_get_vbios_version', get_vbios_version) + disp.extension_add_method('display', 'nvcontrol_get_gpu_uuid', get_gpu_uuid) + disp.extension_add_method('display', 'nvcontrol_get_utilization_rates', get_utilization_rates) + disp.extension_add_method('display', 'nvcontrol_get_performance_modes', get_performance_modes) + disp.extension_add_method('display', 'nvcontrol_get_clock_info', get_clock_info) + disp.extension_add_method('display', 'nvcontrol_set_cooler_manual_control_enabled', + set_cooler_manual_control_enabled) + disp.extension_add_method('display', 'nvcontrol_get_gpu_nvclock_offset_range', + get_gpu_nvclock_offset_range) + disp.extension_add_method('display', 'nvcontrol_get_mem_transfer_rate_offset_range', + get_mem_transfer_rate_offset_range) + + +############################################################################ +# +# Attributes +# +# Some attributes may only be read; some may require a display_mask +# argument and others may be valid only for specific target types. +# This information is encoded in the "permission" comment after each +# attribute #define, and can be queried at run time with +# XNVCTRLQueryValidAttributeValues() and/or +# XNVCTRLQueryValidTargetAttributeValues() +# +# Key to Integer Attribute "Permissions": +# +# R: The attribute is readable (in general, all attributes will be +# readable) +# +# W: The attribute is writable (attributes may not be writable for +# various reasons: they represent static system information, they +# can only be changed by changing an XF86Config option, etc). +# +# D: The attribute requires the display mask argument. The +# attributes NV_CTRL_CONNECTED_DISPLAYS and NV_CTRL_ENABLED_DISPLAYS +# will be a bitmask of what display devices are connected and what +# display devices are enabled for use in X, respectively. Each bit +# in the bitmask represents a display device; it is these bits which +# should be used as the display_mask when dealing with attributes +# designated with "D" below. For attributes that do not require the +# display mask, the argument is ignored. +# +# Alternatively, NV-CONTROL versions 1.27 and greater allow these +# attributes to be accessed via display target types, in which case +# the display_mask is ignored. +# +# G: The attribute may be queried using an NV_CTRL_TARGET_TYPE_GPU +# target type via XNVCTRLQueryTargetAttribute(). +# +# F: The attribute may be queried using an NV_CTRL_TARGET_TYPE_FRAMELOCK +# target type via XNVCTRLQueryTargetAttribute(). +# +# X: When Xinerama is enabled, this attribute is kept consistent across +# all Physical X Screens; assignment of this attribute will be +# broadcast by the NVIDIA X Driver to all X Screens. +# +# V: The attribute may be queried using an NV_CTRL_TARGET_TYPE_VCSC +# target type via XNVCTRLQueryTargetAttribute(). +# +# I: The attribute may be queried using an NV_CTRL_TARGET_TYPE_GVI target type +# via XNVCTRLQueryTargetAttribute(). +# +# Q: The attribute is a 64-bit integer attribute; use the 64-bit versions +# of the appropriate query interfaces. +# +# C: The attribute may be queried using an NV_CTRL_TARGET_TYPE_COOLER target +# type via XNVCTRLQueryTargetAttribute(). +# +# S: The attribute may be queried using an NV_CTRL_TARGET_TYPE_THERMAL_SENSOR +# target type via XNVCTRLQueryTargetAttribute(). +# +# T: The attribute may be queried using an +# NV_CTRL_TARGET_TYPE_3D_VISION_PRO_TRANSCEIVER target type +# via XNVCTRLQueryTargetAttribute(). +# +# NOTE: Unless mentioned otherwise, all attributes may be queried using +# an NV_CTRL_TARGET_TYPE_X_SCREEN target type via +# XNVCTRLQueryTargetAttribute(). +# + + +############################################################################ + +# +# Integer attributes: +# +# Integer attributes can be queried through the XNVCTRLQueryAttribute() and +# XNVCTRLQueryTargetAttribute() function calls. +# +# Integer attributes can be set through the XNVCTRLSetAttribute() and +# XNVCTRLSetTargetAttribute() function calls. +# +# Unless otherwise noted, all integer attributes can be queried/set +# using an NV_CTRL_TARGET_TYPE_X_SCREEN target. Attributes that cannot +# take an NV_CTRL_TARGET_TYPE_X_SCREEN also cannot be queried/set through +# XNVCTRLQueryAttribute()/XNVCTRLSetAttribute() (Since these assume +# an X Screen target). +# + + +# +# NV_CTRL_FLATPANEL_SCALING - not supported +# + +NV_CTRL_FLATPANEL_SCALING = 2 # not supported +NV_CTRL_FLATPANEL_SCALING_DEFAULT = 0 # not supported +NV_CTRL_FLATPANEL_SCALING_NATIVE = 1 # not supported +NV_CTRL_FLATPANEL_SCALING_SCALED = 2 # not supported +NV_CTRL_FLATPANEL_SCALING_CENTERED = 3 # not supported +NV_CTRL_FLATPANEL_SCALING_ASPECT_SCALED = 4 # not supported + +# +# NV_CTRL_FLATPANEL_DITHERING - not supported +# +# NV_CTRL_DITHERING should be used instead. +# + +NV_CTRL_FLATPANEL_DITHERING = 3 # not supported +NV_CTRL_FLATPANEL_DITHERING_DEFAULT = 0 # not supported +NV_CTRL_FLATPANEL_DITHERING_ENABLED = 1 # not supported +NV_CTRL_FLATPANEL_DITHERING_DISABLED = 2 # not supported + +# +# NV_CTRL_DITHERING - the requested dithering configuration; +# possible values are: +# +# 0: auto (the driver will decide when to dither) +# 1: enabled (the driver will always dither when possible) +# 2: disabled (the driver will never dither) +# + +NV_CTRL_DITHERING = 3 # RWDG +NV_CTRL_DITHERING_AUTO = 0 +NV_CTRL_DITHERING_ENABLED = 1 +NV_CTRL_DITHERING_DISABLED = 2 + +# +# NV_CTRL_DIGITAL_VIBRANCE - sets the digital vibrance level for the +# specified display device. +# + +NV_CTRL_DIGITAL_VIBRANCE = 4 # RWDG + +# +# NV_CTRL_BUS_TYPE - returns the bus type through which the specified device +# is connected to the computer. +# When this attribute is queried on an X screen target, the bus type of the +# GPU driving the X screen is returned. +# + +NV_CTRL_BUS_TYPE = 5 # R--GI +NV_CTRL_BUS_TYPE_AGP = 0 +NV_CTRL_BUS_TYPE_PCI = 1 +NV_CTRL_BUS_TYPE_PCI_EXPRESS = 2 +NV_CTRL_BUS_TYPE_INTEGRATED = 3 + +# +# NV_CTRL_TOTAL_GPU_MEMORY - returns the total amount of memory available +# to the specified GPU (or the GPU driving the specified X +# screen). Note: if the GPU supports TurboCache(TM), the value +# reported may exceed the amount of video memory installed on the +# GPU. The value reported for integrated GPUs may likewise exceed +# the amount of dedicated system memory set aside by the system +# BIOS for use by the integrated GPU. +# + +NV_CTRL_TOTAL_GPU_MEMORY = 6 # R--G +NV_CTRL_VIDEO_RAM = NV_CTRL_TOTAL_GPU_MEMORY + +# +# NV_CTRL_IRQ - returns the interrupt request line used by the specified +# device. +# When this attribute is queried on an X screen target, the IRQ of the GPU +# driving the X screen is returned. +# + +NV_CTRL_IRQ = 7 # R--GI + +# +# NV_CTRL_OPERATING_SYSTEM - returns the operating system on which +# the X server is running. +# + +NV_CTRL_OPERATING_SYSTEM = 8 # R--G +NV_CTRL_OPERATING_SYSTEM_LINUX = 0 +NV_CTRL_OPERATING_SYSTEM_FREEBSD = 1 +NV_CTRL_OPERATING_SYSTEM_SUNOS = 2 + +# +# NV_CTRL_SYNC_TO_VBLANK - enables sync to vblank for OpenGL clients. +# This setting is only applied to OpenGL clients that are started +# after this setting is applied. +# + +NV_CTRL_SYNC_TO_VBLANK = 9 # RW-X +NV_CTRL_SYNC_TO_VBLANK_OFF = 0 +NV_CTRL_SYNC_TO_VBLANK_ON = 1 + +# +# NV_CTRL_LOG_ANISO - enables anisotropic filtering for OpenGL +# clients; on some NVIDIA hardware, this can only be enabled or +# disabled; on other hardware different levels of anisotropic +# filtering can be specified. This setting is only applied to OpenGL +# clients that are started after this setting is applied. +# + +NV_CTRL_LOG_ANISO = 10 # RW-X + +# +# NV_CTRL_FSAA_MODE - the FSAA setting for OpenGL clients; possible +# FSAA modes: +# +# NV_CTRL_FSAA_MODE_2x "2x Bilinear Multisampling" +# NV_CTRL_FSAA_MODE_2x_5t "2x Quincunx Multisampling" +# NV_CTRL_FSAA_MODE_15x15 "1.5 x 1.5 Supersampling" +# NV_CTRL_FSAA_MODE_2x2 "2 x 2 Supersampling" +# NV_CTRL_FSAA_MODE_4x "4x Bilinear Multisampling" +# NV_CTRL_FSAA_MODE_4x_9t "4x Gaussian Multisampling" +# NV_CTRL_FSAA_MODE_8x "2x Bilinear Multisampling by 4x Supersampling" +# NV_CTRL_FSAA_MODE_16x "4x Bilinear Multisampling by 4x Supersampling" +# NV_CTRL_FSAA_MODE_8xS "4x Multisampling by 2x Supersampling" +# +# This setting is only applied to OpenGL clients that are started +# after this setting is applied. +# + +NV_CTRL_FSAA_MODE = 11 # RW-X +NV_CTRL_FSAA_MODE_NONE = 0 +NV_CTRL_FSAA_MODE_2x = 1 +NV_CTRL_FSAA_MODE_2x_5t = 2 +NV_CTRL_FSAA_MODE_15x15 = 3 +NV_CTRL_FSAA_MODE_2x2 = 4 +NV_CTRL_FSAA_MODE_4x = 5 +NV_CTRL_FSAA_MODE_4x_9t = 6 +NV_CTRL_FSAA_MODE_8x = 7 +NV_CTRL_FSAA_MODE_16x = 8 +NV_CTRL_FSAA_MODE_8xS = 9 +NV_CTRL_FSAA_MODE_8xQ = 10 +NV_CTRL_FSAA_MODE_16xS = 11 +NV_CTRL_FSAA_MODE_16xQ = 12 +NV_CTRL_FSAA_MODE_32xS = 13 +NV_CTRL_FSAA_MODE_32x = 14 +NV_CTRL_FSAA_MODE_64xS = 15 +NV_CTRL_FSAA_MODE_MAX = NV_CTRL_FSAA_MODE_64xS + +# +# NV_CTRL_UBB - returns whether UBB is enabled for the specified X +# screen. +# + +NV_CTRL_UBB = 13 # R-- +NV_CTRL_UBB_OFF = 0 +NV_CTRL_UBB_ON = 1 + +# +# NV_CTRL_OVERLAY - returns whether the RGB overlay is enabled for +# the specified X screen. +# + +NV_CTRL_OVERLAY = 14 # R-- +NV_CTRL_OVERLAY_OFF = 0 +NV_CTRL_OVERLAY_ON = 1 + +# +# NV_CTRL_STEREO - returns whether stereo (and what type) is enabled +# for the specified X screen. +# + +NV_CTRL_STEREO = 16 # R-- +NV_CTRL_STEREO_OFF = 0 +NV_CTRL_STEREO_DDC = 1 +NV_CTRL_STEREO_BLUELINE = 2 +NV_CTRL_STEREO_DIN = 3 +NV_CTRL_STEREO_PASSIVE_EYE_PER_DPY = 4 +NV_CTRL_STEREO_VERTICAL_INTERLACED = 5 +NV_CTRL_STEREO_COLOR_INTERLACED = 6 +NV_CTRL_STEREO_HORIZONTAL_INTERLACED = 7 +NV_CTRL_STEREO_CHECKERBOARD_PATTERN = 8 +NV_CTRL_STEREO_INVERSE_CHECKERBOARD_PATTERN = 9 +NV_CTRL_STEREO_3D_VISION = 10 +NV_CTRL_STEREO_3D_VISION_PRO = 11 +NV_CTRL_STEREO_HDMI_3D = 12 +NV_CTRL_STEREO_TRIDELITY_SL = 13 +NV_CTRL_STEREO_INBAND_STEREO_SIGNALING = 14 +NV_CTRL_STEREO_MAX = NV_CTRL_STEREO_INBAND_STEREO_SIGNALING + +# +# NV_CTRL_EMULATE - not supported +# + +NV_CTRL_EMULATE = 17 # not supported +NV_CTRL_EMULATE_NONE = 0 # not supported + +# +# NV_CTRL_TWINVIEW - returns whether TwinView is enabled for the +# specified X screen. +# + +NV_CTRL_TWINVIEW = 18 # R-- +NV_CTRL_TWINVIEW_NOT_ENABLED = 0 +NV_CTRL_TWINVIEW_ENABLED = 1 + +# +# NV_CTRL_CONNECTED_DISPLAYS - deprecated +# +# NV_CTRL_BINARY_DATA_DISPLAYS_CONNECTED_TO_GPU and +# NV_CTRL_BINARY_DATA_DISPLAYS_ASSIGNED_TO_XSCREEN should be used instead. +# + +NV_CTRL_CONNECTED_DISPLAYS = 19 # deprecated + +# +# NV_CTRL_ENABLED_DISPLAYS - Event that notifies when one or more display +# devices are enabled or disabled on a GPU and/or X screen. +# +# This attribute may be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_GPU or NV_CTRL_TARGET_TYPE_X_SCREEN target. +# +# Note: Querying this value has been deprecated. +# NV_CTRL_BINARY_DATA_DISPLAYS_CONNECTED_TO_GPU, +# NV_CTRL_DISPLAY_ENABLED, and +# NV_CTRL_BINARY_DATA_DISPLAYS_ENABLED_ON_XSCREEN should be used +# instead to obtain the list of enabled displays. +# + +NV_CTRL_ENABLED_DISPLAYS = 20 # ---G + +############################################################################ +# +# Integer attributes specific to configuring Frame Lock on boards that +# support it. +# + + +# +# NV_CTRL_FRAMELOCK - returns whether the underlying GPU supports +# Frame Lock. All of the other frame lock attributes are only +# applicable if NV_CTRL_FRAMELOCK is _SUPPORTED. +# +# This attribute may be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_GPU or NV_CTRL_TARGET_TYPE_X_SCREEN target. +# + +NV_CTRL_FRAMELOCK = 21 # R--G +NV_CTRL_FRAMELOCK_NOT_SUPPORTED = 0 +NV_CTRL_FRAMELOCK_SUPPORTED = 1 + +# +# NV_CTRL_FRAMELOCK_MASTER - deprecated +# +# NV_CTRL_FRAMELOCK_DISPLAY_CONFIG should be used instead. +# + +NV_CTRL_FRAMELOCK_MASTER = 22 # deprecated +NV_CTRL_FRAMELOCK_MASTER_FALSE = 0 # deprecated +NV_CTRL_FRAMELOCK_MASTER_TRUE = 1 # deprecated + +# +# NV_CTRL_FRAMELOCK_POLARITY - sync either to the rising edge of the +# frame lock pulse, the falling edge of the frame lock pulse or both. +# +# On Quadro Sync II, this attribute is ignored when +# NV_CTRL_USE_HOUSE_SYNC is OUTPUT. +# +# This attribute may be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_FRAMELOCK or NV_CTRL_TARGET_TYPE_X_SCREEN +# target. +# + +NV_CTRL_FRAMELOCK_POLARITY = 23 # RW-F +NV_CTRL_FRAMELOCK_POLARITY_RISING_EDGE = 0x1 +NV_CTRL_FRAMELOCK_POLARITY_FALLING_EDGE = 0x2 +NV_CTRL_FRAMELOCK_POLARITY_BOTH_EDGES = 0x3 + +# +# NV_CTRL_FRAMELOCK_SYNC_DELAY - delay between the frame lock pulse +# and the GPU sync. This value must be multiplied by +# NV_CTRL_FRAMELOCK_SYNC_DELAY_RESOLUTION to determine the sync delay in +# nanoseconds. +# +# This attribute may be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_FRAMELOCK or NV_CTRL_TARGET_TYPE_X_SCREEN +# target. +# +# USAGE NOTE: NV_CTRL_FRAMELOCK_SYNC_DELAY_MAX and +# NV_CTRL_FRAMELOCK_SYNC_DELAY_FACTOR are deprecated. +# The Sync Delay _MAX and _FACTOR are different for different +# Quadro Sync products and so, to be correct, the valid values for +# NV_CTRL_FRAMELOCK_SYNC_DELAY must be queried to get the range +# of acceptable sync delay values, and +# NV_CTRL_FRAMELOCK_SYNC_DELAY_RESOLUTION must be queried to +# obtain the correct factor. +# + +NV_CTRL_FRAMELOCK_SYNC_DELAY = 24 # RW-F +NV_CTRL_FRAMELOCK_SYNC_DELAY_MAX = 2047 # deprecated +NV_CTRL_FRAMELOCK_SYNC_DELAY_FACTOR = 7.81 # deprecated + +# +# NV_CTRL_FRAMELOCK_SYNC_INTERVAL - how many house sync pulses +# between the frame lock sync generation (0 == sync every house sync); +# this only applies to the master when receiving house sync. +# +# This attribute may be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_FRAMELOCK or NV_CTRL_TARGET_TYPE_X_SCREEN +# target. +# + +NV_CTRL_FRAMELOCK_SYNC_INTERVAL = 25 # RW-F + +# +# NV_CTRL_FRAMELOCK_PORT0_STATUS - status of the rj45 port0. +# +# This attribute may be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_FRAMELOCK or NV_CTRL_TARGET_TYPE_X_SCREEN +# target. +# + +NV_CTRL_FRAMELOCK_PORT0_STATUS = 26 # R--F +NV_CTRL_FRAMELOCK_PORT0_STATUS_INPUT = 0 +NV_CTRL_FRAMELOCK_PORT0_STATUS_OUTPUT = 1 + +# +# NV_CTRL_FRAMELOCK_PORT1_STATUS - status of the rj45 port1. +# +# This attribute may be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_FRAMELOCK or NV_CTRL_TARGET_TYPE_X_SCREEN +# target. +# + +NV_CTRL_FRAMELOCK_PORT1_STATUS = 27 # R--F +NV_CTRL_FRAMELOCK_PORT1_STATUS_INPUT = 0 +NV_CTRL_FRAMELOCK_PORT1_STATUS_OUTPUT = 1 + +# +# NV_CTRL_FRAMELOCK_HOUSE_STATUS - returns whether or not the house +# sync input signal was detected on the BNC connector of the frame lock +# board. +# +# This attribute may be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_FRAMELOCK or NV_CTRL_TARGET_TYPE_X_SCREEN +# target. +# + +NV_CTRL_FRAMELOCK_HOUSE_STATUS = 28 # R--F +NV_CTRL_FRAMELOCK_HOUSE_STATUS_NOT_DETECTED = 0 +NV_CTRL_FRAMELOCK_HOUSE_STATUS_DETECTED = 1 + +# +# NV_CTRL_FRAMELOCK_SYNC - enable/disable the syncing of display +# devices to the frame lock pulse as specified by previous calls to +# NV_CTRL_FRAMELOCK_DISPLAY_CONFIG. +# +# This attribute can only be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_GPU target. This attribute cannot be +# queried using a NV_CTRL_TARGET_TYPE_X_SCREEN. +# + +NV_CTRL_FRAMELOCK_SYNC = 29 # RW-G +NV_CTRL_FRAMELOCK_SYNC_DISABLE = 0 +NV_CTRL_FRAMELOCK_SYNC_ENABLE = 1 + +# +# NV_CTRL_FRAMELOCK_SYNC_READY - reports whether a frame lock +# board is receiving sync (regardless of whether or not any display +# devices are using the sync). +# +# This attribute may be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_FRAMELOCK or NV_CTRL_TARGET_TYPE_X_SCREEN +# target. +# + +NV_CTRL_FRAMELOCK_SYNC_READY = 30 # R--F +NV_CTRL_FRAMELOCK_SYNC_READY_FALSE = 0 +NV_CTRL_FRAMELOCK_SYNC_READY_TRUE = 1 + +# +# NV_CTRL_FRAMELOCK_STEREO_SYNC - this indicates that the GPU stereo +# signal is in sync with the frame lock stereo signal. +# +# This attribute may be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_GPU or NV_CTRL_TARGET_TYPE_X_SCREEN +# target. +# + +NV_CTRL_FRAMELOCK_STEREO_SYNC = 31 # R--G +NV_CTRL_FRAMELOCK_STEREO_SYNC_FALSE = 0 +NV_CTRL_FRAMELOCK_STEREO_SYNC_TRUE = 1 + +# +# NV_CTRL_FRAMELOCK_TEST_SIGNAL - to test the connections in the sync +# group, tell the master to enable a test signal, then query port[01] +# status and sync_ready on all slaves. When done, tell the master to +# disable the test signal. Test signal should only be manipulated +# while NV_CTRL_FRAMELOCK_SYNC is enabled. +# +# The TEST_SIGNAL is also used to reset the Universal Frame Count (as +# returned by the glXQueryFrameCountNV() function in the +# GLX_NV_swap_group extension). Note: for best accuracy of the +# Universal Frame Count, it is recommended to toggle the TEST_SIGNAL +# on and off after enabling frame lock. +# +# This attribute may be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_GPU or NV_CTRL_TARGET_TYPE_X_SCREEN target. +# + +NV_CTRL_FRAMELOCK_TEST_SIGNAL = 32 # RW-G +NV_CTRL_FRAMELOCK_TEST_SIGNAL_DISABLE = 0 +NV_CTRL_FRAMELOCK_TEST_SIGNAL_ENABLE = 1 + +# +# NV_CTRL_FRAMELOCK_ETHERNET_DETECTED - The frame lock boards are +# cabled together using regular cat5 cable, connecting to rj45 ports +# on the backplane of the card. There is some concern that users may +# think these are ethernet ports and connect them to a +# router/hub/etc. The hardware can detect this and will shut off to +# prevent damage (either to itself or to the router). +# NV_CTRL_FRAMELOCK_ETHERNET_DETECTED may be called to find out if +# ethernet is connected to one of the rj45 ports. An appropriate +# error message should then be displayed. The _PORT0 and _PORT1 +# values may be or'ed together. +# +# This attribute may be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_FRAMELOCK or NV_CTRL_TARGET_TYPE_X_SCREEN +# target. +# + +NV_CTRL_FRAMELOCK_ETHERNET_DETECTED = 33 # R--F +NV_CTRL_FRAMELOCK_ETHERNET_DETECTED_NONE = 0 +NV_CTRL_FRAMELOCK_ETHERNET_DETECTED_PORT0 = 0x1 +NV_CTRL_FRAMELOCK_ETHERNET_DETECTED_PORT1 = 0x2 + +# +# NV_CTRL_FRAMELOCK_VIDEO_MODE - get/set what video mode is used +# to interperate the house sync signal. This should only be set +# on the master. +# +# This attribute may be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_FRAMELOCK or NV_CTRL_TARGET_TYPE_X_SCREEN +# target. +# + +NV_CTRL_FRAMELOCK_VIDEO_MODE = 34 # RW-F +NV_CTRL_FRAMELOCK_VIDEO_MODE_NONE = 0 +NV_CTRL_FRAMELOCK_VIDEO_MODE_TTL = 1 +NV_CTRL_FRAMELOCK_VIDEO_MODE_NTSCPALSECAM = 2 +NV_CTRL_FRAMELOCK_VIDEO_MODE_HDTV = 3 + +# +# During FRAMELOCK bring-up, the above values were redefined to +# these: +# + +NV_CTRL_FRAMELOCK_VIDEO_MODE_COMPOSITE_AUTO = 0 +NV_CTRL_FRAMELOCK_VIDEO_MODE_COMPOSITE_BI_LEVEL = 2 +NV_CTRL_FRAMELOCK_VIDEO_MODE_COMPOSITE_TRI_LEVEL = 3 + +# +# NV_CTRL_FRAMELOCK_SYNC_RATE - this is the refresh rate that the +# frame lock board is sending to the GPU, in milliHz. +# +# This attribute may be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_FRAMELOCK or NV_CTRL_TARGET_TYPE_X_SCREEN +# target. +# + +NV_CTRL_FRAMELOCK_SYNC_RATE = 35 # R--F + +############################################################################ + +# +# NV_CTRL_FORCE_GENERIC_CPU - not supported +# + +NV_CTRL_FORCE_GENERIC_CPU = 37 # not supported +NV_CTRL_FORCE_GENERIC_CPU_DISABLE = 0 # not supported +NV_CTRL_FORCE_GENERIC_CPU_ENABLE = 1 # not supported + +# +# NV_CTRL_OPENGL_AA_LINE_GAMMA - for OpenGL clients, allow +# Gamma-corrected antialiased lines to consider variances in the +# color display capabilities of output devices when rendering smooth +# lines. Only available on recent Quadro GPUs. This setting is only +# applied to OpenGL clients that are started after this setting is +# applied. +# + +NV_CTRL_OPENGL_AA_LINE_GAMMA = 38 # RW-X +NV_CTRL_OPENGL_AA_LINE_GAMMA_DISABLE = 0 +NV_CTRL_OPENGL_AA_LINE_GAMMA_ENABLE = 1 + +# +# NV_CTRL_FRAMELOCK_TIMING - this is TRUE when the gpu is both receiving +# and locked to an input timing signal. Timing information may come from +# the following places: Another frame lock device that is set to master, +# the house sync signal, or the GPU's internal timing from a display +# device. +# +# This attribute may be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_GPU or NV_CTRL_TARGET_TYPE_X_SCREEN target. +# + +NV_CTRL_FRAMELOCK_TIMING = 39 # R--G +NV_CTRL_FRAMELOCK_TIMING_FALSE = 0 +NV_CTRL_FRAMELOCK_TIMING_TRUE = 1 + +# +# NV_CTRL_FLIPPING_ALLOWED - when TRUE, OpenGL will swap by flipping +# when possible; when FALSE, OpenGL will always swap by blitting. +# + +NV_CTRL_FLIPPING_ALLOWED = 40 # RW-X +NV_CTRL_FLIPPING_ALLOWED_FALSE = 0 +NV_CTRL_FLIPPING_ALLOWED_TRUE = 1 + +# +# NV_CTRL_ARCHITECTURE - returns the architecture on which the X server is +# running. +# + +NV_CTRL_ARCHITECTURE = 41 # R-- +NV_CTRL_ARCHITECTURE_X86 = 0 +NV_CTRL_ARCHITECTURE_X86_64 = 1 +NV_CTRL_ARCHITECTURE_IA64 = 2 +NV_CTRL_ARCHITECTURE_ARM = 3 +NV_CTRL_ARCHITECTURE_AARCH64 = 4 +NV_CTRL_ARCHITECTURE_PPC64LE = 5 + +# +# NV_CTRL_TEXTURE_CLAMPING - texture clamping mode in OpenGL. By +# default, _SPEC is used, which forces OpenGL texture clamping to +# conform with the OpenGL specification. _EDGE forces NVIDIA's +# OpenGL implementation to remap GL_CLAMP to GL_CLAMP_TO_EDGE, +# which is not strictly conformant, but some applications rely on +# the non-conformant behavior. +# + +NV_CTRL_TEXTURE_CLAMPING = 42 # RW-X +NV_CTRL_TEXTURE_CLAMPING_EDGE = 0 +NV_CTRL_TEXTURE_CLAMPING_SPEC = 1 + +# +# The NV_CTRL_CURSOR_SHADOW - not supported +# +# use an ARGB cursor instead. +# + +NV_CTRL_CURSOR_SHADOW = 43 # not supported +NV_CTRL_CURSOR_SHADOW_DISABLE = 0 # not supported +NV_CTRL_CURSOR_SHADOW_ENABLE = 1 # not supported + +NV_CTRL_CURSOR_SHADOW_ALPHA = 44 # not supported +NV_CTRL_CURSOR_SHADOW_RED = 45 # not supported +NV_CTRL_CURSOR_SHADOW_GREEN = 46 # not supported +NV_CTRL_CURSOR_SHADOW_BLUE = 47 # not supported + +NV_CTRL_CURSOR_SHADOW_X_OFFSET = 48 # not supported +NV_CTRL_CURSOR_SHADOW_Y_OFFSET = 49 # not supported + +# +# When Application Control for FSAA is enabled, then what the +# application requests is used, and NV_CTRL_FSAA_MODE is ignored. If +# this is disabled, then any application setting is overridden with +# NV_CTRL_FSAA_MODE +# + +NV_CTRL_FSAA_APPLICATION_CONTROLLED = 50 # RW-X +NV_CTRL_FSAA_APPLICATION_CONTROLLED_ENABLED = 1 +NV_CTRL_FSAA_APPLICATION_CONTROLLED_DISABLED = 0 + +# +# When Application Control for LogAniso is enabled, then what the +# application requests is used, and NV_CTRL_LOG_ANISO is ignored. If +# this is disabled, then any application setting is overridden with +# NV_CTRL_LOG_ANISO +# + +NV_CTRL_LOG_ANISO_APPLICATION_CONTROLLED = 51 # RW-X +NV_CTRL_LOG_ANISO_APPLICATION_CONTROLLED_ENABLED = 1 +NV_CTRL_LOG_ANISO_APPLICATION_CONTROLLED_DISABLED = 0 + +# +# IMAGE_SHARPENING adjusts the sharpness of the display's image +# quality by amplifying high frequency content. Valid values will +# normally be in the range [0,32). Only available on GeForceFX or +# newer. +# + +NV_CTRL_IMAGE_SHARPENING = 52 # RWDG + +# +# NV_CTRL_TV_OVERSCAN - not supported +# + +NV_CTRL_TV_OVERSCAN = 53 # not supported + +# +# NV_CTRL_TV_FLICKER_FILTER - not supported +# + +NV_CTRL_TV_FLICKER_FILTER = 54 # not supported + +# +# NV_CTRL_TV_BRIGHTNESS - not supported +# + +NV_CTRL_TV_BRIGHTNESS = 55 # not supported + +# +# NV_CTRL_TV_HUE - not supported +# + +NV_CTRL_TV_HUE = 56 # not supported + +# +# NV_CTRL_TV_CONTRAST - not suppoerted +# + +NV_CTRL_TV_CONTRAST = 57 # not supported + +# +# NV_CTRL_TV_SATURATION - not supported +# + +NV_CTRL_TV_SATURATION = 58 # not supported + +# +# NV_CTRL_TV_RESET_SETTINGS - not supported +# + +NV_CTRL_TV_RESET_SETTINGS = 59 # not supported + +# +# NV_CTRL_GPU_CORE_TEMPERATURE reports the current core temperature +# of the GPU driving the X screen. +# + +NV_CTRL_GPU_CORE_TEMPERATURE = 60 # R--G + +# +# NV_CTRL_GPU_CORE_THRESHOLD reports the current GPU core slowdown +# threshold temperature, NV_CTRL_GPU_DEFAULT_CORE_THRESHOLD and +# NV_CTRL_GPU_MAX_CORE_THRESHOLD report the default and MAX core +# slowdown threshold temperatures. +# +# NV_CTRL_GPU_CORE_THRESHOLD reflects the temperature at which the +# GPU is throttled to prevent overheating. +# + +NV_CTRL_GPU_CORE_THRESHOLD = 61 # R--G +NV_CTRL_GPU_DEFAULT_CORE_THRESHOLD = 62 # R--G +NV_CTRL_GPU_MAX_CORE_THRESHOLD = 63 # R--G + +# +# NV_CTRL_AMBIENT_TEMPERATURE reports the current temperature in the +# immediate neighbourhood of the GPU driving the X screen. +# + +NV_CTRL_AMBIENT_TEMPERATURE = 64 # R--G + +# +# NV_CTRL_PBUFFER_SCANOUT_SUPPORTED - returns whether this X screen +# supports scanout of FP pbuffers; +# +# if this screen does not support PBUFFER_SCANOUT, then all other +# PBUFFER_SCANOUT attributes are unavailable. +# +# PBUFFER_SCANOUT is supported if and only if: +# - Twinview is configured with clone mode. The secondary screen is used to +# scanout the pbuffer. +# - The desktop is running in with 16 bits per pixel. +# +NV_CTRL_PBUFFER_SCANOUT_SUPPORTED = 65 # not supported +NV_CTRL_PBUFFER_SCANOUT_FALSE = 0 +NV_CTRL_PBUFFER_SCANOUT_TRUE = 1 + +# +# NV_CTRL_PBUFFER_SCANOUT_XID indicates the XID of the pbuffer used for +# scanout. +# +NV_CTRL_PBUFFER_SCANOUT_XID = 66 # not supported + +############################################################################ +# +# The NV_CTRL_GVO_* integer attributes are used to configure GVO +# (Graphics to Video Out). This functionality is available, for +# example, on the Quadro SDI Output card. +# +# The following is a typical usage pattern for the GVO attributes: +# +# - query NV_CTRL_GVO_SUPPORTED to determine if the X screen supports GV0. +# +# - specify NV_CTRL_GVO_SYNC_MODE (one of FREE_RUNNING, GENLOCK, or +# FRAMELOCK); if you specify GENLOCK or FRAMELOCK, you should also +# specify NV_CTRL_GVO_SYNC_SOURCE. +# +# - Use NV_CTRL_GVO_COMPOSITE_SYNC_INPUT_DETECTED and +# NV_CTRL_GVO_SDI_SYNC_INPUT_DETECTED to detect what input syncs are +# present. +# +# (If no analog sync is detected but it is known that a valid +# bi-level or tri-level sync is connected set +# NV_CTRL_GVO_COMPOSITE_SYNC_INPUT_DETECT_MODE appropriately and +# retest with NV_CTRL_GVO_COMPOSITE_SYNC_INPUT_DETECTED). +# +# - if syncing to input sync, query the +# NV_CTRL_GVIO_DETECTED_VIDEO_FORMAT attribute; note that Input video +# format can only be queried after SYNC_SOURCE is specified. +# +# - specify the NV_CTRL_GVIO_REQUESTED_VIDEO_FORMAT +# +# - specify the NV_CTRL_GVO_DATA_FORMAT +# +# - specify any custom Color Space Conversion (CSC) matrix, offset, +# and scale with XNVCTRLSetGvoColorConversion(). +# +# - if using the GLX_NV_video_out extension to display one or more +# pbuffers, call glXGetVideoDeviceNV() to lock the GVO output for use +# by the GLX client; then bind the pbuffer(s) to the GVO output with +# glXBindVideoImageNV() and send pbuffers to the GVO output with +# glXSendPbufferToVideoNV(); see the GLX_NV_video_out spec for more +# details. +# +# - if using the GLX_NV_present_video extension, call +# glXBindVideoDeviceNV() to bind the GVO video device to current +# OpenGL context. +# +# Note that setting most GVO attributes only causes the value to be +# cached in the X server. The values will be flushed to the hardware +# either when the next MetaMode is set that uses the GVO display +# device, or when a GLX pbuffer is bound to the GVO output (with +# glXBindVideoImageNV()). +# +# Note that GLX_NV_video_out/GLX_NV_present_video and X screen use +# are mutually exclusive. If a MetaMode is currently using the GVO +# device, then glXGetVideoDeviceNV and glXBindVideoImageNV() will +# fail. Similarly, if a GLX client has locked the GVO output (via +# glXGetVideoDeviceNV or glXBindVideoImageNV), then setting a +# MetaMode that uses the GVO device will fail. The +# NV_CTRL_GVO_GLX_LOCKED event will be sent when a GLX client locks +# the GVO output. +# +# + + +# +# NV_CTRL_GVO_SUPPORTED - returns whether this X screen supports GVO; +# if this screen does not support GVO output, then all other GVO +# attributes are unavailable. +# + +NV_CTRL_GVO_SUPPORTED = 67 # R-- +NV_CTRL_GVO_SUPPORTED_FALSE = 0 +NV_CTRL_GVO_SUPPORTED_TRUE = 1 + +# +# NV_CTRL_GVO_SYNC_MODE - selects the GVO sync mode; possible values +# are: +# +# FREE_RUNNING - GVO does not sync to any external signal +# +# GENLOCK - the GVO output is genlocked to an incoming sync signal; +# genlocking locks at hsync. This requires that the output video +# format exactly match the incoming sync video format. +# +# FRAMELOCK - the GVO output is frame locked to an incoming sync +# signal; frame locking locks at vsync. This requires that the output +# video format have the same refresh rate as the incoming sync video +# format. +# + +NV_CTRL_GVO_SYNC_MODE = 68 # RW- +NV_CTRL_GVO_SYNC_MODE_FREE_RUNNING = 0 +NV_CTRL_GVO_SYNC_MODE_GENLOCK = 1 +NV_CTRL_GVO_SYNC_MODE_FRAMELOCK = 2 + +# +# NV_CTRL_GVO_SYNC_SOURCE - if NV_CTRL_GVO_SYNC_MODE is set to either +# GENLOCK or FRAMELOCK, this controls which sync source is used as +# the incoming sync signal (either Composite or SDI). If +# NV_CTRL_GVO_SYNC_MODE is FREE_RUNNING, this attribute has no +# effect. +# + +NV_CTRL_GVO_SYNC_SOURCE = 69 # RW- +NV_CTRL_GVO_SYNC_SOURCE_COMPOSITE = 0 +NV_CTRL_GVO_SYNC_SOURCE_SDI = 1 + +# +# NV_CTRL_GVIO_REQUESTED_VIDEO_FORMAT - specifies the desired output video +# format for GVO devices or the desired input video format for GVI devices. +# +# Note that for GVO, the valid video formats may vary depending on +# the NV_CTRL_GVO_SYNC_MODE and the incoming sync video format. See +# the definition of NV_CTRL_GVO_SYNC_MODE. +# +# Note that when querying the ValidValues for this data type, the +# values are reported as bits within a bitmask +# (ATTRIBUTE_TYPE_INT_BITS); unfortunately, there are more valid +# value bits than will fit in a single 32-bit value. To solve this, +# query the ValidValues for NV_CTRL_GVIO_REQUESTED_VIDEO_FORMAT to +# check which of the first 31 VIDEO_FORMATS are valid, query the +# ValidValues for NV_CTRL_GVIO_REQUESTED_VIDEO_FORMAT2 to check which +# of the 32-63 VIDEO_FORMATS are valid, and query the ValidValues of +# NV_CTRL_GVIO_REQUESTED_VIDEO_FORMAT3 to check which of the 64-95 +# VIDEO_FORMATS are valid. +# +# Note: Setting this attribute on a GVI device may also result in the +# following NV-CONTROL attributes being reset on that device (to +# ensure the configuration remains valid): +# NV_CTRL_GVI_REQUESTED_STREAM_BITS_PER_COMPONENT +# NV_CTRL_GVI_REQUESTED_STREAM_COMPONENT_SAMPLING +# + +NV_CTRL_GVIO_REQUESTED_VIDEO_FORMAT = 70 # RW--I + +NV_CTRL_GVIO_VIDEO_FORMAT_NONE = 0 +NV_CTRL_GVIO_VIDEO_FORMAT_487I_59_94_SMPTE259_NTSC = 1 +NV_CTRL_GVIO_VIDEO_FORMAT_576I_50_00_SMPTE259_PAL = 2 +NV_CTRL_GVIO_VIDEO_FORMAT_720P_59_94_SMPTE296 = 3 +NV_CTRL_GVIO_VIDEO_FORMAT_720P_60_00_SMPTE296 = 4 +NV_CTRL_GVIO_VIDEO_FORMAT_1035I_59_94_SMPTE260 = 5 +NV_CTRL_GVIO_VIDEO_FORMAT_1035I_60_00_SMPTE260 = 6 +NV_CTRL_GVIO_VIDEO_FORMAT_1080I_50_00_SMPTE295 = 7 +NV_CTRL_GVIO_VIDEO_FORMAT_1080I_50_00_SMPTE274 = 8 +NV_CTRL_GVIO_VIDEO_FORMAT_1080I_59_94_SMPTE274 = 9 +NV_CTRL_GVIO_VIDEO_FORMAT_1080I_60_00_SMPTE274 = 10 +NV_CTRL_GVIO_VIDEO_FORMAT_1080P_23_976_SMPTE274 = 11 +NV_CTRL_GVIO_VIDEO_FORMAT_1080P_24_00_SMPTE274 = 12 +NV_CTRL_GVIO_VIDEO_FORMAT_1080P_25_00_SMPTE274 = 13 +NV_CTRL_GVIO_VIDEO_FORMAT_1080P_29_97_SMPTE274 = 14 +NV_CTRL_GVIO_VIDEO_FORMAT_1080P_30_00_SMPTE274 = 15 +NV_CTRL_GVIO_VIDEO_FORMAT_720P_50_00_SMPTE296 = 16 +NV_CTRL_GVIO_VIDEO_FORMAT_1080I_48_00_SMPTE274 = 17 +NV_CTRL_GVIO_VIDEO_FORMAT_1080I_47_96_SMPTE274 = 18 +NV_CTRL_GVIO_VIDEO_FORMAT_720P_30_00_SMPTE296 = 19 +NV_CTRL_GVIO_VIDEO_FORMAT_720P_29_97_SMPTE296 = 20 +NV_CTRL_GVIO_VIDEO_FORMAT_720P_25_00_SMPTE296 = 21 +NV_CTRL_GVIO_VIDEO_FORMAT_720P_24_00_SMPTE296 = 22 +NV_CTRL_GVIO_VIDEO_FORMAT_720P_23_98_SMPTE296 = 23 +NV_CTRL_GVIO_VIDEO_FORMAT_1080PSF_25_00_SMPTE274 = 24 +NV_CTRL_GVIO_VIDEO_FORMAT_1080PSF_29_97_SMPTE274 = 25 +NV_CTRL_GVIO_VIDEO_FORMAT_1080PSF_30_00_SMPTE274 = 26 +NV_CTRL_GVIO_VIDEO_FORMAT_1080PSF_24_00_SMPTE274 = 27 +NV_CTRL_GVIO_VIDEO_FORMAT_1080PSF_23_98_SMPTE274 = 28 +NV_CTRL_GVIO_VIDEO_FORMAT_2048P_30_00_SMPTE372 = 29 +NV_CTRL_GVIO_VIDEO_FORMAT_2048P_29_97_SMPTE372 = 30 +NV_CTRL_GVIO_VIDEO_FORMAT_2048I_60_00_SMPTE372 = 31 +NV_CTRL_GVIO_VIDEO_FORMAT_2048I_59_94_SMPTE372 = 32 +NV_CTRL_GVIO_VIDEO_FORMAT_2048P_25_00_SMPTE372 = 33 +NV_CTRL_GVIO_VIDEO_FORMAT_2048I_50_00_SMPTE372 = 34 +NV_CTRL_GVIO_VIDEO_FORMAT_2048P_24_00_SMPTE372 = 35 +NV_CTRL_GVIO_VIDEO_FORMAT_2048P_23_98_SMPTE372 = 36 +NV_CTRL_GVIO_VIDEO_FORMAT_2048I_48_00_SMPTE372 = 37 +NV_CTRL_GVIO_VIDEO_FORMAT_2048I_47_96_SMPTE372 = 38 +NV_CTRL_GVIO_VIDEO_FORMAT_1080P_50_00_3G_LEVEL_A_SMPTE274 = 39 +NV_CTRL_GVIO_VIDEO_FORMAT_1080P_59_94_3G_LEVEL_A_SMPTE274 = 40 +NV_CTRL_GVIO_VIDEO_FORMAT_1080P_60_00_3G_LEVEL_A_SMPTE274 = 41 +NV_CTRL_GVIO_VIDEO_FORMAT_1080P_60_00_3G_LEVEL_B_SMPTE274 = 42 +NV_CTRL_GVIO_VIDEO_FORMAT_1080I_60_00_3G_LEVEL_B_SMPTE274 = 43 +NV_CTRL_GVIO_VIDEO_FORMAT_2048I_60_00_3G_LEVEL_B_SMPTE372 = 44 +NV_CTRL_GVIO_VIDEO_FORMAT_1080P_50_00_3G_LEVEL_B_SMPTE274 = 45 +NV_CTRL_GVIO_VIDEO_FORMAT_1080I_50_00_3G_LEVEL_B_SMPTE274 = 46 +NV_CTRL_GVIO_VIDEO_FORMAT_2048I_50_00_3G_LEVEL_B_SMPTE372 = 47 +NV_CTRL_GVIO_VIDEO_FORMAT_1080P_30_00_3G_LEVEL_B_SMPTE274 = 48 +NV_CTRL_GVIO_VIDEO_FORMAT_2048P_30_00_3G_LEVEL_B_SMPTE372 = 49 +NV_CTRL_GVIO_VIDEO_FORMAT_1080P_25_00_3G_LEVEL_B_SMPTE274 = 50 +NV_CTRL_GVIO_VIDEO_FORMAT_2048P_25_00_3G_LEVEL_B_SMPTE372 = 51 +NV_CTRL_GVIO_VIDEO_FORMAT_1080P_24_00_3G_LEVEL_B_SMPTE274 = 52 +NV_CTRL_GVIO_VIDEO_FORMAT_2048P_24_00_3G_LEVEL_B_SMPTE372 = 53 +NV_CTRL_GVIO_VIDEO_FORMAT_1080I_48_00_3G_LEVEL_B_SMPTE274 = 54 +NV_CTRL_GVIO_VIDEO_FORMAT_2048I_48_00_3G_LEVEL_B_SMPTE372 = 55 +NV_CTRL_GVIO_VIDEO_FORMAT_1080P_59_94_3G_LEVEL_B_SMPTE274 = 56 +NV_CTRL_GVIO_VIDEO_FORMAT_1080I_59_94_3G_LEVEL_B_SMPTE274 = 57 +NV_CTRL_GVIO_VIDEO_FORMAT_2048I_59_94_3G_LEVEL_B_SMPTE372 = 58 +NV_CTRL_GVIO_VIDEO_FORMAT_1080P_29_97_3G_LEVEL_B_SMPTE274 = 59 +NV_CTRL_GVIO_VIDEO_FORMAT_2048P_29_97_3G_LEVEL_B_SMPTE372 = 60 +NV_CTRL_GVIO_VIDEO_FORMAT_1080P_23_98_3G_LEVEL_B_SMPTE274 = 61 +NV_CTRL_GVIO_VIDEO_FORMAT_2048P_23_98_3G_LEVEL_B_SMPTE372 = 62 +NV_CTRL_GVIO_VIDEO_FORMAT_1080I_47_96_3G_LEVEL_B_SMPTE274 = 63 +NV_CTRL_GVIO_VIDEO_FORMAT_2048I_47_96_3G_LEVEL_B_SMPTE372 = 64 + +# +# The following have been renamed; NV_CTRL_GVIO_REQUESTED_VIDEO_FORMAT and the +# corresponding NV_CTRL_GVIO_* formats should be used instead. +# +NV_CTRL_GVO_OUTPUT_VIDEO_FORMAT = 70 # renamed + +NV_CTRL_GVO_VIDEO_FORMAT_NONE = 0 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_487I_59_94_SMPTE259_NTSC = 1 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_576I_50_00_SMPTE259_PAL = 2 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_720P_59_94_SMPTE296 = 3 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_720P_60_00_SMPTE296 = 4 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_1035I_59_94_SMPTE260 = 5 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_1035I_60_00_SMPTE260 = 6 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_1080I_50_00_SMPTE295 = 7 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_1080I_50_00_SMPTE274 = 8 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_1080I_59_94_SMPTE274 = 9 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_1080I_60_00_SMPTE274 = 10 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_1080P_23_976_SMPTE274 = 11 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_1080P_24_00_SMPTE274 = 12 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_1080P_25_00_SMPTE274 = 13 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_1080P_29_97_SMPTE274 = 14 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_1080P_30_00_SMPTE274 = 15 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_720P_50_00_SMPTE296 = 16 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_1080I_48_00_SMPTE274 = 17 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_1080I_47_96_SMPTE274 = 18 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_720P_30_00_SMPTE296 = 19 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_720P_29_97_SMPTE296 = 20 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_720P_25_00_SMPTE296 = 21 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_720P_24_00_SMPTE296 = 22 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_720P_23_98_SMPTE296 = 23 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_1080PSF_25_00_SMPTE274 = 24 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_1080PSF_29_97_SMPTE274 = 25 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_1080PSF_30_00_SMPTE274 = 26 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_1080PSF_24_00_SMPTE274 = 27 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_1080PSF_23_98_SMPTE274 = 28 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_2048P_30_00_SMPTE372 = 29 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_2048P_29_97_SMPTE372 = 30 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_2048I_60_00_SMPTE372 = 31 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_2048I_59_94_SMPTE372 = 32 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_2048P_25_00_SMPTE372 = 33 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_2048I_50_00_SMPTE372 = 34 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_2048P_24_00_SMPTE372 = 35 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_2048P_23_98_SMPTE372 = 36 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_2048I_48_00_SMPTE372 = 37 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_2048I_47_96_SMPTE372 = 38 # renamed + +# +# NV_CTRL_GVIO_DETECTED_VIDEO_FORMAT - indicates the input video format +# detected for GVO or GVI devices; the possible values are the +# NV_CTRL_GVIO_VIDEO_FORMAT constants. +# +# For GVI devices, the jack number should be specified in the lower +# 16 bits of the "display_mask" parameter, while the channel number should be +# specified in the upper 16 bits. +# + +NV_CTRL_GVIO_DETECTED_VIDEO_FORMAT = 71 # R--I + +# +# NV_CTRL_GVO_INPUT_VIDEO_FORMAT - renamed +# +# NV_CTRL_GVIO_DETECTED_VIDEO_FORMAT should be used instead. +# + +NV_CTRL_GVO_INPUT_VIDEO_FORMAT = 71 # renamed + +# +# NV_CTRL_GVO_DATA_FORMAT - This controls how the data in the source +# (either the X screen or the GLX pbuffer) is interpretted and +# displayed. +# +# Note: some of the below DATA_FORMATS have been renamed. For +# example, R8G8B8_TO_RGB444 has been renamed to X8X8X8_444_PASSTHRU. +# This is to more accurately reflect DATA_FORMATS where the +# per-channel data could be either RGB or YCrCb -- the point is that +# the driver and GVO hardware do not perform any implicit color space +# conversion on the data; it is passed through to the SDI out. +# + +NV_CTRL_GVO_DATA_FORMAT = 72 # RW- +NV_CTRL_GVO_DATA_FORMAT_R8G8B8_TO_YCRCB444 = 0 +NV_CTRL_GVO_DATA_FORMAT_R8G8B8A8_TO_YCRCBA4444 = 1 +NV_CTRL_GVO_DATA_FORMAT_R8G8B8Z10_TO_YCRCBZ4444 = 2 +NV_CTRL_GVO_DATA_FORMAT_R8G8B8_TO_YCRCB422 = 3 +NV_CTRL_GVO_DATA_FORMAT_R8G8B8A8_TO_YCRCBA4224 = 4 +NV_CTRL_GVO_DATA_FORMAT_R8G8B8Z10_TO_YCRCBZ4224 = 5 +NV_CTRL_GVO_DATA_FORMAT_R8G8B8_TO_RGB444 = 6 # renamed +NV_CTRL_GVO_DATA_FORMAT_X8X8X8_444_PASSTHRU = 6 +NV_CTRL_GVO_DATA_FORMAT_R8G8B8A8_TO_RGBA4444 = 7 # renamed +NV_CTRL_GVO_DATA_FORMAT_X8X8X8A8_4444_PASSTHRU = 7 +NV_CTRL_GVO_DATA_FORMAT_R8G8B8Z10_TO_RGBZ4444 = 8 # renamed +NV_CTRL_GVO_DATA_FORMAT_X8X8X8Z8_4444_PASSTHRU = 8 +NV_CTRL_GVO_DATA_FORMAT_Y10CR10CB10_TO_YCRCB444 = 9 # renamed +NV_CTRL_GVO_DATA_FORMAT_X10X10X10_444_PASSTHRU = 9 +NV_CTRL_GVO_DATA_FORMAT_Y10CR8CB8_TO_YCRCB444 = 10 # renamed +NV_CTRL_GVO_DATA_FORMAT_X10X8X8_444_PASSTHRU = 10 +NV_CTRL_GVO_DATA_FORMAT_Y10CR8CB8A10_TO_YCRCBA4444 = 11 # renamed +NV_CTRL_GVO_DATA_FORMAT_X10X8X8A10_4444_PASSTHRU = 11 +NV_CTRL_GVO_DATA_FORMAT_Y10CR8CB8Z10_TO_YCRCBZ4444 = 12 # renamed +NV_CTRL_GVO_DATA_FORMAT_X10X8X8Z10_4444_PASSTHRU = 12 +NV_CTRL_GVO_DATA_FORMAT_DUAL_R8G8B8_TO_DUAL_YCRCB422 = 13 +NV_CTRL_GVO_DATA_FORMAT_DUAL_Y8CR8CB8_TO_DUAL_YCRCB422 = 14 # renamed +NV_CTRL_GVO_DATA_FORMAT_DUAL_X8X8X8_TO_DUAL_422_PASSTHRU = 14 +NV_CTRL_GVO_DATA_FORMAT_R10G10B10_TO_YCRCB422 = 15 +NV_CTRL_GVO_DATA_FORMAT_R10G10B10_TO_YCRCB444 = 16 +NV_CTRL_GVO_DATA_FORMAT_Y12CR12CB12_TO_YCRCB444 = 17 # renamed +NV_CTRL_GVO_DATA_FORMAT_X12X12X12_444_PASSTHRU = 17 +NV_CTRL_GVO_DATA_FORMAT_R12G12B12_TO_YCRCB444 = 18 +NV_CTRL_GVO_DATA_FORMAT_X8X8X8_422_PASSTHRU = 19 +NV_CTRL_GVO_DATA_FORMAT_X8X8X8A8_4224_PASSTHRU = 20 +NV_CTRL_GVO_DATA_FORMAT_X8X8X8Z8_4224_PASSTHRU = 21 +NV_CTRL_GVO_DATA_FORMAT_X10X10X10_422_PASSTHRU = 22 +NV_CTRL_GVO_DATA_FORMAT_X10X8X8_422_PASSTHRU = 23 +NV_CTRL_GVO_DATA_FORMAT_X10X8X8A10_4224_PASSTHRU = 24 +NV_CTRL_GVO_DATA_FORMAT_X10X8X8Z10_4224_PASSTHRU = 25 +NV_CTRL_GVO_DATA_FORMAT_X12X12X12_422_PASSTHRU = 26 +NV_CTRL_GVO_DATA_FORMAT_R12G12B12_TO_YCRCB422 = 27 + +# +# NV_CTRL_GVO_DISPLAY_X_SCREEN - not supported +# + +NV_CTRL_GVO_DISPLAY_X_SCREEN = 73 # not supported +NV_CTRL_GVO_DISPLAY_X_SCREEN_ENABLE = 1 # not supported +NV_CTRL_GVO_DISPLAY_X_SCREEN_DISABLE = 0 # not supported + +# +# NV_CTRL_GVO_COMPOSITE_SYNC_INPUT_DETECTED - indicates whether +# Composite Sync input is detected. +# + +NV_CTRL_GVO_COMPOSITE_SYNC_INPUT_DETECTED = 74 # R-- +NV_CTRL_GVO_COMPOSITE_SYNC_INPUT_DETECTED_FALSE = 0 +NV_CTRL_GVO_COMPOSITE_SYNC_INPUT_DETECTED_TRUE = 1 + +# +# NV_CTRL_GVO_COMPOSITE_SYNC_INPUT_DETECT_MODE - get/set the +# Composite Sync input detect mode. +# + +NV_CTRL_GVO_COMPOSITE_SYNC_INPUT_DETECT_MODE = 75 # RW- +NV_CTRL_GVO_COMPOSITE_SYNC_INPUT_DETECT_MODE_AUTO = 0 +NV_CTRL_GVO_COMPOSITE_SYNC_INPUT_DETECT_MODE_BI_LEVEL = 1 +NV_CTRL_GVO_COMPOSITE_SYNC_INPUT_DETECT_MODE_TRI_LEVEL = 2 + +# +# NV_CTRL_GVO_SYNC_INPUT_DETECTED - indicates whether SDI Sync input +# is detected, and what type. +# + +NV_CTRL_GVO_SDI_SYNC_INPUT_DETECTED = 76 # R-- +NV_CTRL_GVO_SDI_SYNC_INPUT_DETECTED_NONE = 0 +NV_CTRL_GVO_SDI_SYNC_INPUT_DETECTED_HD = 1 +NV_CTRL_GVO_SDI_SYNC_INPUT_DETECTED_SD = 2 + +# +# NV_CTRL_GVO_VIDEO_OUTPUTS - indicates which GVO video output +# connectors are currently outputing data. +# + +NV_CTRL_GVO_VIDEO_OUTPUTS = 77 # R-- +NV_CTRL_GVO_VIDEO_OUTPUTS_NONE = 0 +NV_CTRL_GVO_VIDEO_OUTPUTS_VIDEO1 = 1 +NV_CTRL_GVO_VIDEO_OUTPUTS_VIDEO2 = 2 +NV_CTRL_GVO_VIDEO_OUTPUTS_VIDEO_BOTH = 3 + +# +# NV_CTRL_GVO_FIRMWARE_VERSION - deprecated +# +# NV_CTRL_STRING_GVIO_FIRMWARE_VERSION should be used instead. +# + +NV_CTRL_GVO_FIRMWARE_VERSION = 78 # deprecated + +# +# NV_CTRL_GVO_SYNC_DELAY_PIXELS - controls the delay between the +# input sync and the output sync in numbers of pixels from hsync; +# this is a 12 bit value. +# +# If the NV_CTRL_GVO_CAPABILITIES_ADVANCE_SYNC_SKEW bit is set, +# then setting this value will set an advance instead of a delay. +# + +NV_CTRL_GVO_SYNC_DELAY_PIXELS = 79 # RW- + +# +# NV_CTRL_GVO_SYNC_DELAY_LINES - controls the delay between the input +# sync and the output sync in numbers of lines from vsync; this is a +# 12 bit value. +# +# If the NV_CTRL_GVO_CAPABILITIES_ADVANCE_SYNC_SKEW bit is set, +# then setting this value will set an advance instead of a delay. +# + +NV_CTRL_GVO_SYNC_DELAY_LINES = 80 # RW- + +# +# NV_CTRL_GVO_INPUT_VIDEO_FORMAT_REACQUIRE - must be set for a period +# of about 2 seconds for the new InputVideoFormat to be properly +# locked to. In nvidia-settings, we do a reacquire whenever genlock +# or frame lock mode is entered into, when the user clicks the +# "detect" button. This value can be written, but always reads back +# _FALSE. +# + +NV_CTRL_GVO_INPUT_VIDEO_FORMAT_REACQUIRE = 81 # -W- +NV_CTRL_GVO_INPUT_VIDEO_FORMAT_REACQUIRE_FALSE = 0 +NV_CTRL_GVO_INPUT_VIDEO_FORMAT_REACQUIRE_TRUE = 1 + +# +# NV_CTRL_GVO_GLX_LOCKED - deprecated +# +# NV_CTRL_GVO_LOCK_OWNER should be used instead. +# + +NV_CTRL_GVO_GLX_LOCKED = 82 # deprecated +NV_CTRL_GVO_GLX_LOCKED_FALSE = 0 # deprecated +NV_CTRL_GVO_GLX_LOCKED_TRUE = 1 # deprecated + +# +# NV_CTRL_GVIO_VIDEO_FORMAT_{WIDTH,HEIGHT,REFRESH_RATE} - query the +# width, height, and refresh rate for the specified +# NV_CTRL_GVIO_VIDEO_FORMAT_*. So that this can be queried with +# existing interfaces, XNVCTRLQueryAttribute() should be used, and +# the video format specified in the display_mask field; eg: +# +# XNVCTRLQueryAttribute (dpy, +# screen, +# NV_CTRL_GVIO_VIDEO_FORMAT_487I_59_94_SMPTE259_NTSC, +# NV_CTRL_GVIO_VIDEO_FORMAT_WIDTH, +# &value); +# +# Note that Refresh Rate is in milliHertz values +# + +NV_CTRL_GVIO_VIDEO_FORMAT_WIDTH = 83 # R--I +NV_CTRL_GVIO_VIDEO_FORMAT_HEIGHT = 84 # R--I +NV_CTRL_GVIO_VIDEO_FORMAT_REFRESH_RATE = 85 # R--I + +# The following have been renamed; use the NV_CTRL_GVIO_* versions, instead +NV_CTRL_GVO_VIDEO_FORMAT_WIDTH = 83 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_HEIGHT = 84 # renamed +NV_CTRL_GVO_VIDEO_FORMAT_REFRESH_RATE = 85 # renamed + +# +# NV_CTRL_GVO_X_SCREEN_PAN_[XY] - not supported +# + +NV_CTRL_GVO_X_SCREEN_PAN_X = 86 # not supported +NV_CTRL_GVO_X_SCREEN_PAN_Y = 87 # not supported + +# +# NV_CTRL_GPU_OVERCLOCKING_STATE - not supported +# + +NV_CTRL_GPU_OVERCLOCKING_STATE = 88 # not supported +NV_CTRL_GPU_OVERCLOCKING_STATE_NONE = 0 # not supported +NV_CTRL_GPU_OVERCLOCKING_STATE_MANUAL = 1 # not supported + +# +# NV_CTRL_GPU_{2,3}D_CLOCK_FREQS - not supported +# + +NV_CTRL_GPU_2D_CLOCK_FREQS = 89 # not supported +NV_CTRL_GPU_3D_CLOCK_FREQS = 90 # not supported + +# +# NV_CTRL_GPU_DEFAULT_{2,3}D_CLOCK_FREQS - not supported +# + +NV_CTRL_GPU_DEFAULT_2D_CLOCK_FREQS = 91 # not supported +NV_CTRL_GPU_DEFAULT_3D_CLOCK_FREQS = 92 # not supported + +# +# NV_CTRL_GPU_CURRENT_CLOCK_FREQS - query the current GPU and memory +# clocks of the graphics device driving the X screen. +# +# NV_CTRL_GPU_CURRENT_CLOCK_FREQS is a "packed" integer attribute; +# the GPU clock is stored in the upper 16 bits of the integer, and +# the memory clock is stored in the lower 16 bits of the integer. +# All clock values are in MHz. All clock values are in MHz. +# + +NV_CTRL_GPU_CURRENT_CLOCK_FREQS = 93 # R--G + +# +# NV_CTRL_GPU_OPTIMAL_CLOCK_FREQS - not supported +# + +NV_CTRL_GPU_OPTIMAL_CLOCK_FREQS = 94 # not supported +NV_CTRL_GPU_OPTIMAL_CLOCK_FREQS_INVALID = 0 # not supported + +# +# NV_CTRL_GPU_OPTIMAL_CLOCK_FREQS_DETECTION - not supported +# + +NV_CTRL_GPU_OPTIMAL_CLOCK_FREQS_DETECTION = 95 # not supported +NV_CTRL_GPU_OPTIMAL_CLOCK_FREQS_DETECTION_START = 0 # not supported +NV_CTRL_GPU_OPTIMAL_CLOCK_FREQS_DETECTION_CANCEL = 1 # not supported + +# +# NV_CTRL_GPU_OPTIMAL_CLOCK_FREQS_DETECTION_STATE - not supported +# + +NV_CTRL_GPU_OPTIMAL_CLOCK_FREQS_DETECTION_STATE = 96 # not supported +NV_CTRL_GPU_OPTIMAL_CLOCK_FREQS_DETECTION_STATE_IDLE = 0 # not supported +NV_CTRL_GPU_OPTIMAL_CLOCK_FREQS_DETECTION_STATE_BUSY = 1 # not supported + +# +# NV_CTRL_FLATPANEL_CHIP_LOCATION - for the specified display device, +# report whether the flat panel is driven by the on-chip controller, +# or a separate controller chip elsewhere on the graphics board. +# This attribute is only available for flat panels. +# + +NV_CTRL_FLATPANEL_CHIP_LOCATION = 215 # R-DG +NV_CTRL_FLATPANEL_CHIP_LOCATION_INTERNAL = 0 +NV_CTRL_FLATPANEL_CHIP_LOCATION_EXTERNAL = 1 + +# +# NV_CTRL_FLATPANEL_LINK - report the number of links for a DVI connection, or +# the main link's active lane count for DisplayPort. +# This attribute is only available for flat panels. +# + +NV_CTRL_FLATPANEL_LINK = 216 # R-DG +NV_CTRL_FLATPANEL_LINK_SINGLE = 0 +NV_CTRL_FLATPANEL_LINK_DUAL = 1 +NV_CTRL_FLATPANEL_LINK_QUAD = 3 + +# +# NV_CTRL_FLATPANEL_SIGNAL - for the specified display device, report +# whether the flat panel is driven by an LVDS, TMDS, or DisplayPort signal. +# This attribute is only available for flat panels. +# + +NV_CTRL_FLATPANEL_SIGNAL = 217 # R-DG +NV_CTRL_FLATPANEL_SIGNAL_LVDS = 0 +NV_CTRL_FLATPANEL_SIGNAL_TMDS = 1 +NV_CTRL_FLATPANEL_SIGNAL_DISPLAYPORT = 2 + +# +# NV_CTRL_USE_HOUSE_SYNC - when INPUT, the server (master) frame lock +# device will propagate the incoming house sync signal as the outgoing +# frame lock sync signal. If the frame lock device cannot detect a +# frame lock sync signal, it will default to using the internal timings +# from the GPU connected to the primary connector. +# +# When set to OUTPUT, the server (master) frame lock device will +# generate a house sync signal from its internal timing and output +# this signal over the BNC connector on the frame lock device. This +# is only allowed on a Quadro Sync II device. If an incoming house +# sync signal is present on the BNC connector, this setting will +# have no effect. +# +# This attribute may be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_FRAMELOCK or NV_CTRL_TARGET_TYPE_X_SCREEN +# target. +# + +NV_CTRL_USE_HOUSE_SYNC = 218 # RW-F +NV_CTRL_USE_HOUSE_SYNC_DISABLED = 0 # aliases with FALSE +NV_CTRL_USE_HOUSE_SYNC_INPUT = 1 # aliases with TRUE +NV_CTRL_USE_HOUSE_SYNC_OUTPUT = 2 +NV_CTRL_USE_HOUSE_SYNC_FALSE = 0 +NV_CTRL_USE_HOUSE_SYNC_TRUE = 1 + +# +# NV_CTRL_EDID_AVAILABLE - report if an EDID is available for the +# specified display device. +# +# This attribute may also be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_GPU or NV_CTRL_TARGET_TYPE_X_SCREEN +# target. +# + +NV_CTRL_EDID_AVAILABLE = 219 # R-DG +NV_CTRL_EDID_AVAILABLE_FALSE = 0 +NV_CTRL_EDID_AVAILABLE_TRUE = 1 + +# +# NV_CTRL_FORCE_STEREO - when TRUE, OpenGL will force stereo flipping +# even when no stereo drawables are visible (if the device is configured +# to support it, see the "Stereo" X config option). +# When false, fall back to the default behavior of only flipping when a +# stereo drawable is visible. +# + +NV_CTRL_FORCE_STEREO = 220 # RW- +NV_CTRL_FORCE_STEREO_FALSE = 0 +NV_CTRL_FORCE_STEREO_TRUE = 1 + +# +# NV_CTRL_IMAGE_SETTINGS - the image quality setting for OpenGL clients. +# +# This setting is only applied to OpenGL clients that are started +# after this setting is applied. +# + +NV_CTRL_IMAGE_SETTINGS = 221 # RW-X +NV_CTRL_IMAGE_SETTINGS_HIGH_QUALITY = 0 +NV_CTRL_IMAGE_SETTINGS_QUALITY = 1 +NV_CTRL_IMAGE_SETTINGS_PERFORMANCE = 2 +NV_CTRL_IMAGE_SETTINGS_HIGH_PERFORMANCE = 3 + +# +# NV_CTRL_XINERAMA - return whether xinerama is enabled +# + +NV_CTRL_XINERAMA = 222 # R--G +NV_CTRL_XINERAMA_OFF = 0 +NV_CTRL_XINERAMA_ON = 1 + +# +# NV_CTRL_XINERAMA_STEREO - when TRUE, OpenGL will allow stereo flipping +# on multiple X screens configured with Xinerama. +# When FALSE, flipping is allowed only on one X screen at a time. +# + +NV_CTRL_XINERAMA_STEREO = 223 # RW- +NV_CTRL_XINERAMA_STEREO_FALSE = 0 +NV_CTRL_XINERAMA_STEREO_TRUE = 1 + +# +# NV_CTRL_BUS_RATE - if the bus type of the specified device is AGP, then +# NV_CTRL_BUS_RATE returns the configured AGP transfer rate. If the bus type +# is PCI Express, then this attribute returns the maximum link width. +# When this attribute is queried on an X screen target, the bus rate of the +# GPU driving the X screen is returned. +# + +NV_CTRL_BUS_RATE = 224 # R--GI + +# +# NV_CTRL_GPU_PCIE_MAX_LINK_WIDTH - returns the maximum +# PCIe link width, in number of lanes. +# +NV_CTRL_GPU_PCIE_MAX_LINK_WIDTH = NV_CTRL_BUS_RATE +# +# NV_CTRL_SHOW_SLI_VISUAL_INDICATOR - when TRUE, OpenGL will draw information +# about the current SLI mode. +# + +NV_CTRL_SHOW_SLI_VISUAL_INDICATOR = 225 # RW-X +NV_CTRL_SHOW_SLI_VISUAL_INDICATOR_FALSE = 0 +NV_CTRL_SHOW_SLI_VISUAL_INDICATOR_TRUE = 1 + +# +# NV_CTRL_SHOW_SLI_HUD - when TRUE, OpenGL will draw information about the +# current SLI mode. +# Renamed this attribute to NV_CTRL_SHOW_SLI_VISUAL_INDICATOR +# + +NV_CTRL_SHOW_SLI_HUD = NV_CTRL_SHOW_SLI_VISUAL_INDICATOR +NV_CTRL_SHOW_SLI_HUD_FALSE = NV_CTRL_SHOW_SLI_VISUAL_INDICATOR_FALSE +NV_CTRL_SHOW_SLI_HUD_TRUE = NV_CTRL_SHOW_SLI_VISUAL_INDICATOR_TRUE + +# +# NV_CTRL_XV_SYNC_TO_DISPLAY - deprecated +# +# NV_CTRL_XV_SYNC_TO_DISPLAY_ID should be used instead. +# + +NV_CTRL_XV_SYNC_TO_DISPLAY = 226 # deprecated + +# +# NV_CTRL_GVIO_REQUESTED_VIDEO_FORMAT2 - this attribute is only +# intended to be used to query the ValidValues for +# NV_CTRL_GVIO_REQUESTED_VIDEO_FORMAT for VIDEO_FORMAT values between +# 31 and 63. See NV_CTRL_GVIO_REQUESTED_VIDEO_FORMAT for details. +# + +NV_CTRL_GVIO_REQUESTED_VIDEO_FORMAT2 = 227 # ---GI + +# +# NV_CTRL_GVO_OUTPUT_VIDEO_FORMAT2 - renamed +# +# NV_CTRL_GVIO_REQUESTED_VIDEO_FORMAT2 should be used instead. +# +NV_CTRL_GVO_OUTPUT_VIDEO_FORMAT2 = 227 # renamed + +# +# NV_CTRL_GVO_OVERRIDE_HW_CSC - Override the SDI hardware's Color Space +# Conversion with the values controlled through +# XNVCTRLSetGvoColorConversion() and XNVCTRLGetGvoColorConversion(). If +# this attribute is FALSE, then the values specified through +# XNVCTRLSetGvoColorConversion() are ignored. +# + +NV_CTRL_GVO_OVERRIDE_HW_CSC = 228 # RW- +NV_CTRL_GVO_OVERRIDE_HW_CSC_FALSE = 0 +NV_CTRL_GVO_OVERRIDE_HW_CSC_TRUE = 1 + +# +# NV_CTRL_GVO_CAPABILITIES - this read-only attribute describes GVO +# capabilities that differ between NVIDIA SDI products. This value +# is a bitmask where each bit indicates whether that capability is +# available. +# +# APPLY_CSC_IMMEDIATELY - whether the CSC matrix, offset, and scale +# specified through XNVCTRLSetGvoColorConversion() will take affect +# immediately, or only after SDI output is disabled and enabled +# again. +# +# APPLY_CSC_TO_X_SCREEN - whether the CSC matrix, offset, and scale +# specified through XNVCTRLSetGvoColorConversion() will also apply +# to GVO output of an X screen, or only to OpenGL GVO output, as +# enabled through the GLX_NV_video_out extension. +# +# COMPOSITE_TERMINATION - whether the 75 ohm termination of the +# SDI composite input signal can be programmed through the +# NV_CTRL_GVO_COMPOSITE_TERMINATION attribute. +# +# SHARED_SYNC_BNC - whether the SDI device has a single BNC +# connector used for both (SDI & Composite) incoming signals. +# +# MULTIRATE_SYNC - whether the SDI device supports synchronization +# of input and output video modes that match in being odd or even +# modes (ie, AA.00 Hz modes can be synched to other BB.00 Hz modes and +# AA.XX Hz can match to BB.YY Hz where .XX and .YY are not .00) +# + +NV_CTRL_GVO_CAPABILITIES = 229 # R-- +NV_CTRL_GVO_CAPABILITIES_APPLY_CSC_IMMEDIATELY = 0x00000001 +NV_CTRL_GVO_CAPABILITIES_APPLY_CSC_TO_X_SCREEN = 0x00000002 +NV_CTRL_GVO_CAPABILITIES_COMPOSITE_TERMINATION = 0x00000004 +NV_CTRL_GVO_CAPABILITIES_SHARED_SYNC_BNC = 0x00000008 +NV_CTRL_GVO_CAPABILITIES_MULTIRATE_SYNC = 0x00000010 +NV_CTRL_GVO_CAPABILITIES_ADVANCE_SYNC_SKEW = 0x00000020 + +# +# NV_CTRL_GVO_COMPOSITE_TERMINATION - enable or disable 75 ohm +# termination of the SDI composite input signal. +# + +NV_CTRL_GVO_COMPOSITE_TERMINATION = 230 # RW- +NV_CTRL_GVO_COMPOSITE_TERMINATION_ENABLE = 1 +NV_CTRL_GVO_COMPOSITE_TERMINATION_DISABLE = 0 + +# +# NV_CTRL_ASSOCIATED_DISPLAY_DEVICES - deprecated +# +# NV_CTRL_BINARY_DATA_DISPLAYS_ASSIGNED_TO_XSCREEN should be used instead. +# + +NV_CTRL_ASSOCIATED_DISPLAY_DEVICES = 231 # deprecated + +# +# NV_CTRL_FRAMELOCK_SLAVES - deprecated +# +# NV_CTRL_FRAMELOCK_DISPLAY_CONFIG should be used instead. +# + +NV_CTRL_FRAMELOCK_SLAVES = 232 # deprecated + +# +# NV_CTRL_FRAMELOCK_MASTERABLE - deprecated +# +# NV_CTRL_FRAMELOCK_DISPLAY_CONFIG should be used instead. +# + +NV_CTRL_FRAMELOCK_MASTERABLE = 233 # deprecated + +# +# NV_CTRL_PROBE_DISPLAYS - re-probes the hardware to detect what +# display devices are connected to the GPU or GPU driving the +# specified X screen. The return value is deprecated and should not be used. +# +# This attribute may be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_GPU or NV_CTRL_TARGET_TYPE_X_SCREEN target. +# + +NV_CTRL_PROBE_DISPLAYS = 234 # R--G + +# +# NV_CTRL_REFRESH_RATE - Returns the refresh rate of the specified +# display device in 100# Hz (ie. to get the refresh rate in Hz, divide +# the returned value by 100.) +# +# This attribute may be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_GPU or NV_CTRL_TARGET_TYPE_X_SCREEN target. +# + +NV_CTRL_REFRESH_RATE = 235 # R-DG + +# +# NV_CTRL_GVO_FLIP_QUEUE_SIZE - The Graphics to Video Out interface +# exposed through NV-CONTROL and the GLX_NV_video_out extension uses +# an internal flip queue when pbuffers are sent to the video device +# (via glXSendPbufferToVideoNV()). The NV_CTRL_GVO_FLIP_QUEUE_SIZE +# can be used to query and assign the flip queue size. This +# attribute is applied to GLX when glXGetVideoDeviceNV() is called by +# the application. +# + +NV_CTRL_GVO_FLIP_QUEUE_SIZE = 236 # RW- + +# +# NV_CTRL_CURRENT_SCANLINE - query the current scanline for the +# specified display device. +# + +NV_CTRL_CURRENT_SCANLINE = 237 # R-DG + +# +# NV_CTRL_INITIAL_PIXMAP_PLACEMENT - Controls where X pixmaps are initially +# created. +# +# NV_CTRL_INITIAL_PIXMAP_PLACEMENT_FORCE_SYSMEM causes pixmaps to stay in +# system memory. These pixmaps can't be accelerated by the NVIDIA driver; this +# will cause blank windows if used with an OpenGL compositing manager. +# NV_CTRL_INITIAL_PIXMAP_PLACEMENT_SYSMEM creates pixmaps in system memory +# initially, but allows them to migrate to video memory. +# NV_CTRL_INITIAL_PIXMAP_PLACEMENT_VIDMEM creates pixmaps in video memory +# when enough resources are available. +# NV_CTRL_INITIAL_PIXMAP_PLACEMENT_RESERVED is currently reserved for future +# use. Behavior is undefined. +# NV_CTRL_INITIAL_PIXMAP_PLACEMENT_GPU_SYSMEM creates pixmaps in GPU accessible +# system memory when enough resources are available. +# + +NV_CTRL_INITIAL_PIXMAP_PLACEMENT = 238 # RW- +NV_CTRL_INITIAL_PIXMAP_PLACEMENT_FORCE_SYSMEM = 0 +NV_CTRL_INITIAL_PIXMAP_PLACEMENT_SYSMEM = 1 +NV_CTRL_INITIAL_PIXMAP_PLACEMENT_VIDMEM = 2 +NV_CTRL_INITIAL_PIXMAP_PLACEMENT_RESERVED = 3 +NV_CTRL_INITIAL_PIXMAP_PLACEMENT_GPU_SYSMEM = 4 + +# +# NV_CTRL_PCI_BUS - Returns the PCI bus number the specified device is using. +# + +NV_CTRL_PCI_BUS = 239 # R--GI + +# +# NV_CTRL_PCI_DEVICE - Returns the PCI device number the specified device is +# using. +# + +NV_CTRL_PCI_DEVICE = 240 # R--GI + +# +# NV_CTRL_PCI_FUNCTION - Returns the PCI function number the specified device +# is using. +# + +NV_CTRL_PCI_FUNCTION = 241 # R--GI + +# +# NV_CTRL_FRAMELOCK_FPGA_REVISION - Queries the FPGA revision of the +# Frame Lock device. +# +# This attribute must be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_FRAMELOCK target. +# + +NV_CTRL_FRAMELOCK_FPGA_REVISION = 242 # R--F + +# +# NV_CTRL_MAX_SCREEN_{WIDTH,HEIGHT} - the maximum allowable size, in +# pixels, of either the specified X screen (if the target_type of the +# query is an X screen), or any X screen on the specified GPU (if the +# target_type of the query is a GPU). +# + +NV_CTRL_MAX_SCREEN_WIDTH = 243 # R--G +NV_CTRL_MAX_SCREEN_HEIGHT = 244 # R--G + +# +# NV_CTRL_MAX_DISPLAYS - The maximum number of display devices that +# can be driven simultaneously on a GPU (e.g., that can be used in a +# MetaMode at once). Note that this does not indicate the maximum +# number of displays that are listed in NV_CTRL_BINARY_DATA_DISPLAYS_ON_GPU +# and NV_CTRL_BINARY_DATA_DISPLAYS_CONNECTED_TO_GPU because more display +# devices can be connected than are actively in use. +# + +NV_CTRL_MAX_DISPLAYS = 245 # R--G + +# +# NV_CTRL_DYNAMIC_TWINVIEW - Returns whether or not the screen +# supports dynamic twinview. +# + +NV_CTRL_DYNAMIC_TWINVIEW = 246 # R-- + +# +# NV_CTRL_MULTIGPU_DISPLAY_OWNER - Returns the (NV-CONTROL) GPU ID of +# the GPU that has the display device(s) used for showing the X Screen. +# + +NV_CTRL_MULTIGPU_DISPLAY_OWNER = 247 # R-- + +# +# NV_CTRL_GPU_SCALING - not supported +# + +NV_CTRL_GPU_SCALING = 248 # not supported + +NV_CTRL_GPU_SCALING_TARGET_INVALID = 0 # not supported +NV_CTRL_GPU_SCALING_TARGET_FLATPANEL_BEST_FIT = 1 # not supported +NV_CTRL_GPU_SCALING_TARGET_FLATPANEL_NATIVE = 2 # not supported + +NV_CTRL_GPU_SCALING_METHOD_INVALID = 0 # not supported +NV_CTRL_GPU_SCALING_METHOD_STRETCHED = 1 # not supported +NV_CTRL_GPU_SCALING_METHOD_CENTERED = 2 # not supported +NV_CTRL_GPU_SCALING_METHOD_ASPECT_SCALED = 3 # not supported + +# +# NV_CTRL_FRONTEND_RESOLUTION - not supported +# + +NV_CTRL_FRONTEND_RESOLUTION = 249 # not supported + +# +# NV_CTRL_BACKEND_RESOLUTION - not supported +# + +NV_CTRL_BACKEND_RESOLUTION = 250 # not supported + +# +# NV_CTRL_FLATPANEL_NATIVE_RESOLUTION - not supported +# + +NV_CTRL_FLATPANEL_NATIVE_RESOLUTION = 251 # not supported + +# +# NV_CTRL_FLATPANEL_BEST_FIT_RESOLUTION - not supported +# + +NV_CTRL_FLATPANEL_BEST_FIT_RESOLUTION = 252 # not supported + +# +# NV_CTRL_GPU_SCALING_ACTIVE - not supported +# + +NV_CTRL_GPU_SCALING_ACTIVE = 253 # not supported + +# +# NV_CTRL_DFP_SCALING_ACTIVE - not supported +# + +NV_CTRL_DFP_SCALING_ACTIVE = 254 # not supported + +# +# NV_CTRL_FSAA_APPLICATION_ENHANCED - Controls how the NV_CTRL_FSAA_MODE +# is applied when NV_CTRL_FSAA_APPLICATION_CONTROLLED is set to +# NV_CTRL_APPLICATION_CONTROLLED_DISABLED. When +# NV_CTRL_FSAA_APPLICATION_ENHANCED is _DISABLED, OpenGL applications will +# be forced to use the FSAA mode specified by NV_CTRL_FSAA_MODE. when set +# to _ENABLED, only those applications that have selected a multisample +# FBConfig will be made to use the NV_CTRL_FSAA_MODE specified. +# +# This attribute is ignored when NV_CTRL_FSAA_APPLICATION_CONTROLLED is +# set to NV_CTRL_FSAA_APPLICATION_CONTROLLED_ENABLED. +# + +NV_CTRL_FSAA_APPLICATION_ENHANCED = 255 # RW-X +NV_CTRL_FSAA_APPLICATION_ENHANCED_ENABLED = 1 +NV_CTRL_FSAA_APPLICATION_ENHANCED_DISABLED = 0 + +# +# NV_CTRL_FRAMELOCK_SYNC_RATE_4 - This is the refresh rate that the +# frame lock board is sending to the GPU with 4 digits of precision. +# +# This attribute may be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_FRAMELOCK. +# + +NV_CTRL_FRAMELOCK_SYNC_RATE_4 = 256 # R--F + +# +# NV_CTRL_GVO_LOCK_OWNER - indicates that the GVO device is available +# or in use (by GLX or an X screen). +# +# The GVO device is locked by GLX when either glXGetVideoDeviceNV +# (part of GLX_NV_video_out) or glXBindVideoDeviceNV (part of +# GLX_NV_present_video) is called. All GVO output resources are +# locked until released by the GLX_NV_video_out/GLX_NV_present_video +# client. +# +# The GVO device is locked/unlocked by an X screen, when the GVO device is +# used in a MetaMode on an X screen. +# +# When the GVO device is locked, setting of the following GVO NV-CONTROL +# attributes will not happen immediately and will instead be cached. The +# GVO resource will need to be disabled/released and re-enabled/claimed for +# the values to be flushed. These attributes are: +# +# NV_CTRL_GVIO_REQUESTED_VIDEO_FORMAT +# NV_CTRL_GVO_DATA_FORMAT +# NV_CTRL_GVO_FLIP_QUEUE_SIZE +# + +NV_CTRL_GVO_LOCK_OWNER = 257 # R-- +NV_CTRL_GVO_LOCK_OWNER_NONE = 0 +NV_CTRL_GVO_LOCK_OWNER_GLX = 1 +NV_CTRL_GVO_LOCK_OWNER_CLONE = 2 # not supported +NV_CTRL_GVO_LOCK_OWNER_X_SCREEN = 3 + +# +# NV_CTRL_HWOVERLAY - when a workstation overlay is in use, reports +# whether the hardware overlay is used, or if the overlay is emulated. +# + +NV_CTRL_HWOVERLAY = 258 # R-- +NV_CTRL_HWOVERLAY_FALSE = 0 +NV_CTRL_HWOVERLAY_TRUE = 1 + +# +# NV_CTRL_NUM_GPU_ERRORS_RECOVERED - Returns the number of GPU errors +# occured. This attribute may be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_X_SCREEN target. +# + +NV_CTRL_NUM_GPU_ERRORS_RECOVERED = 259 # R--- + +# +# NV_CTRL_REFRESH_RATE_3 - Returns the refresh rate of the specified +# display device in 1000# Hz (ie. to get the refresh rate in Hz, divide +# the returned value by 1000.) +# +# This attribute may be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_GPU or NV_CTRL_TARGET_TYPE_X_SCREEN target. +# + +NV_CTRL_REFRESH_RATE_3 = 260 # R-DG + +# +# NV_CTRL_ONDEMAND_VBLANK_INTERRUPTS - not supported +# + +NV_CTRL_ONDEMAND_VBLANK_INTERRUPTS = 261 # not supported +NV_CTRL_ONDEMAND_VBLANK_INTERRUPTS_OFF = 0 # not supported +NV_CTRL_ONDEMAND_VBLANK_INTERRUPTS_ON = 1 # not supported + +# +# NV_CTRL_GPU_POWER_SOURCE reports the type of power source +# of the GPU driving the X screen. +# + +NV_CTRL_GPU_POWER_SOURCE = 262 # R--G +NV_CTRL_GPU_POWER_SOURCE_AC = 0 +NV_CTRL_GPU_POWER_SOURCE_BATTERY = 1 + +# +# NV_CTRL_GPU_CURRENT_PERFORMANCE_MODE - not supported +# + +NV_CTRL_GPU_CURRENT_PERFORMANCE_MODE = 263 # not supported +NV_CTRL_GPU_CURRENT_PERFORMANCE_MODE_DESKTOP = 0 # not supported +NV_CTRL_GPU_CURRENT_PERFORMANCE_MODE_MAXPERF = 1 # not supported + +# NV_CTRL_GLYPH_CACHE - Enables RENDER Glyph Caching to VRAM + +NV_CTRL_GLYPH_CACHE = 264 # RW- +NV_CTRL_GLYPH_CACHE_DISABLED = 0 +NV_CTRL_GLYPH_CACHE_ENABLED = 1 + +# +# NV_CTRL_GPU_CURRENT_PERFORMANCE_LEVEL reports the current +# Performance level of the GPU driving the X screen. Each +# Performance level has associated NVClock and Mem Clock values. +# + +NV_CTRL_GPU_CURRENT_PERFORMANCE_LEVEL = 265 # R--G + +# +# NV_CTRL_GPU_ADAPTIVE_CLOCK_STATE reports if Adaptive Clocking +# is Enabled on the GPU driving the X screen. +# + +NV_CTRL_GPU_ADAPTIVE_CLOCK_STATE = 266 # R--G +NV_CTRL_GPU_ADAPTIVE_CLOCK_STATE_DISABLED = 0 +NV_CTRL_GPU_ADAPTIVE_CLOCK_STATE_ENABLED = 1 + +# +# NV_CTRL_GVO_OUTPUT_VIDEO_LOCKED - Returns whether or not the GVO output +# video is locked to the GPU. +# + +NV_CTRL_GVO_OUTPUT_VIDEO_LOCKED = 267 # R--- +NV_CTRL_GVO_OUTPUT_VIDEO_LOCKED_FALSE = 0 +NV_CTRL_GVO_OUTPUT_VIDEO_LOCKED_TRUE = 1 + +# +# NV_CTRL_GVO_SYNC_LOCK_STATUS - Returns whether or not the GVO device +# is locked to the input ref signal. If the sync mode is set to +# NV_CTRL_GVO_SYNC_MODE_GENLOCK, then this returns the genlock +# sync status, and if the sync mode is set to NV_CTRL_GVO_SYNC_MODE_FRAMELOCK, +# then this reports the frame lock status. +# + +NV_CTRL_GVO_SYNC_LOCK_STATUS = 268 # R--- +NV_CTRL_GVO_SYNC_LOCK_STATUS_UNLOCKED = 0 +NV_CTRL_GVO_SYNC_LOCK_STATUS_LOCKED = 1 + +# +# NV_CTRL_GVO_ANC_TIME_CODE_GENERATION - Allows SDI device to generate +# time codes in the ANC region of the SDI video output stream. +# + +NV_CTRL_GVO_ANC_TIME_CODE_GENERATION = 269 # RW-- +NV_CTRL_GVO_ANC_TIME_CODE_GENERATION_DISABLE = 0 +NV_CTRL_GVO_ANC_TIME_CODE_GENERATION_ENABLE = 1 + +# +# NV_CTRL_GVO_COMPOSITE - Enables/Disables SDI compositing. This attribute +# is only available when an SDI input source is detected and is in genlock +# mode. +# + +NV_CTRL_GVO_COMPOSITE = 270 # RW-- +NV_CTRL_GVO_COMPOSITE_DISABLE = 0 +NV_CTRL_GVO_COMPOSITE_ENABLE = 1 + +# +# NV_CTRL_GVO_COMPOSITE_ALPHA_KEY - When compositing is enabled, this +# enables/disables alpha blending. +# + +NV_CTRL_GVO_COMPOSITE_ALPHA_KEY = 271 # RW-- +NV_CTRL_GVO_COMPOSITE_ALPHA_KEY_DISABLE = 0 +NV_CTRL_GVO_COMPOSITE_ALPHA_KEY_ENABLE = 1 + +# +# NV_CTRL_GVO_COMPOSITE_LUMA_KEY_RANGE - Set the values of a luma +# channel range. This is a packed int that has the following format +# (in order of high-bits to low bits): +# +# Range # (11 bits), (Enabled 1 bit), min value (10 bits), max value (10 bits) +# +# To query the current values, pass the range # throught the display_mask +# variable. +# + +NV_CTRL_GVO_COMPOSITE_LUMA_KEY_RANGE = 272 # RW-- + +# +# NV_CTRL_GVO_COMPOSITE_CR_KEY_RANGE - Set the values of a CR +# channel range. This is a packed int that has the following format +# (in order of high-bits to low bits): +# +# Range # (11 bits), (Enabled 1 bit), min value (10 bits), max value (10 bits) +# +# To query the current values, pass the range # throught he display_mask +# variable. +# + +NV_CTRL_GVO_COMPOSITE_CR_KEY_RANGE = 273 # RW-- + +# +# NV_CTRL_GVO_COMPOSITE_CB_KEY_RANGE - Set the values of a CB +# channel range. This is a packed int that has the following format +# (in order of high-bits to low bits): +# +# Range # (11 bits), (Enabled 1 bit), min value (10 bits), max value (10 bits) +# +# To query the current values, pass the range # throught he display_mask +# variable. +# + +NV_CTRL_GVO_COMPOSITE_CB_KEY_RANGE = 274 # RW-- + +# +# NV_CTRL_GVO_COMPOSITE_NUM_KEY_RANGES - Returns the number of ranges +# available for each channel (Y/Luma, Cr, and Cb.) +# + +NV_CTRL_GVO_COMPOSITE_NUM_KEY_RANGES = 275 # R--- + +# +# NV_CTRL_SWITCH_TO_DISPLAYS - not supported +# + +NV_CTRL_SWITCH_TO_DISPLAYS = 276 # not supported + +# +# NV_CTRL_NOTEBOOK_DISPLAY_CHANGE_LID_EVENT - not supported +# + +NV_CTRL_NOTEBOOK_DISPLAY_CHANGE_LID_EVENT = 277 # not supported + +# +# NV_CTRL_NOTEBOOK_INTERNAL_LCD - deprecated +# + +NV_CTRL_NOTEBOOK_INTERNAL_LCD = 278 # deprecated + +# +# NV_CTRL_DEPTH_30_ALLOWED - returns whether the NVIDIA X driver supports +# depth 30 on the specified X screen or GPU. +# + +NV_CTRL_DEPTH_30_ALLOWED = 279 # R--G + +# +# NV_CTRL_MODE_SET_EVENT This attribute is sent as an event +# when hotkey, ctrl-alt-+/- or randr event occurs. Note that +# This attribute cannot be set or queried and is meant to +# be received by clients that wish to be notified of when +# mode set events occur. +# + +NV_CTRL_MODE_SET_EVENT = 280 # --- + +# +# NV_CTRL_OPENGL_AA_LINE_GAMMA_VALUE - the gamma value used by +# OpenGL when NV_CTRL_OPENGL_AA_LINE_GAMMA is enabled +# + +NV_CTRL_OPENGL_AA_LINE_GAMMA_VALUE = 281 # RW-X + +# +# NV_CTRL_VCSC_HIGH_PERF_MODE - deprecated +# +# Is used to both query High Performance Mode status on the Visual Computing +# System, and also to enable or disable High Performance Mode. +# + +NV_CTRL_VCSC_HIGH_PERF_MODE = 282 # RW-V +NV_CTRL_VCSC_HIGH_PERF_MODE_DISABLE = 0 +NV_CTRL_VCSC_HIGH_PERF_MODE_ENABLE = 1 + +# +# NV_CTRL_DISPLAYPORT_LINK_RATE - returns the negotiated lane bandwidth of the +# DisplayPort main link. The numerical value of this attribute is the link +# rate in bps divided by 27000000. +# This attribute is only available for DisplayPort flat panels. +# + +NV_CTRL_DISPLAYPORT_LINK_RATE = 291 # R-DG +NV_CTRL_DISPLAYPORT_LINK_RATE_DISABLED = 0x0 +NV_CTRL_DISPLAYPORT_LINK_RATE_1_62GBPS = 0x6 # deprecated +NV_CTRL_DISPLAYPORT_LINK_RATE_2_70GBPS = 0xA # deprecated + +# +# NV_CTRL_STEREO_EYES_EXCHANGE - Controls whether or not the left and right +# eyes of a stereo image are flipped. +# + +NV_CTRL_STEREO_EYES_EXCHANGE = 292 # RW-X +NV_CTRL_STEREO_EYES_EXCHANGE_OFF = 0 +NV_CTRL_STEREO_EYES_EXCHANGE_ON = 1 + +# +# NV_CTRL_NO_SCANOUT - returns whether the special "NoScanout" mode is +# enabled on the specified X screen or GPU; for details on this mode, +# see the description of the "none" value for the "UseDisplayDevice" +# X configuration option in the NVIDIA driver README. +# + +NV_CTRL_NO_SCANOUT = 293 # R--G +NV_CTRL_NO_SCANOUT_DISABLED = 0 +NV_CTRL_NO_SCANOUT_ENABLED = 1 + +# +# NV_CTRL_GVO_CSC_CHANGED_EVENT This attribute is sent as an event +# when the color space conversion matrix has been altered by another +# client. +# + +NV_CTRL_GVO_CSC_CHANGED_EVENT = 294 # --- + +# +# NV_CTRL_FRAMELOCK_SLAVEABLE - deprecated +# +# NV_CTRL_FRAMELOCK_DISPLAY_CONFIG should be used instead. +# + +NV_CTRL_FRAMELOCK_SLAVEABLE = 295 # deprecated + +# +# NV_CTRL_GVO_SYNC_TO_DISPLAY This attribute controls whether or not +# the non-SDI display device will be sync'ed to the SDI display device +# (when configured in TwinView, Clone Mode or when using the SDI device +# with OpenGL). +# + +NV_CTRL_GVO_SYNC_TO_DISPLAY = 296 # --- +NV_CTRL_GVO_SYNC_TO_DISPLAY_DISABLE = 0 +NV_CTRL_GVO_SYNC_TO_DISPLAY_ENABLE = 1 + +# +# NV_CTRL_X_SERVER_UNIQUE_ID - returns a pseudo-unique identifier for this +# X server. Intended for use in cases where an NV-CONTROL client communicates +# with multiple X servers, and wants some level of confidence that two +# X Display connections correspond to the same or different X servers. +# + +NV_CTRL_X_SERVER_UNIQUE_ID = 297 # R--- + +# +# NV_CTRL_PIXMAP_CACHE - This attribute controls whether the driver attempts to +# store video memory pixmaps in a cache. The cache speeds up allocation and +# deallocation of pixmaps, but could use more memory than when the cache is +# disabled. +# + +NV_CTRL_PIXMAP_CACHE = 298 # RW-X +NV_CTRL_PIXMAP_CACHE_DISABLE = 0 +NV_CTRL_PIXMAP_CACHE_ENABLE = 1 + +# +# NV_CTRL_PIXMAP_CACHE_ROUNDING_SIZE_KB - When the pixmap cache is enabled and +# there is not enough free space in the cache to fit a new pixmap, the driver +# will round up to the next multiple of this number of kilobytes when +# allocating more memory for the cache. +# + +NV_CTRL_PIXMAP_CACHE_ROUNDING_SIZE_KB = 299 # RW-X + +# +# NV_CTRL_IS_GVO_DISPLAY - returns whether or not a given display is an +# SDI device. +# + +NV_CTRL_IS_GVO_DISPLAY = 300 # R-D +NV_CTRL_IS_GVO_DISPLAY_FALSE = 0 +NV_CTRL_IS_GVO_DISPLAY_TRUE = 1 + +# +# NV_CTRL_PCI_ID - Returns the PCI vendor and device ID of the specified +# device. +# +# NV_CTRL_PCI_ID is a "packed" integer attribute; the PCI vendor ID is stored +# in the upper 16 bits of the integer, and the PCI device ID is stored in the +# lower 16 bits of the integer. +# + +NV_CTRL_PCI_ID = 301 # R--GI + +# +# NV_CTRL_GVO_FULL_RANGE_COLOR - Allow full range color data [4-1019] +# without clamping to [64-940]. +# + +NV_CTRL_GVO_FULL_RANGE_COLOR = 302 # RW- +NV_CTRL_GVO_FULL_RANGE_COLOR_DISABLED = 0 +NV_CTRL_GVO_FULL_RANGE_COLOR_ENABLED = 1 + +# +# NV_CTRL_SLI_MOSAIC_MODE_AVAILABLE - Returns whether or not +# SLI Mosaic Mode supported. +# + +NV_CTRL_SLI_MOSAIC_MODE_AVAILABLE = 303 # R-- +NV_CTRL_SLI_MOSAIC_MODE_AVAILABLE_FALSE = 0 +NV_CTRL_SLI_MOSAIC_MODE_AVAILABLE_TRUE = 1 + +# +# NV_CTRL_GVO_ENABLE_RGB_DATA - Allows clients to specify when +# the GVO board should process colors as RGB when the output data +# format is one of the NV_CTRL_GVO_DATA_FORMAT_???_PASSTRHU modes. +# + +NV_CTRL_GVO_ENABLE_RGB_DATA = 304 # RW- +NV_CTRL_GVO_ENABLE_RGB_DATA_DISABLE = 0 +NV_CTRL_GVO_ENABLE_RGB_DATA_ENABLE = 1 + +# +# NV_CTRL_IMAGE_SHARPENING_DEFAULT - Returns default value of +# Image Sharpening. +# + +NV_CTRL_IMAGE_SHARPENING_DEFAULT = 305 # R-- + +# +# NV_CTRL_PCI_DOMAIN - Returns the PCI domain number the specified device is +# using. +# + +NV_CTRL_PCI_DOMAIN = 306 # R--GI + +# +# NV_CTRL_GVI_NUM_JACKS - Returns the number of input BNC jacks available +# on a GVI device. +# + +NV_CTRL_GVI_NUM_JACKS = 307 # R--I + +# +# NV_CTRL_GVI_MAX_LINKS_PER_STREAM - Returns the maximum supported number of +# links that can be tied to one stream. +# + +NV_CTRL_GVI_MAX_LINKS_PER_STREAM = 308 # R--I + +# +# NV_CTRL_GVI_DETECTED_CHANNEL_BITS_PER_COMPONENT - Returns the detected +# number of bits per component (BPC) of data on the given input jack+ +# channel. +# +# The jack number should be specified in the lower 16 bits of the +# "display_mask" parameter, while the channel number should be specified in +# the upper 16 bits. +# + +NV_CTRL_GVI_DETECTED_CHANNEL_BITS_PER_COMPONENT = 309 # R--I +NV_CTRL_GVI_BITS_PER_COMPONENT_UNKNOWN = 0 +NV_CTRL_GVI_BITS_PER_COMPONENT_8 = 1 +NV_CTRL_GVI_BITS_PER_COMPONENT_10 = 2 +NV_CTRL_GVI_BITS_PER_COMPONENT_12 = 3 + +# +# NV_CTRL_GVI_REQUESTED_STREAM_BITS_PER_COMPONENT - Specify the number of +# bits per component (BPC) of data for the captured stream. +# The stream number should be specified in the "display_mask" parameter. +# +# Note: Setting this attribute may also result in the following +# NV-CONTROL attributes being reset on the GVI device (to ensure +# the configuration remains valid): +# NV_CTRL_GVI_REQUESTED_STREAM_COMPONENT_SAMPLING +# + +NV_CTRL_GVI_REQUESTED_STREAM_BITS_PER_COMPONENT = 310 # RW-I + +# +# NV_CTRL_GVI_DETECTED_CHANNEL_COMPONENT_SAMPLING - Returns the detected +# sampling format for the input jack+channel. +# +# The jack number should be specified in the lower 16 bits of the +# "display_mask" parameter, while the channel number should be specified in +# the upper 16 bits. +# + +NV_CTRL_GVI_DETECTED_CHANNEL_COMPONENT_SAMPLING = 311 # R--I +NV_CTRL_GVI_COMPONENT_SAMPLING_UNKNOWN = 0 +NV_CTRL_GVI_COMPONENT_SAMPLING_4444 = 1 +NV_CTRL_GVI_COMPONENT_SAMPLING_4224 = 2 +NV_CTRL_GVI_COMPONENT_SAMPLING_444 = 3 +NV_CTRL_GVI_COMPONENT_SAMPLING_422 = 4 +NV_CTRL_GVI_COMPONENT_SAMPLING_420 = 5 + +# +# NV_CTRL_GVI_REQUESTED_COMPONENT_SAMPLING - Specify the sampling format for +# the captured stream. +# The possible values are the NV_CTRL_GVI_DETECTED_COMPONENT_SAMPLING +# constants. +# The stream number should be specified in the "display_mask" parameter. +# + +NV_CTRL_GVI_REQUESTED_STREAM_COMPONENT_SAMPLING = 312 # RW-I + +# +# NV_CTRL_GVI_CHROMA_EXPAND - Enable or disable 4:2:2 -> 4:4:4 chroma +# expansion for the captured stream. This value is ignored when a +# COMPONENT_SAMPLING format is selected that does not use chroma subsampling, +# or if a BITS_PER_COMPONENT value is selected that is not supported. +# The stream number should be specified in the "display_mask" parameter. +# + +NV_CTRL_GVI_REQUESTED_STREAM_CHROMA_EXPAND = 313 # RW-I +NV_CTRL_GVI_CHROMA_EXPAND_FALSE = 0 +NV_CTRL_GVI_CHROMA_EXPAND_TRUE = 1 + +# +# NV_CTRL_GVI_DETECTED_CHANNEL_COLOR_SPACE - Returns the detected color space +# of the input jack+channel. +# +# The jack number should be specified in the lower 16 bits of the +# "display_mask" parameter, while the channel number should be specified in +# the upper 16 bits. +# + +NV_CTRL_GVI_DETECTED_CHANNEL_COLOR_SPACE = 314 # R--I +NV_CTRL_GVI_COLOR_SPACE_UNKNOWN = 0 +NV_CTRL_GVI_COLOR_SPACE_GBR = 1 +NV_CTRL_GVI_COLOR_SPACE_GBRA = 2 +NV_CTRL_GVI_COLOR_SPACE_GBRD = 3 +NV_CTRL_GVI_COLOR_SPACE_YCBCR = 4 +NV_CTRL_GVI_COLOR_SPACE_YCBCRA = 5 +NV_CTRL_GVI_COLOR_SPACE_YCBCRD = 6 + +# +# NV_CTRL_GVI_DETECTED_CHANNEL_LINK_ID - Returns the detected link identifier +# for the given input jack+channel. +# +# The jack number should be specified in the lower 16 bits of the +# "display_mask" parameter, while the channel number should be specified in +# the upper 16 bits. +# + +NV_CTRL_GVI_DETECTED_CHANNEL_LINK_ID = 315 # R--I +NV_CTRL_GVI_LINK_ID_UNKNOWN = 0xFFFF + +# +# NV_CTRL_GVI_DETECTED_CHANNEL_SMPTE352_IDENTIFIER - Returns the 4-byte +# SMPTE 352 identifier from the given input jack+channel. +# +# The jack number should be specified in the lower 16 bits of the +# "display_mask" parameter, while the channel number should be specified in +# the upper 16 bits. +# + +NV_CTRL_GVI_DETECTED_CHANNEL_SMPTE352_IDENTIFIER = 316 # R--I + +# +# NV_CTRL_GVI_GLOBAL_IDENTIFIER - Returns a global identifier for the +# GVI device. This identifier can be used to relate GVI devices named +# in NV-CONTROL with those enumerated in OpenGL. +# + +NV_CTRL_GVI_GLOBAL_IDENTIFIER = 317 # R--I + +# +# NV_CTRL_FRAMELOCK_SYNC_DELAY_RESOLUTION - Returns the number of nanoseconds +# that one unit of NV_CTRL_FRAMELOCK_SYNC_DELAY corresponds to. +# +NV_CTRL_FRAMELOCK_SYNC_DELAY_RESOLUTION = 318 # R-- + +# +# NV_CTRL_GPU_COOLER_MANUAL_CONTROL - Query the current or set a new +# cooler control state; the value of this attribute controls the +# availability of additional cooler control attributes (see below). +# +# Note: this attribute is unavailable unless cooler control support +# has been enabled in the X server (by the user). +# + +NV_CTRL_GPU_COOLER_MANUAL_CONTROL = 319 # RW-G +NV_CTRL_GPU_COOLER_MANUAL_CONTROL_FALSE = 0 +NV_CTRL_GPU_COOLER_MANUAL_CONTROL_TRUE = 1 + +# +# NV_CTRL_THERMAL_COOLER_LEVEL - The cooler's target level. +# Normally, the driver dynamically adjusts the cooler based on +# the needs of the GPU. But when NV_CTRL_GPU_COOLER_MANUAL_CONTROL=TRUE, +# the driver will attempt to make the cooler achieve the setting in +# NV_CTRL_THERMAL_COOLER_LEVEL. The actual current level of the cooler +# is reported in NV_CTRL_THERMAL_COOLER_CURRENT_LEVEL. +# + +NV_CTRL_THERMAL_COOLER_LEVEL = 320 # RW-C + +# NV_CTRL_THERMAL_COOLER_LEVEL_SET_DEFAULT - Sets default values of +# cooler. +# + +NV_CTRL_THERMAL_COOLER_LEVEL_SET_DEFAULT = 321 # -W-C + +# +# NV_CTRL_THERMAL_COOLER_CONTROL_TYPE - +# Returns a cooler's control signal characteristics. +# The possible types are restricted, Variable and Toggle. +# + +NV_CTRL_THERMAL_COOLER_CONTROL_TYPE = 322 # R--C +NV_CTRL_THERMAL_COOLER_CONTROL_TYPE_NONE = 0 +NV_CTRL_THERMAL_COOLER_CONTROL_TYPE_TOGGLE = 1 +NV_CTRL_THERMAL_COOLER_CONTROL_TYPE_VARIABLE = 2 + +# +# NV_CTRL_THERMAL_COOLER_TARGET - Returns objects that cooler cools. +# Targets may be GPU, Memory, Power Supply or All of these. +# GPU_RELATED = GPU | MEMORY | POWER_SUPPLY +# +# + +NV_CTRL_THERMAL_COOLER_TARGET = 323 # R--C +NV_CTRL_THERMAL_COOLER_TARGET_NONE = 0 +NV_CTRL_THERMAL_COOLER_TARGET_GPU = 1 +NV_CTRL_THERMAL_COOLER_TARGET_MEMORY = 2 +NV_CTRL_THERMAL_COOLER_TARGET_POWER_SUPPLY = 4 +NV_CTRL_THERMAL_COOLER_TARGET_GPU_RELATED = NV_CTRL_THERMAL_COOLER_TARGET_GPU | NV_CTRL_THERMAL_COOLER_TARGET_MEMORY | NV_CTRL_THERMAL_COOLER_TARGET_POWER_SUPPLY + +# +# NV_CTRL_GPU_ECC_SUPPORTED - Reports whether ECC is supported by the +# targeted GPU. +# +NV_CTRL_GPU_ECC_SUPPORTED = 324 # R--G +NV_CTRL_GPU_ECC_SUPPORTED_FALSE = 0 +NV_CTRL_GPU_ECC_SUPPORTED_TRUE = 1 + +# +# NV_CTRL_GPU_ECC_STATUS - Returns the current hardware ECC setting +# for the targeted GPU. +# +NV_CTRL_GPU_ECC_STATUS = 325 # R--G +NV_CTRL_GPU_ECC_STATUS_DISABLED = 0 +NV_CTRL_GPU_ECC_STATUS_ENABLED = 1 + +# +# NV_CTRL_GPU_ECC_CONFIGURATION - Reports whether ECC can be configured +# dynamically for the GPU in question. +# +NV_CTRL_GPU_ECC_CONFIGURATION_SUPPORTED = 326 # R--G +NV_CTRL_GPU_ECC_CONFIGURATION_SUPPORTED_FALSE = 0 +NV_CTRL_GPU_ECC_CONFIGURATION_SUPPORTED_TRUE = 1 + +# +# NV_CTRL_GPU_ECC_CONFIGURATION_SETTING - Returns the current ECC +# configuration setting or specifies new settings. New settings do not +# take effect until the next POST. +# +NV_CTRL_GPU_ECC_CONFIGURATION = 327 # RW-G +NV_CTRL_GPU_ECC_CONFIGURATION_DISABLED = 0 +NV_CTRL_GPU_ECC_CONFIGURATION_ENABLED = 1 + +# +# NV_CTRL_GPU_ECC_DEFAULT_CONFIGURATION_SETTING - Returns the default +# ECC configuration setting. +# +NV_CTRL_GPU_ECC_DEFAULT_CONFIGURATION = 328 # R--G +NV_CTRL_GPU_ECC_DEFAULT_CONFIGURATION_DISABLED = 0 +NV_CTRL_GPU_ECC_DEFAULT_CONFIGURATION_ENABLED = 1 + +# +# NV_CTRL_GPU_ECC_SINGLE_BIT_ERRORS - Returns the number of single-bit +# ECC errors detected by the targeted GPU since the last POST. +# Note: this attribute is a 64-bit integer attribute. +# +NV_CTRL_GPU_ECC_SINGLE_BIT_ERRORS = 329 # R--GQ + +# +# NV_CTRL_GPU_ECC_DOUBLE_BIT_ERRORS - Returns the number of double-bit +# ECC errors detected by the targeted GPU since the last POST. +# Note: this attribute is a 64-bit integer attribute. +# +NV_CTRL_GPU_ECC_DOUBLE_BIT_ERRORS = 330 # R--GQ + +# +# NV_CTRL_GPU_ECC_AGGREGATE_SINGLE_BIT_ERRORS - Returns the number of +# single-bit ECC errors detected by the targeted GPU since the +# last counter reset. +# Note: this attribute is a 64-bit integer attribute. +# +NV_CTRL_GPU_ECC_AGGREGATE_SINGLE_BIT_ERRORS = 331 # R--GQ + +# +# NV_CTRL_GPU_ECC_AGGREGATE_DOUBLE_BIT_ERRORS - Returns the number of +# double-bit ECC errors detected by the targeted GPU since the +# last counter reset. +# Note: this attribute is a 64-bit integer attribute. +# +NV_CTRL_GPU_ECC_AGGREGATE_DOUBLE_BIT_ERRORS = 332 # R--GQ + +# +# NV_CTRL_GPU_ECC_RESET_ERROR_STATUS - Resets the volatile/aggregate +# single-bit and double-bit error counters. This attribute is a +# bitmask attribute. +# +NV_CTRL_GPU_ECC_RESET_ERROR_STATUS = 333 # -W-G +NV_CTRL_GPU_ECC_RESET_ERROR_STATUS_VOLATILE = 0x00000001 +NV_CTRL_GPU_ECC_RESET_ERROR_STATUS_AGGREGATE = 0x00000002 + +# +# NV_CTRL_GPU_POWER_MIZER_MODE - Provides a hint to the driver +# as to how to manage the performance of the GPU. +# +# ADAPTIVE - adjust GPU clocks based on GPU +# utilization +# PREFER_MAXIMUM_PERFORMANCE - raise GPU clocks to favor +# maximum performance, to the extent +# that thermal and other constraints +# allow +# AUTO - let the driver choose the performance +# policy +# PREFER_CONSISTENT_PERFORMANCE - lock to GPU base clocks +# +NV_CTRL_GPU_POWER_MIZER_MODE = 334 # RW-G +NV_CTRL_GPU_POWER_MIZER_MODE_ADAPTIVE = 0 +NV_CTRL_GPU_POWER_MIZER_MODE_PREFER_MAXIMUM_PERFORMANCE = 1 +NV_CTRL_GPU_POWER_MIZER_MODE_AUTO = 2 +NV_CTRL_GPU_POWER_MIZER_MODE_PREFER_CONSISTENT_PERFORMANCE = 3 + +# +# NV_CTRL_GVI_SYNC_OUTPUT_FORMAT - Returns the output sync signal +# from the GVI device. +# + +NV_CTRL_GVI_SYNC_OUTPUT_FORMAT = 335 # R--I + +# +# NV_CTRL_GVI_MAX_CHANNELS_PER_JACK - Returns the maximum +# supported number of (logical) channels within a single physical jack of +# a GVI device. For most SDI video formats, there is only one channel +# (channel 0). But for 3G video formats (as specified in SMPTE 425), +# as an example, there are two channels (channel 0 and channel 1) per +# physical jack. +# + +NV_CTRL_GVI_MAX_CHANNELS_PER_JACK = 336 # R--I + +# +# NV_CTRL_GVI_MAX_STREAMS - Returns the maximum number of streams +# that can be configured on the GVI device. +# + +NV_CTRL_GVI_MAX_STREAMS = 337 # R--I + +# +# NV_CTRL_GVI_NUM_CAPTURE_SURFACES - The GVI interface exposed through +# NV-CONTROL and the GLX_NV_video_input extension uses internal capture +# surfaces when frames are read from the GVI device. The +# NV_CTRL_GVI_NUM_CAPTURE_SURFACES can be used to query and assign the +# number of capture surfaces. This attribute is applied when +# glXBindVideoCaptureDeviceNV() is called by the application. +# +# A lower number of capture surfaces will mean less video memory is used, +# but can result in frames being dropped if the application cannot keep up +# with the capture device. A higher number will prevent frames from being +# dropped, making capture more reliable but will consume move video memory. +# +NV_CTRL_GVI_NUM_CAPTURE_SURFACES = 338 # RW-I + +# +# NV_CTRL_OVERSCAN_COMPENSATION - not supported +# +NV_CTRL_OVERSCAN_COMPENSATION = 339 # not supported + +# +# NV_CTRL_GPU_PCIE_GENERATION - Reports the current PCIe generation. +# +NV_CTRL_GPU_PCIE_GENERATION = 341 # R--GI +NV_CTRL_GPU_PCIE_GENERATION1 = 0x00000001 +NV_CTRL_GPU_PCIE_GENERATION2 = 0x00000002 +NV_CTRL_GPU_PCIE_GENERATION3 = 0x00000003 + +# +# NV_CTRL_GVI_BOUND_GPU - Returns the NV_CTRL_TARGET_TYPE_GPU target_id of +# the GPU currently bound to the GVI device. Returns -1 if no GPU is +# currently bound to the GVI device. +# +NV_CTRL_GVI_BOUND_GPU = 342 # R--I + +# +# NV_CTRL_GVIO_REQUESTED_VIDEO_FORMAT3 - this attribute is only +# intended to be used to query the ValidValues for +# NV_CTRL_GVIO_REQUESTED_VIDEO_FORMAT for VIDEO_FORMAT values between +# 64 and 95. See NV_CTRL_GVIO_REQUESTED_VIDEO_FORMAT for details. +# + +NV_CTRL_GVIO_REQUESTED_VIDEO_FORMAT3 = 343 # ---GI + +# +# NV_CTRL_ACCELERATE_TRAPEZOIDS - Toggles RENDER Trapezoid acceleration +# + +NV_CTRL_ACCELERATE_TRAPEZOIDS = 344 # RW- +NV_CTRL_ACCELERATE_TRAPEZOIDS_DISABLE = 0 +NV_CTRL_ACCELERATE_TRAPEZOIDS_ENABLE = 1 + +# +# NV_CTRL_GPU_CORES - Returns number of GPU cores supported by the graphics +# pipeline. +# + +NV_CTRL_GPU_CORES = 345 # R--G + +# +# NV_CTRL_GPU_MEMORY_BUS_WIDTH - Returns memory bus bandwidth on the associated +# subdevice. +# + +NV_CTRL_GPU_MEMORY_BUS_WIDTH = 346 # R--G + +# +# NV_CTRL_GVI_TEST_MODE - This attribute controls the GVI test mode. When +# enabled, the GVI device will generate fake data as quickly as possible. All +# GVI settings are still valid when this is enabled (e.g., the requested video +# format is honored and sets the video size). +# This may be used to test the pipeline. +# + +NV_CTRL_GVI_TEST_MODE = 347 # R--I +NV_CTRL_GVI_TEST_MODE_DISABLE = 0 +NV_CTRL_GVI_TEST_MODE_ENABLE = 1 + +# +# NV_CTRL_COLOR_SPACE - This option controls the preferred color space of the +# video signal. This may not match the current color space depending on the +# current mode on this display. +# +# NV_CTRL_CURRENT_COLOR_SPACE will reflect the actual color space in use. +# +NV_CTRL_COLOR_SPACE = 348 # RWDG +NV_CTRL_COLOR_SPACE_RGB = 0 +NV_CTRL_COLOR_SPACE_YCbCr422 = 1 +NV_CTRL_COLOR_SPACE_YCbCr444 = 2 + +# +# NV_CTRL_COLOR_RANGE - This option controls the preferred color range of the +# video signal. +# +# If the current color space requires it, the actual color range will be +# limited. +# +# NV_CTRL_CURRENT_COLOR_RANGE will reflect the actual color range in use. +# +NV_CTRL_COLOR_RANGE = 349 # RWDG +NV_CTRL_COLOR_RANGE_FULL = 0 +NV_CTRL_COLOR_RANGE_LIMITED = 1 + +# +# NV_CTRL_GPU_SCALING_DEFAULT_TARGET - not supported +# + +NV_CTRL_GPU_SCALING_DEFAULT_TARGET = 350 # not supported + +# +# NV_CTRL_GPU_SCALING_DEFAULT_METHOD - not supported +# + +NV_CTRL_GPU_SCALING_DEFAULT_METHOD = 351 # not supported + +# +# NV_CTRL_DITHERING_MODE - Controls the dithering mode, when +# NV_CTRL_CURRENT_DITHERING is Enabled. +# +# AUTO: allow the driver to choose the dithering mode automatically. +# +# DYNAMIC_2X2: use a 2x2 matrix to dither from the GPU's pixel +# pipeline to the bit depth of the flat panel. The matrix values +# are changed from frame to frame. +# +# STATIC_2X2: use a 2x2 matrix to dither from the GPU's pixel +# pipeline to the bit depth of the flat panel. The matrix values +# do not change from frame to frame. +# +# TEMPORAL: use a pseudorandom value from a uniform distribution calculated at +# every pixel to achieve stochastic dithering. This method produces a better +# visual result than 2x2 matrix approaches. +# +NV_CTRL_DITHERING_MODE = 352 # RWDG +NV_CTRL_DITHERING_MODE_AUTO = 0 +NV_CTRL_DITHERING_MODE_DYNAMIC_2X2 = 1 +NV_CTRL_DITHERING_MODE_STATIC_2X2 = 2 +NV_CTRL_DITHERING_MODE_TEMPORAL = 3 + +# +# NV_CTRL_CURRENT_DITHERING - Returns the current dithering state. +# +NV_CTRL_CURRENT_DITHERING = 353 # R-DG +NV_CTRL_CURRENT_DITHERING_DISABLED = 0 +NV_CTRL_CURRENT_DITHERING_ENABLED = 1 + +# +# NV_CTRL_CURRENT_DITHERING_MODE - Returns the current dithering +# mode. +# +NV_CTRL_CURRENT_DITHERING_MODE = 354 # R-DG +NV_CTRL_CURRENT_DITHERING_MODE_NONE = 0 +NV_CTRL_CURRENT_DITHERING_MODE_DYNAMIC_2X2 = 1 +NV_CTRL_CURRENT_DITHERING_MODE_STATIC_2X2 = 2 +NV_CTRL_CURRENT_DITHERING_MODE_TEMPORAL = 3 + +# +# NV_CTRL_THERMAL_SENSOR_READING - Returns the thermal sensor's current +# reading. +# +NV_CTRL_THERMAL_SENSOR_READING = 355 # R--S + +# +# NV_CTRL_THERMAL_SENSOR_PROVIDER - Returns the hardware device that +# provides the thermal sensor. +# +NV_CTRL_THERMAL_SENSOR_PROVIDER = 356 # R--S +NV_CTRL_THERMAL_SENSOR_PROVIDER_NONE = 0 +NV_CTRL_THERMAL_SENSOR_PROVIDER_GPU_INTERNAL = 1 +NV_CTRL_THERMAL_SENSOR_PROVIDER_ADM1032 = 2 +NV_CTRL_THERMAL_SENSOR_PROVIDER_ADT7461 = 3 +NV_CTRL_THERMAL_SENSOR_PROVIDER_MAX6649 = 4 +NV_CTRL_THERMAL_SENSOR_PROVIDER_MAX1617 = 5 +NV_CTRL_THERMAL_SENSOR_PROVIDER_LM99 = 6 +NV_CTRL_THERMAL_SENSOR_PROVIDER_LM89 = 7 +NV_CTRL_THERMAL_SENSOR_PROVIDER_LM64 = 8 +NV_CTRL_THERMAL_SENSOR_PROVIDER_G781 = 9 +NV_CTRL_THERMAL_SENSOR_PROVIDER_ADT7473 = 10 +NV_CTRL_THERMAL_SENSOR_PROVIDER_SBMAX6649 = 11 +NV_CTRL_THERMAL_SENSOR_PROVIDER_VBIOSEVT = 12 +NV_CTRL_THERMAL_SENSOR_PROVIDER_OS = 13 +NV_CTRL_THERMAL_SENSOR_PROVIDER_UNKNOWN = 0xFFFFFFFF + +# +# NV_CTRL_THERMAL_SENSOR_TARGET - Returns what hardware component +# the thermal sensor is measuring. +# +NV_CTRL_THERMAL_SENSOR_TARGET = 357 # R--S +NV_CTRL_THERMAL_SENSOR_TARGET_NONE = 0 +NV_CTRL_THERMAL_SENSOR_TARGET_GPU = 1 +NV_CTRL_THERMAL_SENSOR_TARGET_MEMORY = 2 +NV_CTRL_THERMAL_SENSOR_TARGET_POWER_SUPPLY = 4 +NV_CTRL_THERMAL_SENSOR_TARGET_BOARD = 8 +NV_CTRL_THERMAL_SENSOR_TARGET_UNKNOWN = 0xFFFFFFFF + +# +# NV_CTRL_SHOW_MULTIGPU_VISUAL_INDICATOR - when TRUE, OpenGL will +# draw information about the current MULTIGPU mode. +# +NV_CTRL_SHOW_MULTIGPU_VISUAL_INDICATOR = 358 # RW-X +NV_CTRL_SHOW_MULTIGPU_VISUAL_INDICATOR_FALSE = 0 +NV_CTRL_SHOW_MULTIGPU_VISUAL_INDICATOR_TRUE = 1 + +# +# NV_CTRL_GPU_CURRENT_PROCESSOR_CLOCK_FREQS - Returns GPU's processor +# clock freqs. +# +NV_CTRL_GPU_CURRENT_PROCESSOR_CLOCK_FREQS = 359 # RW-G + +# +# NV_CTRL_GVIO_VIDEO_FORMAT_FLAGS - query the flags (various information +# for the specified NV_CTRL_GVIO_VIDEO_FORMAT_*. So that this can be +# queried with existing interfaces, the video format should be specified +# in the display_mask field; eg: +# +# XNVCTRLQueryTargetAttribute(dpy, +# NV_CTRL_TARGET_TYPE_GVI, +# gvi, +# NV_CTRL_GVIO_VIDEO_FORMAT_720P_60_00_SMPTE296, +# NV_CTRL_GVIO_VIDEO_FORMAT_FLAGS, +# &flags); +# +# Note: The NV_CTRL_GVIO_VIDEO_FORMAT_FLAGS_3G_1080P_NO_12BPC flag is set +# for those 1080P 3G modes (level A and B) that do not support +# 12 bits per component (when configuring a GVI stream.) +# + +NV_CTRL_GVIO_VIDEO_FORMAT_FLAGS = 360 # R--I +NV_CTRL_GVIO_VIDEO_FORMAT_FLAGS_NONE = 0x00000000 +NV_CTRL_GVIO_VIDEO_FORMAT_FLAGS_INTERLACED = 0x00000001 +NV_CTRL_GVIO_VIDEO_FORMAT_FLAGS_PROGRESSIVE = 0x00000002 +NV_CTRL_GVIO_VIDEO_FORMAT_FLAGS_PSF = 0x00000004 +NV_CTRL_GVIO_VIDEO_FORMAT_FLAGS_3G_LEVEL_A = 0x00000008 +NV_CTRL_GVIO_VIDEO_FORMAT_FLAGS_3G_LEVEL_B = 0x00000010 +NV_CTRL_GVIO_VIDEO_FORMAT_FLAGS_3G = NV_CTRL_GVIO_VIDEO_FORMAT_FLAGS_3G_LEVEL_A | NV_CTRL_GVIO_VIDEO_FORMAT_FLAGS_3G_LEVEL_B +NV_CTRL_GVIO_VIDEO_FORMAT_FLAGS_3G_1080P_NO_12BPC = 0x00000020 + +# +# NV_CTRL_GPU_PCIE_MAX_LINK_SPEED - returns maximum PCIe link speed, +# in gigatransfers per second (GT/s). +# + +NV_CTRL_GPU_PCIE_MAX_LINK_SPEED = 361 # R--GI + +# +# NV_CTRL_3D_VISION_PRO_RESET_TRANSCEIVER_TO_FACTORY_SETTINGS - Resets the +# 3D Vision Pro transceiver to its factory settings. +# +NV_CTRL_3D_VISION_PRO_RESET_TRANSCEIVER_TO_FACTORY_SETTINGS = 363 # -W-T + +# +# NV_CTRL_3D_VISION_PRO_TRANSCEIVER_CHANNEL - Controls the channel that is +# currently used by the 3D Vision Pro transceiver. +# +NV_CTRL_3D_VISION_PRO_TRANSCEIVER_CHANNEL = 364 # RW-T + +# +# NV_CTRL_3D_VISION_PRO_TRANSCEIVER_MODE - Controls the mode in which the +# 3D Vision Pro transceiver operates. +# NV_CTRL_3D_VISION_PRO_TM_LOW_RANGE is bidirectional +# NV_CTRL_3D_VISION_PRO_TM_MEDIUM_RANGE is bidirectional +# NV_CTRL_3D_VISION_PRO_TM_HIGH_RANGE may be bidirectional just up to a +# given range, and unidirectional beyond it +# NV_CTRL_3D_VISION_PRO_TM_COUNT is the total number of +# 3D Vision Pro transceiver modes +# +NV_CTRL_3D_VISION_PRO_TRANSCEIVER_MODE = 365 # RW-T +NV_CTRL_3D_VISION_PRO_TRANSCEIVER_MODE_INVALID = 0 +NV_CTRL_3D_VISION_PRO_TRANSCEIVER_MODE_LOW_RANGE = 1 +NV_CTRL_3D_VISION_PRO_TRANSCEIVER_MODE_MEDIUM_RANGE = 2 +NV_CTRL_3D_VISION_PRO_TRANSCEIVER_MODE_HIGH_RANGE = 3 +NV_CTRL_3D_VISION_PRO_TRANSCEIVER_MODE_COUNT = 4 + +# +# NV_CTRL_SYNCHRONOUS_PALETTE_UPDATES - controls whether updates to the color +# lookup table (LUT) are synchronous with respect to X rendering. For example, +# if an X client sends XStoreColors followed by XFillRectangle, the driver will +# guarantee that the FillRectangle request is not processed until after the +# updated LUT colors are actually visible on the screen if +# NV_CTRL_SYNCHRONOUS_PALETTE_UPDATES is enabled. Otherwise, the rendering may +# occur first. +# +# This makes a difference for applications that use the LUT to animate, such as +# XPilot. If you experience flickering in applications that use LUT +# animations, try enabling this attribute. +# +# When synchronous updates are enabled, XStoreColors requests will be processed +# at your screen's refresh rate. +# + +NV_CTRL_SYNCHRONOUS_PALETTE_UPDATES = 367 # RWDG +NV_CTRL_SYNCHRONOUS_PALETTE_UPDATES_DISABLE = 0 +NV_CTRL_SYNCHRONOUS_PALETTE_UPDATES_ENABLE = 1 + +# +# NV_CTRL_DITHERING_DEPTH - Controls the dithering depth when +# NV_CTRL_CURRENT_DITHERING is ENABLED. Some displays connected +# to the GPU via the DVI or LVDS interfaces cannot display the +# full color range of ten bits per channel, so the GPU will +# dither to either 6 or 8 bits per channel. +# +NV_CTRL_DITHERING_DEPTH = 368 # RWDG +NV_CTRL_DITHERING_DEPTH_AUTO = 0 +NV_CTRL_DITHERING_DEPTH_6_BITS = 1 +NV_CTRL_DITHERING_DEPTH_8_BITS = 2 + +# +# NV_CTRL_CURRENT_DITHERING_DEPTH - Returns the current dithering +# depth value. +# +NV_CTRL_CURRENT_DITHERING_DEPTH = 369 # R-DG +NV_CTRL_CURRENT_DITHERING_DEPTH_NONE = 0 +NV_CTRL_CURRENT_DITHERING_DEPTH_6_BITS = 1 +NV_CTRL_CURRENT_DITHERING_DEPTH_8_BITS = 2 + +# +# NV_CTRL_3D_VISION_PRO_TRANSCEIVER_CHANNEL_FREQUENCY - Returns the +# frequency of the channel(in kHz) of the 3D Vision Pro transceiver. +# Use the display_mask parameter to specify the channel number. +# +NV_CTRL_3D_VISION_PRO_TRANSCEIVER_CHANNEL_FREQUENCY = 370 # R--T + +# +# NV_CTRL_3D_VISION_PRO_TRANSCEIVER_CHANNEL_QUALITY - Returns the +# quality of the channel(in percentage) of the 3D Vision Pro transceiver. +# Use the display_mask parameter to specify the channel number. +# +NV_CTRL_3D_VISION_PRO_TRANSCEIVER_CHANNEL_QUALITY = 371 # R--T + +# +# NV_CTRL_3D_VISION_PRO_TRANSCEIVER_CHANNEL_COUNT - Returns the number of +# channels on the 3D Vision Pro transceiver. +# +NV_CTRL_3D_VISION_PRO_TRANSCEIVER_CHANNEL_COUNT = 372 # R--T + +# +# NV_CTRL_3D_VISION_PRO_PAIR_GLASSES - Puts the 3D Vision Pro +# transceiver into pairing mode to gather additional glasses. +# NV_CTRL_3D_VISION_PRO_PAIR_GLASSES_STOP - stops any pairing +# NV_CTRL_3D_VISION_PRO_PAIR_GLASSES_BEACON - starts continuous +# pairing via beacon mode +# Any other value, N - Puts the 3D Vision Pro transceiver into +# authenticated pairing mode for N seconds. +# +NV_CTRL_3D_VISION_PRO_PAIR_GLASSES = 373 # -W-T +NV_CTRL_3D_VISION_PRO_PAIR_GLASSES_STOP = 0 +NV_CTRL_3D_VISION_PRO_PAIR_GLASSES_BEACON = 0xFFFFFFFF + +# +# NV_CTRL_3D_VISION_PRO_UNPAIR_GLASSES - Tells a specific pair +# of glasses to unpair. The glasses will "forget" the address +# of the 3D Vision Pro transceiver to which they have been paired. +# To unpair all the currently paired glasses, specify +# the glasses id as 0. +# +NV_CTRL_3D_VISION_PRO_UNPAIR_GLASSES = 374 # -W-T + +# +# NV_CTRL_3D_VISION_PRO_DISCOVER_GLASSES - Tells the 3D Vision Pro +# transceiver about the glasses that have been paired using +# NV_CTRL_3D_VISION_PRO_PAIR_GLASSES_BEACON. Unless this is done, +# the 3D Vision Pro transceiver will not know about glasses paired in +# beacon mode. +# +NV_CTRL_3D_VISION_PRO_DISCOVER_GLASSES = 375 # -W-T + +# +# NV_CTRL_3D_VISION_PRO_IDENTIFY_GLASSES - Causes glasses LEDs to +# flash for a short period of time. +# +NV_CTRL_3D_VISION_PRO_IDENTIFY_GLASSES = 376 # -W-T + +# +# NV_CTRL_3D_VISION_PRO_GLASSES_SYNC_CYCLE - Controls the +# sync cycle duration(in milliseconds) of the glasses. +# Use the display_mask parameter to specify the glasses id. +# +NV_CTRL_3D_VISION_PRO_GLASSES_SYNC_CYCLE = 378 # RW-T + +# +# NV_CTRL_3D_VISION_PRO_GLASSES_MISSED_SYNC_CYCLES - Returns the +# number of state sync cycles recently missed by the glasses. +# Use the display_mask parameter to specify the glasses id. +# +NV_CTRL_3D_VISION_PRO_GLASSES_MISSED_SYNC_CYCLES = 379 # R--T + +# +# NV_CTRL_3D_VISION_PRO_GLASSES_BATTERY_LEVEL - Returns the +# battery level(in percentage) of the glasses. +# Use the display_mask parameter to specify the glasses id. +# +NV_CTRL_3D_VISION_PRO_GLASSES_BATTERY_LEVEL = 380 # R--T + +# +# NV_CTRL_GVO_ANC_PARITY_COMPUTATION - Controls the SDI device's computation +# of the parity bit (bit 8) for ANC data words. +# + +NV_CTRL_GVO_ANC_PARITY_COMPUTATION = 381 # RW--- +NV_CTRL_GVO_ANC_PARITY_COMPUTATION_AUTO = 0 +NV_CTRL_GVO_ANC_PARITY_COMPUTATION_ON = 1 +NV_CTRL_GVO_ANC_PARITY_COMPUTATION_OFF = 2 + +# +# NV_CTRL_3D_VISION_PRO_GLASSES_PAIR_EVENT - This attribute is sent +# as an event when glasses get paired in response to pair command +# from any of the clients. +# +NV_CTRL_3D_VISION_PRO_GLASSES_PAIR_EVENT = 382 # ---T + +# +# NV_CTRL_3D_VISION_PRO_GLASSES_UNPAIR_EVENT - This attribute is sent +# as an event when glasses get unpaired in response to unpair command +# from any of the clients. +# +NV_CTRL_3D_VISION_PRO_GLASSES_UNPAIR_EVENT = 383 # ---T + +# +# NV_CTRL_GPU_PCIE_CURRENT_LINK_WIDTH - returns the current +# PCIe link width, in number of lanes. +# +NV_CTRL_GPU_PCIE_CURRENT_LINK_WIDTH = 384 # R--GI + +# +# NV_CTRL_GPU_PCIE_CURRENT_LINK_SPEED - returns the current +# PCIe link speed, in megatransfers per second (GT/s). +# +NV_CTRL_GPU_PCIE_CURRENT_LINK_SPEED = 385 # R--GI + +# +# NV_CTRL_GVO_AUDIO_BLANKING - specifies whether the GVO device should delete +# audio ancillary data packets when frames are repeated. +# +# When a new frame is not ready in time, the current frame, including all +# ancillary data packets, is repeated. When this data includes audio packets, +# this can result in stutters or clicks. When this option is enabled, the GVO +# device will detect when frames are repeated, identify audio ancillary data +# packets, and mark them for deletion. +# +# This option is applied when the GVO device is bound. +# +NV_CTRL_GVO_AUDIO_BLANKING = 386 # RW- +NV_CTRL_GVO_AUDIO_BLANKING_DISABLE = 0 +NV_CTRL_GVO_AUDIO_BLANKING_ENABLE = 1 + +# +# NV_CTRL_CURRENT_METAMODE_ID - switch modes to the MetaMode with +# the specified ID. +# +NV_CTRL_CURRENT_METAMODE_ID = 387 # RW- + +# +# NV_CTRL_DISPLAY_ENABLED - Returns whether or not the display device +# is currently enabled. +# +NV_CTRL_DISPLAY_ENABLED = 388 # R-D +NV_CTRL_DISPLAY_ENABLED_TRUE = 1 +NV_CTRL_DISPLAY_ENABLED_FALSE = 0 + +# +# NV_CTRL_FRAMELOCK_INCOMING_HOUSE_SYNC_RATE: this is the rate +# of an incomming house sync signal to the frame lock board, in milliHz. +# +# This attribute may be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_FRAMELOCK or NV_CTRL_TARGET_TYPE_X_SCREEN +# target. +# +NV_CTRL_FRAMELOCK_INCOMING_HOUSE_SYNC_RATE = 389 # R--F + +# +# NV_CTRL_FXAA - enables FXAA. A pixel shader based anti- +# aliasing method. +# +NV_CTRL_FXAA = 390 # RW-X +NV_CTRL_FXAA_DISABLE = 0 +NV_CTRL_FXAA_ENABLE = 1 + +# +# NV_CTRL_DISPLAY_RANDR_OUTPUT_ID - the RandR Output ID (type RROutput) +# that corresponds to the specified Display Device target. If a new +# enough version of RandR is not available in the X server, +# DISPLAY_RANDR_OUTPUT_ID will be 0. +# +NV_CTRL_DISPLAY_RANDR_OUTPUT_ID = 391 # R-D- + +# +# NV_CTRL_FRAMELOCK_DISPLAY_CONFIG - Configures whether the display device +# should listen, ignore or drive the framelock sync signal. +# +# Note that whether or not a display device may be set as a client/server +# depends on the current configuration. For example, only one server may be +# set per Quadro Sync device, and displays can only be configured as a client +# if their refresh rate sufficiently matches the refresh rate of the server +# device. +# +# Note that when querying the ValidValues for this data type, the values are +# reported as bits within a bitmask (ATTRIBUTE_TYPE_INT_BITS); +# +NV_CTRL_FRAMELOCK_DISPLAY_CONFIG = 392 # RWD +NV_CTRL_FRAMELOCK_DISPLAY_CONFIG_DISABLED = 0 +NV_CTRL_FRAMELOCK_DISPLAY_CONFIG_CLIENT = 1 +NV_CTRL_FRAMELOCK_DISPLAY_CONFIG_SERVER = 2 + +# +# NV_CTRL_TOTAL_DEDICATED_GPU_MEMORY - Returns the total amount of dedicated +# GPU video memory, in MB, on the specified GPU. This excludes any TurboCache +# padding included in the value returned by NV_CTRL_TOTAL_GPU_MEMORY. +# +NV_CTRL_TOTAL_DEDICATED_GPU_MEMORY = 393 # R--G + +# +# NV_CTRL_USED_DEDICATED_GPU_MEMORY- Returns the amount of video memory +# currently used on the graphics card in MB. +# +NV_CTRL_USED_DEDICATED_GPU_MEMORY = 394 # R--G + +# +# NV_CTRL_GPU_DOUBLE_PRECISION_BOOST_IMMEDIATE +# Some GPUs can make a tradeoff between double-precision floating-point +# performance and clock speed. Enabling double-precision floating point +# performance may benefit CUDA or OpenGL applications that require high +# bandwidth double-precision performance. Disabling this feature may benefit +# graphics applications that require higher clock speeds. +# +# This attribute is only available when toggling double precision boost +# can be done immediately (without need for a rebooot). +# +NV_CTRL_GPU_DOUBLE_PRECISION_BOOST_IMMEDIATE = 395 # RW-G +NV_CTRL_GPU_DOUBLE_PRECISION_BOOST_IMMEDIATE_DISABLED = 0 +NV_CTRL_GPU_DOUBLE_PRECISION_BOOST_IMMEDIATE_ENABLED = 1 + +# +# NV_CTRL_GPU_DOUBLE_PRECISION_BOOST_REBOOT +# Some GPUs can make a tradeoff between double-precision floating-point +# performance and clock speed. Enabling double-precision floating point +# performance may benefit CUDA or OpenGL applications that require high +# bandwidth double-precision performance. Disabling this feature may benefit +# graphics applications that require higher clock speeds. +# +# This attribute is only available when toggling double precision boost +# requires a reboot. +# + +NV_CTRL_GPU_DOUBLE_PRECISION_BOOST_REBOOT = 396 # RW-G +NV_CTRL_GPU_DOUBLE_PRECISION_BOOST_REBOOT_DISABLED = 0 +NV_CTRL_GPU_DOUBLE_PRECISION_BOOST_REBOOT_ENALED = 1 + +# +# NV_CTRL_DPY_HDMI_3D - Returns whether the specified display device is +# currently using HDMI 3D Frame Packed Stereo mode. Clients may use this +# to help interpret the refresh rate returned by NV_CTRL_REFRESH_RATE or +# NV_CTRL_REFRESH_RATE_3, which will be doubled when using HDMI 3D mode. +# +# This attribute may be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_GPU target. +# + +NV_CTRL_DPY_HDMI_3D = 397 # R-DG +NV_CTRL_DPY_HDMI_3D_DISABLED = 0 +NV_CTRL_DPY_HDMI_3D_ENABLED = 1 + +# +# NV_CTRL_BASE_MOSAIC - Returns whether Base Mosaic is currently enabled on the +# given GPU. Querying the valid values of this attribute returns capabilities. +# + +NV_CTRL_BASE_MOSAIC = 398 # R--G +NV_CTRL_BASE_MOSAIC_DISABLED = 0 +NV_CTRL_BASE_MOSAIC_FULL = 1 +NV_CTRL_BASE_MOSAIC_LIMITED = 2 + +# +# NV_CTRL_MULTIGPU_MASTER_POSSIBLE - Returns whether the GPU can be configured +# as the master GPU in a Multi GPU configuration (SLI, SLI Mosaic, +# Base Mosaic). +# + +NV_CTRL_MULTIGPU_MASTER_POSSIBLE = 399 # R--G +NV_CTRL_MULTIGPU_MASTER_POSSIBLE_FALSE = 0 +NV_CTRL_MULTIGPU_MASTER_POSSIBLE_TRUE = 1 + +# +# NV_CTRL_GPU_POWER_MIZER_DEFAULT_MODE - Returns the default PowerMizer mode +# for the given GPU. +# +NV_CTRL_GPU_POWER_MIZER_DEFAULT_MODE = 400 # R--G + +# +# NV_CTRL_XV_SYNC_TO_DISPLAY_ID - When XVideo Sync To VBlank is enabled, this +# controls which display device will be synched to if the display is enabled. +# Returns NV_CTRL_XV_SYNC_TO_DISPLAY_ID_AUTO if no display has been +# selected. +# +NV_CTRL_XV_SYNC_TO_DISPLAY_ID = 401 # RW- +NV_CTRL_XV_SYNC_TO_DISPLAY_ID_AUTO = 0xFFFFFFFF + +# +# NV_CTRL_BACKLIGHT_BRIGHTNESS - The backlight brightness of an internal panel. +# +NV_CTRL_BACKLIGHT_BRIGHTNESS = 402 # RWD- + +# +# NV_CTRL_GPU_LOGO_BRIGHTNESS - Controls brightness +# of the logo on the GPU, if any. The value is variable from 0% - 100%. +# +NV_CTRL_GPU_LOGO_BRIGHTNESS = 403 # RW-G + +# +# NV_CTRL_GPU_SLI_LOGO_BRIGHTNESS - Controls brightness of the logo +# on the SLI bridge, if any. The value is variable from 0% - 100%. +# +NV_CTRL_GPU_SLI_LOGO_BRIGHTNESS = 404 # RW-G + +# +# NV_CTRL_THERMAL_COOLER_SPEED - Returns cooler's current operating speed in +# rotations per minute (RPM). +# + +NV_CTRL_THERMAL_COOLER_SPEED = 405 # R--C + +# +# NV_CTRL_PALETTE_UPDATE_EVENT - The Color Palette has been changed and the +# color correction info needs to be updated. +# + +NV_CTRL_PALETTE_UPDATE_EVENT = 406 # --- + +# +# NV_CTRL_VIDEO_ENCODER_UTILIZATION - Returns the video encoder engine +# utilization as a percentage. +# +NV_CTRL_VIDEO_ENCODER_UTILIZATION = 407 # R--G + +# +# NV_CTRL_GSYNC_ALLOWED - when TRUE, OpenGL will enable G-SYNC when possible; +# when FALSE, OpenGL will always use a fixed monitor refresh rate. +# + +NV_CTRL_GSYNC_ALLOWED = 408 # RW-X +NV_CTRL_GSYNC_ALLOWED_FALSE = 0 +NV_CTRL_GSYNC_ALLOWED_TRUE = 1 + +# +# NV_CTRL_GPU_NVCLOCK_OFFSET - This attribute controls the GPU clock offsets +# (in MHz) used for overclocking per performance level. +# Use the display_mask parameter to specify the performance level. +# +# Note: To enable overclocking support, set the X configuration +# option "Coolbits" to value "8". +# +# This offset can have any integer value between +# NVCTRLAttributeValidValues.u.range.min and +# NVCTRLAttributeValidValues.u.range.max (inclusive). +# +# This attribute is available on GeForce GTX 400 series and later +# Geforce GPUs. +# +NV_CTRL_GPU_NVCLOCK_OFFSET = 409 # RW-G + +# +# NV_CTRL_GPU_MEM_TRANSFER_RATE_OFFSET - This attribute controls +# the memory transfer rate offsets (in MHz) used for overclocking +# per performance level. +# Use the display_mask parameter to specify the performance level. +# +# Note: To enable overclocking support, set the X configuration +# option "Coolbits" to value "8". +# +# This offset can have any integer value between +# NVCTRLAttributeValidValues.u.range.min and +# NVCTRLAttributeValidValues.u.range.max (inclusive). +# +# This attribute is available on GeForce GTX 400 series and later +# Geforce GPUs. +# +NV_CTRL_GPU_MEM_TRANSFER_RATE_OFFSET = 410 # RW-G + +# +# NV_CTRL_VIDEO_DECODER_UTILIZATION - Returns the video decoder engine +# utilization as a percentage. +# +NV_CTRL_VIDEO_DECODER_UTILIZATION = 411 # R--G + +# +# NV_CTRL_GPU_OVER_VOLTAGE_OFFSET - This attribute controls +# the overvoltage offset in microvolts (uV). +# +# Note: To enable overvoltage support, set the X configuration +# option "Coolbits" to value "16". +# +# This offset can have any integer value between +# NVCTRLAttributeValidValues.u.range.min and +# NVCTRLAttributeValidValues.u.range.max (inclusive). +# +# This attribute is available on GeForce GTX 400 series and later +# Geforce GPUs. +# + +NV_CTRL_GPU_OVER_VOLTAGE_OFFSET = 412 # RW-G + +# +# NV_CTRL_GPU_CURRENT_CORE_VOLTAGE - This attribute returns the +# GPU's current operating voltage in microvolts (uV). +# +# This attribute is available on GPUs that support +# NV_CTRL_GPU_OVER_VOLTAGE_OFFSET. +# +NV_CTRL_GPU_CURRENT_CORE_VOLTAGE = 413 # R--G + +# +# NV_CTRL_CURRENT_COLOR_SPACE - Returns the current color space of the video +# signal. +# +# This will match NV_CTRL_COLOR_SPACE unless the current mode on this display +# device is an HDMI 2.0 4K@60Hz mode and the display device or GPU does not +# support driving this mode in RGB, in which case YCbCr420 will be returned. +# +NV_CTRL_CURRENT_COLOR_SPACE = 414 # R-DG +NV_CTRL_CURRENT_COLOR_SPACE_RGB = 0 +NV_CTRL_CURRENT_COLOR_SPACE_YCbCr422 = 1 +NV_CTRL_CURRENT_COLOR_SPACE_YCbCr444 = 2 +NV_CTRL_CURRENT_COLOR_SPACE_YCbCr420 = 3 + +# +# NV_CTRL_CURRENT_COLOR_RANGE - Returns the current color range of the video +# signal. +# +NV_CTRL_CURRENT_COLOR_RANGE = 415 # R-DG +NV_CTRL_CURRENT_COLOR_RANGE_FULL = 0 +NV_CTRL_CURRENT_COLOR_RANGE_LIMITED = 1 + +# +# NV_CTRL_SHOW_GSYNC_VISUAL_INDICATOR - when TRUE, OpenGL will indicate when +# G-SYNC is in use for full-screen applications. +# + +NV_CTRL_SHOW_GSYNC_VISUAL_INDICATOR = 416 # RW-X +NV_CTRL_SHOW_GSYNC_VISUAL_INDICATOR_FALSE = 0 +NV_CTRL_SHOW_GSYNC_VISUAL_INDICATOR_TRUE = 1 + +# +# NV_CTRL_THERMAL_COOLER_CURRENT_LEVEL - Returns cooler's current +# operating level. This may fluctuate dynamically. When +# NV_CTRL_GPU_COOLER_MANUAL_CONTROL=TRUE, the driver attempts +# to make this match NV_CTRL_THERMAL_COOLER_LEVEL. When +# NV_CTRL_GPU_COOLER_MANUAL_CONTROL=FALSE, the driver adjusts the +# current level based on the needs of the GPU. +# + +NV_CTRL_THERMAL_COOLER_CURRENT_LEVEL = 417 # R--C + +# +# NV_CTRL_STEREO_SWAP_MODE - This attribute controls the swap mode when +# Quad-Buffered stereo is used. +# NV_CTRL_STEREO_SWAP_MODE_APPLICATION_CONTROL : Stereo swap mode is derived +# from the value of swap interval. +# If it's odd, the per eye swap mode is used. +# If it's even, the per eye pair swap mode is used. +# NV_CTRL_STEREO_SWAP_MODE_PER_EYE : The driver swaps each eye as it is ready. +# NV_CTRL_STEREO_SWAP_MODE_PER_EYE_PAIR : The driver waits for both eyes to +# complete rendering before swapping. +# + +NV_CTRL_STEREO_SWAP_MODE = 418 # RW-X +NV_CTRL_STEREO_SWAP_MODE_APPLICATION_CONTROL = 0 +NV_CTRL_STEREO_SWAP_MODE_PER_EYE = 1 +NV_CTRL_STEREO_SWAP_MODE_PER_EYE_PAIR = 2 + +# +# NV_CTRL_CURRENT_XV_SYNC_TO_DISPLAY_ID - When XVideo Sync To VBlank is +# enabled, this returns the display id of the device currently synched to. +# Returns NV_CTRL_XV_SYNC_TO_DISPLAY_ID_AUTO if no display is currently +# set. +# + +NV_CTRL_CURRENT_XV_SYNC_TO_DISPLAY_ID = 419 # R-- + +# +# NV_CTRL_GPU_FRAMELOCK_FIRMWARE_UNSUPPORTED - Returns true if the +# Quadro Sync card connected to this GPU has a firmware version incompatible +# with this GPU. +# + +NV_CTRL_GPU_FRAMELOCK_FIRMWARE_UNSUPPORTED = 420 # R--G +NV_CTRL_GPU_FRAMELOCK_FIRMWARE_UNSUPPORTED_FALSE = 0 +NV_CTRL_GPU_FRAMELOCK_FIRMWARE_UNSUPPORTED_TRUE = 1 + +# +# NV_CTRL_DISPLAYPORT_CONNECTOR_TYPE - Returns the connector type used by +# a DisplayPort display. +# + +NV_CTRL_DISPLAYPORT_CONNECTOR_TYPE = 421 # R-DG +NV_CTRL_DISPLAYPORT_CONNECTOR_TYPE_UNKNOWN = 0 +NV_CTRL_DISPLAYPORT_CONNECTOR_TYPE_DISPLAYPORT = 1 +NV_CTRL_DISPLAYPORT_CONNECTOR_TYPE_HDMI = 2 +NV_CTRL_DISPLAYPORT_CONNECTOR_TYPE_DVI = 3 +NV_CTRL_DISPLAYPORT_CONNECTOR_TYPE_VGA = 4 + +# +# NV_CTRL_DISPLAYPORT_IS_MULTISTREAM - Returns multi-stream support for +# DisplayPort displays. +# +NV_CTRL_DISPLAYPORT_IS_MULTISTREAM = 422 # R-DG + +# +# NV_CTRL_DISPLAYPORT_SINK_IS_AUDIO_CAPABLE - Returns whether a DisplayPort +# device supports audio. +# +NV_CTRL_DISPLAYPORT_SINK_IS_AUDIO_CAPABLE = 423 # R-DG + +# +# NV_CTRL_GPU_NVCLOCK_OFFSET_ALL_PERFORMANCE_LEVELS - This attribute +# controls the GPU clock offsets (in MHz) used for overclocking. +# The offset is applied to all performance levels. +# +# Note: To enable overclocking support, set the X configuration +# option "Coolbits" to value "8". +# +# This offset can have any integer value between +# NVCTRLAttributeValidValues.u.range.min and +# NVCTRLAttributeValidValues.u.range.max (inclusive). +# +# This attribute is available on GeForce GTX 1000 series and later +# Geforce GPUs. +# +NV_CTRL_GPU_NVCLOCK_OFFSET_ALL_PERFORMANCE_LEVELS = 424 # RW-G + +# +# NV_CTRL_GPU_MEM_TRANSFER_RATE_OFFSET_ALL_PERFORMANCE_LEVELS - This +# attribute controls the memory transfer rate offsets (in MHz) used +# for overclocking. The offset is applied to all performance levels. +# +# Note: To enable overclocking support, set the X configuration +# option "Coolbits" to value "8". +# +# This offset can have any integer value between +# NVCTRLAttributeValidValues.u.range.min and +# NVCTRLAttributeValidValues.u.range.max (inclusive). +# +# This attribute is available on GeForce GTX 1000 series and later +# Geforce GPUs. +# +NV_CTRL_GPU_MEM_TRANSFER_RATE_OFFSET_ALL_PERFORMANCE_LEVELS = 425 # RW-G + +# +# NV_CTRL_FRAMELOCK_FIRMWARE_VERSION - Queries the firmware major version of +# the Frame Lock device. +# +# This attribute must be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_FRAMELOCK target. +# + +NV_CTRL_FRAMELOCK_FIRMWARE_VERSION = 426 # R--F + +# +# NV_CTRL_FRAMELOCK_FIRMWARE_MINOR_VERSION - Queries the firmware minor +# version of the Frame Lock device. +# +# This attribute must be queried through XNVCTRLQueryTargetAttribute() +# using a NV_CTRL_TARGET_TYPE_FRAMELOCK target. +# + +NV_CTRL_FRAMELOCK_FIRMWARE_MINOR_VERSION = 427 # R--F + +# +# NV_CTRL_SHOW_GRAPHICS_VISUAL_INDICATOR - when TRUE, graphics APIs will +# indicate various runtime information such as flip/blit, vsync status, API +# in use. +# + +NV_CTRL_SHOW_GRAPHICS_VISUAL_INDICATOR = 428 # RW-X +NV_CTRL_SHOW_GRAPHICS_VISUAL_INDICATOR_FALSE = 0 +NV_CTRL_SHOW_GRAPHICS_VISUAL_INDICATOR_TRUE = 1 + +NV_CTRL_LAST_ATTRIBUTE = NV_CTRL_SHOW_GRAPHICS_VISUAL_INDICATOR + +############################################################################ + +# +# String Attributes: +# +# String attributes can be queryied through the XNVCTRLQueryStringAttribute() +# and XNVCTRLQueryTargetStringAttribute() function calls. +# +# String attributes can be set through the XNVCTRLSetStringAttribute() +# function call. (There are currently no string attributes that can be +# set on non-X Screen targets.) +# +# Unless otherwise noted, all string attributes can be queried/set using an +# NV_CTRL_TARGET_TYPE_X_SCREEN target. Attributes that cannot take an +# NV_CTRL_TARGET_TYPE_X_SCREEN target also cannot be queried/set through +# XNVCTRLQueryStringAttribute()/XNVCTRLSetStringAttribute() (Since +# these assume an X Screen target). +# + + +# +# NV_CTRL_STRING_PRODUCT_NAME - the product name on which the +# specified X screen is running, or the product name of the specified +# Frame Lock device. +# +# This attribute may be queried through XNVCTRLQueryTargetStringAttribute() +# using a NV_CTRL_TARGET_TYPE_GPU or NV_CTRL_TARGET_TYPE_X_SCREEN target to +# return the product name of the GPU, or a NV_CTRL_TARGET_TYPE_FRAMELOCK to +# return the product name of the Frame Lock device. +# + +NV_CTRL_STRING_PRODUCT_NAME = 0 # R--GF + +# +# NV_CTRL_STRING_VBIOS_VERSION - the video bios version on the GPU on +# which the specified X screen is running. +# + +NV_CTRL_STRING_VBIOS_VERSION = 1 # R--G + +# +# NV_CTRL_STRING_NVIDIA_DRIVER_VERSION - string representation of the +# NVIDIA driver version number for the NVIDIA X driver in use. +# + +NV_CTRL_STRING_NVIDIA_DRIVER_VERSION = 3 # R--G + +# +# NV_CTRL_STRING_DISPLAY_DEVICE_NAME - name of the display device +# specified in the display_mask argument. +# +# This attribute may be queried through XNVCTRLQueryTargetStringAttribute() +# using a NV_CTRL_TARGET_TYPE_GPU or NV_CTRL_TARGET_TYPE_X_SCREEN target. +# + +NV_CTRL_STRING_DISPLAY_DEVICE_NAME = 4 # R-DG + +# +# NV_CTRL_STRING_TV_ENCODER_NAME - not supported +# + +NV_CTRL_STRING_TV_ENCODER_NAME = 5 # not supported + +# +# NV_CTRL_STRING_GVIO_FIRMWARE_VERSION - indicates the version of the +# Firmware on the GVIO device. +# + +NV_CTRL_STRING_GVIO_FIRMWARE_VERSION = 8 # R--I + +# +# NV_CTRL_STRING_GVO_FIRMWARE_VERSION - renamed +# +# NV_CTRL_STRING_GVIO_FIRMWARE_VERSION should be used instead. +# +NV_CTRL_STRING_GVO_FIRMWARE_VERSION = 8 # renamed + +# +# NV_CTRL_STRING_CURRENT_MODELINE - Return the ModeLine currently +# being used by the specified display device. +# +# This attribute may be queried through XNVCTRLQueryTargetStringAttribute() +# using an NV_CTRL_TARGET_TYPE_GPU or NV_CTRL_TARGET_TYPE_X_SCREEN target. +# +# The ModeLine string may be prepended with a comma-separated list of +# "token=value" pairs, separated from the ModeLine string by "::". +# This "token=value" syntax is the same as that used in +# NV_CTRL_BINARY_DATA_MODELINES +# + +NV_CTRL_STRING_CURRENT_MODELINE = 9 # R-DG + +# +# NV_CTRL_STRING_ADD_MODELINE - Adds a ModeLine to the specified +# display device. The ModeLine is not added if validation fails. +# +# The ModeLine string should have the same syntax as a ModeLine in +# the X configuration file; e.g., +# +# "1600x1200" 229.5 1600 1664 1856 2160 1200 1201 1204 1250 +HSync +VSync +# + +NV_CTRL_STRING_ADD_MODELINE = 10 # -WDG + +# +# NV_CTRL_STRING_DELETE_MODELINE - Deletes an existing ModeLine +# from the specified display device. The currently selected +# ModeLine cannot be deleted. (This also means you cannot delete +# the last ModeLine.) +# +# The ModeLine string should have the same syntax as a ModeLine in +# the X configuration file; e.g., +# +# "1600x1200" 229.5 1600 1664 1856 2160 1200 1201 1204 1250 +HSync +VSync +# + +NV_CTRL_STRING_DELETE_MODELINE = 11 # -WDG + +# +# NV_CTRL_STRING_CURRENT_METAMODE - Returns the metamode currently +# being used by the specified X screen. The MetaMode string has the +# same syntax as the MetaMode X configuration option, as documented +# in the NVIDIA driver README. +# +# The returned string may be prepended with a comma-separated list of +# "token=value" pairs, separated from the MetaMode string by "::". +# This "token=value" syntax is the same as that used in +# NV_CTRL_BINARY_DATA_METAMODES. +# + +NV_CTRL_STRING_CURRENT_METAMODE = 12 # RW-- +NV_CTRL_STRING_CURRENT_METAMODE_VERSION_1 = NV_CTRL_STRING_CURRENT_METAMODE + +# +# NV_CTRL_STRING_ADD_METAMODE - Adds a MetaMode to the specified +# X Screen. +# +# It is recommended to not use this attribute, but instead use +# NV_CTRL_STRING_OPERATION_ADD_METAMODE. +# + +NV_CTRL_STRING_ADD_METAMODE = 13 # -W-- + +# +# NV_CTRL_STRING_DELETE_METAMODE - Deletes an existing MetaMode from +# the specified X Screen. The currently selected MetaMode cannot be +# deleted. (This also means you cannot delete the last MetaMode). +# The MetaMode string should have the same syntax as the MetaMode X +# configuration option, as documented in the NVIDIA driver README. +# + +NV_CTRL_STRING_DELETE_METAMODE = 14 # -WD-- + +# +# NV_CTRL_STRING_VCSC_PRODUCT_NAME - deprecated +# +# Queries the product name of the VCSC device. +# +# This attribute must be queried through XNVCTRLQueryTargetStringAttribute() +# using a NV_CTRL_TARGET_TYPE_VCSC target. +# + +NV_CTRL_STRING_VCSC_PRODUCT_NAME = 15 # R---V + +# +# NV_CTRL_STRING_VCSC_PRODUCT_ID - deprecated +# +# Queries the product ID of the VCSC device. +# +# This attribute must be queried through XNVCTRLQueryTargetStringAttribute() +# using a NV_CTRL_TARGET_TYPE_VCSC target. +# + +NV_CTRL_STRING_VCSC_PRODUCT_ID = 16 # R---V + +# +# NV_CTRL_STRING_VCSC_SERIAL_NUMBER - deprecated +# +# Queries the unique serial number of the VCS device. +# +# This attribute must be queried through XNVCTRLQueryTargetStringAttribute() +# using a NV_CTRL_TARGET_TYPE_VCSC target. +# + +NV_CTRL_STRING_VCSC_SERIAL_NUMBER = 17 # R---V + +# +# NV_CTRL_STRING_VCSC_BUILD_DATE - deprecated +# +# Queries the date of the VCS device. the returned string is in the following +# format: "Week.Year" +# +# This attribute must be queried through XNVCTRLQueryTargetStringAttribute() +# using a NV_CTRL_TARGET_TYPE_VCSC target. +# + +NV_CTRL_STRING_VCSC_BUILD_DATE = 18 # R---V + +# +# NV_CTRL_STRING_VCSC_FIRMWARE_VERSION - deprecated +# +# Queries the firmware version of the VCS device. +# +# This attribute must be queried through XNVCTRLQueryTargetStringAttribute() +# using a NV_CTRL_TARGET_TYPE_VCSC target. +# + +NV_CTRL_STRING_VCSC_FIRMWARE_VERSION = 19 # R---V + +# +# NV_CTRL_STRING_VCSC_FIRMWARE_REVISION - deprecated +# +# Queries the firmware revision of the VCS device. +# +# This attribute must be queried through XNVCTRLQueryTargetStringAttribute() +# using a NV_CTRL_TARGET_TYPE_VCS target. +# + +NV_CTRL_STRING_VCSC_FIRMWARE_REVISION = 20 # R---V + +# +# NV_CTRL_STRING_VCSC_HARDWARE_VERSION - deprecated +# +# Queries the hardware version of the VCS device. +# +# This attribute must be queried through XNVCTRLQueryTargetStringAttribute() +# using a NV_CTRL_TARGET_TYPE_VCSC target. +# + +NV_CTRL_STRING_VCSC_HARDWARE_VERSION = 21 # R---V + +# +# NV_CTRL_STRING_VCSC_HARDWARE_REVISION - deprecated +# +# Queries the hardware revision of the VCS device. +# +# This attribute must be queried through XNVCTRLQueryTargetStringAttribute() +# using a NV_CTRL_TARGET_TYPE_VCSC target. +# + +NV_CTRL_STRING_VCSC_HARDWARE_REVISION = 22 # R---V + +# +# NV_CTRL_STRING_MOVE_METAMODE - Moves a MetaMode to the specified +# index location. The MetaMode must already exist in the X Screen's +# list of MetaModes (as returned by the NV_CTRL_BINARY_DATA_METAMODES +# attribute). If the index is larger than the number of MetaModes in +# the list, the MetaMode is moved to the end of the list. The +# MetaMode string should have the same syntax as the MetaMode X +# configuration option, as documented in the NVIDIA driver README. + +# The MetaMode string must be prepended with a comma-separated list +# of "token=value" pairs, separated from the MetaMode string by "::". +# Currently, the only valid token is "index", which indicates where +# in the MetaMode list the MetaMode should be moved to. +# +# Other tokens may be added in the future. +# +# E.g., +# "index=5 :: CRT-0: 1024x768 @1024x768 +0+0" +# + +NV_CTRL_STRING_MOVE_METAMODE = 23 # -W-- + +# +# NV_CTRL_STRING_VALID_HORIZ_SYNC_RANGES - returns the valid +# horizontal sync ranges used to perform mode validation for the +# specified display device. The ranges are in the same format as the +# "HorizSync" X config option: +# +# "horizsync-range may be a comma separated list of either discrete +# values or ranges of values. A range of values is two values +# separated by a dash." +# +# The values are in kHz. +# +# Additionally, the string may be prepended with a comma-separated +# list of "token=value" pairs, separated from the HorizSync string by +# "::". Valid tokens: +# +# Token Value +# "source" "edid" - HorizSync is from the display device's EDID +# "xconfig" - HorizSync is from the "HorizSync" entry in +# the Monitor section of the X config file +# "option" - HorizSync is from the "HorizSync" NVIDIA X +# config option +# "builtin" - HorizSync is from NVIDIA X driver builtin +# default values +# +# Additional tokens and/or values may be added in the future. +# +# Example: "source=edid :: 30.000-62.000" +# + +NV_CTRL_STRING_VALID_HORIZ_SYNC_RANGES = 24 # R-DG + +# +# NV_CTRL_STRING_VALID_VERT_REFRESH_RANGES - returns the valid +# vertical refresh ranges used to perform mode validation for the +# specified display device. The ranges are in the same format as the +# "VertRefresh" X config option: +# +# "vertrefresh-range may be a comma separated list of either discrete +# values or ranges of values. A range of values is two values +# separated by a dash." +# +# The values are in Hz. +# +# Additionally, the string may be prepended with a comma-separated +# list of "token=value" pairs, separated from the VertRefresh string by +# "::". Valid tokens: +# +# Token Value +# "source" "edid" - VertRefresh is from the display device's EDID +# "xconfig" - VertRefresh is from the "VertRefresh" entry in +# the Monitor section of the X config file +# "option" - VertRefresh is from the "VertRefresh" NVIDIA X +# config option +# "builtin" - VertRefresh is from NVIDIA X driver builtin +# default values +# +# Additional tokens and/or values may be added in the future. +# +# Example: "source=edid :: 50.000-75.000" +# + +NV_CTRL_STRING_VALID_VERT_REFRESH_RANGES = 25 # R-DG + +# +# NV_CTRL_STRING_SCREEN_RECTANGLE - returns the physical X Screen's +# initial position and size (in absolute coordinates) within the +# desktop as the "token=value" string: "x=#, y=#, width=#, height=#" +# +# Querying this attribute returns success only when Xinerama is enabled +# or the X server ABI is greater than equal to 12. +# + +NV_CTRL_STRING_SCREEN_RECTANGLE = 26 # R--- + +# +# NV_CTRL_STRING_XINERAMA_SCREEN_INFO - renamed +# +# NV_CTRL_STRING_SCREEN_RECTANGLE should be used instead. +# + +NV_CTRL_STRING_XINERAMA_SCREEN_INFO = 26 # renamed + +# +# NV_CTRL_STRING_TWINVIEW_XINERAMA_INFO_ORDER - used to specify the +# order that display devices will be returned via Xinerama when +# nvidiaXineramaInfo is enabled. Follows the same syntax as the +# nvidiaXineramaInfoOrder X config option. +# + +NV_CTRL_STRING_NVIDIA_XINERAMA_INFO_ORDER = 27 # RW-- + +NV_CTRL_STRING_TWINVIEW_XINERAMA_INFO_ORDER = NV_CTRL_STRING_NVIDIA_XINERAMA_INFO_ORDER # for backwards compatibility: + +# +# NV_CTRL_STRING_SLI_MODE - returns a string describing the current +# SLI mode, if any, or FALSE if SLI is not currently enabled. +# +# This string should be used for informational purposes only, and +# should not be used to distinguish between SLI modes, other than to +# recognize when SLI is disabled (FALSE is returned) or +# enabled (the returned string is non-NULL and describes the current +# SLI configuration). +# + +NV_CTRL_STRING_SLI_MODE = 28 # R---*/ + +# +# NV_CTRL_STRING_PERFORMANCE_MODES - returns a string with all the +# performance modes defined for this GPU along with their associated +# NV Clock and Memory Clock values. +# Not all tokens will be reported on all GPUs, and additional tokens +# may be added in the future. +# For backwards compatibility we still provide nvclock, memclock, and +# processorclock those are the same as nvclockmin, memclockmin and +# processorclockmin. +# +# Note: These clock values take into account the offset +# set by clients through NV_CTRL_GPU_NVCLOCK_OFFSET and +# NV_CTRL_GPU_MEM_TRANSFER_RATE_OFFSET. +# +# Each performance modes are returned as a comma-separated list of +# "token=value" pairs. Each set of performance mode tokens are separated +# by a ";". Valid tokens: +# +# Token Value +# "perf" integer - the Performance level +# "nvclock" integer - the GPU clocks (in MHz) for the perf level +# "nvclockmin" integer - the GPU clocks min (in MHz) for the perf level +# "nvclockmax" integer - the GPU clocks max (in MHz) for the perf level +# "nvclockeditable" integer - if the GPU clock domain is editable +# for the perf level +# "memclock" integer - the memory clocks (in MHz) for the perf level +# "memclockmin" integer - the memory clocks min (in MHz) for the perf level +# "memclockmax" integer - the memory clocks max (in MHz) for the perf level +# "memclockeditable" integer - if the memory clock domain is editable +# for the perf level +# "memtransferrate" integer - the memory transfer rate (in MHz) +# for the perf level +# "memtransferratemin" integer - the memory transfer rate min (in MHz) +# for the perf level +# "memtransferratemax" integer - the memory transfer rate max (in MHz) +# for the perf level +# "memtransferrateeditable" integer - if the memory transfer rate is editable +# for the perf level +# "processorclock" integer - the processor clocks (in MHz) +# for the perf level +# "processorclockmin" integer - the processor clocks min (in MHz) +# for the perf level +# "processorclockmax" integer - the processor clocks max (in MHz) +# for the perf level +# "processorclockeditable" integer - if the processor clock domain is editable +# for the perf level +# +# Example: +# +# perf=0, nvclock=324, nvclockmin=324, nvclockmax=324, nvclockeditable=0, +# memclock=324, memclockmin=324, memclockmax=324, memclockeditable=0, +# memtransferrate=648, memtransferratemin=648, memtransferratemax=648, +# memtransferrateeditable=0 ; +# perf=1, nvclock=324, nvclockmin=324, nvclockmax=640, nvclockeditable=0, +# memclock=810, memclockmin=810, memclockmax=810, memclockeditable=0, +# memtransferrate=1620, memtransferrate=1620, memtransferrate=1620, +# memtransferrateeditable=0 ; +# +# This attribute may be queried through XNVCTRLQueryTargetStringAttribute() +# using a NV_CTRL_TARGET_TYPE_GPU or NV_CTRL_TARGET_TYPE_X_SCREEN target. +# + +NV_CTRL_STRING_PERFORMANCE_MODES = 29 # R--G + +# +# NV_CTRL_STRING_VCSC_FAN_STATUS - deprecated +# +# Returns a string with status of all the fans in the Visual Computing System, +# if such a query is supported. Fan information is reported along with its +# tachometer reading (in RPM) and a flag indicating whether the fan has failed +# or not. +# +# Valid tokens: +# +# Token Value +# "fan" integer - the Fan index +# "speed" integer - the tachometer reading of the fan in rpm +# "fail" integer - flag to indicate whether the fan has failed +# +# Example: +# +# fan=0, speed=694, fail=0 ; fan=1, speed=693, fail=0 +# +# This attribute must be queried through XNVCTRLQueryTargetStringAttribute() +# using a NV_CTRL_TARGET_TYPE_VCSC target. +# +# + +NV_CTRL_STRING_VCSC_FAN_STATUS = 30 # R---V + +# +# NV_CTRL_STRING_VCSC_TEMPERATURES - Deprecated +# +# Returns a string with all Temperature readings in the Visual Computing +# System, if such a query is supported. Intake, Exhaust and Board Temperature +# values are reported in Celcius. +# +# Valid tokens: +# +# Token Value +# "intake" integer - the intake temperature for the VCS +# "exhaust" integer - the exhaust temperature for the VCS +# "board" integer - the board temperature of the VCS +# +# Example: +# +# intake=29, exhaust=46, board=41 +# +# This attribute must be queried through XNVCTRLQueryTargetStringAttribute() +# using a NV_CTRL_TARGET_TYPE_VCSC target. +# +# + +NV_CTRL_STRING_VCSC_TEMPERATURES = 31 # R---V + +# +# NV_CTRL_STRING_VCSC_PSU_INFO - Deprecated +# +# Returns a string with all Power Supply Unit related readings in the Visual +# Computing System, if such a query is supported. Current in amperes, Power +# in watts, Voltage in volts and PSU state may be reported. Not all PSU types +# support all of these values, and therefore some readings may be unknown. +# +# Valid tokens: +# +# Token Value +# "current" integer - the current drawn in amperes by the VCS +# "power" integer - the power drawn in watts by the VCS +# "voltage" integer - the voltage reading of the VCS +# "state" integer - flag to indicate whether PSU is operating normally +# +# Example: +# +# current=10, power=15, voltage=unknown, state=normal +# +# This attribute must be queried through XNVCTRLQueryTargetStringAttribute() +# using a NV_CTRL_TARGET_TYPE_VCSC target. +# +# + + +NV_CTRL_STRING_VCSC_PSU_INFO = 32 # R---V + +# +# NV_CTRL_STRING_GVIO_VIDEO_FORMAT_NAME - query the name for the specified +# NV_CTRL_GVIO_VIDEO_FORMAT_*. So that this can be queried with existing +# interfaces, XNVCTRLQueryStringAttribute() should be used, and the video +# format specified in the display_mask field; eg: +# +# XNVCTRLQueryStringAttribute(dpy, +# screen, +# NV_CTRL_GVIO_VIDEO_FORMAT_720P_60_00_SMPTE296, +# NV_CTRL_GVIO_VIDEO_FORMAT_NAME, +# &name); +# + +NV_CTRL_STRING_GVIO_VIDEO_FORMAT_NAME = 33 # R--GI + +# +# NV_CTRL_STRING_GVO_VIDEO_FORMAT_NAME - renamed +# +# NV_CTRL_STRING_GVIO_VIDEO_FORMAT_NAME should be used instead. +# +NV_CTRL_STRING_GVO_VIDEO_FORMAT_NAME = 33 # renamed + +# +# NV_CTRL_STRING_GPU_CURRENT_CLOCK_FREQS - returns a string with the +# associated NV Clock, Memory Clock and Processor Clock values. +# +# Current valid tokens are "nvclock", "nvclockmin", "nvclockmax", +# "memclock", "memclockmin", "memclockmax", "processorclock", +# "processorclockmin" and "processorclockmax". +# Not all tokens will be reported on all GPUs, and additional tokens +# may be added in the future. +# +# Note: These clock values take into account the offset +# set by clients through NV_CTRL_GPU_NVCLOCK_OFFSET and +# NV_CTRL_GPU_MEM_TRANSFER_RATE_OFFSET. +# +# Clock values are returned as a comma-separated list of +# "token=value" pairs. +# Valid tokens: +# +# Token Value +# "nvclock" integer - the GPU clocks (in MHz) for the perf level +# "nvclockmin" integer - the GPU clocks min (in MHz) for the perf level +# "nvclockmax" integer - the GPU clocks max (in MHz) for the perf level +# "nvclockeditable" integer - if the GPU clock domain is editable +# for the perf level +# "memclock" integer - the memory clocks (in MHz) for the perf level +# "memclockmin" integer - the memory clocks min (in MHz) for the perf level +# "memclockmax" integer - the memory clocks (max in MHz) for the perf level +# "memclockeditable" integer - if the memory clock domain is editable +# for the perf level +# "memtransferrate" integer - the memory transfer rate (in MHz) +# for the perf level +# "memtransferratemin" integer - the memory transfer rate min (in MHz) +# for the perf level +# "memtransferratemax" integer - the memory transfer rate max (in MHz) +# for the perf level +# "memtransferrateeditable" integer - if the memory transfer rate is editable +# for the perf level +# "processorclock" integer - the processor clocks (in MHz) +# for the perf level +# "processorclockmin" integer - the processor clocks min (in MHz) +# for the perf level +# "processorclockmax" integer - the processor clocks max (in MHz) +# for the perf level +# "processorclockeditable" integer - if the processor clock domain is editable +# for the perf level +# +# Example: +# +# nvclock=324, nvclockmin=324, nvclockmax=324, nvclockeditable=0 +# memclock=324, memclockmin=324, memclockmax=324, memclockeditable=0 +# memtrasferrate=628 +# +# This attribute may be queried through XNVCTRLQueryTargetStringAttribute() +# using an NV_CTRL_TARGET_TYPE_GPU or NV_CTRL_TARGET_TYPE_X_SCREEN target. +# + +NV_CTRL_STRING_GPU_CURRENT_CLOCK_FREQS = 34 # RW-G + +# +# NV_CTRL_STRING_3D_VISION_PRO_TRANSCEIVER_HARDWARE_REVISION - Returns the +# hardware revision of the 3D Vision Pro transceiver. +# +NV_CTRL_STRING_3D_VISION_PRO_TRANSCEIVER_HARDWARE_REVISION = 35 # R--T + +# +# NV_CTRL_STRING_3D_VISION_PRO_TRANSCEIVER_FIRMWARE_VERSION_A - Returns the +# firmware version of chip A of the 3D Vision Pro transceiver. +# +NV_CTRL_STRING_3D_VISION_PRO_TRANSCEIVER_FIRMWARE_VERSION_A = 36 # R--T + +# +# NV_CTRL_STRING_3D_VISION_PRO_TRANSCEIVER_FIRMWARE_DATE_A - Returns the +# date of the firmware of chip A of the 3D Vision Pro transceiver. +# +NV_CTRL_STRING_3D_VISION_PRO_TRANSCEIVER_FIRMWARE_DATE_A = 37 # R--T + +# +# NV_CTRL_STRING_3D_VISION_PRO_TRANSCEIVER_FIRMWARE_VERSION_B - Returns the +# firmware version of chip B of the 3D Vision Pro transceiver. +# +NV_CTRL_STRING_3D_VISION_PRO_TRANSCEIVER_FIRMWARE_VERSION_B = 38 # R--T + +# +# NV_CTRL_STRING_3D_VISION_PRO_TRANSCEIVER_FIRMWARE_DATE_B - Returns the +# date of the firmware of chip B of the 3D Vision Pro transceiver. +# +NV_CTRL_STRING_3D_VISION_PRO_TRANSCEIVER_FIRMWARE_DATE_B = 39 # R--T + +# +# NV_CTRL_STRING_3D_VISION_PRO_TRANSCEIVER_ADDRESS - Returns the RF address +# of the 3D Vision Pro transceiver. +# +NV_CTRL_STRING_3D_VISION_PRO_TRANSCEIVER_ADDRESS = 40 # R--T + +# +# NV_CTRL_STRING_3D_VISION_PRO_GLASSES_FIRMWARE_VERSION_A - Returns the +# firmware version of chip A of the glasses. +# Use the display_mask parameter to specify the glasses id. +# +NV_CTRL_STRING_3D_VISION_PRO_GLASSES_FIRMWARE_VERSION_A = 41 # R--T + +# +# NV_CTRL_STRING_3D_VISION_PRO_GLASSES_FIRMWARE_DATE_A - Returns the +# date of the firmware of chip A of the glasses. +# Use the display_mask parameter to specify the glasses id. +# +NV_CTRL_STRING_3D_VISION_PRO_GLASSES_FIRMWARE_DATE_A = 42 # R--T + +# +# NV_CTRL_STRING_3D_VISION_PRO_GLASSES_ADDRESS - Returns the RF address +# of the glasses. +# Use the display_mask parameter to specify the glasses id. +# +NV_CTRL_STRING_3D_VISION_PRO_GLASSES_ADDRESS = 43 # R--T + +# +# NV_CTRL_STRING_3D_VISION_PRO_GLASSES_NAME - Controls the name the +# glasses should use. +# Use the display_mask parameter to specify the glasses id. +# Glasses' name should start and end with an alpha-numeric character. +# +NV_CTRL_STRING_3D_VISION_PRO_GLASSES_NAME = 44 # RW-T + +# +# NV_CTRL_STRING_CURRENT_METAMODE_VERSION_2 - Returns the metamode currently +# being used by the specified X screen. The MetaMode string has the same +# syntax as the MetaMode X configuration option, as documented in the NVIDIA +# driver README. Also, see NV_CTRL_BINARY_DATA_METAMODES_VERSION_2 for more +# details on the base syntax. +# +# The returned string may also be prepended with a comma-separated list of +# "token=value" pairs, separated from the MetaMode string by "::". +# +NV_CTRL_STRING_CURRENT_METAMODE_VERSION_2 = 45 # RW-- + +# +# NV_CTRL_STRING_DISPLAY_NAME_TYPE_BASENAME - Returns a type name for the +# display device ("CRT", "DFP", or "TV"). However, note that the determination +# of the name is based on the protocol through which the X driver communicates +# to the display device. E.g., if the driver communicates using VGA ,then the +# basename is "CRT"; if the driver communicates using TMDS, LVDS, or DP, then +# the name is "DFP". +# +NV_CTRL_STRING_DISPLAY_NAME_TYPE_BASENAME = 46 # R-D- + +# +# NV_CTRL_STRING_DISPLAY_NAME_TYPE_ID - Returns the type-based name + ID for +# the display device, e.g. "CRT-0", "DFP-1", "TV-2". If this device is a +# DisplayPort multistream device, then this name will also be prepended with the +# device's port address like so: "DFP-1.0.1.2.3". See +# NV_CTRL_STRING_DISPLAY_NAME_TYPE_BASENAME for more information about the +# construction of type-based names. +# +NV_CTRL_STRING_DISPLAY_NAME_TYPE_ID = 47 # R-D- + +# +# NV_CTRL_STRING_DISPLAY_NAME_DP_GUID - Returns the GUID of the DisplayPort +# display device. e.g. "DP-GUID-f16a5bde-79f3-11e1-b2ae-8b5a8969ba9c" +# +# The display device must be a DisplayPort 1.2 device. +# +NV_CTRL_STRING_DISPLAY_NAME_DP_GUID = 48 # R-D- + +# +# NV_CTRL_STRING_DISPLAY_NAME_EDID_HASH - Returns the SHA-1 hash of the +# display device's EDID in 8-4-4-4-12 UID format. e.g. +# "DPY-EDID-f16a5bde-79f3-11e1-b2ae-8b5a8969ba9c" +# +# The display device must have a valid EDID. +# +NV_CTRL_STRING_DISPLAY_NAME_EDID_HASH = 49 # R-D- + +# +# NV_CTRL_STRING_DISPLAY_NAME_TARGET_INDEX - Returns the current NV-CONTROL +# target ID (name) of the display device. e.g. "DPY-1", "DPY-4" +# +# This name for the display device is not guarenteed to be the same between +# different runs of the X server. +# +NV_CTRL_STRING_DISPLAY_NAME_TARGET_INDEX = 50 # R-D- + +# +# NV_CTRL_STRING_DISPLAY_NAME_RANDR - Returns the RandR output name for the +# display device. e.g. "VGA-1", "DVI-I-0", "DVI-D-3", "LVDS-1", "DP-2", +# "HDMI-3", "eDP-6". This name should match If this device is a DisplayPort +# 1.2 device, then this name will also be prepended with the device's port +# address like so: "DVI-I-3.0.1.2.3" +# +NV_CTRL_STRING_DISPLAY_NAME_RANDR = 51 # R-D- + +# +# NV_CTRL_STRING_GPU_UUID - Returns the UUID of the given GPU. +# +NV_CTRL_STRING_GPU_UUID = 52 # R--G + +# +# NV_CTRL_STRING_GPU_UTILIZATION - Returns the current percentage usage +# of the various components of the GPU. +# +# Current valid tokens are "graphics", "memory", "video" and "PCIe". +# Not all tokens will be reported on all GPUs, and additional tokens +# may be added in the future. +# +# Utilization values are returned as a comma-separated list of +# "token=value" pairs. +# Valid tokens: +# +# Token Value +# "graphics" integer - the percentage usage of graphics engine. +# "memory" integer - the percentage usage of FB. +# "video" integer - the percentage usage of video engine. +# "PCIe" integer - the percentage usage of PCIe bandwidth. +# +# +# Example: +# +# graphics=45, memory=6, video=0, PCIe=0 +# +# This attribute may be queried through XNVCTRLQueryTargetStringAttribute() +# using an NV_CTRL_TARGET_TYPE_GPU. +# +NV_CTRL_STRING_GPU_UTILIZATION = 53 # R--G + +# +# NV_CTRL_STRING_MULTIGPU_MODE - returns a string describing the current +# MULTIGPU mode, if any, or FALSE if MULTIGPU is not currently enabled. +# +NV_CTRL_STRING_MULTIGPU_MODE = 54 # R--- + +# +# NV_CTRL_STRING_PRIME_OUTPUTS_DATA - returns a semicolon delimited list of +# strings that describe all PRIME configured displays. +# +# ex. "xpos=1920, ypos=0, width=1280, height=1024, screen=0;xpos=3200, +# ypos=0, width=800, height=600, screen=0;" +# +NV_CTRL_STRING_PRIME_OUTPUTS_DATA = 55 # R--- + +NV_CTRL_STRING_LAST_ATTRIBUTE = NV_CTRL_STRING_PRIME_OUTPUTS_DATA + +############################################################################ + +# +# Binary Data Attributes: +# +# Binary data attributes can be queryied through the XNVCTRLQueryBinaryData() +# and XNVCTRLQueryTargetBinaryData() function calls. +# +# There are currently no binary data attributes that can be set. +# +# Unless otherwise noted, all Binary data attributes can be queried +# using an NV_CTRL_TARGET_TYPE_X_SCREEN target. Attributes that cannot take +# an NV_CTRL_TARGET_TYPE_X_SCREEN target also cannot be queried through +# XNVCTRLQueryBinaryData() (Since an X Screen target is assumed). +# + + +# +# NV_CTRL_BINARY_DATA_EDID - Returns a display device's EDID information +# data. +# +# This attribute may be queried through XNVCTRLQueryTargetBinaryData() +# using a NV_CTRL_TARGET_TYPE_GPU or NV_CTRL_TARGET_TYPE_X_SCREEN target. +# + +NV_CTRL_BINARY_DATA_EDID = 0 # R-DG + +# +# NV_CTRL_BINARY_DATA_MODELINES - Returns a display device's supported +# ModeLines. ModeLines are returned in a buffer, separated by a single +# '\0' and terminated by two consecutive '\0' s like so: +# +# "ModeLine 1\0ModeLine 2\0ModeLine 3\0Last ModeLine\0\0" +# +# This attribute may be queried through XNVCTRLQueryTargetBinaryData() +# using a NV_CTRL_TARGET_TYPE_GPU or NV_CTRL_TARGET_TYPE_X_SCREEN target. +# +# Each ModeLine string may be prepended with a comma-separated list +# of "token=value" pairs, separated from the ModeLine string with a +# "::". Valid tokens: +# +# Token Value +# "source" "xserver" - the ModeLine is from the core X server +# "xconfig" - the ModeLine was specified in the X config file +# "builtin" - the NVIDIA driver provided this builtin ModeLine +# "vesa" - this is a VESA standard ModeLine +# "edid" - the ModeLine was in the display device's EDID +# "nv-control" - the ModeLine was specified via NV-CONTROL +# +# "xconfig-name" - for ModeLines that were specified in the X config +# file, this is the name the X config file +# gave for the ModeLine. +# +# Note that a ModeLine can have several sources; the "source" token +# can appear multiple times in the "token=value" pairs list. +# Additional source values may be specified in the future. +# +# Additional tokens may be added in the future, so it is recommended +# that any token parser processing the returned string from +# NV_CTRL_BINARY_DATA_MODELINES be implemented to gracefully ignore +# unrecognized tokens. +# +# E.g., +# +# "source=xserver, source=vesa, source=edid :: "1024x768_70" 75.0 1024 1048 1184 1328 768 771 777 806 -HSync -VSync" +# "source=xconfig, xconfig-name=1600x1200_60.00 :: "1600x1200_60_0" 161.0 1600 1704 1880 2160 1200 1201 1204 1242 -HSync +VSync" +# + +NV_CTRL_BINARY_DATA_MODELINES = 1 # R-DG + +# +# NV_CTRL_BINARY_DATA_METAMODES - Returns an X Screen's supported +# MetaModes. MetaModes are returned in a buffer separated by a +# single '\0' and terminated by two consecutive '\0' s like so: +# +# "MetaMode 1\0MetaMode 2\0MetaMode 3\0Last MetaMode\0\0" +# +# The MetaMode string should have the same syntax as the MetaMode X +# configuration option, as documented in the NVIDIA driver README. + +# Each MetaMode string may be prepended with a comma-separated list +# of "token=value" pairs, separated from the MetaMode string with +# "::". Currently, valid tokens are: +# +# Token Value +# "id" - the id of this MetaMode; this is stored in +# the Vertical Refresh field, as viewed +# by the XRandR and XF86VidMode X# +# extensions. +# +# "switchable" "yes"/"no" - whether this MetaMode may be switched to via +# ctrl-alt-+/-; Implicit MetaModes (see +# the "IncludeImplicitMetaModes" X +# config option), for example, are not +# normally made available through +# ctrl-alt-+/-. +# +# "source" "xconfig" - the MetaMode was specified in the X +# config file. +# "implicit" - the MetaMode was implicitly added; see the +# "IncludeImplicitMetaModes" X config option +# for details. +# "nv-control" - the MetaMode was added via the NV-CONTROL X +# extension to the currently running X server. +# "RandR" - the MetaMode was modified in response to an +# RandR RRSetCrtcConfig request. +# +# Additional tokens may be added in the future, so it is recommended +# that any token parser processing the returned string from +# NV_CTRL_BINARY_DATA_METAMODES be implemented to gracefully ignore +# unrecognized tokens. +# +# E.g., +# +# "id=50, switchable=yes, source=xconfig :: CRT-0: 1024x768 @1024x768 +0+0" +# + +NV_CTRL_BINARY_DATA_METAMODES = 2 # R-D- +NV_CTRL_BINARY_DATA_METAMODES_VERSION_1 = NV_CTRL_BINARY_DATA_METAMODES + +# +# NV_CTRL_BINARY_DATA_XSCREENS_USING_GPU - Returns the list of X +# screens currently driven by the given GPU. +# +# The format of the returned data is: +# +# 4 CARD32 number of screens +# 4# n CARD32 screen indices +# +# This attribute can only be queried through XNVCTRLQueryTargetBinaryData() +# using a NV_CTRL_TARGET_TYPE_GPU target. This attribute cannot be +# queried using a NV_CTRL_TARGET_TYPE_X_SCREEN. +# + +NV_CTRL_BINARY_DATA_XSCREENS_USING_GPU = 3 # R-DG + +# +# NV_CTRL_BINARY_DATA_GPUS_USED_BY_XSCREEN - Returns the list of GPUs +# currently in use by the given X screen. +# +# The format of the returned data is: +# +# 4 CARD32 number of GPUs +# 4# n CARD32 GPU indices +# + +NV_CTRL_BINARY_DATA_GPUS_USED_BY_XSCREEN = 4 # R--- + +# +# NV_CTRL_BINARY_DATA_GPUS_USING_FRAMELOCK - Returns the list of +# GPUs currently connected to the given frame lock board. +# +# The format of the returned data is: +# +# 4 CARD32 number of GPUs +# 4# n CARD32 GPU indices +# +# This attribute can only be queried through XNVCTRLQueryTargetBinaryData() +# using a NV_CTRL_TARGET_TYPE_FRAMELOCK target. This attribute cannot be +# queried using a NV_CTRL_TARGET_TYPE_X_SCREEN. +# + +NV_CTRL_BINARY_DATA_GPUS_USING_FRAMELOCK = 5 # R-DF + +# +# NV_CTRL_BINARY_DATA_DISPLAY_VIEWPORT - Returns the Display Device's +# viewport box into the given X Screen (in X Screen coordinates.) +# +# The format of the returned data is: +# +# 4 CARD32 Offset X +# 4 CARD32 Offset Y +# 4 CARD32 Width +# 4 CARD32 Height +# + +NV_CTRL_BINARY_DATA_DISPLAY_VIEWPORT = 6 # R-DG + +# +# NV_CTRL_BINARY_DATA_FRAMELOCKS_USED_BY_GPU - Returns the list of +# Framelock devices currently connected to the given GPU. +# +# The format of the returned data is: +# +# 4 CARD32 number of Framelocks +# 4# n CARD32 Framelock indices +# +# This attribute can only be queried through XNVCTRLQueryTargetBinaryData() +# using a NV_CTRL_TARGET_TYPE_GPU target. This attribute cannot be +# queried using a NV_CTRL_TARGET_TYPE_X_SCREEN. +# + +NV_CTRL_BINARY_DATA_FRAMELOCKS_USED_BY_GPU = 7 # R-DG + +# +# NV_CTRL_BINARY_DATA_GPUS_USING_VCSC - Deprecated +# +# Returns the list of GPU devices connected to the given VCS. +# +# The format of the returned data is: +# +# 4 CARD32 number of GPUs +# 4# n CARD32 GPU indices +# +# This attribute can only be queried through XNVCTRLQueryTargetBinaryData() +# using a NV_CTRL_TARGET_TYPE_VCSC target. This attribute cannot be +# queried using a NV_CTRL_TARGET_TYPE_X_SCREEN and cannot be queried using +# a NV_CTRL_TARGET_TYPE_X_GPU +# + +NV_CTRL_BINARY_DATA_GPUS_USING_VCSC = 8 # R-DV + +# +# NV_CTRL_BINARY_DATA_VCSCS_USED_BY_GPU - Deprecated +# +# Returns the VCSC device that is controlling the given GPU. +# +# The format of the returned data is: +# +# 4 CARD32 number of VCS (always 1) +# 4# n CARD32 VCS indices +# +# This attribute can only be queried through XNVCTRLQueryTargetBinaryData() +# using a NV_CTRL_TARGET_TYPE_GPU target. This attribute cannot be +# queried using a NV_CTRL_TARGET_TYPE_X_SCREEN +# + +NV_CTRL_BINARY_DATA_VCSCS_USED_BY_GPU = 9 # R-DG + +# +# NV_CTRL_BINARY_DATA_COOLERS_USED_BY_GPU - Returns the coolers that +# are cooling the given GPU. +# +# The format of the returned data is: +# +# 4 CARD32 number of COOLER +# 4# n CARD32 COOLER indices +# +# This attribute can only be queried through XNVCTRLQueryTargetBinaryData() +# using a NV_CTRL_TARGET_TYPE_GPU target. This attribute cannot be +# queried using a NV_CTRL_TARGET_TYPE_X_SCREEN +# + +NV_CTRL_BINARY_DATA_COOLERS_USED_BY_GPU = 10 # R-DG + +# +# NV_CTRL_BINARY_DATA_GPUS_USED_BY_LOGICAL_XSCREEN - Returns the list of +# GPUs currently driving the given X screen. If Xinerama is enabled, this +# will return all GPUs that are driving any X screen. +# +# The format of the returned data is: +# +# 4 CARD32 number of GPUs +# 4# n CARD32 GPU indices +# + +NV_CTRL_BINARY_DATA_GPUS_USED_BY_LOGICAL_XSCREEN = 11 # R--- + +# +# NV_CTRL_BINARY_DATA_THERMAL_SENSORS_USED_BY_GPU - Returns the sensors that +# are attached to the given GPU. +# +# The format of the returned data is: +# +# 4 CARD32 number of SENSOR +# 4# n CARD32 SENSOR indices +# +# This attribute can only be queried through XNVCTRLQueryTargetBinaryData() +# using a NV_CTRL_TARGET_TYPE_GPU target. This attribute cannot be +# queried using a NV_CTRL_TARGET_TYPE_X_SCREEN +# + +NV_CTRL_BINARY_DATA_THERMAL_SENSORS_USED_BY_GPU = 12 # R--G + +# +# NV_CTRL_BINARY_DATA_GLASSES_PAIRED_TO_3D_VISION_PRO_TRANSCEIVER - Returns +# the id of the glasses that are currently paired to the given +# 3D Vision Pro transceiver. +# +# The format of the returned data is: +# +# 4 CARD32 number of glasses +# 4# n CARD32 id of glasses +# +# This attribute can only be queried through XNVCTRLQueryTargetBinaryData() +# using a NV_CTRL_TARGET_TYPE_3D_VISION_PRO_TRANSCEIVER target. +# +NV_CTRL_BINARY_DATA_GLASSES_PAIRED_TO_3D_VISION_PRO_TRANSCEIVER = 13 # R--T + +# +# NV_CTRL_BINARY_DATA_DISPLAY_TARGETS - Returns all the display devices +# currently connected to any GPU on the X server. +# +# The format of the returned data is: +# +# 4 CARD32 number of display devices +# 4# n CARD32 display device indices +# +# This attribute can only be queried through XNVCTRLQueryTargetBinaryData(). +# + +NV_CTRL_BINARY_DATA_DISPLAY_TARGETS = 14 # R--- + +# +# NV_CTRL_BINARY_DATA_DISPLAYS_CONNECTED_TO_GPU - Returns the list of +# display devices that are connected to the GPU target. +# +# The format of the returned data is: +# +# 4 CARD32 number of display devices +# 4# n CARD32 display device indices +# +# This attribute can only be queried through XNVCTRLQueryTargetBinaryData() +# using a NV_CTRL_TARGET_TYPE_GPU target. +# + +NV_CTRL_BINARY_DATA_DISPLAYS_CONNECTED_TO_GPU = 15 # R--G + +# +# NV_CTRL_BINARY_DATA_METAMODES_VERSION_2 - Returns values similar to +# NV_CTRL_BINARY_DATA_METAMODES(_VERSION_1) but also returns extended syntax +# information to indicate a specific display device, as well as other per- +# display deviceflags as "token=value" pairs. For example: +# +# "DPY-1: 1280x1024 {Stereo=PassiveLeft}, +# DPY-2: 1280x1024 {Stereo=PassiveRight}," +# +# The display device names have the form "DPY-%d", where the integer +# part of the name is the NV-CONTROL target ID for that display device +# for this instance of the X server. Note that display device NV-CONTROL +# target IDs are not guaranteed to be the same from one run of the X +# server to the next. +# + +NV_CTRL_BINARY_DATA_METAMODES_VERSION_2 = 16 # R-D- + +# +# NV_CTRL_BINARY_DATA_DISPLAYS_ENABLED_ON_XSCREEN - Returns the list of +# display devices that are currently scanning out the X screen target. +# +# The format of the returned data is: +# +# 4 CARD32 number of display devices +# 4# n CARD32 display device indices +# +# This attribute can only be queried through XNVCTRLQueryTargetBinaryData() +# using a NV_CTRL_TARGET_TYPE_X_SCREEN target. +# + +NV_CTRL_BINARY_DATA_DISPLAYS_ENABLED_ON_XSCREEN = 17 # R--- + +# +# NV_CTRL_BINARY_DATA_DISPLAYS_ASSIGNED_TO_XSCREEN - Returns the list of +# display devices that are currently assigned the X screen target. +# +# The format of the returned data is: +# +# 4 CARD32 number of display devices +# 4# n CARD32 display device indices +# +# This attribute can only be queried through XNVCTRLQueryTargetBinaryData() +# using a NV_CTRL_TARGET_TYPE_X_SCREEN target. +# + +NV_CTRL_BINARY_DATA_DISPLAYS_ASSIGNED_TO_XSCREEN = 18 # R--- + +# +# NV_CTRL_BINARY_DATA_GPU_FLAGS - Returns a list of flags for the +# given GPU. A flag can, for instance, be a capability which enables +# or disables some features according to the GPU state. +# +# The format of the returned data is: +# +# 4 CARD32 number of GPU flags +# 4# n CARD32 GPU flag +# +# This attribute can only be queried through XNVCTRLQueryTargetBinaryData() +# using a NV_CTRL_TARGET_TYPE_GPU target. +# +NV_CTRL_BINARY_DATA_GPU_FLAGS = 19 # R--- + +# Stereo and display composition transformations are mutually exclusive. +NV_CTRL_BINARY_DATA_GPU_FLAGS_STEREO_DISPLAY_TRANSFORM_EXCLUSIVE = 0 +# Overlay and display composition transformations are mutually exclusive. +NV_CTRL_BINARY_DATA_GPU_FLAGS_OVERLAY_DISPLAY_TRANSFORM_EXCLUSIVE = 1 +# Depth 8 and display composition transformations are mutually exclusive. +NV_CTRL_BINARY_DATA_GPU_FLAGS_DEPTH_8_DISPLAY_TRANSFORM_EXCLUSIVE = 2 + +# +# NV_CTRL_BINARY_DATA_DISPLAYS_ON_GPU - Returns the list of valid +# display devices that can be connected to the GPU target. +# +# The format of the returned data is: +# +# 4 CARD32 number of display devices +# 4# n CARD32 display device indices +# +# This attribute can only be queried through XNVCTRLQueryTargetBinaryData() +# using a NV_CTRL_TARGET_TYPE_GPU target. +# + +NV_CTRL_BINARY_DATA_DISPLAYS_ON_GPU = 20 # R--G + +NV_CTRL_BINARY_DATA_LAST_ATTRIBUTE = NV_CTRL_BINARY_DATA_DISPLAYS_ON_GPU + +############################################################################ + +# +# String Operation Attributes: +# +# These attributes are used with the XNVCTRLStringOperation() +# function; a string is specified as input, and a string is returned +# as output. +# +# Unless otherwise noted, all attributes can be operated upon using +# an NV_CTRL_TARGET_TYPE_X_SCREEN target. +# + + +# +# NV_CTRL_STRING_OPERATION_ADD_METAMODE - provide a MetaMode string +# as input, and returns a string containing comma-separated list of +# "token=value" pairs as output. Currently, the only output token is +# "id", which indicates the id that was assigned to the MetaMode. +# +# All ModeLines referenced in the MetaMode must already exist for +# each display device (as returned by the +# NV_CTRL_BINARY_DATA_MODELINES attribute). +# +# The MetaMode string should have the same syntax as the MetaMode X +# configuration option, as documented in the NVIDIA driver README. +# +# The input string can optionally be prepended with a string of +# comma-separated "token=value" pairs, separated from the MetaMode +# string by "::". Currently, the only valid token is "index" which +# indicates the insertion index for the MetaMode. +# +# E.g., +# +# Input: "index=5 :: 1600x1200+0+0, 1600x1200+1600+0" +# Output: "id=58" +# +# which causes the MetaMode to be inserted at position 5 in the +# MetaMode list (all entries after 5 will be shifted down one slot in +# the list), and the X server's containing mode stores 58 as the +# VRefresh, so that the MetaMode can be uniquely identifed through +# XRandR and XF86VidMode. +# + +NV_CTRL_STRING_OPERATION_ADD_METAMODE = 0 # ---- + +# +# NV_CTRL_STRING_OPERATION_GTF_MODELINE - provide as input a string +# of comma-separated "token=value" pairs, and returns a ModeLine +# string, computed using the GTF formula using the parameters from +# the input string. Valid tokens for the input string are "width", +# "height", and "refreshrate". +# +# E.g., +# +# Input: "width=1600, height=1200, refreshrate=60" +# Output: "160.96 1600 1704 1880 2160 1200 1201 1204 1242 -HSync +VSync" +# +# This operation does not have any impact on any display device's +# modePool, and the ModeLine is not validated; it is simply intended +# for generating ModeLines. +# + +NV_CTRL_STRING_OPERATION_GTF_MODELINE = 1 # --- + +# +# NV_CTRL_STRING_OPERATION_CVT_MODELINE - provide as input a string +# of comma-separated "token=value" pairs, and returns a ModeLine +# string, computed using the CVT formula using the parameters from +# the input string. Valid tokens for the input string are "width", +# "height", "refreshrate", and "reduced-blanking". The +# "reduced-blanking" argument can be "0" or "1", to enable or disable +# use of reduced blanking for the CVT formula. +# +# E.g., +# +# Input: "width=1600, height=1200, refreshrate=60, reduced-blanking=1" +# Output: "130.25 1600 1648 1680 1760 1200 1203 1207 1235 +HSync -VSync" +# +# This operation does not have any impact on any display device's +# modePool, and the ModeLine is not validated; it is simply intended +# for generating ModeLines. +# + +NV_CTRL_STRING_OPERATION_CVT_MODELINE = 2 # --- + +# +# NV_CTRL_STRING_OPERATION_BUILD_MODEPOOL - build a ModePool for the +# specified display device on the specified target (either an X +# screen or a GPU). This is typically used to generate a ModePool +# for a display device on a GPU on which no X screens are present. +# +# Currently, a display device's ModePool is static for the life of +# the X server, so XNVCTRLStringOperation will return FALSE if +# requested to build a ModePool on a display device that already has +# a ModePool. +# +# The string input to BUILD_MODEPOOL may be NULL. If it is not NULL, +# then it is interpreted as a double-colon ("::") separated list +# of "option=value" pairs, where the options and the syntax of their +# values are the X configuration options that impact the behavior of +# modePool construction; namely: +# +# "ModeValidation" +# "HorizSync" +# "VertRefresh" +# "FlatPanelProperties" +# "ExactModeTimingsDVI" +# "UseEdidFreqs" +# +# An example input string might look like: +# +# "ModeValidation=NoVesaModes :: HorizSync=50-110 :: VertRefresh=50-150" +# +# This request currently does not return a string. +# + +NV_CTRL_STRING_OPERATION_BUILD_MODEPOOL = 3 # DG + +# +# NV_CTRL_STRING_OPERATION_GVI_CONFIGURE_STREAMS - Configure the streams- +# to-jack+channel topology for a GVI (Graphics capture board). +# +# The string input to GVI_CONFIGURE_STREAMS may be NULL. If this is the +# case, then the current topology is returned. +# +# If the input string to GVI_CONFIGURE_STREAMS is not NULL, the string +# is interpreted as a semicolon (";") separated list of comma-separated +# lists of "option=value" pairs that define a stream's composition. The +# available options and their values are: +# +# "stream": Defines which stream this comma-separated list describes. +# Valid values are the integers between 0 and +# NV_CTRL_GVI_NUM_STREAMS-1 (inclusive). +# +# "linkN": Defines a jack+channel pair to use for the given link N. +# Valid options are the string "linkN", where N is an integer +# between 0 and NV_CTRL_GVI_MAX_LINKS_PER_STREAM-1 (inclusive). +# Valid values for these options are strings of the form +# "jackX" and/or "jackX.Y", where X is an integer between 0 and +# NV_CTRL_GVI_NUM_JACKS-1 (inclusive), and Y (optional) is an +# integer between 0 and NV_CTRL_GVI_MAX_CHANNELS_PER_JACK-1 +# (inclusive). +# +# An example input string might look like: +# +# "stream=0, link0=jack0, link1=jack1; stream=1, link0=jack2.1" +# +# This example specifies two streams, stream 0 and stream 1. Stream 0 +# is defined to capture link0 data from the first channel (channel 0) of +# BNC jack 0 and link1 data from the first channel of BNC jack 1. The +# second stream (Stream 1) is defined to capture link0 data from channel 1 +# (second channel) of BNC jack 2. +# +# This example shows a possible configuration for capturing 3G input: +# +# "stream=0, link0=jack0.0, link1=jack0.1" +# +# Applications should query the following attributes to determine +# possible combinations: +# +# NV_CTRL_GVI_MAX_STREAMS +# NV_CTRL_GVI_MAX_LINKS_PER_STREAM +# NV_CTRL_GVI_NUM_JACKS +# NV_CTRL_GVI_MAX_CHANNELS_PER_JACK +# +# Note: A jack+channel pair can only be tied to one link/stream. +# +# Upon successful configuration or querying of this attribute, a string +# representing the current topology for all known streams on the device +# will be returned. On failure, NULL is returned. +# +# Note: Setting this attribute may also result in the following +# NV-CONTROL attributes being reset on the GVI device (to ensure +# the configuration remains valid): +# NV_CTRL_GVIO_REQUESTED_VIDEO_FORMAT +# NV_CTRL_GVI_REQUESTED_STREAM_BITS_PER_COMPONENT +# NV_CTRL_GVI_REQUESTED_STREAM_COMPONENT_SAMPLING +# + +NV_CTRL_STRING_OPERATION_GVI_CONFIGURE_STREAMS = 4 # RW-I + +# +# NV_CTRL_STRING_OPERATION_PARSE_METAMODE - Parses the given MetaMode string +# and returns the validated MetaMode string - possibly re-calculating various +# values such as ViewPortIn. If the MetaMode matches an existing MetaMode, +# the details of the existing MetaMode are returned. If the MetaMode fails to +# be parsed, NULL is returned. +# +NV_CTRL_STRING_OPERATION_PARSE_METAMODE = 5 # R--- + +NV_CTRL_STRING_OPERATION_LAST_ATTRIBUTE = NV_CTRL_STRING_OPERATION_PARSE_METAMODE + +############################################################################### +# NV-CONTROL major op numbers. these constants identify the request type +# +X_nvCtrlQueryExtension = 0 +X_nvCtrlQueryAttribute = 2 +X_nvCtrlQueryStringAttribute = 4 +X_nvCtrlQueryValidAttributeValues = 5 +X_nvCtrlSetStringAttribute = 9 +X_nvCtrlSetAttributeAndGetStatus = 19 +X_nvCtrlQueryBinaryData = 20 +X_nvCtrlQueryTargetCount = 24 +X_nvCtrlStringOperation = 25 + +############################################################################### +# various lists that go with attrs, but are handled more compactly +# this way. these lists are indexed by the possible values of their attrs +# and are explained in NVCtrl.h +# + +ATTRIBUTE_TYPE_UNKNOWN = 0 +ATTRIBUTE_TYPE_INTEGER = 1 +ATTRIBUTE_TYPE_BITMASK = 2 +ATTRIBUTE_TYPE_BOOL = 3 +ATTRIBUTE_TYPE_RANGE = 4 +ATTRIBUTE_TYPE_INT_BITS = 5 + +ATTRIBUTE_TYPE_READ = 0x01 +ATTRIBUTE_TYPE_WRITE = 0x02 +ATTRIBUTE_TYPE_DISPLAY = 0x04 +ATTRIBUTE_TYPE_GPU = 0x08 +ATTRIBUTE_TYPE_FRAMELOCK = 0x10 +ATTRIBUTE_TYPE_X_SCREEN = 0x20 +ATTRIBUTE_TYPE_XINERAMA = 0x40 +ATTRIBUTE_TYPE_VCSC = 0x80 + +############################################################################ + +# +# Attribute Targets +# +# Targets define attribute groups. For example, some attributes are only +# valid to set on a GPU, others are only valid when talking about an +# X Screen. Target types are then what is used to identify the target +# group of the attribute you wish to set/query. +# +# Here are the supported target types: +# + +NV_CTRL_TARGET_TYPE_X_SCREEN = 0 +NV_CTRL_TARGET_TYPE_GPU = 1 +NV_CTRL_TARGET_TYPE_FRAMELOCK = 2 +# Visual Computing System - deprecated. To be removed along with all +# VCS-specific attributes in a later release. +NV_CTRL_TARGET_TYPE_VCSC = 3 +NV_CTRL_TARGET_TYPE_GVI = 4 +NV_CTRL_TARGET_TYPE_COOLER = 5 # e.g., fan +NV_CTRL_TARGET_TYPE_THERMAL_SENSOR = 6 +NV_CTRL_TARGET_TYPE_3D_VISION_PRO_TRANSCEIVER = 7 +NV_CTRL_TARGET_TYPE_DISPLAY = 8 + + +############################################################################### +# Targets, to indicate where a command should be executed. +# +class Target(object): + def __init__(self): + self._id = -1 + self._type = -1 + self._name = '' + + def id(self): + return self._id + + def type(self): + return self._type + + def __str__(self): + return ''.format(self._name, self.id()) + + +class Gpu(Target): + def __init__(self, ngpu=0): + """Target a GPU""" + super(self.__class__, self).__init__() + self._id = ngpu + self._type = NV_CTRL_TARGET_TYPE_GPU + self._name = 'GPU' + + +class Screen(Target): + def __init__(self, nscr=0): + """Target an X screen""" + super(self.__class__, self).__init__() + self._id = nscr + self._type = NV_CTRL_TARGET_TYPE_X_SCREEN + self._name = 'X screen' + + +class Cooler(Target): + def __init__(self, nfan=0): + """Target a fann""" + super(self.__class__, self).__init__() + self._id = nfan + self._type = NV_CTRL_TARGET_TYPE_COOLER + self._name = 'Cooler' + + +class NVCtrlQueryTargetCountReplyRequest(rq.ReplyRequest): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(X_nvCtrlQueryTargetCount), + rq.RequestLength(), + rq.Card32('target_type'), + ) + _reply = rq.Struct( + rq.ReplyCode(), + rq.Card8('padb1'), + rq.Card16('sequence_number'), + rq.ReplyLength(), + rq.Card32('count'), + rq.Card32('pad4'), + rq.Card32('pad5'), + rq.Card32('pad6'), + rq.Card32('pad7'), + rq.Card32('pad8'), + ) + + +class NVCtrlQueryAttributeReplyRequest(rq.ReplyRequest): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(X_nvCtrlQueryAttribute), + rq.RequestLength(), + rq.Card16('target_id'), + rq.Card16('target_type'), + rq.Card32('display_mask'), + rq.Card32('attr'), + ) + _reply = rq.Struct( + rq.ReplyCode(), + rq.Card8('pad0'), + rq.Card16('sequence_number'), + rq.ReplyLength(), + rq.Card32('flags'), + rq.Int32('value'), + rq.Card32('pad4'), + rq.Card32('pad5'), + rq.Card32('pad6'), + rq.Card32('pad7'), + ) + + +class NVCtrlSetAttributeAndGetStatusReplyRequest(rq.ReplyRequest): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(X_nvCtrlSetAttributeAndGetStatus), + rq.RequestLength(), + rq.Card16('target_id'), + rq.Card16('target_type'), + rq.Card32('display_mask'), + rq.Card32('attr'), + rq.Int32('value') + ) + _reply = rq.Struct( + rq.ReplyCode(), + rq.Card8('pad0'), + rq.Card16('sequence_number'), + rq.ReplyLength(), + rq.Card32('flags'), + rq.Card32('pad3'), + rq.Card32('pad4'), + rq.Card32('pad5'), + rq.Card32('pad6'), + rq.Card32('pad7'), + ) + + +class NVCtrlQueryStringAttributeReplyRequest(rq.ReplyRequest): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(X_nvCtrlQueryStringAttribute), + rq.RequestLength(), + rq.Card16('target_id'), + rq.Card16('target_type'), + rq.Card32('display_mask'), + rq.Card32('attr'), + ) + _reply = rq.Struct( + rq.ReplyCode(), + rq.Card8('pad0'), + rq.Card16('sequence_number'), + rq.ReplyLength(), + rq.Card32('flags'), + rq.Card32('string', 4), + rq.Card32('pad4'), + rq.Card32('pad5'), + rq.Card32('pad6'), + rq.Card32('pad7'), + rq.String8('string'), + ) + + +class NVCtrlQueryValidAttributeValuesReplyRequest(rq.ReplyRequest): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(X_nvCtrlQueryValidAttributeValues), + rq.RequestLength(), + rq.Card16('target_id'), + rq.Card16('target_type'), + rq.Card32('display_mask'), + rq.Card32('attr'), + ) + _reply = rq.Struct( + rq.ReplyCode(), + rq.Card8('pad0'), + rq.Card16('sequence_number'), + rq.ReplyLength(), + rq.Card32('flags'), + rq.Int32('attr_type'), + rq.Int32('min'), + rq.Int32('max'), + rq.Card32('bits'), + rq.Card32('perms'), + ) + + +class NVCtrlQueryBinaryDataReplyRequest(rq.ReplyRequest): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(X_nvCtrlQueryBinaryData), + rq.RequestLength(), + rq.Card16('target_id'), + rq.Card16('target_type'), + rq.Card32('display_mask'), + rq.Card32('attr'), + ) + _reply = rq.Struct( + rq.ReplyCode(), + rq.Card8('pad0'), + rq.Card16('sequence_number'), + rq.ReplyLength(), + rq.Card32('flags'), + rq.Card32('data', 4), + rq.Card32('pad4'), + rq.Card32('pad5'), + rq.Card32('pad6'), + rq.Card32('pad7'), + rq.Binary('data'), + ) + + +class NVCtrlQueryListCard32ReplyRequest(rq.ReplyRequest): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(X_nvCtrlQueryBinaryData), + rq.RequestLength(), + rq.Card16('target_id'), + rq.Card16('target_type'), + rq.Card32('display_mask'), + rq.Card32('attr'), + ) + _reply = rq.Struct( + rq.ReplyCode(), + rq.Card8('pad0'), + rq.Card16('sequence_number'), + rq.ReplyLength(), + rq.Card32('flags'), + rq.Card32('list', 4), + rq.Card32('pad4'), + rq.Card32('pad5'), + rq.Card32('pad6'), + rq.Card32('pad7'), + rq.List('list', rq.Card32), + ) diff --git a/Xlib/ext/randr.py b/Xlib/ext/randr.py index 168b90f6..9cbfe2da 100644 --- a/Xlib/ext/randr.py +++ b/Xlib/ext/randr.py @@ -2,28 +2,30 @@ # # Copyright (C) 2006 Mike Meyer # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA """RandR - provide access to the RandR extension information. -This implementation is based off version 1.3 of the XRandR protocol, and may +This implementation is based off version 1.5 of the XRandR protocol, and may not be compatible with other versions. -Version 1.2 of the protocol is documented at: +Version 1.5 of the protocol is documented at: http://cgit.freedesktop.org/xorg/proto/randrproto/tree/randrproto.txt Version 1.3.1 here: @@ -33,7 +35,7 @@ from Xlib import X -from Xlib.protocol import rq, structs +from Xlib.protocol import rq extname = 'RANDR' @@ -120,6 +122,12 @@ BadRRCrtc = 1 BadRRMode = 2 +# Error classes # +class BadRROutputError(Exception): pass + +class BadRRCrtcError(Exception): pass + +class BadRRModeError(Exception): pass # Data Structures # @@ -166,6 +174,19 @@ rq.Card32('matrix33'), ) +MonitorInfo = rq.Struct( + rq.Card32('name'), + rq.Bool('primary'), + rq.Bool('automatic'), + rq.LengthOf('crtcs', 2), + rq.Int16('x'), + rq.Int16('y'), + rq.Card16('width_in_pixels'), + rq.Card16('height_in_pixels'), + rq.Card32('width_in_millimeters'), + rq.Card32('height_in_millimeters'), + rq.List('crtcs', rq.Card32Obj) +) # Requests # @@ -195,7 +216,7 @@ def query_version(self): display=self.display, opcode=self.display.get_extension_major(extname), major_version=1, - minor_version=3, + minor_version=5, ) @@ -697,7 +718,7 @@ class DeleteOutputMode(rq.Request): rq.Card32('mode'), ) -def delete_output_mode(self): +def delete_output_mode(self, output, mode): return DeleteOutputMode( display=self.display, opcode=self.display.get_extension_major(extname), @@ -1076,6 +1097,76 @@ def get_output_primary(self): ) +# Version 1.5 methods + +class GetMonitors(rq.ReplyRequest): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(42), + rq.RequestLength(), + rq.Window('window'), + rq.Bool('is_active'), + rq.Pad(3) + ) + + _reply = rq.Struct( + rq.ReplyCode(), + rq.Pad(1), + rq.Card16('sequence_number'), + rq.ReplyLength(), + rq.Card32('timestamp'), + rq.LengthOf('monitors', 4), + rq.Card32('outputs'), + rq.Pad(12), + rq.List('monitors', MonitorInfo) + ) + + +def get_monitors(self, is_active=True): + return GetMonitors( + display=self.display, + opcode=self.display.get_extension_major(extname), + window=self, + is_active=is_active + ) + +class SetMonitor(rq.Request): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(43), + rq.RequestLength(), + rq.Window('window'), + rq.Object('monitor_info', MonitorInfo) + ) + + +def set_monitor(self, monitor_info): + return SetMonitor( + display=self.display, + opcode=self.display.get_extension_major(extname), + window=self, + monitor_info=monitor_info + ) + + +class DeleteMonitor(rq.Request): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(44), + rq.RequestLength(), + rq.Window('window'), + rq.Card32('name') + ) + + +def delete_monitor(self, name): + return DeleteMonitor( + display=self.display, + opcode=self.display.get_extension_major(extname), + window=self, + name=name + ) + # Events # class ScreenChangeNotify(rq.Event): @@ -1147,8 +1238,6 @@ class OutputPropertyNotify(rq.Event): rq.Card8('state'), rq.Pad(11), ) - - # Initialization # def init(disp, info): @@ -1184,12 +1273,20 @@ def init(disp, info): disp.extension_add_method('display', 'xrandr_get_panning', get_panning) disp.extension_add_method('display', 'xrandr_set_panning', set_panning) - disp.extension_add_event(info.first_event + RRScreenChangeNotify, ScreenChangeNotify) - # add RRNotify events (1 event code with 3 subcodes) - disp.extension_add_subevent(info.first_event + RRNotify, RRNotify_CrtcChange, CrtcChangeNotify) - disp.extension_add_subevent(info.first_event + RRNotify, RRNotify_OutputChange, OutputChangeNotify) - disp.extension_add_subevent(info.first_event + RRNotify, RRNotify_OutputProperty, OutputPropertyNotify) - - #disp.extension_add_error(BadRROutput, BadRROutputError) - #disp.extension_add_error(BadRRCrtc, BadRRCrtcError) - #disp.extension_add_error(BadRRMode, BadRRModeError) + # If the server is running RANDR 1.5+, enable 1.5 compatible methods and events + version = query_version(disp) + if version.major_version == 1 and version.minor_version >= 5: + # version 1.5 compatible + disp.extension_add_method('window', 'xrandr_get_monitors', get_monitors) + disp.extension_add_method('window', 'xrandr_set_monitor', set_monitor) + disp.extension_add_method('window', 'xrandr_delete_monitor', delete_monitor) + + disp.extension_add_event(info.first_event + RRScreenChangeNotify, ScreenChangeNotify) + # add RRNotify events (1 event code with 3 subcodes) + disp.extension_add_subevent(info.first_event + RRNotify, RRNotify_CrtcChange, CrtcChangeNotify) + disp.extension_add_subevent(info.first_event + RRNotify, RRNotify_OutputChange, OutputChangeNotify) + disp.extension_add_subevent(info.first_event + RRNotify, RRNotify_OutputProperty, OutputPropertyNotify) + + disp.extension_add_error(BadRROutput, BadRROutputError) + disp.extension_add_error(BadRRCrtc, BadRRCrtcError) + disp.extension_add_error(BadRRMode, BadRRModeError) diff --git a/Xlib/ext/record.py b/Xlib/ext/record.py index a6a34e00..638a5b38 100644 --- a/Xlib/ext/record.py +++ b/Xlib/ext/record.py @@ -2,21 +2,23 @@ # # Copyright (C) 2006 Alex Badea # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA -from Xlib import X from Xlib.protocol import rq extname = 'RECORD' @@ -43,8 +45,10 @@ rq.Card16('first'), rq.Card16('last')) Record_ExtRange = rq.Struct( - rq.Object('major_range', Record_Range8), - rq.Object('minor_range', Record_Range16)) + rq.Card8('major_range_first'), + rq.Card8('major_range_last'), + rq.Card16('minor_range_first'), + rq.Card16('minor_range_last')) Record_Range = rq.Struct( rq.Object('core_requests', Record_Range8), rq.Object('core_replies', Record_Range8), @@ -71,7 +75,7 @@ def pack_value(self, val): return val, len(val), None def parse_binary_value(self, data, display, length, format): - return str(data), '' + return data, '' class GetVersion(rq.ReplyRequest): @@ -212,7 +216,7 @@ class EnableContext(rq.ReplyRequest): def __init__(self, callback, *args, **keys): self._callback = callback - apply(rq.ReplyRequest.__init__, (self, ) + args, keys) + rq.ReplyRequest.__init__(self, *args, **keys) def _parse_response(self, data): r, d = self._reply.parse_binary(data, self._display) diff --git a/Xlib/ext/res.py b/Xlib/ext/res.py new file mode 100644 index 00000000..f2c4e9fe --- /dev/null +++ b/Xlib/ext/res.py @@ -0,0 +1,288 @@ +# Xlib.ext.res -- X-Resource extension module +# +# Copyright (C) 2021 Aleksei Bavshin +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 51 Franklin Street, +# Fifth Floor, +# Boston, MA 02110-1301 USA + +"""X-Resource extension allows a client to query the X server about its usage +of various resources. + +For detailed description see any of the following documents. +Protocol specification: + https://www.x.org/releases/current/doc/resourceproto/resproto.txt +XCB Protocol specification: + https://cgit.freedesktop.org/xcb/proto/tree/src/res.xml +""" +from Xlib.protocol import rq + +RES_MAJOR_VERSION = 1 +RES_MINOR_VERSION = 2 + +extname = "X-Resource" + +# v1.0 +ResQueryVersion = 0 +ResQueryClients = 1 +ResQueryClientResources = 2 +ResQueryClientPixmapBytes = 3 +# v1.2 +ResQueryClientIds = 4 +ResQueryResourceBytes = 5 + + +class QueryVersion(rq.ReplyRequest): + _request = rq.Struct( + rq.Card8("opcode"), + rq.Opcode(ResQueryVersion), + rq.RequestLength(), + rq.Card8("client_major"), + rq.Card8("client_minor"), + rq.Pad(2)) + _reply = rq.Struct( + rq.ReplyCode(), + rq.Pad(1), + rq.Card16("sequence_number"), + rq.ReplyLength(), + rq.Card16("server_major"), + rq.Card16("server_minor"), + rq.Pad(20)) + + +def query_version(self, client_major=RES_MAJOR_VERSION, + client_minor=RES_MINOR_VERSION): + """ Query the protocol version supported by the X server. + + The client sends the highest supported version to the server and the + server sends the highest version it supports, but no higher than the + requested version.""" + return QueryVersion( + display=self.display, + opcode=self.display.get_extension_major(extname), + client_major=client_major, + client_minor=client_minor) + + +Client = rq.Struct( + rq.Card32("resource_base"), + rq.Card32("resource_mask")) + + +class QueryClients(rq.ReplyRequest): + _request = rq.Struct( + rq.Card8("opcode"), + rq.Opcode(ResQueryClients), + rq.RequestLength()) + _reply = rq.Struct( + rq.ReplyCode(), + rq.Pad(1), + rq.Card16("sequence_number"), + rq.ReplyLength(), + rq.LengthOf("clients", 4), + rq.Pad(20), + rq.List("clients", Client)) + + +def query_clients(self): + """Request the list of all currently connected clients.""" + return QueryClients( + display=self.display, + opcode=self.display.get_extension_major(extname)) + + +Type = rq.Struct( + rq.Card32("resource_type"), + rq.Card32("count")) + + +class QueryClientResources(rq.ReplyRequest): + _request = rq.Struct( + rq.Card8("opcode"), + rq.Opcode(ResQueryClientResources), + rq.RequestLength(), + rq.Card32("client")) + _reply = rq.Struct( + rq.ReplyCode(), + rq.Pad(1), + rq.Card16("sequence_number"), + rq.ReplyLength(), + rq.LengthOf("types", 4), + rq.Pad(20), + rq.List("types", Type)) + + +def query_client_resources(self, client): + """Request the number of resources owned by a client. + + The server will return the counts of each type of resource. + """ + return QueryClientResources( + display=self.display, + opcode=self.display.get_extension_major(extname), + client=client) + + +class QueryClientPixmapBytes(rq.ReplyRequest): + _request = rq.Struct( + rq.Card8("opcode"), + rq.Opcode(ResQueryClientPixmapBytes), + rq.RequestLength(), + rq.Card32("client")) + _reply = rq.Struct( + rq.ReplyCode(), + rq.Pad(1), + rq.Card16("sequence_number"), + rq.ReplyLength(), + rq.Card32("bytes"), + rq.Card32("bytes_overflow"), + rq.Pad(16)) + + +def query_client_pixmap_bytes(self, client): + """Query the pixmap usage of some client. + + The returned number is a sum of memory usage of each pixmap that can be + attributed to the given client. + """ + return QueryClientPixmapBytes( + display=self.display, + opcode=self.display.get_extension_major(extname), + client=client) + + +class SizeOf(rq.LengthOf): + """A SizeOf stores the size in bytes of some other Field whose size + may vary, e.g. List + """ + def __init__(self, name, size, item_size): + rq.LengthOf.__init__(self, name, size) + self.item_size = item_size + + def parse_value(self, length, display): + return length // self.item_size + + +ClientXIDMask = 1 << 0 +LocalClientPIDMask = 1 << 1 + + +ClientIdSpec = rq.Struct( + rq.Card32("client"), + rq.Card32("mask")) + + +ClientIdValue = rq.Struct( + rq.Object("spec", ClientIdSpec), + SizeOf("value", 4, 4), + rq.List("value", rq.Card32Obj)) + + +class QueryClientIds(rq.ReplyRequest): + _request = rq.Struct( + rq.Card8("opcode"), + rq.Opcode(ResQueryClientIds), + rq.RequestLength(), + rq.LengthOf("specs", 4), + rq.List("specs", ClientIdSpec)) + _reply = rq.Struct( + rq.ReplyCode(), + rq.Pad(1), + rq.Card16("sequence_number"), + rq.ReplyLength(), + rq.LengthOf("ids", 4), + rq.Pad(20), + rq.List("ids", ClientIdValue)) + + +def query_client_ids(self, specs): + """Request to identify a given set of clients with some identification method. + + The request sends a list of specifiers that select clients and + identification methods to server. The server then tries to identify the + chosen clients using the identification methods specified for each client. + The server returns IDs for those clients that were successfully identified. + """ + return QueryClientIds( + display=self.display, + opcode=self.display.get_extension_major(extname), + specs=specs) + + +ResourceIdSpec = rq.Struct( + rq.Card32("resource"), + rq.Card32("type")) + + +ResourceSizeSpec = rq.Struct( + # inline struct ResourceIdSpec to work around + # a parser bug with nested objects + rq.Card32("resource"), + rq.Card32("type"), + rq.Card32("bytes"), + rq.Card32("ref_count"), + rq.Card32("use_count")) + + +ResourceSizeValue = rq.Struct( + rq.Object("size", ResourceSizeSpec), + rq.LengthOf("cross_references", 4), + rq.List("cross_references", ResourceSizeSpec)) + + +class QueryResourceBytes(rq.ReplyRequest): + _request = rq.Struct( + rq.Card8("opcode"), + rq.Opcode(ResQueryResourceBytes), + rq.RequestLength(), + rq.Card32("client"), + rq.LengthOf("specs", 4), + rq.List("specs", ResourceIdSpec)) + _reply = rq.Struct( + rq.ReplyCode(), + rq.Pad(1), + rq.Card16("sequence_number"), + rq.ReplyLength(), + rq.LengthOf("sizes", 4), + rq.Pad(20), + rq.List("sizes", ResourceSizeValue)) + + +def query_resource_bytes(self, client, specs): + """Query the sizes of resources from X server. + + The request sends a list of specifiers that selects resources for size + calculation. The server tries to calculate the sizes of chosen resources + and returns an estimate for a resource only if the size could be determined + """ + return QueryResourceBytes( + display=self.display, + opcode=self.display.get_extension_major(extname), + client=client, + specs=specs) + + +def init(disp, info): + disp.extension_add_method("display", "res_query_version", query_version) + disp.extension_add_method("display", "res_query_clients", query_clients) + disp.extension_add_method("display", "res_query_client_resources", + query_client_resources) + disp.extension_add_method("display", "res_query_client_pixmap_bytes", + query_client_pixmap_bytes) + disp.extension_add_method("display", "res_query_client_ids", + query_client_ids) + disp.extension_add_method("display", "res_query_resource_bytes", + query_resource_bytes) diff --git a/Xlib/ext/screensaver.py b/Xlib/ext/screensaver.py new file mode 100644 index 00000000..12f4325c --- /dev/null +++ b/Xlib/ext/screensaver.py @@ -0,0 +1,198 @@ +# Xlib.ext.screensaver -- X ScreenSaver extension module +# +# Copyright (C) 2022 Vladimir Panteleev +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 51 Franklin Street, +# Fifth Floor, +# Boston, MA 02110-1301 USA + +"""This extension allows registering the client as an X screensaver, +or query information about the current screensaver. + +For detailed description see any of the following documents. +Protocol specification: + https://www.x.org/releases/X11R7.7/doc/scrnsaverproto/saver.html +XCB Protocol specification: + https://cgit.freedesktop.org/xcb/proto/tree/src/screensaver.xml + +""" + +from Xlib import X +from Xlib.protocol import rq, structs + +extname = 'MIT-SCREEN-SAVER' + +# Event members +NotifyMask = 1 +CycleMask = 2 + +# Notify state +StateOff = 0 +StateOn = 1 +StateCycle = 2 + +# Notify kind +KindBlanked = 0 +KindInternal = 1 +KindExternal = 2 + +class QueryVersion(rq.ReplyRequest): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(0), + rq.RequestLength(), + rq.Card8('major_version'), + rq.Card8('minor_version'), + rq.Pad(2), + ) + + _reply = rq.Struct( + rq.ReplyCode(), + rq.Pad(1), + rq.Card16('sequence_number'), + rq.ReplyLength(), + rq.Card16('major_version'), + rq.Card16('minor_version'), + rq.Pad(20), + ) + +def query_version(self): + return QueryVersion(display=self.display, + opcode=self.display.get_extension_major(extname), + major_version=1, + minor_version=0) + + +class QueryInfo(rq.ReplyRequest): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(1), + rq.RequestLength(), + rq.Drawable('drawable'), + ) + + _reply = rq.Struct( + rq.ReplyCode(), + rq.Card8('state'), + rq.Card16('sequence_number'), + rq.ReplyLength(), + rq.Window('saver_window'), + rq.Card32('til_or_since'), + rq.Card32('idle'), + rq.Card32('event_mask'), # rq.Set('event_mask', 4, (NotifyMask, CycleMask)), + rq.Card8('kind'), + rq.Pad(7), + ) + +def query_info(self): + return QueryInfo(display=self.display, + opcode=self.display.get_extension_major(extname), + drawable=self, + ) + + +class SelectInput(rq.Request): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(2), + rq.RequestLength(), + rq.Drawable('drawable'), + rq.Card32('event_mask'), # rq.Set('event_mask', 4, (NotifyMask, CycleMask)), + ) + +def select_input(self, mask): + return SelectInput(display=self.display, + opcode=self.display.get_extension_major(extname), + drawable=self, + event_mask=mask, + ) + + +class SetAttributes(rq.Request): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(3), + rq.RequestLength(), + rq.Drawable('drawable'), + rq.Int16('x'), + rq.Int16('y'), + rq.Card16('width'), + rq.Card16('height'), + rq.Card16('border_width'), + rq.Set('window_class', 1, (X.CopyFromParent, X.InputOutput, X.InputOnly)), + rq.Card8('depth'), + rq.Card32('visual'), + structs.WindowValues('attrs'), + ) + +def set_attributes(self, x, y, width, height, border_width, + window_class = X.CopyFromParent, + depth = X.CopyFromParent, + visual = X.CopyFromParent, + onerror = None, + **keys): + return SetAttributes(display=self.display, + onerror = onerror, + opcode=self.display.get_extension_major(extname), + drawable=self, + x = x, + y = y, + width = width, + height = height, + border_width = border_width, + window_class = window_class, + depth = depth, + visual = visual, + attrs = keys) + + +class UnsetAttributes(rq.Request): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(4), + rq.RequestLength(), + rq.Drawable('drawable'), + ) + +def unset_attributes(self, onerror = None): + return UnsetAttributes(display=self.display, + onerror = onerror, + opcode=self.display.get_extension_major(extname), + drawable=self) + + +class Notify(rq.Event): + _code = None + _fields = rq.Struct( + rq.Card8('type'), + rq.Set('state', 1, (StateOff, StateOn, StateCycle)), + rq.Card16('sequence_number'), + rq.Card32('timestamp'), + rq.Window('root'), + rq.Window('window'), + rq.Set('kind', 1, (KindBlanked, KindInternal, KindExternal)), + rq.Bool('forced'), + rq.Pad(14), + ) + +def init(disp, info): + disp.extension_add_method('display', 'screensaver_query_version', query_version) + disp.extension_add_method('drawable', 'screensaver_query_info', query_info) + disp.extension_add_method('drawable', 'screensaver_select_input', select_input) + disp.extension_add_method('drawable', 'screensaver_set_attributes', set_attributes) + disp.extension_add_method('drawable', 'screensaver_unset_attributes', unset_attributes) + + disp.extension_add_event(info.first_event + 0, Notify) diff --git a/Xlib/ext/security.py b/Xlib/ext/security.py index d0be663d..a8210171 100644 --- a/Xlib/ext/security.py +++ b/Xlib/ext/security.py @@ -3,19 +3,22 @@ # Copyright (C) 2010-2013 Outpost Embedded, LLC # Forest Bond # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA ''' A partial implementation of the SECURITY extension. Support for the @@ -72,7 +75,7 @@ class SecurityGenerateAuthorization(rq.ReplyRequest): rq.LengthOf('auth_data', 2), rq.Card32('value_mask'), rq.String8('auth_proto'), - rq.String8('auth_data'), + rq.Binary('auth_data'), rq.List('values', rq.Card32Obj) ) _reply = rq.Struct(rq.ReplyCode(), @@ -82,11 +85,11 @@ class SecurityGenerateAuthorization(rq.ReplyRequest): AUTHID('authid'), rq.LengthOf('auth_data_return', 2), rq.Pad(18), - rq.String8('auth_data_return') + rq.Binary('auth_data_return') ) -def generate_authorization(self, auth_proto, auth_data='', timeout=None, +def generate_authorization(self, auth_proto, auth_data=b'', timeout=None, trust_level=None, group=None, event_mask=None): value_mask = 0 values = [] diff --git a/Xlib/ext/shape.py b/Xlib/ext/shape.py index fd0d157c..05a517ac 100644 --- a/Xlib/ext/shape.py +++ b/Xlib/ext/shape.py @@ -1,334 +1,297 @@ -# Xlib.ext.shape -- SHAPE extension module -# -# Copyright (C) 2002 Jeffrey Boser -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - -# Constants to use -# -# Regions of a window -ShapeBounding = 0 # the 'edge' of a shaped window -ShapeClip = 1 # the clipping region -# Shape Operations -ShapeSet = 0 # Set the region unmodified (dest=src) -ShapeUnion = 1 # Add the new region to the old (dest=src|dest) -ShapeIntersect = 2 # Use the intersection (dest=src&dest) -ShapeSubtract = 3 # remove region (dest = dest - intersect) -ShapeInvert = 4 # opposite of subtract (dest = src - intersect) -# Events -ShapeNotifyMask = (1<<0) #a keypress mask? -ShapeNotify = 0 #still unsure of these values - -# How to Use -# The basic functions that change the shapes of things are: -# shape_rectangles (uses a set of rectangles as the source) -# operation, region, ordering, rects -# shape_mask (uses a bitmap as the source) -# operation, region, x_offset, y_offset, bitmap -# shape_combine (uses a window as the source) -# operation, src_region, dest_region, x_offset, y_offset, src_window -# shape_offset (moves the region) -# region, x_offset, y_offset -# The functions to find stuff out (these three return mappings of field/values): -# shape_query_version (shape extension version) -# major_version, minor_version -# shape_query_extents (rectangle boundaries of a window's regions) -# clip_shaped, clip_x, clip_y, clip_width, clip_height, -# bounding_shaped, bounding_x, bounding_y, bounding_width, bounding_height -# shape_input_selected (if the window products shapenotify events) -# enabled -# shape_get_rectangles (the rectangles set by shape_rectangles) -# ordering, rects -# And to turn on shape notify events: -# shape_select_input -# enable - - - -from Xlib import X +# Automatically generated file; DO NOT EDIT. +# Generated from: /usr/share/xcb/shape.xml + from Xlib.protocol import rq, structs + extname = 'SHAPE' -class QueryVersion(rq.ReplyRequest): - _request = rq.Struct( - rq.Card8('opcode'), - rq.Opcode(0), - rq.RequestLength(), - ) - _reply = rq.Struct( - rq.ReplyCode(), - rq.Pad(1), - rq.Card16('sequence_number'), - rq.ReplyLength(), - rq.Card16('major_version'), - rq.Card16('minor_version'), - rq.Pad(20), - ) - -def query_version(self): - return QueryVersion( - display = self.display, - opcode = self.display.get_extension_major(extname), - ) +OP = rq.Card8 +class SO: + Set = 0 + Union = 1 + Intersect = 2 + Subtract = 3 + Invert = 4 +class SK: + Bounding = 0 + Clip = 1 + Input = 2 -class Rectangles(rq.Request): - _request = rq.Struct( - rq.Card8('opcode'), - rq.Opcode(1), - rq.RequestLength(), - rq.Card8('operation'), - rq.Set('region', 1, (ShapeBounding, ShapeClip)), - rq.Card8('ordering'), - rq.Pad(1), - rq.Window('window'), - rq.Int16('x'), - rq.Int16('y'), - rq.List('rectangles', structs.Rectangle), - ) - -def rectangles(self, region, operation, ordering, x, y, rectangles): - Rectangles( - display = self.display, - opcode = self.display.get_extension_major(extname), - operation = operation, - region = region, - ordering = ordering, - window = self.id, - x = x, - y = y, - rectangles = rectangles, - ) +class KIND(rq.Set): + def __init__(self, name): + super(KIND, self).__init__(name, 1, + values=(SK.Bounding, + SK.Clip, + SK.Input)) +class NotifyEventData(rq.Event): + _code = None + _fields = rq.Struct( + rq.Card8('type'), + KIND('shape_kind'), + rq.Card16('sequence_number'), + rq.Window('affected_window'), + rq.Int16('extents_x'), + rq.Int16('extents_y'), + rq.Card16('extents_width'), + rq.Card16('extents_height'), + rq.Card32('server_time'), + rq.Card8('shaped'), + rq.Pad(11), + ) + +class QueryVersion(rq.ReplyRequest): -class Mask(rq.Request): _request = rq.Struct( - rq.Card8('opcode'), - rq.Opcode(2), - rq.RequestLength(), - rq.Card8('operation'), - rq.Set('region', 1, (ShapeBounding, ShapeClip)), - rq.Pad(2), - rq.Window('window'), - rq.Int16('x'), - rq.Int16('y'), - rq.Pixmap('source', (X.NONE, )), - ) - -def mask(self, operation, region, x, y, source): - Mask(display = self.display, - opcode = self.display.get_extension_major(extname), - window = self.id, - operation = operation, - region = region, - x = x, - y = y, - source = source, - ) + rq.Card8('opcode'), + rq.Opcode(0), + rq.RequestLength(), + ) + + _reply = rq.Struct( + rq.ReplyCode(), + rq.Pad(1), + rq.Card16('sequence_number'), + rq.ReplyLength(), + rq.Card16('major_version'), + rq.Card16('minor_version'), + ) +class Rectangles(rq.Request): -class Combine(rq.Request): _request = rq.Struct( - rq.Card8('opcode'), - rq.Opcode(3), - rq.RequestLength(), - rq.Card8('operation'), - rq.Set('dest_region', 1, (ShapeBounding, ShapeClip)), - rq.Set('source_region', 1, (ShapeBounding, ShapeClip)), - rq.Pad(1), - rq.Window('dest'), - rq.Int16('x'), - rq.Int16('y'), - rq.Window('source'), - ) - -def combine(self, operation, region, source, source_region, x, y): - Combine( - display = self.display, - opcode = self.display.get_extension_major(extname), - operation = operation, - dest_region = region, - source_region = source_region, - dest = self.id, - x = x, - y = y, - source = source, - ) + rq.Card8('opcode'), + rq.Opcode(1), + rq.RequestLength(), + OP('operation'), + KIND('destination_kind'), + rq.Card8('ordering'), + rq.Pad(1), + rq.Window('destination_window'), + rq.Int16('x_offset'), + rq.Int16('y_offset'), + rq.List('rectangles', structs.Rectangle, pad=0), + ) +class Mask(rq.Request): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(2), + rq.RequestLength(), + OP('operation'), + KIND('destination_kind'), + rq.Pad(2), + rq.Window('destination_window'), + rq.Int16('x_offset'), + rq.Int16('y_offset'), + rq.Pixmap('source_bitmap'), + ) + +class Combine(rq.Request): -class Offset(rq.Request): _request = rq.Struct( - rq.Card8('opcode'), - rq.Opcode(4), - rq.RequestLength(), - rq.Set('region', 1, (ShapeBounding, ShapeClip)), - rq.Pad(3), - rq.Window('window'), - rq.Int16('x'), - rq.Int16('y'), - ) - -def offset(self, region, x, y): - Offset( - display = self.display, - opcode = self.display.get_extension_major(extname), - region = region, - window = self.id, - x = x, - y = y, - ) + rq.Card8('opcode'), + rq.Opcode(3), + rq.RequestLength(), + OP('operation'), + KIND('destination_kind'), + KIND('source_kind'), + rq.Pad(1), + rq.Window('destination_window'), + rq.Int16('x_offset'), + rq.Int16('y_offset'), + rq.Window('source_window'), + ) +class Offset(rq.Request): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(4), + rq.RequestLength(), + KIND('destination_kind'), + rq.Pad(3), + rq.Window('destination_window'), + rq.Int16('x_offset'), + rq.Int16('y_offset'), + ) class QueryExtents(rq.ReplyRequest): + _request = rq.Struct( - rq.Card8('opcode'), - rq.Opcode(5), - rq.RequestLength(), - rq.Window('window'), - ) + rq.Card8('opcode'), + rq.Opcode(5), + rq.RequestLength(), + rq.Window('destination_window'), + ) _reply = rq.Struct( - rq.ReplyCode(), - rq.Pad(1), - rq.Card16('sequence_number'), - rq.ReplyLength(), - rq.Bool('bounding_shaped'), - rq.Bool('clip_shaped'), - rq.Pad(2), - rq.Int16('bounding_x'), - rq.Int16('bounding_y'), - rq.Card16('bounding_width'), - rq.Card16('bounding_height'), - rq.Int16('clip_x'), - rq.Int16('clip_y'), - rq.Card16('clip_width'), - rq.Card16('clip_height'), - rq.Pad(4), - ) - -def query_extents(self): - return QueryExtents( - display = self.display, - opcode = self.display.get_extension_major(extname), - window = self.id, - ) - + rq.ReplyCode(), + rq.Pad(1), + rq.Card16('sequence_number'), + rq.ReplyLength(), + rq.Card8('bounding_shaped'), + rq.Card8('clip_shaped'), + rq.Pad(2), + rq.Int16('bounding_shape_extents_x'), + rq.Int16('bounding_shape_extents_y'), + rq.Card16('bounding_shape_extents_width'), + rq.Card16('bounding_shape_extents_height'), + rq.Int16('clip_shape_extents_x'), + rq.Int16('clip_shape_extents_y'), + rq.Card16('clip_shape_extents_width'), + rq.Card16('clip_shape_extents_height'), + ) class SelectInput(rq.Request): - _request = rq.Struct( - rq.Card8('opcode'), - rq.Opcode(6), - rq.RequestLength(), - rq.Window('window'), - rq.Bool('enable'), - rq.Pad(3), - ) - -def select_input(self, enable = 1): - SelectInput( - display = self.display, - opcode = self.display.get_extension_major(extname), - window = self.id, - enable = enable, - ) + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(6), + rq.RequestLength(), + rq.Window('destination_window'), + rq.Card8('enable'), + rq.Pad(3), + ) class InputSelected(rq.ReplyRequest): + _request = rq.Struct( - rq.Card8('opcode'), - rq.Opcode(7), - rq.RequestLength(), - rq.Window('window'), - ) + rq.Card8('opcode'), + rq.Opcode(7), + rq.RequestLength(), + rq.Window('destination_window'), + ) _reply = rq.Struct( - rq.ReplyCode(), - rq.Bool('enabled'), - rq.Card16('sequence_number'), - rq.ReplyLength(), - rq.Pad(24), - ) - -def input_selected(self): - reply = InputSelected( - display = self.display, - opcode = self.display.get_extension_major(extname), - window = self.id, - ) - return reply.enabled - + rq.ReplyCode(), + rq.Card8('enabled'), + rq.Card16('sequence_number'), + rq.ReplyLength(), + ) class GetRectangles(rq.ReplyRequest): + _request = rq.Struct( - rq.Card8('opcode'), - rq.Opcode(8), - rq.RequestLength(), - rq.Window('window'), - rq.Set('region', 1, (ShapeBounding, ShapeClip)), - rq.Pad(3), - ) + rq.Card8('opcode'), + rq.Opcode(8), + rq.RequestLength(), + rq.Window('window'), + KIND('source_kind'), + rq.Pad(3), + ) _reply = rq.Struct( - rq.ReplyCode(), - rq.Card8('ordering'), - rq.Card16('sequence_number'), - rq.ReplyLength(), - rq.LengthOf('rectangles', 4), - rq.Pad(20), - rq.List('rectangles', structs.Rectangle), - ) - -def get_rectangles(self, region): + rq.ReplyCode(), + rq.Card8('ordering'), + rq.Card16('sequence_number'), + rq.ReplyLength(), + rq.LengthOf('rectangles', 4), + rq.Pad(20), + rq.List('rectangles', structs.Rectangle, pad=0), + ) + +class Event: + # Sub events. + Notify = 0 + +def combine(self, operation, destination_kind, source_kind, x_offset, y_offset): + Combine( + display=self.display, + opcode=self.display.get_extension_major(extname), + source_window=self, + operation=operation, + destination_kind=destination_kind, + source_kind=source_kind, + x_offset=x_offset, + y_offset=y_offset, + ) + +def get_rectangles(self, source_kind): return GetRectangles( - display = self.display, - opcode = self.display.get_extension_major(extname), - window = self.id, - region = region, - ) + display=self.display, + opcode=self.display.get_extension_major(extname), + window=self, + source_kind=source_kind, + ) + +def input_selected(self, ): + return InputSelected( + display=self.display, + opcode=self.display.get_extension_major(extname), + destination_window=self, + ) + +def mask(self, operation, destination_kind, x_offset, y_offset, source_bitmap): + Mask( + display=self.display, + opcode=self.display.get_extension_major(extname), + destination_window=self, + operation=operation, + destination_kind=destination_kind, + x_offset=x_offset, + y_offset=y_offset, + source_bitmap=source_bitmap, + ) + +def offset(self, destination_kind, x_offset, y_offset): + Offset( + display=self.display, + opcode=self.display.get_extension_major(extname), + destination_window=self, + destination_kind=destination_kind, + x_offset=x_offset, + y_offset=y_offset, + ) + +def query_extents(self, ): + return QueryExtents( + display=self.display, + opcode=self.display.get_extension_major(extname), + destination_window=self, + ) +def query_version(self, ): + return QueryVersion( + display=self.display, + opcode=self.display.get_extension_major(extname), + ) -class ShapeNotify(rq.Event): - _code = None - _fields = rq.Struct( rq.Card8('type'), - rq.Set('region', 1, (ShapeBounding, ShapeClip)), - rq.Card16('sequence_number'), - rq.Window('window'), - rq.Int16('x'), - rq.Int16('y'), - rq.Card16('width'), - rq.Card16('height'), - rq.Card32('time'), - rq.Bool('shaped'), - rq.Pad(11), - ) +def rectangles(self, operation, destination_kind, ordering, x_offset, y_offset, rectangles): + Rectangles( + display=self.display, + opcode=self.display.get_extension_major(extname), + destination_window=self, + operation=operation, + destination_kind=destination_kind, + ordering=ordering, + x_offset=x_offset, + y_offset=y_offset, + rectangles=rectangles, + ) + +def select_input(self, enable): + SelectInput( + display=self.display, + opcode=self.display.get_extension_major(extname), + destination_window=self, + enable=enable, + ) def init(disp, info): - disp.extension_add_method('display', 'shape_query_version', query_version ) - disp.extension_add_method('window', 'shape_rectangles', rectangles ) - disp.extension_add_method('window', 'shape_mask', mask ) - disp.extension_add_method('window', 'shape_combine', combine ) - disp.extension_add_method('window', 'shape_offset', offset ) - disp.extension_add_method('window', 'shape_query_extents', query_extents ) - disp.extension_add_method('window', 'shape_select_input', select_input ) - disp.extension_add_method('window', 'shape_input_selected', input_selected ) - disp.extension_add_method('window', 'shape_get_rectangles', get_rectangles ) - - disp.extension_add_event(info.first_event, ShapeNotify) + disp.extension_add_method('window', 'shape_combine', combine) + disp.extension_add_method('window', 'shape_get_rectangles', get_rectangles) + disp.extension_add_method('window', 'shape_input_selected', input_selected) + disp.extension_add_method('window', 'shape_mask', mask) + disp.extension_add_method('window', 'shape_offset', offset) + disp.extension_add_method('window', 'shape_query_extents', query_extents) + disp.extension_add_method('display', 'shape_query_version', query_version) + disp.extension_add_method('window', 'shape_rectangles', rectangles) + disp.extension_add_method('window', 'shape_select_input', select_input) + disp.extension_add_event(info.first_event + Event.Notify, NotifyEventData, 'ShapeNotify') + diff --git a/Xlib/ext/xfixes.py b/Xlib/ext/xfixes.py index 671bcafa..8b3c35fe 100644 --- a/Xlib/ext/xfixes.py +++ b/Xlib/ext/xfixes.py @@ -3,29 +3,44 @@ # Copyright (C) 2010-2011 Outpost Embedded, LLC # Forest Bond # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA ''' A partial implementation of the XFIXES extension. Only the HideCursor and -ShowCursor requests are provided. +ShowCursor requests and SelectionNotify events are provided. ''' from Xlib.protocol import rq extname = 'XFIXES' +XFixesSelectionNotify = 0 +XFixesCursorNotify = 1 + +XFixesSetSelectionOwnerNotifyMask = (1 << 0) +XFixesSelectionWindowDestroyNotifyMask = (1 << 1) +XFixesSelectionClientCloseNotifyMask = (1 << 2) +XFixesDisplayCursorNotifyMask = (1 << 0) + +XFixesSetSelectionOwnerNotify = 0 +XFixesSelectionWindowDestroyNotify = 1 +XFixesSelectionClientCloseNotify = 2 +XFixesDisplayCursorNotify = 0 class QueryVersion(rq.ReplyRequest): _request = rq.Struct(rq.Card8('opcode'), @@ -77,8 +92,109 @@ def show_cursor(self): opcode=self.display.get_extension_major(extname), window=self) +class SelectSelectionInput(rq.Request): + _request = rq.Struct(rq.Card8('opcode'), + rq.Opcode(2), + rq.RequestLength(), + rq.Window('window'), + rq.Card32('selection'), + rq.Card32('mask') + ) + +def select_selection_input(self, window, selection, mask): + return SelectSelectionInput(opcode=self.display.get_extension_major(extname), + display=self.display, + window=window, + selection=selection, + mask=mask) + + +class SelectionNotify(rq.Event): + _code = None + _fields = rq.Struct(rq.Card8('type'), + rq.Card8('sub_code'), + rq.Card16('sequence_number'), + rq.Window('window'), + rq.Window('owner'), + rq.Card32('selection'), + rq.Card32('timestamp'), + rq.Card32('selection_timestamp'), + rq.Pad(8)) + + +class SetSelectionOwnerNotify(SelectionNotify): + pass + + +class SelectionWindowDestroyNotify(SelectionNotify): + pass + + +class SelectionClientCloseNotify(SelectionNotify): + pass + + +class SelectCursorInput(rq.Request): + _request = rq.Struct(rq.Card8('opcode'), + rq.Opcode(3), + rq.RequestLength(), + rq.Window('window'), + rq.Card32('mask') + ) + +def select_cursor_input(self, window, mask): + return SelectCursorInput(opcode=self.display.get_extension_major(extname), + display=self.display, + window=window, + cursor_serial=0, + mask=mask) + + +class GetCursorImage(rq.ReplyRequest): + _request = rq.Struct(rq.Card8('opcode'), + rq.Opcode(4), + rq.RequestLength() + ) + _reply = rq.Struct(rq.ReplyCode(), + rq.Pad(1), + rq.Card16('sequence_number'), + rq.ReplyLength(), + rq.Int16('x'), + rq.Int16('y'), + rq.Card16('width'), + rq.Card16('height'), + rq.Card16('xhot'), + rq.Card16('yhot'), + rq.Card32('cursor_serial'), + rq.Pad(8), + rq.List('cursor_image', rq.Card32) + ) + +def get_cursor_image(self, window): + return GetCursorImage(opcode=self.display.get_extension_major(extname), + display=self.display, + ) + + +class DisplayCursorNotify(rq.Event): + _code = None + _fields = rq.Struct(rq.Card8('type'), + rq.Card8('sub_code'), + rq.Card16('sequence_number'), + rq.Window('window'), + rq.Card32('cursor_serial'), + rq.Card32('timestamp')) + def init(disp, info): + disp.extension_add_method('display', 'xfixes_select_selection_input', select_selection_input) disp.extension_add_method('display', 'xfixes_query_version', query_version) disp.extension_add_method('window', 'xfixes_hide_cursor', hide_cursor) disp.extension_add_method('window', 'xfixes_show_cursor', show_cursor) + disp.extension_add_method('display', 'xfixes_select_cursor_input', select_cursor_input) + disp.extension_add_method('display', 'xfixes_get_cursor_image', get_cursor_image) + + disp.extension_add_subevent(info.first_event + XFixesSelectionNotify, XFixesSetSelectionOwnerNotify, SetSelectionOwnerNotify) + disp.extension_add_subevent(info.first_event + XFixesSelectionNotify, XFixesSelectionWindowDestroyNotify, SelectionWindowDestroyNotify) + disp.extension_add_subevent(info.first_event + XFixesSelectionNotify, XFixesSelectionClientCloseNotify, SelectionClientCloseNotify) + disp.extension_add_subevent(info.first_event + XFixesCursorNotify, XFixesDisplayCursorNotify, DisplayCursorNotify) diff --git a/Xlib/ext/xinerama.py b/Xlib/ext/xinerama.py index 65d7bd41..dcb78b89 100644 --- a/Xlib/ext/xinerama.py +++ b/Xlib/ext/xinerama.py @@ -2,20 +2,22 @@ # # Copyright (C) 2006 Mike Meyer # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA """Xinerama - provide access to the Xinerama extension information. @@ -28,12 +30,11 @@ this is untested because I don't have a server that implements it. The functions loosely follow the libXineram functions. Mostly, they -return an rq.Struct in lieue of passing in pointers that get data from +return an rq.Struct in lieu of passing in pointers that get data from the rq.Struct crammed into them. The exception is isActive, which returns the state information - because that's what libXinerama does.""" -from Xlib import X from Xlib.protocol import rq, structs extname = 'XINERAMA' diff --git a/Xlib/ext/xinput.py b/Xlib/ext/xinput.py index 119334a8..f9218064 100644 --- a/Xlib/ext/xinput.py +++ b/Xlib/ext/xinput.py @@ -3,27 +3,36 @@ # Copyright (C) 2012 Outpost Embedded, LLC # Forest Bond # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA ''' A very incomplete implementation of the XInput extension. ''' -import sys, array +import sys +import array +import struct + +# Python 2/3 compatibility. +from six import integer_types from Xlib.protocol import rq +from Xlib import X extname = 'XInputExtension' @@ -52,6 +61,7 @@ GrabtypeKeycode = 1 GrabtypeEnter = 2 GrabtypeFocusIn = 3 +GrabtypeTouchBegin = 4 AnyModifier = (1 << 31) AnyButton = 0 @@ -96,6 +106,8 @@ KeyClass = 0 ButtonClass = 1 ValuatorClass = 2 +ScrollClass = 3 +TouchClass = 8 KeyRepeat = (1 << 16) @@ -138,10 +150,37 @@ RawButtonReleaseMask = (1 << RawButtonRelease) RawMotionMask = (1 << RawMotion) +GrabModeSync = 0 +GrabModeAsync = 1 +GrabModeTouch = 2 + DEVICEID = rq.Card16 DEVICE = rq.Card16 DEVICEUSE = rq.Card8 +PROPERTY_TYPE_FLOAT = 'FLOAT' + +class FP1616(rq.Int32): + + def check_value(self, value): + return int(value * 65536.0) + + def parse_value(self, value, display): + return float(value) / float(1 << 16) + +class FP3232(rq.ValueField): + structcode = 'lL' + structvalues = 2 + + def check_value(self, value): + return value + + def parse_value(self, value, display): + integral, frac = value + ret = float(integral) + # optimised math.ldexp(float(frac), -32) + ret += float(frac) * (1.0 / (1 << 32)) + return ret class XIQueryVersion(rq.ReplyRequest): _request = rq.Struct( @@ -156,9 +195,9 @@ class XIQueryVersion(rq.ReplyRequest): rq.Pad(1), rq.Card16('sequence_number'), rq.ReplyLength(), - rq.Card32('major_version'), - rq.Card32('minor_version'), - rq.Pad(16), + rq.Card16('major_version'), + rq.Card16('minor_version'), + rq.Pad(20), ) @@ -170,12 +209,42 @@ def query_version(self): minor_version=0, ) +class Mask(rq.List): + + def __init__(self, name): + rq.List.__init__(self, name, rq.Card32, pad=0) + + def pack_value(self, val): + + mask_seq = array.array(rq.struct_to_array_codes['L']) + + if isinstance(val, integer_types): + # 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 + # array with just one item. For values too big to fit inside 4 + # bytes we build a longer array, being careful to maintain native + # byte order across the entire set of values. + if sys.byteorder == 'little': + def fun(val): + mask_seq.insert(0, val) + elif sys.byteorder == 'big': + fun = mask_seq.append + else: + raise AssertionError(sys.byteorder) + while val: + fun(val & 0xFFFFFFFF) + val = val >> 32 + else: + mask_seq.extend(val) + + return rq.encode_array(mask_seq), len(mask_seq), None EventMask = rq.Struct( - DEVICE('deviceid'), - rq.LengthOf('mask', 2), - rq.List('mask', rq.Card32), - ) + DEVICE('deviceid'), + rq.LengthOf('mask', 2), + Mask('mask'), +) class XISelectEvents(rq.Request): @@ -187,8 +256,7 @@ class XISelectEvents(rq.Request): rq.LengthOf('masks', 2), rq.Pad(2), rq.List('masks', EventMask), - ) - + ) def select_events(self, event_masks): ''' @@ -197,64 +265,513 @@ def select_events(self, event_masks): event_masks: Sequence of (deviceid, mask) pairs, where deviceid is a numerical device ID, or AllDevices or AllMasterDevices, and mask is either an unsigned - integer or sequence of 32 byte unsigned values + integer or sequence of 32 bits unsigned values ''' + return XISelectEvents( + display=self.display, + opcode=self.display.get_extension_major(extname), + window=self, + masks=event_masks, + ) + +AnyInfo = rq.Struct( + rq.Card16('type'), + rq.Card16('length'), + rq.Card16('sourceid'), + rq.Pad(2), +) + +class ButtonMask(object): + + def __init__(self, value, length): + self._value = value + self._length = length + + def __len__(self): + return self._length + + def __getitem__(self, key): + return self._value & (1 << key) + + def __str__(self): + return repr(self) + + def __repr__(self): + return '0b{value:0{width}b}'.format(value=self._value, + width=self._length) + +class ButtonState(rq.ValueField): + + structcode = None + + def __init__(self, name): + rq.ValueField.__init__(self, name) + + def parse_binary_value(self, data, display, length, fmt): + # Mask: bitfield of button states. + mask_len = 4 * ((((length + 7) >> 3) + 3) >> 2) + mask_data = data[:mask_len] + mask_value = 0 + for byte in reversed(struct.unpack('={0:d}B'.format(mask_len), mask_data)): + mask_value <<= 8 + mask_value |= byte + data = data[mask_len:] + assert (mask_value & 1) == 0 + return ButtonMask(mask_value >> 1, length), data + +ButtonInfo = rq.Struct( + rq.Card16('type'), + rq.Card16('length'), + rq.Card16('sourceid'), + rq.LengthOf(('state', 'labels'), 2), + ButtonState('state'), + rq.List('labels', rq.Card32), +) + +KeyInfo = rq.Struct( + rq.Card16('type'), + rq.Card16('length'), + rq.Card16('sourceid'), + rq.LengthOf('keycodes', 2), + rq.List('keycodes', rq.Card32), +) + +ValuatorInfo = rq.Struct( + rq.Card16('type'), + rq.Card16('length'), + rq.Card16('sourceid'), + rq.Card16('number'), + rq.Card32('label'), + FP3232('min'), + FP3232('max'), + FP3232('value'), + rq.Card32('resolution'), + rq.Card8('mode'), + rq.Pad(3), +) + +ScrollInfo = rq.Struct( + rq.Card16('type'), + rq.Card16('length'), + rq.Card16('sourceid'), + rq.Card16('number'), + rq.Card16('scroll_type'), + rq.Pad(2), + rq.Card32('flags'), + FP3232('increment'), +) + +TouchInfo = rq.Struct( + rq.Card16('type'), + rq.Card16('length'), + rq.Card16('sourceid'), + rq.Card8('mode'), + rq.Card8('num_touches'), +) + +INFO_CLASSES = { + KeyClass: KeyInfo, + ButtonClass: ButtonInfo, + ValuatorClass: ValuatorInfo, + ScrollClass: ScrollInfo, + TouchClass: TouchInfo, +} + +class ClassInfoClass(object): + + structcode = None + + def parse_binary(self, data, display): + class_type, length = struct.unpack('=HH', data[:4]) + class_struct = INFO_CLASSES.get(class_type, AnyInfo) + class_data, _ = class_struct.parse_binary(data, display) + data = data[length * 4:] + return class_data, data + +ClassInfo = ClassInfoClass() + +DeviceInfo = rq.Struct( + DEVICEID('deviceid'), + rq.Card16('use'), + rq.Card16('attachment'), + rq.LengthOf('classes', 2), + rq.LengthOf('name', 2), + rq.Bool('enabled'), + rq.Pad(1), + rq.String8('name', 4), + rq.List('classes', ClassInfo), +) + +class XIQueryDevice(rq.ReplyRequest): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(48), + rq.RequestLength(), + DEVICEID('deviceid'), + rq.Pad(2), + ) - masks = [] - for deviceid, mask in event_masks: - mask_seq = array.array(rq.struct_to_array_codes['L']) + _reply = rq.Struct( + rq.ReplyCode(), + rq.Pad(1), + rq.Card16('sequence_number'), + rq.ReplyLength(), + rq.LengthOf('devices', 2), + rq.Pad(22), + rq.List('devices', DeviceInfo), + ) - if isinstance(mask, (int, long)): - # 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 - # array with just one item. For values too big to fit inside 4 - # bytes we build a longer array, being careful to maintain native - # byte order across the entire set of values. - if sys.byteorder == 'little': - f = lambda v: mask_seq.insert(0, v) - elif sys.byteorder == 'big': - f = mask_seq.append - else: - raise AssertionError(sys.byteorder) - while mask: - f(mask & 0xFFFFFFFF) - mask = mask >> 32 - else: - mask_seq.extend(mask) +def query_device(self, deviceid): + return XIQueryDevice( + display=self.display, + opcode=self.display.get_extension_major(extname), + deviceid=deviceid, + ) - masks.append({'deviceid': deviceid, 'mask': mask_seq}) +class XIListProperties(rq.ReplyRequest): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(56), + rq.RequestLength(), + DEVICEID('deviceid'), + rq.Pad(2), + ) - return XISelectEvents( + _reply = rq.Struct( + rq.ReplyCode(), + rq.Pad(1), + rq.Card16('sequence_number'), + rq.ReplyLength(), + rq.LengthOf('atoms', 2), + rq.Pad(22), + rq.List('atoms', rq.Card32Obj), + ) + +def list_device_properties(self, deviceid): + return XIListProperties( display=self.display, opcode=self.display.get_extension_major(extname), - window=self, - masks=masks, - ) + deviceid=deviceid, + ) +class XIGetProperty(rq.ReplyRequest): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(59), + rq.RequestLength(), + DEVICEID('deviceid'), + rq.Card8('delete'), + rq.Pad(1), + rq.Card32('property'), + rq.Card32('type'), + rq.Card32('offset'), + rq.Card32('length'), + ) -HierarchyInfo = rq.Struct( + _reply = rq.Struct( + rq.ReplyCode(), + rq.Pad(1), + rq.Card16('sequence_number'), + rq.ReplyLength(), + rq.Card32('type'), + rq.Card32('bytes_after'), + rq.LengthOf('value', 4), + rq.Format('value', 1), + rq.Pad(11), + rq.PropertyData('value') + ) + +def get_device_property(self, deviceid, property, type, offset, length, delete=False): + return XIGetProperty( + display=self.display, + opcode=self.display.get_extension_major(extname), + deviceid=deviceid, + property=property, + type=type, + offset=offset, + length=length, + delete=delete, + ) + +class XIChangeProperty(rq.Request): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(57), + rq.RequestLength(), + DEVICEID('deviceid'), + rq.Card8('mode'), + rq.Format('value', 1), + rq.Card32('property'), + rq.Card32('type'), + rq.LengthOf('value', 4), + rq.PropertyData('value'), + ) + +def change_device_property(self, deviceid, property, type, mode, value): + return XIChangeProperty( + display=self.display, + opcode=self.display.get_extension_major(extname), + deviceid=deviceid, + property=property, + type=type, + mode=mode, + value=value, + ) + +class XIDeleteProperty(rq.Request): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(58), + rq.RequestLength(), DEVICEID('deviceid'), - DEVICEID('attachment'), - DEVICEUSE('type'), - rq.Bool('enabled'), rq.Pad(2), - rq.Card32('flags'), + rq.Card32('property'), + ) + +def delete_device_property(self, deviceid, property): + return XIDeleteProperty( + display=self.display, + opcode=self.display.get_extension_major(extname), + deviceid=deviceid, + property=property, + ) + +class XIGrabDevice(rq.ReplyRequest): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(51), + rq.RequestLength(), + rq.Window('grab_window'), + rq.Card32('time'), + rq.Cursor('cursor', (X.NONE, )), + DEVICEID('deviceid'), + rq.Set('grab_mode', 1, (GrabModeSync, GrabModeAsync)), + rq.Set('paired_device_mode', 1, (GrabModeSync, GrabModeAsync)), + rq.Bool('owner_events'), + rq.Pad(1), + rq.LengthOf('mask', 2), + Mask('mask'), + ) + + _reply = rq.Struct( + rq.ReplyCode(), + rq.Pad(1), + rq.Card16('sequence_number'), + rq.ReplyLength(), + rq.Card8('status'), + rq.Pad(23), ) +def grab_device(self, deviceid, time, grab_mode, paired_device_mode, owner_events, event_mask): + return XIGrabDevice( + display=self.display, + opcode=self.display.get_extension_major(extname), + deviceid=deviceid, + grab_window=self, + time=time, + cursor=X.NONE, + grab_mode=grab_mode, + paired_device_mode=paired_device_mode, + owner_events=owner_events, + mask=event_mask, + ) -HierarchyEventData = rq.Struct( +class XIUngrabDevice(rq.Request): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(52), + rq.RequestLength(), + rq.Card32('time'), DEVICEID('deviceid'), + rq.Pad(2), + ) + +def ungrab_device(self, deviceid, time): + return XIUngrabDevice( + display=self.display, + opcode=self.display.get_extension_major(extname), + time=time, + deviceid=deviceid, + ) + +class XIPassiveGrabDevice(rq.ReplyRequest): + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(54), + rq.RequestLength(), rq.Card32('time'), - rq.Card32('flags'), - rq.LengthOf('info', 2), - rq.Pad(10), - rq.List('info', HierarchyInfo), + rq.Window('grab_window'), + rq.Cursor('cursor', (X.NONE, )), + rq.Card32('detail'), + DEVICEID('deviceid'), + rq.LengthOf('modifiers', 2), + rq.LengthOf('mask', 2), + rq.Set('grab_type', 1, (GrabtypeButton, GrabtypeKeycode, GrabtypeEnter, + GrabtypeFocusIn, GrabtypeTouchBegin)), + rq.Set('grab_mode', 1, (GrabModeSync, GrabModeAsync)), + rq.Set('paired_device_mode', 1, (GrabModeSync, GrabModeAsync)), + rq.Bool('owner_events'), + rq.Pad(2), + Mask('mask'), + rq.List('modifiers', rq.Card32), + ) + + _reply = rq.Struct( + rq.ReplyCode(), + rq.Pad(1), + rq.Card16('sequence_number'), + rq.ReplyLength(), + rq.LengthOf('modifiers', 2), + rq.Pad(22), + rq.List('modifiers', rq.Card32), ) +def passive_grab_device(self, deviceid, time, detail, + grab_type, grab_mode, paired_device_mode, + owner_events, event_mask, modifiers): + return XIPassiveGrabDevice( + display=self.display, + opcode=self.display.get_extension_major(extname), + deviceid=deviceid, + grab_window=self, + time=time, + cursor=X.NONE, + detail=detail, + grab_type=grab_type, + grab_mode=grab_mode, + paired_device_mode=paired_device_mode, + owner_events=owner_events, + mask=event_mask, + modifiers=modifiers, + ) + +def grab_keycode(self, deviceid, time, keycode, + grab_mode, paired_device_mode, + owner_events, event_mask, modifiers): + return passive_grab_device(self, deviceid, time, keycode, + GrabtypeKeycode, + grab_mode, paired_device_mode, + owner_events, event_mask, modifiers) + +class XIPassiveUngrabDevice(rq.Request): + + _request = rq.Struct( + rq.Card8('opcode'), + rq.Opcode(55), + rq.RequestLength(), + rq.Window('grab_window'), + rq.Card32('detail'), + DEVICEID('deviceid'), + rq.LengthOf('modifiers', 2), + rq.Set('grab_type', 1, (GrabtypeButton, GrabtypeKeycode, + GrabtypeEnter, GrabtypeFocusIn, + GrabtypeTouchBegin)), + rq.Pad(3), + rq.List('modifiers', rq.Card32), + ) + +def passive_ungrab_device(self, deviceid, detail, grab_type, modifiers): + return XIPassiveUngrabDevice( + display=self.display, + opcode=self.display.get_extension_major(extname), + deviceid=deviceid, + grab_window=self, + detail=detail, + grab_type=grab_type, + modifiers=modifiers, + ) + +def ungrab_keycode(self, deviceid, keycode, modifiers): + return passive_ungrab_device(self, deviceid, keycode, + GrabtypeKeycode, modifiers) + +HierarchyInfo = rq.Struct( + DEVICEID('deviceid'), + DEVICEID('attachment'), + DEVICEUSE('type'), + rq.Bool('enabled'), + rq.Pad(2), + rq.Card32('flags'), +) + + +HierarchyEventData = rq.Struct( + DEVICEID('deviceid'), + rq.Card32('time'), + rq.Card32('flags'), + rq.LengthOf('info', 2), + rq.Pad(10), + rq.List('info', HierarchyInfo), +) + +ModifierInfo = rq.Struct( + rq.Card32('base_mods'), + rq.Card32('latched_mods'), + rq.Card32('locked_mods'), + rq.Card32('effective_mods'), +) + +GroupInfo = rq.Struct( + rq.Card8('base_group'), + rq.Card8('latched_group'), + rq.Card8('locked_group'), + rq.Card8('effective_group'), +) + +DeviceEventData = rq.Struct( + DEVICEID('deviceid'), + rq.Card32('time'), + rq.Card32('detail'), + rq.Window('root'), + rq.Window('event'), + rq.Window('child'), + FP1616('root_x'), + FP1616('root_y'), + FP1616('event_x'), + FP1616('event_y'), + rq.LengthOf('buttons', 2), + rq.Card16('valulators_len'), + DEVICEID('sourceid'), + rq.Pad(2), + rq.Card32('flags'), + rq.Object('mods', ModifierInfo), + rq.Object('groups', GroupInfo), + ButtonState('buttons'), +) + +DeviceChangedEventData = rq.Struct( + DEVICEID('deviceid'), + rq.Card32('time'), + rq.LengthOf('classes', 2), + DEVICEID('sourceid'), + rq.Card8('reason'), + rq.Pad(11), + rq.List('classes', ClassInfo), +) + +PropertyEventData = rq.Struct( + DEVICEID('deviceid'), + rq.Card32('time'), + rq.Card32('property'), + rq.Card8('what'), + rq.Pad(11), +) def init(disp, info): disp.extension_add_method('display', 'xinput_query_version', query_version) disp.extension_add_method('window', 'xinput_select_events', select_events) - - disp.ge_add_event_data(info.major_opcode, 11, HierarchyEventData) + disp.extension_add_method('display', 'xinput_query_device', query_device) + disp.extension_add_method('window', 'xinput_grab_device', grab_device) + disp.extension_add_method('display', 'xinput_ungrab_device', ungrab_device) + disp.extension_add_method('window', 'xinput_grab_keycode', grab_keycode) + disp.extension_add_method('window', 'xinput_ungrab_keycode', ungrab_keycode) + disp.extension_add_method('display', 'xinput_get_device_property', get_device_property) + disp.extension_add_method('display', 'xinput_list_device_properties', list_device_properties) + disp.extension_add_method('display', 'xinput_change_device_property', change_device_property) + disp.extension_add_method('display', 'xinput_delete_device_property', delete_device_property) + if hasattr(disp,"ge_add_event_data"): + for device_event in (ButtonPress, ButtonRelease, KeyPress, KeyRelease, Motion): + disp.ge_add_event_data(info.major_opcode, device_event, DeviceEventData) + disp.ge_add_event_data(info.major_opcode, DeviceChanged, DeviceEventData) + disp.ge_add_event_data(info.major_opcode, HierarchyChanged, HierarchyEventData) + disp.ge_add_event_data(info.major_opcode, PropertyEvent, PropertyEventData) diff --git a/Xlib/ext/xtest.py b/Xlib/ext/xtest.py index e69b25cd..602df2ae 100644 --- a/Xlib/ext/xtest.py +++ b/Xlib/ext/xtest.py @@ -2,19 +2,22 @@ # # Copyright (C) 2000 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA from Xlib import X from Xlib.protocol import rq diff --git a/Xlib/keysymdef/__init__.py b/Xlib/keysymdef/__init__.py index adbe499d..4ff14416 100644 --- a/Xlib/keysymdef/__init__.py +++ b/Xlib/keysymdef/__init__.py @@ -2,19 +2,22 @@ # # Copyright (C) 2001 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA __all__ = [ 'apl', diff --git a/Xlib/keysymdef/xf86.py b/Xlib/keysymdef/xf86.py index a0d79aef..4ccf12a7 100644 --- a/Xlib/keysymdef/xf86.py +++ b/Xlib/keysymdef/xf86.py @@ -1,179 +1,202 @@ -XK_XF86_MonBrightnessUp = 0x1008FF02 -XK_XF86_MonBrightnessDown = 0x1008FF03 -XK_XF86_KbdLightOnOff = 0x1008FF04 -XK_XF86_KbdBrightnessUp = 0x1008FF05 -XK_XF86_KbdBrightnessDown = 0x1008FF06 - -XK_XF86_Standby = 0x1008FF10 -XK_XF86_AudioLowerVolume = 0x1008FF11 -XK_XF86_AudioMute = 0x1008FF12 -XK_XF86_AudioRaiseVolume = 0x1008FF13 -XK_XF86_AudioPlay = 0x1008FF14 -XK_XF86_AudioStop = 0x1008FF15 -XK_XF86_AudioPrev = 0x1008FF16 -XK_XF86_AudioNext = 0x1008FF17 -XK_XF86_HomePage = 0x1008FF18 -XK_XF86_Mail = 0x1008FF19 -XK_XF86_Start = 0x1008FF1A -XK_XF86_Search = 0x1008FF1B -XK_XF86_AudioRecord = 0x1008FF1C - -XK_XF86_Calculator = 0x1008FF1D -XK_XF86_Memo = 0x1008FF1E -XK_XF86_ToDoList = 0x1008FF1F -XK_XF86_Calendar = 0x1008FF20 -XK_XF86_PowerDown = 0x1008FF21 -XK_XF86_ContrastAdjust = 0x1008FF22 -XK_XF86_RockerUp = 0x1008FF23 -XK_XF86_RockerDown = 0x1008FF24 -XK_XF86_RockerEnter = 0x1008FF25 - -XK_XF86_Back = 0x1008FF26 -XK_XF86_Forward = 0x1008FF27 -XK_XF86_Stop = 0x1008FF28 -XK_XF86_Refresh = 0x1008FF29 -XK_XF86_PowerOff = 0x1008FF2A -XK_XF86_WakeUp = 0x1008FF2B -XK_XF86_Eject = 0x1008FF2C -XK_XF86_ScreenSaver = 0x1008FF2D -XK_XF86_WWW = 0x1008FF2E -XK_XF86_Sleep = 0x1008FF2F -XK_XF86_Favorites = 0x1008FF30 -XK_XF86_AudioPause = 0x1008FF31 -XK_XF86_AudioMedia = 0x1008FF32 -XK_XF86_MyComputer = 0x1008FF33 -XK_XF86_VendorHome = 0x1008FF34 -XK_XF86_LightBulb = 0x1008FF35 -XK_XF86_Shop = 0x1008FF36 -XK_XF86_History = 0x1008FF37 -XK_XF86_OpenURL = 0x1008FF38 -XK_XF86_AddFavorite = 0x1008FF39 -XK_XF86_HotLinks = 0x1008FF3A -XK_XF86_BrightnessAdjust = 0x1008FF3B -XK_XF86_Finance = 0x1008FF3C -XK_XF86_Community = 0x1008FF3D -XK_XF86_AudioRewind = 0x1008FF3E -XK_XF86_XF86BackForward = 0x1008FF3F -XK_XF86_Launch0 = 0x1008FF40 -XK_XF86_Launch1 = 0x1008FF41 -XK_XF86_Launch2 = 0x1008FF42 -XK_XF86_Launch3 = 0x1008FF43 -XK_XF86_Launch4 = 0x1008FF44 -XK_XF86_Launch5 = 0x1008FF45 -XK_XF86_Launch6 = 0x1008FF46 -XK_XF86_Launch7 = 0x1008FF47 -XK_XF86_Launch8 = 0x1008FF48 -XK_XF86_Launch9 = 0x1008FF49 -XK_XF86_LaunchA = 0x1008FF4A -XK_XF86_LaunchB = 0x1008FF4B -XK_XF86_LaunchC = 0x1008FF4C -XK_XF86_LaunchD = 0x1008FF4D -XK_XF86_LaunchE = 0x1008FF4E -XK_XF86_LaunchF = 0x1008FF4F - -XK_XF86_ApplicationLeft = 0x1008FF50 -XK_XF86_ApplicationRight = 0x1008FF51 -XK_XF86_Book = 0x1008FF52 -XK_XF86_CD = 0x1008FF53 -XK_XF86_Calculater = 0x1008FF54 -XK_XF86_Clear = 0x1008FF55 -XK_XF86_Close = 0x1008FF56 -XK_XF86_Copy = 0x1008FF57 -XK_XF86_Cut = 0x1008FF58 -XK_XF86_Display = 0x1008FF59 -XK_XF86_DOS = 0x1008FF5A -XK_XF86_Documents = 0x1008FF5B -XK_XF86_Excel = 0x1008FF5C -XK_XF86_Explorer = 0x1008FF5D -XK_XF86_Game = 0x1008FF5E -XK_XF86_Go = 0x1008FF5F -XK_XF86_iTouch = 0x1008FF60 -XK_XF86_LogOff = 0x1008FF61 -XK_XF86_Market = 0x1008FF62 -XK_XF86_Meeting = 0x1008FF63 -XK_XF86_MenuKB = 0x1008FF65 -XK_XF86_MenuPB = 0x1008FF66 -XK_XF86_MySites = 0x1008FF67 -XK_XF86_New = 0x1008FF68 -XK_XF86_News = 0x1008FF69 -XK_XF86_OfficeHome = 0x1008FF6A -XK_XF86_Open = 0x1008FF6B -XK_XF86_Option = 0x1008FF6C -XK_XF86_Paste = 0x1008FF6D -XK_XF86_Phone = 0x1008FF6E -XK_XF86_Q = 0x1008FF70 -XK_XF86_Reply = 0x1008FF72 -XK_XF86_Reload = 0x1008FF73 -XK_XF86_RotateWindows = 0x1008FF74 -XK_XF86_RotationPB = 0x1008FF75 -XK_XF86_RotationKB = 0x1008FF76 -XK_XF86_Save = 0x1008FF77 -XK_XF86_ScrollUp = 0x1008FF78 -XK_XF86_ScrollDown = 0x1008FF79 -XK_XF86_ScrollClick = 0x1008FF7A -XK_XF86_Send = 0x1008FF7B -XK_XF86_Spell = 0x1008FF7C -XK_XF86_SplitScreen = 0x1008FF7D -XK_XF86_Support = 0x1008FF7E -XK_XF86_TaskPane = 0x1008FF7F -XK_XF86_Terminal = 0x1008FF80 -XK_XF86_Tools = 0x1008FF81 -XK_XF86_Travel = 0x1008FF82 -XK_XF86_UserPB = 0x1008FF84 -XK_XF86_User1KB = 0x1008FF85 -XK_XF86_User2KB = 0x1008FF86 -XK_XF86_Video = 0x1008FF87 -XK_XF86_WheelButton = 0x1008FF88 -XK_XF86_Word = 0x1008FF89 -XK_XF86_Xfer = 0x1008FF8A -XK_XF86_ZoomIn = 0x1008FF8B -XK_XF86_ZoomOut = 0x1008FF8C - -XK_XF86_Away = 0x1008FF8D -XK_XF86_Messenger = 0x1008FF8E -XK_XF86_WebCam = 0x1008FF8F -XK_XF86_MailForward = 0x1008FF90 -XK_XF86_Pictures = 0x1008FF91 -XK_XF86_Music = 0x1008FF92 - -XK_XF86_Battery = 0x1008FF93 -XK_XF86_Bluetooth = 0x1008FF94 -XK_XF86_WLAN = 0x1008FF95 -XK_XF86_UWB = 0x1008FF96 - -XK_XF86_AudioForward = 0x1008FF97 -XK_XF86_AudioRepeat = 0x1008FF98 -XK_XF86_AudioRandomPlay = 0x1008FF99 -XK_XF86_Subtitle = 0x1008FF9A -XK_XF86_AudioCycleTrack = 0x1008FF9B -XK_XF86_CycleAngle = 0x1008FF9C -XK_XF86_FrameBack = 0x1008FF9D -XK_XF86_FrameForward = 0x1008FF9E -XK_XF86_Time = 0x1008FF9F -XK_XF86_Select = 0x1008FFA0 -XK_XF86_View = 0x1008FFA1 -XK_XF86_TopMenu = 0x1008FFA2 - -XK_XF86_Red = 0x1008FFA3 -XK_XF86_Green = 0x1008FFA4 -XK_XF86_Yellow = 0x1008FFA5 -XK_XF86_Blue = 0x1008FFA6 - -XK_XF86_Switch_VT_1 = 0x1008FE01 -XK_XF86_Switch_VT_2 = 0x1008FE02 -XK_XF86_Switch_VT_3 = 0x1008FE03 -XK_XF86_Switch_VT_4 = 0x1008FE04 -XK_XF86_Switch_VT_5 = 0x1008FE05 -XK_XF86_Switch_VT_6 = 0x1008FE06 -XK_XF86_Switch_VT_7 = 0x1008FE07 -XK_XF86_Switch_VT_8 = 0x1008FE08 -XK_XF86_Switch_VT_9 = 0x1008FE09 -XK_XF86_Switch_VT_10 = 0x1008FE0A -XK_XF86_Switch_VT_11 = 0x1008FE0B -XK_XF86_Switch_VT_12 = 0x1008FE0C - -XK_XF86_Ungrab = 0x1008FE20 -XK_XF86_ClearGrab = 0x1008FE21 -XK_XF86_Next_VMode = 0x1008FE22 -XK_XF86_Prev_VMode = 0x1008FE23 +XK_XF86_ModeLock = 0x1008FF01 +XK_XF86_MonBrightnessUp = 0x1008FF02 +XK_XF86_MonBrightnessDown = 0x1008FF03 +XK_XF86_KbdLightOnOff = 0x1008FF04 +XK_XF86_KbdBrightnessUp = 0x1008FF05 +XK_XF86_KbdBrightnessDown = 0x1008FF06 +XK_XF86_MonBrightnessCycle = 0x1008FF07 + +XK_XF86_Standby = 0x1008FF10 +XK_XF86_AudioLowerVolume = 0x1008FF11 +XK_XF86_AudioMute = 0x1008FF12 +XK_XF86_AudioRaiseVolume = 0x1008FF13 +XK_XF86_AudioPlay = 0x1008FF14 +XK_XF86_AudioStop = 0x1008FF15 +XK_XF86_AudioPrev = 0x1008FF16 +XK_XF86_AudioNext = 0x1008FF17 +XK_XF86_HomePage = 0x1008FF18 +XK_XF86_Mail = 0x1008FF19 +XK_XF86_Start = 0x1008FF1A +XK_XF86_Search = 0x1008FF1B +XK_XF86_AudioRecord = 0x1008FF1C + +XK_XF86_Calculator = 0x1008FF1D +XK_XF86_Memo = 0x1008FF1E +XK_XF86_ToDoList = 0x1008FF1F +XK_XF86_Calendar = 0x1008FF20 +XK_XF86_PowerDown = 0x1008FF21 +XK_XF86_ContrastAdjust = 0x1008FF22 +XK_XF86_RockerUp = 0x1008FF23 +XK_XF86_RockerDown = 0x1008FF24 +XK_XF86_RockerEnter = 0x1008FF25 + +XK_XF86_Back = 0x1008FF26 +XK_XF86_Forward = 0x1008FF27 +XK_XF86_Stop = 0x1008FF28 +XK_XF86_Refresh = 0x1008FF29 +XK_XF86_PowerOff = 0x1008FF2A +XK_XF86_WakeUp = 0x1008FF2B +XK_XF86_Eject = 0x1008FF2C +XK_XF86_ScreenSaver = 0x1008FF2D +XK_XF86_WWW = 0x1008FF2E +XK_XF86_Sleep = 0x1008FF2F +XK_XF86_Favorites = 0x1008FF30 +XK_XF86_AudioPause = 0x1008FF31 +XK_XF86_AudioMedia = 0x1008FF32 +XK_XF86_MyComputer = 0x1008FF33 +XK_XF86_VendorHome = 0x1008FF34 +XK_XF86_LightBulb = 0x1008FF35 +XK_XF86_Shop = 0x1008FF36 +XK_XF86_History = 0x1008FF37 +XK_XF86_OpenURL = 0x1008FF38 +XK_XF86_AddFavorite = 0x1008FF39 +XK_XF86_HotLinks = 0x1008FF3A +XK_XF86_BrightnessAdjust = 0x1008FF3B +XK_XF86_Finance = 0x1008FF3C +XK_XF86_Community = 0x1008FF3D +XK_XF86_AudioRewind = 0x1008FF3E +XK_XF86_XF86BackForward = 0x1008FF3F +XK_XF86_Launch0 = 0x1008FF40 +XK_XF86_Launch1 = 0x1008FF41 +XK_XF86_Launch2 = 0x1008FF42 +XK_XF86_Launch3 = 0x1008FF43 +XK_XF86_Launch4 = 0x1008FF44 +XK_XF86_Launch5 = 0x1008FF45 +XK_XF86_Launch6 = 0x1008FF46 +XK_XF86_Launch7 = 0x1008FF47 +XK_XF86_Launch8 = 0x1008FF48 +XK_XF86_Launch9 = 0x1008FF49 +XK_XF86_LaunchA = 0x1008FF4A +XK_XF86_LaunchB = 0x1008FF4B +XK_XF86_LaunchC = 0x1008FF4C +XK_XF86_LaunchD = 0x1008FF4D +XK_XF86_LaunchE = 0x1008FF4E +XK_XF86_LaunchF = 0x1008FF4F + +XK_XF86_ApplicationLeft = 0x1008FF50 +XK_XF86_ApplicationRight = 0x1008FF51 +XK_XF86_Book = 0x1008FF52 +XK_XF86_CD = 0x1008FF53 +XK_XF86_Calculater = 0x1008FF54 +XK_XF86_Clear = 0x1008FF55 +XK_XF86_Close = 0x1008FF56 +XK_XF86_Copy = 0x1008FF57 +XK_XF86_Cut = 0x1008FF58 +XK_XF86_Display = 0x1008FF59 +XK_XF86_DOS = 0x1008FF5A +XK_XF86_Documents = 0x1008FF5B +XK_XF86_Excel = 0x1008FF5C +XK_XF86_Explorer = 0x1008FF5D +XK_XF86_Game = 0x1008FF5E +XK_XF86_Go = 0x1008FF5F +XK_XF86_iTouch = 0x1008FF60 +XK_XF86_LogOff = 0x1008FF61 +XK_XF86_Market = 0x1008FF62 +XK_XF86_Meeting = 0x1008FF63 +XK_XF86_MenuKB = 0x1008FF65 +XK_XF86_MenuPB = 0x1008FF66 +XK_XF86_MySites = 0x1008FF67 +XK_XF86_New = 0x1008FF68 +XK_XF86_News = 0x1008FF69 +XK_XF86_OfficeHome = 0x1008FF6A +XK_XF86_Open = 0x1008FF6B +XK_XF86_Option = 0x1008FF6C +XK_XF86_Paste = 0x1008FF6D +XK_XF86_Phone = 0x1008FF6E +XK_XF86_Q = 0x1008FF70 +XK_XF86_Reply = 0x1008FF72 +XK_XF86_Reload = 0x1008FF73 +XK_XF86_RotateWindows = 0x1008FF74 +XK_XF86_RotationPB = 0x1008FF75 +XK_XF86_RotationKB = 0x1008FF76 +XK_XF86_Save = 0x1008FF77 +XK_XF86_ScrollUp = 0x1008FF78 +XK_XF86_ScrollDown = 0x1008FF79 +XK_XF86_ScrollClick = 0x1008FF7A +XK_XF86_Send = 0x1008FF7B +XK_XF86_Spell = 0x1008FF7C +XK_XF86_SplitScreen = 0x1008FF7D +XK_XF86_Support = 0x1008FF7E +XK_XF86_TaskPane = 0x1008FF7F +XK_XF86_Terminal = 0x1008FF80 +XK_XF86_Tools = 0x1008FF81 +XK_XF86_Travel = 0x1008FF82 +XK_XF86_UserPB = 0x1008FF84 +XK_XF86_User1KB = 0x1008FF85 +XK_XF86_User2KB = 0x1008FF86 +XK_XF86_Video = 0x1008FF87 +XK_XF86_WheelButton = 0x1008FF88 +XK_XF86_Word = 0x1008FF89 +XK_XF86_Xfer = 0x1008FF8A +XK_XF86_ZoomIn = 0x1008FF8B +XK_XF86_ZoomOut = 0x1008FF8C + +XK_XF86_Away = 0x1008FF8D +XK_XF86_Messenger = 0x1008FF8E +XK_XF86_WebCam = 0x1008FF8F +XK_XF86_MailForward = 0x1008FF90 +XK_XF86_Pictures = 0x1008FF91 +XK_XF86_Music = 0x1008FF92 + +XK_XF86_Battery = 0x1008FF93 +XK_XF86_Bluetooth = 0x1008FF94 +XK_XF86_WLAN = 0x1008FF95 +XK_XF86_UWB = 0x1008FF96 + +XK_XF86_AudioForward = 0x1008FF97 +XK_XF86_AudioRepeat = 0x1008FF98 +XK_XF86_AudioRandomPlay = 0x1008FF99 +XK_XF86_Subtitle = 0x1008FF9A +XK_XF86_AudioCycleTrack = 0x1008FF9B +XK_XF86_CycleAngle = 0x1008FF9C +XK_XF86_FrameBack = 0x1008FF9D +XK_XF86_FrameForward = 0x1008FF9E +XK_XF86_Time = 0x1008FF9F +XK_XF86_Select = 0x1008FFA0 +XK_XF86_View = 0x1008FFA1 +XK_XF86_TopMenu = 0x1008FFA2 + +XK_XF86_Red = 0x1008FFA3 +XK_XF86_Green = 0x1008FFA4 +XK_XF86_Yellow = 0x1008FFA5 +XK_XF86_Blue = 0x1008FFA6 + +XK_XF86_Suspend = 0x1008FFA7 +XK_XF86_Hibernate = 0x1008FFA8 +XK_XF86_TouchpadToggle = 0x1008FFA9 +XK_XF86_TouchpadOn = 0x1008FFB0 +XK_XF86_TouchpadOff = 0x1008FFB1 + +XK_XF86_AudioMicMute = 0x1008FFB2 + +XK_XF86_Keyboard = 0x1008FFB3 + +XK_XF86_WWAN = 0x1008FFB4 +XK_XF86_RFKill = 0x1008FFB5 + +XK_XF86_AudioPreset = 0x1008FFB6 + +XK_XF86_RotationLockToggle = 0x1008FFB7 + +XK_XF86_FullScreen = 0x1008FFB8 + +XK_XF86_Switch_VT_1 = 0x1008FE01 +XK_XF86_Switch_VT_2 = 0x1008FE02 +XK_XF86_Switch_VT_3 = 0x1008FE03 +XK_XF86_Switch_VT_4 = 0x1008FE04 +XK_XF86_Switch_VT_5 = 0x1008FE05 +XK_XF86_Switch_VT_6 = 0x1008FE06 +XK_XF86_Switch_VT_7 = 0x1008FE07 +XK_XF86_Switch_VT_8 = 0x1008FE08 +XK_XF86_Switch_VT_9 = 0x1008FE09 +XK_XF86_Switch_VT_10 = 0x1008FE0A +XK_XF86_Switch_VT_11 = 0x1008FE0B +XK_XF86_Switch_VT_12 = 0x1008FE0C + +XK_XF86_Ungrab = 0x1008FE20 +XK_XF86_ClearGrab = 0x1008FE21 +XK_XF86_Next_VMode = 0x1008FE22 +XK_XF86_Prev_VMode = 0x1008FE23 +XK_XF86_LogWindowTree = 0x1008FE24 +XK_XF86_LogGrabInfo = 0x1008FE25 diff --git a/Xlib/protocol/__init__.py b/Xlib/protocol/__init__.py index b1239b4b..4e2840a1 100644 --- a/Xlib/protocol/__init__.py +++ b/Xlib/protocol/__init__.py @@ -2,19 +2,22 @@ # # Copyright (C) 2000 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA __all__ = [ 'display', diff --git a/Xlib/protocol/display.py b/Xlib/protocol/display.py index 45730490..0d910dab 100644 --- a/Xlib/protocol/display.py +++ b/Xlib/protocol/display.py @@ -1,29 +1,36 @@ -# -*- coding: iso-8859-1 -*- +# -*- coding: utf-8 -*- # # Xlib.protocol.display -- core display communication # # Copyright (C) 2000-2002 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA # Standard modules -import sys -import select -import struct import errno +import math +import select import socket +import struct +import sys + +# Python 2/3 compatibility. +from six import PY3, byte2int, indexbytes # Xlib modules from .. import error @@ -35,22 +42,54 @@ from . import rq from . import event +if PY3: + + class bytesview(object): + + def __init__(self, data, offset=0, size=None): + if size is None: + size = len(data)-offset + if isinstance(data, bytes): + view = memoryview(data) + elif isinstance(data, bytesview): + view = data.view + else: + raise TypeError('unsupported type: {}'.format(type(data))) + self.view = view[offset:offset+size] + + def __len__(self): + return len(self.view) + + def __getitem__(self, key): + if isinstance(key, slice): + 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): - resource_classes = {} extension_major_opcodes = {} error_classes = error.xerror_class.copy() event_classes = event.event_class.copy() def __init__(self, display = None): - name, host, displayno, screenno = connect.get_display(display) + name, protocol, host, displayno, screenno = connect.get_display(display) self.display_name = name self.default_screen = screenno - self.socket = connect.get_socket(name, host, displayno) + self.socket = connect.get_socket(name, protocol, host, displayno) - auth_name, auth_data = connect.get_auth(self.socket, - name, host, displayno) + auth_name, auth_data = connect.get_auth(self.socket, name, + protocol, host, displayno) # Internal structures for communication, grouped # by their function and locks @@ -70,7 +109,7 @@ def __init__(self, display = None): self.request_serial = 1 self.request_queue = [] - # Send-and-recieve loop, see function send_and_recive + # Send-and-receive loop, see function send_and_receive # for a detailed explanation self.send_recv_lock = lock.allocate_lock() self.send_active = 0 @@ -81,11 +120,17 @@ def __init__(self, display = None): self.request_waiting = 0 self.request_wait_lock = lock.allocate_lock() - # Data used by the send-and-recieve loop + # Calculate optimal default buffer size for recv. + buffer_size = self.socket.getsockopt(socket.SOL_SOCKET, + socket.SO_RCVBUF) + buffer_size = math.pow(2, math.floor(math.log(buffer_size, 2))) + self.recv_buffer_size = int(buffer_size) + + # Data used by the send-and-receive loop self.sent_requests = [] self.recv_packet_len = 0 - self.data_send = '' - self.data_recv = '' + self.data_send = b'' + self.data_recv = b'' self.data_sent_bytes = 0 # Resource ID structures @@ -100,7 +145,7 @@ def __init__(self, display = None): # Right, now we're all set up for the connection setup # request with the server. - # Figure out which endianess the hardware uses + # Figure out which endianness the hardware uses self.big_endian = struct.unpack('BB', struct.pack('H', 0x0100))[0] if self.big_endian: @@ -158,7 +203,7 @@ def next_event(self): while not self.event_queue: - # Lock send_recv so no send_and_recieve + # Lock send_recv so no send_and_receive # can start or stop while we're checking # whether there are one active. self.send_recv_lock.acquire() @@ -169,7 +214,7 @@ def next_event(self): # Call send_and_recv, which will return when # something has occured - self.send_and_recv(event = 1) + self.send_and_recv(event = True) # Before looping around, lock the event queue against # modifications. @@ -195,7 +240,7 @@ def pending_events(self): # Make a send_and_recv pass, receiving any events self.send_recv_lock.acquire() - self.send_and_recv(recv = 1) + self.send_and_recv(recv = True) # Lock the queue, get the event count, and unlock again. self.event_queue_write_lock.acquire() @@ -207,7 +252,7 @@ def pending_events(self): def flush(self): self.check_for_error() self.send_recv_lock.acquire() - self.send_and_recv(flush = 1) + self.send_and_recv(flush = True) def close(self): self.flush() @@ -339,7 +384,7 @@ def close_internal(self, whom): self.socket_error_lock.release() - def send_and_recv(self, flush = None, event = None, request = None, recv = None): + def send_and_recv(self, flush = False, event = False, request = None, recv = False): """send_and_recv(flush = None, event = None, request = None, recv = None) Perform I/O, or wait for some other thread to do it for us. @@ -354,10 +399,10 @@ def send_and_recv(self, flush = None, event = None, request = None, recv = None) be true. Will return immediately if another thread is already doing send_and_recv. - To wait for an event to be recieved, event should be true. + To wait for an event to be received, event should be true. To wait for a response to a certain request (either an error - or a response), request should be set the that request's + or a response), request should be set to that request's serial number. To just read any pending data from the server, recv should be true. @@ -439,19 +484,19 @@ def send_and_recv(self, flush = None, event = None, request = None, recv = None) # There's no thread doing what we need to do. Find out exactly # what to do - # There must always be some thread recieving data, but it must not + # There must always be some thread receiving data, but it must not # necessarily be us if not self.recv_active: - recieving = 1 + receiving = 1 self.recv_active = 1 else: - recieving = 0 + receiving = 0 flush_bytes = None sending = 0 - # Loop, recieving and sending data. + # Loop, receiving and sending data. while 1: # We might want to start sending data @@ -483,7 +528,7 @@ def send_and_recv(self, flush = None, event = None, request = None, recv = None) self.send_recv_lock.release() # There's no longer anything useful we can do here. - if not (sending or recieving): + if not (sending or receiving): break # If we're flushing, figure out how many bytes we @@ -496,9 +541,9 @@ def send_and_recv(self, flush = None, event = None, request = None, recv = None) try: # We're only checking for the socket to be writable # if we're the sending thread. We always check for it - # to become readable: either we are the recieving thread - # and should take care of the data, or the recieving thread - # might finish recieving after having read the data + # to become readable: either we are the receiving thread + # and should take care of the data, or the receiving thread + # might finish receiving after having read the data if sending: writeset = [self.socket] @@ -515,11 +560,15 @@ def send_and_recv(self, flush = None, event = None, request = None, recv = None) rs, ws, es = select.select([self.socket], writeset, [], timeout) - # Ignore errors caused by a signal recieved while blocking. + # Ignore errors caused by a signal received while blocking. # All other errors are re-raised. - except select.error, err: - if err[0] != errno.EINTR: - raise err + except select.error as err: + if isinstance(err, OSError): + code = err.errno + else: + code = err[0] + if code != errno.EINTR: + raise # We must lock send_and_recv before we can loop to # the start of the loop @@ -532,8 +581,8 @@ def send_and_recv(self, flush = None, event = None, request = None, recv = None) if ws: try: i = self.socket.send(self.data_send) - except socket.error, err: - self.close_internal('server: %s' % err[1]) + except socket.error as err: + self.close_internal('server: %s' % err) raise self.socket_error self.data_send = self.data_send[i:] @@ -544,12 +593,14 @@ def send_and_recv(self, flush = None, event = None, request = None, recv = None) gotreq = 0 if rs: - # We're the recieving thread, parse the data - if recieving: + # We're the receiving thread, parse the data + if receiving: try: - bytes_recv = self.socket.recv(2048) - except socket.error, err: - self.close_internal('server: %s' % err[1]) + count = self.recv_packet_len - len(self.data_recv) + count = max(self.recv_buffer_size, count) + bytes_recv = self.socket.recv(count) + except socket.error as err: + self.close_internal('server: %s' % err) raise self.socket_error if not bytes_recv: @@ -557,7 +608,7 @@ def send_and_recv(self, flush = None, event = None, request = None, recv = None) self.close_internal('server') raise self.socket_error - self.data_recv = self.data_recv + bytes_recv + self.data_recv = bytes(self.data_recv) + bytes_recv gotreq = self.parse_response(request) # Otherwise return, allowing the calling thread to figure @@ -575,7 +626,7 @@ def send_and_recv(self, flush = None, event = None, request = None, recv = None) # There are three different end of send-recv-loop conditions. # However, we don't leave the loop immediately, instead we - # try to send and recieve any data that might be left. We + # try to send and receive any data that might be left. We # do this by giving a timeout of 0 to select to poll # the socket. @@ -591,7 +642,7 @@ def send_and_recv(self, flush = None, event = None, request = None, recv = None) if request is not None and gotreq: break - # Always break if we just want to recieve as much as possible + # Always break if we just want to receive as much as possible if recv: break @@ -609,7 +660,7 @@ def send_and_recv(self, flush = None, event = None, request = None, recv = None) if sending: self.send_active = 0 - if recieving: + if receiving: self.recv_active = 0 if self.event_waiting: @@ -626,9 +677,9 @@ def send_and_recv(self, flush = None, event = None, request = None, recv = None) def parse_response(self, request): """Internal method. - Parse data recieved from server. If REQUEST is not None + Parse data received from server. If REQUEST is not None true is returned if the request with that serial number - was recieved, otherwise false is returned. + was received, otherwise false is returned. If REQUEST is -1, we're parsing the server connection setup response. @@ -638,11 +689,11 @@ def parse_response(self, request): return self.parse_connection_setup() # Parse ordinary server response - gotreq = 0 - while 1: + gotreq = False + while True: if self.data_recv: # Check the first byte to find out what kind of response it is - rtype = ord(self.data_recv[0]) + rtype = byte2int(self.data_recv) # Are we're waiting for additional data for the current packet? if self.recv_packet_len: @@ -651,17 +702,19 @@ def parse_response(self, request): if rtype == 1: gotreq = self.parse_request_response(request) or gotreq + continue elif rtype & 0x7f == ge.GenericEventCode: self.parse_event_response(rtype) + continue else: raise AssertionError(rtype) # Every response is at least 32 bytes long, so don't bother - # until we have recieved that much + # until we have received that much if len(self.data_recv) < 32: return gotreq - # Error resposne + # Error response if rtype == 0: gotreq = self.parse_error_response(request) or gotreq @@ -679,13 +732,13 @@ def parse_response(self, request): def parse_error_response(self, request): # Code is second byte - code = ord(self.data_recv[1]) + code = indexbytes(self.data_recv, 1) # Fetch error class estruct = self.error_classes.get(code, error.XError) e = estruct(self, self.data_recv[:32]) - self.data_recv = buffer(self.data_recv, 32) + self.data_recv = bytesview(self.data_recv, 32) # print 'recv Error:', e @@ -719,7 +772,7 @@ def parse_error_response(self, request): else: self.default_error_handler(e) - return 0 + return False def default_error_handler(self, err): @@ -739,7 +792,7 @@ def parse_request_response(self, request): req._parse_response(self.data_recv[:self.recv_packet_len]) # print 'recv Request:', req - self.data_recv = buffer(self.data_recv, self.recv_packet_len) + self.data_recv = bytesview(self.data_recv, self.recv_packet_len) self.recv_packet_len = 0 @@ -768,23 +821,32 @@ def parse_event_response(self, etype): estruct = self.event_classes.get(etype, event.AnyEvent) if type(estruct) == dict: + subcode = self.data_recv[1] + + # Python2 compatibility + if type(subcode) == str: + subcode = ord(subcode) + # this etype refers to a set of sub-events with individual subcodes - estruct = estruct[ord(self.data_recv[1])] + estruct = estruct[subcode] e = estruct(display = self, binarydata = self.data_recv[:length]) if etype == ge.GenericEventCode: self.recv_packet_len = 0 - self.data_recv = buffer(self.data_recv, length) + self.data_recv = bytesview(self.data_recv, length) # Drop all requests having an error handler, # but which obviously succeded. # Decrement it by one, so that we don't remove the request # that generated these events, if there is such a one. - # Bug reported by Ilpo Nyyssönen - self.get_waiting_request((e.sequence_number - 1) % 65536) + # Bug reported by Ilpo Nyyssönen + # Note: not all events have a sequence_number field! + # (e.g. KeymapNotify). + if hasattr(e, 'sequence_number'): + self.get_waiting_request((e.sequence_number - 1) % 65536) # print 'recv Event:', e @@ -875,7 +937,7 @@ def parse_connection_setup(self): # Only the ConnectionSetupRequest has been sent so far r = self.sent_requests[0] - while 1: + while True: # print 'data_send:', repr(self.data_send) # print 'data_recv:', repr(self.data_recv) @@ -884,7 +946,7 @@ def parse_connection_setup(self): # The full response haven't arrived yet if len(self.data_recv) < alen: - return 0 + return False # Connection failed or further authentication is needed. # Set reason to the reason string @@ -894,22 +956,22 @@ def parse_connection_setup(self): # Else connection succeeded, parse the reply else: x, d = r._success_reply.parse_binary(self.data_recv[:alen], - self, rawdict = 1) + self, rawdict = True) r._data.update(x) del self.sent_requests[0] self.data_recv = self.data_recv[alen:] - return 1 + return True else: # The base reply is 8 bytes long if len(self.data_recv) < 8: - return 0 + return False r._data, d = r._reply.parse_binary(self.data_recv[:8], - self, rawdict = 1) + self, rawdict = True) self.data_recv = self.data_recv[8:] # Loop around to see if we have got the additional data @@ -998,13 +1060,13 @@ class ConnectionSetupRequest(rq.GetAttrData): def __init__(self, display, *args, **keys): - self._binary = apply(self._request.to_binary, args, keys) + self._binary = self._request.to_binary(*args, **keys) self._data = None # Don't bother about locking, since no other threads have # access to the display yet - display.request_queue.append((self, 1)) + display.request_queue.append((self, True)) # However, we must lock send_and_recv, but we don't have # to loop. diff --git a/Xlib/protocol/event.py b/Xlib/protocol/event.py index ff2cf766..04743c6d 100644 --- a/Xlib/protocol/event.py +++ b/Xlib/protocol/event.py @@ -2,19 +2,22 @@ # # Copyright (C) 2000-2002 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA # Xlib modules @@ -29,7 +32,7 @@ class AnyEvent(rq.Event): _fields = rq.Struct( rq.Card8('type'), rq.Card8('detail'), rq.Card16('sequence_number'), - rq.FixedString('data', 28), + rq.FixedBinary('data', 28), ) class KeyButtonPointer(rq.Event): diff --git a/Xlib/protocol/request.py b/Xlib/protocol/request.py index e58a9bd2..b431e137 100644 --- a/Xlib/protocol/request.py +++ b/Xlib/protocol/request.py @@ -2,19 +2,22 @@ # # Copyright (C) 2000-2002 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA # Xlib modules @@ -1063,7 +1066,7 @@ class PutImage(rq.Request): rq.Card8('left_pad'), rq.Card8('depth'), rq.Pad(2), - rq.String8('data'), + rq.Binary('data'), ) class GetImage(rq.ReplyRequest): @@ -1086,7 +1089,7 @@ class GetImage(rq.ReplyRequest): rq.ReplyLength(), rq.Card32('visual'), rq.Pad(20), - rq.String8('data'), + rq.Binary('data'), ) class PolyText8(rq.Request): @@ -1637,7 +1640,8 @@ class ChangeHosts(rq.Request): rq.Opcode(109), rq.Set('mode', 1, (X.HostInsert, X.HostDelete)), rq.RequestLength(), - rq.Set('host_family', 1, (X.FamilyInternet, X.FamilyDECnet, X.FamilyChaos)), + rq.Set('host_family', 1, (X.FamilyInternet, X.FamilyDECnet, X.FamilyChaos, + X.FamilyServerInterpreted, X.FamilyInternetV6)), rq.Pad(1), rq.LengthOf('host', 2), rq.List('host', rq.Card8Obj) diff --git a/Xlib/protocol/rq.py b/Xlib/protocol/rq.py index acfd19f4..8bc82059 100644 --- a/Xlib/protocol/rq.py +++ b/Xlib/protocol/rq.py @@ -2,32 +2,48 @@ # # Copyright (C) 2000-2002 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA # Standard modules import sys import traceback import struct from array import array -import types + +# Python 2/3 compatibility. +from six import PY3, binary_type, byte2int, indexbytes, iterbytes # Xlib modules from .. import X from ..support import lock +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() + + class BadDataError(Exception): pass # These are struct codes, we know their byte sizes @@ -57,25 +73,6 @@ class BadDataError(Exception): pass # print array_unsigned_codes, struct_to_array_codes -def _method(func, instance): - """Dynamically create a new method. - - Exposes a common interface for types.MethodType across Python 3 and 2 - """ - if sys.version_info[0] >= 3: - return types.MethodType(func, instance) - else: - return types.MethodType(func, instance, type(instance)) - -def _to_ord(ch): - """Get char code in a cross-Python way""" - if isinstance(ch, int): - # Python 3: bytes char is already an integer, no need to call ord() - return ch - else: - # Python 2: string char required to call ord() - return ord(ch) - class Field(object): """Field objects represent the data fields of a Struct. @@ -121,7 +118,7 @@ class Field(object): check_value = None parse_value = None - keyword_args = 0 + keyword_args = False def __init__(self): pass @@ -380,7 +377,7 @@ def __init__(self, name): X.SouthEastGravity)) -class FixedString(ValueField): +class FixedBinary(ValueField): structvalues = 1 def __init__(self, name, size): @@ -388,6 +385,34 @@ def __init__(self, name, size): self.structcode = '{0}s'.format(size) +class Binary(ValueField): + structcode = None + + def __init__(self, name, pad = 1): + ValueField.__init__(self, name) + self.pad = pad + + def pack_value(self, val): + val_bytes = val + slen = len(val_bytes) + + if self.pad: + return val_bytes + b'\0' * ((4 - slen % 4) % 4), slen, None + else: + return val_bytes, slen, None + + def parse_binary_value(self, data, display, length, format): + if length is None: + return data, b'' + + if self.pad: + slen = length + ((4 - length % 4) % 4) + else: + slen = length + + return data[:length], data[slen:] + + class String8(ValueField): structcode = None @@ -396,7 +421,10 @@ def __init__(self, name, pad = 1): self.pad = pad def pack_value(self, val): - val_bytes = val.encode() + if isinstance(val, bytes): + val_bytes = val + else: + val_bytes = val.encode() slen = len(val_bytes) if self.pad: @@ -406,14 +434,16 @@ def pack_value(self, val): def parse_binary_value(self, data, display, length, format): if length is None: - return data.decode(), b'' + return decode_string(data), b'' if self.pad: slen = length + ((4 - length % 4) % 4) else: slen = length - return data[:length].decode(), data[slen:] + data_str = decode_string(data[:length]) + + return data_str, data[slen:] class String16(ValueField): @@ -425,8 +455,8 @@ def __init__(self, name, pad = 1): def pack_value(self, val): """Convert 8-byte string into 16-byte list""" - if type(val) is bytes: - val = map(lambda c: ord(c), val) + if isinstance(val, bytes): + val = list(iterbytes(val)) slen = len(val) @@ -435,7 +465,7 @@ def pack_value(self, val): else: pad = b'' - return struct.pack(*('>' + 'H' * slen, ) + tuple(val)) + pad, slen, None + return struct.pack('>' + 'H' * slen, *val) + pad, slen, None def parse_binary_value(self, data, display, length, format): if length == 'odd': @@ -529,8 +559,8 @@ def pack_value(self, val): if self.type.structcode and len(self.type.structcode) == 1: if self.type.check_value is not None: val = [self.type.check_value(v) for v in val] - data = array(struct_to_array_codes[self.type.structcode], - val).tostring() + a = array(struct_to_array_codes[self.type.structcode], val) + data = encode_array(a) else: data = [] for v in val: @@ -576,7 +606,7 @@ def pack_value(self, val): return self.type.pack_value(val) def check_value(self, val): - if type(val) is tuple: + if isinstance(val, tuple): vals = [] i = 0 for f in self.type.fields: @@ -592,7 +622,7 @@ def check_value(self, val): i = i + 1 return vals - if type(val) is dict: + if isinstance(val, dict): data = val elif isinstance(val, DictWrapper): data = val._data @@ -627,15 +657,15 @@ def parse_binary_value(self, data, display, length, format): ret = None elif format == 8: - ret = (8, str(data[:length])) + ret = (8, data[:length]) data = data[length + ((4 - length % 4) % 4):] elif format == 16: - ret = (16, array(array_unsigned_codes[2], data[:2 * length].decode().encode())) + ret = (16, array(array_unsigned_codes[2], data[:2 * length])) data = data[2 * (length + length % 2):] elif format == 32: - ret = (32, array(array_unsigned_codes[4], data[:4 * length].decode().encode())) + ret = (32, array(array_unsigned_codes[4], data[:4 * length])) data = data[4 * length:] return ret, data @@ -646,23 +676,24 @@ def pack_value(self, value): if fmt not in (8, 16, 32): raise BadDataError('Invalid property data format {0}'.format(fmt)) - if type(val) in [bytes, str]: + if isinstance(val, binary_type): size = fmt // 8 vlen = len(val) if vlen % size: vlen = vlen - vlen % size - data = val[:vlen].encode() + data = val[:vlen] else: - data = val.encode() + data = val dlen = vlen // size else: - if type(val) is tuple: + if isinstance(val, tuple): val = list(val) size = fmt // 8 - data = array(array_unsigned_codes[size], val).tostring() + a = array(array_unsigned_codes[size], val) + data = encode_array(a) dlen = len(val) dl = len(data) @@ -692,7 +723,7 @@ def pack_value(self, value): class ValueList(Field): structcode = None - keyword_args = 1 + keyword_args = True default = 'usekeywords' def __init__(self, name, mask, pad, *fields): @@ -783,7 +814,7 @@ def pack_value(self, value): for i in range(len(v), keycodes): a.append(X.NoSymbol) - return a.tostring(), len(value), keycodes + return encode_array(a), len(value), keycodes class ModifierMapping(ValueField): @@ -814,7 +845,7 @@ def pack_value(self, value): for i in range(len(v), keycodes): a.append(0) - return a.tostring(), len(value), keycodes + return encode_array(a), len(value), keycodes class EventField(ValueField): structcode = None @@ -828,10 +859,10 @@ def pack_value(self, value): def parse_binary_value(self, data, display, length, format): from . import event - estruct = display.event_classes.get(_to_ord(data[0]) & 0x7f, event.AnyEvent) + estruct = display.event_classes.get(byte2int(data) & 0x7f, event.AnyEvent) if type(estruct) == dict: # this etype refers to a set of sub-events with individual subcodes - estruct = estruct[_to_ord(data[1])] + estruct = estruct[indexbytes(data, 1)] return estruct(display = display, binarydata = data[:32]), data[32:] @@ -876,11 +907,11 @@ class StrClass(object): structcode = None def pack_value(self, val): - return chr(len(val)) + val + return (chr(len(val)) + val).encode() def parse_binary(self, data, display): - slen = _to_ord(data[0]) + 1 - return data[1:slen], data[slen:] + slen = byte2int(data) + 1 + return decode_string(data[1:slen]), data[slen:] Str = StrClass() @@ -1026,7 +1057,7 @@ def to_binary(self, *varargs, **keys): pack_items.append(field_args[f.name]) # Multivalue field. Handled like single valuefield, - # but the value are tuple unpacked into seperate arguments + # but the value are tuple unpacked into separate arguments # which are appended to pack_items else: if f.check_value is not None: @@ -1049,7 +1080,7 @@ def pack_value(self, value): if type(value) is tuple: return self.to_binary(*value) - elif type(value) is dict: + elif isinstance(value, dict): return self.to_binary(**value) elif isinstance(value, DictWrapper): return self.to_binary(**value._data) @@ -1057,7 +1088,7 @@ def pack_value(self, value): raise BadDataError('%s is not a tuple or a list' % (value)) - def parse_value(self, val, display, rawdict = 0): + def parse_value(self, val, display, rawdict = False): """This function is used by List and Object fields to convert Struct objects with no var_fields into Python values. @@ -1100,9 +1131,9 @@ def parse_value(self, val, display, rawdict = 0): return DictWrapper(ret) return ret - def parse_binary(self, data, display, rawdict = 0): + def parse_binary(self, data, display, rawdict = False): - """values, remdata = s.parse_binary(data, display, rawdict = 0) + """values, remdata = s.parse_binary(data, display, rawdict = False) Convert a binary representation of the structure into Python values. @@ -1189,29 +1220,28 @@ def pack_value(self, value): for v in value: # Let values be simple strings, meaning a delta of 0 - if type(v) is bytes: + if type(v) in (str, bytes): v = (0, v) # A tuple, it should be (delta, string) # Encode it as one or more textitems - if type(v) in (tuple, dict) or \ - isinstance(v, DictWrapper): + if isinstance(v, (tuple, dict, DictWrapper)): - if type(v) is tuple: - delta, str = v + if isinstance(v, tuple): + delta, m_str = v else: delta = v['delta'] - str = v['string'] + m_str = v['string'] - while delta or str: + while delta or m_str: args['delta'] = delta - args['string'] = str[:254] + args['string'] = m_str[:254] data = data + self.string_textitem.to_binary(*(), **args) delta = 0 - str = str[254:] + m_str = m_str[254:] # Else an integer, i.e. a font change else: @@ -1232,12 +1262,12 @@ def parse_binary_value(self, data, display, length, format): break # font change - if _to_ord(data[0]) == 255: - values.append(struct.unpack('>L', data[1:5].decode().encode())[0]) + if byte2int(data) == 255: + values.append(struct.unpack('>L', bytes(data[1:5]))[0]) data = data[5:] # skip null strings - elif _to_ord(data[0]) == 0 and _to_ord(data[1]) == 0: + elif byte2int(data) == 0 and indexbytes(data, 1) == 0: data = data[2:] # string with delta @@ -1289,13 +1319,25 @@ def __str__(self): return str(self._data) def __repr__(self): - return '%s(%s)' % (self.__class__, repr(self._data)) + return '%s(%s)' % (self.__class__.__name__, repr(self._data)) - def __cmp__(self, other): + def __lt__(self, other): if isinstance(other, DictWrapper): - return cmp(self._data, other._data) + return self._data < other._data else: - return cmp(self._data, other) + return self._data < other + + def __gt__(self, other): + if isinstance(other, DictWrapper): + return self._data > other._data + else: + return self._data > other + + def __eq__(self, other): + if isinstance(other, DictWrapper): + return self._data == other._data + else: + return self._data == other class Request(object): @@ -1312,7 +1354,7 @@ def _set_error(self, error): return 0 class ReplyRequest(GetAttrData): - def __init__(self, display, defer = 0, *args, **keys): + def __init__(self, display, defer = False, *args, **keys): self._display = display self._binary = self._request.to_binary(*args, **keys) self._serial = None @@ -1321,7 +1363,7 @@ def __init__(self, display, defer = 0, *args, **keys): self._response_lock = lock.allocate_lock() - self._display.send_request(self, 1) + self._display.send_request(self, True) if not defer: self.reply() @@ -1347,7 +1389,7 @@ def reply(self): def _parse_response(self, data): self._response_lock.acquire() - self._data, d = self._reply.parse_binary(data, self._display, rawdict = 1) + self._data, d = self._reply.parse_binary(data, self._display, rawdict = True) self._response_lock.release() def _set_error(self, error): @@ -1357,7 +1399,7 @@ def _set_error(self, error): return 1 def __repr__(self): - return '<%s serial = %s, data = %s, error = %s>' % (self.__class__, self._serial, self._data, self._error) + return '<%s serial = %s, data = %s, error = %s>' % (self.__class__.__name__, self._serial, self._data, self._error) class Event(GetAttrData): @@ -1366,7 +1408,7 @@ def __init__(self, binarydata = None, display = None, if binarydata: self._binary = binarydata self._data, data = self._fields.parse_binary(binarydata, display, - rawdict = 1) + rawdict = True) # split event type into type and send_event bit self._data['send_event'] = not not self._data['type'] & 0x80 self._data['type'] = self._data['type'] & 0x7f @@ -1391,13 +1433,25 @@ def __repr__(self): kwlist.append('%s = %s' % (kw, repr(val))) kws = ', '.join(kwlist) - return '%s(%s)' % (self.__class__, kws) + return '%s(%s)' % (self.__class__.__name__, kws) + + def __lt__(self, other): + if isinstance(other, Event): + return self._data < other._data + else: + return self._data < other + + def __gt__(self, other): + if isinstance(other, Event): + return self._data > other._data + else: + return self._data > other - def __cmp__(self, other): + def __eq__(self, other): if isinstance(other, Event): - return cmp(self._data, other._data) + return self._data == other._data else: - return cmp(self._data, other) + return self._data == other def call_error_handler(handler, error, request): diff --git a/Xlib/protocol/structs.py b/Xlib/protocol/structs.py index 826a6940..1661440d 100644 --- a/Xlib/protocol/structs.py +++ b/Xlib/protocol/structs.py @@ -2,19 +2,22 @@ # # Copyright (C) 2000 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA # Xlib modules from .. import X diff --git a/Xlib/rdb.py b/Xlib/rdb.py index 17b1f003..03b06e2a 100644 --- a/Xlib/rdb.py +++ b/Xlib/rdb.py @@ -2,19 +2,22 @@ # # Copyright (C) 2000 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA # See end of file for an explanation of the algorithm and @@ -387,8 +390,14 @@ def __init__(self, path, dbs): self.skip = 1 self.db = dbs - def __cmp__(self, other): - return cmp(self.path, other.path) + def __lt__(self, other): + return self.path < other.path + + def __gt__(self, other): + return self.path > other.path + + def __eq__(self, other): + return self.path == other.path def match_length(self): return len(self.path) @@ -690,7 +699,7 @@ def get_display_opts(options, argv = sys.argv): # the resource object. # Example: Inserting "foo.bar*gazonk: yep" into an otherwise empty -# resource database would give the folliwing structure: +# resource database would give the following structure: # { 'foo': ( { 'bar': ( { }, # { 'gazonk': ( { }, diff --git a/Xlib/support/__init__.py b/Xlib/support/__init__.py index a7c049cf..4c0d622b 100644 --- a/Xlib/support/__init__.py +++ b/Xlib/support/__init__.py @@ -2,19 +2,22 @@ # # Copyright (C) 2000 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA __all__ = [ 'lock', diff --git a/Xlib/support/connect.py b/Xlib/support/connect.py index 6670817d..4db4c2f4 100644 --- a/Xlib/support/connect.py +++ b/Xlib/support/connect.py @@ -2,21 +2,25 @@ # # Copyright (C) 2000 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA import sys +import importlib # List the modules which contain the corresponding functions @@ -47,47 +51,52 @@ del _parts +def _relative_import(modname): + return importlib.import_module('..' + modname, __name__) + + def get_display(display): - """dname, host, dno, screen = get_display(display) + """dname, protocol, host, dno, screen = get_display(display) Parse DISPLAY into its components. If DISPLAY is None, use the default display. The return values are: - DNAME -- the full display name (string) - HOST -- the host name (string, possibly empty) - DNO -- display number (integer) - SCREEN -- default screen number (integer) + DNAME -- the full display name (string) + PROTOCOL -- the protocol to use (None if automatic) + HOST -- the host name (string, possibly empty) + DNO -- display number (integer) + SCREEN -- default screen number (integer) """ modname = _display_mods.get(platform, _default_display_mod) - mod = __import__(modname, globals()) + mod = _relative_import(modname) return mod.get_display(display) -def get_socket(dname, host, dno): - """socket = get_socket(dname, host, dno) +def get_socket(dname, protocol, host, dno): + """socket = get_socket(dname, protocol, host, dno) - Connect to the display specified by DNAME, HOST and DNO, which + Connect to the display specified by DNAME, PROTOCOL, HOST and DNO, which are the corresponding values from a previous call to get_display(). Return SOCKET, a new socket object connected to the X server. """ modname = _socket_mods.get(platform, _default_socket_mod) - mod = __import__(modname, globals()) - return mod.get_socket(dname, host, dno) + mod = _relative_import(modname) + return mod.get_socket(dname, protocol, host, dno) -def get_auth(sock, dname, host, dno): - """auth_name, auth_data = get_auth(sock, dname, host, dno) +def get_auth(sock, dname, protocol, host, dno): + """auth_name, auth_data = get_auth(sock, dname, protocol, host, dno) Return authentication data for the display on the other side of - SOCK, which was opened with DNAME, HOST and DNO. + SOCK, which was opened with DNAME, HOST and DNO, using PROTOCOL. Return AUTH_NAME and AUTH_DATA, two strings to be used in the connection setup request. """ modname = _auth_mods.get(platform, _default_auth_mod) - mod = __import__(modname, globals()) - return mod.get_auth(sock, dname, host, dno) + mod = _relative_import(modname) + return mod.get_auth(sock, dname, protocol, host, dno) diff --git a/Xlib/support/lock.py b/Xlib/support/lock.py index dca874f6..6eee31f4 100644 --- a/Xlib/support/lock.py +++ b/Xlib/support/lock.py @@ -2,19 +2,22 @@ # # Copyright (C) 2000 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA class _DummyLock(object): def __init__(self): diff --git a/Xlib/support/unix_connect.py b/Xlib/support/unix_connect.py index b5354cb5..bd690c18 100644 --- a/Xlib/support/unix_connect.py +++ b/Xlib/support/unix_connect.py @@ -2,116 +2,170 @@ # # Copyright (C) 2000,2002 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA import re import os import platform import socket - -# FCNTL is deprecated from Python 2.2, so only import it if we doesn't -# get the names we need. Furthermore, FD_CLOEXEC seems to be missing -# in Python 2.2. - -import fcntl - -if hasattr(fcntl, 'F_SETFD'): - F_SETFD = fcntl.F_SETFD - if hasattr(fcntl, 'FD_CLOEXEC'): - FD_CLOEXEC = fcntl.FD_CLOEXEC - else: - FD_CLOEXEC = 1 -else: - from FCNTL import F_SETFD, FD_CLOEXEC +from Xlib import error, xauth -from Xlib import error, xauth +SUPPORTED_PROTOCOLS = (None, 'tcp', 'unix') +# Darwin funky socket. uname = platform.uname() if (uname[0] == 'Darwin') and ([int(x) for x in uname[2].split('.')] >= [9, 0]): + SUPPORTED_PROTOCOLS += ('darwin',) + DARWIN_DISPLAY_RE = re.compile(r'^/private/tmp/[-:a-zA-Z0-9._]*:(?P[0-9]+)(\.(?P[0-9]+))?$') - display_re = re.compile(r'^([-:a-zA-Z0-9._/]*):([0-9]+)(\.([0-9]+))?$') +DISPLAY_RE = re.compile(r'^((?Ptcp|unix)/)?(?P[-:a-zA-Z0-9._]*):(?P[0-9]+)(\.(?P[0-9]+))?$') -else: - - display_re = re.compile(r'^([-:a-zA-Z0-9._]*):([0-9]+)(\.([0-9]+))?$') def get_display(display): # Use $DISPLAY if display isn't provided if display is None: display = os.environ.get('DISPLAY', '') - m = display_re.match(display) - if not m: + re_list = [(DISPLAY_RE, {})] + + if 'darwin' in SUPPORTED_PROTOCOLS: + re_list.insert(0, (DARWIN_DISPLAY_RE, {'protocol': 'darwin'})) + + for re, defaults in re_list: + m = re.match(display) + if m is not None: + protocol, host, dno, screen = [ + m.groupdict().get(field, defaults.get(field)) + for field in ('proto', 'host', 'dno', 'screen') + ] + break + else: raise error.DisplayNameError(display) - name = display - host = m.group(1) - dno = int(m.group(2)) - screen = m.group(4) + if protocol == 'tcp' and not host: + # Host is mandatory when protocol is TCP. + raise error.DisplayNameError(display) + + dno = int(dno) if screen: screen = int(screen) else: screen = 0 - return name, host, dno, screen + return display, protocol, host, dno, screen + + +def _get_tcp_socket(host, dno): + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.connect((host, 6000 + dno)) + return s + + +def _get_unix_socket(address): + s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + s.connect(address) + return s -def get_socket(dname, host, dno): +def get_socket(dname, protocol, host, dno): + assert protocol in SUPPORTED_PROTOCOLS try: - # Darwin funky socket - if (uname[0] == 'Darwin') and host and host.startswith('/tmp/'): - s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) - s.connect(dname) + # Darwin funky socket. + if protocol == 'darwin': + s = _get_unix_socket(dname) - # If hostname (or IP) is provided, use TCP socket - elif host: - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.connect((host, 6000 + dno)) + # TCP socket, note the special case: `unix:0.0` is equivalent to `:0.0`. + elif (protocol is None or protocol != 'unix') and host and host != 'unix': + s = _get_tcp_socket(host, dno) - # Else use Unix socket + # Unix socket. else: - s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) - s.connect('/tmp/.X11-unix/X%d' % dno) - except socket.error, val: + address = '/tmp/.X11-unix/X%d' % dno + if not os.path.exists(address): + # Use abstract address. + address = '\0' + address + try: + s = _get_unix_socket(address) + except socket.error: + if not protocol and not host: + # If no protocol/host was specified, fallback to TCP. + s = _get_tcp_socket(host, dno) + else: + raise + except socket.error as val: raise error.DisplayConnectionError(dname, str(val)) - # Make sure that the connection isn't inherited in child processes - fcntl.fcntl(s.fileno(), F_SETFD, FD_CLOEXEC) + # Make sure that the connection isn't inherited in child processes. + _ensure_not_inheritable(s) return s -def new_get_auth(sock, dname, host, dno): +def _ensure_not_inheritable(sock): + # According to PEP446, in Python 3.4 and above, + # it is not inherited in child processes by default. + # However, just in case, we explicitly make it non-inheritable. + # Also, we don't use the code like the following, + # because there would be no possibility of backporting to past versions. + # if sys.version_info.major == 3 and sys.version_info.minor >= 4: + # sock.set_inheritable(False) + # return + # We just check if the socket has `set_inheritable`. + if hasattr(sock, 'set_inheritable'): + sock.set_inheritable(False) + return + + # On Windows, + # Python doesn't support fcntl module because Windows doesn't have fcntl API. + # At least by not importing fcntl, we will be able to import python-xlib on Windows. + if platform.system() == 'Windows': + # so.. unfortunately, for Python 3.3 and below, on Windows, + # we can't make sure that the connection isn't inherited in child processes for now. + return + + import fcntl + fcntl.fcntl(sock.fileno(), fcntl.F_SETFD, fcntl.FD_CLOEXEC) + + +def new_get_auth(sock, dname, protocol, host, dno): + assert protocol in SUPPORTED_PROTOCOLS # Translate socket address into the xauth domain - if (uname[0] == 'Darwin') and host and host.startswith('/tmp/'): + if protocol == 'darwin': family = xauth.FamilyLocal addr = socket.gethostname() - elif host: + elif protocol == 'tcp': family = xauth.FamilyInternet # Convert the prettyprinted IP number into 4-octet string. # Sometimes these modules are too damn smart... octets = sock.getpeername()[0].split('.') - addr = ''.join(map(lambda x: chr(int(x)), octets)) + addr = bytearray(int(x) for x in octets) else: family = xauth.FamilyLocal - addr = socket.gethostname() + addr = socket.gethostname().encode() + + try: + au = xauth.Xauthority() + except error.XauthError: + return b'', b'' - au = xauth.Xauthority() while 1: try: return au.get_best_auth(family, addr, dno) @@ -122,16 +176,16 @@ def new_get_auth(sock, dname, host, dno): # $DISPLAY to localhost:10, but stores the xauth cookie as if # DISPLAY was :10. Hence, if localhost and not found, try # again as a Unix socket. - if family == xauth.FamilyInternet and addr == '\x7f\x00\x00\x01': + if family == xauth.FamilyInternet and addr == b'\x7f\x00\x00\x01': family = xauth.FamilyLocal - addr = socket.gethostname() + addr = socket.gethostname().encode() else: - return '', '' + return b'', b'' def old_get_auth(sock, dname, host, dno): # Find authorization cookie - auth_name = auth_data = '' + auth_name = auth_data = b'' try: # We could parse .Xauthority, but xauth is simpler @@ -148,7 +202,7 @@ def old_get_auth(sock, dname, host, dno): if len(parts) == 3: auth_name = parts[1] hexauth = parts[2] - auth = '' + auth = b'' # Translate hexcode into binary for i in range(0, len(hexauth), 2): diff --git a/Xlib/support/vms_connect.py b/Xlib/support/vms_connect.py index 106eba11..3c53695f 100644 --- a/Xlib/support/vms_connect.py +++ b/Xlib/support/vms_connect.py @@ -2,19 +2,22 @@ # # Copyright (C) 2000 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA import re import socket @@ -29,7 +32,7 @@ def get_display(display): # check DECW$DISPLAY instead, but that has to wait if display is None: - return ':0.0', 'localhost', 0, 0 + return ':0.0', None, 'localhost', 0, 0 m = display_re.match(display) if not m: @@ -49,10 +52,10 @@ def get_display(display): else: screen = 0 - return name, host, dno, screen + return name, None, host, dno, screen -def get_socket(dname, host, dno): +def get_socket(dname, protocol, host, dno): try: # Always use TCP/IP sockets. Later it would be nice to # be able to use DECNET och LOCAL connections. @@ -60,7 +63,7 @@ def get_socket(dname, host, dno): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((host, 6000 + dno)) - except socket.error, val: + except socket.error as val: raise error.DisplayConnectionError(dname, str(val)) return s diff --git a/Xlib/threaded.py b/Xlib/threaded.py index 6e51d27b..44fcafeb 100644 --- a/Xlib/threaded.py +++ b/Xlib/threaded.py @@ -2,24 +2,27 @@ # # Copyright (C) 2000 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA -import thread +from six.moves import _thread # We change the allocate_lock function in Xlib.support.lock to # return a basic Python lock, instead of the default dummy lock from Xlib.support import lock -lock.allocate_lock = thread.allocate_lock +lock.allocate_lock = _thread.allocate_lock diff --git a/Xlib/xauth.py b/Xlib/xauth.py index be738aba..303bd491 100644 --- a/Xlib/xauth.py +++ b/Xlib/xauth.py @@ -2,19 +2,22 @@ # # Copyright (C) 2000 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA import os import struct @@ -24,6 +27,8 @@ FamilyInternet = X.FamilyInternet FamilyDECnet = X.FamilyDECnet FamilyChaos = X.FamilyChaos +FamilyServerInterpreted = X.FamilyServerInterpreted +FamilyInternetV6 = X.FamilyInternetV6 FamilyLocal = 256 class Xauthority(object): @@ -39,9 +44,10 @@ def __init__(self, filename = None): '$HOME not set, cannot find ~/.Xauthority') try: - raw = open(filename, 'rb').read() - except IOError, err: - raise error.XauthError('~/.Xauthority: %s' % err) + with open(filename, 'rb') as fp: + raw = fp.read() + except IOError as err: + raise error.XauthError('could not read from {0}: {1}'.format(filename, err)) self.entries = [] @@ -82,12 +88,11 @@ def __init__(self, filename = None): break self.entries.append((family, addr, num, name, data)) - except struct.error, e: - print "Xlib.xauth: warning, failed to parse part of xauthority file (%s), aborting all further parsing" % filename - #pass + except struct.error: + print("Xlib.xauth: warning, failed to parse part of xauthority file {0}, aborting all further parsing".format(filename)) if len(self.entries) == 0: - print "Xlib.xauth: warning, no xauthority details available" + print("Xlib.xauth: warning, no xauthority details available") # raise an error? this should get partially caught by the XNoAuthError in get_best_auth.. def __len__(self): @@ -97,7 +102,7 @@ def __getitem__(self, i): return self.entries[i] def get_best_auth(self, family, address, dispno, - types = ( "MIT-MAGIC-COOKIE-1", )): + types = ( b"MIT-MAGIC-COOKIE-1", )): """Find an authentication entry matching FAMILY, ADDRESS and DISPNO. @@ -110,11 +115,13 @@ def get_best_auth(self, family, address, dispno, otherwise XNoAuthError is raised. """ - num = str(dispno) + num = str(dispno).encode() matches = {} for efam, eaddr, enum, ename, edata in self.entries: + if enum == b'' and ename not in matches: + enum = num if efam == family and eaddr == address and num == enum: matches[ename] = edata diff --git a/Xlib/xobject/__init__.py b/Xlib/xobject/__init__.py index 06da3453..67d32549 100644 --- a/Xlib/xobject/__init__.py +++ b/Xlib/xobject/__init__.py @@ -2,19 +2,22 @@ # # Copyright (C) 2000 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA __all__ = [ 'colormap', diff --git a/Xlib/xobject/colormap.py b/Xlib/xobject/colormap.py index 3353da4b..033fb493 100644 --- a/Xlib/xobject/colormap.py +++ b/Xlib/xobject/colormap.py @@ -2,24 +2,27 @@ # # Copyright (C) 2000 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA from Xlib import error from Xlib.protocol import request -import resource +from . import resource import re diff --git a/Xlib/xobject/cursor.py b/Xlib/xobject/cursor.py index 574f5ce7..432e4fd9 100644 --- a/Xlib/xobject/cursor.py +++ b/Xlib/xobject/cursor.py @@ -2,23 +2,26 @@ # # Copyright (C) 2000 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA from Xlib.protocol import request -import resource +from . import resource class Cursor(resource.Resource): __cursor__ = resource.Resource.__resource__ @@ -29,8 +32,9 @@ def free(self, onerror = None): cursor = self.id) self.display.free_resource_id(self.id) - def recolor(self, (fore_red, fore_green, fore_blue), - (back_red, back_green, back_blue), onerror = None): + def recolor(self, foreground, background, onerror=None): + fore_red, fore_green, fore_blue = foreground + back_red, back_green, back_blue = background request.RecolorCursor(display = self.display, onerror = onerror, diff --git a/Xlib/xobject/drawable.py b/Xlib/xobject/drawable.py index 33e7b004..f8e625f6 100644 --- a/Xlib/xobject/drawable.py +++ b/Xlib/xobject/drawable.py @@ -2,31 +2,34 @@ # # Copyright (C) 2000 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -from Xlib import X, Xatom, Xutil +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA + +from Xlib import X, Xatom from Xlib.protocol import request, rq # Other X resource objects -import resource -import colormap -import cursor -import fontable +from . import resource +from . import colormap +from . import cursor +from . import fontable # Inter-client communication conventions -import icccm +from . import icccm class Drawable(resource.Resource): __drawable__ = resource.Resource.__resource__ @@ -229,7 +232,7 @@ def put_pil_image(self, gc, x, y, image, onerror = None): unit = self.display.info.bitmap_format_scanline_unit stride = roundup(width * unit, pad) >> 3 else: - raise ValueError, 'Unknown data format' + raise ValueError('Unknown data format') maxlen = (self.display.info.max_request_length << 2) \ - request.PutImage._request.static_size @@ -246,7 +249,7 @@ def put_pil_image(self, gc, x, y, image, onerror = None): else: subimage = image w, h = subimage.size - data = subimage.tostring("raw", rawmode, stride, 0) + data = subimage.tobytes("raw", rawmode, stride, 0) self.put_image(gc, x, y, w, h, format, depth, 0, data) y1 = y1 + h y = y + h @@ -317,6 +320,9 @@ def query_best_size(self, item_class, width, height): class Window(Drawable): __window__ = resource.Resource.__resource__ + _STRING_ENCODING = 'ISO-8859-1' + _UTF8_STRING_ENCODING = 'UTF-8' + def create_window(self, x, y, width, height, border_width, depth, window_class = X.CopyFromParent, visual = X.CopyFromParent, @@ -418,8 +424,7 @@ def query_tree(self): return request.QueryTree(display = self.display, window = self.id) - - def change_property(self, property, type, format, data, + def change_property(self, property, property_type, format, data, mode = X.PropModeReplace, onerror = None): request.ChangeProperty(display = self.display, @@ -427,21 +432,31 @@ def change_property(self, property, type, format, data, mode = mode, window = self.id, property = property, - type = type, + type = property_type, data = (format, data)) + def change_text_property(self, property, property_type, data, + mode = X.PropModeReplace, onerror = None): + if not isinstance(data, bytes): + if property_type == Xatom.STRING: + data = data.encode(self._STRING_ENCODING) + elif property_type == self.display.get_atom('UTF8_STRING'): + data = data.encode(self._UTF8_STRING_ENCODING) + self.change_property(property, property_type, 8, data, + mode=mode, onerror=onerror) + def delete_property(self, property, onerror = None): request.DeleteProperty(display = self.display, onerror = onerror, window = self.id, property = property) - def get_property(self, property, type, offset, length, delete = 0): + def get_property(self, property, property_type, offset, length, delete = False): r = request.GetProperty(display = self.display, delete = delete, window = self.id, property = property, - type = type, + type = property_type, long_offset = offset, long_length = length) @@ -453,12 +468,12 @@ def get_property(self, property, type, offset, length, delete = 0): else: return None - def get_full_property(self, property, type, sizehint = 10): - prop = self.get_property(property, type, 0, sizehint) + def get_full_property(self, property, property_type, sizehint = 10): + prop = self.get_property(property, property_type, 0, sizehint) if prop: val = prop.value if prop.bytes_after: - prop = self.get_property(property, type, sizehint, + prop = self.get_property(property, property_type, sizehint, prop.bytes_after // 4 + 1) val = val + prop.value @@ -467,6 +482,19 @@ def get_full_property(self, property, type, sizehint = 10): else: return None + def get_full_text_property(self, property, property_type=X.AnyPropertyType, sizehint = 10): + prop = self.get_full_property(property, property_type, + sizehint=sizehint) + if prop is None or prop.format != 8: + return None + if prop.property_type == Xatom.STRING: + prop.value = prop.value.decode(self._STRING_ENCODING) + elif prop.property_type == self.display.get_atom('UTF8_STRING'): + prop.value = prop.value.decode(self._UTF8_STRING_ENCODING) + # FIXME: at least basic support for compound text would be nice. + # elif prop.property_type == self.display.get_atom('COMPOUND_TEXT'): + return prop.value + def list_properties(self): r = request.ListProperties(display = self.display, window = self.id) @@ -488,7 +516,7 @@ def convert_selection(self, selection, target, property, time, onerror = None): property = property, time = time) - def send_event(self, event, event_mask = 0, propagate = 0, onerror = None): + def send_event(self, event, event_mask = 0, propagate = False, onerror = None): request.SendEvent(display = self.display, onerror = onerror, propagate = propagate, @@ -601,7 +629,7 @@ def set_input_focus(self, revert_to, time, onerror = None): focus = self.id, time = time) - def clear_area(self, x = 0, y = 0, width = 0, height = 0, exposures = 0, onerror = None): + def clear_area(self, x = 0, y = 0, width = 0, height = 0, exposures = False, onerror = None): request.ClearArea(display = self.display, onerror = onerror, exposures = exposures, @@ -634,47 +662,37 @@ def rotate_properties(self, properties, delta, onerror = None): properties = properties) def set_wm_name(self, name, onerror = None): - self.change_property(Xatom.WM_NAME, Xatom.STRING, 8, name, - onerror = onerror) + self.change_text_property(Xatom.WM_NAME, Xatom.STRING, name, + onerror = onerror) def get_wm_name(self): - d = self.get_full_property(Xatom.WM_NAME, Xatom.STRING) - if d is None or d.format != 8: - return None - else: - return d.value + return self.get_full_text_property(Xatom.WM_NAME, Xatom.STRING) def set_wm_icon_name(self, name, onerror = None): - self.change_property(Xatom.WM_ICON_NAME, Xatom.STRING, 8, name, - onerror = onerror) + self.change_text_property(Xatom.WM_ICON_NAME, Xatom.STRING, name, + onerror = onerror) def get_wm_icon_name(self): - d = self.get_full_property(Xatom.WM_ICON_NAME, Xatom.STRING) - if d is None or d.format != 8: - return None - else: - return d.value - + return self.get_full_text_property(Xatom.WM_ICON_NAME, Xatom.STRING) def set_wm_class(self, inst, cls, onerror = None): - self.change_property(Xatom.WM_CLASS, Xatom.STRING, 8, - '%s\0%s\0' % (inst, cls), - onerror = onerror) + self.change_text_property(Xatom.WM_CLASS, Xatom.STRING, + '%s\0%s\0' % (inst, cls), + onerror = onerror) def get_wm_class(self): - d = self.get_full_property(Xatom.WM_CLASS, Xatom.STRING) - if d is None or d.format != 8: + value = self.get_full_text_property(Xatom.WM_CLASS, Xatom.STRING) + if value is None: + return None + parts = value.split('\0') + if len(parts) < 2: return None else: - parts = d.value.split('\0') - if len(parts) < 2: - return None - else: - return parts[0], parts[1] + return parts[0], parts[1] def set_wm_transient_for(self, window, onerror = None): self.change_property(Xatom.WM_TRANSIENT_FOR, Xatom.WINDOW, - 32, window.id, + 32, [window.id], onerror = onerror) def get_wm_transient_for(self): @@ -716,15 +734,11 @@ def get_wm_colormap_windows(self): def set_wm_client_machine(self, name, onerror = None): - self.change_property(Xatom.WM_CLIENT_MACHINE, Xatom.STRING, 8, name, - onerror = onerror) + self.change_text_property(Xatom.WM_CLIENT_MACHINE, Xatom.STRING, name, + onerror = onerror) def get_wm_client_machine(self): - d = self.get_full_property(Xatom.WM_CLIENT_MACHINE, Xatom.STRING) - if d is None or d.format != 8: - return None - else: - return d.value + return self.get_full_text_property(Xatom.WM_CLIENT_MACHINE, Xatom.STRING) def set_wm_normal_hints(self, hints = {}, onerror = None, **keys): self._set_struct_prop(Xatom.WM_NORMAL_HINTS, Xatom.WM_SIZE_HINTS, @@ -765,7 +779,7 @@ def get_wm_icon_size(self): def _get_struct_prop(self, pname, ptype, pstruct): r = self.get_property(pname, ptype, 0, pstruct.static_size // 4) if r and r.format == 32: - value = r.value.tostring() + value = rq.encode_array(r.value) if len(value) == pstruct.static_size: return pstruct.parse_binary(value, self.display)[0] @@ -797,10 +811,9 @@ def free(self, onerror = None): self.display.free_resource_id(self.id) - def create_cursor(self, mask, - (fore_red, fore_green, fore_blue), - (back_red, back_green, back_blue), - x, y): + def create_cursor(self, mask, foreground, background, x, y): + fore_red, fore_green, fore_blue = foreground + back_red, back_green, back_blue = background cid = self.display.allocate_resource_id() request.CreateCursor(display = self.display, cid = cid, diff --git a/Xlib/xobject/fontable.py b/Xlib/xobject/fontable.py index befe85f8..892f2665 100644 --- a/Xlib/xobject/fontable.py +++ b/Xlib/xobject/fontable.py @@ -2,24 +2,27 @@ # # Copyright (C) 2000 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA from Xlib.protocol import request -import resource -import cursor +from . import resource +from . import cursor class Fontable(resource.Resource): __fontable__ = resource.Resource.__resource__ @@ -85,8 +88,9 @@ def close(self, onerror = None): self.display.free_resource_id(self.id) def create_glyph_cursor(self, mask, source_char, mask_char, - (fore_red, fore_green, fore_blue), - (back_red, back_green, back_blue)): + foreground, background): + fore_red, fore_green, fore_blue = foreground + back_red, back_green, back_blue = background cid = self.display.allocate_resource_id() request.CreateGlyphCursor(display = self.display, diff --git a/Xlib/xobject/icccm.py b/Xlib/xobject/icccm.py index a6a1eb4e..d445e6df 100644 --- a/Xlib/xobject/icccm.py +++ b/Xlib/xobject/icccm.py @@ -2,19 +2,22 @@ # # Copyright (C) 2000 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA from Xlib import X, Xutil from Xlib.protocol import rq diff --git a/Xlib/xobject/resource.py b/Xlib/xobject/resource.py index 4c08483c..ea256ca1 100644 --- a/Xlib/xobject/resource.py +++ b/Xlib/xobject/resource.py @@ -2,19 +2,22 @@ # # Copyright (C) 2000 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA from Xlib.protocol import request @@ -27,23 +30,23 @@ def __init__(self, display, rid, owner = 0): def __resource__(self): return self.id - def __cmp__(self, obj): + def __eq__(self, obj): if isinstance(obj, Resource): if self.display == obj.display: - return cmp(self.id, obj.id) + return self.id == obj.id else: - return cmp(self.display, obj.display) + return False else: - return cmp(id(self), id(obj)) + return id(self) == id(obj) + + def __ne__(self, obj): + return not self == obj def __hash__(self): return int(self.id) - def __str__(self): - return '%s(0x%08x)' % (self.__class__, self.id) - def __repr__(self): - return '<%s 0x%08x>' % (self.__class__, self.id) + return '<%s 0x%08x>' % (self.__class__.__name__, self.id) def kill_client(self, onerror = None): request.KillClient(display = self.display, diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 00000000..72bff4bf --- /dev/null +++ b/codecov.yml @@ -0,0 +1,8 @@ +comment: + layout: header, changes, diff +coverage: + ignore: + - examples/.* + - test/.* + status: + patch: false diff --git a/debian/rules b/debian/rules index 9bc7713d..dd820f18 100644 --- a/debian/rules +++ b/debian/rules @@ -7,7 +7,7 @@ # Uncomment this to turn on verbose mode. #export DH_VERBOSE=1 -# This is the debhelper compatability version to use. +# This is the debhelper compatibility version to use. export DH_COMPAT=1 build: build-stamp diff --git a/dev-requirements.txt b/dev-requirements.txt index 403b034e..b2f5288c 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,2 +1,5 @@ coverage -codecov \ No newline at end of file +codecov +mock +nose +setuptools-scm diff --git a/doc/html/Makefile b/doc/html/Makefile index 7f20e89d..2fd50997 100644 --- a/doc/html/Makefile +++ b/doc/html/Makefile @@ -3,7 +3,7 @@ include ../src/defs python-xlib_toc.html: $(SRCS) - ./texi2html -splitnode -menu $(TOPSRC) + texi2html --output=. --split=node --menu $(TOPSRC) ln -sf python-xlib_toc.html index.html clean: diff --git a/doc/html/texi2html b/doc/html/texi2html deleted file mode 100755 index 80bc9a13..00000000 --- a/doc/html/texi2html +++ /dev/null @@ -1,2128 +0,0 @@ -eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $argv:q' - if 0; -'di '; -'ig 00 '; -#+############################################################################## -# # -# File: texi2html # -# # -# Description: Program to transform most Texinfo documents to HTML # -# # -#-############################################################################## - -# From @(#)texi2html 1.52 01/05/98 Written (mainly) by Lionel Cons, Lionel.Cons@cern.ch -# This version of texi2html is currently maintained at -# ftp://ftp.cs.umb.edu/pub/tex/texi2html by kb@cs.umb.edu. - -# The man page for this program is included at the end of this file and can be -# viewed using the command 'nroff -man texi2html'. -# Please read the copyright at the end of the man page. - -#+++############################################################################ -# # -# Constants # -# # -#---############################################################################ - -$DEBUG_TOC = 1; -$DEBUG_INDEX = 2; -$DEBUG_BIB = 4; -$DEBUG_GLOSS = 8; -$DEBUG_DEF = 16; -$DEBUG_HTML = 32; -$DEBUG_USER = 64; - -$BIBRE = '\[[\w\/-]+\]'; # RE for a bibliography reference -$FILERE = '[\/\w.+-]+'; # RE for a file name -$VARRE = '[^\s\{\}]+'; # RE for a variable name -$NODERE = '[^@{}:\'`",]+'; # RE for a node name -$NODESRE = '[^@{}:\'`"]+'; # RE for a list of node names -$XREFRE = '[^@{}]+'; # RE for a xref (should use NODERE) - -$ERROR = "***"; # prefix for errors and warnings -$THISVERSION = "1.56k"; -$THISPROG = "texi2html $THISVERSION"; # program name and version -$HOMEPAGE = "http://wwwinfo.cern.ch/dis/texi2html/"; # program home page -$TODAY = &pretty_date; # like "20 September 1993" -$SPLITTAG = "\n"; # tag to know where to split -$PROTECTTAG = "_ThisIsProtected_"; # tag to recognize protected sections -$html2_doctype = ''; - -# -# language dependent constants -# -#$LDC_SEE = 'see'; -#$LDC_SECTION = 'section'; -#$LDC_IN = 'in'; -#$LDC_TOC = 'Table of Contents'; -#$LDC_GOTO = 'Go to the'; -#$LDC_FOOT = 'Footnotes'; -# TODO: @def* shortcuts - -# -# pre-defined indices -# -%predefined_index = ( - 'cp', 'c', - 'fn', 'f', - 'vr', 'v', - 'ky', 'k', - 'pg', 'p', - 'tp', 't', - ); - -# -# valid indices -# -%valid_index = ( - 'c', 1, - 'f', 1, - 'v', 1, - 'k', 1, - 'p', 1, - 't', 1, - ); - -# -# texinfo section names to level -# -%sec2level = ( - 'top', 0, - 'chapter', 1, - 'unnumbered', 1, - 'majorheading', 1, - 'chapheading', 1, - 'appendix', 1, - 'section', 2, - 'unnumberedsec', 2, - 'heading', 2, - 'appendixsec', 2, - 'appendixsection', 2, - 'subsection', 3, - 'unnumberedsubsec', 3, - 'subheading', 3, - 'appendixsubsec', 3, - 'subsubsection', 4, - 'unnumberedsubsubsec', 4, - 'subsubheading', 4, - 'appendixsubsubsec', 4, - ); - -# -# accent map, TeX command to ISO name -# -%accent_map = ( - '"', 'uml', - '~', 'tilde', - '^', 'circ', - '`', 'grave', - '\'', 'acute', - ); - -# -# texinfo "simple things" (@foo) to HTML ones -# -%simple_map = ( - # cf. makeinfo.c - "*", "
", # HTML+ - " ", " ", - "\t", " ", - "-", "­", # soft hyphen - "\n", "\n", - "|", "", - 'tab', '<\/TD>', - # spacing commands - ":", "", - "!", "!", - "?", "?", - ".", ".", - "-", "", - ); - -# -# texinfo "things" (@foo{}) to HTML ones -# -%things_map = ( - 'TeX', 'TeX', - 'br', '

', # paragraph break - 'bullet', '*', - 'copyright', '(C)', - 'dots', '...', - 'equiv', '==', - 'error', 'error-->', - 'expansion', '==>', - 'minus', '-', - 'point', '-!-', - 'print', '-|', - 'result', '=>', - 'today', $TODAY, - ); - -# -# texinfo styles (@foo{bar}) to HTML ones -# -%style_map = ( - 'asis', '', - 'b', 'B', - 'cite', 'CITE', - 'code', 'CODE', - 'ctrl', '&do_ctrl', # special case - 'dfn', 'EM', # DFN tag is illegal in the standard - 'dmn', '', # useless - 'email', '&do_email', # insert a clickable email address - 'emph', 'EM', - 'file', '"TT', # will put quotes, cf. &apply_style - 'i', 'I', - 'kbd', 'KBD', - 'key', 'KBD', - 'math', 'EM', - 'r', '', # unsupported - 'samp', '"SAMP', # will put quotes, cf. &apply_style - 'sc', '&do_sc', # special case - 'strong', 'STRONG', - 't', 'TT', - 'titlefont', '', # useless - 'uref', '&do_uref', # insert a clickable URL - 'url', '&do_url', # insert a clickable URL - 'var', 'VAR', - 'w', '', # unsupported - ); - -# -# texinfo format (@foo/@end foo) to HTML ones -# -%format_map = ( - 'display', 'PRE', - 'example', 'PRE', - 'format', 'PRE', - 'lisp', 'PRE', - 'quotation', 'BLOCKQUOTE', - 'smallexample', 'PRE', - 'smalllisp', 'PRE', - # lists - 'itemize', 'UL', - 'enumerate', 'OL', - # poorly supported - 'flushleft', 'PRE', - 'flushright', 'PRE', - ); - -# -# texinfo definition shortcuts to real ones -# -%def_map = ( - # basic commands - 'deffn', 0, - 'defvr', 0, - 'deftypefn', 0, - 'deftypevr', 0, - 'defcv', 0, - 'defop', 0, - 'deftp', 0, - # basic x commands - 'deffnx', 0, - 'defvrx', 0, - 'deftypefnx', 0, - 'deftypevrx', 0, - 'defcvx', 0, - 'defopx', 0, - 'deftpx', 0, - # shortcuts - 'defun', 'deffn Function', - 'defmac', 'deffn Macro', - 'defspec', 'deffn {Special Form}', - 'defvar', 'defvr Variable', - 'defopt', 'defvr {User Option}', - 'deftypefun', 'deftypefn Function', - 'deftypevar', 'deftypevr Variable', - 'defivar', 'defcv {Instance Variable}', - 'defmethod', 'defop Method', - # x shortcuts - 'defunx', 'deffnx Function', - 'defmacx', 'deffnx Macro', - 'defspecx', 'deffnx {Special Form}', - 'defvarx', 'defvrx Variable', - 'defoptx', 'defvrx {User Option}', - 'deftypefunx', 'deftypefnx Function', - 'deftypevarx', 'deftypevrx Variable', - 'defivarx', 'defcvx {Instance Variable}', - 'defmethodx', 'defopx Method', - ); - -# -# things to skip -# -%to_skip = ( - # comments - 'c', 1, - 'comment', 1, - 'ifnothtml', 1, - # useless - 'detailmenu', 1, - 'direntry', 1, - 'contents', 1, - 'shortcontents', 1, - 'summarycontents', 1, - 'footnotestyle', 1, - 'end ifclear', 1, - 'end ifset', 1, - 'titlepage', 1, - 'end titlepage', 1, - # unsupported commands (formatting) - 'afourpaper', 1, - 'cropmarks', 1, - 'finalout', 1, - 'headings', 1, - 'sp', 1, - 'need', 1, - 'page', 1, - 'setchapternewpage', 1, - 'everyheading', 1, - 'everyfooting', 1, - 'evenheading', 1, - 'evenfooting', 1, - 'oddheading', 1, - 'oddfooting', 1, - 'smallbook', 1, - 'vskip', 1, - 'filbreak', 1, - 'paragraphindent', 1, - # unsupported formats - 'cartouche', 1, - 'end cartouche', 1, - 'group', 1, - 'end group', 1, - ); - -#+++############################################################################ -# # -# Argument parsing, initialisation # -# # -#---############################################################################ - -%value = (); # hold texinfo variables, see also -D - -$use_bibliography = 1; -$use_acc = 0; -$debug = 0; -$doctype = ''; -$check = 0; -$expandinfo = 0; -$use_glossary = 0; -$invisible_mark = ''; -$use_iso = 0; -@include_dirs = (); -$show_menu = 0; -$number_sections = 0; -$split_node = 0; -$split_chapter = 0; -$monolithic = 0; -$verbose = 0; -$usage = < 0; - ✓ - exit; -} - -if (($split_node || $split_chapter) && $monolithic) { - warn "Can't use -monolithic with -split, -monolithic ignored.\n"; - $monolithic = 0; -} -if ($expandinfo) { - $to_skip{'ifinfo'}++; - $to_skip{'end ifinfo'}++; - $to_skip{'ifnottex'}++; - $to_skip{'end ifnottex'}++; -} else { - $to_skip{'iftex'}++; - $to_skip{'end iftex'}++; -} -$invisible_mark = '' if $invisible_mark eq 'xbm'; -die $usage unless @ARGV == 1; -$docu = shift(@ARGV); -if ($docu =~ /.*\//) { - chop($docu_dir = $&); - $docu_name = $'; -} else { - $docu_dir = '.'; - $docu_name = $docu; -} -unshift(@include_dirs, $docu_dir); -$docu_name =~ s/\.te?x(i|info)?$//; # basename of the document - -$docu_doc = "$docu_name.html"; # document's contents -if ($monolithic) { - $docu_toc = $docu_foot = $docu_doc; -} else { - $docu_toc = "${docu_name}_toc.html"; # document's table of contents - $docu_foot = "${docu_name}_foot.html"; # document's footnotes -} - -# -# variables -# -$value{'html'} = 1; # predefine html (the output format) -$value{'texi2html'} = $THISVERSION; # predefine texi2html (the translator) -# _foo: internal to track @foo -foreach ('_author', '_title', '_subtitle', - '_settitle', '_setfilename') { - $value{$_} = ''; # prevent -w warnings -} -%node2sec = (); # node to section name -%node2href = (); # node to HREF -%bib2href = (); # bibliography reference to HREF -%gloss2href = (); # glossary term to HREF -@sections = (); # list of sections -%tag2pro = (); # protected sections - -# -# initial indexes -# -$bib_num = 0; -$foot_num = 0; -$gloss_num = 0; -$idx_num = 0; -$sec_num = 0; -$doc_num = 0; -$html_num = 0; - -# -# can I use ISO8879 characters? (HTML+) -# -if ($use_iso) { - $things_map{'bullet'} = "•"; - $things_map{'copyright'} = "©"; - $things_map{'dots'} = "…"; - $things_map{'equiv'} = "≡"; - $things_map{'expansion'} = "→"; - $things_map{'point'} = "∗"; - $things_map{'result'} = "⇒"; -} - -# -# read texi2html extensions (if any) -# -$extensions = 'texi2html.ext'; # extensions in working directory -if (-f $extensions) { - print "# reading extensions from $extensions\n" if $verbose; - require($extensions); -} -($progdir = $0) =~ s/[^\/]+$//; -if ($progdir && ($progdir ne './')) { - $extensions = "${progdir}texi2html.ext"; # extensions in texi2html directory - if (-f $extensions) { - print "# reading extensions from $extensions\n" if $verbose; - require($extensions); - } -} - -print "# reading from $docu\n" if $verbose; - -#+++############################################################################ -# # -# Pass 1: read source, handle command, variable, simple substitution # -# # -#---############################################################################ - -@lines = (); # whole document -@toc_lines = (); # table of contents -$toplevel = 0; # top level seen in hierarchy -$curlevel = 0; # current level in TOC -$node = ''; # current node name -$in_table = 0; # am I inside a table -$table_type = ''; # type of table ('', 'f', 'v', 'multi') -@tables = (); # nested table support -$in_bibliography = 0; # am I inside a bibliography -$in_glossary = 0; # am I inside a glossary -$in_top = 0; # am I inside the top node -$in_pre = 0; # am I inside a preformatted section -$in_list = 0; # am I inside a list -$in_html = 0; # am I inside an HTML section -$first_line = 1; # is it the first line -$dont_html = 0; # don't protect HTML on this line -$split_num = 0; # split index -$deferred_ref = ''; # deferred reference for indexes -@html_stack = (); # HTML elements stack -$html_element = ''; # current HTML element -&html_reset; - -# build code for simple substitutions -# the maps used (%simple_map and %things_map) MUST be aware of this -# watch out for regexps, / and escaped characters! -$subst_code = ''; -foreach (keys(%simple_map)) { - ($re = $_) =~ s/(\W)/\\$1/g; # protect regexp chars - $subst_code .= "s/\\\@$re/$simple_map{$_}/g;\n"; -} -foreach (keys(%things_map)) { - $subst_code .= "s/\\\@$_\\{\\}/$things_map{$_}/g;\n"; -} -if ($use_acc) { - # accentuated characters - foreach (keys(%accent_map)) { - if ($_ eq "`") { - $subst_code .= "s/$;3"; - } elsif ($_ eq "'") { - $subst_code .= "s/$;4"; - } else { - $subst_code .= "s/\\\@\\$_"; - } - $subst_code .= "([aeiou])/&\${1}$accent_map{$_};/gi;\n"; - } -} -eval("sub simple_substitutions { $subst_code }"); - -&init_input; -while ($_ = &next_line) { - # - # remove \input on the first lines only - # - if ($first_line) { - next if /^\\input/; - $first_line = 0; - } - # - # parse texinfo tags - # - $tag = ''; - $end_tag = ''; - if (/^\s*\@end\s+(\w+)\b/) { - $end_tag = $1; - } elsif (/^\s*\@(\w+)\b/) { - $tag = $1; - } - # - # handle @ifhtml / @end ifhtml - # - if ($in_html) { - if ($end_tag eq 'ifhtml') { - $in_html = 0; - } else { - $tag2pro{$in_html} .= $_; - } - next; - } elsif ($tag eq 'ifhtml') { - $in_html = $PROTECTTAG . ++$html_num; - push(@lines, $in_html); - next; - } - # - # try to skip the line - # - if ($end_tag) { - next if $to_skip{"end $end_tag"}; - } elsif ($tag) { - next if $to_skip{$tag}; - last if $tag eq 'bye'; - } - if ($in_top) { - # parsing the top node - if ($tag eq 'node' || $tag eq 'include' || $sec2level{$tag}) { - # no more in top - $in_top = 0; - } else { - # skip it - next; - } - } - # - # try to remove inlined comments - # syntax from tex-mode.el comment-start-skip - # - s/((^|[^\@])(\@\@)*)\@c(omment)? .*/$1/; - # non-@ substitutions cf. texinfmt.el - unless ($in_pre) { - s/``/\"/g; - s/''/\"/g; - s/([\w ])---([\w ])/$1--$2/g; - } - # - # analyze the tag - # - if ($tag) { - # skip lines - &skip_until($tag), next if $tag eq 'ignore'; - if ($expandinfo) { - &skip_until($tag), next if $tag eq 'iftex'; - } else { - &skip_until($tag), next if $tag eq 'ifinfo'; - } - &skip_until($tag), next if $tag eq 'tex'; - # handle special tables - if ($tag =~ /^(|f|v|multi)table$/) { - $table_type = $1; - $tag = 'table'; - } - # special cases - if ($tag eq 'top' || ($tag eq 'node' && /^\@node\s+top\s*,/i)) { - $in_top = 1; - @lines = (); # ignore all lines before top (title page garbage) - next; - } elsif ($tag eq 'node') { - $in_top = 0; - warn "$ERROR Bad node line: $_" unless $_ =~ /^\@node\s$NODESRE$/o; - $_ = &protect_html($_); # if node contains '&' for instance - s/^\@node\s+//; - ($node) = split(/,/); - &normalise_node($node); - if ($split_node) { - &next_doc; - push(@lines, $SPLITTAG) if $split_num++; - push(@sections, $node); - } - next; - } elsif ($tag eq 'include') { - if (/^\@include\s+($FILERE)\s*$/o) { - $file = $1; - unless (-e $file) { - foreach $dir (@include_dirs) { - $file = "$dir/$1"; - last if -e $file; - } - } - if (-e $file) { - &open($file); - print "# including $file\n" if $verbose; - } else { - warn "$ERROR Can't find $file, skipping"; - } - } else { - warn "$ERROR Bad include line: $_"; - } - next; - } elsif ($tag eq 'ifclear') { - if (/^\@ifclear\s+($VARRE)\s*$/o) { - next unless defined($value{$1}); - &skip_until($tag); - } else { - warn "$ERROR Bad ifclear line: $_"; - } - next; - } elsif ($tag eq 'ifset') { - if (/^\@ifset\s+($VARRE)\s*$/o) { - next if defined($value{$1}); - &skip_until($tag); - } else { - warn "$ERROR Bad ifset line: $_"; - } - next; - } elsif ($tag eq 'menu') { - unless ($show_menu) { - &skip_until($tag); - next; - } - &html_push_if($tag); - push(@lines, &html_debug("\n", __LINE__)); - } elsif ($format_map{$tag}) { - $in_pre = 1 if $format_map{$tag} eq 'PRE'; - &html_push_if($format_map{$tag}); - push(@lines, &html_debug("\n", __LINE__)); - $in_list++ if $format_map{$tag} eq 'UL' || $format_map{$tag} eq 'OL' ; - push(@lines, &debug("<$format_map{$tag}>\n", __LINE__)); - next; - } elsif ($tag eq 'table') { - if (/^\s*\@(|f|v)table\s+\@(\w+)/ || /^\s*\@multitable\s+/) { - $in_table = $2; - unshift(@tables, join($;, $table_type, $in_table)); - if ($table_type eq "multi") { - push(@lines, &debug("\n", __LINE__)); - &html_push_if('TABLE'); - } else { - push(@lines, &debug("
\n", __LINE__)); - &html_push_if('DL'); - } - push(@lines, &html_debug("\n", __LINE__)); - } else { - warn "$ERROR Bad table line: $_"; - } - next; - } elsif ($tag eq 'synindex' || $tag eq 'syncodeindex') { - if (/^\@$tag\s+(\w)\w\s+(\w)\w\s*$/) { - eval("*${1}index = *${2}index"); - } else { - warn "$ERROR Bad syn*index line: $_"; - } - next; - } elsif ($tag eq 'sp') { - push(@lines, &debug("

\n", __LINE__)); - next; - } elsif ($tag eq 'setref') { - &protect_html; # if setref contains '&' for instance - if (/^\@$tag\s*{($NODERE)}\s*$/) { - $setref = $1; - $setref =~ s/\s+/ /g; # normalize - $setref =~ s/ $//; - $node2sec{$setref} = $name; - $node2href{$setref} = "$docu_doc#$docid"; - } else { - warn "$ERROR Bad setref line: $_"; - } - next; - } elsif ($tag eq 'defindex' || $tag eq 'defcodeindex') { - if (/^\@$tag\s+(\w\w)\s*$/) { - $valid_index{$1} = 1; - } else { - warn "$ERROR Bad defindex line: $_"; - } - next; - } elsif ($tag eq 'lowersections') { - local ($sec, $level); - while (($sec, $level) = each %sec2level) { - $sec2level{$sec} = $level + 1; - } - next; - } elsif ($tag eq 'raisesections') { - local ($sec, $level); - while (($sec, $level) = each %sec2level) { - $sec2level{$sec} = $level - 1; - } - next; - } elsif (defined($def_map{$tag})) { - if ($def_map{$tag}) { - s/^\@$tag\s+//; - $tag = $def_map{$tag}; - $_ = "\@$tag $_"; - $tag =~ s/\s.*//; - } - } elsif (defined($user_sub{$tag})) { - s/^\@$tag\s+//; - $sub = $user_sub{$tag}; - print "# user $tag = $sub, arg: $_" if $debug & $DEBUG_USER; - if (defined(&$sub)) { - chop($_); - &$sub($_); - } else { - warn "$ERROR Bad user sub for $tag: $sub\n"; - } - next; - } - if (defined($def_map{$tag})) { - s/^\@$tag\s+//; - if ($tag =~ /x$/) { - # extra definition line - $tag = $`; - $is_extra = 1; - } else { - $is_extra = 0; - } - while (/\{([^\{\}]*)\}/) { - # this is a {} construct - ($before, $contents, $after) = ($`, $1, $'); - # protect spaces - $contents =~ s/\s+/$;9/g; - # restore $_ protecting {} - $_ = "$before$;7$contents$;8$after"; - } - @args = split(/\s+/, &protect_html($_)); - foreach (@args) { - s/$;9/ /g; # unprotect spaces - s/$;7/\{/g; # ... { - s/$;8/\}/g; # ... } - } - $type = shift(@args); - $type =~ s/^\{(.*)\}$/$1/; - print "# def ($tag): {$type} ", join(', ', @args), "\n" - if $debug & $DEBUG_DEF; - $type .= ':'; # it's nicer like this - $name = shift(@args); - $name =~ s/^\{(.*)\}$/$1/; - if ($is_extra) { - $_ = &debug("

", __LINE__); - } else { - $_ = &debug("
\n
", __LINE__); - } - if ($tag eq 'deffn' || $tag eq 'defvr' || $tag eq 'deftp') { - $_ .= "$type $name"; - $_ .= " @args" if @args; - } elsif ($tag eq 'deftypefn' || $tag eq 'deftypevr' - || $tag eq 'defcv' || $tag eq 'defop') { - $ftype = $name; - $name = shift(@args); - $name =~ s/^\{(.*)\}$/$1/; - $_ .= "$type $ftype $name"; - $_ .= " @args" if @args; - } else { - warn "$ERROR Unknown definition type: $tag\n"; - $_ .= "$type $name"; - $_ .= " @args" if @args; - } - $_ .= &debug("\n
", __LINE__); - $name = &unprotect_html($name); - if ($tag eq 'deffn' || $tag eq 'deftypefn') { - unshift(@input_spool, "\@findex $name\n"); - } elsif ($tag eq 'defop') { - unshift(@input_spool, "\@findex $name on $ftype\n"); - } elsif ($tag eq 'defvr' || $tag eq 'deftypevr' || $tag eq 'defcv') { - unshift(@input_spool, "\@vindex $name\n"); - } else { - unshift(@input_spool, "\@tindex $name\n"); - } - $dont_html = 1; - } - } elsif ($end_tag) { - if ($format_map{$end_tag}) { - $in_pre = 0 if $format_map{$end_tag} eq 'PRE'; - $in_list-- if $format_map{$end_tag} eq 'UL' || $format_map{$end_tag} eq 'OL' ; - &html_pop_if('LI', 'P'); - &html_pop_if(); - push(@lines, &debug("\n", __LINE__)); - push(@lines, &html_debug("\n", __LINE__)); - } elsif ($end_tag =~ /^(|f|v|multi)table$/) { - unless (@tables) { - warn "$ERROR \@end $end_tag without \@*table\n"; - next; - } - ($table_type, $in_table) = split($;, shift(@tables)); - unless ($1 eq $table_type) { - warn "$ERROR \@end $end_tag without matching \@$end_tag\n"; - next; - } - if ($table_type eq "multi") { - push(@lines, "
\n"); - &html_pop_if('TR'); - } else { - push(@lines, "\n"); - &html_pop_if('DD'); - } - &html_pop_if(); - if (@tables) { - ($table_type, $in_table) = split($;, $tables[0]); - } else { - $in_table = 0; - } - } elsif (defined($def_map{$end_tag})) { - push(@lines, &debug("\n", __LINE__)); - } elsif ($end_tag eq 'menu') { - &html_pop_if(); - push(@lines, $_); # must keep it for pass 2 - } - next; - } - # - # misc things - # - # protect texi and HTML things - &protect_texi; - $_ = &protect_html($_) unless $dont_html; - $dont_html = 0; - # substitution (unsupported things) - s/^\@center\s+//g; - s/^\@exdent\s+//g; - s/\@noindent\s+//g; - s/\@refill\s+//g; - # other substitutions - &simple_substitutions; - s/\@value{($VARRE)}/$value{$1}/eg; - s/\@footnote\{/\@footnote$docu_doc\{/g; # mark footnotes, cf. pass 4 - # - # analyze the tag again - # - if ($tag) { - if (defined($sec2level{$tag}) && $sec2level{$tag} > 0) { - if (/^\@$tag\s+(.+)$/) { - $name = $1; - $name =~ s/\s+$//; - $level = $sec2level{$tag}; - $name = &update_sec_num($tag, $level) . " $name" - if $number_sections && $tag !~ /^unnumbered/; - if ($tag =~ /heading$/) { - push(@lines, &html_debug("\n", __LINE__)); - if ($html_element ne 'body') { - # We are in a nice pickle here. We are trying to get a H? heading - # even though we are not in the body level. So, we convert it to a - # nice, bold, line by itself. - $_ = &debug("\n\n

$name\n\n", __LINE__); - } else { - $_ = &debug("$name\n", __LINE__); - &html_push_if('body'); - } - print "# heading, section $name, level $level\n" - if $debug & $DEBUG_TOC; - } else { - if ($split_chapter) { - unless ($toplevel) { - # first time we see a "section" - unless ($level == 1) { - warn "$ERROR The first section found is not of level 1: $_"; - warn "$ERROR I'll split on sections of level $level...\n"; - } - $toplevel = $level; - } - if ($level == $toplevel) { - &next_doc; - push(@lines, $SPLITTAG) if $split_num++; - push(@sections, $name); - } - } - $sec_num++; - $docid = "SEC$sec_num"; - $tocid = "TOC$sec_num"; - # check biblio and glossary - $in_bibliography = ($name =~ /^([A-Z]|\d+)?(\.\d+)*\s*bibliography$/i); - $in_glossary = ($name =~ /^([A-Z]|\d+)?(\.\d+)*\s*glossary$/i); - # check node - if ($node) { - if ($node2sec{$node}) { - warn "$ERROR Duplicate node found: $node\n"; - } else { - $node2sec{$node} = $name; - $node2href{$node} = "$docu_doc#$docid"; - print "# node $node, section $name, level $level\n" - if $debug & $DEBUG_TOC; - } - $node = ''; - } else { - print "# no node, section $name, level $level\n" - if $debug & $DEBUG_TOC; - } - # update TOC - while ($level > $curlevel) { - $curlevel++; - push(@toc_lines, "

    \n"); - } - while ($level < $curlevel) { - $curlevel--; - push(@toc_lines, "
\n"); - } - $_ = "
  • " . &anchor($tocid, "$docu_doc#$docid", $name, 1); - push(@toc_lines, &substitute_style($_)); - # update DOC - push(@lines, &html_debug("\n", __LINE__)); - &html_reset; - $_ = "".&anchor($docid, "$docu_toc#$tocid", $name)."\n"; - $_ = &debug($_, __LINE__); - push(@lines, &html_debug("\n", __LINE__)); - } - # update DOC - foreach $line (split(/\n+/, $_)) { - push(@lines, "$line\n"); - } - next; - } else { - warn "$ERROR Bad section line: $_"; - } - } else { - # track variables - $value{$1} = $2, next if /^\@set\s+($VARRE)\s+(.*)$/o; - delete $value{$1}, next if /^\@clear\s+($VARRE)\s*$/o; - # store things - $value{'_setfilename'} = $1, next if /^\@setfilename\s+(.*)$/; - $value{'_settitle'} = $1, next if /^\@settitle\s+(.*)$/; - $value{'_author'} .= "$1\n", next if /^\@author\s+(.*)$/; - $value{'_subtitle'} .= "$1\n", next if /^\@subtitle\s+(.*)$/; - $value{'_title'} .= "$1\n", next if /^\@title\s+(.*)$/; - # index - if (/^\@(..?)index\s+/) { - unless ($valid_index{$1}) { - warn "$ERROR Undefined index command: $_"; - next; - } - $id = 'IDX' . ++$idx_num; - $index = $1 . 'index'; - $what = &substitute_style($'); - $what =~ s/\s+$//; - print "# found $index for '$what' id $id\n" - if $debug & $DEBUG_INDEX; - eval(<\n", __LINE__)); - push(@lines, &anchor($id, '', $invisible_mark, !$in_pre)); - &html_push('P'); - } elsif ($html_element eq 'DL' || - $html_element eq 'UL' || - $html_element eq 'OL' ) { - $deferred_ref .= &anchor($id, '', $invisible_mark, !$in_pre) . " "; - } - next; - } - # list item - if (/^\s*\@itemx?\s+/) { - $what = $'; - $what =~ s/\s+$//; - if ($in_bibliography && $use_bibliography) { - if ($what =~ /^$BIBRE$/o) { - $id = 'BIB' . ++$bib_num; - $bib2href{$what} = "$docu_doc#$id"; - print "# found bibliography for '$what' id $id\n" - if $debug & $DEBUG_BIB; - $what = &anchor($id, '', $what); - } - } elsif ($in_glossary && $use_glossary) { - $id = 'GLOSS' . ++$gloss_num; - $entry = $what; - $entry =~ tr/A-Z/a-z/ unless $entry =~ /^[A-Z\s]+$/; - $gloss2href{$entry} = "$docu_doc#$id"; - print "# found glossary for '$entry' id $id\n" - if $debug & $DEBUG_GLOSS; - $what = &anchor($id, '', $what); - } - &html_pop_if('P'); - if ($html_element eq 'DL' || $html_element eq 'DD') { - if ($things_map{$in_table} && !$what) { - # special case to allow @table @bullet for instance - push(@lines, &debug("
    $things_map{$in_table}\n", __LINE__)); - } else { - push(@lines, &debug("
    \@$in_table\{$what\}\n", __LINE__)); - } - push(@lines, "
    "); - &html_push('DD') unless $html_element eq 'DD'; - if ($table_type) { # add also an index - unshift(@input_spool, "\@${table_type}index $what\n"); - } - } elsif ($html_element eq 'TABLE') { - push(@lines, &debug("$what\n", __LINE__)); - &html_push('TR'); - } elsif ($html_element eq 'TR') { - push(@lines, &debug("\n", __LINE__)); - push(@lines, &debug("$what\n", __LINE__)); - } else { - push(@lines, &debug("
  • $what\n", __LINE__)); - &html_push('LI') unless $html_element eq 'LI'; - } - push(@lines, &html_debug("\n", __LINE__)); - if ($deferred_ref) { - push(@lines, &debug("$deferred_ref\n", __LINE__)); - $deferred_ref = ''; - } - next; - } elsif (/^\@tab\s+(.*)$/) { - push(@lines, "$1\n"); - next; - } - } - } - # paragraph separator - if ($_ eq "\n") { - next if $#lines >= 0 && $lines[$#lines] eq "\n"; - if ($html_element eq 'P') { - push(@lines, "\n"); - $_ = &debug("\n", __LINE__); - &html_pop; - } - } elsif ($html_element eq 'body' || $html_element eq 'BLOCKQUOTE') { - push(@lines, "

    \n"); - &html_push('P'); - $_ = &debug($_, __LINE__); - } - # otherwise - push(@lines, $_); -} - -# finish TOC -$level = 0; -while ($level < $curlevel) { - $curlevel--; - push(@toc_lines, "\n"); -} - -print "# end of pass 1\n" if $verbose; - -#+++############################################################################ -# # -# Pass 2/3: handle style, menu, index, cross-reference # -# # -#---############################################################################ - -@lines2 = (); # whole document (2nd pass) -@lines3 = (); # whole document (3rd pass) -$in_menu = 0; # am I inside a menu - -while (@lines) { - $_ = shift(@lines); - # - # special case (protected sections) - # - if (/^$PROTECTTAG/o) { - push(@lines2, $_); - next; - } - # - # menu - # - $in_menu = 1, push(@lines2, &debug("

      \n", __LINE__)), next if /^\@menu\b/; - $in_menu = 0, push(@lines2, &debug("
    \n", __LINE__)), next if /^\@end\s+menu\b/; - if ($in_menu) { - if (/^\*\s+($NODERE)::/o) { - $descr = $'; - chop($descr); - &menu_entry($1, $1, $descr); - } elsif (/^\*\s+(.+):\s+([^\t,\.\n]+)[\t,\.\n]/) { - $descr = $'; - chop($descr); - &menu_entry($1, $2, $descr); - } elsif (/^\*/) { - warn "$ERROR Bad menu line: $_"; - } else { # description continued? - push(@lines2, $_); - } - next; - } - # - # printindex - # - if (/^\@printindex\s+(\w\w)\b/) { - local($index, *ary, @keys, $key, $letter, $last_letter, @refs); - if ($predefined_index{$1}) { - $index = $predefined_index{$1} . 'index'; - } else { - $index = $1 . 'index'; - } - eval("*ary = *$index"); - @keys = keys(%ary); - foreach $key (@keys) { - $_ = $key; - 1 while s/<(\w+)>\`(.*)\'<\/\1>/$2/; # remove HTML tags with quotes - 1 while s/<(\w+)>(.*)<\/\1>/$2/; # remove HTML tags - $_ = &unprotect_html($_); - &unprotect_texi; - tr/A-Z/a-z/; # lowercase - $key2alpha{$key} = $_; - print "# index $key sorted as $_\n" - if $key ne $_ && $debug & $DEBUG_INDEX; - } - push(@lines2, "Jump to:\n"); - $last_letter = undef; - foreach $key (sort byalpha @keys) { - $letter = substr($key2alpha{$key}, 0, 1); - $letter = substr($key2alpha{$key}, 0, 2) if $letter eq $;; - if (!defined($last_letter) || $letter ne $last_letter) { - push(@lines2, "-\n") if defined($last_letter); - push(@lines2, "" . &protect_html($letter) . "\n"); - $last_letter = $letter; - } - } - push(@lines2, "

    \n"); - $last_letter = undef; - foreach $key (sort byalpha @keys) { - $letter = substr($key2alpha{$key}, 0, 1); - $letter = substr($key2alpha{$key}, 0, 2) if $letter eq $;; - if (!defined($last_letter) || $letter ne $last_letter) { - push(@lines2, "\n") if defined($last_letter); - push(@lines2, "

    " . &protect_html($letter) . "

    \n"); - push(@lines2, "\n"); - $last_letter = $letter; - } - @refs = (); - foreach (split(/$;/, $ary{$key})) { - push(@refs, &anchor('', $_, $key, 0)); - } - push(@lines2, "
  • " . join(", ", @refs) . "\n"); - } - push(@lines2, "
  • \n") if defined($last_letter); - next; - } - # - # simple style substitutions - # - $_ = &substitute_style($_); - # - # xref - # - while (/\@(x|px|info|)ref{($XREFRE)(}?)/o) { - # note: Texinfo may accept other characters - ($type, $nodes, $full) = ($1, $2, $3); - ($before, $after) = ($`, $'); - if (! $full && $after) { - warn "$ERROR Bad xref (no ending } on line): $_"; - $_ = "$before$;0${type}ref\{$nodes$after"; - next; # while xref - } - if ($type eq 'x') { - $type = 'See '; - } elsif ($type eq 'px') { - $type = 'see '; - } elsif ($type eq 'info') { - $type = 'See Info'; - } else { - $type = ''; - } - unless ($full) { - $next = shift(@lines); - $next = &substitute_style($next); - chop($nodes); # remove final newline - if ($next =~ /\}/) { # split on 2 lines - $nodes .= " $`"; - $after = $'; - } else { - $nodes .= " $next"; - $next = shift(@lines); - $next = &substitute_style($next); - chop($nodes); - if ($next =~ /\}/) { # split on 3 lines - $nodes .= " $`"; - $after = $'; - } else { - warn "$ERROR Bad xref (no ending }): $_"; - $_ = "$before$;0xref\{$nodes$after"; - unshift(@lines, $next); - next; # while xref - } - } - } - $nodes =~ s/\s+/ /g; # remove useless spaces - @args = split(/\s*,\s*/, $nodes); - $node = $args[0]; # the node is always the first arg - &normalise_node($node); - $sec = $node2sec{$node}; - if (@args == 5) { # reference to another manual - $sec = $args[2] || $node; - $man = $args[4] || $args[3]; - $_ = "${before}${type}section `$sec' in \@cite{$man}$after"; - } elsif ($type =~ /Info/) { # inforef - warn "$ERROR Wrong number of arguments: $_" unless @args == 3; - ($nn, $_, $in) = @args; - $_ = "${before}${type} file `$in', node `$nn'$after"; - } elsif ($sec) { - $href = $node2href{$node}; - $_ = "${before}${type}section " . &anchor('', $href, $sec) . $after; - } else { - warn "$ERROR Undefined node ($node): $_"; - $_ = "$before$;0xref{$nodes}$after"; - } - } - - if (/^\@image\s*{/) { - s/\@image\s*{//; - my (@args) = split (/,/); - my $base = $args[0]; - my $image; - if (-r "$base.jpg") { - $image = "$base.jpg"; - } elsif (-r "$base.png") { - $image = "$base.png"; - } elsif (-r "$base.gif") { - $image = "$base.gif"; - } else { - warn "$ERROR no image file for $base: $_"; - } - $_ = "\"$base\""; - } - - # - # try to guess bibliography references or glossary terms - # - unless (/^/) { - $done .= $pre . &anchor('', $href, $what); - } else { - $done .= "$pre$what"; - } - $_ = $post; - } - $_ = $done . $_; - } - if ($use_glossary) { - $done = ''; - while (/\b\w+\b/) { - ($pre, $what, $post) = ($`, $&, $'); - $entry = $what; - $entry =~ tr/A-Z/a-z/ unless $entry =~ /^[A-Z\s]+$/; - $href = $gloss2href{$entry}; - if (defined($href) && $post !~ /^[^<]*<\/A>/) { - $done .= $pre . &anchor('', $href, $what); - } else { - $done .= "$pre$what"; - } - $_ = $post; - } - $_ = $done . $_; - } - } - # otherwise - push(@lines2, $_); -} -print "# end of pass 2\n" if $verbose; - -# -# split style substitutions -# -while (@lines2) { - $_ = shift(@lines2); - # - # special case (protected sections) - # - if (/^$PROTECTTAG/o) { - push(@lines3, $_); - next; - } - # - # split style substitutions - # - $old = ''; - while ($old ne $_) { - $old = $_; - if (/\@(\w+)\{/) { - ($before, $style, $after) = ($`, $1, $'); - if (defined($style_map{$style})) { - $_ = $after; - $text = ''; - $after = ''; - $failed = 1; - while (@lines2) { - if (/\}/) { - $text .= $`; - $after = $'; - $failed = 0; - last; - } else { - $text .= $_; - $_ = shift(@lines2); - } - } - if ($failed) { - die "* Bad syntax (\@$style) after: $before\n"; - } else { - $text = &apply_style($style, $text); - $_ = "$before$text$after"; - } - } - } - } - # otherwise - push(@lines3, $_); -} -print "# end of pass 3\n" if $verbose; - -#+++############################################################################ -# # -# Pass 4: foot notes, final cleanup # -# # -#---############################################################################ - -@foot_lines = (); # footnotes -@doc_lines = (); # final document -$end_of_para = 0; # true if last line is

    - -while (@lines3) { - $_ = shift(@lines3); - # - # special case (protected sections) - # - if (/^$PROTECTTAG/o) { - push(@doc_lines, $_); - $end_of_para = 0; - next; - } - # - # footnotes - # - while (/\@footnote([^\{\s]+)\{/) { - ($before, $d, $after) = ($`, $1, $'); - $_ = $after; - $text = ''; - $after = ''; - $failed = 1; - while (@lines3) { - if (/\}/) { - $text .= $`; - $after = $'; - $failed = 0; - last; - } else { - $text .= $_; - $_ = shift(@lines3); - } - } - if ($failed) { - die "* Bad syntax (\@footnote) after: $before\n"; - } else { - $foot_num++; - $docid = "DOCF$foot_num"; - $footid = "FOOT$foot_num"; - $foot = "($foot_num)"; - push(@foot_lines, "

    " . &anchor($footid, "$d#$docid", $foot) . "

    \n"); - $text = "

    $text" unless $text =~ /^\s*

    /; - push(@foot_lines, "$text\n"); - $_ = $before . &anchor($docid, "$docu_foot#$footid", $foot) . $after; - } - } - # - # remove unnecessary

    - # - if (/^\s*

    \s*$/) { - next if $end_of_para++; - } else { - $end_of_para = 0; - } - # otherwise - push(@doc_lines, $_); -} -print "# end of pass 4\n" if $verbose; - -#+++############################################################################ -# # -# Pass 5: print things # -# # -#---############################################################################ - -$header = < -EOT - -$full_title = $value{'_title'} || $value{'_settitle'} || "Untitled Document"; -$title = $value{'_settitle'} || $full_title; -$_ = &substitute_style($full_title); -&unprotect_texi; -s/\n$//; # rmv last \n (if any) -$full_title = "

    " . join("

    \n

    ", split(/\n/, $_)) . "

    \n"; - -# -# print ToC -# -if (!$monolithic && @toc_lines) { - if (open(FILE, "> $docu_toc")) { - print "# creating $docu_toc...\n" if $verbose; - &print_toplevel_header("$title - Table of Contents"); - &print_ruler; - &print(*toc_lines, FILE); - &print_toplevel_footer; - close(FILE); - } else { - warn "$ERROR Can't write to $docu_toc: $!\n"; - } -} - -# -# print footnotes -# -if (!$monolithic && @foot_lines) { - if (open(FILE, "> $docu_foot")) { - print "# creating $docu_foot...\n" if $verbose; - &print_toplevel_header("$title - Footnotes"); - &print_ruler; - &print(*foot_lines, FILE); - &print_toplevel_footer; - close(FILE); - } else { - warn "$ERROR Can't write to $docu_foot: $!\n"; - } -} - -# -# print document -# -if ($split_chapter || $split_node) { # split - $doc_num = 0; - $last_num = scalar(@sections); - $first_doc = &doc_name(1); - $last_doc = &doc_name($last_num); - while (@sections) { - $section = shift(@sections); - &next_doc; - if (open(FILE, "> $docu_doc")) { - print "# creating $docu_doc...\n" if $verbose; - &print_header("$title - $section"); - $prev_doc = ($doc_num == 1 ? undef : &doc_name($doc_num - 1)); - $next_doc = ($doc_num == $last_num ? undef : &doc_name($doc_num + 1)); - $navigation = "Go to the "; - $navigation .= ($prev_doc ? &anchor('', $first_doc, "first") : "first"); - $navigation .= ", "; - $navigation .= ($prev_doc ? &anchor('', $prev_doc, "previous") : "previous"); - $navigation .= ", "; - $navigation .= ($next_doc ? &anchor('', $next_doc, "next") : "next"); - $navigation .= ", "; - $navigation .= ($next_doc ? &anchor('', $last_doc, "last") : "last"); - $navigation .= " section, " . &anchor('', $docu_toc, "table of contents") . ".\n"; - print FILE $navigation; - &print_ruler; - # find corresponding lines - @tmp_lines = (); - while (@doc_lines) { - $_ = shift(@doc_lines); - last if ($_ eq $SPLITTAG); - push(@tmp_lines, $_); - } - &print(*tmp_lines, FILE); - &print_ruler; - print FILE $navigation; - &print_footer; - close(FILE); - } else { - warn "$ERROR Can't write to $docu_doc: $!\n"; - } - } -} else { # not split - if (open(FILE, "> $docu_doc")) { - print "# creating $docu_doc...\n" if $verbose; - if ($monolithic || !@toc_lines) { - &print_toplevel_header($title); - } else { - &print_header($title); - print FILE $full_title; - } - if ($monolithic && @toc_lines) { - &print_ruler; - print FILE "

    Table of Contents

    \n"; - &print(*toc_lines, FILE); - } - &print_ruler; - &print(*doc_lines, FILE); - if ($monolithic && @foot_lines) { - &print_ruler; - print FILE "

    Footnotes

    \n"; - &print(*foot_lines, FILE); - } - if ($monolithic || !@toc_lines) { - &print_toplevel_footer; - } else { - &print_footer; - } - close(FILE); - } else { - warn "$ERROR Can't write to $docu_doc: $!\n"; - } -} - -print "# that's all folks\n" if $verbose; - -#+++############################################################################ -# # -# Low level functions # -# # -#---############################################################################ - -sub update_sec_num { - local($name, $level) = @_; - my $ret; - - $level--; # here we start at 0 - if ($name =~ /^appendix/) { - # appendix style - if (defined(@appendix_sec_num)) { - &incr_sec_num($level, @appendix_sec_num); - } else { - @appendix_sec_num = ('A', 0, 0, 0); - } - $ret = join('.', @appendix_sec_num[0..$level]); - } else { - # normal style - if (defined(@normal_sec_num)) { - &incr_sec_num($level, @normal_sec_num); - } else { - @normal_sec_num = (1, 0, 0, 0); - } - $ret = join('.', @normal_sec_num[0..$level]); - } - - $ret .= "." if $level == 0; - return $ret; -} - -sub incr_sec_num { - local($level, $l); - $level = shift(@_); - $_[$level]++; - foreach $l ($level+1 .. 3) { - $_[$l] = 0; - } -} - -sub check { - local($_, %seen, %context, $before, $match, $after); - - while (<>) { - if (/\@(\*|\.|\:|\@|\{|\})/) { - $seen{$&}++; - $context{$&} .= "> $_" if $verbose; - $_ = "$`XX$'"; - redo; - } - if (/\@(\w+)/) { - ($before, $match, $after) = ($`, $&, $'); - if ($before =~ /\b[\w-]+$/ && $after =~ /^[\w-.]*\b/) { # e-mail address - $seen{'e-mail address'}++; - $context{'e-mail address'} .= "> $_" if $verbose; - } else { - $seen{$match}++; - $context{$match} .= "> $_" if $verbose; - } - $match =~ s/^\@/X/; - $_ = "$before$match$after"; - redo; - } - } - - foreach (sort(keys(%seen))) { - if ($verbose) { - print "$_\n"; - print $context{$_}; - } else { - print "$_ ($seen{$_})\n"; - } - } -} - -sub open { - local($name) = @_; - - ++$fh_name; - if (open($fh_name, $name)) { - unshift(@fhs, $fh_name); - } else { - warn "$ERROR Can't read file $name: $!\n"; - } -} - -sub init_input { - @fhs = (); # hold the file handles to read - @input_spool = (); # spooled lines to read - $fh_name = 'FH000'; - &open($docu); -} - -sub next_line { - local($fh, $line); - - if (@input_spool) { - $line = shift(@input_spool); - return($line); - } - while (@fhs) { - $fh = $fhs[0]; - $line = <$fh>; - return($line) if $line; - close($fh); - shift(@fhs); - } - return(undef); -} - -# used in pass 1, use &next_line -sub skip_until { - local($tag) = @_; - local($_); - - while ($_ = &next_line) { - return if /^\@end\s+$tag\s*$/; - } - die "* Failed to find '$tag' after: " . $lines[$#lines]; -} - -# -# HTML stacking to have a better HTML output -# - -sub html_reset { - @html_stack = ('html'); - $html_element = 'body'; -} - -sub html_push { - local($what) = @_; - push(@html_stack, $html_element); - $html_element = $what; -} - -sub html_push_if { - local($what) = @_; - push(@html_stack, $html_element) - if ($html_element && $html_element ne 'P'); - $html_element = $what; -} - -sub html_pop { - $html_element = pop(@html_stack); -} - -sub html_pop_if { - local($elt); - - if (@_) { - foreach $elt (@_) { - if ($elt eq $html_element) { - $html_element = pop(@html_stack) if @html_stack; - last; - } - } - } else { - $html_element = pop(@html_stack) if @html_stack; - } -} - -sub html_debug { - local($what, $line) = @_; - return("$what") - if $debug & $DEBUG_HTML; - return($what); -} - -# to debug the output... -sub debug { - local($what, $line) = @_; - return("$what") - if $debug & $DEBUG_HTML; - return($what); -} - -sub normalise_node { - $_[0] =~ s/\s+/ /g; - $_[0] =~ s/ $//; - $_[0] =~ s/^ //; -} - -sub menu_entry { - local($entry, $node, $descr) = @_; - local($href); - - &normalise_node($node); - $href = $node2href{$node}; - if ($href) { - $descr =~ s/^\s+//; - $descr = ": $descr" if $descr; - push(@lines2, "
  • " . &anchor('', $href, $entry) . "$descr\n"); - } else { - warn "$ERROR Undefined node ($node): $_"; - } -} - -sub do_ctrl { "^$_[0]" } - -sub do_email { - local($addr, $text) = split(/,\s*/, $_[0]); - - $text = $addr unless $text; - &anchor('', "mailto:$addr", $text); -} - -sub do_sc { "\U$_[0]\E" } - -sub do_uref { - local($url, $text) = split(/,\s*/, $_[0]); - - $text = $url unless $text; - &anchor('', $url, $text); -} - -sub do_url { &anchor('', $_[0], $_[0]) } - -sub apply_style { - local($texi_style, $text) = @_; - local($style); - - $style = $style_map{$texi_style}; - if (defined($style)) { # known style - if ($style =~ /^\"/) { # add quotes - $style = $'; - $text = "\`$text\'"; - } - if ($style =~ /^\&/) { # custom - $style = $'; - $text = &$style($text); - } elsif ($style) { # good style - $text = "<$style>$text"; - } else { # no style - } - } else { # unknown style - $text = undef; - } - return($text); -} - -# remove Texinfo styles -sub remove_style { - local($_) = @_; - s/\@\w+{([^\{\}]+)}/$1/g; - return($_); -} - -sub substitute_style { - local($_) = @_; - local($changed, $done, $style, $text); - - $changed = 1; - while ($changed) { - $changed = 0; - $done = ''; - while (/\@(\w+){([^\{\}]+)}/) { - $text = &apply_style($1, $2); - if ($text) { - $_ = "$`$text$'"; - $changed = 1; - } else { - $done .= "$`\@$1"; - $_ = "{$2}$'"; - } - } - $_ = $done . $_; - } - return($_); -} - -sub anchor { - local($name, $href, $text, $newline) = @_; - local($result); - - $result = "

    \n"; -} - -sub print_header { - local($_); - - # clean the title - $_ = &remove_style($_[0]); - &unprotect_texi; - # print the header - if ($doctype eq 'html2') { - print FILE $html2_doctype; - } elsif ($doctype) { - print FILE $doctype; - } - print FILE < - -$header -$_ - - -EOT -} - -sub print_toplevel_header { - local($_); - - &print_header; # pass given arg... - print FILE $full_title; - if ($value{'_subtitle'}) { - $value{'_subtitle'} =~ s/\n+$//; - foreach (split(/\n/, $value{'_subtitle'})) { - $_ = &substitute_style($_); - &unprotect_texi; - print FILE "

    $_

    \n"; - } - } - if ($value{'_author'}) { - $value{'_author'} =~ s/\n+$//; - foreach (split(/\n/, $value{'_author'})) { - $_ = &substitute_style($_); - &unprotect_texi; - s/[\w.-]+\@[\w.-]+/
    $&<\/A>/g; - print FILE "
    $_
    \n"; - } - } - print FILE "

    \n"; -} - -sub print_footer { - print FILE < - -EOT -} - -sub print_toplevel_footer { - &print_ruler; - print FILE <texi2html $value{texi2html}. -EOT - &print_footer; -} - -sub protect_texi { - # protect @ { } ` ' - s/\@\@/$;0/go; - s/\@\{/$;1/go; - s/\@\}/$;2/go; - s/\@\`/$;3/go; - s/\@\'/$;4/go; -} - -sub protect_html { - local($what) = @_; - # protect & < > - $what =~ s/\&/\&\#38;/g; - $what =~ s/\/\&\#62;/g; - # but recognize some HTML things - $what =~ s/\&\#60;\/A\&\#62;/<\/A>/g; # - $what =~ s/\&\#60;A ([^\&]+)\&\#62;//g; # - $what =~ s/\&\#60;IMG ([^\&]+)\&\#62;//g; # - return($what); -} - -sub unprotect_texi { - s/$;0/\@/go; - s/$;1/\{/go; - s/$;2/\}/go; - s/$;3/\`/go; - s/$;4/\'/go; -} - -sub unprotect_html { - local($what) = @_; - $what =~ s/\&\#38;/\&/g; - $what =~ s/\&\#60;/\/g; - return($what); -} - -sub byalpha { - $key2alpha{$a} cmp $key2alpha{$b}; -} - -############################################################################## - - # These next few lines are legal in both Perl and nroff. - -.00 ; # finish .ig - -'di \" finish diversion--previous line must be blank -.nr nl 0-1 \" fake up transition to first page again -.nr % 0 \" start at page 1 -'; __END__ ############# From here on it's a standard manual page ############ -.TH TEXI2HTML 1 "01/05/98" -.AT 3 -.SH NAME -texi2html \- a Texinfo to HTML converter -.SH SYNOPSIS -.B texi2html [options] file -.PP -.B texi2html -check [-verbose] files -.SH DESCRIPTION -.I Texi2html -converts the given Texinfo file to a set of HTML files. It tries to handle -most of the Texinfo commands. It creates hypertext links for cross-references, -footnotes... -.PP -It also tries to add links from a reference to its corresponding entry in the -bibliography (if any). It may also handle a glossary (see the -.B \-glossary -option). -.PP -.I Texi2html -creates several files depending on the contents of the Texinfo file and on -the chosen options (see FILES). -.PP -The HTML files created by -.I texi2html -are closer to TeX than to Info, that's why -.I texi2html -converts @iftex sections and not @ifinfo ones by default. You can reverse -this with the \-expandinfo option. -.SH OPTIONS -.TP 12 -.B \-check -Check the given file and give the list of all things that may be Texinfo commands. -This may be used to check the output of -.I texi2html -to find the Texinfo commands that have been left in the HTML file. -.TP -.B \-expandinfo -Expand @ifinfo sections, not @iftex ones. -.TP -.B \-glossary -Use the section named 'Glossary' to build a list of terms and put links in the HTML -document from each term toward its definition. -.TP -.B \-invisible \fIname\fP -Use \fIname\fP to create invisible destination anchors for index links -(you can for instance use the invisible.xbm file shipped with this program). -This is a workaround for a known bug of many WWW browsers, including netscape. -.TP -.B \-I \fIdir\fP -Look also in \fIdir\fP to find included files. -.TP -.B \-menu -Show the Texinfo menus; by default they are ignored. -.TP -.B \-monolithic -Output only one file, including the table of contents and footnotes. -.TP -.B \-number -Number the sections. -.TP -.B \-split_chapter -Split the output into several HTML files (one per main section: -chapter, appendix...). -.TP -.B \-split_node -Split the output into several HTML files (one per node). -.TP -.B \-usage -Print usage instructions, listing the current available command-line options. -.TP -.B \-verbose -Give a verbose output. Can be used with the -.B \-check -option. -.PP -.SH FILES -By default -.I texi2html -creates the following files (foo being the name of the Texinfo file): -.TP 16 -.B foo_toc.html -The table of contents. -.TP -.B foo.html -The document's contents. -.TP -.B foo_foot.html -The footnotes (if any). -.PP -When used with the -.B \-split -option, it creates several files (one per chapter or node), named -.B foo_n.html -(n being the indice of the chapter or node), instead of the single -.B foo.html -file. -.PP -When used with the -.B \-monolithic -option, it creates only one file: -.B foo.html -.SH VARIABLES -.I texi2html -predefines the following variables: \fBhtml\fP, \fBtexi2html\fP. -.SH ADDITIONAL COMMANDS -.I texi2html -implements the following non-Texinfo commands (maybe they are in Texinfo now...): -.TP 16 -.B @ifhtml -This indicates the start of an HTML section, this section will passed through -without any modification. -.TP -.B @end ifhtml -This indicates the end of an HTML section. -.SH VERSION -This is \fItexi2html\fP version 1.56k, 1999-02-20. -.PP -The latest version of \fItexi2html\fP can be found in WWW, cf. URLs -http://wwwinfo.cern.ch/dis/texi2html/ -.br -http://texinfo.org/texi2html/ -.SH AUTHOR -The main author is Lionel Cons, CERN IT/DIS/OSE, Lionel.Cons@cern.ch. -Many other people around the net contributed to this program. -.SH COPYRIGHT -This program is the intellectual property of the European -Laboratory for Particle Physics (known as CERN). No guarantee whatsoever is -provided by CERN. No liability whatsoever is accepted for any loss or damage -of any kind resulting from any defect or inaccuracy in this information or -code. -.PP -CERN, 1211 Geneva 23, Switzerland -.SH "SEE ALSO" -GNU Texinfo Documentation Format, -HyperText Markup Language (HTML), -World Wide Web (WWW). -.SH BUGS -This program does not understand all Texinfo commands (yet). -.PP -TeX specific commands (normally enclosed in @iftex) will be -passed unmodified. -.ex diff --git a/doc/src/concepts.texi b/doc/src/concepts.texi index 8c9f08b0..d71f62fe 100644 --- a/doc/src/concepts.texi +++ b/doc/src/concepts.texi @@ -9,4 +9,4 @@ Here you might find an introduction to X concepts sometime in the future. For now, I just refer to the introduction parts of the standard X documentation. A vast collection of X documentation links can be -found at @uref{http://www.rahul.net/kenton/xsites.html}. +found at @uref{https://web.archive.org/web/20201228053920/http://www.rahul.net/kenton/xsites.html}. diff --git a/doc/src/errors.texi b/doc/src/errors.texi index 2a9a700d..a76ce316 100644 --- a/doc/src/errors.texi +++ b/doc/src/errors.texi @@ -142,7 +142,7 @@ Forget any caught error. Since the X protocol is mostly asynchronous any error we're watching for -might not have been recieved when we call @code{get_error}. To make +might not have been received when we call @code{get_error}. To make sure that the request has been processed by the server and any error generated has been received by the Xlib, we must synchronize with the server. diff --git a/doc/src/events.texi b/doc/src/events.texi index 035a5220..ba678ffd 100644 --- a/doc/src/events.texi +++ b/doc/src/events.texi @@ -22,7 +22,7 @@ typically by doing one or more X requests. @section Getting Events Events can be sent at any time, not necessarily when the client is ready -to recieve an event. Therefore they must be stored temporarily from that +to receive an event. Therefore they must be stored temporarily from that they are read from the network until the client is ready to handle them. Read but unhandled events are stored on an event queue in the Display object. There are two functions to access this queue: @@ -72,7 +72,7 @@ while 1: if not readable: handle_timeout() - # if display is readable, handle as many events as have been recieved + # if display is readable, handle as many events as have been received elif disp in readable: i = disp.pending_events() while i > 0: diff --git a/doc/src/objects.texi b/doc/src/objects.texi index 16d4adbe..094bf95c 100644 --- a/doc/src/objects.texi +++ b/doc/src/objects.texi @@ -205,7 +205,7 @@ list items have the following attributes: The ID of this visual. @item visual_class -One of @code{X.StaticGrey}, @code{X.StaticColor}, @code{X.TrueColor}, +One of @code{X.StaticGray}, @code{X.StaticColor}, @code{X.TrueColor}, @code{X.GrayScale}, @code{X.PseudoColor}, or @code{X.DirectColor}. @item bits_per_rgb_value @@ -475,7 +475,7 @@ The name of the font. @itemx font_ascent @itemx font_descent @itemx replies_hint -See the descripton of XFontStruct in XGetFontProperty(3X11) for details +See the description of XFontStruct in XGetFontProperty(3X11) for details on these values. @item properties @@ -678,7 +678,8 @@ XGetScreenSaver(3X11) for details. @var{mode} is either @code{X.HostInsert} or @code{X.HostDelete}. @var{host_family} is one of @code{X.FamilyInternet}, -@code{X.FamilyDECnet} or @code{X.FamilyChaos}. +@code{X.FamilyDECnet}, @code{X.FamilyChaos}, @code{X.FamilyServerInterpreted} +or @code{X.FamilyInternetV6}. @var{host} is a list of bytes. For the Internet family, it should be the four bytes of an IPv4 address. @@ -699,7 +700,8 @@ The hosts on the access list. Each entry has the following attributes: @table @code @item family -@code{X.FamilyInternet}, @code{X.FamilyDECnet}, or @code{X.FamilyChaos}. +@code{X.FamilyInternet}, @code{X.FamilyDECnet}, @code{X.FamilyChaos}, +@code{X.FamilyServerInterpreted} or @code{X.FamilyInternetV6}. @item name A list of byte values, the coding depends on @code{family}. For the @@ -1175,7 +1177,7 @@ Returns None or string. @end defmethod @defmethod Window get_wm_class ( ) -Returns None or (isntance, class) +Returns None or (instance, class) @end defmethod @defmethod Window set_wm_transient_for ( window, onerror = None ) diff --git a/examples/childwin.py b/examples/childwin.py index 1fad1f62..9a0cf6b3 100755 --- a/examples/childwin.py +++ b/examples/childwin.py @@ -5,20 +5,25 @@ # Copyright (C) 2008 David Bronke # Copyright (C) 2002 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA +# Python 2/3 compatibility. +from __future__ import print_function import sys import os @@ -29,7 +34,7 @@ from Xlib import X, display, Xutil # Application window -class Window: +class Window(object): def __init__(self, display): self.d = display @@ -127,7 +132,7 @@ def loop(self): # Button released, add or subtract elif e.type == X.ButtonRelease: if e.detail == 1: - print "Moving child window." + print("Moving child window.") self.childWindow.configure( x=e.event_x - self.childWidth // 2, y=e.event_y - self.childHeight // 2 diff --git a/examples/dpms.py b/examples/dpms.py new file mode 100755 index 00000000..0a04be57 --- /dev/null +++ b/examples/dpms.py @@ -0,0 +1,130 @@ +#!/usr/bin/python +# +# examples/dpms.py -- DPMS usage examples. +# +# Copyright (C) 2020 Thiago Kenji Okada +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA + +import random +import time + +from Xlib import display +from Xlib.ext import dpms + + +class DPMSExamples(object): + def __init__(self): + self.d = display.Display() + + capable = self.d.dpms_capable() + assert capable, 'DPMS is not supported in your system' + + self.initial_info = self.d.dpms_info() + self.initial_timeouts = self.d.dpms_get_timeouts() + + # Making sure that DPMS is enable for this examples + self.d.dpms_enable() + self.d.sync() + + def print_dpms(self): + current_info = self.d.dpms_info() + print('\nDPMS state: {}\nPower level: {}'.format(current_info.state, + current_info.power_level)) + current_timeouts = self.d.dpms_get_timeouts() + print('Standby: {}, Suspend: {}, Off: {}\n'.format(current_timeouts.standby_timeout, + current_timeouts.suspend_timeout, + current_timeouts.off_timeout)) + + def toggle_dpms(self): + current_info = self.d.dpms_info() + if current_info.state: + self.d.dpms_disable() + else: + self.d.dpms_enable() + + self.d.sync() + + def restore(self): + print('Restoring DPMS configuration') + self.d.dpms_set_timeouts(self.initial_timeouts.standby_timeout, + self.initial_timeouts.suspend_timeout, + self.initial_timeouts.off_timeout) + if self.initial_info.state: + self.d.dpms_enable() + else: + self.d.dpms_disable() + + self.d.sync() + + self.print_dpms() + + def set_random_timeouts(self): + # Can be any number greater than 0 + # Using 10 just to not turnoff the screen suddenly + standby_timeout = random.randint(10, 600) + # Shouldn't be smaller than standby_timeout + suspend_timeout = random.randint(standby_timeout, 600) + # Shouldn't be smaller than standby_timeout or suspend_timeout + off_timeout = random.randint(suspend_timeout, 600) + self.d.dpms_set_timeouts(standby_timeout, suspend_timeout, off_timeout) + self.d.sync() + + def turn_off_display(self): + self.d.dpms_force_level(dpms.DPMSModeOff) + self.d.sync() + + def turn_on_display(self): + self.d.dpms_force_level(dpms.DPMSModeOn) + self.d.sync() + + +def main(): + try: + examples = DPMSExamples() + + print('Initial state') + examples.print_dpms() + + print('Setting random timeouts') + examples.set_random_timeouts() + examples.print_dpms() + + print('The next example will turn-off your screen, press Ctrl-C to cancel.') + time.sleep(2) + examples.turn_off_display() + + print('Turning it on again...') + time.sleep(2) + examples.turn_on_display() + + print() + + print('Toggle DPMS') + examples.toggle_dpms() + examples.print_dpms() + + print('Toggle it again') + examples.toggle_dpms() + examples.print_dpms() + finally: + examples.restore() + + +if __name__ == '__main__': + main() diff --git a/examples/draw-proto.py b/examples/draw-proto.py index 21b26070..4edc361a 100755 --- a/examples/draw-proto.py +++ b/examples/draw-proto.py @@ -4,19 +4,22 @@ # # Copyright (C) 2000 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA import sys @@ -30,7 +33,7 @@ from Xlib.protocol.request import * # Application window (only one) -class Window: +class Window(object): def __init__(self, display): self.d = display self.objects = [] @@ -104,9 +107,9 @@ def loop(self): current.motion(e) # A drawed objects, consisting of either a single -# romboid, or two romboids connected by a winding line +# rhomboid, or two rhomboids connected by a winding line -class Movement: +class Movement(object): def __init__(self, win, ev): self.win = win @@ -118,7 +121,7 @@ def __init__(self, win, ev): self.time = ev.time self.lines = [(ev.event_x, ev.event_y)] - self.first = Romboid(self.win, ev) + self.first = Rhomboid(self.win, ev) self.last = None def motion(self, ev): @@ -179,7 +182,7 @@ def motion(self, ev): def finish(self, ev): self.motion(ev) if len(self.lines) > 1: - self.last = Romboid(self.win, ev) + self.last = Rhomboid(self.win, ev) self.left = min(ev.event_x - 5, self.left) self.right = max(ev.event_x + 5, self.right) @@ -203,8 +206,8 @@ def expose(self, ev): self.last.draw() -# A romboid, drawed around the Movement endpoints -class Romboid: +# A rhomboid, drawed around the Movement endpoints +class Rhomboid(object): def __init__(self, win, ev): self.win = win self.x = ev.event_x @@ -212,7 +215,7 @@ def __init__(self, win, ev): self.draw() def draw(self): - # Draw the segments of the romboid + # Draw the segments of the rhomboid PolyLine(self.win.d, None, X.CoordModePrevious, self.win.window, diff --git a/examples/draw.py b/examples/draw.py index dba1ebf4..f456d801 100755 --- a/examples/draw.py +++ b/examples/draw.py @@ -4,19 +4,22 @@ # # Copyright (C) 2000 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA import sys @@ -28,7 +31,7 @@ from Xlib import X, display, Xutil # Application window (only one) -class Window: +class Window(object): def __init__(self, display): self.d = display self.objects = [] @@ -115,9 +118,9 @@ def loop(self): sys.exit(0) # A drawed objects, consisting of either a single -# romboid, or two romboids connected by a winding line +# rhomboid, or two rhomboids connected by a winding line -class Movement: +class Movement(object): def __init__(self, win, ev): self.win = win @@ -129,7 +132,7 @@ def __init__(self, win, ev): self.time = ev.time self.lines = [(ev.event_x, ev.event_y)] - self.first = Romboid(self.win, ev) + self.first = Rhomboid(self.win, ev) self.last = None def motion(self, ev): @@ -182,7 +185,7 @@ def motion(self, ev): def finish(self, ev): self.motion(ev) if len(self.lines) > 1: - self.last = Romboid(self.win, ev) + self.last = Rhomboid(self.win, ev) self.left = min(ev.event_x - 5, self.left) self.right = max(ev.event_x + 5, self.right) @@ -204,8 +207,8 @@ def expose(self, ev): self.last.draw() -# A romboid, drawed around the Movement endpoints -class Romboid: +# A rhomboid, drawed around the Movement endpoints +class Rhomboid(object): def __init__(self, win, ev): self.win = win self.x = ev.event_x @@ -213,7 +216,7 @@ def __init__(self, win, ev): self.draw() def draw(self): - # Draw the segments of the romboid + # Draw the segments of the rhomboid self.win.window.poly_line(self.win.gc, X.CoordModePrevious, [(self.x, self.y - 5), (5, 5), diff --git a/examples/eventthread.py b/examples/eventthread.py index 2a7d50bf..da8cb505 100755 --- a/examples/eventthread.py +++ b/examples/eventthread.py @@ -5,24 +5,36 @@ # Copyright (C) 2010-2011 Outpost Embedded, LLC # Forest Bond # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA -import sys, time +# Python 2/3 compatibility. +from __future__ import print_function + +import sys +import os + +# Change path so we find Xlib +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) + +import time from threading import Thread -from Xlib import X, Xatom, threaded +from Xlib import Xatom, threaded from Xlib.display import Display @@ -38,7 +50,7 @@ def __init__(self, display): def run(self): while True: event = self.display.next_event() - print 'event: %r' % event + print('event: %r' % event) def main(argv): @@ -54,7 +66,7 @@ def main(argv): # call in the thread. atom = display.intern_atom('_XROOTPMAP_ID', True) response = screen.root.get_property(atom, Xatom.PIXMAP, 0, 1) - print 'get_property response: %r' % response + print('get_property response: %r' % response) display.close() diff --git a/examples/get_selection.py b/examples/get_selection.py index 6a02a0b2..b249c027 100755 --- a/examples/get_selection.py +++ b/examples/get_selection.py @@ -5,20 +5,24 @@ # # Copyright (C) 2013 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA + +import binascii import sys import os @@ -78,8 +82,8 @@ def main(): # Ask for the selection. We shouldn't use X.CurrentTime, but # since we don't have an event here we have to. w.convert_selection(sel_atom, target_atom, data_atom, X.CurrentTime) - - # Wait for the notificiaton that we got the selection + + # Wait for the notification that we got the selection while True: e = d.next_event() if e.type == X.SelectionNotify: @@ -112,7 +116,7 @@ def main(): # Tell selection owner that we're done w.delete_property(data_atom) - + def handle_incr(d, w, data_atom, target_name): # This works by us removing the data property, the selection owner @@ -140,7 +144,7 @@ def handle_incr(d, w, data_atom, target_name): # End of data if len(r.value) == 0: return - + output_data(d, r, target_name) # loop around @@ -152,7 +156,13 @@ def output_data(d, r, target_name): len(r.value)) if r.format == 8: - sys.stdout.write(r.value) + if r.property_type == Xatom.STRING: + value = r.value.decode('ISO-8859-1') + elif r.property_type == d.get_atom('UTF8_STRING'): + value = r.value.decode('UTF-8') + else: + value = binascii.hexlify(r.value).decode('ascii') + sys.stdout.write(value) elif r.format == 32 and r.property_type == Xatom.ATOM: for v in r.value: diff --git a/examples/nvcontrol.py b/examples/nvcontrol.py new file mode 100755 index 00000000..dece439f --- /dev/null +++ b/examples/nvcontrol.py @@ -0,0 +1,95 @@ +#!/usr/bin/python +# +# examples/nvcontrol.py -- demonstrate the NV-CONTROL extension +# +# Copyright (C) 2019 Roberto Leinardi +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA + + +# Python 2/3 compatibility. +from __future__ import print_function + +import sys +import os + +# Change path so we find Xlib +from pprint import pprint + +from Xlib.display import Display +from Xlib.ext.nvcontrol import Gpu, Cooler + +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) + +if __name__ == '__main__': + display = Display() + # Check for extension + if not display.has_extension('NV-CONTROL'): + sys.stderr.write('{}: server does not have the NV-CONTROL extension\n'.format(sys.argv[0])) + ext = display.query_extension('NV-CONTROL') + print(ext) + sys.stderr.write("\n".join(display.list_extensions())) + if ext is None: + sys.exit(1) + + gpu = Gpu(0) + fan = Cooler(0) + + perf_level = 3 + + dic = { + 'get_gpu_count': display.nvcontrol_get_gpu_count(), + 'get_vram': display.nvcontrol_get_vram(gpu), + 'get_irq': display.nvcontrol_get_irq(gpu), + 'supports_framelock': display.nvcontrol_supports_framelock(gpu), + 'get_core_temp': display.nvcontrol_get_core_temp(gpu), + 'get_core_threshold': display.nvcontrol_get_core_threshold(gpu), + 'get_default_core_threshold': display.nvcontrol_get_default_core_threshold(gpu), + 'get_max_core_threshold': display.nvcontrol_get_max_core_threshold(gpu), + 'get_ambient_temp': display.nvcontrol_get_ambient_temp(gpu), + 'get_cuda_cores': display.nvcontrol_get_cuda_cores(gpu), + 'get_memory_bus_width': display.nvcontrol_get_memory_bus_width(gpu), + 'get_total_dedicated_gpu_memory': display.nvcontrol_get_total_dedicated_gpu_memory(gpu), + 'get_used_dedicated_gpu_memory': display.nvcontrol_get_used_dedicated_gpu_memory(gpu), + 'get_curr_pcie_link_width': display.nvcontrol_get_curr_pcie_link_width(gpu), + 'get_max_pcie_link_width': display.nvcontrol_get_max_pcie_link_width(gpu), + 'get_curr_pcie_link_generation': display.nvcontrol_get_curr_pcie_link_generation(gpu), + 'get_encoder_utilization': display.nvcontrol_get_encoder_utilization(gpu), + 'get_decoder_utilization': display.nvcontrol_get_decoder_utilization(gpu), + 'get_current_performance_level': display.nvcontrol_get_current_performance_level(gpu), + 'get_gpu_nvclock_offset': display.nvcontrol_get_gpu_nvclock_offset(gpu, perf_level), + 'get_mem_transfer_rate_offset': display.nvcontrol_get_mem_transfer_rate_offset(gpu, perf_level), + 'get_cooler_manual_control_enabled': display.nvcontrol_get_cooler_manual_control_enabled(gpu), + 'get_fan_duty': display.nvcontrol_get_fan_duty(fan), + 'get_fan_rpm': display.nvcontrol_get_fan_rpm(fan), + 'get_coolers_used_by_gpu': display.nvcontrol_get_coolers_used_by_gpu(gpu), + 'get_max_displays': display.nvcontrol_get_max_displays(gpu), + 'get_name': display.nvcontrol_get_name(gpu), + 'get_driver_version': display.nvcontrol_get_driver_version(gpu), + 'get_vbios_version': display.nvcontrol_get_vbios_version(gpu), + 'get_gpu_uuid': display.nvcontrol_get_gpu_uuid(gpu), + 'get_utilization_rates': display.nvcontrol_get_utilization_rates(gpu), + 'get_performance_modes': display.nvcontrol_get_performance_modes(gpu), + 'get_gpu_nvclock_offset_range': display.nvcontrol_get_gpu_nvclock_offset_range(gpu, perf_level), + 'get_mem_transfer_rate_offset_range': display.nvcontrol_get_mem_transfer_rate_offset_range(gpu, perf_level), + 'get_clock_info': display.nvcontrol_get_clock_info(gpu) + } + + pprint(dic) + + display.close() diff --git a/examples/profilex.py b/examples/profilex.py index 548a1a1a..e8361fd0 100755 --- a/examples/profilex.py +++ b/examples/profilex.py @@ -3,6 +3,10 @@ # 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 @@ -18,9 +22,9 @@ def dostuff(): r = d.screen().root cm = d.screen().default_colormap - for i in xrange(0, 1000): + for i in range(0, 1000): if i % 50 == 0: - print 'Iteration', i + print('Iteration', i) r.delete_property(Xatom.WM_NORMAL_HINTS) r.delete_property(Xatom.WM_NORMAL_HINTS) @@ -39,4 +43,4 @@ def main(filename): if len(sys.argv) == 2: main(sys.argv[1]) else: - print sys.argv[0], "" + print(sys.argv[0], "") diff --git a/examples/put_selection.py b/examples/put_selection.py index b0df239f..ac488621 100755 --- a/examples/put_selection.py +++ b/examples/put_selection.py @@ -5,19 +5,22 @@ # # Copyright (C) 2013 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA import sys import os @@ -88,7 +91,7 @@ def main(): # We must have a window to own a selection w = d.screen().root.create_window( 0, 0, 10, 10, 0, X.CopyFromParent) - + # And to grab the selection we must have a timestamp, get one with # a property notify when we're anyway setting wm_name w.change_attributes(event_mask = X.PropertyChangeMask) @@ -97,7 +100,7 @@ def main(): e = d.next_event() sel_time = e.time w.change_attributes(event_mask = 0) - + # Grab the selection and make sure we actually got it w.set_selection_owner(sel_atom, sel_time) if d.get_selection_owner(sel_atom) != w: @@ -105,7 +108,7 @@ def main(): return log('took ownership of selection {0}', sel_name) - + # The event loop, waiting for and processing requests while True: e = d.next_event() @@ -123,7 +126,7 @@ def main(): client_prop = e.property target_name = d.get_atom_name(e.target) - + log('got request for {0}, dest {1} on 0x{2:08x} {3}', target_name, d.get_atom_name(client_prop), client.id, client.get_wm_name()) @@ -162,7 +165,7 @@ def main(): client.send_event(ev) # Done! - + elif (e.type == X.SelectionClear and e.window == w and e.atom == sel_atom): diff --git a/examples/record_demo.py b/examples/record_demo.py index 0315eba5..25ed575d 100755 --- a/examples/record_demo.py +++ b/examples/record_demo.py @@ -4,22 +4,32 @@ # # Copyright (C) 2006 Alex Badea # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA -# Simple demo for the RECORD extension -# Not very much unlike the xmacrorec2 program in the xmacro package. +''' +Simple demo for the RECORD extension + +Not very much unlike the xmacrorec2 program in the xmacro package. +''' + + +# Python 2/3 compatibility. +from __future__ import print_function import sys import os @@ -44,9 +54,9 @@ def record_callback(reply): if reply.category != record.FromServer: return if reply.client_swapped: - print "* received swapped protocol data, cowardly ignored" + print("* received swapped protocol data, cowardly ignored") return - if not len(reply.data) or ord(reply.data[0]) < 2: + if not len(reply.data) or reply.data[0] < 2: # not an event return @@ -59,28 +69,28 @@ def record_callback(reply): keysym = local_dpy.keycode_to_keysym(event.detail, 0) if not keysym: - print "KeyCode%s" % pr, event.detail + print("KeyCode%s" % pr, event.detail) else: - print "KeyStr%s" % pr, lookup_keysym(keysym) + print("KeyStr%s" % pr, lookup_keysym(keysym)) if event.type == X.KeyPress and keysym == XK.XK_Escape: local_dpy.record_disable_context(ctx) local_dpy.flush() return elif event.type == X.ButtonPress: - print "ButtonPress", event.detail + print("ButtonPress", event.detail) elif event.type == X.ButtonRelease: - print "ButtonRelease", event.detail + print("ButtonRelease", event.detail) elif event.type == X.MotionNotify: - print "MotionNotify", event.root_x, event.root_y + print("MotionNotify", event.root_x, event.root_y) # Check if the extension is present if not record_dpy.has_extension("RECORD"): - print "RECORD extension not found" + print("RECORD extension not found") sys.exit(1) r = record_dpy.record_get_version(0, 0) -print "RECORD extension version %d.%d" % (r.major_version, r.minor_version) +print("RECORD extension version %d.%d" % (r.major_version, r.minor_version)) # Create a recording context; we only want key and mouse events ctx = record_dpy.record_create_context( diff --git a/examples/run_examples.py b/examples/run_examples.py new file mode 100644 index 00000000..9c834dcd --- /dev/null +++ b/examples/run_examples.py @@ -0,0 +1,86 @@ +#!/usr/bin/env python +# +# examples/run_examples.py -- run some examples. +# +# Copyright (C) 2016 Svetlana Filicheva +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA + +# Python 2/3 compatibility. +from __future__ import print_function + +import sys +import os +import subprocess +import unittest + +examples_folder = os.path.abspath(os.path.dirname(__file__)) + "/" + +def run_example(path): + """ Returns returncode of example """ + cmd = "{0} {1}".format(sys.executable, path) + proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + res = proc.communicate() + if proc.returncode: + print(res[1].decode()) + return proc.returncode + +class TestExamples(unittest.TestCase): + """ Run some of examples """ + +# TODO +# def test_eventthread(self): +# """ Run eventthread.py -- Tests multithreaded event handling """ +# self.assertEqual(run_example(examples_folder + "eventthread.py"), 0) + + def test_get_selection(self): + """ Run get_selection.py -- demonstrate getting selections """ + self.assertEqual(run_example(examples_folder + "get_selection.py PRIMARY"), 0) + self.assertEqual(run_example(examples_folder + "get_selection.py SECONDARY"), 0) + self.assertEqual(run_example(examples_folder + "get_selection.py CLIPBOARD"), 0) + + def test_profilex(self): + """ Run profilex.py -- program to generate profiling data """ + self.assertEqual(run_example(examples_folder + "profilex.py " + examples_folder + "profilex_output"), 0) + subprocess.call(["rm", examples_folder + "profilex_output"]) + +# TODO +# def test_record_demo(self): +# """ Run record_demo.py -- demonstrate record extension """ +# self.assertEqual(run_example(examples_folder + "record_demo.py"), 0) + + def test_security(self): + """ Run security.py -- demonstrate the SECURITY extension """ + self.assertEqual(run_example(examples_folder + "security.py --generate"), 0) + self.assertEqual(run_example(examples_folder + "security.py --revoke"), 0) + + def test_xfixes(self): + """ Run xfixes.py -- demonstrate the XFIXES extension """ + self.assertEqual(run_example(examples_folder + "xfixes.py"), 0) + + def test_xlsatoms(self): + """ Run xlsatoms.py -- show list atoms on X server """ + self.assertEqual(run_example(examples_folder + "xlsatoms.py"), 0) + + def test_xres(self): + """ Run xres.py -- demonstrate the X-Resource extension """ + self.assertEqual(run_example(examples_folder + "xres.py"), 0) + + +if __name__ == '__main__': + unittest.main() diff --git a/examples/security.py b/examples/security.py index 1fc7af52..f95047ed 100755 --- a/examples/security.py +++ b/examples/security.py @@ -5,20 +5,25 @@ # Copyright (C) 2011 Outpost Embedded, LLC # Forest Bond # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA +# Python 2/3 compatibility. +from __future__ import print_function import sys, os from optparse import OptionParser @@ -52,14 +57,14 @@ def main(argv): if not display.has_extension('SECURITY'): if display.query_extension('SECURITY') is None: - print >>sys.stderr, 'SECURITY extension not supported' + print('SECURITY extension not supported', file=sys.stderr) return 1 security_version = display.security_query_version() - print >>sys.stderr, 'Found SECURITY version %s.%s' % ( + print('SECURITY version %s.%s' % ( security_version.major_version, security_version.minor_version, - ) + ), file=sys.stderr) if opts.generate: kwargs = {} @@ -68,7 +73,7 @@ def main(argv): elif opts.untrusted: kwargs['trust_level'] = security.SecurityClientUntrusted reply = display.security_generate_authorization(opts.proto, **kwargs) - print reply.authid + print(reply.authid) elif opts.revoke: for arg in args: diff --git a/examples/shapewin.py b/examples/shapewin.py index 5fa5a5c0..015a03cf 100755 --- a/examples/shapewin.py +++ b/examples/shapewin.py @@ -4,21 +4,27 @@ # # Copyright (C) 2002 Peter Liljenberg # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA +# Python 2/3 compatibility. +from __future__ import print_function + import sys import os @@ -29,7 +35,7 @@ from Xlib.ext import shape # Application window (only one) -class Window: +class Window(object): def __init__(self, display): self.d = display @@ -39,9 +45,9 @@ def __init__(self, display): % sys.argv[1]) sys.exit(1) - # print version + # print(version) r = self.d.shape_query_version() - print 'SHAPE version %d.%d' % (r.major_version, r.minor_version) + print('SHAPE version %d.%d' % (r.major_version, r.minor_version)) # Find which screen to open the window on @@ -74,7 +80,7 @@ def __init__(self, display): # special attribute values background_pixmap = bgpm, event_mask = (X.StructureNotifyMask | - X.ButtonReleaseMask), + X.ButtonPressMask | X.ButtonReleaseMask), colormap = X.CopyFromParent, ) @@ -119,13 +125,13 @@ def __init__(self, display): gc.free() # Set initial mask - self.window.shape_mask(shape.ShapeSet, shape.ShapeBounding, + self.window.shape_mask(shape.SO.Set, shape.SK.Bounding, 0, 0, self.add_pm) - self.window.shape_mask(shape.ShapeUnion, shape.ShapeBounding, + self.window.shape_mask(shape.SO.Union, shape.SK.Bounding, 400 - self.add_size, 0, self.add_pm) - self.window.shape_mask(shape.ShapeUnion, shape.ShapeBounding, + self.window.shape_mask(shape.SO.Union, shape.SK.Bounding, 0, 300 - self.add_size, self.add_pm) - self.window.shape_mask(shape.ShapeUnion, shape.ShapeBounding, + self.window.shape_mask(shape.SO.Union, shape.SK.Bounding, 400 - self.add_size, 300 - self.add_size, self.add_pm) @@ -149,21 +155,21 @@ def loop(self): # Button released, add or subtract elif e.type == X.ButtonRelease: if e.detail == 1: - self.window.shape_mask(shape.ShapeUnion, - shape.ShapeBounding, + self.window.shape_mask(shape.SO.Union, + shape.SK.Bounding, e.event_x - self.add_size // 2, e.event_y - self.add_size // 2, self.add_pm) elif e.detail == 3: - self.window.shape_mask(shape.ShapeSubtract, - shape.ShapeBounding, + self.window.shape_mask(shape.SO.Subtract, + shape.SK.Bounding, e.event_x - self.sub_size // 2, e.event_y - self.sub_size // 2, self.sub_pm) # Shape has changed elif e.type == self.d.extension_event.ShapeNotify: - print 'Shape change' + print('Shape change') # Somebody wants to tell us something elif e.type == X.ClientMessage: diff --git a/examples/threadtest.py b/examples/threadtest.py index ed074dd8..9732f575 100755 --- a/examples/threadtest.py +++ b/examples/threadtest.py @@ -1,9 +1,13 @@ #!/usr/bin/python +# Python 2/3 compatibility. +from __future__ import print_function + import sys import os -sys.path[1:1] = [os.path.join(sys.path[0], '..')] +# Change path so we find Xlib +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) from Xlib import display, X, threaded import time @@ -16,7 +20,7 @@ def redraw(win, gc): def blink(display, win, gc, cols): while 1: time.sleep(2) - print 'Changing color', cols[0] + print('Changing color', cols[0]) gc.change(foreground = cols[0]) cols = (cols[1], cols[0]) redraw(win, gc) diff --git a/examples/xdamage.py b/examples/xdamage.py new file mode 100644 index 00000000..46cbab9d --- /dev/null +++ b/examples/xdamage.py @@ -0,0 +1,139 @@ +#!/usr/bin/python +# +# examples/xdamage.py -- demonstrate damage extension +# +# Copyright (C) 2019 Mohit Garg +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA + + +# Python 2/3 compatibility. +from __future__ import print_function + +import sys +import os + +# Change path so we find Xlib +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) + +from Xlib import display, X, threaded,Xutil +import time + +try: + import thread +except ModuleNotFoundError: + import _thread as thread + +from Xlib.ext import damage +from PIL import Image, ImageTk +import traceback + +def redraw(win, gc): + # win.clear_area() + win.fill_rectangle(gc, 0, 0, 60, 60) + +def blink(display, win, gc, cols): + while 1: + time.sleep(2) + print('Changing color', cols[0]) + gc.change(foreground = cols[0]) + cols = (cols[1], cols[0]) + redraw(win, gc) + display.flush() + +def get_image_from_win(win, pt_w, pt_h, pt_x=0, pt_y=0): + try: + raw = win.get_image(pt_x, pt_y, pt_w, pt_h, X.ZPixmap, 0xffffffff) + image = Image.frombytes("RGB", (pt_w, pt_h), raw.data, "raw", "BGRX") + return image + + except Exception: + traceback.print_exc() + +def check_ext(disp): + # Check for extension + if not disp.has_extension('DAMAGE'): + sys.stderr.write('server does not have the DAMAGE extension\n') + sys.stderr.write("\n".join(disp.list_extensions())) + + if disp.query_extension('DAMAGE') is None: + sys.exit(1) + else: + r = disp.damage_query_version() + print('DAMAGE version {}.{}'.format(r.major_version, r.minor_version)) + +def main(): + d = display.Display() + root = d.screen().root + + check_ext(d) + colormap = d.screen().default_colormap + + red = colormap.alloc_named_color("red").pixel + blue = colormap.alloc_named_color("blue").pixel + background = colormap.alloc_named_color("white").pixel + + window1 = root.create_window(100, 100, 250, 100, 1, + X.CopyFromParent, X.InputOutput, + X.CopyFromParent, + background_pixel = background, + event_mask = X.StructureNotifyMask | X.ExposureMask) + window1.set_wm_name('Changing Window') + window1.map() + gc = window1.create_gc(foreground = red) + + thread.start_new_thread(blink, (d, window1, gc, (blue, red))) + + window1.damage_create(damage.DamageReportRawRectangles) + window1.set_wm_normal_hints( + flags=(Xutil.PPosition | Xutil.PSize | Xutil.PMinSize), + min_width=50, + min_height=50 + ) + + window2 = root.create_window(100, 250, 250, 100, 1, + X.CopyFromParent, X.InputOutput, + X.CopyFromParent, + background_pixel = background, + event_mask = X.StructureNotifyMask | X.ExposureMask) + window2.set_wm_normal_hints( + flags=(Xutil.PPosition | Xutil.PSize | Xutil.PMinSize), + min_width=50, + min_height=50 + ) + + window2.set_wm_name('Tracking Window') + window2.map() + + while 1: + event = d.next_event() + if event.type == X.Expose: + if event.count == 0: + redraw(window1, gc) + elif event.type == d.extension_event.DamageNotify: + image = get_image_from_win(window1, event.area.width, event.area.height, event.area.x, event.area.y) + bgpm = window2.create_pixmap(image.width, image.height, d.screen().root_depth) + bggc = window2.create_gc(foreground=0, background=0) + bgpm.put_pil_image(bggc, 0, 0, image) + window2.copy_area(bggc, bgpm, 0, 0, image.width, image.height, 0, 0) + # bggc.free() + elif event.type == X.DestroyNotify: + sys.exit(0) + +if __name__ == "__main__": + main() diff --git a/examples/xfixes-cursor-notify.py b/examples/xfixes-cursor-notify.py new file mode 100755 index 00000000..cc443fe9 --- /dev/null +++ b/examples/xfixes-cursor-notify.py @@ -0,0 +1,72 @@ +#!/usr/bin/python3 +# +# examples/xfixes-cursor-notify.py -- demonstrate the XFIXES extension +# CursorNotify event. +# +# Copyright (C) 2022 +# Dan Isla +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# 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 + +def main(): + display = Display() + + if not display.has_extension('XFIXES'): + if display.query_extension('XFIXES') is None: + print('XFIXES extension not supported') + return 1 + + xfixes_version = display.xfixes_query_version() + print('Found XFIXES version {}.{}'.format( + xfixes_version.major_version, + xfixes_version.minor_version + )) + + screen = display.screen() + + display.xfixes_select_cursor_input(screen.root, xfixes.XFixesDisplayCursorNotifyMask) + + cursor_cache = {} + + while True: + e = display.next_event() + print(e) + + if (e.type, e.sub_code) == display.extension_event.DisplayCursorNotify: + print("DisplayCursorNotify: cursor_serial={}".format(e.cursor_serial)) + image = display.xfixes_get_cursor_image(screen.root) + cached = False + if cursor_cache.get(image.cursor_serial): + cached = True + else: + cursor_cache[image.cursor_serial] = image.cursor_image + + print("Cursor position={},{}, size={}x{}, xyhot={},{}, cursor_serial={}, cached={}".format( + image.x, image.y, image.width,image.height, image.xhot, image.yhot, image.cursor_serial, cached + )) + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/examples/xfixes-selection-notify.py b/examples/xfixes-selection-notify.py new file mode 100755 index 00000000..20728fbd --- /dev/null +++ b/examples/xfixes-selection-notify.py @@ -0,0 +1,82 @@ +#!/usr/bin/python3 +# +# examples/xfixes-selection-notify.py -- demonstrate the XFIXES extension +# SelectionNotify event. +# +# Copyright (C) 2019 +# Tony Crisci +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA + +# Python 2/3 compatibility. +from __future__ import print_function + +import sys +import os +import time + +# Change path so we find Xlib +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) + +from Xlib.display import Display +from Xlib.ext import xfixes + +def main(argv): + if len(sys.argv) != 2: + sys.exit('usage: {0} SELECTION\n\n' + 'SELECTION is typically PRIMARY, SECONDARY or CLIPBOARD.\n' + .format(sys.argv[0])) + + display = Display() + + sel_name = sys.argv[1] + sel_atom = display.get_atom(sel_name) + + if not display.has_extension('XFIXES'): + if display.query_extension('XFIXES') is None: + print('XFIXES extension not supported', file=sys.stderr) + return 1 + + xfixes_version = display.xfixes_query_version() + print('Found XFIXES version %s.%s' % ( + xfixes_version.major_version, + xfixes_version.minor_version, + ), file=sys.stderr) + + screen = display.screen() + + mask = xfixes.XFixesSetSelectionOwnerNotifyMask | \ + xfixes.XFixesSelectionWindowDestroyNotifyMask | \ + xfixes.XFixesSelectionClientCloseNotifyMask + + display.xfixes_select_selection_input(screen.root, sel_atom, mask) + + while True: + e = display.next_event() + print(e) + + if (e.type, e.sub_code) == display.extension_event.SetSelectionOwnerNotify: + print('SetSelectionOwner: owner=0x{0:08x}'.format(e.owner.id)) + elif (e.type, e.sub_code) == display.extension_event.SelectionWindowDestroyNotify: + print('SelectionWindowDestroy: owner=0x{0:08x}'.format(e.owner.id)) + elif (e.type, e.sub_code) == display.extension_event.SelectionClientCloseNotify: + print('SelectionClientClose: owner=0x{0:08x}'.format(e.owner.id)) + + +if __name__ == '__main__': + sys.exit(main(sys.argv)) diff --git a/examples/xfixes.py b/examples/xfixes.py index f74299ad..53c37146 100755 --- a/examples/xfixes.py +++ b/examples/xfixes.py @@ -5,22 +5,29 @@ # Copyright (C) 2011 Outpost Embedded, LLC # Forest Bond # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA +# Python 2/3 compatibility. +from __future__ import print_function -import sys, os, time +import sys +import os +import time # Change path so we find Xlib sys.path.append(os.path.join(os.path.dirname(__file__), '..')) @@ -33,25 +40,25 @@ def main(argv): if not display.has_extension('XFIXES'): if display.query_extension('XFIXES') is None: - print >>sys.stderr, 'XFIXES extension not supported' + print('XFIXES extension not supported', file=sys.stderr) return 1 xfixes_version = display.xfixes_query_version() - print >>sys.stderr, 'Found XFIXES version %s.%s' % ( + print('Found XFIXES version %s.%s' % ( xfixes_version.major_version, xfixes_version.minor_version, - ) + ), file=sys.stderr) screen = display.screen() - print >>sys.stderr, 'Hiding cursor ...' + print('Hiding cursor ...', file=sys.stderr) screen.root.xfixes_hide_cursor() display.sync() time.sleep(5) - print >>sys.stderr, 'Showing cursor ...' - screen.root.xfixes_hide_cursor() + print('Showing cursor ...', file=sys.stderr) + screen.root.xfixes_show_cursor() display.sync() diff --git a/examples/xinerama.py b/examples/xinerama.py index 72e00530..13419ba9 100755 --- a/examples/xinerama.py +++ b/examples/xinerama.py @@ -4,22 +4,30 @@ # # Copyright (C) 2009 David H. Bronke # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA -import sys, os, pprint +# Python 2/3 compatibility. +from __future__ import print_function + +import sys +import os +import pprint # Change path so we find Xlib sys.path.append(os.path.join(os.path.dirname(__file__), '..')) @@ -28,22 +36,22 @@ from Xlib.ext import xinerama # Application window (only one) -class Window: +class Window(object): def __init__(self, display): self.d = display # Check for extension if not self.d.has_extension('XINERAMA'): - sys.stderr.write('%s: server does not have the XINERAMA extension\n' - % sys.argv[0]) - print self.d.query_extension('XINERAMA') + sys.stderr.write('{}: server does not have the XINERAMA extension\n'.format(sys.argv[0])) + ext = self.d.query_extension('XINERAMA') + print(ext) sys.stderr.write("\n".join(self.d.list_extensions())) - if self.d.query_extension('XINERAMA') is None: + if ext is None: sys.exit(1) # print version r = self.d.xinerama_query_version() - print 'XINERAMA version %d.%d' % (r.major_version, r.minor_version) + print('XINERAMA version %d.%d' % (r.major_version, r.minor_version)) # Grab the current screen @@ -93,23 +101,23 @@ def __init__(self, display): self.pp = pprint.PrettyPrinter(indent=4) - print "Xinerama active:", bool(self.d.xinerama_is_active()) + print("Xinerama active:", bool(self.d.xinerama_is_active())) - print "Screen info:" + print("Screen info:") self.pp.pprint(self.d.xinerama_query_screens()._data) # FIXME: This doesn't work! - #print "Xinerama info:" + #print("Xinerama info:") #self.pp.pprint(self.d.xinerama_get_info(self.d.screen().root_visual)._data) - print "Xinerama state:" + print("Xinerama state:") self.pp.pprint(self.window.xinerama_get_state()._data) - print "Screen count:" + print("Screen count:") self.pp.pprint(self.window.xinerama_get_screen_count()._data) for screennum in range(self.window.xinerama_get_screen_count().screen_count): - print "Screen %d size:" % (screennum, ) + print("Screen %d size:" % (screennum, )) self.pp.pprint(self.window.xinerama_get_screen_size(screennum)._data) def parseModes(self, mode_names, modes): @@ -142,4 +150,3 @@ def loop(self): if __name__ == '__main__': Window(display.Display()).loop() - diff --git a/examples/xinput.py b/examples/xinput.py index 57cdbd98..ccfb27a3 100755 --- a/examples/xinput.py +++ b/examples/xinput.py @@ -5,45 +5,55 @@ # Copyright (C) 2012 Outpost Embedded, LLC # Forest Bond # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA + +# Python 2/3 compatibility. +from __future__ import print_function import sys +import os + +# Change path so we find Xlib +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) from Xlib.display import Display from Xlib.ext import xinput def print_hierarchy_changed_event(event): - print '' + print('}>') def print_info(info): - print ' ' % ( + print(' ' % ( info.deviceid, info.attachment, info.type, info.enabled, info.flags, - ) + )) def main(argv): @@ -53,10 +63,10 @@ def main(argv): xinput_major = extension_info.major_opcode version_info = display.xinput_query_version() - print 'Found XInput version %u.%u' % ( + print('Found XInput version %u.%u' % ( version_info.major_version, version_info.minor_version, - ) + )) screen = display.screen() screen.root.xinput_select_events([ diff --git a/examples/xlsatoms.py b/examples/xlsatoms.py index 363a352f..02a26f6d 100755 --- a/examples/xlsatoms.py +++ b/examples/xlsatoms.py @@ -1,34 +1,55 @@ #!/usr/bin/python # Copyright (C) 2011 Arun Balasubramanian # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA ''' xlsatoms - list atoms on X server (see man xlsatoms) -sample program using python Xlib that mimics the standard xlsatoms utility +sample program using python Xlib that mimics the standard xlsatoms utility additional capability is to match against regular expressions for atoms ''' -import sys,re -from Xlib import X,display,error +# 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=":0.0") +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) parser.add_option("-m","--match",dest="match_re",help="This option specifies a regular expression to match against name of an atom to list. If the atom does not exist, a message will be printed on the standard error.",metavar="reg-exp",default=None) parser.add_option("-f","--format",dest="format",help="This option specifies a printf-style string used to list each atom pair, printed in that order (value is an unsigned long and name is a char *). Xlsatoms will supply a newline at the end of each line. The default is %ld\\t%s.",metavar="string",default="%ld\t%s") @@ -42,43 +63,43 @@ d = display.Display(options.display) def print_atom(print_format,atom,value): - print print_format%(atom,value) + print(print_format%(atom,value)) def list_atoms(d,re_obj,low,high): - while(low <= high): - try: - val = d.get_atom_name(low) - if (re_obj == None) : - print_atom(options.format,low,val) - elif re_obj.match(val) != None: - print_atom(options.format,low,val) - low += 1 - except: - sys.exit(0) + while(low <= high): + try: + val = d.get_atom_name(low) + if (re_obj == None) : + print_atom(options.format,low,val) + elif re_obj.match(val) != None: + print_atom(options.format,low,val) + low += 1 + except: + sys.exit(0) if options.name != None: - try: - atom = d.intern_atom(options.name) - val = d.get_atom_name(atom) - print_atom(options.format,atom,val) - except: - sys.stderr.write('xlsatoms: no atom named "%s" on server "%s"'%(options.name,options.display)) - sys.stderr.write("\n") - sys.exit(1) - sys.exit(0) + try: + atom = d.intern_atom(options.name) + val = d.get_atom_name(atom) + print_atom(options.format,atom,val) + except: + sys.stderr.write('xlsatoms: no atom named "%s" on server "%s"'%(options.name,options.display)) + sys.stderr.write("\n") + sys.exit(1) + sys.exit(0) rangeVals = options.range.split("-") if rangeVals[0] != "": - low = long(rangeVals[0]) + low = integer_type(rangeVals[0]) if rangeVals[1] != "": - high = long(rangeVals[1]) + high = integer_type(rangeVals[1]) else: - high = sys.maxint + high = MAXSIZE if options.match_re != None: - re_obj = re.compile(options.match_re) + re_obj = re.compile(options.match_re) else: - re_obj = None + re_obj = None list_atoms(d,re_obj,low,high) diff --git a/examples/xrandr.py b/examples/xrandr.py index 9d9f6bcd..5a645340 100755 --- a/examples/xrandr.py +++ b/examples/xrandr.py @@ -4,22 +4,30 @@ # # Copyright (C) 2009 David H. Bronke # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. # -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 59 Temple Place, +# Suite 330, +# Boston, MA 02111-1307 USA -import sys, os, pprint +# Python 2/3 compatibility. +from __future__ import print_function + +import sys +import os +import pprint # Change path so we find Xlib sys.path.append(os.path.join(os.path.dirname(__file__), '..')) @@ -28,22 +36,22 @@ from Xlib.ext import randr # Application window (only one) -class Window: +class Window(object): def __init__(self, display): self.d = display # Check for extension if not self.d.has_extension('RANDR'): - sys.stderr.write('%s: server does not have the RANDR extension\n' - % sys.argv[0]) - print self.d.query_extension('RANDR') + sys.stderr.write('{}: server does not have the RANDR extension\n'.format(sys.argv[0])) + ext = self.d.query_extension('RANDR') + print(ext) sys.stderr.write("\n".join(self.d.list_extensions())) - if self.d.query_extension('RANDR') is None: + if ext is None: sys.exit(1) - # print version + # print(version) r = self.d.xrandr_query_version() - print 'RANDR version %d.%d' % (r.major_version, r.minor_version) + print('RANDR version %d.%d' % (r.major_version, r.minor_version)) # Grab the current screen @@ -101,30 +109,30 @@ def __init__(self, display): self.pp = pprint.PrettyPrinter(indent=4) - print "Screen info:" + print("Screen info:") self.pp.pprint(self.window.xrandr_get_screen_info()._data) - print "Screen size range:" + print("Screen size range:") self.pp.pprint(self.window.xrandr_get_screen_size_range()._data) - print "Primary output:" + print("Primary output:") self.pp.pprint(self.window.xrandr_get_output_primary()._data) resources = self.window.xrandr_get_screen_resources()._data - print "Modes:" - for mode_id, mode in self.parseModes(resources['mode_names'], resources['modes']).iteritems(): - print " %d: %s" % (mode_id, mode['name']) + print("Modes:") + for mode_id, mode in self.parseModes(resources['mode_names'], resources['modes']).items(): + print(" %d: %s" % (mode_id, mode['name'])) for output in resources['outputs']: - print "Output %d info:" % (output, ) + print("Output %d info:" % (output, )) self.pp.pprint(self.d.xrandr_get_output_info(output, resources['config_timestamp'])._data) for crtc in resources['crtcs']: - print "CRTC %d info:" % (crtc, ) + print("CRTC %d info:" % (crtc, )) self.pp.pprint(self.d.xrandr_get_crtc_info(crtc, resources['config_timestamp'])._data) - print "Raw screen resources:" + print("Raw screen resources:") self.pp.pprint(resources) def parseModes(self, mode_names, modes): @@ -149,8 +157,8 @@ def loop(self): # Screen information has changed elif e.__class__.__name__ == randr.ScreenChangeNotify.__name__: - print 'Screen change' - print self.pp.pprint(e._data) + print('Screen change') + print(self.pp.pprint(e._data)) # check if we're getting one of the RandR event types with subcodes elif e.type == self.d.extension_event.CrtcChangeNotify[0]: @@ -158,23 +166,23 @@ def loop(self): # CRTC information has changed if (e.type, e.sub_code) == self.d.extension_event.CrtcChangeNotify: - print 'CRTC change' + print('CRTC change') #e = randr.CrtcChangeNotify(display=display.display, binarydata = e._binary) - print self.pp.pprint(e._data) + print(self.pp.pprint(e._data)) # Output information has changed elif (e.type, e.sub_code) == self.d.extension_event.OutputChangeNotify: - print 'Output change' + print('Output change') #e = randr.OutputChangeNotify(display=display.display, binarydata = e._binary) - print self.pp.pprint(e._data) + print(self.pp.pprint(e._data)) # Output property information has changed elif (e.type, e.sub_code) == self.d.extension_event.OutputPropertyNotify: - print 'Output property change' + print('Output property change') #e = randr.OutputPropertyNotify(display=display.display, binarydata = e._binary) - print self.pp.pprint(e._data) + print(self.pp.pprint(e._data)) else: - print "Unrecognised subcode", e.sub_code + print("Unrecognised subcode", e.sub_code) # Somebody wants to tell us something elif e.type == X.ClientMessage: @@ -186,4 +194,3 @@ def loop(self): if __name__ == '__main__': Window(display.Display()).loop() - diff --git a/examples/xres.py b/examples/xres.py new file mode 100755 index 00000000..b28d7c38 --- /dev/null +++ b/examples/xres.py @@ -0,0 +1,85 @@ +#!/usr/bin/python +# +# examples/xres.py -- demonstrate the X-Resource extension +# +# Copyright (C) 2021 Aleksei Bavshin +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# as published by the Free Software Foundation; either version 2.1 +# of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., +# 51 Franklin Street, +# Fifth Floor, +# Boston, MA 02110-1301 USA + +import os +import sys + +# Change path so we find Xlib +sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) + +from Xlib.display import Display +from Xlib.ext import res as XRes + + +def check_ext(disp, extname, version): + if disp.query_extension(extname) is None: + raise AssertionError("Server has {} extension".format(extname)) + + r = disp.res_query_version() + if (r.server_major, r.server_minor) < version: + raise AssertionError( + "Server has requested version {} of {} extension".format(version, extname) + ) + + +def query_client_id(display, wid): + specs = [{"client": wid, "mask": XRes.LocalClientPIDMask}] + r = display.res_query_client_ids(specs) + for id in r.ids: + if id.spec.client > 0 and id.spec.mask == XRes.LocalClientPIDMask: + for value in id.value: + return value + return None + + +def print_client_info(disp, client): + print("client: {}".format(client)) + + resources = disp.res_query_client_resources(client) + rc = [r.count for r in resources.types] + print("\tresouces: {} resources of {} types".format(sum(rc), len(rc))) + + pb = disp.res_query_client_pixmap_bytes(client) + print("\tpixmaps: {} bytes {} overflow".format(pb.bytes, pb.bytes_overflow)) + + pid = query_client_id(disp, client) + print("\tpid: {}".format(pid)) + + rb = disp.res_query_resource_bytes(client, [{"resource": 0, "type": 0}]) + sizes = [s.size.bytes for s in rb.sizes] + print("\t{} resources consume {} bytes".format(len(sizes), sum(sizes))) + + +def main(): + display = Display() + check_ext(display, XRes.extname, (1, 2)) + + clients = display.res_query_clients().clients + print("{} clients connected to the server".format(len(clients))) + + for client in clients: + print_client_info(display, client.resource_base) + + +if __name__ == "__main__": + main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..dde39334 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +six>=1.10.0 diff --git a/runtests.py b/runtests.py new file mode 100755 index 00000000..4e77de87 --- /dev/null +++ b/runtests.py @@ -0,0 +1,134 @@ +#!/usr/bin/env python + +# Python 2/3 compatibility. +from __future__ import print_function + +import os +import signal +import subprocess +import sys +import tempfile +import textwrap + +from pkg_resources import load_entry_point + + +class SigException(BaseException): + def __init__(self, signum): + super(SigException, self).__init__() + self.signum = signum + +def xsession_sighandler(signum, frame): + raise SigException(signum) + +def xserver_start(display, executable='Xvfb', authfile=None): + pid = os.fork() + if pid != 0: + return pid + if authfile is None: + authfile = os.devnull + # This will make the xserver send us a SIGUSR1 when ready. + signal.signal(signal.SIGUSR1, signal.SIG_IGN) + cmd = [ + executable, + '-auth', authfile, + '-noreset', + display, + ] + print('starting xserver: `{0}`'.format(' '.join(cmd))) + os.execlp(cmd[0], *cmd) + +def tests_run(display, authfile=None): + pid = os.fork() + if pid != 0: + return pid + if authfile is None: + authfile = os.devnull + os.environ['DISPLAY'] = display + os.environ['XAUTHORITY'] = authfile + cmd = [ + sys.executable, + '-c', textwrap.dedent( + ''' + from pkg_resources import load_entry_point + sys.exit(load_entry_point( + 'nose', 'console_scripts', 'nosetests', + )()) + ''' + ).lstrip(), + '--exe', '--with-xunit', '--verbosity=3', + ] + has_custom_tests = False + for arg in sys.argv[1:]: + if not arg.startswith('-'): + has_custom_tests = True + cmd.append(arg) + if not has_custom_tests: + cmd.extend(('test/', 'examples/run_examples.py')) + print('running tests: `{0}`'.format(' '.join(cmd))) + sys.argv = cmd + try: + load_entry_point('nose', 'console_scripts', 'nosetests')() + except SystemExit as err: + code = err.code + else: + code = 0 + os._exit(code) + + +def runtests(): + + cleanup_funcs = [] + + try: + if hasattr(sys, 'pypy_version_info'): + server_display = ':8' + else: + server_display = ':9' + server_display += ''.join(str(n) for n in sys.version_info[:3]) + + # Setup a temporary authentication file. + cookie = subprocess.check_output('mcookie').strip() + authfile = tempfile.NamedTemporaryFile(delete=False) + cleanup_funcs.append(lambda: os.unlink(authfile.name)) + authfile.close() + subprocess.check_call(( + 'xauth', + '-f', authfile.name, + 'add', server_display, '.', cookie, + )) + + # Setup signal handler to wait for xserver to be ready. + signal.signal(signal.SIGUSR1, xsession_sighandler) + + # Start xserver. + server_pid = xserver_start(server_display, authfile=authfile.name) + cleanup_funcs.append(lambda: os.waitpid(server_pid, 0)) + cleanup_funcs.append(lambda: os.kill(server_pid, signal.SIGTERM)) + + # Give the server 3 seconds to start. + signal.alarm(3) + + # Wait for server to be ready. + try: + signal.pause() + except SigException as err: + assert signal.SIGUSR1 == err.signum + signal.alarm(0) + + # Run tests. + tests_pid = tests_run(server_display, authfile=authfile.name) + pid, status = os.waitpid(tests_pid, 0) + assert pid == tests_pid + sys.exit(status >> 8) + + except KeyboardInterrupt: + sys.exit(1) + + finally: + for func in reversed(cleanup_funcs): + func() + + +if __name__ == '__main__': + runtests() diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 00000000..29a11ad0 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,39 @@ +[metadata] +name = python-xlib +version = attr: Xlib.__version_string__ +description = Python X Library +long_description = file: README.rst +download_url = https://github.com/python-xlib/python-xlib/releases +url = https://github.com/python-xlib/python-xlib +license = LGPLv2+ +author = Peter Liljenberg +author_email = petli@ctrl-c.liu.se +keywords = + windows + x + x11 + xlib +classifiers = + Development Status :: 5 - Production/Stable + Environment :: X11 Applications + 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 :: 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 28eacf8a..71bdb085 100644 --- a/setup.py +++ b/setup.py @@ -1,32 +1,23 @@ # Distutils script for python-xlib -from distutils.core import setup -import sys - -if sys.version < '2.3.3': - from distutils.dist import DistributionMetadata - DistributionMetadata.download_url = None - -import Xlib - -setup(name='python-xlib', - version=Xlib.__version_string__, - - description='Python X Library', - download_url='http://sourceforge.net/projects/python-xlib/files/', - url='http://python-xlib.sourceforge.net/', - license='GPL', - - author='Peter Liljenberg', - author_email='petli@ctrl-c.liu.se', - - packages=[ - 'Xlib', - 'Xlib.ext', - 'Xlib.keysymdef', - 'Xlib.protocol', - 'Xlib.support', - 'Xlib.xobject' - ], - ) - +from pkg_resources import parse_requirements +from setuptools import (__version__ as setuptools_version, setup) + + +# Check setuptools is recent enough to support `setup.cfg`. +setuptools_require = next(parse_requirements('setuptools>=30.3.0')) +assert setuptools_version in setuptools_require, '{} is required'.format(setuptools_require) + + +setup( + install_requires=['six>=1.10.0'], + setup_requires=['setuptools-scm'], + packages=[ + 'Xlib', + 'Xlib.ext', + 'Xlib.keysymdef', + 'Xlib.protocol', + 'Xlib.support', + 'Xlib.xobject' + ], +) diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 00000000..7b73e96c --- /dev/null +++ b/test/__init__.py @@ -0,0 +1,79 @@ + +import unittest +import binascii +import difflib +import struct +import array + +import Xlib.protocol.event +import Xlib.protocol.rq + + +class CmpArray(object): + + def __init__(self, *args, **kws): + self.array = array.array(*args, **kws) + + def __len__(self): + return len(self.array) + + def __getitem__(self, key): + if isinstance(key, slice): + x = key.start + y = key.stop + return list(self.array[x:y]) + else: + return self.array[key] + + def __getattr__(self, attr): + return getattr(self.array, attr) + + def __eq__(self, other): + return self.array.tolist() == other + +Xlib.protocol.rq.array = CmpArray + + +class DummyDisplay(object): + + def get_resource_class(self, x): + return None + + event_classes = Xlib.protocol.event.event_class + + +class TestCase(unittest.TestCase): + + def assertBinaryEqual(self, bin1, bin2): + if bin1 != bin2: + self.fail('binary contents differ:\n' + bindiff(bin1, bin2)) + + def assertBinaryEmpty(self, bin): + if len(bin) != 0: + self.fail('binary content not empty:\n' + ''.join(tohex(bin))) + +class BigEndianTest(TestCase): + + @classmethod + def setUpClass(cls): + if struct.unpack('BB', struct.pack('H', 0x0100))[0] != 1: + raise unittest.SkipTest('big-endian tests, skipping on this system') + +class LittleEndianTest(TestCase): + + @classmethod + def setUpClass(cls): + if struct.unpack('BB', struct.pack('H', 0x0100))[0] != 0: + raise unittest.SkipTest('little-endian tests, skipping on this system') + + +def tohex(bin): + hex = [] + for i in range(0, len(bin), 16): + hex.append(str(binascii.hexlify(bin[i:i+16])) + '\n') + return hex + +def bindiff(bin1, bin2): + hex1 = tohex(bin1) + hex2 = tohex(bin2) + return ''.join(difflib.ndiff(hex1, hex2)) diff --git a/test/gen/.gitignore b/test/gen/.gitignore new file mode 100644 index 00000000..e41b14be --- /dev/null +++ b/test/gen/.gitignore @@ -0,0 +1,4 @@ +/genevent +/genevent.c +/genrequest +/genrequest.c diff --git a/test/gen/genprottest.py b/test/gen/genprottest.py old mode 100755 new mode 100644 index 1275acc9..86619af1 --- a/test/gen/genprottest.py +++ b/test/gen/genprottest.py @@ -3,14 +3,17 @@ import sys import os -sys.path.insert(1, os.path.join(sys.path[0], '../..')) +sys.path.insert(0, os.path.normpath(os.path.join(__file__, '../../..'))) -import types import struct -from whrandom import randint, choice +from random import randint, choice, seed from Xlib.protocol import request, structs, rq, event -from Xlib import X, XK +from Xlib import X + + + +seed(42) MINI_DEF = (('CARD8', 'reqType'), ('BYTE', 'pad'), @@ -71,8 +74,8 @@ def build_request(endian): fc.write(C_HEADER) - reqlist = request.major_codes.items() - reqlist.sort(lambda x, y: cmp(x[0], y[0])) + reqlist = list(request.major_codes.items()) + reqlist.sort(key=lambda x: x[0]) genfuncs = [] req_args = {} @@ -181,14 +184,14 @@ def build_request(endian): elif parts[0] == 'REPLY': reply_bins[parts[1]] = parts[2] - fpy = open('test_requests_%s.py' % endian, 'w') - os.chmod('test_requests_%s.py' % endian, 0755) + fpy = open('../test_requests_%s.py' % endian, 'w') + os.chmod('../test_requests_%s.py' % endian, 0o755) if endian == 'be': - e = 'Big-endian' + e = 'BigEndian' v = 1 else: - e = 'Little-endian' + e = 'LittleEndian' v = 0 fpy.write(PY_HEADER % { 'endname': e, 'endvalue': v }) @@ -196,7 +199,7 @@ def build_request(endian): for code, req in reqlist: name = req.__name__ - fpy.write('\n\nclass Test%s(unittest.TestCase):\n' % name) + fpy.write('\n\nclass Test%s(EndianTest):\n' % name) fpy.write(' def setUp(self):\n') i = 0 @@ -233,30 +236,29 @@ def build_request(endian): fpy.write(''' def testPackRequest%(n)d(self): bin = request.%(req)s._request.to_binary(*(), **self.req_args_%(n)d) - self.assert_(bin == self.req_bin_%(n)d, tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_%(n)d) def testUnpackRequest%(n)d(self): args, remain = request.%(req)s._request.parse_binary(self.req_bin_%(n)d, dummy_display, 1) - self.assert_(len(remain) == 0, tohex(remain)) - self.assert_(args == self.req_args_%(n)d, args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_%(n)d) ''' % { 'req': req.__name__, 'n': i }) for i in range(0, replies + 1): fpy.write(''' def testPackReply%(n)d(self): bin = request.%(req)s._reply.to_binary(*(), **self.reply_args_%(n)d) - self.assert_(bin == self.reply_bin_%(n)d, tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_%(n)d) def testUnpackReply%(n)d(self): args, remain = request.%(req)s._reply.parse_binary(self.reply_bin_%(n)d, dummy_display, 1) - self.assert_(len(remain) == 0, tohex(remain)) - self.assert_(args == self.reply_args_%(n)d, args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_%(n)d) ''' % { 'req': req.__name__, 'n': i }) fpy.write(''' if __name__ == "__main__": - check_endian() unittest.main() ''') @@ -266,8 +268,8 @@ def build_event(endian): fc.write(C_HEADER) - evtlist = event.event_class.items() - evtlist.sort(lambda x, y: cmp(x[0], y[0])) + evtlist = list(event.event_class.items()) + evtlist.sort(key=lambda x: x[0]) genfuncs = [] evt_args = {} @@ -350,14 +352,14 @@ def build_event(endian): if parts[0] == 'EVENT': evt_bins[parts[1]] = parts[2] - fpy = open('test_events_%s.py' % endian, 'w') - os.chmod('test_events_%s.py' % endian, 0755) + fpy = open('../test_events_%s.py' % endian, 'w') + os.chmod('../test_events_%s.py' % endian, 0o755) if endian == 'be': - e = 'Big-endian' + e = 'BigEndian' v = 1 else: - e = 'Little-endian' + e = 'LittleEndian' v = 0 fpy.write(PY_HEADER % { 'endname': e, 'endvalue': v }) @@ -368,7 +370,7 @@ def build_event(endian): name = evt.__name__ - fpy.write('\n\nclass Test%s(unittest.TestCase):\n' % name) + fpy.write('\n\nclass Test%s(EndianTest):\n' % name) fpy.write(' def setUp(self):\n') i = 0 @@ -395,18 +397,17 @@ def build_event(endian): fpy.write(''' def testPack%(n)d(self): bin = event.%(evt)s._fields.to_binary(*(), **self.evt_args_%(n)d) - self.assert_(bin == self.evt_bin_%(n)d, tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_%(n)d) def testUnpack%(n)d(self): args, remain = event.%(evt)s._fields.parse_binary(self.evt_bin_%(n)d, dummy_display, 1) - self.assert_(len(remain) == 0, tohex(remain)) - self.assert_(args == self.evt_args_%(n)d, args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_%(n)d) ''' % { 'evt': evt.__name__, 'n': i }) fpy.write(''' if __name__ == "__main__": - check_endian() unittest.main() ''') @@ -477,7 +478,7 @@ def gen_func(fc, funcname, structname, outputname, pydef, cdef, vardefs): def rand(x, rmin = rmin, rmax = rmax): return randint(rmin, rmax) - vfdata = map(rand, range(0, vflen)) + vfdata = list(map(rand, range(0, vflen))) # # Special case for a few in-line coded lists @@ -584,7 +585,7 @@ def rand(x, rmin = rmin, rmax = rmax): # # byte-char string # - elif isinstance(f, rq.String8): + elif isinstance(f, (rq.String8, rq.Binary)): vfstr = vardefs[i] vflen = len(vfstr) @@ -630,11 +631,11 @@ def rand(x, rmin = rmin, rmax = rmax): # elif isinstance(f, rq.TextElements8): if isinstance(f, rq.TextElements16): - vfstr = '\x02\x02\x10\x23\x00\x12\xff\x01\x02\x03\x04' + vfstr = b'\x02\x02\x10\x23\x00\x12\xff\x01\x02\x03\x04' ret = [{'delta': 2, 'string': (0x1023, 0x0012)}, 0x01020304] else: - vfstr = '\x03\x02zoo\xff\x01\x02\x03\x04\x02\x00ie' + vfstr = b'\x03\x02zoo\xff\x01\x02\x03\x04\x02\x00ie' ret = [{'delta': 2, 'string': 'zoo'}, 0x01020304, { 'delta': 0, 'string': 'ie'}] @@ -790,14 +791,14 @@ def rand(x, rmin = rmin, rmax = rmax): assert f == 'length' fc.write(' assert(sizeof(data) % 4 == 0);\n') - fc.write(' data.xstruct.length = sizeof(data) // 4;\n') + fc.write(' data.xstruct.length = sizeof(data) / 4;\n') elif isinstance(pyf, rq.ReplyLength): assert f == 'length' fc.write(' assert(sizeof(data) % 4 == 0);\n') fc.write(' assert(sizeof(data) >= 32);\n') - fc.write(' data.xstruct.length = (sizeof(data) - 32) // 4;\n') + fc.write(' data.xstruct.length = (sizeof(data) - 32) / 4;\n') elif isinstance(pyf, rq.LengthOf): fc.write(' data.xstruct.%s = %d;\n' % (f, varfs[pyf.name][1])) @@ -869,13 +870,24 @@ def pad4(l): return l + (4 - l % 4) % 4 def cstring(s): - return '"' + ''.join(map(lambda c: '\\x%x' % ord(c), s)) + '"' + if not isinstance(s, bytes): + s = s.encode('ascii') + return '"' + ''.join('\\x%x' % c for c in s) + '"' def build_args(args): kwlist = [] - for kw, val in args.items(): - kwlist.append(" '%s': %s,\n" % (kw, repr(val))) + for kw, val in sorted(args.items(), key=lambda i: i[0]): + if isinstance(val, rq.Event): + members = list(val._data.keys()) + members.remove('send_event') + kwlist.append(" '%s': event.%s(%s),\n" % ( + kw, val.__class__.__name__, + ', '.join('%s=%s' % (m, val._data[m]) + for m in sorted(members)), + )) + else: + kwlist.append(" '%s': %s,\n" % (kw, repr(val))) return '{\n' + ''.join(kwlist) + ' }' @@ -887,18 +899,18 @@ def build_bin(bin): bins2 = [] for i in range(0, len(bins), 2): try: - bins2.append("'%s' '%s'" % (bins[i], bins[i + 1])) + bins2.append("b'%s' b'%s'" % (bins[i], bins[i + 1])) except IndexError: - bins2.append("'%s'" % bins[i]) + bins2.append("b'%s'" % bins[i]) return ' \\\n '.join(bins2) request_var_defs = { 'InternAtom': ('fuzzy_prop', ), - 'ChangeProperty': [((8, ''), ), - ((8, 'foo'), ), - ((8, 'zoom'), ), + 'ChangeProperty': [((8, b''), ), + ((8, b'foo'), ), + ((8, b'zoom'), ), ((16, []), ), ((16, [1, 2, 3]), ), ((16, [1, 2, 3, 4]), ), @@ -921,7 +933,7 @@ def build_bin(bin): 'FillPoly': (('Point', 3), ), 'PolyFillRectangle': (('Rectangle', 2), ), 'PolyFillArc': (('Arc', 1), ), - 'PutImage': ('bit map data', ), + 'PutImage': (b'\xe9\x10\xf2o\x7f{\xae-\xe6\x18\xce\x83', ), 'ImageText8': ('showme', ), 'ImageText16': ('showmore', ), 'AllocNamedColor': ('octarin', ), @@ -939,9 +951,9 @@ def build_bin(bin): reply_var_defs = { 'QueryTree': (7, ), 'GetAtomName': ('WM_CLASS', ), - 'GetProperty': [((8, ''), ), - ((8, 'foo'), ), - ((8, 'zoom'), ), + 'GetProperty': [((8, b''), ), + ((8, b'foo'), ), + ((8, b'zoom'), ), ((16, []), ), ((16, [1, 2, 3]), ), ((16, [1, 2, 3, 4]), ), @@ -955,7 +967,7 @@ def build_bin(bin): 'ListFontsWithInfo': (('FontProp', 1), 'fontfont'), 'GetFontPath': [(['path1', 'path2232'], ), ([], ) ], - 'GetImage': ('this is real ly imag e b-map', ), + 'GetImage': (b'\xeb?:\xa7\xc6\x8b\xc2\x96o-S\xe6\xd6z6\x94\xd7v\xd2R.\xa2\xeaw\t\x13\x95\x85',), 'ListInstalledColormaps': (2, ), 'AllocColorCells': [(17, 3), (0, 0) ], @@ -968,7 +980,7 @@ def build_bin(bin): } event_var_defs = { - 'ClientMessage': [((8, '01234567890123456789'), ), + 'ClientMessage': [((8, b'01234567890123456789'), ), ((16, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), ), ((32, [1, 2, 3, 4, 5]), ) ], } @@ -986,6 +998,7 @@ def build_bin(bin): #include #include #include +#include #include void output(char *name, void *data, int length) @@ -1007,70 +1020,17 @@ def build_bin(bin): ''' -PY_HEADER = r'''#!/usr/bin/env python +PY_HEADER = r'''#!/usr/bin/env python2 import sys, os -sys.path.append(os.path.join(os.path.dirname(__file__), '..')) +sys.path.insert(0, os.path.normpath(os.path.join(__file__, '../..'))) import unittest -from Xlib.protocol import request, rq, event -import Xlib.protocol.event - -import struct -import array - -class CmpArray(object): - def __init__(self, *args, **kws): - self.array = array.array(*args, **kws) - - def __len__(self): - return len(self.array) +from Xlib.protocol import request, event +from . import %(endname)sTest as EndianTest +from . import DummyDisplay - def __getitem__(self, key): - if isinstance(key, slice): - x = key.start - y = key.stop - return list(self.array[x:y]) - else: - return self.array[key] - - def __getattr__(self, attr): - return getattr(self.array, attr) - - def __cmp__(self, other): - return cmp(self.array.tolist(), other) - -rq.array = CmpArray - -def tohex(bin): - bin = ''.join(map(lambda c: '\\x%%02x' %% ord(c), bin)) - - bins = [] - for i in range(0, len(bin), 16): - bins.append(bin[i:i+16]) - - bins2 = [] - for i in range(0, len(bins), 2): - try: - bins2.append("'%%s' '%%s'" %% (bins[i], bins[i + 1])) - except IndexError: - bins2.append("'%%s'" %% bins[i]) - - return ' \\\n '.join(bins2) - -class DummyDisplay: - def get_resource_class(self, x): - return None - - event_classes = Xlib.protocol.event.event_class dummy_display = DummyDisplay() - - -def check_endian(): - if struct.unpack('BB', struct.pack('H', 0x0100))[0] != %(endvalue)d: - sys.stderr.write('%(endname)s tests, skipping on this system.\n') - sys.exit(0) - ''' if __name__ == '__main__': diff --git a/test/test_bytesview.py b/test/test_bytesview.py new file mode 100644 index 00000000..565793a1 --- /dev/null +++ b/test/test_bytesview.py @@ -0,0 +1,27 @@ + +import unittest + +# Python 2/3 compatibility. +from six import indexbytes, text_type + +from Xlib.protocol.display import bytesview + + +class BytesViewTest(unittest.TestCase): + + def test(self): + with self.assertRaises(TypeError): + bytesview(text_type('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')) + view = bytesview(view, 5) + self.assertEqual(view[:], b'56789ABCDEF') + self.assertEqual(indexbytes(view, 4), ord('9')) + view = bytesview(view, 0, 5) + self.assertEqual(view[:], b'56789') + self.assertEqual(indexbytes(view, 1), ord('6')) diff --git a/test/test_events_be.py b/test/test_events_be.py index d0514d30..827ee53d 100755 --- a/test/test_events_be.py +++ b/test/test_events_be.py @@ -1,908 +1,638 @@ -#!/usr/bin/env python +#!/usr/bin/env python2 import sys, os -sys.path.append(os.path.join(os.path.dirname(__file__), '..')) +sys.path.insert(0, os.path.normpath(os.path.join(__file__, '../..'))) import unittest -from Xlib.protocol import request, rq, event -import Xlib.protocol.event +from Xlib.protocol import request, event +from . import BigEndianTest as EndianTest +from . import DummyDisplay -import struct -import array - -class CmpArray(object): - def __init__(self, *args, **kws): - self.array = array.array(*args, **kws) - - def __len__(self): - return len(self.array) - - def __getitem__(self, key): - if isinstance(key, slice): - x = key.start - y = key.stop - return list(self.array[x:y]) - else: - return self.array[key] - - def __getattr__(self, attr): - return getattr(self.array, attr) - - def __cmp__(self, other): - return cmp(self.array.tolist(), other) - -rq.array = CmpArray - -def tohex(bin): - bin = ''.join(map(lambda c: '\\x%02x' % ord(c), bin)) - - bins = [] - for i in range(0, len(bin), 16): - bins.append(bin[i:i+16]) - - bins2 = [] - for i in range(0, len(bins), 2): - try: - bins2.append("'%s' '%s'" % (bins[i], bins[i + 1])) - except IndexError: - bins2.append("'%s'" % bins[i]) - - return ' \\\n '.join(bins2) - -class DummyDisplay: - def get_resource_class(self, x): - return None - - event_classes = Xlib.protocol.event.event_class dummy_display = DummyDisplay() -def check_endian(): - if struct.unpack('BB', struct.pack('H', 0x0100))[0] != 1: - sys.stderr.write('Big-endian tests, skipping on this system.\n') - sys.exit(0) - - - -class TestKeymapNotify(unittest.TestCase): +class TestKeymapNotify(EndianTest): def setUp(self): self.evt_args_0 = { - 'type': 154, - 'data': [160, 192, 133, 223, 245, 128, 133, 188, 208, 142, 202, 142, 218, 238, 145, 150, 211, 150, 165, 230, 149, 162, 139, 159, 135, 255, 246, 202, 232, 185, 164], + 'data': [248, 202, 136, 187, 201, 200, 244, 146, 187, 195, 178, 236, 157, 185, 166, 196, 164, 146, 143, 170, 206, 201, 240, 159, 247, 205, 231, 197, 254, 240, 148], + 'type': 138, } - self.evt_bin_0 = '\x9a\xa0\xc0\x85' '\xdf\xf5\x80\x85' \ - '\xbc\xd0\x8e\xca' '\x8e\xda\xee\x91' \ - '\x96\xd3\x96\xa5' '\xe6\x95\xa2\x8b' \ - '\x9f\x87\xff\xf6' '\xca\xe8\xb9\xa4' + self.evt_bin_0 = b'\x8a\xf8\xca\x88' b'\xbb\xc9\xc8\xf4' \ + b'\x92\xbb\xc3\xb2' b'\xec\x9d\xb9\xa6' \ + b'\xc4\xa4\x92\x8f' b'\xaa\xce\xc9\xf0' \ + b'\x9f\xf7\xcd\xe7' b'\xc5\xfe\xf0\x94' def testPack0(self): bin = event.KeymapNotify._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.KeymapNotify._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestExpose(unittest.TestCase): +class TestExpose(EndianTest): def setUp(self): self.evt_args_0 = { - 'height': 22214, - 'sequence_number': 56268, - 'type': 254, - 'x': 16974, - 'y': 19752, - 'window': 1381709156, - 'width': 26369, - 'count': 60118, + 'count': 15258, + 'height': 6241, + 'sequence_number': 48394, + 'type': 238, + 'width': 1951, + 'window': 692245859, + 'x': 39820, + 'y': 16664, } - self.evt_bin_0 = '\xfe\x00\xdb\xcc' '\x52\x5b\x35\x64' \ - '\x42\x4e\x4d\x28' '\x67\x01\x56\xc6' \ - '\xea\xd6\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.evt_bin_0 = b'\xee\x00\xbd\x0a' b'\x29\x42\xd5\x63' \ + b'\x9b\x8c\x41\x18' b'\x07\x9f\x18\x61' \ + b'\x3b\x9a\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.Expose._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.Expose._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestGraphicsExpose(unittest.TestCase): +class TestGraphicsExpose(EndianTest): def setUp(self): self.evt_args_0 = { - 'height': 352, - 'sequence_number': 6380, - 'type': 242, - 'drawable': 820411264, - 'x': 57593, - 'y': 41762, - 'major_event': 216, - 'count': 63321, - 'width': 58556, - 'minor_event': 22632, + 'count': 49818, + 'drawable': 1443779242, + 'height': 2892, + 'major_event': 172, + 'minor_event': 50267, + 'sequence_number': 50375, + 'type': 133, + 'width': 38020, + 'x': 54088, + 'y': 17918, } - self.evt_bin_0 = '\xf2\x00\x18\xec' '\x30\xe6\x7b\x80' \ - '\xe0\xf9\xa3\x22' '\xe4\xbc\x01\x60' \ - '\x58\x68\xf7\x59' '\xd8\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.evt_bin_0 = b'\x85\x00\xc4\xc7' b'\x56\x0e\x52\xaa' \ + b'\xd3\x48\x45\xfe' b'\x94\x84\x0b\x4c' \ + b'\xc4\x5b\xc2\x9a' b'\xac\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.GraphicsExpose._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.GraphicsExpose._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestNoExpose(unittest.TestCase): +class TestNoExpose(EndianTest): def setUp(self): self.evt_args_0 = { - 'sequence_number': 46171, - 'major_event': 242, - 'type': 187, - 'window': 1319843810, - 'minor_event': 45687, + 'major_event': 199, + 'minor_event': 29237, + 'sequence_number': 34266, + 'type': 248, + 'window': 1399171519, } - self.evt_bin_0 = '\xbb\x00\xb4\x5b' '\x4e\xab\x37\xe2' \ - '\xb2\x77\xf2\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.evt_bin_0 = b'\xf8\x00\x85\xda' b'\x53\x65\xa9\xbf' \ + b'\x72\x35\xc7\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.NoExpose._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.NoExpose._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestVisibilityNotify(unittest.TestCase): +class TestVisibilityNotify(EndianTest): def setUp(self): self.evt_args_0 = { - 'state': 238, - 'sequence_number': 52805, - 'type': 242, - 'window': 1543431298, + 'sequence_number': 38616, + 'state': 253, + 'type': 174, + 'window': 936121409, } - self.evt_bin_0 = '\xf2\x00\xce\x45' '\x5b\xfe\xe4\x82' \ - '\xee\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.evt_bin_0 = b'\xae\x00\x96\xd8' b'\x37\xcc\x14\x41' \ + b'\xfd\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.VisibilityNotify._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.VisibilityNotify._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestCreateNotify(unittest.TestCase): +class TestCreateNotify(EndianTest): def setUp(self): self.evt_args_0 = { - 'height': 15506, - 'sequence_number': 8253, - 'type': 255, - 'border_width': 53414, - 'x': -31204, - 'y': -23908, - 'override': 1, - 'parent': 654326356, - 'window': 8505372, - 'width': 8871, + 'border_width': 56468, + 'height': 7111, + 'override': 0, + 'parent': 747306217, + 'sequence_number': 31058, + 'type': 151, + 'width': 44173, + 'window': 876986399, + 'x': -21847, + 'y': -22248, } - self.evt_bin_0 = '\xff\x00\x20\x3d' '\x27\x00\x3a\x54' \ - '\x00\x81\xc8\x1c' '\x86\x1c\xa2\x9c' \ - '\x22\xa7\x3c\x92' '\xd0\xa6\x01\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.evt_bin_0 = b'\x97\x00\x79\x52' b'\x2c\x8a\xfc\xe9' \ + b'\x34\x45\xc0\x1f' b'\xaa\xa9\xa9\x18' \ + b'\xac\x8d\x1b\xc7' b'\xdc\x94\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.CreateNotify._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.CreateNotify._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestDestroyNotify(unittest.TestCase): +class TestDestroyNotify(EndianTest): def setUp(self): self.evt_args_0 = { - 'sequence_number': 49137, - 'event': 408289937, - 'type': 223, - 'window': 1716558237, + 'event': 1489718405, + 'sequence_number': 27233, + 'type': 212, + 'window': 1064077163, } - self.evt_bin_0 = '\xdf\x00\xbf\xf1' '\x18\x56\x02\x91' \ - '\x66\x50\x99\x9d' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.evt_bin_0 = b'\xd4\x00\x6a\x61' b'\x58\xcb\x4c\x85' \ + b'\x3f\x6c\x87\x6b' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.DestroyNotify._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.DestroyNotify._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestUnmapNotify(unittest.TestCase): +class TestUnmapNotify(EndianTest): def setUp(self): self.evt_args_0 = { + 'event': 2029853215, 'from_configure': 0, - 'sequence_number': 4412, - 'event': 1122103072, - 'type': 217, - 'window': 1455493798, + 'sequence_number': 43679, + 'type': 201, + 'window': 860030193, } - self.evt_bin_0 = '\xd9\x00\x11\x3c' '\x42\xe1\xef\x20' \ - '\x56\xc1\x12\xa6' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.evt_bin_0 = b'\xc9\x00\xaa\x9f' b'\x78\xfd\x1a\x1f' \ + b'\x33\x43\x04\xf1' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.UnmapNotify._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.UnmapNotify._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestMapNotify(unittest.TestCase): +class TestMapNotify(EndianTest): def setUp(self): self.evt_args_0 = { - 'sequence_number': 65096, - 'event': 328610268, - 'type': 228, - 'window': 1882369959, - 'override': 0, + 'event': 675485985, + 'override': 1, + 'sequence_number': 6027, + 'type': 244, + 'window': 542087937, } - self.evt_bin_0 = '\xe4\x00\xfe\x48' '\x13\x96\x31\xdc' \ - '\x70\x32\xaf\xa7' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.evt_bin_0 = b'\xf4\x00\x17\x8b' b'\x28\x43\x19\x21' \ + b'\x20\x4f\x9b\x01' b'\x01\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.MapNotify._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.MapNotify._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestMapRequest(unittest.TestCase): +class TestMapRequest(EndianTest): def setUp(self): self.evt_args_0 = { - 'parent': 1664235152, - 'sequence_number': 51552, - 'type': 171, - 'window': 488763730, + 'parent': 1659099581, + 'sequence_number': 63838, + 'type': 157, + 'window': 868024861, } - self.evt_bin_0 = '\xab\x00\xc9\x60' '\x63\x32\x36\x90' \ - '\x1d\x21\xf1\x52' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.evt_bin_0 = b'\x9d\x00\xf9\x5e' b'\x62\xe3\xd9\xbd' \ + b'\x33\xbd\x02\x1d' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.MapRequest._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.MapRequest._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestReparentNotify(unittest.TestCase): +class TestReparentNotify(EndianTest): def setUp(self): self.evt_args_0 = { - 'sequence_number': 9256, - 'event': 2000272853, - 'type': 229, - 'override': 1, - 'x': -28587, - 'y': -11597, - 'parent': 912114770, - 'window': 1142506827, + 'event': 1867017989, + 'override': 0, + 'parent': 992152190, + 'sequence_number': 43356, + 'type': 128, + 'window': 1165276406, + 'x': -19227, + 'y': -30992, } - self.evt_bin_0 = '\xe5\x00\x24\x28' '\x77\x39\xbd\xd5' \ - '\x44\x19\x45\x4b' '\x36\x5d\xc4\x52' \ - '\x90\x55\xd2\xb3' '\x01\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.evt_bin_0 = b'\x80\x00\xa9\x5c' b'\x6f\x48\x6f\x05' \ + b'\x45\x74\xb4\xf6' b'\x3b\x23\x0a\x7e' \ + b'\xb4\xe5\x86\xf0' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.ReparentNotify._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.ReparentNotify._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestConfigureNotify(unittest.TestCase): +class TestConfigureNotify(EndianTest): def setUp(self): self.evt_args_0 = { - 'height': 16243, - 'sequence_number': 62364, - 'event': 1373455462, - 'type': 191, - 'border_width': 7244, - 'x': -12771, - 'y': -15228, - 'override': 1, - 'above_sibling': 1099666850, - 'window': 2046157981, - 'width': 8604, + 'above_sibling': 1343120585, + 'border_width': 17757, + 'event': 1624514845, + 'height': 13596, + 'override': 0, + 'sequence_number': 41060, + 'type': 220, + 'width': 3638, + 'window': 1070571314, + 'x': -18284, + 'y': -7865, } - self.evt_bin_0 = '\xbf\x00\xf3\x9c' '\x51\xdd\x44\x66' \ - '\x79\xf5\xe4\x9d' '\x41\x8b\x95\xa2' \ - '\xce\x1d\xc4\x84' '\x21\x9c\x3f\x73' \ - '\x1c\x4c\x01\x00' '\x00\x00\x00\x00' + self.evt_bin_0 = b'\xdc\x00\xa0\x64' b'\x60\xd4\x21\x1d' \ + b'\x3f\xcf\x9f\x32' b'\x50\x0e\x64\xc9' \ + b'\xb8\x94\xe1\x47' b'\x0e\x36\x35\x1c' \ + b'\x45\x5d\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.ConfigureNotify._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.ConfigureNotify._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestConfigureRequest(unittest.TestCase): +class TestConfigureRequest(EndianTest): def setUp(self): self.evt_args_0 = { - 'sequence_number': 31377, - 'value_mask': 19345, - 'type': 156, - 'border_width': 54779, - 'x': -18191, - 'y': -17663, - 'window': 1231046739, - 'width': 51620, - 'height': 47094, - 'sibling': 1154714518, - 'stack_mode': 199, - 'parent': 176713389, + 'border_width': 52639, + 'height': 40159, + 'parent': 1499546058, + 'sequence_number': 57983, + 'sibling': 260826075, + 'stack_mode': 240, + 'type': 201, + 'value_mask': 15938, + 'width': 41545, + 'window': 1040976198, + 'x': -31823, + 'y': -880, } - self.evt_bin_0 = '\x9c\xc7\x7a\x91' '\x0a\x88\x6e\xad' \ - '\x49\x60\x48\x53' '\x44\xd3\x8b\x96' \ - '\xb8\xf1\xbb\x01' '\xc9\xa4\xb7\xf6' \ - '\xd5\xfb\x4b\x91' '\x00\x00\x00\x00' + self.evt_bin_0 = b'\xc9\xf0\xe2\x7f' b'\x59\x61\x41\xca' \ + b'\x3e\x0c\x09\x46' b'\x0f\x8b\xe3\xdb' \ + b'\x83\xb1\xfc\x90' b'\xa2\x49\x9c\xdf' \ + b'\xcd\x9f\x3e\x42' b'\x00\x00\x00\x00' def testPack0(self): bin = event.ConfigureRequest._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.ConfigureRequest._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestGravityNotify(unittest.TestCase): +class TestGravityNotify(EndianTest): def setUp(self): self.evt_args_0 = { - 'sequence_number': 43376, - 'event': 641536677, - 'type': 192, - 'window': 51697690, - 'x': -21924, - 'y': -4866, + 'event': 1182983311, + 'sequence_number': 20621, + 'type': 168, + 'window': 29431224, + 'x': -14672, + 'y': -19399, } - self.evt_bin_0 = '\xc0\x00\xa9\x70' '\x26\x3d\x12\xa5' \ - '\x03\x14\xd8\x1a' '\xaa\x5c\xec\xfe' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.evt_bin_0 = b'\xa8\x00\x50\x8d' b'\x46\x82\xe4\x8f' \ + b'\x01\xc1\x15\xb8' b'\xc6\xb0\xb4\x39' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.GravityNotify._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.GravityNotify._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestResizeRequest(unittest.TestCase): +class TestResizeRequest(EndianTest): def setUp(self): self.evt_args_0 = { - 'height': 59752, - 'sequence_number': 21348, - 'type': 149, - 'window': 1698104652, - 'width': 41494, + 'height': 60085, + 'sequence_number': 14981, + 'type': 151, + 'width': 55398, + 'window': 2130921516, } - self.evt_bin_0 = '\x95\x00\x53\x64' '\x65\x37\x05\x4c' \ - '\xa2\x16\xe9\x68' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.evt_bin_0 = b'\x97\x00\x3a\x85' b'\x7f\x03\x48\x2c' \ + b'\xd8\x66\xea\xb5' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.ResizeRequest._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.ResizeRequest._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestPropertyNotify(unittest.TestCase): +class TestPropertyNotify(EndianTest): def setUp(self): self.evt_args_0 = { - 'atom': 762586168, - 'sequence_number': 29670, - 'time': 1791118117, - 'type': 188, - 'state': 181, - 'window': 334365400, + 'atom': 252322161, + 'sequence_number': 30497, + 'state': 167, + 'time': 1391011497, + 'type': 157, + 'window': 2033863003, } - self.evt_bin_0 = '\xbc\x00\x73\xe6' '\x13\xee\x02\xd8' \ - '\x2d\x74\x24\x38' '\x6a\xc2\x4b\x25' \ - '\xb5\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.evt_bin_0 = b'\x9d\x00\x77\x21' b'\x79\x3a\x49\x5b' \ + b'\x0f\x0a\x21\x71' b'\x52\xe9\x26\xa9' \ + b'\xa7\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.PropertyNotify._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.PropertyNotify._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestSelectionClear(unittest.TestCase): +class TestSelectionClear(EndianTest): def setUp(self): self.evt_args_0 = { - 'time': 578079299, - 'sequence_number': 13691, - 'atom': 1385452659, - 'type': 170, - 'window': 355039782, + 'atom': 1092859866, + 'sequence_number': 61378, + 'time': 1538959461, + 'type': 255, + 'window': 626833463, } - self.evt_bin_0 = '\xaa\x00\x35\x7b' '\x22\x74\xca\x43' \ - '\x15\x29\x7a\x26' '\x52\x94\x54\x73' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.evt_bin_0 = b'\xff\x00\xef\xc2' b'\x5b\xba\xa8\x65' \ + b'\x25\x5c\xb8\x37' b'\x41\x23\xb7\xda' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.SelectionClear._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.SelectionClear._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestSelectionRequest(unittest.TestCase): +class TestSelectionRequest(EndianTest): def setUp(self): self.evt_args_0 = { - 'sequence_number': 13254, - 'type': 162, - 'property': 397160681, - 'owner': 2075837783, - 'time': 1154635674, - 'target': 1312534659, - 'selection': 1972323175, - 'requestor': 178195168, + 'owner': 1036225485, + 'property': 981007010, + 'requestor': 2105124856, + 'selection': 1014149797, + 'sequence_number': 27485, + 'target': 523473665, + 'time': 1792621552, + 'type': 197, } - self.evt_bin_0 = '\xa2\x00\x33\xc6' '\x44\xd2\x57\x9a' \ - '\x7b\xba\xc5\x57' '\x0a\x9f\x0a\xe0' \ - '\x75\x8f\x43\x67' '\x4e\x3b\xb0\x83' \ - '\x17\xac\x30\xe9' '\x00\x00\x00\x00' + self.evt_bin_0 = b'\xc5\x00\x6b\x5d' b'\x6a\xd9\x3b\xf0' \ + b'\x3d\xc3\x8b\xcd' b'\x7d\x79\xa7\xf8' \ + b'\x3c\x72\xb2\xa5' b'\x1f\x33\x93\x01' \ + b'\x3a\x78\xfa\xa2' b'\x00\x00\x00\x00' def testPack0(self): bin = event.SelectionRequest._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.SelectionRequest._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestSelectionNotify(unittest.TestCase): +class TestSelectionNotify(EndianTest): def setUp(self): self.evt_args_0 = { - 'sequence_number': 39736, - 'type': 199, - 'property': 302372755, - 'time': 882192222, - 'target': 2131462701, - 'selection': 781895626, - 'requestor': 1242076588, + 'property': 1602716574, + 'requestor': 1979762314, + 'selection': 1287219120, + 'sequence_number': 25394, + 'target': 1091504539, + 'time': 409398186, + 'type': 165, } - self.evt_bin_0 = '\xc7\x00\x9b\x38' '\x34\x95\x2f\x5e' \ - '\x4a\x08\x95\xac' '\x2e\x9a\xc7\xca' \ - '\x7f\x0b\x8a\x2d' '\x12\x05\xd7\x93' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.evt_bin_0 = b'\xa5\x00\x63\x32' b'\x18\x66\xeb\xaa' \ + b'\x76\x00\xc6\x8a' b'\x4c\xb9\x67\xb0' \ + b'\x41\x0f\x09\x9b' b'\x5f\x87\x83\x9e' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.SelectionNotify._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.SelectionNotify._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestColormapNotify(unittest.TestCase): +class TestColormapNotify(EndianTest): def setUp(self): self.evt_args_0 = { - 'state': 209, - 'sequence_number': 62902, - 'colormap': 300799750, - 'type': 233, - 'window': 1591667531, + 'colormap': 593302316, 'new': 1, + 'sequence_number': 56880, + 'state': 215, + 'type': 162, + 'window': 149981547, } - self.evt_bin_0 = '\xe9\x00\xf5\xb6' '\x5e\xde\xeb\x4b' \ - '\x11\xed\xd7\x06' '\x01\xd1\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.evt_bin_0 = b'\xa2\x00\xde\x30' b'\x08\xf0\x89\x6b' \ + b'\x23\x5d\x13\x2c' b'\x01\xd7\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.ColormapNotify._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.ColormapNotify._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestClientMessage(unittest.TestCase): +class TestClientMessage(EndianTest): def setUp(self): self.evt_args_0 = { - 'sequence_number': 48712, - 'data': (8, '01234567890123456789'), - 'type': 245, - 'client_type': 1340394836, - 'window': 1256861040, + 'client_type': 607457628, + 'data': (8, b'01234567890123456789'), + 'sequence_number': 54031, + 'type': 196, + 'window': 5574388, } - self.evt_bin_0 = '\xf5\x08\xbe\x48' '\x4a\xea\x2d\x70' \ - '\x4f\xe4\xcd\x54' '\x30\x31\x32\x33' \ - '\x34\x35\x36\x37' '\x38\x39\x30\x31' \ - '\x32\x33\x34\x35' '\x36\x37\x38\x39' + self.evt_bin_0 = b'\xc4\x08\xd3\x0f' b'\x00\x55\x0e\xf4' \ + b'\x24\x35\x11\x5c' b'\x30\x31\x32\x33' \ + b'\x34\x35\x36\x37' b'\x38\x39\x30\x31' \ + b'\x32\x33\x34\x35' b'\x36\x37\x38\x39' self.evt_args_1 = { - 'sequence_number': 62804, + 'client_type': 1245441508, 'data': (16, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), - 'type': 250, - 'client_type': 214585025, - 'window': 151327338, + 'sequence_number': 55140, + 'type': 204, + 'window': 1260504694, } - self.evt_bin_1 = '\xfa\x10\xf5\x54' '\x09\x05\x12\x6a' \ - '\x0c\xca\x4e\xc1' '\x00\x01\x00\x02' \ - '\x00\x03\x00\x04' '\x00\x05\x00\x06' \ - '\x00\x07\x00\x08' '\x00\x09\x00\x0a' + self.evt_bin_1 = b'\xcc\x10\xd7\x64' b'\x4b\x21\xc6\x76' \ + b'\x4a\x3b\xed\xe4' b'\x00\x01\x00\x02' \ + b'\x00\x03\x00\x04' b'\x00\x05\x00\x06' \ + b'\x00\x07\x00\x08' b'\x00\x09\x00\x0a' self.evt_args_2 = { - 'sequence_number': 3122, + 'client_type': 959018764, 'data': (32, [1, 2, 3, 4, 5]), - 'type': 243, - 'client_type': 698151018, - 'window': 725159371, + 'sequence_number': 56961, + 'type': 253, + 'window': 319171761, } - self.evt_bin_2 = '\xf3\x20\x0c\x32' '\x2b\x39\x0d\xcb' \ - '\x29\x9c\xf0\x6a' '\x00\x00\x00\x01' \ - '\x00\x00\x00\x02' '\x00\x00\x00\x03' \ - '\x00\x00\x00\x04' '\x00\x00\x00\x05' + self.evt_bin_2 = b'\xfd\x20\xde\x81' b'\x13\x06\x2c\xb1' \ + b'\x39\x29\x77\x0c' b'\x00\x00\x00\x01' \ + b'\x00\x00\x00\x02' b'\x00\x00\x00\x03' \ + b'\x00\x00\x00\x04' b'\x00\x00\x00\x05' def testPack0(self): bin = event.ClientMessage._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.ClientMessage._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) def testPack1(self): bin = event.ClientMessage._fields.to_binary(*(), **self.evt_args_1) - try: - assert bin == self.evt_bin_1 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_1) def testUnpack1(self): args, remain = event.ClientMessage._fields.parse_binary(self.evt_bin_1, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_1 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_1) def testPack2(self): bin = event.ClientMessage._fields.to_binary(*(), **self.evt_args_2) - try: - assert bin == self.evt_bin_2 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_2) def testUnpack2(self): args, remain = event.ClientMessage._fields.parse_binary(self.evt_bin_2, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_2 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_2) -class TestMappingNotify(unittest.TestCase): +class TestMappingNotify(EndianTest): def setUp(self): self.evt_args_0 = { - 'sequence_number': 53541, - 'count': 151, - 'request': 141, - 'type': 252, - 'first_keycode': 218, + 'count': 244, + 'first_keycode': 224, + 'request': 213, + 'sequence_number': 22874, + 'type': 251, } - self.evt_bin_0 = '\xfc\x00\xd1\x25' '\x8d\xda\x97\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.evt_bin_0 = b'\xfb\x00\x59\x5a' b'\xd5\xe0\xf4\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.MappingNotify._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.MappingNotify._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) if __name__ == "__main__": - check_endian() unittest.main() diff --git a/test/test_events_le.py b/test/test_events_le.py index 63101028..1e5dbfd3 100755 --- a/test/test_events_le.py +++ b/test/test_events_le.py @@ -1,893 +1,624 @@ -#!/usr/bin/env python +#!/usr/bin/env python2 import sys, os -sys.path.append(os.path.join(os.path.dirname(__file__), '..')) +sys.path.insert(0, os.path.normpath(os.path.join(__file__, '../..'))) import unittest -from Xlib.protocol import request, rq, event -import Xlib.protocol.event +from Xlib.protocol import request, event +from . import LittleEndianTest as EndianTest +from . import DummyDisplay -import struct -import array - -if sys.version_info[0] >= 3: - def _ordb(i): - """Integer representation of a byte indexed from a byte string - Py3""" - return i -else: - def _ordb(c): - """Integer representation of a byte indexed from a byte string - Py2""" - return ord(c) - -class CmpArray(object): - def __init__(self, *args, **kws): - self.array = array.array(*args, **kws) - - def __len__(self): - return len(self.array) - - def __getitem__(self, key): - if isinstance(key, slice): - x = key.start - y = key.stop - return list(self.array[x:y]) - else: - return self.array[key] - - def __getattr__(self, attr): - return getattr(self.array, attr) - - def __cmp__(self, other): - return cmp(self.array.tolist(), other) - -rq.array = CmpArray - -def tohex(bin): - bin = ''.join(map(lambda c: '\\x%02x' % _ordb(c), bin)) - - bins = [] - for i in range(0, len(bin), 16): - bins.append(bin[i:i+16]) - - bins2 = [] - for i in range(0, len(bins), 2): - try: - bins2.append("'%s' '%s'" % (bins[i], bins[i + 1])) - except IndexError: - bins2.append("'%s'" % bins[i]) - - return ' \\\n '.join(bins2) - -class DummyDisplay: - def get_resource_class(self, x): - return None - - event_classes = Xlib.protocol.event.event_class dummy_display = DummyDisplay() -def check_endian(): - if struct.unpack('BB', struct.pack('H', 0x0100))[0] != 0: - sys.stderr.write('Little-endian tests, skipping on this system.\n') - sys.exit(0) - - - -class TestKeymapNotify(unittest.TestCase): +class TestKeymapNotify(EndianTest): def setUp(self): self.evt_args_0 = { - 'type': 173, - 'data': [130, 181, 177, 244, 167, 144, 216, 185, 228, 220, 254, 130, 239, 213, 142, 240, 233, 248, 161, 238, 160, 205, 212, 205, 166, 156, 241, 169, 198, 147, 144], + 'data': [248, 202, 136, 187, 201, 200, 244, 146, 187, 195, 178, 236, 157, 185, 166, 196, 164, 146, 143, 170, 206, 201, 240, 159, 247, 205, 231, 197, 254, 240, 148], + 'type': 138, } - self.evt_bin_0 = b'\xad\x82\xb5\xb1' b'\xf4\xa7\x90\xd8' \ - b'\xb9\xe4\xdc\xfe' b'\x82\xef\xd5\x8e' \ - b'\xf0\xe9\xf8\xa1' b'\xee\xa0\xcd\xd4' \ - b'\xcd\xa6\x9c\xf1' b'\xa9\xc6\x93\x90' + self.evt_bin_0 = b'\x8a\xf8\xca\x88' b'\xbb\xc9\xc8\xf4' \ + b'\x92\xbb\xc3\xb2' b'\xec\x9d\xb9\xa6' \ + b'\xc4\xa4\x92\x8f' b'\xaa\xce\xc9\xf0' \ + b'\x9f\xf7\xcd\xe7' b'\xc5\xfe\xf0\x94' def testPack0(self): bin = event.KeymapNotify._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.KeymapNotify._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestExpose(unittest.TestCase): +class TestExpose(EndianTest): def setUp(self): self.evt_args_0 = { - 'count': 31063, - 'width': 57024, - 'window': 1993119152, - 'y': 29154, - 'x': 15652, - 'type': 192, - 'sequence_number': 45668, - 'height': 29709, + 'count': 15258, + 'height': 6241, + 'sequence_number': 48394, + 'type': 238, + 'width': 1951, + 'window': 692245859, + 'x': 39820, + 'y': 16664, } - self.evt_bin_0 = b'\xc0\x00\x64\xb2' b'\xb0\x95\xcc\x76' \ - b'\x24\x3d\xe2\x71' b'\xc0\xde\x0d\x74' \ - b'\x57\x79\x00\x00' b'\x00\x00\x00\x00' \ + self.evt_bin_0 = b'\xee\x00\x0a\xbd' b'\x63\xd5\x42\x29' \ + b'\x8c\x9b\x18\x41' b'\x9f\x07\x61\x18' \ + b'\x9a\x3b\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.Expose._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.Expose._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestGraphicsExpose(unittest.TestCase): +class TestGraphicsExpose(EndianTest): def setUp(self): self.evt_args_0 = { - 'count': 7002, - 'width': 21650, - 'major_event': 238, - 'minor_event': 44368, - 'y': 2412, - 'x': 50041, - 'drawable': 950531249, - 'type': 138, - 'sequence_number': 9516, - 'height': 10465, + 'count': 49818, + 'drawable': 1443779242, + 'height': 2892, + 'major_event': 172, + 'minor_event': 50267, + 'sequence_number': 50375, + 'type': 133, + 'width': 38020, + 'x': 54088, + 'y': 17918, } - self.evt_bin_0 = b'\x8a\x00\x2c\x25' b'\xb1\xf4\xa7\x38' \ - b'\x79\xc3\x6c\x09' b'\x92\x54\xe1\x28' \ - b'\x50\xad\x5a\x1b' b'\xee\x00\x00\x00' \ + self.evt_bin_0 = b'\x85\x00\xc7\xc4' b'\xaa\x52\x0e\x56' \ + b'\x48\xd3\xfe\x45' b'\x84\x94\x4c\x0b' \ + b'\x5b\xc4\x9a\xc2' b'\xac\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.GraphicsExpose._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.GraphicsExpose._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestNoExpose(unittest.TestCase): +class TestNoExpose(EndianTest): def setUp(self): self.evt_args_0 = { - 'minor_event': 49058, - 'window': 1389793826, - 'type': 198, - 'major_event': 149, - 'sequence_number': 51301, + 'major_event': 199, + 'minor_event': 29237, + 'sequence_number': 34266, + 'type': 248, + 'window': 1399171519, } - self.evt_bin_0 = b'\xc6\x00\x65\xc8' b'\x22\x92\xd6\x52' \ - b'\xa2\xbf\x95\x00' b'\x00\x00\x00\x00' \ + self.evt_bin_0 = b'\xf8\x00\xda\x85' b'\xbf\xa9\x65\x53' \ + b'\x35\x72\xc7\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.NoExpose._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.NoExpose._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestVisibilityNotify(unittest.TestCase): +class TestVisibilityNotify(EndianTest): def setUp(self): self.evt_args_0 = { - 'window': 848538738, - 'type': 233, - 'state': 239, - 'sequence_number': 38248, + 'sequence_number': 38616, + 'state': 253, + 'type': 174, + 'window': 936121409, } - self.evt_bin_0 = b'\xe9\x00\x68\x95' b'\x72\xac\x93\x32' \ - b'\xef\x00\x00\x00' b'\x00\x00\x00\x00' \ + self.evt_bin_0 = b'\xae\x00\xd8\x96' b'\x41\x14\xcc\x37' \ + b'\xfd\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.VisibilityNotify._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.VisibilityNotify._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestCreateNotify(unittest.TestCase): +class TestCreateNotify(EndianTest): def setUp(self): self.evt_args_0 = { - 'width': 24559, - 'window': 1328254552, - 'parent': 112487253, + 'border_width': 56468, + 'height': 7111, 'override': 0, - 'y': -31372, - 'x': -13676, - 'border_width': 32812, - 'type': 230, - 'sequence_number': 14268, - 'height': 8803, + 'parent': 747306217, + 'sequence_number': 31058, + 'type': 151, + 'width': 44173, + 'window': 876986399, + 'x': -21847, + 'y': -22248, } - self.evt_bin_0 = b'\xe6\x00\xbc\x37' b'\x55\x6b\xb4\x06' \ - b'\x58\x8e\x2b\x4f' b'\x94\xca\x74\x85' \ - b'\xef\x5f\x63\x22' b'\x2c\x80\x00\x00' \ + self.evt_bin_0 = b'\x97\x00\x52\x79' b'\xe9\xfc\x8a\x2c' \ + b'\x1f\xc0\x45\x34' b'\xa9\xaa\x18\xa9' \ + b'\x8d\xac\xc7\x1b' b'\x94\xdc\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.CreateNotify._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.CreateNotify._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestDestroyNotify(unittest.TestCase): +class TestDestroyNotify(EndianTest): def setUp(self): self.evt_args_0 = { - 'window': 1384567865, - 'type': 183, - 'event': 1596763581, - 'sequence_number': 37839, + 'event': 1489718405, + 'sequence_number': 27233, + 'type': 212, + 'window': 1064077163, } - self.evt_bin_0 = b'\xb7\x00\xcf\x93' b'\xbd\xad\x2c\x5f' \ - b'\x39\xd4\x86\x52' b'\x00\x00\x00\x00' \ + self.evt_bin_0 = b'\xd4\x00\x61\x6a' b'\x85\x4c\xcb\x58' \ + b'\x6b\x87\x6c\x3f' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.DestroyNotify._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.DestroyNotify._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestUnmapNotify(unittest.TestCase): +class TestUnmapNotify(EndianTest): def setUp(self): self.evt_args_0 = { - 'window': 1267184116, - 'type': 192, - 'event': 913541146, - 'sequence_number': 55135, + 'event': 2029853215, 'from_configure': 0, + 'sequence_number': 43679, + 'type': 201, + 'window': 860030193, } - self.evt_bin_0 = b'\xc0\x00\x5f\xd7' b'\x1a\x88\x73\x36' \ - b'\xf4\xb1\x87\x4b' b'\x00\x00\x00\x00' \ + self.evt_bin_0 = b'\xc9\x00\x9f\xaa' b'\x1f\x1a\xfd\x78' \ + b'\xf1\x04\x43\x33' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.UnmapNotify._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.UnmapNotify._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestMapNotify(unittest.TestCase): +class TestMapNotify(EndianTest): def setUp(self): self.evt_args_0 = { - 'override': 0, - 'window': 2002432488, - 'type': 216, - 'event': 1566597012, - 'sequence_number': 8920, + 'event': 675485985, + 'override': 1, + 'sequence_number': 6027, + 'type': 244, + 'window': 542087937, } - self.evt_bin_0 = b'\xd8\x00\xd8\x22' b'\x94\x5f\x60\x5d' \ - b'\xe8\xb1\x5a\x77' b'\x00\x00\x00\x00' \ + self.evt_bin_0 = b'\xf4\x00\x8b\x17' b'\x21\x19\x43\x28' \ + b'\x01\x9b\x4f\x20' b'\x01\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.MapNotify._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.MapNotify._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestMapRequest(unittest.TestCase): +class TestMapRequest(EndianTest): def setUp(self): self.evt_args_0 = { - 'window': 1740270413, - 'type': 242, - 'parent': 1188866605, - 'sequence_number': 6729, + 'parent': 1659099581, + 'sequence_number': 63838, + 'type': 157, + 'window': 868024861, } - self.evt_bin_0 = b'\xf2\x00\x49\x1a' b'\x2d\xaa\xdc\x46' \ - b'\x4d\x6b\xba\x67' b'\x00\x00\x00\x00' \ + self.evt_bin_0 = b'\x9d\x00\x5e\xf9' b'\xbd\xd9\xe3\x62' \ + b'\x1d\x02\xbd\x33' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.MapRequest._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.MapRequest._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestReparentNotify(unittest.TestCase): +class TestReparentNotify(EndianTest): def setUp(self): self.evt_args_0 = { + 'event': 1867017989, 'override': 0, - 'window': 918878719, - 'parent': 1046822430, - 'y': -10755, - 'x': -11814, - 'type': 185, - 'event': 1344092894, - 'sequence_number': 31034, + 'parent': 992152190, + 'sequence_number': 43356, + 'type': 128, + 'window': 1165276406, + 'x': -19227, + 'y': -30992, } - self.evt_bin_0 = b'\xb9\x00\x3a\x79' b'\xde\x3a\x1d\x50' \ - b'\xff\xf9\xc4\x36' b'\x1e\x3e\x65\x3e' \ - b'\xda\xd1\xfd\xd5' b'\x00\x00\x00\x00' \ + self.evt_bin_0 = b'\x80\x00\x5c\xa9' b'\x05\x6f\x48\x6f' \ + b'\xf6\xb4\x74\x45' b'\x7e\x0a\x23\x3b' \ + b'\xe5\xb4\xf0\x86' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.ReparentNotify._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.ReparentNotify._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestConfigureNotify(unittest.TestCase): +class TestConfigureNotify(EndianTest): def setUp(self): self.evt_args_0 = { - 'y': -32583, - 'above_sibling': 1143940649, - 'height': 44365, - 'width': 24191, - 'window': 1699527401, - 'override': 1, - 'x': -23713, - 'border_width': 51797, - 'type': 191, - 'event': 2102634753, - 'sequence_number': 21818, + 'above_sibling': 1343120585, + 'border_width': 17757, + 'event': 1624514845, + 'height': 13596, + 'override': 0, + 'sequence_number': 41060, + 'type': 220, + 'width': 3638, + 'window': 1070571314, + 'x': -18284, + 'y': -7865, } - self.evt_bin_0 = b'\xbf\x00\x3a\x55' b'\x01\xa9\x53\x7d' \ - b'\xe9\xba\x4c\x65' b'\x29\x26\x2f\x44' \ - b'\x5f\xa3\xb9\x80' b'\x7f\x5e\x4d\xad' \ - b'\x55\xca\x01\x00' b'\x00\x00\x00\x00' + self.evt_bin_0 = b'\xdc\x00\x64\xa0' b'\x1d\x21\xd4\x60' \ + b'\x32\x9f\xcf\x3f' b'\xc9\x64\x0e\x50' \ + b'\x94\xb8\x47\xe1' b'\x36\x0e\x1c\x35' \ + b'\x5d\x45\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.ConfigureNotify._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.ConfigureNotify._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestConfigureRequest(unittest.TestCase): +class TestConfigureRequest(EndianTest): def setUp(self): self.evt_args_0 = { - 'parent': 1484835068, - 'width': 46666, - 'value_mask': 41755, - 'stack_mode': 155, - 'height': 27280, - 'sibling': 1153557246, - 'window': 549283037, - 'y': -1019, - 'x': -11524, - 'border_width': 41299, - 'type': 140, - 'sequence_number': 48820, + 'border_width': 52639, + 'height': 40159, + 'parent': 1499546058, + 'sequence_number': 57983, + 'sibling': 260826075, + 'stack_mode': 240, + 'type': 201, + 'value_mask': 15938, + 'width': 41545, + 'window': 1040976198, + 'x': -31823, + 'y': -880, } - self.evt_bin_0 = b'\x8c\x9b\xb4\xbe' b'\xfc\xc8\x80\x58' \ - b'\xdd\x64\xbd\x20' b'\xfe\xe2\xc1\x44' \ - b'\xfc\xd2\x05\xfc' b'\x4a\xb6\x90\x6a' \ - b'\x53\xa1\x1b\xa3' b'\x00\x00\x00\x00' + self.evt_bin_0 = b'\xc9\xf0\x7f\xe2' b'\xca\x41\x61\x59' \ + b'\x46\x09\x0c\x3e' b'\xdb\xe3\x8b\x0f' \ + b'\xb1\x83\x90\xfc' b'\x49\xa2\xdf\x9c' \ + b'\x9f\xcd\x42\x3e' b'\x00\x00\x00\x00' def testPack0(self): bin = event.ConfigureRequest._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.ConfigureRequest._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestGravityNotify(unittest.TestCase): +class TestGravityNotify(EndianTest): def setUp(self): self.evt_args_0 = { - 'window': 1471159096, - 'y': -26841, - 'x': -10882, - 'type': 191, - 'event': 860169186, - 'sequence_number': 48472, + 'event': 1182983311, + 'sequence_number': 20621, + 'type': 168, + 'window': 29431224, + 'x': -14672, + 'y': -19399, } - self.evt_bin_0 = b'\xbf\x00\x58\xbd' b'\xe2\x23\x45\x33' \ - b'\x38\x1b\xb0\x57' b'\x7e\xd5\x27\x97' \ + self.evt_bin_0 = b'\xa8\x00\x8d\x50' b'\x8f\xe4\x82\x46' \ + b'\xb8\x15\xc1\x01' b'\xb0\xc6\x39\xb4' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.GravityNotify._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.GravityNotify._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestResizeRequest(unittest.TestCase): +class TestResizeRequest(EndianTest): def setUp(self): self.evt_args_0 = { - 'width': 8842, - 'window': 995086195, - 'type': 139, - 'sequence_number': 9443, - 'height': 58942, + 'height': 60085, + 'sequence_number': 14981, + 'type': 151, + 'width': 55398, + 'window': 2130921516, } - self.evt_bin_0 = b'\x8b\x00\xe3\x24' b'\x73\xcf\x4f\x3b' \ - b'\x8a\x22\x3e\xe6' b'\x00\x00\x00\x00' \ + self.evt_bin_0 = b'\x97\x00\x85\x3a' b'\x2c\x48\x03\x7f' \ + b'\x66\xd8\xb5\xea' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.ResizeRequest._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.ResizeRequest._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestPropertyNotify(unittest.TestCase): +class TestPropertyNotify(EndianTest): def setUp(self): self.evt_args_0 = { - 'window': 1763395006, - 'time': 936540618, - 'atom': 47197280, - 'type': 205, - 'state': 241, - 'sequence_number': 47586, + 'atom': 252322161, + 'sequence_number': 30497, + 'state': 167, + 'time': 1391011497, + 'type': 157, + 'window': 2033863003, } - self.evt_bin_0 = b'\xcd\x00\xe2\xb9' b'\xbe\x45\x1b\x69' \ - b'\x60\x2c\xd0\x02' b'\xca\x79\xd2\x37' \ - b'\xf1\x00\x00\x00' b'\x00\x00\x00\x00' \ + self.evt_bin_0 = b'\x9d\x00\x21\x77' b'\x5b\x49\x3a\x79' \ + b'\x71\x21\x0a\x0f' b'\xa9\x26\xe9\x52' \ + b'\xa7\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.PropertyNotify._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.PropertyNotify._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestSelectionClear(unittest.TestCase): +class TestSelectionClear(EndianTest): def setUp(self): self.evt_args_0 = { - 'window': 336291153, - 'atom': 256452607, - 'type': 232, - 'sequence_number': 26660, - 'time': 1732839301, + 'atom': 1092859866, + 'sequence_number': 61378, + 'time': 1538959461, + 'type': 255, + 'window': 626833463, } - self.evt_bin_0 = b'\xe8\x00\x24\x68' b'\x85\x07\x49\x67' \ - b'\x51\x65\x0b\x14' b'\xff\x27\x49\x0f' \ + self.evt_bin_0 = b'\xff\x00\xc2\xef' b'\x65\xa8\xba\x5b' \ + b'\x37\xb8\x5c\x25' b'\xda\xb7\x23\x41' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.SelectionClear._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.SelectionClear._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestSelectionRequest(unittest.TestCase): +class TestSelectionRequest(EndianTest): def setUp(self): self.evt_args_0 = { - 'requestor': 264947265, - 'selection': 1535909824, - 'target': 607705863, - 'time': 1423586793, - 'owner': 764886771, - 'property': 1148098854, - 'type': 147, - 'sequence_number': 20571, + 'owner': 1036225485, + 'property': 981007010, + 'requestor': 2105124856, + 'selection': 1014149797, + 'sequence_number': 27485, + 'target': 523473665, + 'time': 1792621552, + 'type': 197, } - self.evt_bin_0 = b'\x93\x00\x5b\x50' b'\xe9\x35\xda\x54' \ - b'\xf3\x3e\x97\x2d' b'\x41\xc6\xca\x0f' \ - b'\xc0\x1f\x8c\x5b' b'\x07\xdb\x38\x24' \ - b'\x26\x99\x6e\x44' b'\x00\x00\x00\x00' + self.evt_bin_0 = b'\xc5\x00\x5d\x6b' b'\xf0\x3b\xd9\x6a' \ + b'\xcd\x8b\xc3\x3d' b'\xf8\xa7\x79\x7d' \ + b'\xa5\xb2\x72\x3c' b'\x01\x93\x33\x1f' \ + b'\xa2\xfa\x78\x3a' b'\x00\x00\x00\x00' def testPack0(self): bin = event.SelectionRequest._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.SelectionRequest._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestSelectionNotify(unittest.TestCase): +class TestSelectionNotify(EndianTest): def setUp(self): self.evt_args_0 = { - 'requestor': 971528625, - 'selection': 327380230, - 'target': 1874329297, - 'time': 1022248107, - 'property': 1791820478, - 'type': 133, - 'sequence_number': 30741, + 'property': 1602716574, + 'requestor': 1979762314, + 'selection': 1287219120, + 'sequence_number': 25394, + 'target': 1091504539, + 'time': 409398186, + 'type': 165, } - self.evt_bin_0 = b'\x85\x00\x15\x78' b'\xab\x44\xee\x3c' \ - b'\xb1\x59\xe8\x39' b'\x06\x6d\x83\x13' \ - b'\xd1\xfe\xb7\x6f' b'\xbe\x02\xcd\x6a' \ + self.evt_bin_0 = b'\xa5\x00\x32\x63' b'\xaa\xeb\x66\x18' \ + b'\x8a\xc6\x00\x76' b'\xb0\x67\xb9\x4c' \ + b'\x9b\x09\x0f\x41' b'\x9e\x83\x87\x5f' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.SelectionNotify._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.SelectionNotify._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestColormapNotify(unittest.TestCase): +class TestColormapNotify(EndianTest): def setUp(self): self.evt_args_0 = { - 'window': 1353796539, - 'colormap': 659729309, + 'colormap': 593302316, 'new': 1, - 'type': 211, - 'state': 168, - 'sequence_number': 8684, + 'sequence_number': 56880, + 'state': 215, + 'type': 162, + 'window': 149981547, } - self.evt_bin_0 = b'\xd3\x00\xec\x21' b'\xbb\x4b\xb1\x50' \ - b'\x9d\xab\x52\x27' b'\x01\xa8\x00\x00' \ + self.evt_bin_0 = b'\xa2\x00\x30\xde' b'\x6b\x89\xf0\x08' \ + b'\x2c\x13\x5d\x23' b'\x01\xd7\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPack0(self): bin = event.ColormapNotify._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.ColormapNotify._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) -class TestClientMessage(unittest.TestCase): +class TestClientMessage(EndianTest): def setUp(self): self.evt_args_0 = { - 'type': 237, - 'window': 1804643202, - 'client_type': 455293257, - 'data': (8, '01234567890123456789'), - 'sequence_number': 14854, + 'client_type': 607457628, + 'data': (8, b'01234567890123456789'), + 'sequence_number': 54031, + 'type': 196, + 'window': 5574388, } - self.evt_bin_0 = b'\xed\x08\x06\x3a' b'\x82\xab\x90\x6b' \ - b'\x49\x39\x23\x1b' b'\x30\x31\x32\x33' \ + self.evt_bin_0 = b'\xc4\x08\x0f\xd3' b'\xf4\x0e\x55\x00' \ + b'\x5c\x11\x35\x24' b'\x30\x31\x32\x33' \ b'\x34\x35\x36\x37' b'\x38\x39\x30\x31' \ b'\x32\x33\x34\x35' b'\x36\x37\x38\x39' self.evt_args_1 = { - 'type': 160, - 'window': 948875838, - 'client_type': 212297388, + 'client_type': 1245441508, 'data': (16, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), - 'sequence_number': 28171, + 'sequence_number': 55140, + 'type': 204, + 'window': 1260504694, } - self.evt_bin_1 = b'\xa0\x10\x0b\x6e' b'\x3e\xb2\x8e\x38' \ - b'\xac\x66\xa7\x0c' b'\x01\x00\x02\x00' \ + self.evt_bin_1 = b'\xcc\x10\x64\xd7' b'\x76\xc6\x21\x4b' \ + b'\xe4\xed\x3b\x4a' b'\x01\x00\x02\x00' \ b'\x03\x00\x04\x00' b'\x05\x00\x06\x00' \ b'\x07\x00\x08\x00' b'\x09\x00\x0a\x00' self.evt_args_2 = { - 'type': 243, - 'window': 581929030, - 'client_type': 966878718, + 'client_type': 959018764, 'data': (32, [1, 2, 3, 4, 5]), - 'sequence_number': 63569, + 'sequence_number': 56961, + 'type': 253, + 'window': 319171761, } - self.evt_bin_2 = b'\xf3\x20\x51\xf8' b'\x46\x88\xaf\x22' \ - b'\xfe\x65\xa1\x39' b'\x01\x00\x00\x00' \ + self.evt_bin_2 = b'\xfd\x20\x81\xde' b'\xb1\x2c\x06\x13' \ + b'\x0c\x77\x29\x39' b'\x01\x00\x00\x00' \ b'\x02\x00\x00\x00' b'\x03\x00\x00\x00' \ b'\x04\x00\x00\x00' b'\x05\x00\x00\x00' def testPack0(self): bin = event.ClientMessage._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.ClientMessage._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) def testPack1(self): bin = event.ClientMessage._fields.to_binary(*(), **self.evt_args_1) - try: - assert bin == self.evt_bin_1 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_1) def testUnpack1(self): args, remain = event.ClientMessage._fields.parse_binary(self.evt_bin_1, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_1 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_1) def testPack2(self): bin = event.ClientMessage._fields.to_binary(*(), **self.evt_args_2) - try: - assert bin == self.evt_bin_2 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_2) def testUnpack2(self): args, remain = event.ClientMessage._fields.parse_binary(self.evt_bin_2, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_2 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_2) -class TestMappingNotify(unittest.TestCase): +class TestMappingNotify(EndianTest): def setUp(self): self.evt_args_0 = { - 'first_keycode': 246, - 'request': 189, - 'type': 198, - 'count': 201, - 'sequence_number': 32665, + 'count': 244, + 'first_keycode': 224, + 'request': 213, + 'sequence_number': 22874, + 'type': 251, } - self.evt_bin_0 = b'\xc6\x00\x99\x7f' b'\xbd\xf6\xc9\x00' \ + self.evt_bin_0 = b'\xfb\x00\x5a\x59' b'\xd5\xe0\xf4\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' @@ -895,23 +626,13 @@ def setUp(self): def testPack0(self): bin = event.MappingNotify._fields.to_binary(*(), **self.evt_args_0) - try: - assert bin == self.evt_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.evt_bin_0) def testUnpack0(self): args, remain = event.MappingNotify._fields.parse_binary(self.evt_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.evt_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.evt_args_0) if __name__ == "__main__": - check_endian() unittest.main() diff --git a/test/test_manual.py b/test/test_manual.py old mode 100755 new mode 100644 diff --git a/test/test_rdb.py b/test/test_rdb.py old mode 100755 new mode 100644 diff --git a/test/test_requests_be.py b/test/test_requests_be.py old mode 100644 new mode 100755 index c67074b0..0ffdc67a --- a/test/test_requests_be.py +++ b/test/test_requests_be.py @@ -1,5601 +1,3936 @@ -#!/usr/bin/env python +#!/usr/bin/env python2 import sys, os -sys.path.append(os.path.join(os.path.dirname(__file__), '..')) +sys.path.insert(0, os.path.normpath(os.path.join(__file__, '../..'))) import unittest -from Xlib.protocol import request, rq, event -import Xlib.protocol.event +from Xlib.protocol import request, event +from . import BigEndianTest as EndianTest +from . import DummyDisplay -import struct -import array - -class CmpArray(object): - def __init__(self, *args, **kws): - self.array = array.array(*args, **kws) - - def __len__(self): - return len(self.array) - - def __getitem__(self, key): - if isinstance(key, slice): - x = key.start - y = key.stop - return list(self.array[x:y]) - else: - return self.array[key] - - def __getattr__(self, attr): - return getattr(self.array, attr) - - def __cmp__(self, other): - return cmp(self.array.tolist(), other) - -rq.array = CmpArray - -def tohex(bin): - bin = ''.join(map(lambda c: '\\x%02x' % ord(c), bin)) - - bins = [] - for i in range(0, len(bin), 16): - bins.append(bin[i:i+16]) - - bins2 = [] - for i in range(0, len(bins), 2): - try: - bins2.append("'%s' '%s'" % (bins[i], bins[i + 1])) - except IndexError: - bins2.append("'%s'" % bins[i]) - - return ' \\\n '.join(bins2) - -class DummyDisplay: - def get_resource_class(self, x): - return None - - event_classes = Xlib.protocol.event.event_class dummy_display = DummyDisplay() -def check_endian(): - if struct.unpack('BB', struct.pack('H', 0x0100))[0] != 1: - sys.stderr.write('Big-endian tests, skipping on this system.\n') - sys.exit(0) - - - -class TestCreateWindow(unittest.TestCase): +class TestCreateWindow(EndianTest): def setUp(self): self.req_args_0 = { - 'height': 38608, - 'window_class': 0, - 'border_width': 34451, - 'visual': 398069779, - 'x': -20771, - 'y': -4049, - 'parent': 1960526158, - 'attrs': {'backing_pixel': 561400151, 'cursor': 1442692293, 'background_pixmap': 1583833923, 'border_pixmap': 1992559786, 'backing_planes': 1454152605, 'win_gravity': 3, 'backing_store': 2, 'event_mask': 368242204, 'save_under': 0, 'background_pixel': 209127175, 'colormap': 377416705, 'border_pixel': 2135465356, 'bit_gravity': 0, 'do_not_propagate_mask': 597142897, 'override_redirect': 0}, - 'wid': 1828913444, - 'depth': 186, - 'width': 51466, - } - self.req_bin_0 = '\x01\xba\x00\x17' '\x6d\x03\x01\x24' \ - '\x74\xdb\x41\x4e' '\xae\xdd\xf0\x2f' \ - '\xc9\x0a\x96\xd0' '\x86\x93\x00\x00' \ - '\x17\xba\x10\x13' '\x00\x00\x7f\xff' \ - '\x5e\x67\x63\x43' '\x0c\x77\x07\x07' \ - '\x76\xc4\x0c\xaa' '\x7f\x48\x9d\x8c' \ - '\x00\x00\x00\x00' '\x03\x00\x00\x00' \ - '\x02\x00\x00\x00' '\x56\xac\x9b\x9d' \ - '\x21\x76\x49\x57' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x15\xf2\xee\x1c' \ - '\x23\x97\xad\x71' '\x16\x7e\xec\x01' \ - '\x55\xfd\xbc\xc5' + 'attrs': {'cursor': 64054583, 'override_redirect': 0, 'bit_gravity': 3, 'event_mask': 1268138548, 'border_pixel': 1592533117, 'background_pixel': 239147199, 'save_under': 0, 'colormap': 68318329, 'do_not_propagate_mask': 906135756, 'backing_store': 0, 'win_gravity': 2, 'backing_planes': 299720948, 'border_pixmap': 53775720, 'backing_pixel': 1581625428, 'background_pixmap': 1373224142}, + 'border_width': 13287, + 'depth': 151, + 'height': 37037, + 'parent': 499701004, + 'visual': 1395681732, + 'wid': 469587013, + 'width': 1995, + 'window_class': 2, + 'x': -16209, + 'y': -13042, + } + self.req_bin_0 = b'\x01\x97\x00\x17' b'\x1b\xfd\x54\x45' \ + b'\x1d\xc8\xd5\x0c' b'\xc0\xaf\xcd\x0e' \ + b'\x07\xcb\x90\xad' b'\x33\xe7\x00\x02' \ + b'\x53\x30\x69\xc4' b'\x00\x00\x7f\xff' \ + b'\x51\xd9\xbc\xce' b'\x0e\x41\x18\xbf' \ + b'\x03\x34\x8d\x68' b'\x5e\xec\x20\x7d' \ + b'\x03\x00\x00\x00' b'\x02\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x11\xdd\x60\xf4' \ + b'\x5e\x45\xb0\x54' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x4b\x96\x42\x34' \ + b'\x36\x02\x88\xcc' b'\x04\x12\x74\x79' \ + b'\x03\xd1\x65\x37' def testPackRequest0(self): bin = request.CreateWindow._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.CreateWindow._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestChangeWindowAttributes(unittest.TestCase): +class TestChangeWindowAttributes(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 1813552124, - 'attrs': {'backing_pixel': 59516078, 'cursor': 1682969315, 'background_pixmap': 370313360, 'border_pixmap': 1158771722, 'backing_planes': 1432315664, 'win_gravity': 3, 'backing_store': 1, 'event_mask': 1054128649, 'save_under': 0, 'background_pixel': 1953340842, 'colormap': 1462101672, 'border_pixel': 287436510, 'bit_gravity': 10, 'do_not_propagate_mask': 1283834625, 'override_redirect': 0}, + 'attrs': {'cursor': 596789700, 'override_redirect': 0, 'bit_gravity': 6, 'event_mask': 1499308477, 'border_pixel': 473458160, 'background_pixel': 1170318459, 'save_under': 0, 'colormap': 730747963, 'do_not_propagate_mask': 907623048, 'backing_store': 1, 'win_gravity': 8, 'backing_planes': 1738304197, 'border_pixmap': 900977490, 'backing_pixel': 1866873765, 'background_pixmap': 1506149446}, + 'window': 333955224, } - self.req_bin_0 = '\x02\x00\x00\x12' '\x6c\x18\x9b\xfc' \ - '\x00\x00\x7f\xff' '\x16\x12\x88\x90' \ - '\x74\x6d\x9d\xaa' '\x45\x11\x74\x0a' \ - '\x11\x21\xee\xde' '\x0a\x00\x00\x00' \ - '\x03\x00\x00\x00' '\x01\x00\x00\x00' \ - '\x55\x5f\x67\x10' '\x03\x8c\x24\xae' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x3e\xd4\xba\x09' '\x4c\x85\xc3\x01' \ - '\x57\x25\xe6\xa8' '\x64\x50\x12\xe3' + self.req_bin_0 = b'\x02\x00\x00\x12' b'\x13\xe7\xc0\x98' \ + b'\x00\x00\x7f\xff' b'\x59\xc6\x04\x46' \ + b'\x45\xc1\xa4\x7b' b'\x35\xb3\xd3\x52' \ + b'\x1c\x38\x65\xf0' b'\x06\x00\x00\x00' \ + b'\x08\x00\x00\x00' b'\x01\x00\x00\x00' \ + b'\x67\x9c\x6a\xc5' b'\x6f\x46\x3b\xa5' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x59\x5d\xa1\xbd' b'\x36\x19\x3a\x88' \ + b'\x2b\x8e\x54\x3b' b'\x23\x92\x49\xc4' def testPackRequest0(self): bin = request.ChangeWindowAttributes._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ChangeWindowAttributes._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGetWindowAttributes(unittest.TestCase): +class TestGetWindowAttributes(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 1931593850, + 'window': 462448317, } - self.req_bin_0 = '\x03\x00\x00\x02' '\x73\x21\xc8\x7a' + self.req_bin_0 = b'\x03\x00\x00\x02' b'\x1b\x90\x66\xbd' self.reply_args_0 = { - 'sequence_number': 60057, - 'backing_pixel': 136561993, - 'your_event_mask': 1332399119, + 'all_event_masks': 1980679760, + 'backing_bit_planes': 1820045833, + 'backing_pixel': 738704824, + 'backing_store': 214, + 'bit_gravity': 152, + 'colormap': 2089815718, + 'do_not_propagate_mask': 5420, 'map_is_installed': 0, - 'visual': 687387929, - 'backing_bit_planes': 990144409, - 'backing_store': 147, - 'win_class': 18284, - 'map_state': 185, - 'save_under': 0, - 'all_event_masks': 270223628, - 'colormap': 1161384334, - 'win_gravity': 157, - 'bit_gravity': 253, - 'do_not_propagate_mask': 33787, + 'map_state': 245, 'override_redirect': 0, + 'save_under': 1, + 'sequence_number': 6954, + 'visual': 199235720, + 'win_class': 25154, + 'win_gravity': 219, + 'your_event_mask': 812961929, } - self.reply_bin_0 = '\x01\x93\xea\x99' '\x00\x00\x00\x03' \ - '\x28\xf8\xb5\x19' '\x47\x6c\xfd\x9d' \ - '\x3b\x04\x67\x99' '\x08\x23\xc5\x49' \ - '\x00\x00\xb9\x00' '\x45\x39\x51\x8e' \ - '\x10\x1b\x49\x0c' '\x4f\x6a\xcc\x0f' \ - '\x83\xfb\x00\x00' + self.reply_bin_0 = b'\x01\xd6\x1b\x2a' b'\x00\x00\x00\x03' \ + b'\x0b\xe0\x18\x88' b'\x62\x42\x98\xdb' \ + b'\x6c\x7b\xb2\x09' b'\x2c\x07\xbd\xb8' \ + b'\x01\x00\xf5\x00' b'\x7c\x90\x0e\xa6' \ + b'\x76\x0e\xc6\x50' b'\x30\x74\xd0\x89' \ + b'\x15\x2c\x00\x00' def testPackRequest0(self): bin = request.GetWindowAttributes._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetWindowAttributes._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetWindowAttributes._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetWindowAttributes._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestDestroyWindow(unittest.TestCase): +class TestDestroyWindow(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 1622184267, + 'window': 1185563768, } - self.req_bin_0 = '\x04\x00\x00\x02' '\x60\xb0\x91\x4b' + self.req_bin_0 = b'\x04\x00\x00\x02' b'\x46\xaa\x44\x78' def testPackRequest0(self): bin = request.DestroyWindow._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.DestroyWindow._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestDestroySubWindows(unittest.TestCase): +class TestDestroySubWindows(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 1000376476, + 'window': 629661088, } - self.req_bin_0 = '\x05\x00\x00\x02' '\x3b\xa0\x88\x9c' + self.req_bin_0 = b'\x05\x00\x00\x02' b'\x25\x87\xdd\xa0' def testPackRequest0(self): bin = request.DestroySubWindows._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.DestroySubWindows._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestChangeSaveSet(unittest.TestCase): +class TestChangeSaveSet(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 1577523459, - 'mode': 0, + 'mode': 1, + 'window': 1239919839, } - self.req_bin_0 = '\x06\x00\x00\x02' '\x5e\x07\x19\x03' + self.req_bin_0 = b'\x06\x01\x00\x02' b'\x49\xe7\xac\xdf' def testPackRequest0(self): bin = request.ChangeSaveSet._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ChangeSaveSet._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestReparentWindow(unittest.TestCase): +class TestReparentWindow(EndianTest): def setUp(self): self.req_args_0 = { - 'parent': 72188776, - 'window': 1300734112, - 'x': -5207, - 'y': -22675, + 'parent': 1513122040, + 'window': 413002134, + 'x': -30489, + 'y': -31267, } - self.req_bin_0 = '\x07\x00\x00\x04' '\x4d\x87\xa0\xa0' \ - '\x04\x4d\x83\x68' '\xeb\xa9\xa7\x6d' + self.req_bin_0 = b'\x07\x00\x00\x04' b'\x18\x9d\xe9\x96' \ + b'\x5a\x30\x68\xf8' b'\x88\xe7\x85\xdd' def testPackRequest0(self): bin = request.ReparentWindow._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ReparentWindow._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestMapWindow(unittest.TestCase): +class TestMapWindow(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 61469476, + 'window': 1420117708, } - self.req_bin_0 = '\x08\x00\x00\x02' '\x03\xa9\xf3\x24' + self.req_bin_0 = b'\x08\x00\x00\x02' b'\x54\xa5\x46\xcc' def testPackRequest0(self): bin = request.MapWindow._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.MapWindow._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestMapSubwindows(unittest.TestCase): +class TestMapSubwindows(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 818738118, + 'window': 489473351, } - self.req_bin_0 = '\x09\x00\x00\x02' '\x30\xcc\xf3\xc6' + self.req_bin_0 = b'\x09\x00\x00\x02' b'\x1d\x2c\xc5\x47' def testPackRequest0(self): bin = request.MapSubwindows._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.MapSubwindows._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestUnmapWindow(unittest.TestCase): +class TestUnmapWindow(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 1923663468, + 'window': 1660217157, } - self.req_bin_0 = '\x0a\x00\x00\x02' '\x72\xa8\xc6\x6c' + self.req_bin_0 = b'\x0a\x00\x00\x02' b'\x62\xf4\xe7\x45' def testPackRequest0(self): bin = request.UnmapWindow._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.UnmapWindow._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestUnmapSubwindows(unittest.TestCase): +class TestUnmapSubwindows(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 999740194, + 'window': 621521446, } - self.req_bin_0 = '\x0b\x00\x00\x02' '\x3b\x96\xd3\x22' + self.req_bin_0 = b'\x0b\x00\x00\x02' b'\x25\x0b\xaa\x26' def testPackRequest0(self): bin = request.UnmapSubwindows._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.UnmapSubwindows._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestConfigureWindow(unittest.TestCase): +class TestConfigureWindow(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 190634459, - 'attrs': {'height': 57788, 'stack_mode': 2, 'border_width': -320, 'width': 53674, 'x': -2248, 'y': -29960, 'sibling': 1012823324}, + 'attrs': {'width': 39387, 'stack_mode': 2, 'height': 57679, 'sibling': 973756745, 'y': -17512, 'x': -27539, 'border_width': -14551}, + 'window': 349362548, } - self.req_bin_0 = '\x0c\x00\x00\x0a' '\x0b\x5c\xd9\xdb' \ - '\x00\x7f\x00\x00' '\xf7\x38\x00\x00' \ - '\x8a\xf8\x00\x00' '\xd1\xaa\x00\x00' \ - '\xe1\xbc\x00\x00' '\xfe\xc0\x00\x00' \ - '\x3c\x5e\x75\x1c' '\x02\x00\x00\x00' + self.req_bin_0 = b'\x0c\x00\x00\x0a' b'\x14\xd2\xd9\x74' \ + b'\x00\x7f\x00\x00' b'\x94\x6d\x00\x00' \ + b'\xbb\x98\x00\x00' b'\x99\xdb\x00\x00' \ + b'\xe1\x4f\x00\x00' b'\xc7\x29\x00\x00' \ + b'\x3a\x0a\x59\x49' b'\x02\x00\x00\x00' def testPackRequest0(self): bin = request.ConfigureWindow._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ConfigureWindow._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestCirculateWindow(unittest.TestCase): +class TestCirculateWindow(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 1712979067, 'direction': 1, + 'window': 763003561, } - self.req_bin_0 = '\x0d\x01\x00\x02' '\x66\x19\xfc\x7b' + self.req_bin_0 = b'\x0d\x01\x00\x02' b'\x2d\x7a\x82\xa9' def testPackRequest0(self): bin = request.CirculateWindow._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.CirculateWindow._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGetGeometry(unittest.TestCase): +class TestGetGeometry(EndianTest): def setUp(self): self.req_args_0 = { - 'drawable': 680179490, + 'drawable': 449978455, } - self.req_bin_0 = '\x0e\x00\x00\x02' '\x28\x8a\xb7\x22' + self.req_bin_0 = b'\x0e\x00\x00\x02' b'\x1a\xd2\x20\x57' self.reply_args_0 = { - 'height': 64954, - 'sequence_number': 39469, - 'root': 609586545, - 'border_width': 496, - 'x': -1253, - 'y': -11180, - 'depth': 204, - 'width': 38433, + 'border_width': 41869, + 'depth': 196, + 'height': 40176, + 'root': 2011515940, + 'sequence_number': 46250, + 'width': 4935, + 'x': -10370, + 'y': -11534, } - self.reply_bin_0 = '\x01\xcc\x9a\x2d' '\x00\x00\x00\x00' \ - '\x24\x55\x8d\x71' '\xfb\x1b\xd4\x54' \ - '\x96\x21\xfd\xba' '\x01\xf0\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.reply_bin_0 = b'\x01\xc4\xb4\xaa' b'\x00\x00\x00\x00' \ + b'\x77\xe5\x4c\x24' b'\xd7\x7e\xd2\xf2' \ + b'\x13\x47\x9c\xf0' b'\xa3\x8d\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.GetGeometry._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetGeometry._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetGeometry._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetGeometry._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestQueryTree(unittest.TestCase): +class TestQueryTree(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 2052496265, + 'window': 367582976, } - self.req_bin_0 = '\x0f\x00\x00\x02' '\x7a\x56\x9b\x89' + self.req_bin_0 = b'\x0f\x00\x00\x02' b'\x15\xe8\xdf\x00' self.reply_args_0 = { - 'sequence_number': 33887, - 'children': [1795767666, 1494491557, 748301378, 729512097, 1262057849, 64238195, 1088261715], - 'root': 1856577120, - 'parent': 2105827407, + 'children': [1147122179, 1565853418, 525792997, 350969719, 992761785, 814939899, 579774073], + 'parent': 1374454548, + 'root': 1987327953, + 'sequence_number': 65105, } - self.reply_bin_0 = '\x01\x00\x84\x5f' '\x00\x00\x00\x07' \ - '\x6e\xa9\x1e\x60' '\x7d\x84\x60\x4f' \ - '\x00\x07\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x6b\x09\x3d\x72' '\x59\x14\x21\xa5' \ - '\x2c\x9a\x2c\x42' '\x2b\x7b\x78\xa1' \ - '\x4b\x39\x79\x79' '\x03\xd4\x32\x73' \ - '\x40\xdd\x8e\x53' + self.reply_bin_0 = b'\x01\x00\xfe\x51' b'\x00\x00\x00\x07' \ + b'\x76\x74\x37\xd1' b'\x51\xec\x83\x14' \ + b'\x00\x07\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x44\x5f\xb2\x03' b'\x5d\x55\x06\xea' \ + b'\x1f\x56\xf6\xe5' b'\x14\xeb\x5f\x77' \ + b'\x3b\x2c\x57\xb9' b'\x30\x92\xfe\xfb' \ + b'\x22\x8e\xa6\x79' def testPackRequest0(self): bin = request.QueryTree._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.QueryTree._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.QueryTree._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.QueryTree._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestInternAtom(unittest.TestCase): +class TestInternAtom(EndianTest): def setUp(self): self.req_args_0 = { - 'only_if_exists': 0, 'name': 'fuzzy_prop', + 'only_if_exists': 0, } - self.req_bin_0 = '\x10\x00\x00\x05' '\x00\x0a\x00\x00' \ - '\x66\x75\x7a\x7a' '\x79\x5f\x70\x72' \ - '\x6f\x70\x00\x00' + self.req_bin_0 = b'\x10\x00\x00\x05' b'\x00\x0a\x00\x00' \ + b'\x66\x75\x7a\x7a' b'\x79\x5f\x70\x72' \ + b'\x6f\x70\x00\x00' self.reply_args_0 = { - 'atom': 48723297, - 'sequence_number': 35223, + 'atom': 696457407, + 'sequence_number': 45122, } - self.reply_bin_0 = '\x01\x00\x89\x97' '\x00\x00\x00\x00' \ - '\x02\xe7\x75\x61' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.reply_bin_0 = b'\x01\x00\xb0\x42' b'\x00\x00\x00\x00' \ + b'\x29\x83\x18\xbf' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.InternAtom._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.InternAtom._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.InternAtom._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.InternAtom._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestGetAtomName(unittest.TestCase): +class TestGetAtomName(EndianTest): def setUp(self): self.req_args_0 = { - 'atom': 1022286544, + 'atom': 1810076242, } - self.req_bin_0 = '\x11\x00\x00\x02' '\x3c\xee\xda\xd0' + self.req_bin_0 = b'\x11\x00\x00\x02' b'\x6b\xe3\x92\x52' self.reply_args_0 = { - 'sequence_number': 22699, 'name': 'WM_CLASS', + 'sequence_number': 50608, } - self.reply_bin_0 = '\x01\x00\x58\xab' '\x00\x00\x00\x02' \ - '\x00\x08\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x57\x4d\x5f\x43' '\x4c\x41\x53\x53' + self.reply_bin_0 = b'\x01\x00\xc5\xb0' b'\x00\x00\x00\x02' \ + b'\x00\x08\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x57\x4d\x5f\x43' b'\x4c\x41\x53\x53' def testPackRequest0(self): bin = request.GetAtomName._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetAtomName._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetAtomName._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetAtomName._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestChangeProperty(unittest.TestCase): +class TestChangeProperty(EndianTest): def setUp(self): self.req_args_0 = { + 'data': (8, b''), 'mode': 0, - 'data': (8, ''), - 'property': 2085394193, - 'window': 266197951, - 'type': 1343008022, + 'property': 1764873173, + 'type': 69000273, + 'window': 491942524, } - self.req_bin_0 = '\x12\x00\x00\x06' '\x0f\xdd\xdb\xbf' \ - '\x7c\x4c\x97\x11' '\x50\x0c\xad\x16' \ - '\x08\x00\x00\x00' '\x00\x00\x00\x00' + self.req_bin_0 = b'\x12\x00\x00\x06' b'\x1d\x52\x72\x7c' \ + b'\x69\x31\xd3\xd5' b'\x04\x1c\xdc\x51' \ + b'\x08\x00\x00\x00' b'\x00\x00\x00\x00' self.req_args_1 = { - 'mode': 2, - 'data': (8, 'foo'), - 'property': 449719979, - 'window': 1522118044, - 'type': 121096013, + 'data': (8, b'foo'), + 'mode': 1, + 'property': 575034703, + 'type': 142204480, + 'window': 861560365, } - self.req_bin_1 = '\x12\x02\x00\x07' '\x5a\xb9\xad\x9c' \ - '\x1a\xce\x2e\xab' '\x07\x37\xc7\x4d' \ - '\x08\x00\x00\x00' '\x00\x00\x00\x03' \ - '\x66\x6f\x6f\x00' + self.req_bin_1 = b'\x12\x01\x00\x07' b'\x33\x5a\x5e\x2d' \ + b'\x22\x46\x55\x4f' b'\x08\x79\xde\x40' \ + b'\x08\x00\x00\x00' b'\x00\x00\x00\x03' \ + b'\x66\x6f\x6f\x00' self.req_args_2 = { - 'mode': 2, - 'data': (8, 'zoom'), - 'property': 1009841498, - 'window': 286324270, - 'type': 1547457396, + 'data': (8, b'zoom'), + 'mode': 0, + 'property': 2024948722, + 'type': 1218075423, + 'window': 1961010416, } - self.req_bin_2 = '\x12\x02\x00\x07' '\x11\x10\xf6\x2e' \ - '\x3c\x30\xf5\x5a' '\x5c\x3c\x53\x74' \ - '\x08\x00\x00\x00' '\x00\x00\x00\x04' \ - '\x7a\x6f\x6f\x6d' + self.req_bin_2 = b'\x12\x00\x00\x07' b'\x74\xe2\xa4\xf0' \ + b'\x78\xb2\x43\xf2' b'\x48\x9a\x5b\x1f' \ + b'\x08\x00\x00\x00' b'\x00\x00\x00\x04' \ + b'\x7a\x6f\x6f\x6d' self.req_args_3 = { - 'mode': 0, 'data': (16, []), - 'property': 426983104, - 'window': 1964921608, - 'type': 692879036, + 'mode': 2, + 'property': 456677559, + 'type': 1407609354, + 'window': 675831147, } - self.req_bin_3 = '\x12\x00\x00\x06' '\x75\x1e\x53\x08' \ - '\x19\x73\x3e\xc0' '\x29\x4c\x7e\xbc' \ - '\x10\x00\x00\x00' '\x00\x00\x00\x00' + self.req_bin_3 = b'\x12\x02\x00\x06' b'\x28\x48\x5d\x6b' \ + b'\x1b\x38\x58\xb7' b'\x53\xe6\x6a\x0a' \ + b'\x10\x00\x00\x00' b'\x00\x00\x00\x00' self.req_args_4 = { - 'mode': 0, 'data': (16, [1, 2, 3]), - 'property': 801006756, - 'window': 560040176, - 'type': 2030208993, + 'mode': 1, + 'property': 1899908134, + 'type': 1964041522, + 'window': 849678568, } - self.req_bin_4 = '\x12\x00\x00\x08' '\x21\x61\x88\xf0' \ - '\x2f\xbe\x64\xa4' '\x79\x02\x87\xe1' \ - '\x10\x00\x00\x00' '\x00\x00\x00\x03' \ - '\x00\x01\x00\x02' '\x00\x03\x00\x00' + self.req_bin_4 = b'\x12\x01\x00\x08' b'\x32\xa5\x10\xe8' \ + b'\x71\x3e\x4c\x26' b'\x75\x10\xe5\x32' \ + b'\x10\x00\x00\x00' b'\x00\x00\x00\x03' \ + b'\x00\x01\x00\x02' b'\x00\x03\x00\x00' self.req_args_5 = { - 'mode': 0, 'data': (16, [1, 2, 3, 4]), - 'property': 1401687842, - 'window': 2016421454, - 'type': 434059096, + 'mode': 2, + 'property': 306879937, + 'type': 568891375, + 'window': 985442388, } - self.req_bin_5 = '\x12\x00\x00\x08' '\x78\x30\x26\x4e' \ - '\x53\x8c\x0f\x22' '\x19\xdf\x37\x58' \ - '\x10\x00\x00\x00' '\x00\x00\x00\x04' \ - '\x00\x01\x00\x02' '\x00\x03\x00\x04' + self.req_bin_5 = b'\x12\x02\x00\x08' b'\x3a\xbc\xa8\x54' \ + b'\x12\x4a\x9d\xc1' b'\x21\xe8\x97\xef' \ + b'\x10\x00\x00\x00' b'\x00\x00\x00\x04' \ + b'\x00\x01\x00\x02' b'\x00\x03\x00\x04' self.req_args_6 = { - 'mode': 2, 'data': (32, []), - 'property': 1008934075, - 'window': 461926013, - 'type': 613217208, + 'mode': 0, + 'property': 1599917196, + 'type': 1205594429, + 'window': 529694076, } - self.req_bin_6 = '\x12\x02\x00\x06' '\x1b\x88\x6e\x7d' \ - '\x3c\x23\x1c\xbb' '\x24\x8c\xf3\xb8' \ - '\x20\x00\x00\x00' '\x00\x00\x00\x00' + self.req_bin_6 = b'\x12\x00\x00\x06' b'\x1f\x92\x7d\x7c' \ + b'\x5f\x5c\xcc\x8c' b'\x47\xdb\xe9\x3d' \ + b'\x20\x00\x00\x00' b'\x00\x00\x00\x00' self.req_args_7 = { - 'mode': 1, 'data': (32, [1, 2, 3]), - 'property': 1472503640, - 'window': 367636986, - 'type': 1085552939, + 'mode': 2, + 'property': 1604265475, + 'type': 1255454396, + 'window': 564298846, } - self.req_bin_7 = '\x12\x01\x00\x09' '\x15\xe9\xb1\xfa' \ - '\x57\xc4\x9f\x58' '\x40\xb4\x39\x2b' \ - '\x20\x00\x00\x00' '\x00\x00\x00\x03' \ - '\x00\x00\x00\x01' '\x00\x00\x00\x02' \ - '\x00\x00\x00\x03' + self.req_bin_7 = b'\x12\x02\x00\x09' b'\x21\xa2\x84\x5e' \ + b'\x5f\x9f\x26\x03' b'\x4a\xd4\xb6\xbc' \ + b'\x20\x00\x00\x00' b'\x00\x00\x00\x03' \ + b'\x00\x00\x00\x01' b'\x00\x00\x00\x02' \ + b'\x00\x00\x00\x03' def testPackRequest0(self): bin = request.ChangeProperty._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ChangeProperty._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackRequest1(self): bin = request.ChangeProperty._request.to_binary(*(), **self.req_args_1) - try: - assert bin == self.req_bin_1 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_1) def testUnpackRequest1(self): args, remain = request.ChangeProperty._request.parse_binary(self.req_bin_1, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_1 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_1) def testPackRequest2(self): bin = request.ChangeProperty._request.to_binary(*(), **self.req_args_2) - try: - assert bin == self.req_bin_2 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_2) def testUnpackRequest2(self): args, remain = request.ChangeProperty._request.parse_binary(self.req_bin_2, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_2 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_2) def testPackRequest3(self): bin = request.ChangeProperty._request.to_binary(*(), **self.req_args_3) - try: - assert bin == self.req_bin_3 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_3) def testUnpackRequest3(self): args, remain = request.ChangeProperty._request.parse_binary(self.req_bin_3, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_3 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_3) def testPackRequest4(self): bin = request.ChangeProperty._request.to_binary(*(), **self.req_args_4) - try: - assert bin == self.req_bin_4 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_4) def testUnpackRequest4(self): args, remain = request.ChangeProperty._request.parse_binary(self.req_bin_4, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_4 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_4) def testPackRequest5(self): bin = request.ChangeProperty._request.to_binary(*(), **self.req_args_5) - try: - assert bin == self.req_bin_5 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_5) def testUnpackRequest5(self): args, remain = request.ChangeProperty._request.parse_binary(self.req_bin_5, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_5 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_5) def testPackRequest6(self): bin = request.ChangeProperty._request.to_binary(*(), **self.req_args_6) - try: - assert bin == self.req_bin_6 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_6) def testUnpackRequest6(self): args, remain = request.ChangeProperty._request.parse_binary(self.req_bin_6, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_6 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_6) def testPackRequest7(self): bin = request.ChangeProperty._request.to_binary(*(), **self.req_args_7) - try: - assert bin == self.req_bin_7 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_7) def testUnpackRequest7(self): args, remain = request.ChangeProperty._request.parse_binary(self.req_bin_7, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_7 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_7) -class TestDeleteProperty(unittest.TestCase): +class TestDeleteProperty(EndianTest): def setUp(self): self.req_args_0 = { - 'property': 506897017, - 'window': 381870530, + 'property': 1928125498, + 'window': 920120163, } - self.req_bin_0 = '\x13\x00\x00\x03' '\x16\xc2\xe1\xc2' \ - '\x1e\x36\xa2\x79' + self.req_bin_0 = b'\x13\x00\x00\x03' b'\x36\xd7\xeb\x63' \ + b'\x72\xec\xdc\x3a' def testPackRequest0(self): bin = request.DeleteProperty._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.DeleteProperty._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGetProperty(unittest.TestCase): +class TestGetProperty(EndianTest): def setUp(self): self.req_args_0 = { - 'delete': 0, - 'long_offset': 1563462862, - 'type': 1556454304, - 'property': 1007774483, - 'window': 1477792536, - 'long_length': 1346507413, + 'delete': 1, + 'long_length': 297130690, + 'long_offset': 2142261240, + 'property': 471053276, + 'type': 2141806322, + 'window': 777446987, } - self.req_bin_0 = '\x14\x00\x00\x06' '\x58\x15\x53\x18' \ - '\x3c\x11\x6b\x13' '\x5c\xc5\x9b\xa0' \ - '\x5d\x30\x8c\xce' '\x50\x42\x12\x95' + self.req_bin_0 = b'\x14\x01\x00\x06' b'\x2e\x56\xe6\x4b' \ + b'\x1c\x13\xb3\xdc' b'\x7f\xa9\x5e\xf2' \ + b'\x7f\xb0\x4f\xf8' b'\x11\xb5\xda\xc2' self.reply_args_0 = { - 'value': (8, ''), - 'sequence_number': 30606, - 'property_type': 1392423916, - 'bytes_after': 2046056935, + 'bytes_after': 195292012, + 'property_type': 1059882735, + 'sequence_number': 33648, + 'value': (8, b''), } - self.reply_bin_0 = '\x01\x08\x77\x8e' '\x00\x00\x00\x00' \ - '\x52\xfe\xb3\xec' '\x79\xf4\x59\xe7' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.reply_bin_0 = b'\x01\x08\x83\x70' b'\x00\x00\x00\x00' \ + b'\x3f\x2c\x86\xef' b'\x0b\xa3\xeb\x6c' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' self.reply_args_1 = { - 'value': (8, 'foo'), - 'sequence_number': 44279, - 'property_type': 186441230, - 'bytes_after': 469299413, + 'bytes_after': 1849269963, + 'property_type': 101247178, + 'sequence_number': 49786, + 'value': (8, b'foo'), } - self.reply_bin_1 = '\x01\x08\xac\xf7' '\x00\x00\x00\x01' \ - '\x0b\x1c\xde\x0e' '\x1b\xf8\xf0\xd5' \ - '\x00\x00\x00\x03' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x66\x6f\x6f\x00' + self.reply_bin_1 = b'\x01\x08\xc2\x7a' b'\x00\x00\x00\x01' \ + b'\x06\x08\xe8\xca' b'\x6e\x39\x9e\xcb' \ + b'\x00\x00\x00\x03' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x66\x6f\x6f\x00' self.reply_args_2 = { - 'value': (8, 'zoom'), - 'sequence_number': 12674, - 'property_type': 1802804296, - 'bytes_after': 1968158856, + 'bytes_after': 1347495650, + 'property_type': 328289775, + 'sequence_number': 7441, + 'value': (8, b'zoom'), } - self.reply_bin_2 = '\x01\x08\x31\x82' '\x00\x00\x00\x01' \ - '\x6b\x74\x9c\x48' '\x75\x4f\xb8\x88' \ - '\x00\x00\x00\x04' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x7a\x6f\x6f\x6d' + self.reply_bin_2 = b'\x01\x08\x1d\x11' b'\x00\x00\x00\x01' \ + b'\x13\x91\x4d\xef' b'\x50\x51\x26\xe2' \ + b'\x00\x00\x00\x04' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x7a\x6f\x6f\x6d' self.reply_args_3 = { + 'bytes_after': 1461387818, + 'property_type': 1701043014, + 'sequence_number': 10740, 'value': (16, []), - 'sequence_number': 25311, - 'property_type': 536196393, - 'bytes_after': 1874157309, } - self.reply_bin_3 = '\x01\x10\x62\xdf' '\x00\x00\x00\x00' \ - '\x1f\xf5\xb5\x29' '\x6f\xb5\x5e\xfd' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.reply_bin_3 = b'\x01\x10\x29\xf4' b'\x00\x00\x00\x00' \ + b'\x65\x63\xdb\x46' b'\x57\x1b\x02\x2a' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' self.reply_args_4 = { + 'bytes_after': 136490248, + 'property_type': 1280844186, + 'sequence_number': 27922, 'value': (16, [1, 2, 3]), - 'sequence_number': 22665, - 'property_type': 1046879880, - 'bytes_after': 1952710167, } - self.reply_bin_4 = '\x01\x10\x58\x89' '\x00\x00\x00\x02' \ - '\x3e\x66\x1e\x88' '\x74\x63\xfe\x17' \ - '\x00\x00\x00\x03' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x01\x00\x02' '\x00\x03\x00\x00' + self.reply_bin_4 = b'\x01\x10\x6d\x12' b'\x00\x00\x00\x02' \ + b'\x4c\x58\x21\x9a' b'\x08\x22\xad\x08' \ + b'\x00\x00\x00\x03' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x01\x00\x02' b'\x00\x03\x00\x00' self.reply_args_5 = { + 'bytes_after': 1279726180, + 'property_type': 819586705, + 'sequence_number': 25472, 'value': (16, [1, 2, 3, 4]), - 'sequence_number': 19028, - 'property_type': 1014173132, - 'bytes_after': 1791090668, } - self.reply_bin_5 = '\x01\x10\x4a\x54' '\x00\x00\x00\x02' \ - '\x3c\x73\x0d\xcc' '\x6a\xc1\xdf\xec' \ - '\x00\x00\x00\x04' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x01\x00\x02' '\x00\x03\x00\x04' + self.reply_bin_5 = b'\x01\x10\x63\x80' b'\x00\x00\x00\x02' \ + b'\x30\xd9\xe6\x91' b'\x4c\x47\x12\x64' \ + b'\x00\x00\x00\x04' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x01\x00\x02' b'\x00\x03\x00\x04' self.reply_args_6 = { + 'bytes_after': 539973238, + 'property_type': 1136329940, + 'sequence_number': 30930, 'value': (32, []), - 'sequence_number': 47226, - 'property_type': 2053870497, - 'bytes_after': 1727548898, } - self.reply_bin_6 = '\x01\x20\xb8\x7a' '\x00\x00\x00\x00' \ - '\x7a\x6b\x93\xa1' '\x66\xf8\x4d\xe2' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.reply_bin_6 = b'\x01\x20\x78\xd2' b'\x00\x00\x00\x00' \ + b'\x43\xbb\x04\xd4' b'\x20\x2f\x56\x76' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' self.reply_args_7 = { + 'bytes_after': 1848575862, + 'property_type': 1188109101, + 'sequence_number': 63896, 'value': (32, [1, 2, 3]), - 'sequence_number': 37094, - 'property_type': 704363625, - 'bytes_after': 1957409055, } - self.reply_bin_7 = '\x01\x20\x90\xe6' '\x00\x00\x00\x03' \ - '\x29\xfb\xbc\x69' '\x74\xab\xb1\x1f' \ - '\x00\x00\x00\x03' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x01' '\x00\x00\x00\x02' \ - '\x00\x00\x00\x03' + self.reply_bin_7 = b'\x01\x20\xf9\x98' b'\x00\x00\x00\x03' \ + b'\x46\xd1\x1b\x2d' b'\x6e\x2f\x07\x76' \ + b'\x00\x00\x00\x03' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x01' b'\x00\x00\x00\x02' \ + b'\x00\x00\x00\x03' def testPackRequest0(self): bin = request.GetProperty._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetProperty._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetProperty._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetProperty._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) def testPackReply1(self): bin = request.GetProperty._reply.to_binary(*(), **self.reply_args_1) - try: - assert bin == self.reply_bin_1 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_1) def testUnpackReply1(self): args, remain = request.GetProperty._reply.parse_binary(self.reply_bin_1, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_1 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_1) def testPackReply2(self): bin = request.GetProperty._reply.to_binary(*(), **self.reply_args_2) - try: - assert bin == self.reply_bin_2 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_2) def testUnpackReply2(self): args, remain = request.GetProperty._reply.parse_binary(self.reply_bin_2, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_2 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_2) def testPackReply3(self): bin = request.GetProperty._reply.to_binary(*(), **self.reply_args_3) - try: - assert bin == self.reply_bin_3 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_3) def testUnpackReply3(self): args, remain = request.GetProperty._reply.parse_binary(self.reply_bin_3, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_3 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_3) def testPackReply4(self): bin = request.GetProperty._reply.to_binary(*(), **self.reply_args_4) - try: - assert bin == self.reply_bin_4 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_4) def testUnpackReply4(self): args, remain = request.GetProperty._reply.parse_binary(self.reply_bin_4, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_4 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_4) def testPackReply5(self): bin = request.GetProperty._reply.to_binary(*(), **self.reply_args_5) - try: - assert bin == self.reply_bin_5 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_5) def testUnpackReply5(self): args, remain = request.GetProperty._reply.parse_binary(self.reply_bin_5, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_5 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_5) def testPackReply6(self): bin = request.GetProperty._reply.to_binary(*(), **self.reply_args_6) - try: - assert bin == self.reply_bin_6 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_6) def testUnpackReply6(self): args, remain = request.GetProperty._reply.parse_binary(self.reply_bin_6, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_6 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_6) def testPackReply7(self): bin = request.GetProperty._reply.to_binary(*(), **self.reply_args_7) - try: - assert bin == self.reply_bin_7 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_7) def testUnpackReply7(self): args, remain = request.GetProperty._reply.parse_binary(self.reply_bin_7, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_7 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_7) -class TestListProperties(unittest.TestCase): +class TestListProperties(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 91262675, + 'window': 2023920407, } - self.req_bin_0 = '\x15\x00\x00\x02' '\x05\x70\x8e\xd3' + self.req_bin_0 = b'\x15\x00\x00\x02' b'\x78\xa2\x93\x17' self.reply_args_0 = { - 'atoms': [580972634, 926488735, 714741529, 408777797, 679906858, 705092899, 2063243279, 893967755, 1591182471, 571137996, 1677110101, 1783836762, 1678219148, 1992402577, 871298793, 1182885899, 1155013854, 1822076326, 2117552706, 1972668469, 1660227078, 1523268962, 694042433], - 'sequence_number': 42191, - } - self.reply_bin_0 = '\x01\x00\xa4\xcf' '\x00\x00\x00\x17' \ - '\x00\x17\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x22\xa0\xf0\x5a' '\x37\x39\x18\x9f' \ - '\x2a\x9a\x17\x19' '\x18\x5d\x74\x45' \ - '\x28\x86\x8e\x2a' '\x2a\x06\xdd\x23' \ - '\x7a\xfa\x98\x0f' '\x35\x48\xdd\x8b' \ - '\x5e\xd7\x84\x87' '\x22\x0a\xdf\xcc' \ - '\x63\xf6\xab\x55' '\x6a\x53\x30\x5a' \ - '\x64\x07\x97\x8c' '\x76\xc1\xa6\x91' \ - '\x33\xee\xf6\xe9' '\x46\x81\x68\x0b' \ - '\x44\xd8\x1c\xde' '\x6c\x9a\xad\xa6' \ - '\x7e\x37\x4a\x42' '\x75\x94\x88\x35' \ - '\x62\xf5\x0e\x06' '\x5a\xcb\x3d\x62' \ - '\x29\x5e\x3f\x41' + 'atoms': [24720840, 1460963027, 1547803868, 246063525, 1464027403, 1900134270, 1153200538, 1612563336, 573068260, 1650618737, 1376520521, 730586807, 239622004, 630352260, 933716813, 339706725, 974429777, 7034796, 2048369638, 1550746425, 1880945398, 1545568005, 565689201], + 'sequence_number': 63949, + } + self.reply_bin_0 = b'\x01\x00\xf9\xcd' b'\x00\x00\x00\x17' \ + b'\x00\x17\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x01\x79\x35\xc8' b'\x57\x14\x86\xd3' \ + b'\x5c\x41\x9c\xdc' b'\x0e\xaa\xa1\xa5' \ + b'\x57\x43\x49\x0b' b'\x71\x41\xbf\x7e' \ + b'\x44\xbc\x71\x9a' b'\x60\x1d\xc3\x88' \ + b'\x22\x28\x53\xe4' b'\x62\x62\x71\x71' \ + b'\x52\x0c\x09\x49' b'\x2b\x8b\xde\xb7' \ + b'\x0e\x48\x57\x74' b'\x25\x92\x69\x84' \ + b'\x37\xa7\x63\x4d' b'\x14\x3f\x83\x65' \ + b'\x3a\x14\x9e\x51' b'\x00\x6b\x57\xac' \ + b'\x7a\x17\xa3\xe6' b'\x5c\x6e\x83\x39' \ + b'\x70\x1c\xf2\xf6' b'\x5c\x1f\x7f\x05' \ + b'\x21\xb7\xbb\x71' def testPackRequest0(self): bin = request.ListProperties._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ListProperties._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.ListProperties._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.ListProperties._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestSetSelectionOwner(unittest.TestCase): +class TestSetSelectionOwner(EndianTest): def setUp(self): self.req_args_0 = { - 'selection': 2071258139, - 'window': 1190911777, - 'time': 1606660593, + 'selection': 1636366903, + 'time': 383717530, + 'window': 1075066031, } - self.req_bin_0 = '\x16\x00\x00\x04' '\x46\xfb\xdf\x21' \ - '\x7b\x74\xe4\x1b' '\x5f\xc3\xb1\xf1' + self.req_bin_0 = b'\x16\x00\x00\x04' b'\x40\x14\x34\xaf' \ + b'\x61\x88\xfa\x37' b'\x16\xdf\x10\x9a' def testPackRequest0(self): bin = request.SetSelectionOwner._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.SetSelectionOwner._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGetSelectionOwner(unittest.TestCase): +class TestGetSelectionOwner(EndianTest): def setUp(self): self.req_args_0 = { - 'selection': 819576555, + 'selection': 1090303630, } - self.req_bin_0 = '\x17\x00\x00\x02' '\x30\xd9\xbe\xeb' + self.req_bin_0 = b'\x17\x00\x00\x02' b'\x40\xfc\xb6\x8e' self.reply_args_0 = { - 'sequence_number': 14152, - 'owner': 1922331178, + 'owner': 228581038, + 'sequence_number': 60065, } - self.reply_bin_0 = '\x01\x00\x37\x48' '\x00\x00\x00\x00' \ - '\x72\x94\x72\x2a' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.reply_bin_0 = b'\x01\x00\xea\xa1' b'\x00\x00\x00\x00' \ + b'\x0d\x9f\xde\xae' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.GetSelectionOwner._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetSelectionOwner._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetSelectionOwner._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetSelectionOwner._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestConvertSelection(unittest.TestCase): +class TestConvertSelection(EndianTest): def setUp(self): self.req_args_0 = { - 'property': 2137791927, - 'time': 1594653142, - 'target': 1972273672, - 'selection': 125139929, - 'requestor': 300355135, + 'property': 1807536699, + 'requestor': 1869489931, + 'selection': 1342887479, + 'target': 640970836, + 'time': 1372199123, } - self.req_bin_0 = '\x18\x00\x00\x06' '\x11\xe7\x0e\x3f' \ - '\x07\x75\x7b\xd9' '\x75\x8e\x82\x08' \ - '\x7f\x6c\x1d\xb7' '\x5f\x0c\x79\xd6' + self.req_bin_0 = b'\x18\x00\x00\x06' b'\x6f\x6e\x27\x0b' \ + b'\x50\x0a\xd6\x37' b'\x26\x34\x70\x54' \ + b'\x6b\xbc\xd2\x3b' b'\x51\xca\x18\xd3' def testPackRequest0(self): bin = request.ConvertSelection._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ConvertSelection._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestSendEvent(unittest.TestCase): +class TestSendEvent(EndianTest): def setUp(self): self.req_args_0 = { - 'event': Xlib.protocol.event.Expose(height = 64784, sequence_number = 0, type = 12, x = 52546, y = 56316, window = 1322187412, width = 16612, count = 14164), - 'propagate': 1, - 'destination': 1369243800, - 'event_mask': 1594482936, + 'destination': 1158373169, + 'event': event.Expose(count=50227, height=24760, sequence_number=0, type=12, width=10272, window=1090263274, x=40165, y=13291), + 'event_mask': 2047690655, + 'propagate': 0, } - self.req_bin_0 = '\x19\x01\x00\x0b' '\x51\x9d\x00\x98' \ - '\x5f\x09\xe0\xf8' '\x0c\x00\x00\x00' \ - '\x4e\xce\xfa\x94' '\xcd\x42\xdb\xfc' \ - '\x40\xe4\xfd\x10' '\x37\x54\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' + self.req_bin_0 = b'\x19\x00\x00\x0b' b'\x45\x0b\x5f\x31' \ + b'\x7a\x0d\x47\x9f' b'\x0c\x00\x00\x00' \ + b'\x40\xfc\x18\xea' b'\x9c\xe5\x33\xeb' \ + b'\x28\x20\x60\xb8' b'\xc4\x33\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.SendEvent._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.SendEvent._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGrabPointer(unittest.TestCase): +class TestGrabPointer(EndianTest): def setUp(self): self.req_args_0 = { - 'owner_events': 1, - 'grab_window': 2104857020, - 'confine_to': 1988278615, - 'event_mask': 2075, - 'pointer_mode': 0, - 'time': 1316427724, - 'keyboard_mode': 1, - 'cursor': 17101598, + 'confine_to': 240299645, + 'cursor': 1995289624, + 'event_mask': 21499, + 'grab_window': 1286289242, + 'keyboard_mode': 0, + 'owner_events': 0, + 'pointer_mode': 1, + 'time': 779560794, } - self.req_bin_0 = '\x1a\x01\x00\x06' '\x7d\x75\x91\xbc' \ - '\x08\x1b\x00\x01' '\x76\x82\xb9\x57' \ - '\x01\x04\xf3\x1e' '\x4e\x77\x17\xcc' + self.req_bin_0 = b'\x1a\x00\x00\x06' b'\x4c\xab\x37\x5a' \ + b'\x53\xfb\x01\x00' b'\x0e\x52\xae\x7d' \ + b'\x76\xed\xb4\x18' b'\x2e\x77\x27\x5a' self.reply_args_0 = { - 'sequence_number': 47539, - 'status': 149, + 'sequence_number': 15948, + 'status': 206, } - self.reply_bin_0 = '\x01\x95\xb9\xb3' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.reply_bin_0 = b'\x01\xce\x3e\x4c' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.GrabPointer._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GrabPointer._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GrabPointer._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GrabPointer._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestUngrabPointer(unittest.TestCase): +class TestUngrabPointer(EndianTest): def setUp(self): self.req_args_0 = { - 'time': 209008422, + 'time': 124458893, } - self.req_bin_0 = '\x1b\x00\x00\x02' '\x0c\x75\x37\x26' + self.req_bin_0 = b'\x1b\x00\x00\x02' b'\x07\x6b\x17\x8d' def testPackRequest0(self): bin = request.UngrabPointer._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.UngrabPointer._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGrabButton(unittest.TestCase): +class TestGrabButton(EndianTest): def setUp(self): self.req_args_0 = { - 'owner_events': 1, - 'grab_window': 526402184, - 'confine_to': 1843948635, - 'event_mask': 16279, - 'pointer_mode': 1, - 'modifiers': 15589, - 'button': 208, - 'keyboard_mode': 1, - 'cursor': 1070323643, + 'button': 145, + 'confine_to': 1571825127, + 'cursor': 1043722096, + 'event_mask': 37438, + 'grab_window': 1885576796, + 'keyboard_mode': 0, + 'modifiers': 64349, + 'owner_events': 0, + 'pointer_mode': 0, } - self.req_bin_0 = '\x1c\x01\x00\x06' '\x1f\x60\x42\x88' \ - '\x3f\x97\x01\x01' '\x6d\xe8\x6c\x5b' \ - '\x3f\xcb\xd7\xbb' '\xd0\x00\x3c\xe5' + self.req_bin_0 = b'\x1c\x00\x00\x06' b'\x70\x63\x9e\x5c' \ + b'\x92\x3e\x00\x00' b'\x5d\xb0\x25\xe7' \ + b'\x3e\x35\xef\x70' b'\x91\x00\xfb\x5d' def testPackRequest0(self): bin = request.GrabButton._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GrabButton._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestUngrabButton(unittest.TestCase): +class TestUngrabButton(EndianTest): def setUp(self): self.req_args_0 = { - 'grab_window': 795414150, - 'button': 240, - 'modifiers': 51717, + 'button': 160, + 'grab_window': 275784110, + 'modifiers': 43493, } - self.req_bin_0 = '\x1d\xf0\x00\x03' '\x2f\x69\x0e\x86' \ - '\xca\x05\x00\x00' + self.req_bin_0 = b'\x1d\xa0\x00\x03' b'\x10\x70\x21\xae' \ + b'\xa9\xe5\x00\x00' def testPackRequest0(self): bin = request.UngrabButton._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.UngrabButton._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestChangeActivePointerGrab(unittest.TestCase): +class TestChangeActivePointerGrab(EndianTest): def setUp(self): self.req_args_0 = { - 'time': 891337572, - 'event_mask': 23423, - 'cursor': 1696594928, + 'cursor': 1020726671, + 'event_mask': 36287, + 'time': 2033407590, } - self.req_bin_0 = '\x1e\x00\x00\x04' '\x65\x1f\xfb\xf0' \ - '\x35\x20\xbb\x64' '\x5b\x7f\x00\x00' + self.req_bin_0 = b'\x1e\x00\x00\x04' b'\x3c\xd7\x0d\x8f' \ + b'\x79\x33\x56\x66' b'\x8d\xbf\x00\x00' def testPackRequest0(self): bin = request.ChangeActivePointerGrab._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ChangeActivePointerGrab._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGrabKeyboard(unittest.TestCase): +class TestGrabKeyboard(EndianTest): def setUp(self): self.req_args_0 = { + 'grab_window': 569270305, + 'keyboard_mode': 0, 'owner_events': 0, - 'grab_window': 76132199, - 'time': 1562605785, 'pointer_mode': 1, - 'keyboard_mode': 1, + 'time': 1133236353, } - self.req_bin_0 = '\x1f\x00\x00\x04' '\x04\x89\xaf\x67' \ - '\x5d\x23\x78\xd9' '\x01\x01\x00\x00' + self.req_bin_0 = b'\x1f\x00\x00\x04' b'\x21\xee\x60\x21' \ + b'\x43\x8b\xd0\x81' b'\x01\x00\x00\x00' self.reply_args_0 = { - 'sequence_number': 9648, - 'status': 129, + 'sequence_number': 46979, + 'status': 179, } - self.reply_bin_0 = '\x01\x81\x25\xb0' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.reply_bin_0 = b'\x01\xb3\xb7\x83' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.GrabKeyboard._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GrabKeyboard._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GrabKeyboard._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GrabKeyboard._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestUngrabKeyboard(unittest.TestCase): +class TestUngrabKeyboard(EndianTest): def setUp(self): self.req_args_0 = { - 'time': 1352311886, + 'time': 669471181, } - self.req_bin_0 = '\x20\x00\x00\x02' '\x50\x9a\xa4\x4e' + self.req_bin_0 = b'\x20\x00\x00\x02' b'\x27\xe7\x51\xcd' def testPackRequest0(self): bin = request.UngrabKeyboard._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.UngrabKeyboard._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGrabKey(unittest.TestCase): +class TestGrabKey(EndianTest): def setUp(self): self.req_args_0 = { + 'grab_window': 2137132511, + 'key': 223, + 'keyboard_mode': 1, + 'modifiers': 44275, 'owner_events': 1, - 'grab_window': 1467490800, - 'pointer_mode': 0, - 'keyboard_mode': 0, - 'modifiers': 28819, - 'key': 193, + 'pointer_mode': 1, } - self.req_bin_0 = '\x21\x01\x00\x04' '\x57\x78\x21\xf0' \ - '\x70\x93\xc1\x00' '\x00\x00\x00\x00' + self.req_bin_0 = b'\x21\x01\x00\x04' b'\x7f\x62\x0d\xdf' \ + b'\xac\xf3\xdf\x01' b'\x01\x00\x00\x00' def testPackRequest0(self): bin = request.GrabKey._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GrabKey._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestUngrabKey(unittest.TestCase): +class TestUngrabKey(EndianTest): def setUp(self): self.req_args_0 = { - 'grab_window': 769929659, - 'key': 215, - 'modifiers': 60588, + 'grab_window': 532438798, + 'key': 158, + 'modifiers': 14981, } - self.req_bin_0 = '\x22\xd7\x00\x03' '\x2d\xe4\x31\xbb' \ - '\xec\xac\x00\x00' + self.req_bin_0 = b'\x22\x9e\x00\x03' b'\x1f\xbc\x5f\x0e' \ + b'\x3a\x85\x00\x00' def testPackRequest0(self): bin = request.UngrabKey._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.UngrabKey._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestAllowEvents(unittest.TestCase): +class TestAllowEvents(EndianTest): def setUp(self): self.req_args_0 = { - 'time': 342147129, 'mode': 1, + 'time': 726098765, } - self.req_bin_0 = '\x23\x01\x00\x02' '\x14\x64\xc0\x39' + self.req_bin_0 = b'\x23\x01\x00\x02' b'\x2b\x47\x63\x4d' def testPackRequest0(self): bin = request.AllowEvents._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.AllowEvents._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGrabServer(unittest.TestCase): +class TestGrabServer(EndianTest): def setUp(self): self.req_args_0 = { } - self.req_bin_0 = '\x24\x00\x00\x01' + self.req_bin_0 = b'\x24\x00\x00\x01' def testPackRequest0(self): bin = request.GrabServer._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GrabServer._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestUngrabServer(unittest.TestCase): +class TestUngrabServer(EndianTest): def setUp(self): self.req_args_0 = { } - self.req_bin_0 = '\x25\x00\x00\x01' + self.req_bin_0 = b'\x25\x00\x00\x01' def testPackRequest0(self): bin = request.UngrabServer._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.UngrabServer._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestQueryPointer(unittest.TestCase): +class TestQueryPointer(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 561336799, + 'window': 45236268, } - self.req_bin_0 = '\x26\x00\x00\x02' '\x21\x75\x51\xdf' + self.req_bin_0 = b'\x26\x00\x00\x02' b'\x02\xb2\x40\x2c' self.reply_args_0 = { - 'win_y': -25733, + 'child': 15507755, + 'mask': 15259, + 'root': 472978779, + 'root_x': -30442, + 'root_y': -9574, 'same_screen': 0, - 'sequence_number': 41448, - 'root': 1599238998, - 'root_x': -4185, - 'root_y': -6112, - 'mask': 35955, - 'child': 1075058918, - 'win_x': -18858, + 'sequence_number': 38820, + 'win_x': -12089, + 'win_y': -30839, } - self.reply_bin_0 = '\x01\x00\xa1\xe8' '\x00\x00\x00\x00' \ - '\x5f\x52\x73\x56' '\x40\x14\x18\xe6' \ - '\xef\xa7\xe8\x20' '\xb6\x56\x9b\x7b' \ - '\x8c\x73\x00\x00' '\x00\x00\x00\x00' + self.reply_bin_0 = b'\x01\x00\x97\xa4' b'\x00\x00\x00\x00' \ + b'\x1c\x31\x15\x5b' b'\x00\xec\xa1\x2b' \ + b'\x89\x16\xda\x9a' b'\xd0\xc7\x87\x89' \ + b'\x3b\x9b\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.QueryPointer._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.QueryPointer._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.QueryPointer._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.QueryPointer._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestGetMotionEvents(unittest.TestCase): +class TestGetMotionEvents(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 843681780, - 'start': 1520150500, - 'stop': 11115313, + 'start': 1944440211, + 'stop': 67524349, + 'window': 144806627, } - self.req_bin_0 = '\x27\x00\x00\x04' '\x32\x49\x8f\xf4' \ - '\x5a\x9b\xa7\xe4' '\x00\xa9\x9b\x31' + self.req_bin_0 = b'\x27\x00\x00\x04' b'\x08\xa1\x92\xe3' \ + b'\x73\xe5\xcd\x93' b'\x04\x06\x56\xfd' self.reply_args_0 = { - 'sequence_number': 52222, - 'events': [{'time': 2107444516, 'x': -649, 'y': -11631}, {'time': 1827536960, 'x': -18061, 'y': -2301}, {'time': 554175146, 'x': -32111, 'y': -13522}, {'time': 608168588, 'x': -5963, 'y': -24618}, {'time': 590416221, 'x': -3325, 'y': -19656}], + 'events': [{'y': -30447, 'x': -21941, 'time': 1846118496}, {'y': -23643, 'x': -24970, 'time': 1104207400}, {'y': -25748, 'x': -16862, 'time': 1436684371}, {'y': -9066, 'x': -28433, 'time': 1158061593}, {'y': -14057, 'x': -3855, 'time': 2009067067}], + 'sequence_number': 38018, } - self.reply_bin_0 = '\x01\x00\xcb\xfe' '\x00\x00\x00\x0a' \ - '\x00\x00\x00\x05' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x7d\x9d\x0d\x24' '\xfd\x77\xd2\x91' \ - '\x6c\xee\x00\x40' '\xb9\x73\xf7\x03' \ - '\x21\x08\x0a\xaa' '\x82\x91\xcb\x2e' \ - '\x24\x3f\xea\x8c' '\xe8\xb5\x9f\xd6' \ - '\x23\x31\x09\x5d' '\xf3\x03\xb3\x38' + self.reply_bin_0 = b'\x01\x00\x94\x82' b'\x00\x00\x00\x0a' \ + b'\x00\x00\x00\x05' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x6e\x09\x88\x60' b'\xaa\x4b\x89\x11' \ + b'\x41\xd0\xde\x28' b'\x9e\x76\xa3\xa5' \ + b'\x55\xa2\x10\x53' b'\xbe\x22\x9b\x6c' \ + b'\x45\x06\x9e\x19' b'\x90\xef\xdc\x96' \ + b'\x77\xbf\xee\x3b' b'\xf0\xf1\xc9\x17' def testPackRequest0(self): bin = request.GetMotionEvents._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetMotionEvents._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetMotionEvents._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetMotionEvents._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestTranslateCoords(unittest.TestCase): +class TestTranslateCoords(EndianTest): def setUp(self): self.req_args_0 = { - 'src_y': -27247, - 'src_x': -25331, - 'src_wid': 257619448, - 'dst_wid': 1238981863, + 'dst_wid': 521898132, + 'src_wid': 1015118844, + 'src_x': -7058, + 'src_y': -17270, } - self.req_bin_0 = '\x28\x00\x00\x04' '\x0f\x5a\xf5\xf8' \ - '\x49\xd9\x5c\xe7' '\x9d\x0d\x95\x91' + self.req_bin_0 = b'\x28\x00\x00\x04' b'\x3c\x81\x7b\xfc' \ + b'\x1f\x1b\x88\x94' b'\xe4\x6e\xbc\x8a' self.reply_args_0 = { - 'child': 2050350678, + 'child': 202628650, 'same_screen': 1, - 'sequence_number': 38657, - 'x': -18096, - 'y': -5252, + 'sequence_number': 12734, + 'x': -29592, + 'y': -11175, } - self.reply_bin_0 = '\x01\x01\x97\x01' '\x00\x00\x00\x00' \ - '\x7a\x35\xde\x56' '\xb9\x50\xeb\x7c' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.reply_bin_0 = b'\x01\x01\x31\xbe' b'\x00\x00\x00\x00' \ + b'\x0c\x13\xde\x2a' b'\x8c\x68\xd4\x59' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.TranslateCoords._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.TranslateCoords._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.TranslateCoords._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.TranslateCoords._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestWarpPointer(unittest.TestCase): +class TestWarpPointer(EndianTest): def setUp(self): self.req_args_0 = { - 'src_height': 56634, - 'src_window': 1335081711, - 'dst_window': 675547124, - 'src_width': 21809, - 'src_y': -26071, - 'src_x': -27119, - 'dst_x': -30516, - 'dst_y': -24204, + 'dst_window': 760913775, + 'dst_x': -8878, + 'dst_y': -30993, + 'src_height': 56868, + 'src_width': 30862, + 'src_window': 925740905, + 'src_x': -18889, + 'src_y': -19298, } - self.req_bin_0 = '\x29\x00\x00\x06' '\x4f\x93\xba\xef' \ - '\x28\x44\x07\xf4' '\x96\x11\x9a\x29' \ - '\x55\x31\xdd\x3a' '\x88\xcc\xa1\x74' + self.req_bin_0 = b'\x29\x00\x00\x06' b'\x37\x2d\xaf\x69' \ + b'\x2d\x5a\x9f\x6f' b'\xb6\x37\xb4\x9e' \ + b'\x78\x8e\xde\x24' b'\xdd\x52\x86\xef' def testPackRequest0(self): bin = request.WarpPointer._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.WarpPointer._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestSetInputFocus(unittest.TestCase): +class TestSetInputFocus(EndianTest): def setUp(self): self.req_args_0 = { - 'revert_to': 1, - 'time': 1079702500, - 'focus': 1026400247, + 'focus': 1403350503, + 'revert_to': 2, + 'time': 2113544232, } - self.req_bin_0 = '\x2a\x01\x00\x03' '\x3d\x2d\x9f\xf7' \ - '\x40\x5a\xf3\xe4' + self.req_bin_0 = b'\x2a\x02\x00\x03' b'\x53\xa5\x6d\xe7' \ + b'\x7d\xfa\x20\x28' def testPackRequest0(self): bin = request.SetInputFocus._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.SetInputFocus._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGetInputFocus(unittest.TestCase): +class TestGetInputFocus(EndianTest): def setUp(self): self.req_args_0 = { } - self.req_bin_0 = '\x2b\x00\x00\x01' + self.req_bin_0 = b'\x2b\x00\x00\x01' self.reply_args_0 = { - 'revert_to': 152, - 'sequence_number': 16002, - 'focus': 2024022965, + 'focus': 864688157, + 'revert_to': 153, + 'sequence_number': 4228, } - self.reply_bin_0 = '\x01\x98\x3e\x82' '\x00\x00\x00\x00' \ - '\x78\xa4\x23\xb5' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.reply_bin_0 = b'\x01\x99\x10\x84' b'\x00\x00\x00\x00' \ + b'\x33\x8a\x18\x1d' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.GetInputFocus._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetInputFocus._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetInputFocus._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetInputFocus._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestQueryKeymap(unittest.TestCase): +class TestQueryKeymap(EndianTest): def setUp(self): self.req_args_0 = { } - self.req_bin_0 = '\x2c\x00\x00\x01' + self.req_bin_0 = b'\x2c\x00\x00\x01' self.reply_args_0 = { - 'sequence_number': 16233, - 'map': [186, 167, 191, 213, 241, 231, 234, 175, 154, 169, 132, 146, 215, 191, 196, 212, 158, 156, 177, 233, 220, 192, 130, 226, 181, 233, 238, 141, 129, 215, 245, 215], + 'map': [214, 155, 191, 177, 176, 242, 163, 236, 174, 199, 246, 191, 147, 241, 153, 140, 131, 151, 188, 170, 232, 252, 251, 182, 230, 143, 170, 225, 128, 227, 195, 244], + 'sequence_number': 18950, } - self.reply_bin_0 = '\x01\x00\x3f\x69' '\x00\x00\x00\x02' \ - '\xba\xa7\xbf\xd5' '\xf1\xe7\xea\xaf' \ - '\x9a\xa9\x84\x92' '\xd7\xbf\xc4\xd4' \ - '\x9e\x9c\xb1\xe9' '\xdc\xc0\x82\xe2' \ - '\xb5\xe9\xee\x8d' '\x81\xd7\xf5\xd7' + self.reply_bin_0 = b'\x01\x00\x4a\x06' b'\x00\x00\x00\x02' \ + b'\xd6\x9b\xbf\xb1' b'\xb0\xf2\xa3\xec' \ + b'\xae\xc7\xf6\xbf' b'\x93\xf1\x99\x8c' \ + b'\x83\x97\xbc\xaa' b'\xe8\xfc\xfb\xb6' \ + b'\xe6\x8f\xaa\xe1' b'\x80\xe3\xc3\xf4' def testPackRequest0(self): bin = request.QueryKeymap._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.QueryKeymap._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.QueryKeymap._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.QueryKeymap._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestOpenFont(unittest.TestCase): +class TestOpenFont(EndianTest): def setUp(self): self.req_args_0 = { - 'fid': 1728036313, + 'fid': 908467189, 'name': 'foofont', } - self.req_bin_0 = '\x2d\x00\x00\x05' '\x66\xff\xbd\xd9' \ - '\x00\x07\x00\x00' '\x66\x6f\x6f\x66' \ - '\x6f\x6e\x74\x00' + self.req_bin_0 = b'\x2d\x00\x00\x05' b'\x36\x26\x1b\xf5' \ + b'\x00\x07\x00\x00' b'\x66\x6f\x6f\x66' \ + b'\x6f\x6e\x74\x00' def testPackRequest0(self): bin = request.OpenFont._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.OpenFont._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestCloseFont(unittest.TestCase): +class TestCloseFont(EndianTest): def setUp(self): self.req_args_0 = { - 'font': 1139770507, + 'font': 1495984396, } - self.req_bin_0 = '\x2e\x00\x00\x02' '\x43\xef\x84\x8b' + self.req_bin_0 = b'\x2e\x00\x00\x02' b'\x59\x2a\xe9\x0c' def testPackRequest0(self): bin = request.CloseFont._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.CloseFont._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestQueryFont(unittest.TestCase): +class TestQueryFont(EndianTest): def setUp(self): self.req_args_0 = { - 'font': 1867659050, + 'font': 2055889505, } - self.req_bin_0 = '\x2f\x00\x00\x02' '\x6f\x52\x37\x2a' + self.req_bin_0 = b'\x2f\x00\x00\x02' b'\x7a\x8a\x62\x61' self.reply_args_0 = { - 'sequence_number': 8877, - 'properties': [{'value': 2110348825, 'name': 1450586355}], - 'min_byte1': 190, - 'max_byte1': 168, - 'char_infos': [{'descent': -331, 'ascent': -14454, 'character_width': -28521, 'left_side_bearing': -4521, 'right_side_bearing': -9875, 'attributes': 55191}, {'descent': -18739, 'ascent': -6278, 'character_width': -4532, 'left_side_bearing': -20397, 'right_side_bearing': -25187, 'attributes': 29476}, {'descent': -18381, 'ascent': -2378, 'character_width': -21855, 'left_side_bearing': -20068, 'right_side_bearing': -906, 'attributes': 34385}], - 'max_char_or_byte2': 2516, - 'default_char': 8994, - 'min_char_or_byte2': 49360, - 'draw_direction': 143, - 'min_bounds': {'descent': -29813, 'ascent': -27033, 'character_width': -5286, 'left_side_bearing': -20740, 'right_side_bearing': -21698, 'attributes': 11392}, - 'all_chars_exist': 1, - 'font_ascent': -15646, - 'font_descent': -23067, - 'max_bounds': {'descent': -24292, 'ascent': -26972, 'character_width': -19286, 'left_side_bearing': -16363, 'right_side_bearing': -3149, 'attributes': 35968}, - } - self.reply_bin_0 = '\x01\x00\x22\xad' '\x00\x00\x00\x12' \ - '\xae\xfc\xab\x3e' '\xeb\x5a\x96\x67' \ - '\x8b\x8b\x2c\x80' '\x00\x00\x00\x00' \ - '\xc0\x15\xf3\xb3' '\xb4\xaa\x96\xa4' \ - '\xa1\x1c\x8c\x80' '\x00\x00\x00\x00' \ - '\xc0\xd0\x09\xd4' '\x23\x22\x00\x01' \ - '\x8f\xbe\xa8\x01' '\xc2\xe2\xa5\xe5' \ - '\x00\x00\x00\x03' '\x56\x76\x30\xf3' \ - '\x7d\xc9\x5e\x19' '\xee\x57\xd9\x6d' \ - '\x90\x97\xc7\x8a' '\xfe\xb5\xd7\x97' \ - '\xb0\x53\x9d\x9d' '\xee\x4c\xe7\x7a' \ - '\xb6\xcd\x73\x24' '\xb1\x9c\xfc\x76' \ - '\xaa\xa1\xf6\xb6' '\xb8\x33\x86\x51' + 'all_chars_exist': 0, + 'char_infos': [{'descent': -16821, 'right_side_bearing': -14557, 'character_width': -11080, 'left_side_bearing': -7099, 'attributes': 10400, 'ascent': -9228}, {'descent': -30852, 'right_side_bearing': -23046, 'character_width': -25635, 'left_side_bearing': -26546, 'attributes': 38213, 'ascent': -1026}, {'descent': -22492, 'right_side_bearing': -15002, 'character_width': -30771, 'left_side_bearing': -8660, 'attributes': 4002, 'ascent': -8259}], + 'default_char': 39252, + 'draw_direction': 145, + 'font_ascent': -1914, + 'font_descent': -3596, + 'max_bounds': {'descent': -30143, 'right_side_bearing': -30905, 'character_width': -1286, 'left_side_bearing': -27610, 'attributes': 56049, 'ascent': -16128}, + 'max_byte1': 231, + 'max_char_or_byte2': 4746, + 'min_bounds': {'descent': -4827, 'right_side_bearing': -17145, 'character_width': -16291, 'left_side_bearing': -13626, 'attributes': 35063, 'ascent': -2642}, + 'min_byte1': 188, + 'min_char_or_byte2': 12434, + 'properties': [{'name': 1568813755, 'value': 2137719486}], + 'sequence_number': 3542, + } + self.reply_bin_0 = b'\x01\x00\x0d\xd6' b'\x00\x00\x00\x12' \ + b'\xca\xc6\xbd\x07' b'\xc0\x5d\xf5\xae' \ + b'\xed\x25\x88\xf7' b'\x00\x00\x00\x00' \ + b'\x94\x26\x87\x47' b'\xfa\xfa\xc1\x00' \ + b'\x8a\x41\xda\xf1' b'\x00\x00\x00\x00' \ + b'\x30\x92\x12\x8a' b'\x99\x54\x00\x01' \ + b'\x91\xbc\xe7\x00' b'\xf8\x86\xf1\xf4' \ + b'\x00\x00\x00\x03' b'\x5d\x82\x32\xbb' \ + b'\x7f\x6b\x02\xbe' b'\xe4\x45\xc7\x23' \ + b'\xd4\xb8\xdb\xf4' b'\xbe\x4b\x28\xa0' \ + b'\x98\x4e\xa5\xfa' b'\x9b\xdd\xfb\xfe' \ + b'\x87\x7c\x95\x45' b'\xde\x2c\xc5\x66' \ + b'\x87\xcd\xdf\xbd' b'\xa8\x24\x0f\xa2' def testPackRequest0(self): bin = request.QueryFont._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.QueryFont._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.QueryFont._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.QueryFont._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestQueryTextExtents(unittest.TestCase): +class TestQueryTextExtents(EndianTest): def setUp(self): self.req_args_0 = { - 'font': 1562125736, + 'font': 1223434172, 'string': (102, 111, 111), } - self.req_bin_0 = '\x30\x01\x00\x04' '\x5d\x1c\x25\xa8' \ - '\x00\x66\x00\x6f' '\x00\x6f\x00\x00' + self.req_bin_0 = b'\x30\x01\x00\x04' b'\x48\xec\x1f\xbc' \ + b'\x00\x66\x00\x6f' b'\x00\x6f\x00\x00' self.reply_args_0 = { - 'overall_width': -1378352414, - 'draw_direction': 219, - 'sequence_number': 6791, - 'font_ascent': -16915, - 'overall_ascent': -22910, - 'overall_descent': -1795, - 'overall_right': -530284310, - 'overall_left': -1046976699, - 'font_descent': -14179, - } - self.reply_bin_0 = '\x01\xdb\x1a\x87' '\x00\x00\x00\x00' \ - '\xbd\xed\xc8\x9d' '\xa6\x82\xf8\xfd' \ - '\xad\xd8\x02\xe2' '\xc1\x98\x67\x45' \ - '\xe0\x64\x80\xea' '\x00\x00\x00\x00' + 'draw_direction': 191, + 'font_ascent': -13287, + 'font_descent': -31466, + 'overall_ascent': -12473, + 'overall_descent': -30082, + 'overall_left': -735785526, + 'overall_right': -894056953, + 'overall_width': -1247205006, + 'sequence_number': 38196, + } + self.reply_bin_0 = b'\x01\xbf\x95\x34' b'\x00\x00\x00\x00' \ + b'\xcc\x19\x85\x16' b'\xcf\x47\x8a\x7e' \ + b'\xb5\xa9\x29\x72' b'\xd4\x24\xcd\xca' \ + b'\xca\xb5\xc6\x07' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.QueryTextExtents._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.QueryTextExtents._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.QueryTextExtents._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.QueryTextExtents._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestListFonts(unittest.TestCase): +class TestListFonts(EndianTest): def setUp(self): self.req_args_0 = { - 'max_names': 53961, + 'max_names': 37298, 'pattern': 'bhazr', } - self.req_bin_0 = '\x31\x00\x00\x04' '\xd2\xc9\x00\x05' \ - '\x62\x68\x61\x7a' '\x72\x00\x00\x00' + self.req_bin_0 = b'\x31\x00\x00\x04' b'\x91\xb2\x00\x05' \ + b'\x62\x68\x61\x7a' b'\x72\x00\x00\x00' self.reply_args_0 = { 'fonts': ['fie', 'fuzzy', 'foozooom'], - 'sequence_number': 38267, + 'sequence_number': 34517, } - self.reply_bin_0 = '\x01\x00\x95\x7b' '\x00\x00\x00\x05' \ - '\x00\x03\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x03\x66\x69\x65' '\x05\x66\x75\x7a' \ - '\x7a\x79\x08\x66' '\x6f\x6f\x7a\x6f' \ - '\x6f\x6f\x6d\x00' + self.reply_bin_0 = b'\x01\x00\x86\xd5' b'\x00\x00\x00\x05' \ + b'\x00\x03\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x03\x66\x69\x65' b'\x05\x66\x75\x7a' \ + b'\x7a\x79\x08\x66' b'\x6f\x6f\x7a\x6f' \ + b'\x6f\x6f\x6d\x00' def testPackRequest0(self): bin = request.ListFonts._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ListFonts._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.ListFonts._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.ListFonts._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestListFontsWithInfo(unittest.TestCase): +class TestListFontsWithInfo(EndianTest): def setUp(self): self.req_args_0 = { - 'max_names': 46571, + 'max_names': 20989, 'pattern': 'bhazr2', } - self.req_bin_0 = '\x32\x00\x00\x04' '\xb5\xeb\x00\x06' \ - '\x62\x68\x61\x7a' '\x72\x32\x00\x00' + self.req_bin_0 = b'\x32\x00\x00\x04' b'\x51\xfd\x00\x06' \ + b'\x62\x68\x61\x7a' b'\x72\x32\x00\x00' self.reply_args_0 = { - 'sequence_number': 20014, - 'properties': [{'value': 2110430409, 'name': 435956656}], - 'min_byte1': 214, - 'max_byte1': 217, - 'max_char_or_byte2': 2479, - 'default_char': 17041, - 'min_char_or_byte2': 26638, - 'draw_direction': 192, - 'replies_hint': 1985190562, - 'min_bounds': {'descent': -27837, 'ascent': -14775, 'character_width': -13026, 'left_side_bearing': -29767, 'right_side_bearing': -31908, 'attributes': 2465}, 'all_chars_exist': 0, + 'default_char': 61580, + 'draw_direction': 146, + 'font_ascent': -30368, + 'font_descent': -15151, + 'max_bounds': {'descent': -17786, 'right_side_bearing': -10759, 'character_width': -11617, 'left_side_bearing': -28480, 'attributes': 20976, 'ascent': -22938}, + 'max_byte1': 245, + 'max_char_or_byte2': 49530, + 'min_bounds': {'descent': -24065, 'right_side_bearing': -9300, 'character_width': -22473, 'left_side_bearing': -10823, 'attributes': 26194, 'ascent': -24947}, + 'min_byte1': 130, + 'min_char_or_byte2': 61140, 'name': 'fontfont', - 'font_ascent': -30550, - 'font_descent': -28978, - 'max_bounds': {'descent': -20692, 'ascent': -6999, 'character_width': -15180, 'left_side_bearing': -7789, 'right_side_bearing': -5339, 'attributes': 1068}, - } - self.reply_bin_0 = '\x01\x08\x4e\x2e' '\x00\x00\x00\x0b' \ - '\x8b\xb9\x83\x5c' '\xcd\x1e\xc6\x49' \ - '\x93\x43\x09\xa1' '\x00\x00\x00\x00' \ - '\xe1\x93\xeb\x25' '\xc4\xb4\xe4\xa9' \ - '\xaf\x2c\x04\x2c' '\x00\x00\x00\x00' \ - '\x68\x0e\x09\xaf' '\x42\x91\x00\x01' \ - '\xc0\xd6\xd9\x00' '\x88\xaa\x8e\xce' \ - '\x76\x53\x9a\xa2' '\x19\xfc\x2b\xb0' \ - '\x7d\xca\x9c\xc9' '\x66\x6f\x6e\x74' \ - '\x66\x6f\x6e\x74' + 'properties': [{'name': 2007331946, 'value': 560055601}], + 'replies_hint': 457810933, + 'sequence_number': 13642, + } + self.reply_bin_0 = b'\x01\x08\x35\x4a' b'\x00\x00\x00\x0b' \ + b'\xd5\xb9\xdb\xac' b'\xa8\x37\x9e\x8d' \ + b'\xa1\xff\x66\x52' b'\x00\x00\x00\x00' \ + b'\x90\xc0\xd5\xf9' b'\xd2\x9f\xa6\x66' \ + b'\xba\x86\x51\xf0' b'\x00\x00\x00\x00' \ + b'\xee\xd4\xc1\x7a' b'\xf0\x8c\x00\x01' \ + b'\x92\x82\xf5\x00' b'\x89\x60\xc4\xd1' \ + b'\x1b\x49\xa3\xf5' b'\x77\xa5\x74\x6a' \ + b'\x21\x61\xc5\x31' b'\x66\x6f\x6e\x74' \ + b'\x66\x6f\x6e\x74' def testPackRequest0(self): bin = request.ListFontsWithInfo._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ListFontsWithInfo._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.ListFontsWithInfo._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.ListFontsWithInfo._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestSetFontPath(unittest.TestCase): +class TestSetFontPath(EndianTest): def setUp(self): self.req_args_0 = { 'path': ['foo', 'bar', 'gazonk'], } - self.req_bin_0 = '\x33\x00\x00\x06' '\x00\x03\x00\x00' \ - '\x03\x66\x6f\x6f' '\x03\x62\x61\x72' \ - '\x06\x67\x61\x7a' '\x6f\x6e\x6b\x00' + self.req_bin_0 = b'\x33\x00\x00\x06' b'\x00\x03\x00\x00' \ + b'\x03\x66\x6f\x6f' b'\x03\x62\x61\x72' \ + b'\x06\x67\x61\x7a' b'\x6f\x6e\x6b\x00' self.req_args_1 = { 'path': [], } - self.req_bin_1 = '\x33\x00\x00\x02' '\x00\x00\x00\x00' + self.req_bin_1 = b'\x33\x00\x00\x02' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.SetFontPath._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.SetFontPath._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackRequest1(self): bin = request.SetFontPath._request.to_binary(*(), **self.req_args_1) - try: - assert bin == self.req_bin_1 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_1) def testUnpackRequest1(self): args, remain = request.SetFontPath._request.parse_binary(self.req_bin_1, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_1 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_1) -class TestGetFontPath(unittest.TestCase): +class TestGetFontPath(EndianTest): def setUp(self): self.req_args_0 = { } - self.req_bin_0 = '\x34\x00\x00\x01' + self.req_bin_0 = b'\x34\x00\x00\x01' self.reply_args_0 = { - 'sequence_number': 21510, 'paths': ['path1', 'path2232'], + 'sequence_number': 33409, } - self.reply_bin_0 = '\x01\x00\x54\x06' '\x00\x00\x00\x04' \ - '\x00\x02\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x05\x70\x61\x74' '\x68\x31\x08\x70' \ - '\x61\x74\x68\x32' '\x32\x33\x32\x00' + self.reply_bin_0 = b'\x01\x00\x82\x81' b'\x00\x00\x00\x04' \ + b'\x00\x02\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x05\x70\x61\x74' b'\x68\x31\x08\x70' \ + b'\x61\x74\x68\x32' b'\x32\x33\x32\x00' self.reply_args_1 = { - 'sequence_number': 62463, 'paths': [], + 'sequence_number': 17636, } - self.reply_bin_1 = '\x01\x00\xf3\xff' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.reply_bin_1 = b'\x01\x00\x44\xe4' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.GetFontPath._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetFontPath._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetFontPath._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetFontPath._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) def testPackReply1(self): bin = request.GetFontPath._reply.to_binary(*(), **self.reply_args_1) - try: - assert bin == self.reply_bin_1 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_1) def testUnpackReply1(self): args, remain = request.GetFontPath._reply.parse_binary(self.reply_bin_1, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_1 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_1) -class TestCreatePixmap(unittest.TestCase): +class TestCreatePixmap(EndianTest): def setUp(self): self.req_args_0 = { - 'height': 65515, - 'drawable': 162261202, - 'pid': 926490960, - 'depth': 145, - 'width': 5641, + 'depth': 161, + 'drawable': 749556300, + 'height': 4764, + 'pid': 2004224799, + 'width': 57984, } - self.req_bin_0 = '\x35\x91\x00\x04' '\x37\x39\x21\x50' \ - '\x09\xab\xe8\xd2' '\x16\x09\xff\xeb' + self.req_bin_0 = b'\x35\xa1\x00\x04' b'\x77\x76\x0b\x1f' \ + b'\x2c\xad\x52\x4c' b'\xe2\x80\x12\x9c' def testPackRequest0(self): bin = request.CreatePixmap._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.CreatePixmap._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestFreePixmap(unittest.TestCase): +class TestFreePixmap(EndianTest): def setUp(self): self.req_args_0 = { - 'pixmap': 213012851, + 'pixmap': 1888284001, } - self.req_bin_0 = '\x36\x00\x00\x02' '\x0c\xb2\x51\x73' + self.req_bin_0 = b'\x36\x00\x00\x02' b'\x70\x8c\xed\x61' def testPackRequest0(self): bin = request.FreePixmap._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.FreePixmap._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestCreateGC(unittest.TestCase): +class TestCreateGC(EndianTest): def setUp(self): self.req_args_0 = { - 'cid': 1060658282, - 'drawable': 456876463, - 'attrs': {'dashes': 183, 'fill_rule': 0, 'clip_mask': 620422624, 'plane_mask': 1797423280, 'line_style': 1, 'tile': 77620460, 'arc_mode': 0, 'clip_y_origin': -7419, 'dash_offset': 62459, 'line_width': 50494, 'background': 44336037, 'clip_x_origin': -32045, 'join_style': 2, 'graphics_exposures': 0, 'font': 95118395, 'tile_stipple_y_origin': -17619, 'stipple': 631657813, 'fill_style': 0, 'cap_style': 0, 'subwindow_mode': 0, 'tile_stipple_x_origin': -12494, 'foreground': 2096879871, 'function': 10}, - } - self.req_bin_0 = '\x37\x00\x00\x1b' '\x3f\x38\x5c\x6a' \ - '\x1b\x3b\x61\xaf' '\x00\x7f\xff\xff' \ - '\x0a\x00\x00\x00' '\x6b\x22\x80\xb0' \ - '\x7c\xfb\xd8\xff' '\x02\xa4\x83\xa5' \ - '\xc5\x3e\x00\x00' '\x01\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x02\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x04\xa0\x64\xec' '\x25\xa6\x55\x55' \ - '\xcf\x32\x00\x00' '\xbb\x2d\x00\x00' \ - '\x05\xab\x64\x3b' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x82\xd3\x00\x00' \ - '\xe3\x05\x00\x00' '\x24\xfa\xe5\xe0' \ - '\xf3\xfb\x00\x00' '\xb7\x00\x00\x00' \ - '\x00\x00\x00\x00' + 'attrs': {'stipple': 1424681955, 'background': 338824284, 'subwindow_mode': 0, 'fill_style': 0, 'font': 568001783, 'graphics_exposures': 0, 'tile': 2000996399, 'tile_stipple_x_origin': -25980, 'dashes': 215, 'function': 7, 'foreground': 612071305, 'clip_x_origin': -22581, 'cap_style': 2, 'tile_stipple_y_origin': -23968, 'join_style': 2, 'line_width': 61484, 'dash_offset': 46571, 'clip_y_origin': -14920, 'arc_mode': 0, 'line_style': 2, 'plane_mask': 793618921, 'clip_mask': 605132525, 'fill_rule': 1}, + 'cid': 1476454377, + 'drawable': 1362081172, + } + self.req_bin_0 = b'\x37\x00\x00\x1b' b'\x58\x00\xe7\xe9' \ + b'\x51\x2f\xb5\x94' b'\x00\x7f\xff\xff' \ + b'\x07\x00\x00\x00' b'\x2f\x4d\xa9\xe9' \ + b'\x24\x7b\x77\x89' b'\x14\x32\x0c\x5c' \ + b'\xf0\x2c\x00\x00' b'\x02\x00\x00\x00' \ + b'\x02\x00\x00\x00' b'\x02\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x01\x00\x00\x00' \ + b'\x77\x44\xc8\x2f' b'\x54\xea\xeb\xe3' \ + b'\x9a\x84\x00\x00' b'\xa2\x60\x00\x00' \ + b'\x21\xdb\x04\xf7' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\xa7\xcb\x00\x00' \ + b'\xc5\xb8\x00\x00' b'\x24\x11\x96\xed' \ + b'\xb5\xeb\x00\x00' b'\xd7\x00\x00\x00' \ + b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.CreateGC._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.CreateGC._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestChangeGC(unittest.TestCase): +class TestChangeGC(EndianTest): def setUp(self): self.req_args_0 = { - 'attrs': {'dashes': 249, 'fill_rule': 1, 'clip_mask': 496525721, 'plane_mask': 1467281901, 'line_style': 2, 'tile': 1713935374, 'arc_mode': 0, 'clip_y_origin': -24572, 'dash_offset': 46636, 'line_width': 61036, 'background': 1598773587, 'clip_x_origin': -19725, 'join_style': 1, 'graphics_exposures': 0, 'font': 429323306, 'tile_stipple_y_origin': -11767, 'stipple': 1365263649, 'fill_style': 2, 'cap_style': 1, 'subwindow_mode': 1, 'tile_stipple_x_origin': -23501, 'foreground': 1272378077, 'function': 11}, - 'gc': 518903558, - } - self.req_bin_0 = '\x38\x00\x00\x1a' '\x1e\xed\xd7\x06' \ - '\x00\x7f\xff\xff' '\x0b\x00\x00\x00' \ - '\x57\x74\xf1\xed' '\x4b\xd6\xf2\xdd' \ - '\x5f\x4b\x59\x53' '\xee\x6c\x00\x00' \ - '\x02\x00\x00\x00' '\x01\x00\x00\x00' \ - '\x01\x00\x00\x00' '\x02\x00\x00\x00' \ - '\x01\x00\x00\x00' '\x66\x28\x94\x0e' \ - '\x51\x60\x45\x21' '\xa4\x33\x00\x00' \ - '\xd2\x09\x00\x00' '\x19\x96\xf4\x2a' \ - '\x01\x00\x00\x00' '\x00\x00\x00\x00' \ - '\xb2\xf3\x00\x00' '\xa0\x04\x00\x00' \ - '\x1d\x98\x61\x99' '\xb6\x2c\x00\x00' \ - '\xf9\x00\x00\x00' '\x00\x00\x00\x00' + 'attrs': {'stipple': 1656031462, 'background': 539344312, 'subwindow_mode': 1, 'fill_style': 0, 'font': 347060191, 'graphics_exposures': 1, 'tile': 716372747, 'tile_stipple_x_origin': -24195, 'dashes': 137, 'function': 8, 'foreground': 1049179696, 'clip_x_origin': -32135, 'cap_style': 3, 'tile_stipple_y_origin': -15601, 'join_style': 1, 'line_width': 36097, 'dash_offset': 42536, 'clip_y_origin': -25437, 'arc_mode': 1, 'line_style': 0, 'plane_mask': 1085423224, 'clip_mask': 161650480, 'fill_rule': 0}, + 'gc': 1250995304, + } + self.req_bin_0 = b'\x38\x00\x00\x1a' b'\x4a\x90\xac\x68' \ + b'\x00\x7f\xff\xff' b'\x08\x00\x00\x00' \ + b'\x40\xb2\x3e\x78' b'\x3e\x89\x36\x30' \ + b'\x20\x25\xbd\xb8' b'\x8d\x01\x00\x00' \ + b'\x00\x00\x00\x00' b'\x03\x00\x00\x00' \ + b'\x01\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x2a\xb2\xfb\x0b' \ + b'\x62\xb5\x08\xe6' b'\xa1\x7d\x00\x00' \ + b'\xc3\x0f\x00\x00' b'\x14\xaf\xb7\xdf' \ + b'\x01\x00\x00\x00' b'\x01\x00\x00\x00' \ + b'\x82\x79\x00\x00' b'\x9c\xa3\x00\x00' \ + b'\x09\xa2\x97\x30' b'\xa6\x28\x00\x00' \ + b'\x89\x00\x00\x00' b'\x01\x00\x00\x00' def testPackRequest0(self): bin = request.ChangeGC._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ChangeGC._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestCopyGC(unittest.TestCase): +class TestCopyGC(EndianTest): def setUp(self): self.req_args_0 = { - 'mask': 1039948946, - 'src_gc': 1958847367, - 'dst_gc': 1311353896, + 'dst_gc': 318094523, + 'mask': 923025483, + 'src_gc': 1186604145, } - self.req_bin_0 = '\x39\x00\x00\x04' '\x74\xc1\xa3\x87' \ - '\x4e\x29\xac\x28' '\x3d\xfc\x5c\x92' + self.req_bin_0 = b'\x39\x00\x00\x04' b'\x46\xba\x24\x71' \ + b'\x12\xf5\xbc\xbb' b'\x37\x04\x40\x4b' def testPackRequest0(self): bin = request.CopyGC._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.CopyGC._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestSetDashes(unittest.TestCase): +class TestSetDashes(EndianTest): def setUp(self): self.req_args_0 = { - 'dashes': [169, 241, 158, 238, 173, 159, 182, 139, 139], - 'dash_offset': 51693, - 'gc': 1639787502, + 'dash_offset': 51381, + 'dashes': [160, 138, 206, 221, 138, 219, 181, 191, 154], + 'gc': 759584613, } - self.req_bin_0 = '\x3a\x00\x00\x06' '\x61\xbd\x2b\xee' \ - '\xc9\xed\x00\x09' '\xa9\xf1\x9e\xee' \ - '\xad\x9f\xb6\x8b' '\x8b\x00\x00\x00' + self.req_bin_0 = b'\x3a\x00\x00\x06' b'\x2d\x46\x57\x65' \ + b'\xc8\xb5\x00\x09' b'\xa0\x8a\xce\xdd' \ + b'\x8a\xdb\xb5\xbf' b'\x9a\x00\x00\x00' def testPackRequest0(self): bin = request.SetDashes._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.SetDashes._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestSetClipRectangles(unittest.TestCase): +class TestSetClipRectangles(EndianTest): def setUp(self): self.req_args_0 = { - 'rectangles': [{'height': 59391, 'x': -15430, 'width': 46673, 'y': -3009}, {'height': 9883, 'x': -14046, 'width': 7782, 'y': -24857}], - 'gc': 1105675380, - 'x_origin': -22760, - 'y_origin': -16557, - 'ordering': 3, + 'gc': 1856792138, + 'ordering': 1, + 'rectangles': [{'y': -3797, 'x': -14422, 'height': 26888, 'width': 57581}, {'y': -12431, 'x': -858, 'height': 10384, 'width': 49373}], + 'x_origin': -27444, + 'y_origin': -780, } - self.req_bin_0 = '\x3b\x03\x00\x07' '\x41\xe7\x44\x74' \ - '\xa7\x18\xbf\x53' '\xc3\xba\xf4\x3f' \ - '\xb6\x51\xe7\xff' '\xc9\x22\x9e\xe7' \ - '\x1e\x66\x26\x9b' + self.req_bin_0 = b'\x3b\x01\x00\x07' b'\x6e\xac\x66\x4a' \ + b'\x94\xcc\xfc\xf4' b'\xc7\xaa\xf1\x2b' \ + b'\xe0\xed\x69\x08' b'\xfc\xa6\xcf\x71' \ + b'\xc0\xdd\x28\x90' self.req_args_1 = { + 'gc': 1892892424, + 'ordering': 1, 'rectangles': [], - 'gc': 291514811, - 'x_origin': -29867, - 'y_origin': -10293, - 'ordering': 0, + 'x_origin': -19258, + 'y_origin': -31956, } - self.req_bin_1 = '\x3b\x00\x00\x03' '\x11\x60\x29\xbb' \ - '\x8b\x55\xd7\xcb' + self.req_bin_1 = b'\x3b\x01\x00\x03' b'\x70\xd3\x3f\x08' \ + b'\xb4\xc6\x83\x2c' def testPackRequest0(self): bin = request.SetClipRectangles._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.SetClipRectangles._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackRequest1(self): bin = request.SetClipRectangles._request.to_binary(*(), **self.req_args_1) - try: - assert bin == self.req_bin_1 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_1) def testUnpackRequest1(self): args, remain = request.SetClipRectangles._request.parse_binary(self.req_bin_1, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_1 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_1) -class TestFreeGC(unittest.TestCase): +class TestFreeGC(EndianTest): def setUp(self): self.req_args_0 = { - 'gc': 371787524, + 'gc': 385239625, } - self.req_bin_0 = '\x3c\x00\x00\x02' '\x16\x29\x07\x04' + self.req_bin_0 = b'\x3c\x00\x00\x02' b'\x16\xf6\x4a\x49' def testPackRequest0(self): bin = request.FreeGC._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.FreeGC._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestClearArea(unittest.TestCase): +class TestClearArea(EndianTest): def setUp(self): self.req_args_0 = { - 'exposures': 0, - 'height': 53776, - 'width': 63821, - 'window': 1253992673, - 'x': -1843, - 'y': -32148, + 'exposures': 1, + 'height': 44159, + 'width': 52831, + 'window': 1680227732, + 'x': -2268, + 'y': -19277, } - self.req_bin_0 = '\x3d\x00\x00\x04' '\x4a\xbe\x68\xe1' \ - '\xf8\xcd\x82\x6c' '\xf9\x4d\xd2\x10' + self.req_bin_0 = b'\x3d\x01\x00\x04' b'\x64\x26\x3d\x94' \ + b'\xf7\x24\xb4\xb3' b'\xce\x5f\xac\x7f' def testPackRequest0(self): bin = request.ClearArea._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ClearArea._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestCopyArea(unittest.TestCase): +class TestCopyArea(EndianTest): def setUp(self): self.req_args_0 = { - 'src_drawable': 321720617, - 'dst_drawable': 252019697, - 'src_y': -8372, - 'src_x': -25544, - 'gc': 126071392, - 'width': 49414, - 'height': 61502, - 'dst_x': -19068, - 'dst_y': -4602, - } - self.req_bin_0 = '\x3e\x00\x00\x07' '\x13\x2d\x11\x29' \ - '\x0f\x05\x83\xf1' '\x07\x83\xb2\x60' \ - '\x9c\x38\xdf\x4c' '\xb5\x84\xee\x06' \ - '\xc1\x06\xf0\x3e' + 'dst_drawable': 1578589574, + 'dst_x': -27552, + 'dst_y': -6968, + 'gc': 1741136437, + 'height': 7340, + 'src_drawable': 1855628899, + 'src_x': -24637, + 'src_y': -24026, + 'width': 46214, + } + self.req_bin_0 = b'\x3e\x00\x00\x07' b'\x6e\x9a\xa6\x63' \ + b'\x5e\x17\x5d\x86' b'\x67\xc7\xa2\x35' \ + b'\x9f\xc3\xa2\x26' b'\x94\x60\xe4\xc8' \ + b'\xb4\x86\x1c\xac' def testPackRequest0(self): bin = request.CopyArea._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.CopyArea._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestCopyPlane(unittest.TestCase): +class TestCopyPlane(EndianTest): def setUp(self): self.req_args_0 = { - 'src_drawable': 1988650265, - 'bit_plane': 2052065832, - 'dst_drawable': 2120887972, - 'src_y': -22401, - 'src_x': -4542, - 'gc': 1266180573, - 'width': 41241, - 'height': 33787, - 'dst_x': -24940, - 'dst_y': -13009, - } - self.req_bin_0 = '\x3f\x00\x00\x08' '\x76\x88\x65\x19' \ - '\x7e\x6a\x2e\xa4' '\x4b\x78\x61\xdd' \ - '\xee\x42\xa8\x7f' '\x9e\x94\xcd\x2f' \ - '\xa1\x19\x83\xfb' '\x7a\x50\x0a\x28' + 'bit_plane': 988559210, + 'dst_drawable': 1873029448, + 'dst_x': -25480, + 'dst_y': -26229, + 'gc': 83225989, + 'height': 60447, + 'src_drawable': 821567629, + 'src_x': -4634, + 'src_y': -17345, + 'width': 53771, + } + self.req_bin_0 = b'\x3f\x00\x00\x08' b'\x30\xf8\x20\x8d' \ + b'\x6f\xa4\x29\x48' b'\x04\xf5\xed\x85' \ + b'\xed\xe6\xbc\x3f' b'\x9c\x78\x99\x8b' \ + b'\xd2\x0b\xec\x1f' b'\x3a\xec\x37\x6a' def testPackRequest0(self): bin = request.CopyPlane._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.CopyPlane._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestPolyPoint(unittest.TestCase): +class TestPolyPoint(EndianTest): def setUp(self): self.req_args_0 = { - 'gc': 206266633, - 'points': [{'x': -22449, 'y': -16714}, {'x': -16465, 'y': -12850}, {'x': -19616, 'y': -13131}], - 'drawable': 1008674, - 'coord_mode': 1, + 'coord_mode': 0, + 'drawable': 50884525, + 'gc': 1417476013, + 'points': [{'y': -22768, 'x': -21311}, {'y': -6707, 'x': -5881}, {'y': -25311, 'x': -4217}], } - self.req_bin_0 = '\x40\x01\x00\x06' '\x00\x0f\x64\x22' \ - '\x0c\x4b\x61\x09' '\xa8\x4f\xbe\xb6' \ - '\xbf\xaf\xcd\xce' '\xb3\x60\xcc\xb5' + self.req_bin_0 = b'\x40\x00\x00\x06' b'\x03\x08\x6f\xad' \ + b'\x54\x7c\xf7\xad' b'\xac\xc1\xa7\x10' \ + b'\xe9\x07\xe5\xcd' b'\xef\x87\x9d\x21' def testPackRequest0(self): bin = request.PolyPoint._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.PolyPoint._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestPolyLine(unittest.TestCase): +class TestPolyLine(EndianTest): def setUp(self): self.req_args_0 = { - 'gc': 1355594189, - 'points': [{'x': -11743, 'y': -18781}, {'x': -21373, 'y': -22722}, {'x': -17579, 'y': -13699}, {'x': -26545, 'y': -19353}, {'x': -11779, 'y': -26488}], - 'drawable': 1668889192, 'coord_mode': 1, + 'drawable': 1459319574, + 'gc': 2107068434, + 'points': [{'y': -19712, 'x': -26440}, {'y': -23639, 'x': -22012}, {'y': -30494, 'x': -4445}, {'y': -7428, 'x': -1085}, {'y': -21262, 'x': -23622}], } - self.req_bin_0 = '\x41\x01\x00\x08' '\x63\x79\x3a\x68' \ - '\x50\xcc\xb9\xcd' '\xd2\x21\xb6\xa3' \ - '\xac\x83\xa7\x3e' '\xbb\x55\xca\x7d' \ - '\x98\x4f\xb4\x67' '\xd1\xfd\x98\x88' + self.req_bin_0 = b'\x41\x01\x00\x08' b'\x56\xfb\x73\x16' \ + b'\x7d\x97\x50\x12' b'\x98\xb8\xb3\x00' \ + b'\xaa\x04\xa3\xa9' b'\xee\xa3\x88\xe2' \ + b'\xfb\xc3\xe2\xfc' b'\xa3\xba\xac\xf2' def testPackRequest0(self): bin = request.PolyLine._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.PolyLine._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestPolySegment(unittest.TestCase): +class TestPolySegment(EndianTest): def setUp(self): self.req_args_0 = { - 'segments': [{'y1': -24252, 'y2': -22523, 'x1': -12610, 'x2': -25770}], - 'drawable': 146511635, - 'gc': 53385255, + 'drawable': 59337240, + 'gc': 247760051, + 'segments': [{'y1': -15198, 'x2': -21917, 'x1': -5123, 'y2': -1992}], } - self.req_bin_0 = '\x42\x00\x00\x05' '\x08\xbb\x97\x13' \ - '\x03\x2e\x98\x27' '\xce\xbe\xa1\x44' \ - '\x9b\x56\xa8\x05' + self.req_bin_0 = b'\x42\x00\x00\x05' b'\x03\x89\x6a\x18' \ + b'\x0e\xc4\x84\xb3' b'\xeb\xfd\xc4\xa2' \ + b'\xaa\x63\xf8\x38' def testPackRequest0(self): bin = request.PolySegment._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.PolySegment._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestPolyRectangle(unittest.TestCase): +class TestPolyRectangle(EndianTest): def setUp(self): self.req_args_0 = { - 'drawable': 1927481661, - 'gc': 410140275, - 'rectangles': [{'height': 63567, 'x': -16992, 'width': 11122, 'y': -21320}, {'height': 34652, 'x': -18051, 'width': 59622, 'y': -30426}, {'height': 45646, 'x': -1111, 'width': 46231, 'y': -25261}], + 'drawable': 742422946, + 'gc': 1564604140, + 'rectangles': [{'y': -970, 'x': -4030, 'height': 11958, 'width': 17374}, {'y': -1228, 'x': -13744, 'height': 17653, 'width': 64713}, {'y': -29216, 'x': -31515, 'height': 28735, 'width': 39352}], } - self.req_bin_0 = '\x43\x00\x00\x09' '\x72\xe3\x09\x3d' \ - '\x18\x72\x3e\x73' '\xbd\xa0\xac\xb8' \ - '\x2b\x72\xf8\x4f' '\xb9\x7d\x89\x26' \ - '\xe8\xe6\x87\x5c' '\xfb\xa9\x9d\x53' \ - '\xb4\x97\xb2\x4e' + self.req_bin_0 = b'\x43\x00\x00\x09' b'\x2c\x40\x79\xa2' \ + b'\x5d\x41\xf6\xec' b'\xf0\x42\xfc\x36' \ + b'\x43\xde\x2e\xb6' b'\xca\x50\xfb\x34' \ + b'\xfc\xc9\x44\xf5' b'\x84\xe5\x8d\xe0' \ + b'\x99\xb8\x70\x3f' def testPackRequest0(self): bin = request.PolyRectangle._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.PolyRectangle._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestPolyArc(unittest.TestCase): +class TestPolyArc(EndianTest): def setUp(self): self.req_args_0 = { - 'arcs': [{'height': 37549, 'angle1': -16979, 'x': -4943, 'angle2': -25650, 'width': 65448, 'y': -9205}, {'height': 9322, 'angle1': -20781, 'x': -13865, 'angle2': -8498, 'width': 62173, 'y': -22862}, {'height': 63266, 'angle1': -1231, 'x': -12693, 'angle2': -809, 'width': 63732, 'y': -7550}], - 'drawable': 718777148, - 'gc': 1127021391, + 'arcs': [{'height': 39984, 'width': 28855, 'angle1': -517, 'angle2': -16010, 'y': -22490, 'x': -6999}, {'height': 38043, 'width': 59205, 'angle1': -26540, 'angle2': -24422, 'y': -20146, 'x': -28979}, {'height': 366, 'width': 28833, 'angle1': -15732, 'angle2': -2439, 'y': -9543, 'x': -31314}], + 'drawable': 1732034432, + 'gc': 1156382390, } - self.req_bin_0 = '\x44\x00\x00\x0c' '\x2a\xd7\xab\x3c' \ - '\x43\x2c\xfb\x4f' '\xec\xb1\xdc\x0b' \ - '\xff\xa8\x92\xad' '\xbd\xad\x9b\xce' \ - '\xc9\xd7\xa6\xb2' '\xf2\xdd\x24\x6a' \ - '\xae\xd3\xde\xce' '\xce\x6b\xe2\x82' \ - '\xf8\xf4\xf7\x22' '\xfb\x31\xfc\xd7' + self.req_bin_0 = b'\x44\x00\x00\x0c' b'\x67\x3c\xbf\x80' \ + b'\x44\xec\xfe\xb6' b'\xe4\xa9\xa8\x26' \ + b'\x70\xb7\x9c\x30' b'\xfd\xfb\xc1\x76' \ + b'\x8e\xcd\xb1\x4e' b'\xe7\x45\x94\x9b' \ + b'\x98\x54\xa0\x9a' b'\x85\xae\xda\xb9' \ + b'\x70\xa1\x01\x6e' b'\xc2\x8c\xf6\x79' def testPackRequest0(self): bin = request.PolyArc._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.PolyArc._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestFillPoly(unittest.TestCase): +class TestFillPoly(EndianTest): def setUp(self): self.req_args_0 = { - 'shape': 1, - 'gc': 1070496026, - 'points': [{'x': -18749, 'y': -19415}, {'x': -8904, 'y': -26948}, {'x': -13336, 'y': -9462}], - 'drawable': 1326525185, 'coord_mode': 0, + 'drawable': 423195261, + 'gc': 782225195, + 'points': [{'y': -9194, 'x': -10262}, {'y': -8456, 'x': -1958}, {'y': -10793, 'x': -8617}], + 'shape': 1, } - self.req_bin_0 = '\x45\x00\x00\x07' '\x4f\x11\x2b\x01' \ - '\x3f\xce\x79\x1a' '\x01\x00\x00\x00' \ - '\xb6\xc3\xb4\x29' '\xdd\x38\x96\xbc' \ - '\xcb\xe8\xdb\x0a' + self.req_bin_0 = b'\x45\x00\x00\x07' b'\x19\x39\x72\x7d' \ + b'\x2e\x9f\xcf\x2b' b'\x01\x00\x00\x00' \ + b'\xd7\xea\xdc\x16' b'\xf8\x5a\xde\xf8' \ + b'\xde\x57\xd5\xd7' def testPackRequest0(self): bin = request.FillPoly._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.FillPoly._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestPolyFillRectangle(unittest.TestCase): +class TestPolyFillRectangle(EndianTest): def setUp(self): self.req_args_0 = { - 'drawable': 1708671692, - 'gc': 1965498255, - 'rectangles': [{'height': 36920, 'x': -2965, 'width': 26437, 'y': -3568}, {'height': 44383, 'x': -18327, 'width': 37730, 'y': -26752}], + 'drawable': 267696363, + 'gc': 1545726032, + 'rectangles': [{'y': -11003, 'x': -1676, 'height': 21895, 'width': 60599}, {'y': -22482, 'x': -12349, 'height': 55831, 'width': 43731}], } - self.req_bin_0 = '\x46\x00\x00\x07' '\x65\xd8\x42\xcc' \ - '\x75\x27\x1f\x8f' '\xf4\x6b\xf2\x10' \ - '\x67\x45\x90\x38' '\xb8\x69\x97\x80' \ - '\x93\x62\xad\x5f' + self.req_bin_0 = b'\x46\x00\x00\x07' b'\x0f\xf4\xb8\xeb' \ + b'\x5c\x21\xe8\x50' b'\xf9\x74\xd5\x05' \ + b'\xec\xb7\x55\x87' b'\xcf\xc3\xa8\x2e' \ + b'\xaa\xd3\xda\x17' def testPackRequest0(self): bin = request.PolyFillRectangle._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.PolyFillRectangle._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestPolyFillArc(unittest.TestCase): +class TestPolyFillArc(EndianTest): def setUp(self): self.req_args_0 = { - 'arcs': [{'height': 64114, 'angle1': -28360, 'x': -10754, 'angle2': -6712, 'width': 53819, 'y': -19555}], - 'drawable': 2083870696, - 'gc': 414470877, + 'arcs': [{'height': 20525, 'width': 33490, 'angle1': -10916, 'angle2': -19386, 'y': -22928, 'x': -3276}], + 'drawable': 700537986, + 'gc': 864213787, } - self.req_bin_0 = '\x47\x00\x00\x06' '\x7c\x35\x57\xe8' \ - '\x18\xb4\x52\xdd' '\xd5\xfe\xb3\x9d' \ - '\xd2\x3b\xfa\x72' '\x91\x38\xe5\xc8' + self.req_bin_0 = b'\x47\x00\x00\x06' b'\x29\xc1\x5c\x82' \ + b'\x33\x82\xdb\x1b' b'\xf3\x34\xa6\x70' \ + b'\x82\xd2\x50\x2d' b'\xd5\x5c\xb4\x46' def testPackRequest0(self): bin = request.PolyFillArc._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.PolyFillArc._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestPutImage(unittest.TestCase): +class TestPutImage(EndianTest): def setUp(self): self.req_args_0 = { - 'height': 9883, - 'data': 'bit map data', - 'drawable': 1534678783, - 'left_pad': 147, - 'format': 1, - 'dst_x': -3284, - 'gc': 209913475, - 'depth': 173, - 'width': 62850, - 'dst_y': -30693, - } - self.req_bin_0 = '\x48\x01\x00\x09' '\x5b\x79\x56\xff' \ - '\x0c\x83\x06\x83' '\xf5\x82\x26\x9b' \ - '\xf3\x2c\x88\x1b' '\x93\xad\x00\x00' \ - '\x62\x69\x74\x20' '\x6d\x61\x70\x20' \ - '\x64\x61\x74\x61' + 'data': b'\xe9\x10\xf2o\x7f{\xae-\xe6\x18\xce\x83', + 'depth': 172, + 'drawable': 634980240, + 'dst_x': -18991, + 'dst_y': -10980, + 'format': 2, + 'gc': 1190657277, + 'height': 12828, + 'left_pad': 225, + 'width': 8597, + } + self.req_bin_0 = b'\x48\x02\x00\x09' b'\x25\xd9\x07\x90' \ + b'\x46\xf7\xfc\xfd' b'\x21\x95\x32\x1c' \ + b'\xb5\xd1\xd5\x1c' b'\xe1\xac\x00\x00' \ + b'\xe9\x10\xf2\x6f' b'\x7f\x7b\xae\x2d' \ + b'\xe6\x18\xce\x83' def testPackRequest0(self): bin = request.PutImage._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.PutImage._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGetImage(unittest.TestCase): +class TestGetImage(EndianTest): def setUp(self): self.req_args_0 = { - 'height': 42657, - 'plane_mask': 1756278272, - 'drawable': 1329487747, - 'x': -27672, - 'y': -30859, - 'format': 1, - 'width': 58993, - } - self.req_bin_0 = '\x49\x01\x00\x05' '\x4f\x3e\x5f\x83' \ - '\x93\xe8\x87\x75' '\xe6\x71\xa6\xa1' \ - '\x68\xae\xae\x00' + 'drawable': 872105322, + 'format': 2, + 'height': 20170, + 'plane_mask': 616208054, + 'width': 282, + 'x': -14814, + 'y': -5449, + } + self.req_bin_0 = b'\x49\x02\x00\x05' b'\x33\xfb\x45\x6a' \ + b'\xc6\x22\xea\xb7' b'\x01\x1a\x4e\xca' \ + b'\x24\xba\x96\xb6' self.reply_args_0 = { - 'sequence_number': 54997, - 'data': 'this is real ly imag e b-map', - 'visual': 1108632607, + 'data': b'\xeb?:\xa7\xc6\x8b\xc2\x96o-S\xe6\xd6z6\x94\xd7v\xd2R.\xa2\xeaw\t\x13\x95\x85', 'depth': 181, + 'sequence_number': 28429, + 'visual': 1687469773, } - self.reply_bin_0 = '\x01\xb5\xd6\xd5' '\x00\x00\x00\x07' \ - '\x42\x14\x64\x1f' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x74\x68\x69\x73' '\x20\x69\x73\x20' \ - '\x72\x65\x61\x6c' '\x20\x6c\x79\x20' \ - '\x69\x6d\x61\x67' '\x20\x65\x20\x62' \ - '\x2d\x6d\x61\x70' + self.reply_bin_0 = b'\x01\xb5\x6f\x0d' b'\x00\x00\x00\x07' \ + b'\x64\x94\xbe\xcd' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\xeb\x3f\x3a\xa7' b'\xc6\x8b\xc2\x96' \ + b'\x6f\x2d\x53\xe6' b'\xd6\x7a\x36\x94' \ + b'\xd7\x76\xd2\x52' b'\x2e\xa2\xea\x77' \ + b'\x09\x13\x95\x85' def testPackRequest0(self): bin = request.GetImage._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetImage._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetImage._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetImage._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestPolyText8(unittest.TestCase): +class TestPolyText8(EndianTest): def setUp(self): self.req_args_0 = { - 'gc': 1481564777, - 'x': -13548, - 'drawable': 1550998666, - 'items': [{'delta': 2, 'string': 'zoo'}, 16909060, {'delta': 0, 'string': 'ie'}], - 'y': -8902, + 'drawable': 1245573363, + 'gc': 1302861330, + 'items': [{'string': 'zoo', 'delta': 2}, 16909060, {'string': 'ie', 'delta': 0}], + 'x': -11315, + 'y': -22209, } - self.req_bin_0 = '\x4a\x00\x00\x08' '\x5c\x72\x5c\x8a' \ - '\x58\x4e\xe2\x69' '\xcb\x14\xdd\x3a' \ - '\x03\x02\x7a\x6f' '\x6f\xff\x01\x02' \ - '\x03\x04\x02\x00' '\x69\x65\x00\x00' + self.req_bin_0 = b'\x4a\x00\x00\x08' b'\x4a\x3d\xf0\xf3' \ + b'\x4d\xa8\x16\x12' b'\xd3\xcd\xa9\x3f' \ + b'\x03\x02\x7a\x6f' b'\x6f\xff\x01\x02' \ + b'\x03\x04\x02\x00' b'\x69\x65\x00\x00' def testPackRequest0(self): bin = request.PolyText8._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.PolyText8._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestPolyText16(unittest.TestCase): +class TestPolyText16(EndianTest): def setUp(self): self.req_args_0 = { - 'gc': 400697368, - 'x': -31614, - 'drawable': 1591407092, - 'items': [{'delta': 2, 'string': (4131, 18)}, 16909060], - 'y': -2741, + 'drawable': 998620068, + 'gc': 948793778, + 'items': [{'string': (4131, 18), 'delta': 2}, 16909060], + 'x': -18280, + 'y': -10630, } - self.req_bin_0 = '\x4b\x00\x00\x07' '\x5e\xda\xf1\xf4' \ - '\x17\xe2\x28\x18' '\x84\x82\xf5\x4b' \ - '\x02\x02\x10\x23' '\x00\x12\xff\x01' \ - '\x02\x03\x04\x00' + self.req_bin_0 = b'\x4b\x00\x00\x07' b'\x3b\x85\xbb\xa4' \ + b'\x38\x8d\x71\xb2' b'\xb8\x98\xd6\x7a' \ + b'\x02\x02\x10\x23' b'\x00\x12\xff\x01' \ + b'\x02\x03\x04\x00' def testPackRequest0(self): bin = request.PolyText16._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.PolyText16._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestImageText8(unittest.TestCase): +class TestImageText8(EndianTest): def setUp(self): self.req_args_0 = { + 'drawable': 458985805, + 'gc': 1097803335, 'string': 'showme', - 'gc': 1393590305, - 'drawable': 1823595869, - 'x': -16077, - 'y': -4873, + 'x': -17263, + 'y': -6759, } - self.req_bin_0 = '\x4c\x06\x00\x06' '\x6c\xb1\xdd\x5d' \ - '\x53\x10\x80\x21' '\xc1\x33\xec\xf7' \ - '\x73\x68\x6f\x77' '\x6d\x65\x00\x00' + self.req_bin_0 = b'\x4c\x06\x00\x06' b'\x1b\x5b\x91\x4d' \ + b'\x41\x6f\x26\x47' b'\xbc\x91\xe5\x99' \ + b'\x73\x68\x6f\x77' b'\x6d\x65\x00\x00' def testPackRequest0(self): bin = request.ImageText8._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ImageText8._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestImageText16(unittest.TestCase): +class TestImageText16(EndianTest): def setUp(self): self.req_args_0 = { + 'drawable': 1935336610, + 'gc': 2061289059, 'string': (115, 104, 111, 119, 109, 111, 114, 101), - 'gc': 1702299870, - 'drawable': 33607184, - 'x': -21343, - 'y': -24237, + 'x': -6684, + 'y': -8653, } - self.req_bin_0 = '\x4d\x08\x00\x08' '\x02\x00\xce\x10' \ - '\x65\x77\x08\xde' '\xac\xa1\xa1\x53' \ - '\x00\x73\x00\x68' '\x00\x6f\x00\x77' \ - '\x00\x6d\x00\x6f' '\x00\x72\x00\x65' + self.req_bin_0 = b'\x4d\x08\x00\x08' b'\x73\x5a\xe4\xa2' \ + b'\x7a\xdc\xc6\x63' b'\xe5\xe4\xde\x33' \ + b'\x00\x73\x00\x68' b'\x00\x6f\x00\x77' \ + b'\x00\x6d\x00\x6f' b'\x00\x72\x00\x65' def testPackRequest0(self): bin = request.ImageText16._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ImageText16._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestCreateColormap(unittest.TestCase): +class TestCreateColormap(EndianTest): def setUp(self): self.req_args_0 = { - 'mid': 157536683, 'alloc': 0, - 'visual': 813982403, - 'window': 698475631, + 'mid': 1414936748, + 'visual': 609492200, + 'window': 182162564, } - self.req_bin_0 = '\x4e\x00\x00\x04' '\x09\x63\xd1\xab' \ - '\x29\xa1\xe4\x6f' '\x30\x84\x62\xc3' + self.req_bin_0 = b'\x4e\x00\x00\x04' b'\x54\x56\x38\xac' \ + b'\x0a\xdb\x94\x84' b'\x24\x54\x1c\xe8' def testPackRequest0(self): bin = request.CreateColormap._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.CreateColormap._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestFreeColormap(unittest.TestCase): +class TestFreeColormap(EndianTest): def setUp(self): self.req_args_0 = { - 'cmap': 1296514923, + 'cmap': 1106990292, } - self.req_bin_0 = '\x4f\x00\x00\x02' '\x4d\x47\x3f\x6b' + self.req_bin_0 = b'\x4f\x00\x00\x02' b'\x41\xfb\x54\xd4' def testPackRequest0(self): bin = request.FreeColormap._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.FreeColormap._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestCopyColormapAndFree(unittest.TestCase): +class TestCopyColormapAndFree(EndianTest): def setUp(self): self.req_args_0 = { - 'src_cmap': 1049336329, - 'mid': 1237242690, + 'mid': 1425680795, + 'src_cmap': 1359295675, } - self.req_bin_0 = '\x50\x00\x00\x03' '\x49\xbe\xd3\x42' \ - '\x3e\x8b\x9a\x09' + self.req_bin_0 = b'\x50\x00\x00\x03' b'\x54\xfa\x29\x9b' \ + b'\x51\x05\x34\xbb' def testPackRequest0(self): bin = request.CopyColormapAndFree._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.CopyColormapAndFree._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestInstallColormap(unittest.TestCase): +class TestInstallColormap(EndianTest): def setUp(self): self.req_args_0 = { - 'cmap': 1539075582, + 'cmap': 1329917990, } - self.req_bin_0 = '\x51\x00\x00\x02' '\x5b\xbc\x6d\xfe' + self.req_bin_0 = b'\x51\x00\x00\x02' b'\x4f\x44\xf0\x26' def testPackRequest0(self): bin = request.InstallColormap._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.InstallColormap._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestUninstallColormap(unittest.TestCase): +class TestUninstallColormap(EndianTest): def setUp(self): self.req_args_0 = { - 'cmap': 959493342, + 'cmap': 719876845, } - self.req_bin_0 = '\x52\x00\x00\x02' '\x39\x30\xb4\xde' + self.req_bin_0 = b'\x52\x00\x00\x02' b'\x2a\xe8\x72\xed' def testPackRequest0(self): bin = request.UninstallColormap._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.UninstallColormap._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestListInstalledColormaps(unittest.TestCase): +class TestListInstalledColormaps(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 1517864638, + 'window': 200613013, } - self.req_bin_0 = '\x53\x00\x00\x02' '\x5a\x78\xc6\xbe' + self.req_bin_0 = b'\x53\x00\x00\x02' b'\x0b\xf5\x1c\x95' self.reply_args_0 = { - 'cmaps': [2146327722, 1361260227], - 'sequence_number': 61652, + 'cmaps': [1757616530, 2044469232], + 'sequence_number': 49482, } - self.reply_bin_0 = '\x01\x00\xf0\xd4' '\x00\x00\x00\x02' \ - '\x00\x02\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x7f\xee\x5c\xaa' '\x51\x23\x2e\xc3' + self.reply_bin_0 = b'\x01\x00\xc1\x4a' b'\x00\x00\x00\x02' \ + b'\x00\x02\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x68\xc3\x19\x92' b'\x79\xdc\x1f\xf0' def testPackRequest0(self): bin = request.ListInstalledColormaps._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ListInstalledColormaps._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.ListInstalledColormaps._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.ListInstalledColormaps._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestAllocColor(unittest.TestCase): +class TestAllocColor(EndianTest): def setUp(self): self.req_args_0 = { - 'red': 39725, - 'green': 49854, - 'cmap': 523356125, - 'blue': 49580, + 'blue': 14978, + 'cmap': 504442007, + 'green': 20599, + 'red': 44348, } - self.req_bin_0 = '\x54\x00\x00\x04' '\x1f\x31\xc7\xdd' \ - '\x9b\x2d\xc2\xbe' '\xc1\xac\x00\x00' + self.req_bin_0 = b'\x54\x00\x00\x04' b'\x1e\x11\x2c\x97' \ + b'\xad\x3c\x50\x77' b'\x3a\x82\x00\x00' self.reply_args_0 = { - 'sequence_number': 10904, - 'red': 43784, - 'green': 3170, - 'pixel': 1067923656, - 'blue': 14525, + 'blue': 1856, + 'green': 9912, + 'pixel': 99308744, + 'red': 13306, + 'sequence_number': 53114, } - self.reply_bin_0 = '\x01\x00\x2a\x98' '\x00\x00\x00\x00' \ - '\xab\x08\x0c\x62' '\x38\xbd\x00\x00' \ - '\x3f\xa7\x38\xc8' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.reply_bin_0 = b'\x01\x00\xcf\x7a' b'\x00\x00\x00\x00' \ + b'\x33\xfa\x26\xb8' b'\x07\x40\x00\x00' \ + b'\x05\xeb\x54\xc8' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.AllocColor._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.AllocColor._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.AllocColor._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.AllocColor._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestAllocNamedColor(unittest.TestCase): +class TestAllocNamedColor(EndianTest): def setUp(self): self.req_args_0 = { - 'cmap': 128217824, + 'cmap': 525860889, 'name': 'octarin', } - self.req_bin_0 = '\x55\x00\x00\x05' '\x07\xa4\x72\xe0' \ - '\x00\x07\x00\x00' '\x6f\x63\x74\x61' \ - '\x72\x69\x6e\x00' + self.req_bin_0 = b'\x55\x00\x00\x05' b'\x1f\x58\x00\x19' \ + b'\x00\x07\x00\x00' b'\x6f\x63\x74\x61' \ + b'\x72\x69\x6e\x00' self.reply_args_0 = { - 'sequence_number': 19971, - 'pixel': 1324239222, - 'screen_green': 50499, - 'screen_red': 33379, - 'exact_green': 29067, - 'exact_blue': 58811, - 'screen_blue': 43109, - 'exact_red': 64213, + 'exact_blue': 50619, + 'exact_green': 55944, + 'exact_red': 40316, + 'pixel': 1020413057, + 'screen_blue': 27416, + 'screen_green': 30102, + 'screen_red': 5028, + 'sequence_number': 64739, } - self.reply_bin_0 = '\x01\x00\x4e\x03' '\x00\x00\x00\x00' \ - '\x4e\xee\x49\x76' '\xfa\xd5\x71\x8b' \ - '\xe5\xbb\x82\x63' '\xc5\x43\xa8\x65' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.reply_bin_0 = b'\x01\x00\xfc\xe3' b'\x00\x00\x00\x00' \ + b'\x3c\xd2\x44\x81' b'\x9d\x7c\xda\x88' \ + b'\xc5\xbb\x13\xa4' b'\x75\x96\x6b\x18' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.AllocNamedColor._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.AllocNamedColor._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.AllocNamedColor._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.AllocNamedColor._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestAllocColorCells(unittest.TestCase): +class TestAllocColorCells(EndianTest): def setUp(self): self.req_args_0 = { - 'planes': 32867, - 'colors': 58698, - 'cmap': 675372338, - 'contiguous': 1, + 'cmap': 1542701632, + 'colors': 45892, + 'contiguous': 0, + 'planes': 25420, } - self.req_bin_0 = '\x56\x01\x00\x03' '\x28\x41\x5d\x32' \ - '\xe5\x4a\x80\x63' + self.req_bin_0 = b'\x56\x00\x00\x03' b'\x5b\xf3\xc2\x40' \ + b'\xb3\x44\x63\x4c' self.reply_args_0 = { - 'masks': [733927381, 1023311668, 595898647], - 'pixels': [693075497, 1294879029, 1478712895, 1781963728, 1442185575, 1654003869, 787619123, 1049825849, 1773935772, 1689075922, 1626562257, 177731275, 661046122, 1970509470, 1918486395, 688539096, 41044851], - 'sequence_number': 54025, - } - self.reply_bin_0 = '\x01\x00\xd3\x09' '\x00\x00\x00\x14' \ - '\x00\x11\x00\x03' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x29\x4f\x7e\x29' '\x4d\x2e\x49\x35' \ - '\x58\x23\x5e\x3f' '\x6a\x36\x9b\xd0' \ - '\x55\xf6\x01\x67' '\x62\x96\x18\x9d' \ - '\x2e\xf2\x1d\x33' '\x3e\x93\x12\x39' \ - '\x69\xbc\x1c\x9c' '\x64\xad\x40\xd2' \ - '\x60\xf3\x5e\xd1' '\x0a\x97\xf6\xcb' \ - '\x27\x66\xc3\x6a' '\x75\x73\x96\x9e' \ - '\x72\x59\xc7\x7b' '\x29\x0a\x45\xd8' \ - '\x02\x72\x4b\x73' '\x2b\xbe\xd7\xd5' \ - '\x3c\xfe\x7f\x34' '\x23\x84\xb1\x17' + 'masks': [1726878301, 2057281944, 1494524694], + 'pixels': [1061732426, 858313521, 524018138, 316972578, 1408939380, 1476723430, 11972931, 1917037904, 1612749468, 1847847580, 1653727126, 1901587588, 228960010, 1671710636, 913060041, 470023299, 377779303], + 'sequence_number': 34200, + } + self.reply_bin_0 = b'\x01\x00\x85\x98' b'\x00\x00\x00\x14' \ + b'\x00\x11\x00\x03' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x3f\x48\xc0\x4a' b'\x33\x28\xd3\x31' \ + b'\x1f\x3b\xe1\xda' b'\x12\xe4\x9e\x22' \ + b'\x53\xfa\xb5\x74' b'\x58\x05\x02\xe6' \ + b'\x00\xb6\xb1\x43' b'\x72\x43\xad\x50' \ + b'\x60\x20\x9a\x9c' b'\x6e\x23\xea\x9c' \ + b'\x62\x91\xdf\x96' b'\x71\x57\xec\x84' \ + b'\x0d\xa5\xa7\x0a' b'\x63\xa4\x47\xac' \ + b'\x36\x6c\x30\xc9' b'\x1c\x03\xfc\x83' \ + b'\x16\x84\x74\x67' b'\x66\xee\x12\x5d' \ + b'\x7a\x9f\xa1\x98' b'\x59\x14\xa3\x16' self.reply_args_1 = { 'masks': [], 'pixels': [], - 'sequence_number': 6273, + 'sequence_number': 30700, } - self.reply_bin_1 = '\x01\x00\x18\x81' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.reply_bin_1 = b'\x01\x00\x77\xec' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.AllocColorCells._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.AllocColorCells._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.AllocColorCells._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.AllocColorCells._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) def testPackReply1(self): bin = request.AllocColorCells._reply.to_binary(*(), **self.reply_args_1) - try: - assert bin == self.reply_bin_1 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_1) def testUnpackReply1(self): args, remain = request.AllocColorCells._reply.parse_binary(self.reply_bin_1, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_1 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_1) -class TestAllocColorPlanes(unittest.TestCase): +class TestAllocColorPlanes(EndianTest): def setUp(self): self.req_args_0 = { - 'red': 22876, - 'colors': 58275, - 'green': 9425, - 'cmap': 308019811, + 'blue': 8209, + 'cmap': 1197085372, + 'colors': 16587, 'contiguous': 0, - 'blue': 23880, + 'green': 55852, + 'red': 60383, } - self.req_bin_0 = '\x57\x00\x00\x04' '\x12\x5c\x02\x63' \ - '\xe3\xa3\x59\x5c' '\x24\xd1\x5d\x48' + self.req_bin_0 = b'\x57\x00\x00\x04' b'\x47\x5a\x12\xbc' \ + b'\x40\xcb\xeb\xdf' b'\xda\x2c\x20\x11' self.reply_args_0 = { - 'green_mask': 265888391, - 'sequence_number': 36175, - 'pixels': [491961865, 1301906366, 1604705021, 1418751120], - 'blue_mask': 44676180, - 'red_mask': 734623206, + 'blue_mask': 1200348460, + 'green_mask': 2121548418, + 'pixels': [980309855, 286409072, 1721094583, 997879295], + 'red_mask': 1140662566, + 'sequence_number': 44006, } - self.reply_bin_0 = '\x01\x00\x8d\x4f' '\x00\x00\x00\x04' \ - '\x00\x04\x00\x00' '\x2b\xc9\x75\xe6' \ - '\x0f\xd9\x22\x87' '\x02\xa9\xb4\x54' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x1d\x52\xbe\x09' '\x4d\x99\x83\xbe' \ - '\x5f\xa5\xda\xfd' '\x54\x90\x6c\x90' + self.reply_bin_0 = b'\x01\x00\xab\xe6' b'\x00\x00\x00\x04' \ + b'\x00\x04\x00\x00' b'\x43\xfd\x21\x26' \ + b'\x7e\x74\x42\x82' b'\x47\x8b\xdd\x2c' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x3a\x6e\x57\x5f' b'\x11\x12\x41\x70' \ + b'\x66\x95\xd1\xb7' b'\x3b\x7a\x6d\xff' def testPackRequest0(self): bin = request.AllocColorPlanes._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.AllocColorPlanes._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.AllocColorPlanes._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.AllocColorPlanes._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestFreeColors(unittest.TestCase): +class TestFreeColors(EndianTest): def setUp(self): self.req_args_0 = { - 'cmap': 727008216, - 'pixels': [61281082, 398475082, 1660604639, 1516738417, 1211104329, 105034864, 884930615, 902914796, 288637231, 2097165249, 1171127263, 1027274519, 806213035, 1485898709, 542709465, 169067149, 1230881159], - 'plane_mask': 1204733200, - } - self.req_bin_0 = '\x58\x00\x00\x14' '\x2b\x55\x43\xd8' \ - '\x47\xce\xc5\x10' '\x03\xa7\x13\x3a' \ - '\x17\xc0\x3f\x4a' '\x62\xfa\xd0\xdf' \ - '\x5a\x67\x97\x71' '\x48\x2f\xfc\x49' \ - '\x06\x42\xb4\x70' '\x34\xbe\xf8\x37' \ - '\x35\xd1\x62\xec' '\x11\x34\x41\x2f' \ - '\x7d\x00\x33\xc1' '\x45\xcd\xfb\xdf' \ - '\x3d\x3a\xf7\x17' '\x30\x0d\xd5\xab' \ - '\x58\x91\x03\xd5' '\x20\x59\x16\xd9' \ - '\x0a\x13\xc2\x8d' '\x49\x5d\xc1\x87' + 'cmap': 341854532, + 'pixels': [1278789650, 681457705, 2040260049, 1621952585, 1914388136, 950484730, 1315726377, 1750278681, 1544694596, 1915664535, 1084068385, 916484334, 1783699241, 1947521244, 1176611597, 957657715, 1926805276], + 'plane_mask': 1597053435, + } + self.req_bin_0 = b'\x58\x00\x00\x14' b'\x14\x60\x49\x44' \ + b'\x5f\x31\x19\xfb' b'\x4c\x38\xc8\x12' \ + b'\x28\x9e\x38\x29' b'\x79\x9b\xe5\xd1' \ + b'\x60\xad\x08\x49' b'\x72\x1b\x3e\xa8' \ + b'\x38\xa7\x3e\xfa' b'\x4e\x6c\x64\x29' \ + b'\x68\x53\x22\x19' b'\x5c\x12\x2b\x44' \ + b'\x72\x2e\xb8\x97' b'\x40\x9d\x92\x21' \ + b'\x36\xa0\x70\xee' b'\x6a\x51\x17\x29' \ + b'\x74\x14\xd0\xdc' b'\x46\x21\xab\x0d' \ + b'\x39\x14\xb2\x73' b'\x72\xd8\xb7\x1c' def testPackRequest0(self): bin = request.FreeColors._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.FreeColors._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestStoreColors(unittest.TestCase): +class TestStoreColors(EndianTest): def setUp(self): self.req_args_0 = { - 'cmap': 501035281, - 'items': [{'red': 27925, 'pixel': 1094971765, 'green': 3673, 'flags': 189, 'blue': 31593}, {'red': 41633, 'pixel': 1330003189, 'green': 56186, 'flags': 178, 'blue': 30263}, {'red': 36007, 'pixel': 1813524037, 'green': 29697, 'flags': 224, 'blue': 14071}, {'red': 45716, 'pixel': 1987610486, 'green': 55405, 'flags': 200, 'blue': 35734}], + 'cmap': 686636594, + 'items': [{'blue': 17242, 'flags': 191, 'green': 29751, 'pixel': 1850111768, 'red': 31364}, {'blue': 50444, 'flags': 252, 'green': 18429, 'pixel': 1803657350, 'red': 42045}, {'blue': 29083, 'flags': 147, 'green': 18252, 'pixel': 1345997556, 'red': 15935}, {'blue': 18063, 'flags': 213, 'green': 15623, 'pixel': 1532391469, 'red': 18981}], } - self.req_bin_0 = '\x59\x00\x00\x0e' '\x1d\xdd\x31\x11' \ - '\x41\x43\xf1\x75' '\x6d\x15\x0e\x59' \ - '\x7b\x69\xbd\x00' '\x4f\x46\x3c\xf5' \ - '\xa2\xa1\xdb\x7a' '\x76\x37\xb2\x00' \ - '\x6c\x18\x2e\x45' '\x8c\xa7\x74\x01' \ - '\x36\xf7\xe0\x00' '\x76\x78\x87\x76' \ - '\xb2\x94\xd8\x6d' '\x8b\x96\xc8\x00' + self.req_bin_0 = b'\x59\x00\x00\x0e' b'\x28\xed\x3e\x32' \ + b'\x6e\x46\x77\x18' b'\x7a\x84\x74\x37' \ + b'\x43\x5a\xbf\x00' b'\x6b\x81\xa0\x86' \ + b'\xa4\x3d\x47\xfd' b'\xc5\x0c\xfc\x00' \ + b'\x50\x3a\x4a\xf4' b'\x3e\x3f\x47\x4c' \ + b'\x71\x9b\x93\x00' b'\x5b\x56\x70\x2d' \ + b'\x4a\x25\x3d\x07' b'\x46\x8f\xd5\x00' def testPackRequest0(self): bin = request.StoreColors._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.StoreColors._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestStoreNamedColor(unittest.TestCase): +class TestStoreNamedColor(EndianTest): def setUp(self): self.req_args_0 = { + 'cmap': 297221571, + 'flags': 148, 'name': 'blue', - 'flags': 186, - 'cmap': 2061119590, - 'pixel': 1846011298, + 'pixel': 323971915, } - self.req_bin_0 = '\x5a\xba\x00\x05' '\x7a\xda\x30\x66' \ - '\x6e\x07\xe5\xa2' '\x00\x04\x00\x00' \ - '\x62\x6c\x75\x65' + self.req_bin_0 = b'\x5a\x94\x00\x05' b'\x11\xb7\x3d\xc3' \ + b'\x13\x4f\x6b\x4b' b'\x00\x04\x00\x00' \ + b'\x62\x6c\x75\x65' def testPackRequest0(self): bin = request.StoreNamedColor._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.StoreNamedColor._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestQueryColors(unittest.TestCase): +class TestQueryColors(EndianTest): def setUp(self): self.req_args_0 = { - 'cmap': 596369797, - 'pixels': [1018587496, 1553480933, 952694607, 341816269, 306591348, 1178729919, 173027853, 875811363], + 'cmap': 875378525, + 'pixels': [496695788, 822627561, 1490311416, 328212337, 1517089095, 459525846, 137995944, 890987562], } - self.req_bin_0 = '\x5b\x00\x00\x0a' '\x23\x8b\xe1\x85' \ - '\x3c\xb6\x69\x68' '\x5c\x98\x3c\xe5' \ - '\x38\xc8\xf7\x4f' '\x14\x5f\xb3\xcd' \ - '\x12\x46\x36\x74' '\x46\x41\xfd\xbf' \ - '\x0a\x50\x32\x0d' '\x34\x33\xd2\x23' + self.req_bin_0 = b'\x5b\x00\x00\x0a' b'\x34\x2d\x37\x5d' \ + b'\x1d\x9a\xf9\xec' b'\x31\x08\x4c\xe9' \ + b'\x58\xd4\x58\xf8' b'\x13\x90\x1f\x71' \ + b'\x5a\x6c\xf1\x47' b'\x1b\x63\xce\xd6' \ + b'\x08\x39\xa6\xa8' b'\x35\x1b\x64\x2a' self.reply_args_0 = { - 'colors': [{'red': 6715, 'blue': 40144, 'green': 56664}, {'red': 5799, 'blue': 22078, 'green': 35523}, {'red': 60111, 'blue': 58654, 'green': 25206}, {'red': 7433, 'blue': 60908, 'green': 14468}, {'red': 31213, 'blue': 9298, 'green': 27481}], - 'sequence_number': 60323, - } - self.reply_bin_0 = '\x01\x00\xeb\xa3' '\x00\x00\x00\x0a' \ - '\x00\x05\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x1a\x3b\xdd\x58' '\x9c\xd0\x00\x00' \ - '\x16\xa7\x8a\xc3' '\x56\x3e\x00\x00' \ - '\xea\xcf\x62\x76' '\xe5\x1e\x00\x00' \ - '\x1d\x09\x38\x84' '\xed\xec\x00\x00' \ - '\x79\xed\x6b\x59' '\x24\x52\x00\x00' + 'colors': [{'blue': 27504, 'green': 30790, 'red': 35816}, {'blue': 54840, 'green': 13811, 'red': 4336}, {'blue': 59555, 'green': 25780, 'red': 27790}, {'blue': 62257, 'green': 38534, 'red': 50705}, {'blue': 56402, 'green': 1536, 'red': 45837}], + 'sequence_number': 57970, + } + self.reply_bin_0 = b'\x01\x00\xe2\x72' b'\x00\x00\x00\x0a' \ + b'\x00\x05\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x8b\xe8\x78\x46' b'\x6b\x70\x00\x00' \ + b'\x10\xf0\x35\xf3' b'\xd6\x38\x00\x00' \ + b'\x6c\x8e\x64\xb4' b'\xe8\xa3\x00\x00' \ + b'\xc6\x11\x96\x86' b'\xf3\x31\x00\x00' \ + b'\xb3\x0d\x06\x00' b'\xdc\x52\x00\x00' self.req_args_1 = { - 'cmap': 79317049, + 'cmap': 710627905, 'pixels': [], } - self.req_bin_1 = '\x5b\x00\x00\x02' '\x04\xba\x48\x39' + self.req_bin_1 = b'\x5b\x00\x00\x02' b'\x2a\x5b\x52\x41' def testPackRequest0(self): bin = request.QueryColors._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.QueryColors._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackRequest1(self): bin = request.QueryColors._request.to_binary(*(), **self.req_args_1) - try: - assert bin == self.req_bin_1 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_1) def testUnpackRequest1(self): args, remain = request.QueryColors._request.parse_binary(self.req_bin_1, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_1 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_1) def testPackReply0(self): bin = request.QueryColors._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.QueryColors._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestLookupColor(unittest.TestCase): +class TestLookupColor(EndianTest): def setUp(self): self.req_args_0 = { - 'cmap': 789574750, + 'cmap': 1644167361, 'name': 'octarin', } - self.req_bin_0 = '\x5c\x00\x00\x05' '\x2f\x0f\xf4\x5e' \ - '\x00\x07\x00\x00' '\x6f\x63\x74\x61' \ - '\x72\x69\x6e\x00' + self.req_bin_0 = b'\x5c\x00\x00\x05' b'\x62\x00\x00\xc1' \ + b'\x00\x07\x00\x00' b'\x6f\x63\x74\x61' \ + b'\x72\x69\x6e\x00' self.reply_args_0 = { - 'sequence_number': 21040, - 'screen_green': 65314, - 'screen_red': 51033, - 'exact_green': 59546, - 'exact_blue': 61512, - 'screen_blue': 29893, - 'exact_red': 41875, + 'exact_blue': 642, + 'exact_green': 31515, + 'exact_red': 25184, + 'screen_blue': 19825, + 'screen_green': 23308, + 'screen_red': 62039, + 'sequence_number': 37984, } - self.reply_bin_0 = '\x01\x00\x52\x30' '\x00\x00\x00\x00' \ - '\xa3\x93\xe8\x9a' '\xf0\x48\xc7\x59' \ - '\xff\x22\x74\xc5' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.reply_bin_0 = b'\x01\x00\x94\x60' b'\x00\x00\x00\x00' \ + b'\x62\x60\x7b\x1b' b'\x02\x82\xf2\x57' \ + b'\x5b\x0c\x4d\x71' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.LookupColor._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.LookupColor._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.LookupColor._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.LookupColor._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestCreateCursor(unittest.TestCase): +class TestCreateCursor(EndianTest): def setUp(self): self.req_args_0 = { - 'x': 14199, - 'fore_red': 65323, - 'back_green': 5090, - 'mask': 420188900, - 'back_blue': 49879, - 'y': 32780, - 'cid': 2022028217, - 'fore_blue': 63540, - 'fore_green': 43028, - 'back_red': 31899, - 'source': 794739749, - } - self.req_bin_0 = '\x5d\x00\x00\x08' '\x78\x85\xb3\xb9' \ - '\x2f\x5e\xc4\x25' '\x19\x0b\x92\xe4' \ - '\xff\x2b\xa8\x14' '\xf8\x34\x7c\x9b' \ - '\x13\xe2\xc2\xd7' '\x37\x77\x80\x0c' + 'back_blue': 49245, + 'back_green': 35528, + 'back_red': 27716, + 'cid': 1618141054, + 'fore_blue': 55026, + 'fore_green': 62740, + 'fore_red': 58690, + 'mask': 1832831050, + 'source': 837555484, + 'x': 48400, + 'y': 36047, + } + self.req_bin_0 = b'\x5d\x00\x00\x08' b'\x60\x72\xdf\x7e' \ + b'\x31\xec\x15\x1c' b'\x6d\x3e\xc8\x4a' \ + b'\xe5\x42\xf5\x14' b'\xd6\xf2\x6c\x44' \ + b'\x8a\xc8\xc0\x5d' b'\xbd\x10\x8c\xcf' def testPackRequest0(self): bin = request.CreateCursor._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.CreateCursor._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestCreateGlyphCursor(unittest.TestCase): +class TestCreateGlyphCursor(EndianTest): def setUp(self): self.req_args_0 = { - 'fore_red': 56306, - 'source_char': 7568, - 'mask': 2018599719, - 'back_blue': 6500, - 'cid': 1999539964, - 'mask_char': 46124, - 'fore_blue': 30793, - 'fore_green': 16989, - 'back_red': 64484, - 'source': 1412345132, - 'back_green': 52966, - } - self.req_bin_0 = '\x5e\x00\x00\x08' '\x77\x2e\x8e\xfc' \ - '\x54\x2e\xad\x2c' '\x78\x51\x63\x27' \ - '\x1d\x90\xb4\x2c' '\xdb\xf2\x42\x5d' \ - '\x78\x49\xfb\xe4' '\xce\xe6\x19\x64' + 'back_blue': 25740, + 'back_green': 2158, + 'back_red': 32083, + 'cid': 1717769345, + 'fore_blue': 28818, + 'fore_green': 18143, + 'fore_red': 14636, + 'mask': 1928100723, + 'mask_char': 32252, + 'source': 1295540602, + 'source_char': 14709, + } + self.req_bin_0 = b'\x5e\x00\x00\x08' b'\x66\x63\x14\x81' \ + b'\x4d\x38\x61\x7a' b'\x72\xec\x7b\x73' \ + b'\x39\x75\x7d\xfc' b'\x39\x2c\x46\xdf' \ + b'\x70\x92\x7d\x53' b'\x08\x6e\x64\x8c' def testPackRequest0(self): bin = request.CreateGlyphCursor._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.CreateGlyphCursor._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestFreeCursor(unittest.TestCase): +class TestFreeCursor(EndianTest): def setUp(self): self.req_args_0 = { - 'cursor': 553262138, + 'cursor': 721898231, } - self.req_bin_0 = '\x5f\x00\x00\x02' '\x20\xfa\x1c\x3a' + self.req_bin_0 = b'\x5f\x00\x00\x02' b'\x2b\x07\x4a\xf7' def testPackRequest0(self): bin = request.FreeCursor._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.FreeCursor._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestRecolorCursor(unittest.TestCase): +class TestRecolorCursor(EndianTest): def setUp(self): self.req_args_0 = { - 'fore_red': 44718, - 'fore_green': 33104, - 'back_blue': 49533, - 'back_green': 12163, - 'fore_blue': 17246, - 'back_red': 64013, - 'cursor': 295995276, + 'back_blue': 55339, + 'back_green': 11072, + 'back_red': 47715, + 'cursor': 1436460699, + 'fore_blue': 26753, + 'fore_green': 52563, + 'fore_red': 44764, } - self.req_bin_0 = '\x60\x00\x00\x05' '\x11\xa4\x87\x8c' \ - '\xae\xae\x81\x50' '\x43\x5e\xfa\x0d' \ - '\x2f\x83\xc1\x7d' + self.req_bin_0 = b'\x60\x00\x00\x05' b'\x55\x9e\xa6\x9b' \ + b'\xae\xdc\xcd\x53' b'\x68\x81\xba\x63' \ + b'\x2b\x40\xd8\x2b' def testPackRequest0(self): bin = request.RecolorCursor._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.RecolorCursor._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestQueryBestSize(unittest.TestCase): +class TestQueryBestSize(EndianTest): def setUp(self): self.req_args_0 = { - 'height': 34743, - 'drawable': 503496990, + 'drawable': 1974766133, + 'height': 64528, 'item_class': 1, - 'width': 27916, + 'width': 8620, } - self.req_bin_0 = '\x61\x01\x00\x03' '\x1e\x02\xc1\x1e' \ - '\x6d\x0c\x87\xb7' + self.req_bin_0 = b'\x61\x01\x00\x03' b'\x75\xb4\x8a\x35' \ + b'\x21\xac\xfc\x10' self.reply_args_0 = { - 'height': 60728, - 'sequence_number': 34070, - 'width': 35970, + 'height': 2023, + 'sequence_number': 41036, + 'width': 35260, } - self.reply_bin_0 = '\x01\x00\x85\x16' '\x00\x00\x00\x00' \ - '\x8c\x82\xed\x38' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.reply_bin_0 = b'\x01\x00\xa0\x4c' b'\x00\x00\x00\x00' \ + b'\x89\xbc\x07\xe7' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.QueryBestSize._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.QueryBestSize._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.QueryBestSize._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.QueryBestSize._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestQueryExtension(unittest.TestCase): +class TestQueryExtension(EndianTest): def setUp(self): self.req_args_0 = { 'name': 'XTRA', } - self.req_bin_0 = '\x62\x00\x00\x03' '\x00\x04\x00\x00' \ - '\x58\x54\x52\x41' + self.req_bin_0 = b'\x62\x00\x00\x03' b'\x00\x04\x00\x00' \ + b'\x58\x54\x52\x41' self.reply_args_0 = { - 'sequence_number': 39952, - 'major_opcode': 195, - 'first_error': 150, + 'first_error': 237, + 'first_event': 149, + 'major_opcode': 134, 'present': 1, - 'first_event': 202, + 'sequence_number': 59692, } - self.reply_bin_0 = '\x01\x00\x9c\x10' '\x00\x00\x00\x00' \ - '\x01\xc3\xca\x96' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.reply_bin_0 = b'\x01\x00\xe9\x2c' b'\x00\x00\x00\x00' \ + b'\x01\x86\x95\xed' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.QueryExtension._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.QueryExtension._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.QueryExtension._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.QueryExtension._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestListExtensions(unittest.TestCase): +class TestListExtensions(EndianTest): def setUp(self): self.req_args_0 = { } - self.req_bin_0 = '\x63\x00\x00\x01' + self.req_bin_0 = b'\x63\x00\x00\x01' self.reply_args_0 = { - 'sequence_number': 20200, 'names': ['XTRA', 'XTRA-II'], + 'sequence_number': 9149, } - self.reply_bin_0 = '\x01\x02\x4e\xe8' '\x00\x00\x00\x04' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x04\x58\x54\x52' '\x41\x07\x58\x54' \ - '\x52\x41\x2d\x49' '\x49\x00\x00\x00' + self.reply_bin_0 = b'\x01\x02\x23\xbd' b'\x00\x00\x00\x04' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x04\x58\x54\x52' b'\x41\x07\x58\x54' \ + b'\x52\x41\x2d\x49' b'\x49\x00\x00\x00' def testPackRequest0(self): bin = request.ListExtensions._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ListExtensions._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.ListExtensions._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.ListExtensions._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) - - -class TestChangeKeyboardMapping(unittest.TestCase): - def setUp(self): - self.req_args_0 = { - 'keysyms': [[707837223, 99294840, 1205405602], [67157514, 879853050, 2059131033], [1139736188, 578113249, 1525786315], [1335349176, 246731334, 277761436], [1386594542, 1676932187, 1862777168], [535892916, 342718655, 195574000], [5712156, 1820472637, 848853860], [1123197289, 1664064022, 94999154], [380150420, 402902535, 1061375041], [510686316, 502245882, 422893644], [1423643601, 194077695, 403885178], [1571826296, 529249772, 623556591], [720045879, 37553034, 955963792], [513407882, 861125615, 219940695], [184890179, 472466494, 1649347894], [1679171989, 1991748404, 1674460475], [1762342934, 276695222, 1941684480], [886658026, 1860690072, 577030090], [227169721, 1390318675, 321524615], [2144591365, 545119116, 404205206]], - 'first_keycode': 250, - } - self.req_bin_0 = '\x64\x14\x00\x3e' '\xfa\x03\x00\x00' \ - '\x2a\x30\xbd\x27' '\x05\xeb\x1e\x78' \ - '\x47\xd9\x07\xa2' '\x04\x00\xbe\x0a' \ - '\x34\x71\x7d\xfa' '\x7a\xbb\xd8\x99' \ - '\x43\xee\xfe\x7c' '\x22\x75\x4e\xe1' \ - '\x5a\xf1\xa6\xcb' '\x4f\x97\xcf\xb8' \ - '\x0e\xb4\xd2\x46' '\x10\x8e\x4d\x9c' \ - '\x52\xa5\xc0\xee' '\x63\xf3\xf4\x5b' \ - '\x6f\x07\xb9\x50' '\x1f\xf1\x13\xb4' \ - '\x14\x6d\x78\xbf' '\x0b\xa8\x38\xf0' \ - '\x00\x57\x29\x1c' '\x6c\x82\x35\x3d' \ - '\x32\x98\x7b\x64' '\x42\xf2\xa1\x69' \ - '\x63\x2f\x9a\x16' '\x05\xa9\x92\x72' \ - '\x16\xa8\xa2\x94' '\x18\x03\xce\x07' \ - '\x3f\x43\x4c\x41' '\x1e\x70\x74\x6c' \ - '\x1d\xef\xa9\xfa' '\x19\x34\xd8\x4c' \ - '\x54\xdb\x13\xd1' '\x0b\x91\x63\xff' \ - '\x18\x12\xcc\x7a' '\x5d\xb0\x2a\x78' \ - '\x1f\x8b\xb5\xec' '\x25\x2a\xb7\xef' \ - '\x2a\xeb\x07\x37' '\x02\x3d\x03\x8a' \ - '\x38\xfa\xd9\x90' '\x1e\x99\xfb\x8a' \ - '\x33\x53\xbb\xef' '\x0d\x1c\x07\x57' \ - '\x0b\x05\x33\x43' '\x1c\x29\x44\x3e' \ - '\x62\x4f\x0d\x36' '\x64\x16\x21\x95' \ - '\x76\xb7\xab\x34' '\x63\xce\x3d\x3b' \ - '\x69\x0b\x38\x16' '\x10\x7e\x08\xb6' \ - '\x73\xbb\xc1\x00' '\x34\xd9\x53\xea' \ - '\x6e\xe7\xe0\x98' '\x22\x64\xc7\xca' \ - '\x0d\x8a\x55\xb9' '\x52\xde\x94\x53' \ - '\x13\x2a\x13\x87' '\x7f\xd3\xde\x05' \ - '\x20\x7d\xdb\x8c' '\x18\x17\xae\x96' + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) + + +class TestChangeKeyboardMapping(EndianTest): + def setUp(self): + self.req_args_0 = { + 'first_keycode': 157, + 'keysyms': [[1861549105, 991489870, 390260112], [107985429, 558681426, 814119353], [702984500, 454537006, 976459372], [701896028, 724776911, 1634728346], [1889012491, 814167346, 597551532], [1614928797, 2042695294, 1786543801], [905303576, 541748982, 1792957544], [175892294, 1009976242, 41625283], [1608517348, 1158393599, 111852976], [2147285698, 2044231981, 751534113], [481513427, 1396173819, 147356828], [1677685199, 2055755177, 1399632465], [86453688, 1619703478, 66636412], [2039275666, 531036848, 428123802], [1802230236, 43765755, 1334308166], [327238597, 512271361, 271057482], [1016964633, 1437651928, 245649464], [1211115441, 2035292716, 468075293], [998652876, 1502089592, 550279151], [1646901134, 792196355, 360324443]], + } + self.req_bin_0 = b'\x64\x14\x00\x3e' b'\x9d\x03\x00\x00' \ + b'\x6e\xf4\xfc\x31' b'\x3b\x18\xef\x4e' \ + b'\x17\x42\xe5\x90' b'\x06\x6f\xba\x15' \ + b'\x21\x4c\xcd\x52' b'\x30\x86\x79\xb9' \ + b'\x29\xe6\xb1\x34' b'\x1b\x17\xaf\x2e' \ + b'\x3a\x33\x96\x6c' b'\x29\xd6\x15\x5c' \ + b'\x2b\x33\x37\xcf' b'\x61\x6f\xf9\x9a' \ + b'\x70\x98\x0b\x0b' b'\x30\x87\x35\x32' \ + b'\x23\x9d\xe9\xac' b'\x60\x41\xdb\x9d' \ + b'\x79\xc1\x0e\x7e' b'\x6a\x7c\x7e\xb9' \ + b'\x35\xf5\xd6\x18' b'\x20\x4a\x6e\xf6' \ + b'\x6a\xde\x5c\x68' b'\x0a\x7b\xe7\x46' \ + b'\x3c\x33\x03\xb2' b'\x02\x7b\x26\xc3' \ + b'\x5f\xe0\x06\xe4' b'\x45\x0b\xae\xff' \ + b'\x06\xaa\xbd\xb0' b'\x7f\xfc\xfa\xc2' \ + b'\x79\xd8\x81\x2d' b'\x2c\xcb\x80\x21' \ + b'\x1c\xb3\x4f\xd3' b'\x53\x37\xeb\xfb' \ + b'\x08\xc8\x7c\x9c' b'\x63\xff\x71\xcf' \ + b'\x7a\x88\x55\xa9' b'\x53\x6c\xb2\x51' \ + b'\x05\x27\x2d\xb8' b'\x60\x8a\xb6\xb6' \ + b'\x03\xf8\xca\x7c' b'\x79\x8c\xe0\x92' \ + b'\x1f\xa6\xfa\xb0' b'\x19\x84\xa6\x9a' \ + b'\x6b\x6b\xd9\xdc' b'\x02\x9b\xcf\xfb' \ + b'\x4f\x87\xed\x46' b'\x13\x81\x43\xc5' \ + b'\x1e\x88\xa4\x01' b'\x10\x28\x02\x4a' \ + b'\x3c\x9d\xa6\x19' b'\x55\xb0\xd3\xd8' \ + b'\x0e\xa4\x50\x38' b'\x48\x30\x27\xb1' \ + b'\x79\x50\x1a\x2c' b'\x1b\xe6\x43\x1d' \ + b'\x3b\x86\x3b\xcc' b'\x59\x88\x11\x78' \ + b'\x20\xcc\x97\xef' b'\x62\x29\xb7\x8e' \ + b'\x2f\x37\xf5\x03' b'\x15\x7a\x1d\x5b' def testPackRequest0(self): bin = request.ChangeKeyboardMapping._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ChangeKeyboardMapping._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGetKeyboardMapping(unittest.TestCase): +class TestGetKeyboardMapping(EndianTest): def setUp(self): self.req_args_0 = { - 'count': 131, - 'first_keycode': 206, + 'count': 207, + 'first_keycode': 169, } - self.req_bin_0 = '\x65\x00\x00\x02' '\xce\x83\x00\x00' + self.req_bin_0 = b'\x65\x00\x00\x02' b'\xa9\xcf\x00\x00' self.reply_args_0 = { - 'keysyms': [[1550369014, 1683205347, 1879538861], [452613596, 1132022246, 357271408], [528724632, 2118423140, 640580111], [1981239140, 195173082, 497130901], [2001675011, 809172000, 1577756130], [739794769, 1774524806, 787951551], [1784021539, 1998872082, 1747812414], [396316053, 1525431160, 1808906812], [1676662850, 1222579650, 1205117622], [396026453, 1956747483, 1762026309], [1222502216, 1488139702, 1799119214], [1504675136, 1414564657, 419659384], [1934768917, 2095924224, 590955729], [582168798, 383228141, 1552516537], [1482483262, 1041896520, 1047041873], [1932705867, 292473490, 226147737], [780322016, 1965031752, 1481062205], [89811542, 1313413666, 686267194], [237776128, 1310737228, 792176733], [849034415, 1592538831, 837355505]], - 'sequence_number': 61409, - } - self.reply_bin_0 = '\x01\x03\xef\xe1' '\x00\x00\x00\x3c' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x5c\x68\xc0\xf6' '\x64\x53\xac\xe3' \ - '\x70\x07\x7c\xad' '\x1a\xfa\x55\xdc' \ - '\x43\x79\x49\xe6' '\x15\x4b\x87\x70' \ - '\x1f\x83\xb2\x98' '\x7e\x44\x92\x64' \ - '\x26\x2e\x7a\x0f' '\x76\x17\x4f\x64' \ - '\x0b\xa2\x1a\xda' '\x1d\xa1\x9d\x95' \ - '\x77\x4f\x23\x03' '\x30\x3a\xfc\x20' \ - '\x5e\x0a\xa5\xe2' '\x2c\x18\x5f\x51' \ - '\x69\xc5\x19\x86' '\x2e\xf7\x2f\xbf' \ - '\x6a\x56\x02\x23' '\x77\x24\x5e\x12' \ - '\x68\x2d\x80\x3e' '\x17\x9f\x4d\x95' \ - '\x5a\xec\x3b\x78' '\x6b\xd1\xba\x3c' \ - '\x63\xef\xd8\x42' '\x48\xdf\x15\xc2' \ - '\x47\xd4\xa2\xb6' '\x17\x9a\xe2\x55' \ - '\x74\xa1\x98\xdb' '\x69\x06\x63\x45' \ - '\x48\xdd\xe7\x48' '\x58\xb3\x35\xb6' \ - '\x6b\x3c\x61\x6e' '\x59\xaf\x85\x40' \ - '\x54\x50\x8b\x31' '\x19\x03\x7e\x78' \ - '\x73\x52\x3b\x15' '\x7c\xed\x44\x00' \ - '\x23\x39\x44\xd1' '\x22\xb3\x30\xde' \ - '\x16\xd7\x98\xed' '\x5c\x89\x85\xb9' \ - '\x58\x5c\xe6\x3e' '\x3e\x1a\x14\x48' \ - '\x3e\x68\x97\x51' '\x73\x32\xc0\x4b' \ - '\x11\x6e\xca\x92' '\x0d\x7a\xbd\x99' \ - '\x2e\x82\xc4\xe0' '\x75\x20\x01\x48' \ - '\x58\x47\x37\x3d' '\x05\x5a\x6a\x56' \ - '\x4e\x49\x1a\x22' '\x28\xe7\x9b\x3a' \ - '\x0e\x2c\x2d\x00' '\x4e\x20\x43\x4c' \ - '\x2f\x37\xa8\x5d' '\x32\x9b\x3c\xaf' \ - '\x5e\xec\x36\xcf' '\x31\xe9\x07\xf1' + 'keysyms': [[232140298, 1242716010, 55143985], [1994770011, 669923085, 1236514049], [1454592222, 1949971307, 2057660497], [805965556, 851808913, 2021792706], [1535482384, 425909956, 163201187], [1271520474, 1483083165, 1783638995], [1346992789, 521515080, 218831382], [1497210568, 1658890074, 647643874], [1825990828, 1469435098, 1289374120], [1729858135, 259963764, 1709884923], [2112789657, 1215330896, 1680696611], [88195295, 745614404, 1144061708], [919934772, 1420606257, 795794911], [148083460, 1086542523, 1390588550], [732788374, 27170279, 1824449766], [902069278, 1765942198, 1052700150], [226642993, 930984408, 2063275595], [777792886, 1364908620, 1914642756], [1779635393, 987282730, 1518933756], [328545991, 935201525, 378251236]], + 'sequence_number': 48346, + } + self.reply_bin_0 = b'\x01\x03\xbc\xda' b'\x00\x00\x00\x3c' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x0d\xd6\x2e\x0a' b'\x4a\x12\x57\x6a' \ + b'\x03\x49\x6e\x31' b'\x76\xe5\xc6\x5b' \ + b'\x27\xee\x37\x0d' b'\x49\xb3\xb5\x01' \ + b'\x56\xb3\x50\xde' b'\x74\x3a\x33\x6b' \ + b'\x7a\xa5\x68\x51' b'\x30\x0a\x0e\xf4' \ + b'\x32\xc5\x92\x91' b'\x78\x82\x1b\xc2' \ + b'\x5b\x85\x9a\x10' b'\x19\x62\xde\xc4' \ + b'\x09\xba\x40\xa3' b'\x4b\xc9\xdc\xda' \ + b'\x58\x66\x0d\x9d' b'\x6a\x50\x2b\xd3' \ + b'\x50\x49\x7a\x95' b'\x1f\x15\xb0\x48' \ + b'\x0d\x0b\x1a\x16' b'\x59\x3d\x9e\xc8' \ + b'\x62\xe0\xa7\x5a' b'\x26\x9a\x42\xe2' \ + b'\x6c\xd6\x68\xac' b'\x57\x95\xcc\xda' \ + b'\x4c\xda\x49\xa8' b'\x67\x1b\x8a\x57' \ + b'\x0f\x7e\xbb\x74' b'\x65\xea\xc5\xfb' \ + b'\x7d\xee\x9c\x99' b'\x48\x70\x7a\x50' \ + b'\x64\x2d\x65\x23' b'\x05\x41\xc0\xdf' \ + b'\x2c\x71\x2c\x44' b'\x44\x30\xff\x0c' \ + b'\x36\xd5\x17\x34' b'\x54\xac\xbb\x31' \ + b'\x2f\x6e\xdd\xdf' b'\x08\xd3\x93\x04' \ + b'\x40\xc3\x52\xbb' b'\x52\xe2\xb2\x86' \ + b'\x2b\xad\x76\x96' b'\x01\x9e\x95\xe7' \ + b'\x6c\xbe\xe4\xe6' b'\x35\xc4\x7c\x1e' \ + b'\x69\x42\x23\xb6' b'\x3e\xbe\xed\xf6' \ + b'\x0d\x82\x4c\x31' b'\x37\x7d\xb1\xd8' \ + b'\x7a\xfb\x16\x4b' b'\x2e\x5c\x2d\x76' \ + b'\x51\x5a\xda\x4c' b'\x72\x1f\x21\x44' \ + b'\x6a\x13\x14\xc1' b'\x3a\xd8\xbd\x2a' \ + b'\x5a\x89\x16\xfc' b'\x13\x95\x36\xc7' \ + b'\x37\xbe\x0a\xf5' b'\x16\x8b\xa7\xe4' def testPackRequest0(self): bin = request.GetKeyboardMapping._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetKeyboardMapping._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetKeyboardMapping._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetKeyboardMapping._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestChangeKeyboardControl(unittest.TestCase): +class TestChangeKeyboardControl(EndianTest): def setUp(self): self.req_args_0 = { - 'attrs': {'key_click_percent': -35, 'bell_percent': -53, 'led_mode': 1, 'bell_pitch': -17390, 'auto_repeat_mode': 2, 'bell_duration': -30281, 'key': 235, 'led': 192}, + 'attrs': {'led': 196, 'auto_repeat_mode': 0, 'bell_pitch': -2303, 'bell_percent': -5, 'key_click_percent': -59, 'key': 190, 'bell_duration': -4223, 'led_mode': 1}, } - self.req_bin_0 = '\x66\x00\x00\x0a' '\x00\x00\x00\xff' \ - '\xdd\x00\x00\x00' '\xcb\x00\x00\x00' \ - '\xbc\x12\x00\x00' '\x89\xb7\x00\x00' \ - '\xc0\x00\x00\x00' '\x01\x00\x00\x00' \ - '\xeb\x00\x00\x00' '\x02\x00\x00\x00' + self.req_bin_0 = b'\x66\x00\x00\x0a' b'\x00\x00\x00\xff' \ + b'\xc5\x00\x00\x00' b'\xfb\x00\x00\x00' \ + b'\xf7\x01\x00\x00' b'\xef\x81\x00\x00' \ + b'\xc4\x00\x00\x00' b'\x01\x00\x00\x00' \ + b'\xbe\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.ChangeKeyboardControl._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ChangeKeyboardControl._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGetKeyboardControl(unittest.TestCase): +class TestGetKeyboardControl(EndianTest): def setUp(self): self.req_args_0 = { } - self.req_bin_0 = '\x67\x00\x00\x01' + self.req_bin_0 = b'\x67\x00\x00\x01' self.reply_args_0 = { - 'key_click_percent': 206, - 'sequence_number': 30149, - 'bell_percent': 251, - 'bell_pitch': 13779, - 'auto_repeats': [217, 171, 167, 167, 243, 163, 129, 239, 168, 153, 225, 199, 189, 155, 228, 149, 148, 237, 139, 150, 211, 133, 135, 250, 191, 166, 146, 212, 239, 183, 214, 250], + 'auto_repeats': [199, 243, 190, 246, 225, 214, 135, 254, 211, 174, 252, 182, 218, 194, 215, 199, 198, 130, 176, 149, 189, 232, 253, 189, 249, 253, 242, 132, 151, 203, 184, 231], + 'bell_duration': 35050, + 'bell_percent': 249, + 'bell_pitch': 36528, 'global_auto_repeat': 0, - 'led_mask': 438224369, - 'bell_duration': 20235, + 'key_click_percent': 222, + 'led_mask': 1425908825, + 'sequence_number': 20323, } - self.reply_bin_0 = '\x01\x00\x75\xc5' '\x00\x00\x00\x05' \ - '\x1a\x1e\xc5\xf1' '\xce\xfb\x35\xd3' \ - '\x4f\x0b\x00\x00' '\xd9\xab\xa7\xa7' \ - '\xf3\xa3\x81\xef' '\xa8\x99\xe1\xc7' \ - '\xbd\x9b\xe4\x95' '\x94\xed\x8b\x96' \ - '\xd3\x85\x87\xfa' '\xbf\xa6\x92\xd4' \ - '\xef\xb7\xd6\xfa' + self.reply_bin_0 = b'\x01\x00\x4f\x63' b'\x00\x00\x00\x05' \ + b'\x54\xfd\xa4\x59' b'\xde\xf9\x8e\xb0' \ + b'\x88\xea\x00\x00' b'\xc7\xf3\xbe\xf6' \ + b'\xe1\xd6\x87\xfe' b'\xd3\xae\xfc\xb6' \ + b'\xda\xc2\xd7\xc7' b'\xc6\x82\xb0\x95' \ + b'\xbd\xe8\xfd\xbd' b'\xf9\xfd\xf2\x84' \ + b'\x97\xcb\xb8\xe7' def testPackRequest0(self): bin = request.GetKeyboardControl._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetKeyboardControl._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetKeyboardControl._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetKeyboardControl._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestBell(unittest.TestCase): +class TestBell(EndianTest): def setUp(self): self.req_args_0 = { - 'percent': -19, + 'percent': -40, } - self.req_bin_0 = '\x68\xed\x00\x01' + self.req_bin_0 = b'\x68\xd8\x00\x01' def testPackRequest0(self): bin = request.Bell._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.Bell._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestChangePointerControl(unittest.TestCase): +class TestChangePointerControl(EndianTest): def setUp(self): self.req_args_0 = { - 'accel_denum': -32484, - 'accel_num': -9346, - 'do_accel': 0, - 'do_thresh': 0, - 'threshold': -8309, + 'accel_denum': -8326, + 'accel_num': -18826, + 'do_accel': 1, + 'do_thresh': 1, + 'threshold': -14733, } - self.req_bin_0 = '\x69\x00\x00\x03' '\xdb\x7e\x81\x1c' \ - '\xdf\x8b\x00\x00' + self.req_bin_0 = b'\x69\x00\x00\x03' b'\xb6\x76\xdf\x7a' \ + b'\xc6\x73\x01\x01' def testPackRequest0(self): bin = request.ChangePointerControl._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ChangePointerControl._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGetPointerControl(unittest.TestCase): +class TestGetPointerControl(EndianTest): def setUp(self): self.req_args_0 = { } - self.req_bin_0 = '\x6a\x00\x00\x01' + self.req_bin_0 = b'\x6a\x00\x00\x01' self.reply_args_0 = { - 'accel_denom': 63793, - 'sequence_number': 59946, - 'threshold': 46060, - 'accel_num': 53419, + 'accel_denom': 18010, + 'accel_num': 29992, + 'sequence_number': 46318, + 'threshold': 20350, } - self.reply_bin_0 = '\x01\x00\xea\x2a' '\x00\x00\x00\x00' \ - '\xd0\xab\xf9\x31' '\xb3\xec\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.reply_bin_0 = b'\x01\x00\xb4\xee' b'\x00\x00\x00\x00' \ + b'\x75\x28\x46\x5a' b'\x4f\x7e\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.GetPointerControl._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetPointerControl._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetPointerControl._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetPointerControl._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestSetScreenSaver(unittest.TestCase): +class TestSetScreenSaver(EndianTest): def setUp(self): self.req_args_0 = { - 'allow_exposures': 0, - 'timeout': -12675, - 'interval': -12318, - 'prefer_blank': 2, + 'allow_exposures': 2, + 'interval': -25214, + 'prefer_blank': 0, + 'timeout': -24531, } - self.req_bin_0 = '\x6b\x00\x00\x03' '\xce\x7d\xcf\xe2' \ - '\x02\x00\x00\x00' + self.req_bin_0 = b'\x6b\x00\x00\x03' b'\xa0\x2d\x9d\x82' \ + b'\x00\x02\x00\x00' def testPackRequest0(self): bin = request.SetScreenSaver._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.SetScreenSaver._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGetScreenSaver(unittest.TestCase): +class TestGetScreenSaver(EndianTest): def setUp(self): self.req_args_0 = { } - self.req_bin_0 = '\x6c\x00\x00\x01' + self.req_bin_0 = b'\x6c\x00\x00\x01' self.reply_args_0 = { - 'allow_exposures': 1, - 'timeout': 1865, - 'sequence_number': 14674, - 'prefer_blanking': 1, - 'interval': 60559, + 'allow_exposures': 0, + 'interval': 8091, + 'prefer_blanking': 0, + 'sequence_number': 12877, + 'timeout': 20935, } - self.reply_bin_0 = '\x01\x00\x39\x52' '\x00\x00\x00\x00' \ - '\x07\x49\xec\x8f' '\x01\x01\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.reply_bin_0 = b'\x01\x00\x32\x4d' b'\x00\x00\x00\x00' \ + b'\x51\xc7\x1f\x9b' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.GetScreenSaver._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetScreenSaver._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetScreenSaver._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetScreenSaver._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestChangeHosts(unittest.TestCase): +class TestChangeHosts(EndianTest): def setUp(self): self.req_args_0 = { - 'host': [188, 226, 135, 199], - 'mode': 1, - 'host_family': 1, + 'host': [183, 251, 198, 200], + 'host_family': 0, + 'mode': 0, } - self.req_bin_0 = '\x6d\x01\x00\x03' '\x01\x00\x00\x04' \ - '\xbc\xe2\x87\xc7' + self.req_bin_0 = b'\x6d\x00\x00\x03' b'\x00\x00\x00\x04' \ + b'\xb7\xfb\xc6\xc8' def testPackRequest0(self): bin = request.ChangeHosts._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ChangeHosts._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestListHosts(unittest.TestCase): +class TestListHosts(EndianTest): def setUp(self): self.req_args_0 = { } - self.req_bin_0 = '\x6e\x00\x00\x01' + self.req_bin_0 = b'\x6e\x00\x00\x01' self.reply_args_0 = { - 'sequence_number': 31662, + 'hosts': [{'name': [34, 23, 178, 12], 'family': 0}, {'name': [130, 236, 254, 15], 'family': 0}], 'mode': 1, - 'hosts': [{'family': 0, 'name': [34, 23, 178, 12]}, {'family': 0, 'name': [130, 236, 254, 15]}], + 'sequence_number': 15164, } - self.reply_bin_0 = '\x01\x01\x7b\xae' '\x00\x00\x00\x04' \ - '\x00\x02\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x04' '\x22\x17\xb2\x0c' \ - '\x00\x00\x00\x04' '\x82\xec\xfe\x0f' + self.reply_bin_0 = b'\x01\x01\x3b\x3c' b'\x00\x00\x00\x04' \ + b'\x00\x02\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x04' b'\x22\x17\xb2\x0c' \ + b'\x00\x00\x00\x04' b'\x82\xec\xfe\x0f' def testPackRequest0(self): bin = request.ListHosts._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ListHosts._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.ListHosts._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.ListHosts._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestSetAccessControl(unittest.TestCase): +class TestSetAccessControl(EndianTest): def setUp(self): self.req_args_0 = { - 'mode': 0, + 'mode': 1, } - self.req_bin_0 = '\x6f\x00\x00\x01' + self.req_bin_0 = b'\x6f\x01\x00\x01' def testPackRequest0(self): bin = request.SetAccessControl._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.SetAccessControl._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestSetCloseDownMode(unittest.TestCase): +class TestSetCloseDownMode(EndianTest): def setUp(self): self.req_args_0 = { 'mode': 0, } - self.req_bin_0 = '\x70\x00\x00\x01' + self.req_bin_0 = b'\x70\x00\x00\x01' def testPackRequest0(self): bin = request.SetCloseDownMode._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.SetCloseDownMode._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestKillClient(unittest.TestCase): +class TestKillClient(EndianTest): def setUp(self): self.req_args_0 = { - 'resource': 1679944210, + 'resource': 649180254, } - self.req_bin_0 = '\x71\x00\x00\x02' '\x64\x21\xea\x12' + self.req_bin_0 = b'\x71\x00\x00\x02' b'\x26\xb1\xb4\x5e' def testPackRequest0(self): bin = request.KillClient._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.KillClient._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestRotateProperties(unittest.TestCase): +class TestRotateProperties(EndianTest): def setUp(self): self.req_args_0 = { - 'delta': -27095, - 'window': 109899869, - 'properties': [1758270592, 1474783027, 1362037883, 19212066, 1095428186, 1435857629, 337040311, 1202859364, 1426187239, 725785004, 1722986690, 435243112], + 'delta': -11867, + 'properties': [30448914, 1520523655, 1147111912, 271900374, 589144637, 97809756, 2092347973, 117159267, 1188394866, 627424198, 1497757970, 2027482546], + 'window': 271248673, } - self.req_bin_0 = '\x72\x00\x00\x0f' '\x06\x8c\xf0\x5d' \ - '\x00\x0c\x96\x29' '\x68\xcd\x14\x80' \ - '\x57\xe7\x67\x33' '\x51\x2f\x0c\x7b' \ - '\x01\x25\x27\x22' '\x41\x4a\xe8\x5a' \ - '\x55\x95\x72\xdd' '\x14\x16\xd3\xb7' \ - '\x47\xb2\x2d\x64' '\x55\x01\xe3\xe7' \ - '\x2b\x42\x99\xac' '\x66\xb2\xb0\xc2' \ - '\x19\xf1\x48\x68' + self.req_bin_0 = b'\x72\x00\x00\x0f' b'\x10\x2a\xed\x21' \ + b'\x00\x0c\xd1\xa5' b'\x01\xd0\x9d\x12' \ + b'\x5a\xa1\x59\x87' b'\x44\x5f\x89\xe8' \ + b'\x10\x34\xde\xd6' b'\x23\x1d\xa2\x3d' \ + b'\x05\xd4\x75\x5c' b'\x7c\xb6\xb2\x45' \ + b'\x06\xfb\xb5\x63' b'\x46\xd5\x77\x72' \ + b'\x25\x65\xbb\xc6' b'\x59\x45\xf9\x12' \ + b'\x78\xd8\xed\xb2' def testPackRequest0(self): bin = request.RotateProperties._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.RotateProperties._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestForceScreenSaver(unittest.TestCase): +class TestForceScreenSaver(EndianTest): def setUp(self): self.req_args_0 = { 'mode': 1, } - self.req_bin_0 = '\x73\x01\x00\x01' + self.req_bin_0 = b'\x73\x01\x00\x01' def testPackRequest0(self): bin = request.ForceScreenSaver._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ForceScreenSaver._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestSetPointerMapping(unittest.TestCase): +class TestSetPointerMapping(EndianTest): def setUp(self): self.req_args_0 = { - 'map': [218, 142, 195, 250, 194], + 'map': [154, 131, 200, 248, 250], } - self.req_bin_0 = '\x74\x05\x00\x03' '\xda\x8e\xc3\xfa' \ - '\xc2\x00\x00\x00' + self.req_bin_0 = b'\x74\x05\x00\x03' b'\x9a\x83\xc8\xf8' \ + b'\xfa\x00\x00\x00' self.reply_args_0 = { - 'sequence_number': 11995, - 'status': 187, + 'sequence_number': 22584, + 'status': 240, } - self.reply_bin_0 = '\x01\xbb\x2e\xdb' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.reply_bin_0 = b'\x01\xf0\x58\x38' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.SetPointerMapping._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.SetPointerMapping._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.SetPointerMapping._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.SetPointerMapping._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestGetPointerMapping(unittest.TestCase): +class TestGetPointerMapping(EndianTest): def setUp(self): self.req_args_0 = { } - self.req_bin_0 = '\x75\x00\x00\x01' + self.req_bin_0 = b'\x75\x00\x00\x01' self.reply_args_0 = { - 'sequence_number': 35825, - 'map': [165, 233, 136, 197, 230], + 'map': [175, 141, 192, 250, 157], + 'sequence_number': 54134, } - self.reply_bin_0 = '\x01\x05\x8b\xf1' '\x00\x00\x00\x02' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\xa5\xe9\x88\xc5' '\xe6\x00\x00\x00' + self.reply_bin_0 = b'\x01\x05\xd3\x76' b'\x00\x00\x00\x02' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\xaf\x8d\xc0\xfa' b'\x9d\x00\x00\x00' def testPackRequest0(self): bin = request.GetPointerMapping._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetPointerMapping._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetPointerMapping._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetPointerMapping._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestSetModifierMapping(unittest.TestCase): +class TestSetModifierMapping(EndianTest): def setUp(self): self.req_args_0 = { - 'keycodes': [[72, 169], [161, 154], [26, 10], [108, 187], [110, 198], [225, 88], [33, 66], [189, 147]], + 'keycodes': [[33, 205], [251, 37], [27, 77], [76, 155], [43, 127], [60, 213], [115, 194], [230, 226]], } - self.req_bin_0 = '\x76\x02\x00\x05' '\x48\xa9\xa1\x9a' \ - '\x1a\x0a\x6c\xbb' '\x6e\xc6\xe1\x58' \ - '\x21\x42\xbd\x93' + self.req_bin_0 = b'\x76\x02\x00\x05' b'\x21\xcd\xfb\x25' \ + b'\x1b\x4d\x4c\x9b' b'\x2b\x7f\x3c\xd5' \ + b'\x73\xc2\xe6\xe2' self.reply_args_0 = { - 'sequence_number': 44526, - 'status': 188, + 'sequence_number': 56627, + 'status': 204, } - self.reply_bin_0 = '\x01\xbc\xad\xee' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' + self.reply_bin_0 = b'\x01\xcc\xdd\x33' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.SetModifierMapping._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.SetModifierMapping._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.SetModifierMapping._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.SetModifierMapping._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestGetModifierMapping(unittest.TestCase): +class TestGetModifierMapping(EndianTest): def setUp(self): self.req_args_0 = { } - self.req_bin_0 = '\x77\x00\x00\x01' + self.req_bin_0 = b'\x77\x00\x00\x01' self.reply_args_0 = { - 'sequence_number': 58377, - 'keycodes': [[3, 183], [213, 173], [9, 97], [35, 60], [249, 78], [175, 62], [237, 11], [26, 119]], + 'keycodes': [[219, 156], [30, 50], [106, 108], [135, 41], [80, 122], [88, 38], [80, 1], [209, 230]], + 'sequence_number': 45434, } - self.reply_bin_0 = '\x01\x02\xe4\x09' '\x00\x00\x00\x04' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x00\x00\x00\x00' '\x00\x00\x00\x00' \ - '\x03\xb7\xd5\xad' '\x09\x61\x23\x3c' \ - '\xf9\x4e\xaf\x3e' '\xed\x0b\x1a\x77' + self.reply_bin_0 = b'\x01\x02\xb1\x7a' b'\x00\x00\x00\x04' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\xdb\x9c\x1e\x32' b'\x6a\x6c\x87\x29' \ + b'\x50\x7a\x58\x26' b'\x50\x01\xd1\xe6' def testPackRequest0(self): bin = request.GetModifierMapping._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetModifierMapping._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetModifierMapping._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetModifierMapping._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestNoOperation(unittest.TestCase): +class TestNoOperation(EndianTest): def setUp(self): self.req_args_0 = { } - self.req_bin_0 = '\x7f\x00\x00\x01' + self.req_bin_0 = b'\x7f\x00\x00\x01' def testPackRequest0(self): bin = request.NoOperation._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.NoOperation._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) if __name__ == "__main__": - check_endian() unittest.main() diff --git a/test/test_requests_le.py b/test/test_requests_le.py index 2d33cd84..1ddfc547 100755 --- a/test/test_requests_le.py +++ b/test/test_requests_le.py @@ -1,625 +1,410 @@ -#!/usr/bin/env python +#!/usr/bin/env python2 import sys, os -sys.path.append(os.path.join(os.path.dirname(__file__), '..')) +sys.path.insert(0, os.path.normpath(os.path.join(__file__, '../..'))) import unittest -from Xlib.protocol import request, rq, event -import Xlib.protocol.event +from Xlib.protocol import request, event +from . import LittleEndianTest as EndianTest +from . import DummyDisplay -import struct -import array - -class CmpArray(object): - def __init__(self, *args, **kws): - self.array = array.array(*args, **kws) - - def __len__(self): - return len(self.array) - - def __getitem__(self, key): - if isinstance(key, slice): - x = key.start - y = key.stop - return list(self.array[x:y]) - else: - return self.array[key] - - def __getattr__(self, attr): - return getattr(self.array, attr) - - def __cmp__(self, other): - return cmp(self.array.tolist(), other) - -rq.array = CmpArray - -def tohex(bin): - bin = ''.join(map(lambda c: '\\x%02x' % ord(c), bin)) - - bins = [] - for i in range(0, len(bin), 16): - bins.append(bin[i:i+16]) - - bins2 = [] - for i in range(0, len(bins), 2): - try: - bins2.append("'%s' '%s'" % (bins[i], bins[i + 1])) - except IndexError: - bins2.append("'%s'" % bins[i]) - - return ' \\\n '.join(bins2) - -class DummyDisplay: - def get_resource_class(self, x): - return None - - event_classes = Xlib.protocol.event.event_class dummy_display = DummyDisplay() -def check_endian(): - if struct.unpack('BB', struct.pack('H', 0x0100))[0] != 0: - sys.stderr.write('Little-endian tests, skipping on this system.\n') - sys.exit(0) - - - -class TestCreateWindow(unittest.TestCase): +class TestCreateWindow(EndianTest): def setUp(self): self.req_args_0 = { - 'wid': 632893089, - 'parent': 563083824, - 'visual': 811875917, - 'height': 62043, - 'width': 55071, - 'depth': 198, - 'attrs': {'cursor': 788158760, 'override_redirect': 1, 'bit_gravity': 6, 'event_mask': 894192179, 'border_pixel': 1365270572, 'background_pixel': 712927020, 'save_under': 0, 'colormap': 980005049, 'do_not_propagate_mask': 667770563, 'backing_store': 1, 'win_gravity': 6, 'backing_planes': 885526468, 'border_pixmap': 513882421, 'backing_pixel': 1693821982, 'background_pixmap': 1314139736}, - 'y': -29423, - 'x': -5822, - 'border_width': 29625, + 'attrs': {'background_pixmap': 1373224142, 'background_pixel': 239147199, 'border_pixmap': 53775720, 'border_pixel': 1592533117, 'bit_gravity': 3, 'win_gravity': 2, 'backing_store': 0, 'backing_planes': 299720948, 'backing_pixel': 1581625428, 'override_redirect': 0, 'save_under': 0, 'event_mask': 1268138548, 'do_not_propagate_mask': 906135756, 'colormap': 68318329, 'cursor': 64054583}, + 'border_width': 13287, + 'depth': 151, + 'height': 37037, + 'parent': 499701004, + 'visual': 1395681732, + 'wid': 469587013, + 'width': 1995, 'window_class': 2, + 'x': -16209, + 'y': -13042, } - self.req_bin_0 = b'\x01\xc6\x17\x00' b'\xa1\x2e\xb9\x25' \ - b'\x30\xfa\x8f\x21' b'\x42\xe9\x11\x8d' \ - b'\x1f\xd7\x5b\xf2' b'\xb9\x73\x02\x00' \ - b'\x4d\x3e\x64\x30' b'\xff\x7f\x00\x00' \ - b'\x58\x2e\x54\x4e' b'\x2c\x67\x7e\x2a' \ - b'\x35\x39\xa1\x1e' b'\x2c\x60\x60\x51' \ - b'\x06\x00\x00\x00' b'\x06\x00\x00\x00' \ - b'\x01\x00\x00\x00' b'\xc4\x0f\xc8\x34' \ - b'\x1e\xac\xf5\x64' b'\x01\x00\x00\x00' \ - b'\x00\x00\x00\x00' b'\x33\x4a\x4c\x35' \ - b'\xc3\x5e\xcd\x27' b'\xb9\xb0\x69\x3a' \ - b'\x28\x59\xfa\x2e' + self.req_bin_0 = b'\x01\x97\x17\x00' b'\x45\x54\xfd\x1b' \ + b'\x0c\xd5\xc8\x1d' b'\xaf\xc0\x0e\xcd' \ + b'\xcb\x07\xad\x90' b'\xe7\x33\x02\x00' \ + b'\xc4\x69\x30\x53' b'\xff\x7f\x00\x00' \ + b'\xce\xbc\xd9\x51' b'\xbf\x18\x41\x0e' \ + b'\x68\x8d\x34\x03' b'\x7d\x20\xec\x5e' \ + b'\x03\x00\x00\x00' b'\x02\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\xf4\x60\xdd\x11' \ + b'\x54\xb0\x45\x5e' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x34\x42\x96\x4b' \ + b'\xcc\x88\x02\x36' b'\x79\x74\x12\x04' \ + b'\x37\x65\xd1\x03' def testPackRequest0(self): bin = request.CreateWindow._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.CreateWindow._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestChangeWindowAttributes(unittest.TestCase): +class TestChangeWindowAttributes(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 560274578, - 'attrs': {'cursor': 1238338372, 'override_redirect': 0, 'bit_gravity': 6, 'event_mask': 1980992429, 'border_pixel': 310964771, 'background_pixel': 1268171782, 'save_under': 1, 'colormap': 171538239, 'do_not_propagate_mask': 135558419, 'backing_store': 2, 'win_gravity': 10, 'backing_planes': 252687930, 'border_pixmap': 287169917, 'backing_pixel': 1114685309, 'background_pixmap': 2004887498}, - } - self.req_bin_0 = b'\x02\x00\x12\x00' b'\x92\x1c\x65\x21' \ - b'\xff\x7f\x00\x00' b'\xca\x27\x80\x77' \ - b'\x06\xc4\x96\x4b' b'\x7d\xdd\x1d\x11' \ - b'\x23\xf2\x88\x12' b'\x06\x00\x00\x00' \ - b'\x0a\x00\x00\x00' b'\x02\x00\x00\x00' \ - b'\x3a\xb6\x0f\x0f' b'\x7d\xbf\x70\x42' \ - b'\x00\x00\x00\x00' b'\x01\x00\x00\x00' \ - b'\xad\x8b\x13\x76' b'\x13\x75\x14\x08' \ - b'\x3f\x77\x39\x0a' b'\x44\x8b\xcf\x49' + 'attrs': {'background_pixmap': 1506149446, 'background_pixel': 1170318459, 'border_pixmap': 900977490, 'border_pixel': 473458160, 'bit_gravity': 6, 'win_gravity': 8, 'backing_store': 1, 'backing_planes': 1738304197, 'backing_pixel': 1866873765, 'override_redirect': 0, 'save_under': 0, 'event_mask': 1499308477, 'do_not_propagate_mask': 907623048, 'colormap': 730747963, 'cursor': 596789700}, + 'window': 333955224, + } + self.req_bin_0 = b'\x02\x00\x12\x00' b'\x98\xc0\xe7\x13' \ + b'\xff\x7f\x00\x00' b'\x46\x04\xc6\x59' \ + b'\x7b\xa4\xc1\x45' b'\x52\xd3\xb3\x35' \ + b'\xf0\x65\x38\x1c' b'\x06\x00\x00\x00' \ + b'\x08\x00\x00\x00' b'\x01\x00\x00\x00' \ + b'\xc5\x6a\x9c\x67' b'\xa5\x3b\x46\x6f' \ + b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\xbd\xa1\x5d\x59' b'\x88\x3a\x19\x36' \ + b'\x3b\x54\x8e\x2b' b'\xc4\x49\x92\x23' def testPackRequest0(self): bin = request.ChangeWindowAttributes._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ChangeWindowAttributes._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGetWindowAttributes(unittest.TestCase): +class TestGetWindowAttributes(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 1672572666, + 'window': 462448317, } - self.req_bin_0 = b'\x03\x00\x02\x00' b'\xfa\x6e\xb1\x63' + self.req_bin_0 = b'\x03\x00\x02\x00' b'\xbd\x66\x90\x1b' self.reply_args_0 = { - 'do_not_propagate_mask': 33915, - 'your_event_mask': 172607058, + 'all_event_masks': 1980679760, + 'backing_bit_planes': 1820045833, + 'backing_pixel': 738704824, + 'backing_store': 214, + 'bit_gravity': 152, + 'colormap': 2089815718, + 'do_not_propagate_mask': 5420, + 'map_is_installed': 0, + 'map_state': 245, 'override_redirect': 0, - 'bit_gravity': 128, - 'all_event_masks': 1036583348, 'save_under': 1, - 'visual': 1419731381, - 'map_state': 169, - 'win_class': 16168, - 'backing_bit_planes': 849532878, - 'backing_store': 215, - 'win_gravity': 140, - 'map_is_installed': 1, - 'backing_pixel': 933754009, - 'sequence_number': 38504, - 'colormap': 56062036, - } - self.reply_bin_0 = b'\x01\xd7\x68\x96' b'\x03\x00\x00\x00' \ - b'\xb5\x61\x9f\x54' b'\x28\x3f\x80\x8c' \ - b'\xce\xd7\xa2\x32' b'\x99\xf4\xa7\x37' \ - b'\x01\x01\xa9\x00' b'\x54\x70\x57\x03' \ - b'\xb4\x01\xc9\x3d' b'\x52\xc6\x49\x0a' \ - b'\x7b\x84\x00\x00' + 'sequence_number': 6954, + 'visual': 199235720, + 'win_class': 25154, + 'win_gravity': 219, + 'your_event_mask': 812961929, + } + self.reply_bin_0 = b'\x01\xd6\x2a\x1b' b'\x03\x00\x00\x00' \ + b'\x88\x18\xe0\x0b' b'\x42\x62\x98\xdb' \ + b'\x09\xb2\x7b\x6c' b'\xb8\xbd\x07\x2c' \ + b'\x01\x00\xf5\x00' b'\xa6\x0e\x90\x7c' \ + b'\x50\xc6\x0e\x76' b'\x89\xd0\x74\x30' \ + b'\x2c\x15\x00\x00' def testPackRequest0(self): bin = request.GetWindowAttributes._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetWindowAttributes._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetWindowAttributes._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetWindowAttributes._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestDestroyWindow(unittest.TestCase): +class TestDestroyWindow(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 533632985, + 'window': 1185563768, } - self.req_bin_0 = b'\x04\x00\x02\x00' b'\xd9\x97\xce\x1f' + self.req_bin_0 = b'\x04\x00\x02\x00' b'\x78\x44\xaa\x46' def testPackRequest0(self): bin = request.DestroyWindow._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.DestroyWindow._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestDestroySubWindows(unittest.TestCase): +class TestDestroySubWindows(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 490680451, + 'window': 629661088, } - self.req_bin_0 = b'\x05\x00\x02\x00' b'\x83\x30\x3f\x1d' + self.req_bin_0 = b'\x05\x00\x02\x00' b'\xa0\xdd\x87\x25' def testPackRequest0(self): bin = request.DestroySubWindows._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.DestroySubWindows._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestChangeSaveSet(unittest.TestCase): +class TestChangeSaveSet(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 1974200014, - 'mode': 0, + 'mode': 1, + 'window': 1239919839, } - self.req_bin_0 = b'\x06\x00\x02\x00' b'\xce\xe6\xab\x75' + self.req_bin_0 = b'\x06\x01\x02\x00' b'\xdf\xac\xe7\x49' def testPackRequest0(self): bin = request.ChangeSaveSet._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ChangeSaveSet._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestReparentWindow(unittest.TestCase): +class TestReparentWindow(EndianTest): def setUp(self): self.req_args_0 = { - 'y': -12763, - 'x': -18160, - 'window': 2127670410, - 'parent': 1913134105, + 'parent': 1513122040, + 'window': 413002134, + 'x': -30489, + 'y': -31267, } - self.req_bin_0 = b'\x07\x00\x04\x00' b'\x8a\xac\xd1\x7e' \ - b'\x19\x1c\x08\x72' b'\x10\xb9\x25\xce' + self.req_bin_0 = b'\x07\x00\x04\x00' b'\x96\xe9\x9d\x18' \ + b'\xf8\x68\x30\x5a' b'\xe7\x88\xdd\x85' def testPackRequest0(self): bin = request.ReparentWindow._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ReparentWindow._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestMapWindow(unittest.TestCase): +class TestMapWindow(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 962670079, + 'window': 1420117708, } - self.req_bin_0 = b'\x08\x00\x02\x00' b'\xff\x2d\x61\x39' + self.req_bin_0 = b'\x08\x00\x02\x00' b'\xcc\x46\xa5\x54' def testPackRequest0(self): bin = request.MapWindow._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.MapWindow._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestMapSubwindows(unittest.TestCase): +class TestMapSubwindows(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 447820952, + 'window': 489473351, } - self.req_bin_0 = b'\x09\x00\x02\x00' b'\x98\x34\xb1\x1a' + self.req_bin_0 = b'\x09\x00\x02\x00' b'\x47\xc5\x2c\x1d' def testPackRequest0(self): bin = request.MapSubwindows._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.MapSubwindows._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestUnmapWindow(unittest.TestCase): +class TestUnmapWindow(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 1130502889, + 'window': 1660217157, } - self.req_bin_0 = b'\x0a\x00\x02\x00' b'\xe9\x1a\x62\x43' + self.req_bin_0 = b'\x0a\x00\x02\x00' b'\x45\xe7\xf4\x62' def testPackRequest0(self): bin = request.UnmapWindow._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.UnmapWindow._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestUnmapSubwindows(unittest.TestCase): +class TestUnmapSubwindows(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 2009442907, + 'window': 621521446, } - self.req_bin_0 = b'\x0b\x00\x02\x00' b'\x5b\xaa\xc5\x77' + self.req_bin_0 = b'\x0b\x00\x02\x00' b'\x26\xaa\x0b\x25' def testPackRequest0(self): bin = request.UnmapSubwindows._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.UnmapSubwindows._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestConfigureWindow(unittest.TestCase): +class TestConfigureWindow(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 2092974410, - 'attrs': {'sibling': 1102940930, 'width': 52077, 'y': -11332, 'x': -11514, 'border_width': -6900, 'stack_mode': 4, 'height': 62050}, + 'attrs': {'x': -27539, 'y': -17512, 'width': 39387, 'height': 57679, 'border_width': -14551, 'sibling': 973756745, 'stack_mode': 2}, + 'window': 349362548, } - self.req_bin_0 = b'\x0c\x00\x0a\x00' b'\x4a\x41\xc0\x7c' \ - b'\x7f\x00\x00\x00' b'\x06\xd3\x00\x00' \ - b'\xbc\xd3\x00\x00' b'\x6d\xcb\x00\x00' \ - b'\x62\xf2\x00\x00' b'\x0c\xe5\x00\x00' \ - b'\x02\x8b\xbd\x41' b'\x04\x00\x00\x00' + self.req_bin_0 = b'\x0c\x00\x0a\x00' b'\x74\xd9\xd2\x14' \ + b'\x7f\x00\x00\x00' b'\x6d\x94\x00\x00' \ + b'\x98\xbb\x00\x00' b'\xdb\x99\x00\x00' \ + b'\x4f\xe1\x00\x00' b'\x29\xc7\x00\x00' \ + b'\x49\x59\x0a\x3a' b'\x02\x00\x00\x00' def testPackRequest0(self): bin = request.ConfigureWindow._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ConfigureWindow._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestCirculateWindow(unittest.TestCase): +class TestCirculateWindow(EndianTest): def setUp(self): self.req_args_0 = { - 'direction': 0, - 'window': 1132872732, + 'direction': 1, + 'window': 763003561, } - self.req_bin_0 = b'\x0d\x00\x02\x00' b'\x1c\x44\x86\x43' + self.req_bin_0 = b'\x0d\x01\x02\x00' b'\xa9\x82\x7a\x2d' def testPackRequest0(self): bin = request.CirculateWindow._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.CirculateWindow._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGetGeometry(unittest.TestCase): +class TestGetGeometry(EndianTest): def setUp(self): self.req_args_0 = { - 'drawable': 2036121058, + 'drawable': 449978455, } - self.req_bin_0 = b'\x0e\x00\x02\x00' b'\xe2\xbd\x5c\x79' + self.req_bin_0 = b'\x0e\x00\x02\x00' b'\x57\x20\xd2\x1a' self.reply_args_0 = { - 'width': 65264, - 'depth': 253, - 'y': -12126, - 'x': -29040, - 'border_width': 19896, - 'root': 493091314, - 'sequence_number': 36173, - 'height': 9014, - } - self.reply_bin_0 = b'\x01\xfd\x4d\x8d' b'\x00\x00\x00\x00' \ - b'\xf2\xf9\x63\x1d' b'\x90\x8e\xa2\xd0' \ - b'\xf0\xfe\x36\x23' b'\xb8\x4d\x00\x00' \ + 'border_width': 41869, + 'depth': 196, + 'height': 40176, + 'root': 2011515940, + 'sequence_number': 46250, + 'width': 4935, + 'x': -10370, + 'y': -11534, + } + self.reply_bin_0 = b'\x01\xc4\xaa\xb4' b'\x00\x00\x00\x00' \ + b'\x24\x4c\xe5\x77' b'\x7e\xd7\xf2\xd2' \ + b'\x47\x13\xf0\x9c' b'\x8d\xa3\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.GetGeometry._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetGeometry._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetGeometry._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetGeometry._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestQueryTree(unittest.TestCase): +class TestQueryTree(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 884880831, + 'window': 367582976, } - self.req_bin_0 = b'\x0f\x00\x02\x00' b'\xbf\x35\xbe\x34' + self.req_bin_0 = b'\x0f\x00\x02\x00' b'\x00\xdf\xe8\x15' self.reply_args_0 = { - 'parent': 701348115, - 'root': 400550453, - 'children': [1089242139, 925689046, 1668140638, 775016596, 1024466546, 1245533043, 1733661379], - 'sequence_number': 10033, + 'children': [1147122179, 1565853418, 525792997, 350969719, 992761785, 814939899, 579774073], + 'parent': 1374454548, + 'root': 1987327953, + 'sequence_number': 65105, } - self.reply_bin_0 = b'\x01\x00\x31\x27' b'\x07\x00\x00\x00' \ - b'\x35\xea\xdf\x17' b'\x13\xb9\xcd\x29' \ + self.reply_bin_0 = b'\x01\x00\x51\xfe' b'\x07\x00\x00\x00' \ + b'\xd1\x37\x74\x76' b'\x14\x83\xec\x51' \ b'\x07\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ - b'\x1b\x84\xec\x40' b'\xd6\xe4\x2c\x37' \ - b'\x5e\xce\x6d\x63' b'\x94\xd0\x31\x2e' \ - b'\x72\x1e\x10\x3d' b'\x73\x53\x3d\x4a' \ - b'\xc3\x92\x55\x67' + b'\x03\xb2\x5f\x44' b'\xea\x06\x55\x5d' \ + b'\xe5\xf6\x56\x1f' b'\x77\x5f\xeb\x14' \ + b'\xb9\x57\x2c\x3b' b'\xfb\xfe\x92\x30' \ + b'\x79\xa6\x8e\x22' def testPackRequest0(self): bin = request.QueryTree._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.QueryTree._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.QueryTree._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.QueryTree._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestInternAtom(unittest.TestCase): +class TestInternAtom(EndianTest): def setUp(self): self.req_args_0 = { 'name': 'fuzzy_prop', @@ -630,64 +415,46 @@ def setUp(self): b'\x6f\x70\x00\x00' self.reply_args_0 = { - 'sequence_number': 14401, - 'atom': 1112752381, + 'atom': 696457407, + 'sequence_number': 45122, } - self.reply_bin_0 = b'\x01\x00\x41\x38' b'\x00\x00\x00\x00' \ - b'\xfd\x40\x53\x42' b'\x00\x00\x00\x00' \ + self.reply_bin_0 = b'\x01\x00\x42\xb0' b'\x00\x00\x00\x00' \ + b'\xbf\x18\x83\x29' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.InternAtom._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.InternAtom._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.InternAtom._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.InternAtom._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestGetAtomName(unittest.TestCase): +class TestGetAtomName(EndianTest): def setUp(self): self.req_args_0 = { - 'atom': 1234624354, + 'atom': 1810076242, } - self.req_bin_0 = b'\x11\x00\x02\x00' b'\x62\xdf\x96\x49' + self.req_bin_0 = b'\x11\x00\x02\x00' b'\x52\x92\xe3\x6b' self.reply_args_0 = { 'name': 'WM_CLASS', - 'sequence_number': 2504, + 'sequence_number': 50608, } - self.reply_bin_0 = b'\x01\x00\xc8\x09' b'\x02\x00\x00\x00' \ + self.reply_bin_0 = b'\x01\x00\xb0\xc5' b'\x02\x00\x00\x00' \ b'\x08\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ @@ -696,133 +463,115 @@ def setUp(self): def testPackRequest0(self): bin = request.GetAtomName._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetAtomName._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetAtomName._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetAtomName._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestChangeProperty(unittest.TestCase): +class TestChangeProperty(EndianTest): def setUp(self): self.req_args_0 = { - 'type': 1211092921, - 'window': 1252285733, - 'property': 237459721, - 'data': (8, ''), - 'mode': 2, + 'data': (8, b''), + 'mode': 0, + 'property': 1764873173, + 'type': 69000273, + 'window': 491942524, } - self.req_bin_0 = b'\x12\x02\x06\x00' b'\x25\x5d\xa4\x4a' \ - b'\x09\x59\x27\x0e' b'\xb9\xcf\x2f\x48' \ + self.req_bin_0 = b'\x12\x00\x06\x00' b'\x7c\x72\x52\x1d' \ + b'\xd5\xd3\x31\x69' b'\x51\xdc\x1c\x04' \ b'\x08\x00\x00\x00' b'\x00\x00\x00\x00' self.req_args_1 = { - 'type': 347282449, - 'window': 25619481, - 'property': 633953573, - 'data': (8, 'foo'), + 'data': (8, b'foo'), 'mode': 1, + 'property': 575034703, + 'type': 142204480, + 'window': 861560365, } - self.req_bin_1 = b'\x12\x01\x07\x00' b'\x19\xec\x86\x01' \ - b'\x25\x5d\xc9\x25' b'\x11\x1c\xb3\x14' \ + self.req_bin_1 = b'\x12\x01\x07\x00' b'\x2d\x5e\x5a\x33' \ + b'\x4f\x55\x46\x22' b'\x40\xde\x79\x08' \ b'\x08\x00\x00\x00' b'\x03\x00\x00\x00' \ b'\x66\x6f\x6f\x00' self.req_args_2 = { - 'type': 1524334051, - 'window': 481797824, - 'property': 658642629, - 'data': (8, 'zoom'), - 'mode': 1, + 'data': (8, b'zoom'), + 'mode': 0, + 'property': 2024948722, + 'type': 1218075423, + 'window': 1961010416, } - self.req_bin_2 = b'\x12\x01\x07\x00' b'\xc0\xa6\xb7\x1c' \ - b'\xc5\x16\x42\x27' b'\xe3\x7d\xdb\x5a' \ + self.req_bin_2 = b'\x12\x00\x07\x00' b'\xf0\xa4\xe2\x74' \ + b'\xf2\x43\xb2\x78' b'\x1f\x5b\x9a\x48' \ b'\x08\x00\x00\x00' b'\x04\x00\x00\x00' \ b'\x7a\x6f\x6f\x6d' self.req_args_3 = { - 'type': 1895805524, - 'window': 211607059, - 'property': 27240430, 'data': (16, []), 'mode': 2, + 'property': 456677559, + 'type': 1407609354, + 'window': 675831147, } - self.req_bin_3 = b'\x12\x02\x06\x00' b'\x13\xde\x9c\x0c' \ - b'\xee\xa7\x9f\x01' b'\x54\xb2\xff\x70' \ + self.req_bin_3 = b'\x12\x02\x06\x00' b'\x6b\x5d\x48\x28' \ + b'\xb7\x58\x38\x1b' b'\x0a\x6a\xe6\x53' \ b'\x10\x00\x00\x00' b'\x00\x00\x00\x00' self.req_args_4 = { - 'type': 549788841, - 'window': 1498238012, - 'property': 1869628209, 'data': (16, [1, 2, 3]), - 'mode': 0, + 'mode': 1, + 'property': 1899908134, + 'type': 1964041522, + 'window': 849678568, } - self.req_bin_4 = b'\x12\x00\x08\x00' b'\x3c\x4c\x4d\x59' \ - b'\x31\x43\x70\x6f' b'\xa9\x1c\xc5\x20' \ + self.req_bin_4 = b'\x12\x01\x08\x00' b'\xe8\x10\xa5\x32' \ + b'\x26\x4c\x3e\x71' b'\x32\xe5\x10\x75' \ b'\x10\x00\x00\x00' b'\x03\x00\x00\x00' \ b'\x01\x00\x02\x00' b'\x03\x00\x00\x00' self.req_args_5 = { - 'type': 1083661140, - 'window': 2019310438, - 'property': 394292367, 'data': (16, [1, 2, 3, 4]), 'mode': 2, + 'property': 306879937, + 'type': 568891375, + 'window': 985442388, } - self.req_bin_5 = b'\x12\x02\x08\x00' b'\x66\x3b\x5c\x78' \ - b'\x8f\x6c\x80\x17' b'\x54\x5b\x97\x40' \ + self.req_bin_5 = b'\x12\x02\x08\x00' b'\x54\xa8\xbc\x3a' \ + b'\xc1\x9d\x4a\x12' b'\xef\x97\xe8\x21' \ b'\x10\x00\x00\x00' b'\x04\x00\x00\x00' \ b'\x01\x00\x02\x00' b'\x03\x00\x04\x00' self.req_args_6 = { - 'type': 761479544, - 'window': 1274166929, - 'property': 1743863777, 'data': (32, []), - 'mode': 2, + 'mode': 0, + 'property': 1599917196, + 'type': 1205594429, + 'window': 529694076, } - self.req_bin_6 = b'\x12\x02\x06\x00' b'\x91\x3e\xf2\x4b' \ - b'\xe1\x3f\xf1\x67' b'\x78\x41\x63\x2d' \ + self.req_bin_6 = b'\x12\x00\x06\x00' b'\x7c\x7d\x92\x1f' \ + b'\x8c\xcc\x5c\x5f' b'\x3d\xe9\xdb\x47' \ b'\x20\x00\x00\x00' b'\x00\x00\x00\x00' self.req_args_7 = { - 'type': 956119085, - 'window': 1018715281, - 'property': 686054590, 'data': (32, [1, 2, 3]), - 'mode': 1, + 'mode': 2, + 'property': 1604265475, + 'type': 1255454396, + 'window': 564298846, } - self.req_bin_7 = b'\x12\x01\x09\x00' b'\x91\x5c\xb8\x3c' \ - b'\xbe\x5c\xe4\x28' b'\x2d\x38\xfd\x38' \ + self.req_bin_7 = b'\x12\x02\x09\x00' b'\x5e\x84\xa2\x21' \ + b'\x03\x26\x9f\x5f' b'\xbc\xb6\xd4\x4a' \ b'\x20\x00\x00\x00' b'\x03\x00\x00\x00' \ b'\x01\x00\x00\x00' b'\x02\x00\x00\x00' \ b'\x03\x00\x00\x00' @@ -830,281 +579,200 @@ def setUp(self): def testPackRequest0(self): bin = request.ChangeProperty._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ChangeProperty._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackRequest1(self): bin = request.ChangeProperty._request.to_binary(*(), **self.req_args_1) - try: - assert bin == self.req_bin_1 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_1) def testUnpackRequest1(self): args, remain = request.ChangeProperty._request.parse_binary(self.req_bin_1, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_1 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_1) def testPackRequest2(self): bin = request.ChangeProperty._request.to_binary(*(), **self.req_args_2) - try: - assert bin == self.req_bin_2 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_2) def testUnpackRequest2(self): args, remain = request.ChangeProperty._request.parse_binary(self.req_bin_2, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_2 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_2) def testPackRequest3(self): bin = request.ChangeProperty._request.to_binary(*(), **self.req_args_3) - try: - assert bin == self.req_bin_3 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_3) def testUnpackRequest3(self): args, remain = request.ChangeProperty._request.parse_binary(self.req_bin_3, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_3 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_3) def testPackRequest4(self): bin = request.ChangeProperty._request.to_binary(*(), **self.req_args_4) - try: - assert bin == self.req_bin_4 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_4) def testUnpackRequest4(self): args, remain = request.ChangeProperty._request.parse_binary(self.req_bin_4, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_4 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_4) def testPackRequest5(self): bin = request.ChangeProperty._request.to_binary(*(), **self.req_args_5) - try: - assert bin == self.req_bin_5 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_5) def testUnpackRequest5(self): args, remain = request.ChangeProperty._request.parse_binary(self.req_bin_5, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_5 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_5) def testPackRequest6(self): bin = request.ChangeProperty._request.to_binary(*(), **self.req_args_6) - try: - assert bin == self.req_bin_6 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_6) def testUnpackRequest6(self): args, remain = request.ChangeProperty._request.parse_binary(self.req_bin_6, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_6 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_6) def testPackRequest7(self): bin = request.ChangeProperty._request.to_binary(*(), **self.req_args_7) - try: - assert bin == self.req_bin_7 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_7) def testUnpackRequest7(self): args, remain = request.ChangeProperty._request.parse_binary(self.req_bin_7, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_7 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_7) -class TestDeleteProperty(unittest.TestCase): +class TestDeleteProperty(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 1858113940, - 'property': 754854074, + 'property': 1928125498, + 'window': 920120163, } - self.req_bin_0 = b'\x13\x00\x03\x00' b'\x94\x91\xc0\x6e' \ - b'\xba\x28\xfe\x2c' + self.req_bin_0 = b'\x13\x00\x03\x00' b'\x63\xeb\xd7\x36' \ + b'\x3a\xdc\xec\x72' def testPackRequest0(self): bin = request.DeleteProperty._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.DeleteProperty._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGetProperty(unittest.TestCase): +class TestGetProperty(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 1675634394, - 'long_offset': 11483536, - 'property': 1943700626, - 'type': 223769899, - 'long_length': 1748032051, - 'delete': 0, + 'delete': 1, + 'long_length': 297130690, + 'long_offset': 2142261240, + 'property': 471053276, + 'type': 2141806322, + 'window': 777446987, } - self.req_bin_0 = b'\x14\x00\x06\x00' b'\xda\x26\xe0\x63' \ - b'\x92\x84\xda\x73' b'\x2b\x75\x56\x0d' \ - b'\x90\x39\xaf\x00' b'\x33\xda\x30\x68' + self.req_bin_0 = b'\x14\x01\x06\x00' b'\x4b\xe6\x56\x2e' \ + b'\xdc\xb3\x13\x1c' b'\xf2\x5e\xa9\x7f' \ + b'\xf8\x4f\xb0\x7f' b'\xc2\xda\xb5\x11' self.reply_args_0 = { - 'bytes_after': 1264377294, - 'property_type': 1306970370, - 'sequence_number': 34281, - 'value': (8, ''), + 'bytes_after': 195292012, + 'property_type': 1059882735, + 'sequence_number': 33648, + 'value': (8, b''), } - self.reply_bin_0 = b'\x01\x08\xe9\x85' b'\x00\x00\x00\x00' \ - b'\x02\xc9\xe6\x4d' b'\xce\xdd\x5c\x4b' \ + self.reply_bin_0 = b'\x01\x08\x70\x83' b'\x00\x00\x00\x00' \ + b'\xef\x86\x2c\x3f' b'\x6c\xeb\xa3\x0b' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' self.reply_args_1 = { - 'bytes_after': 902042689, - 'property_type': 1846820627, - 'sequence_number': 50371, - 'value': (8, 'foo'), + 'bytes_after': 1849269963, + 'property_type': 101247178, + 'sequence_number': 49786, + 'value': (8, b'foo'), } - self.reply_bin_1 = b'\x01\x08\xc3\xc4' b'\x01\x00\x00\x00' \ - b'\x13\x3f\x14\x6e' b'\x41\x14\xc4\x35' \ + self.reply_bin_1 = b'\x01\x08\x7a\xc2' b'\x01\x00\x00\x00' \ + b'\xca\xe8\x08\x06' b'\xcb\x9e\x39\x6e' \ b'\x03\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x66\x6f\x6f\x00' self.reply_args_2 = { - 'bytes_after': 1782597051, - 'property_type': 1613677639, - 'sequence_number': 58679, - 'value': (8, 'zoom'), + 'bytes_after': 1347495650, + 'property_type': 328289775, + 'sequence_number': 7441, + 'value': (8, b'zoom'), } - self.reply_bin_2 = b'\x01\x08\x37\xe5' b'\x01\x00\x00\x00' \ - b'\x47\xc4\x2e\x60' b'\xbb\x45\x40\x6a' \ + self.reply_bin_2 = b'\x01\x08\x11\x1d' b'\x01\x00\x00\x00' \ + b'\xef\x4d\x91\x13' b'\xe2\x26\x51\x50' \ b'\x04\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x7a\x6f\x6f\x6d' self.reply_args_3 = { - 'bytes_after': 1107167742, - 'property_type': 1964967674, - 'sequence_number': 49647, + 'bytes_after': 1461387818, + 'property_type': 1701043014, + 'sequence_number': 10740, 'value': (16, []), } - self.reply_bin_3 = b'\x01\x10\xef\xc1' b'\x00\x00\x00\x00' \ - b'\xfa\x06\x1f\x75' b'\xfe\x09\xfe\x41' \ + self.reply_bin_3 = b'\x01\x10\xf4\x29' b'\x00\x00\x00\x00' \ + b'\x46\xdb\x63\x65' b'\x2a\x02\x1b\x57' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' self.reply_args_4 = { - 'bytes_after': 1602466976, - 'property_type': 638663972, - 'sequence_number': 58268, + 'bytes_after': 136490248, + 'property_type': 1280844186, + 'sequence_number': 27922, 'value': (16, [1, 2, 3]), } - self.reply_bin_4 = b'\x01\x10\x9c\xe3' b'\x02\x00\x00\x00' \ - b'\x24\x3d\x11\x26' b'\xa0\xb4\x83\x5f' \ + self.reply_bin_4 = b'\x01\x10\x12\x6d' b'\x02\x00\x00\x00' \ + b'\x9a\x21\x58\x4c' b'\x08\xad\x22\x08' \ b'\x03\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x01\x00\x02\x00' b'\x03\x00\x00\x00' self.reply_args_5 = { - 'bytes_after': 651542717, - 'property_type': 947428838, - 'sequence_number': 26901, + 'bytes_after': 1279726180, + 'property_type': 819586705, + 'sequence_number': 25472, 'value': (16, [1, 2, 3, 4]), } - self.reply_bin_5 = b'\x01\x10\x15\x69' b'\x02\x00\x00\x00' \ - b'\xe6\x9d\x78\x38' b'\xbd\xc0\xd5\x26' \ + self.reply_bin_5 = b'\x01\x10\x80\x63' b'\x02\x00\x00\x00' \ + b'\x91\xe6\xd9\x30' b'\x64\x12\x47\x4c' \ b'\x04\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x01\x00\x02\x00' b'\x03\x00\x04\x00' self.reply_args_6 = { - 'bytes_after': 602498418, - 'property_type': 43558782, - 'sequence_number': 11175, + 'bytes_after': 539973238, + 'property_type': 1136329940, + 'sequence_number': 30930, 'value': (32, []), } - self.reply_bin_6 = b'\x01\x20\xa7\x2b' b'\x00\x00\x00\x00' \ - b'\x7e\xa7\x98\x02' b'\x72\x65\xe9\x23' \ + self.reply_bin_6 = b'\x01\x20\xd2\x78' b'\x00\x00\x00\x00' \ + b'\xd4\x04\xbb\x43' b'\x76\x56\x2f\x20' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' self.reply_args_7 = { - 'bytes_after': 1661909208, - 'property_type': 607057672, - 'sequence_number': 4347, + 'bytes_after': 1848575862, + 'property_type': 1188109101, + 'sequence_number': 63896, 'value': (32, [1, 2, 3]), } - self.reply_bin_7 = b'\x01\x20\xfb\x10' b'\x03\x00\x00\x00' \ - b'\x08\xf7\x2e\x24' b'\xd8\xb8\x0e\x63' \ + self.reply_bin_7 = b'\x01\x20\x98\xf9' b'\x03\x00\x00\x00' \ + b'\x2d\x1b\xd1\x46' b'\x76\x07\x2f\x6e' \ b'\x03\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x01\x00\x00\x00' b'\x02\x00\x00\x00' \ @@ -1113,406 +781,262 @@ def setUp(self): def testPackRequest0(self): bin = request.GetProperty._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetProperty._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetProperty._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetProperty._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) def testPackReply1(self): bin = request.GetProperty._reply.to_binary(*(), **self.reply_args_1) - try: - assert bin == self.reply_bin_1 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_1) def testUnpackReply1(self): args, remain = request.GetProperty._reply.parse_binary(self.reply_bin_1, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_1 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_1) def testPackReply2(self): bin = request.GetProperty._reply.to_binary(*(), **self.reply_args_2) - try: - assert bin == self.reply_bin_2 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_2) def testUnpackReply2(self): args, remain = request.GetProperty._reply.parse_binary(self.reply_bin_2, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_2 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_2) def testPackReply3(self): bin = request.GetProperty._reply.to_binary(*(), **self.reply_args_3) - try: - assert bin == self.reply_bin_3 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_3) def testUnpackReply3(self): args, remain = request.GetProperty._reply.parse_binary(self.reply_bin_3, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_3 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_3) def testPackReply4(self): bin = request.GetProperty._reply.to_binary(*(), **self.reply_args_4) - try: - assert bin == self.reply_bin_4 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_4) def testUnpackReply4(self): args, remain = request.GetProperty._reply.parse_binary(self.reply_bin_4, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_4 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_4) def testPackReply5(self): bin = request.GetProperty._reply.to_binary(*(), **self.reply_args_5) - try: - assert bin == self.reply_bin_5 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_5) def testUnpackReply5(self): args, remain = request.GetProperty._reply.parse_binary(self.reply_bin_5, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_5 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_5) def testPackReply6(self): bin = request.GetProperty._reply.to_binary(*(), **self.reply_args_6) - try: - assert bin == self.reply_bin_6 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_6) def testUnpackReply6(self): args, remain = request.GetProperty._reply.parse_binary(self.reply_bin_6, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_6 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_6) def testPackReply7(self): bin = request.GetProperty._reply.to_binary(*(), **self.reply_args_7) - try: - assert bin == self.reply_bin_7 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_7) def testUnpackReply7(self): args, remain = request.GetProperty._reply.parse_binary(self.reply_bin_7, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_7 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_7) -class TestListProperties(unittest.TestCase): +class TestListProperties(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 1002132678, + 'window': 2023920407, } - self.req_bin_0 = b'\x15\x00\x02\x00' b'\xc6\x54\xbb\x3b' + self.req_bin_0 = b'\x15\x00\x02\x00' b'\x17\x93\xa2\x78' self.reply_args_0 = { - 'sequence_number': 58554, - 'atoms': [497337753, 1561366096, 1429910722, 371682445, 1693790956, 124266489, 819023111, 1575252239, 1958056613, 76461795, 2044963121, 1187630009, 890357857, 639310702, 1708479530, 336050724, 1163834063, 1164094286, 1626309474, 136351014, 1163110454, 1416739018, 1380223836], + 'atoms': [24720840, 1460963027, 1547803868, 246063525, 1464027403, 1900134270, 1153200538, 1612563336, 573068260, 1650618737, 1376520521, 730586807, 239622004, 630352260, 933716813, 339706725, 974429777, 7034796, 2048369638, 1550746425, 1880945398, 1545568005, 565689201], + 'sequence_number': 63949, } - self.reply_bin_0 = b'\x01\x00\xba\xe4' b'\x17\x00\x00\x00' \ + self.reply_bin_0 = b'\x01\x00\xcd\xf9' b'\x17\x00\x00\x00' \ b'\x17\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ - b'\x99\xc5\xa4\x1d' b'\x50\x8e\x10\x5d' \ - b'\xc2\xb4\x3a\x55' b'\x8d\x6c\x27\x16' \ - b'\xec\x32\xf5\x64' b'\xf9\x27\x68\x07' \ - b'\x07\x4d\xd1\x30' b'\x0f\x71\xe4\x5d' \ - b'\xa5\x92\xb5\x74' b'\xe3\xb6\x8e\x04' \ - b'\x31\xa9\xe3\x79' b'\xb9\xcb\xc9\x46' \ - b'\x61\xc8\x11\x35' b'\x6e\x1b\x1b\x26' \ - b'\x2a\x54\xd5\x65' b'\x24\xba\x07\x14' \ - b'\xcf\xb2\x5e\x45' b'\x4e\xab\x62\x45' \ - b'\x62\x83\xef\x60' b'\x26\x8d\x20\x08' \ - b'\x36\xa8\x53\x45' b'\xca\xb8\x71\x54' \ - b'\x5c\x8b\x44\x52' + b'\xc8\x35\x79\x01' b'\xd3\x86\x14\x57' \ + b'\xdc\x9c\x41\x5c' b'\xa5\xa1\xaa\x0e' \ + b'\x0b\x49\x43\x57' b'\x7e\xbf\x41\x71' \ + b'\x9a\x71\xbc\x44' b'\x88\xc3\x1d\x60' \ + b'\xe4\x53\x28\x22' b'\x71\x71\x62\x62' \ + b'\x49\x09\x0c\x52' b'\xb7\xde\x8b\x2b' \ + b'\x74\x57\x48\x0e' b'\x84\x69\x92\x25' \ + b'\x4d\x63\xa7\x37' b'\x65\x83\x3f\x14' \ + b'\x51\x9e\x14\x3a' b'\xac\x57\x6b\x00' \ + b'\xe6\xa3\x17\x7a' b'\x39\x83\x6e\x5c' \ + b'\xf6\xf2\x1c\x70' b'\x05\x7f\x1f\x5c' \ + b'\x71\xbb\xb7\x21' def testPackRequest0(self): bin = request.ListProperties._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ListProperties._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.ListProperties._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.ListProperties._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestSetSelectionOwner(unittest.TestCase): +class TestSetSelectionOwner(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 1573750861, - 'selection': 984224380, - 'time': 2112448956, + 'selection': 1636366903, + 'time': 383717530, + 'window': 1075066031, } - self.req_bin_0 = b'\x16\x00\x04\x00' b'\x4d\x88\xcd\x5d' \ - b'\x7c\x12\xaa\x3a' b'\xbc\x69\xe9\x7d' + self.req_bin_0 = b'\x16\x00\x04\x00' b'\xaf\x34\x14\x40' \ + b'\x37\xfa\x88\x61' b'\x9a\x10\xdf\x16' def testPackRequest0(self): bin = request.SetSelectionOwner._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.SetSelectionOwner._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGetSelectionOwner(unittest.TestCase): +class TestGetSelectionOwner(EndianTest): def setUp(self): self.req_args_0 = { - 'selection': 1209066471, + 'selection': 1090303630, } - self.req_bin_0 = b'\x17\x00\x02\x00' b'\xe7\xe3\x10\x48' + self.req_bin_0 = b'\x17\x00\x02\x00' b'\x8e\xb6\xfc\x40' self.reply_args_0 = { - 'owner': 1608499874, - 'sequence_number': 40856, + 'owner': 228581038, + 'sequence_number': 60065, } - self.reply_bin_0 = b'\x01\x00\x98\x9f' b'\x00\x00\x00\x00' \ - b'\xa2\xc2\xdf\x5f' b'\x00\x00\x00\x00' \ + self.reply_bin_0 = b'\x01\x00\xa1\xea' b'\x00\x00\x00\x00' \ + b'\xae\xde\x9f\x0d' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.GetSelectionOwner._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetSelectionOwner._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetSelectionOwner._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetSelectionOwner._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestConvertSelection(unittest.TestCase): +class TestConvertSelection(EndianTest): def setUp(self): self.req_args_0 = { - 'property': 116271887, - 'requestor': 163844177, - 'selection': 246355390, - 'target': 1621875689, - 'time': 385931637, + 'property': 1807536699, + 'requestor': 1869489931, + 'selection': 1342887479, + 'target': 640970836, + 'time': 1372199123, } - self.req_bin_0 = b'\x18\x00\x06\x00' b'\x51\x10\xc4\x09' \ - b'\xbe\x15\xaf\x0e' b'\xe9\xdb\xab\x60' \ - b'\x0f\x2b\xee\x06' b'\x75\xd9\x00\x17' + self.req_bin_0 = b'\x18\x00\x06\x00' b'\x0b\x27\x6e\x6f' \ + b'\x37\xd6\x0a\x50' b'\x54\x70\x34\x26' \ + b'\x3b\xd2\xbc\x6b' b'\xd3\x18\xca\x51' def testPackRequest0(self): bin = request.ConvertSelection._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ConvertSelection._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestSendEvent(unittest.TestCase): +class TestSendEvent(EndianTest): def setUp(self): self.req_args_0 = { - 'event_mask': 985979728, - 'destination': 1646910168, - 'propagate': 1, - 'event': Xlib.protocol.event.Expose(count = 7721, width = 18606, window = 1339231972, y = 45287, x = 46510, type = 12, sequence_number = 0, height = 44735), - } - self.req_bin_0 = b'\x19\x01\x0b\x00' b'\xd8\xda\x29\x62' \ - b'\x50\xdb\xc4\x3a' b'\x0c\x00\x00\x00' \ - b'\xe4\x0e\xd3\x4f' b'\xae\xb5\xe7\xb0' \ - b'\xae\x48\xbf\xae' b'\x29\x1e\x00\x00' \ + 'destination': 1158373169, + 'event': event.Expose(count=50227, height=24760, sequence_number=0, type=12, width=10272, window=1090263274, x=40165, y=13291), + 'event_mask': 2047690655, + 'propagate': 0, + } + self.req_bin_0 = b'\x19\x00\x0b\x00' b'\x31\x5f\x0b\x45' \ + b'\x9f\x47\x0d\x7a' b'\x0c\x00\x00\x00' \ + b'\xea\x18\xfc\x40' b'\xe5\x9c\xeb\x33' \ + b'\x20\x28\xb8\x60' b'\x33\xc4\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.SendEvent._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.SendEvent._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGrabPointer(unittest.TestCase): +class TestGrabPointer(EndianTest): def setUp(self): self.req_args_0 = { - 'cursor': 1773330151, + 'confine_to': 240299645, + 'cursor': 1995289624, + 'event_mask': 21499, + 'grab_window': 1286289242, 'keyboard_mode': 0, + 'owner_events': 0, 'pointer_mode': 1, - 'event_mask': 27410, - 'confine_to': 1526915530, - 'time': 1195309735, - 'grab_window': 1295558486, - 'owner_events': 1, + 'time': 779560794, } - self.req_bin_0 = b'\x1a\x01\x06\x00' b'\x56\xa7\x38\x4d' \ - b'\x12\x6b\x01\x00' b'\xca\xe1\x02\x5b' \ - b'\xe7\xde\xb2\x69' b'\xa7\xfa\x3e\x47' + self.req_bin_0 = b'\x1a\x00\x06\x00' b'\x5a\x37\xab\x4c' \ + b'\xfb\x53\x01\x00' b'\x7d\xae\x52\x0e' \ + b'\x18\xb4\xed\x76' b'\x5a\x27\x77\x2e' self.reply_args_0 = { - 'status': 166, - 'sequence_number': 9454, + 'sequence_number': 15948, + 'status': 206, } - self.reply_bin_0 = b'\x01\xa6\xee\x24' b'\x00\x00\x00\x00' \ + self.reply_bin_0 = b'\x01\xce\x4c\x3e' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' @@ -1520,182 +1044,128 @@ def setUp(self): def testPackRequest0(self): bin = request.GrabPointer._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GrabPointer._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GrabPointer._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GrabPointer._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestUngrabPointer(unittest.TestCase): +class TestUngrabPointer(EndianTest): def setUp(self): self.req_args_0 = { - 'time': 1647345145, + 'time': 124458893, } - self.req_bin_0 = b'\x1b\x00\x02\x00' b'\xf9\x7d\x30\x62' + self.req_bin_0 = b'\x1b\x00\x02\x00' b'\x8d\x17\x6b\x07' def testPackRequest0(self): bin = request.UngrabPointer._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.UngrabPointer._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGrabButton(unittest.TestCase): +class TestGrabButton(EndianTest): def setUp(self): self.req_args_0 = { - 'cursor': 1510380761, + 'button': 145, + 'confine_to': 1571825127, + 'cursor': 1043722096, + 'event_mask': 37438, + 'grab_window': 1885576796, 'keyboard_mode': 0, - 'modifiers': 62613, - 'pointer_mode': 1, - 'event_mask': 23716, - 'confine_to': 2062912931, - 'button': 169, - 'grab_window': 2055413885, + 'modifiers': 64349, 'owner_events': 0, + 'pointer_mode': 0, } - self.req_bin_0 = b'\x1c\x00\x06\x00' b'\x7d\x20\x83\x7a' \ - b'\xa4\x5c\x01\x00' b'\xa3\x8d\xf5\x7a' \ - b'\xd9\x94\x06\x5a' b'\xa9\x00\x95\xf4' + self.req_bin_0 = b'\x1c\x00\x06\x00' b'\x5c\x9e\x63\x70' \ + b'\x3e\x92\x00\x00' b'\xe7\x25\xb0\x5d' \ + b'\x70\xef\x35\x3e' b'\x91\x00\x5d\xfb' def testPackRequest0(self): bin = request.GrabButton._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GrabButton._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestUngrabButton(unittest.TestCase): +class TestUngrabButton(EndianTest): def setUp(self): self.req_args_0 = { - 'button': 220, - 'modifiers': 32389, - 'grab_window': 1891977189, + 'button': 160, + 'grab_window': 275784110, + 'modifiers': 43493, } - self.req_bin_0 = b'\x1d\xdc\x03\x00' b'\xe5\x47\xc5\x70' \ - b'\x85\x7e\x00\x00' + self.req_bin_0 = b'\x1d\xa0\x03\x00' b'\xae\x21\x70\x10' \ + b'\xe5\xa9\x00\x00' def testPackRequest0(self): bin = request.UngrabButton._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.UngrabButton._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestChangeActivePointerGrab(unittest.TestCase): +class TestChangeActivePointerGrab(EndianTest): def setUp(self): self.req_args_0 = { - 'cursor': 777967884, - 'event_mask': 12743, - 'time': 197998305, + 'cursor': 1020726671, + 'event_mask': 36287, + 'time': 2033407590, } - self.req_bin_0 = b'\x1e\x00\x04\x00' b'\x0c\xd9\x5e\x2e' \ - b'\xe1\x36\xcd\x0b' b'\xc7\x31\x00\x00' + self.req_bin_0 = b'\x1e\x00\x04\x00' b'\x8f\x0d\xd7\x3c' \ + b'\x66\x56\x33\x79' b'\xbf\x8d\x00\x00' def testPackRequest0(self): bin = request.ChangeActivePointerGrab._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ChangeActivePointerGrab._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGrabKeyboard(unittest.TestCase): +class TestGrabKeyboard(EndianTest): def setUp(self): self.req_args_0 = { - 'keyboard_mode': 1, - 'time': 1696403859, - 'pointer_mode': 0, - 'grab_window': 316814295, + 'grab_window': 569270305, + 'keyboard_mode': 0, 'owner_events': 0, + 'pointer_mode': 1, + 'time': 1133236353, } - self.req_bin_0 = b'\x1f\x00\x04\x00' b'\xd7\x33\xe2\x12' \ - b'\x93\x11\x1d\x65' b'\x00\x01\x00\x00' + self.req_bin_0 = b'\x1f\x00\x04\x00' b'\x21\x60\xee\x21' \ + b'\x81\xd0\x8b\x43' b'\x01\x00\x00\x00' self.reply_args_0 = { - 'status': 239, - 'sequence_number': 46747, + 'sequence_number': 46979, + 'status': 179, } - self.reply_bin_0 = b'\x01\xef\x9b\xb6' b'\x00\x00\x00\x00' \ + self.reply_bin_0 = b'\x01\xb3\x83\xb7' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' @@ -1703,160 +1173,106 @@ def setUp(self): def testPackRequest0(self): bin = request.GrabKeyboard._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GrabKeyboard._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GrabKeyboard._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GrabKeyboard._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestUngrabKeyboard(unittest.TestCase): +class TestUngrabKeyboard(EndianTest): def setUp(self): self.req_args_0 = { - 'time': 4211611, + 'time': 669471181, } - self.req_bin_0 = b'\x20\x00\x02\x00' b'\x9b\x43\x40\x00' + self.req_bin_0 = b'\x20\x00\x02\x00' b'\xcd\x51\xe7\x27' def testPackRequest0(self): bin = request.UngrabKeyboard._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.UngrabKeyboard._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGrabKey(unittest.TestCase): +class TestGrabKey(EndianTest): def setUp(self): self.req_args_0 = { - 'keyboard_mode': 0, - 'modifiers': 62007, - 'key': 175, - 'pointer_mode': 0, - 'grab_window': 882662093, + 'grab_window': 2137132511, + 'key': 223, + 'keyboard_mode': 1, + 'modifiers': 44275, 'owner_events': 1, + 'pointer_mode': 1, } - self.req_bin_0 = b'\x21\x01\x04\x00' b'\xcd\x5a\x9c\x34' \ - b'\x37\xf2\xaf\x00' b'\x00\x00\x00\x00' + self.req_bin_0 = b'\x21\x01\x04\x00' b'\xdf\x0d\x62\x7f' \ + b'\xf3\xac\xdf\x01' b'\x01\x00\x00\x00' def testPackRequest0(self): bin = request.GrabKey._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GrabKey._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestUngrabKey(unittest.TestCase): +class TestUngrabKey(EndianTest): def setUp(self): self.req_args_0 = { - 'modifiers': 18590, - 'grab_window': 1389213966, - 'key': 141, + 'grab_window': 532438798, + 'key': 158, + 'modifiers': 14981, } - self.req_bin_0 = b'\x22\x8d\x03\x00' b'\x0e\xb9\xcd\x52' \ - b'\x9e\x48\x00\x00' + self.req_bin_0 = b'\x22\x9e\x03\x00' b'\x0e\x5f\xbc\x1f' \ + b'\x85\x3a\x00\x00' def testPackRequest0(self): bin = request.UngrabKey._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.UngrabKey._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestAllowEvents(unittest.TestCase): +class TestAllowEvents(EndianTest): def setUp(self): self.req_args_0 = { - 'mode': 7, - 'time': 1088990319, + 'mode': 1, + 'time': 726098765, } - self.req_bin_0 = b'\x23\x07\x02\x00' b'\x6f\xac\xe8\x40' + self.req_bin_0 = b'\x23\x01\x02\x00' b'\x4d\x63\x47\x2b' def testPackRequest0(self): bin = request.AllowEvents._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.AllowEvents._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGrabServer(unittest.TestCase): +class TestGrabServer(EndianTest): def setUp(self): self.req_args_0 = { } @@ -1865,24 +1281,15 @@ def setUp(self): def testPackRequest0(self): bin = request.GrabServer._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GrabServer._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestUngrabServer(unittest.TestCase): +class TestUngrabServer(EndianTest): def setUp(self): self.req_args_0 = { } @@ -1891,590 +1298,419 @@ def setUp(self): def testPackRequest0(self): bin = request.UngrabServer._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.UngrabServer._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestQueryPointer(unittest.TestCase): +class TestQueryPointer(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 358895460, + 'window': 45236268, } - self.req_bin_0 = b'\x26\x00\x02\x00' b'\x64\x4f\x64\x15' + self.req_bin_0 = b'\x26\x00\x02\x00' b'\x2c\x40\xb2\x02' self.reply_args_0 = { - 'same_screen': 1, - 'child': 2139990686, - 'win_x': -30717, - 'root_y': -18418, - 'root_x': -2403, - 'root': 1853596468, - 'mask': 14486, - 'sequence_number': 29530, - 'win_y': -19690, + 'child': 15507755, + 'mask': 15259, + 'root': 472978779, + 'root_x': -30442, + 'root_y': -9574, + 'same_screen': 0, + 'sequence_number': 38820, + 'win_x': -12089, + 'win_y': -30839, } - self.reply_bin_0 = b'\x01\x01\x5a\x73' b'\x00\x00\x00\x00' \ - b'\x34\xa3\x7b\x6e' b'\x9e\xaa\x8d\x7f' \ - b'\x9d\xf6\x0e\xb8' b'\x03\x88\x16\xb3' \ - b'\x96\x38\x00\x00' b'\x00\x00\x00\x00' + self.reply_bin_0 = b'\x01\x00\xa4\x97' b'\x00\x00\x00\x00' \ + b'\x5b\x15\x31\x1c' b'\x2b\xa1\xec\x00' \ + b'\x16\x89\x9a\xda' b'\xc7\xd0\x89\x87' \ + b'\x9b\x3b\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.QueryPointer._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.QueryPointer._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.QueryPointer._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.QueryPointer._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestGetMotionEvents(unittest.TestCase): +class TestGetMotionEvents(EndianTest): def setUp(self): self.req_args_0 = { - 'start': 2110367101, - 'window': 528148429, - 'stop': 1808786083, + 'start': 1944440211, + 'stop': 67524349, + 'window': 144806627, } - self.req_bin_0 = b'\x27\x00\x04\x00' b'\xcd\xe7\x7a\x1f' \ - b'\x7d\xa5\xc9\x7d' b'\xa3\xe2\xcf\x6b' + self.req_bin_0 = b'\x27\x00\x04\x00' b'\xe3\x92\xa1\x08' \ + b'\x93\xcd\xe5\x73' b'\xfd\x56\x06\x04' self.reply_args_0 = { - 'events': [{'y': -23108, 'x': -3461, 'time': 984326273}, {'y': -4096, 'x': -4908, 'time': 488459157}, {'y': -29782, 'x': -8325, 'time': 1162935901}, {'y': -26418, 'x': -10559, 'time': 275816904}, {'y': -3941, 'x': -2216, 'time': 656439277}], - 'sequence_number': 42652, + 'events': [{'time': 1846118496, 'x': -21941, 'y': -30447}, {'time': 1104207400, 'x': -24970, 'y': -23643}, {'time': 1436684371, 'x': -16862, 'y': -25748}, {'time': 1158061593, 'x': -28433, 'y': -9066}, {'time': 2009067067, 'x': -3855, 'y': -14057}], + 'sequence_number': 38018, } - self.reply_bin_0 = b'\x01\x00\x9c\xa6' b'\x0a\x00\x00\x00' \ + self.reply_bin_0 = b'\x01\x00\x82\x94' b'\x0a\x00\x00\x00' \ b'\x05\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ - b'\x81\xa0\xab\x3a' b'\x7b\xf2\xbc\xa5' \ - b'\x95\x4b\x1d\x1d' b'\xd4\xec\x00\xf0' \ - b'\x5d\xfe\x50\x45' b'\x7b\xdf\xaa\x8b' \ - b'\xc8\xa1\x70\x10' b'\xc1\xd6\xce\x98' \ - b'\xed\x77\x20\x27' b'\x58\xf7\x9b\xf0' + b'\x60\x88\x09\x6e' b'\x4b\xaa\x11\x89' \ + b'\x28\xde\xd0\x41' b'\x76\x9e\xa5\xa3' \ + b'\x53\x10\xa2\x55' b'\x22\xbe\x6c\x9b' \ + b'\x19\x9e\x06\x45' b'\xef\x90\x96\xdc' \ + b'\x3b\xee\xbf\x77' b'\xf1\xf0\x17\xc9' def testPackRequest0(self): bin = request.GetMotionEvents._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetMotionEvents._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetMotionEvents._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetMotionEvents._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestTranslateCoords(unittest.TestCase): +class TestTranslateCoords(EndianTest): def setUp(self): self.req_args_0 = { - 'dst_wid': 246042608, - 'src_wid': 1251919501, - 'src_x': -18176, - 'src_y': -309, + 'dst_wid': 521898132, + 'src_wid': 1015118844, + 'src_x': -7058, + 'src_y': -17270, } - self.req_bin_0 = b'\x28\x00\x04\x00' b'\x8d\xc6\x9e\x4a' \ - b'\xf0\x4f\xaa\x0e' b'\x00\xb9\xcb\xfe' + self.req_bin_0 = b'\x28\x00\x04\x00' b'\xfc\x7b\x81\x3c' \ + b'\x94\x88\x1b\x1f' b'\x6e\xe4\x8a\xbc' self.reply_args_0 = { - 'y': -24269, - 'x': -29750, - 'sequence_number': 39515, - 'same_screen': 0, - 'child': 1548917071, + 'child': 202628650, + 'same_screen': 1, + 'sequence_number': 12734, + 'x': -29592, + 'y': -11175, } - self.reply_bin_0 = b'\x01\x00\x5b\x9a' b'\x00\x00\x00\x00' \ - b'\x4f\x99\x52\x5c' b'\xca\x8b\x33\xa1' \ + self.reply_bin_0 = b'\x01\x01\xbe\x31' b'\x00\x00\x00\x00' \ + b'\x2a\xde\x13\x0c' b'\x68\x8c\x59\xd4' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.TranslateCoords._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.TranslateCoords._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.TranslateCoords._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.TranslateCoords._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestWarpPointer(unittest.TestCase): +class TestWarpPointer(EndianTest): def setUp(self): self.req_args_0 = { - 'src_x': -1322, - 'dst_x': -15518, - 'src_width': 45129, - 'src_height': 8451, - 'src_y': -13238, - 'dst_y': -26121, - 'dst_window': 2139748563, - 'src_window': 1945176770, + 'dst_window': 760913775, + 'dst_x': -8878, + 'dst_y': -30993, + 'src_height': 56868, + 'src_width': 30862, + 'src_window': 925740905, + 'src_x': -18889, + 'src_y': -19298, } - self.req_bin_0 = b'\x29\x00\x06\x00' b'\xc2\x0a\xf1\x73' \ - b'\xd3\xf8\x89\x7f' b'\xd6\xfa\x4a\xcc' \ - b'\x49\xb0\x03\x21' b'\x62\xc3\xf7\x99' + self.req_bin_0 = b'\x29\x00\x06\x00' b'\x69\xaf\x2d\x37' \ + b'\x6f\x9f\x5a\x2d' b'\x37\xb6\x9e\xb4' \ + b'\x8e\x78\x24\xde' b'\x52\xdd\xef\x86' def testPackRequest0(self): bin = request.WarpPointer._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.WarpPointer._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestSetInputFocus(unittest.TestCase): +class TestSetInputFocus(EndianTest): def setUp(self): self.req_args_0 = { - 'revert_to': 0, - 'focus': 1068495705, - 'time': 342883486, + 'focus': 1403350503, + 'revert_to': 2, + 'time': 2113544232, } - self.req_bin_0 = b'\x2a\x00\x03\x00' b'\x59\xf3\xaf\x3f' \ - b'\x9e\xfc\x6f\x14' + self.req_bin_0 = b'\x2a\x02\x03\x00' b'\xe7\x6d\xa5\x53' \ + b'\x28\x20\xfa\x7d' def testPackRequest0(self): bin = request.SetInputFocus._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.SetInputFocus._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGetInputFocus(unittest.TestCase): +class TestGetInputFocus(EndianTest): def setUp(self): self.req_args_0 = { } self.req_bin_0 = b'\x2b\x00\x01\x00' self.reply_args_0 = { - 'revert_to': 129, - 'focus': 1884243837, - 'sequence_number': 9052, + 'focus': 864688157, + 'revert_to': 153, + 'sequence_number': 4228, } - self.reply_bin_0 = b'\x01\x81\x5c\x23' b'\x00\x00\x00\x00' \ - b'\x7d\x47\x4f\x70' b'\x00\x00\x00\x00' \ + self.reply_bin_0 = b'\x01\x99\x84\x10' b'\x00\x00\x00\x00' \ + b'\x1d\x18\x8a\x33' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.GetInputFocus._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetInputFocus._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetInputFocus._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetInputFocus._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestQueryKeymap(unittest.TestCase): +class TestQueryKeymap(EndianTest): def setUp(self): self.req_args_0 = { } self.req_bin_0 = b'\x2c\x00\x01\x00' self.reply_args_0 = { - 'map': [175, 212, 207, 139, 156, 192, 230, 219, 136, 198, 152, 156, 229, 233, 221, 209, 131, 229, 209, 249, 130, 189, 183, 135, 238, 149, 131, 204, 162, 229, 149, 246], - 'sequence_number': 19383, + 'map': [214, 155, 191, 177, 176, 242, 163, 236, 174, 199, 246, 191, 147, 241, 153, 140, 131, 151, 188, 170, 232, 252, 251, 182, 230, 143, 170, 225, 128, 227, 195, 244], + 'sequence_number': 18950, } - self.reply_bin_0 = b'\x01\x00\xb7\x4b' b'\x02\x00\x00\x00' \ - b'\xaf\xd4\xcf\x8b' b'\x9c\xc0\xe6\xdb' \ - b'\x88\xc6\x98\x9c' b'\xe5\xe9\xdd\xd1' \ - b'\x83\xe5\xd1\xf9' b'\x82\xbd\xb7\x87' \ - b'\xee\x95\x83\xcc' b'\xa2\xe5\x95\xf6' + self.reply_bin_0 = b'\x01\x00\x06\x4a' b'\x02\x00\x00\x00' \ + b'\xd6\x9b\xbf\xb1' b'\xb0\xf2\xa3\xec' \ + b'\xae\xc7\xf6\xbf' b'\x93\xf1\x99\x8c' \ + b'\x83\x97\xbc\xaa' b'\xe8\xfc\xfb\xb6' \ + b'\xe6\x8f\xaa\xe1' b'\x80\xe3\xc3\xf4' def testPackRequest0(self): bin = request.QueryKeymap._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.QueryKeymap._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.QueryKeymap._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.QueryKeymap._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestOpenFont(unittest.TestCase): +class TestOpenFont(EndianTest): def setUp(self): self.req_args_0 = { + 'fid': 908467189, 'name': 'foofont', - 'fid': 1809550053, } - self.req_bin_0 = b'\x2d\x00\x05\x00' b'\xe5\x8a\xdb\x6b' \ + self.req_bin_0 = b'\x2d\x00\x05\x00' b'\xf5\x1b\x26\x36' \ b'\x07\x00\x00\x00' b'\x66\x6f\x6f\x66' \ b'\x6f\x6e\x74\x00' def testPackRequest0(self): bin = request.OpenFont._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.OpenFont._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestCloseFont(unittest.TestCase): +class TestCloseFont(EndianTest): def setUp(self): self.req_args_0 = { - 'font': 405865016, + 'font': 1495984396, } - self.req_bin_0 = b'\x2e\x00\x02\x00' b'\x38\x02\x31\x18' + self.req_bin_0 = b'\x2e\x00\x02\x00' b'\x0c\xe9\x2a\x59' def testPackRequest0(self): bin = request.CloseFont._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.CloseFont._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestQueryFont(unittest.TestCase): +class TestQueryFont(EndianTest): def setUp(self): self.req_args_0 = { - 'font': 173413537, + 'font': 2055889505, } - self.req_bin_0 = b'\x2f\x00\x02\x00' b'\xa1\x14\x56\x0a' + self.req_bin_0 = b'\x2f\x00\x02\x00' b'\x61\x62\x8a\x7a' self.reply_args_0 = { - 'max_bounds': {'left_side_bearing': -27346, 'descent': -13574, 'right_side_bearing': -29649, 'attributes': 58157, 'character_width': -6055, 'ascent': -4810}, 'all_chars_exist': 0, - 'font_ascent': -15846, - 'font_descent': -913, - 'draw_direction': 165, - 'min_char_or_byte2': 53512, - 'default_char': 28435, - 'max_char_or_byte2': 48394, - 'min_bounds': {'left_side_bearing': -8151, 'descent': -28819, 'right_side_bearing': -31752, 'attributes': 52666, 'character_width': -19612, 'ascent': -9876}, - 'char_infos': [{'left_side_bearing': -20738, 'descent': -15296, 'right_side_bearing': -2753, 'attributes': 64507, 'character_width': -12227, 'ascent': -13881}, {'left_side_bearing': -10754, 'descent': -1625, 'right_side_bearing': -9647, 'attributes': 29864, 'character_width': -26871, 'ascent': -11229}, {'left_side_bearing': -30834, 'descent': -16816, 'right_side_bearing': -27729, 'attributes': 56962, 'character_width': -4251, 'ascent': -12215}], - 'max_byte1': 219, - 'min_byte1': 195, - 'properties': [{'name': 515636466, 'value': 1798456662}], - 'sequence_number': 52469, - } - self.reply_bin_0 = b'\x01\x00\xf5\xcc' b'\x12\x00\x00\x00' \ - b'\x29\xe0\xf8\x83' b'\x64\xb3\x6c\xd9' \ - b'\x6d\x8f\xba\xcd' b'\x00\x00\x00\x00' \ - b'\x2e\x95\x2f\x8c' b'\x59\xe8\x36\xed' \ - b'\xfa\xca\x2d\xe3' b'\x00\x00\x00\x00' \ - b'\x08\xd1\x0a\xbd' b'\x13\x6f\x01\x00' \ - b'\xa5\xc3\xdb\x00' b'\x1a\xc2\x6f\xfc' \ - b'\x03\x00\x00\x00' b'\xf2\xfc\xbb\x1e' \ - b'\x56\x45\x32\x6b' b'\xfe\xae\x3f\xf5' \ - b'\x3d\xd0\xc7\xc9' b'\x40\xc4\xfb\xfb' \ - b'\xfe\xd5\x51\xda' b'\x09\x97\x23\xd4' \ - b'\xa7\xf9\xa8\x74' b'\x8e\x87\xaf\x93' \ - b'\x65\xef\x49\xd0' b'\x50\xbe\x82\xde' + 'char_infos': [{'left_side_bearing': -7099, 'right_side_bearing': -14557, 'character_width': -11080, 'ascent': -9228, 'descent': -16821, 'attributes': 10400}, {'left_side_bearing': -26546, 'right_side_bearing': -23046, 'character_width': -25635, 'ascent': -1026, 'descent': -30852, 'attributes': 38213}, {'left_side_bearing': -8660, 'right_side_bearing': -15002, 'character_width': -30771, 'ascent': -8259, 'descent': -22492, 'attributes': 4002}], + 'default_char': 39252, + 'draw_direction': 145, + 'font_ascent': -1914, + 'font_descent': -3596, + 'max_bounds': {'left_side_bearing': -27610, 'right_side_bearing': -30905, 'character_width': -1286, 'ascent': -16128, 'descent': -30143, 'attributes': 56049}, + 'max_byte1': 231, + 'max_char_or_byte2': 4746, + 'min_bounds': {'left_side_bearing': -13626, 'right_side_bearing': -17145, 'character_width': -16291, 'ascent': -2642, 'descent': -4827, 'attributes': 35063}, + 'min_byte1': 188, + 'min_char_or_byte2': 12434, + 'properties': [{'name': 1568813755, 'value': 2137719486}], + 'sequence_number': 3542, + } + self.reply_bin_0 = b'\x01\x00\xd6\x0d' b'\x12\x00\x00\x00' \ + b'\xc6\xca\x07\xbd' b'\x5d\xc0\xae\xf5' \ + b'\x25\xed\xf7\x88' b'\x00\x00\x00\x00' \ + b'\x26\x94\x47\x87' b'\xfa\xfa\x00\xc1' \ + b'\x41\x8a\xf1\xda' b'\x00\x00\x00\x00' \ + b'\x92\x30\x8a\x12' b'\x54\x99\x01\x00' \ + b'\x91\xbc\xe7\x00' b'\x86\xf8\xf4\xf1' \ + b'\x03\x00\x00\x00' b'\xbb\x32\x82\x5d' \ + b'\xbe\x02\x6b\x7f' b'\x45\xe4\x23\xc7' \ + b'\xb8\xd4\xf4\xdb' b'\x4b\xbe\xa0\x28' \ + b'\x4e\x98\xfa\xa5' b'\xdd\x9b\xfe\xfb' \ + b'\x7c\x87\x45\x95' b'\x2c\xde\x66\xc5' \ + b'\xcd\x87\xbd\xdf' b'\x24\xa8\xa2\x0f' def testPackRequest0(self): bin = request.QueryFont._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.QueryFont._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.QueryFont._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.QueryFont._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestQueryTextExtents(unittest.TestCase): +class TestQueryTextExtents(EndianTest): def setUp(self): self.req_args_0 = { - 'font': 1637171782, + 'font': 1223434172, 'string': (102, 111, 111), } - self.req_bin_0 = b'\x30\x01\x04\x00' b'\x46\x42\x95\x61' \ + self.req_bin_0 = b'\x30\x01\x04\x00' b'\xbc\x1f\xec\x48' \ b'\x00\x66\x00\x6f' b'\x00\x6f\x00\x00' self.reply_args_0 = { - 'font_descent': -10581, - 'overall_left': -1212859291, - 'draw_direction': 195, - 'overall_right': -813911398, - 'overall_descent': -19862, - 'overall_ascent': -32654, - 'font_ascent': -22971, - 'sequence_number': 6206, - 'overall_width': -127705892, - } - self.reply_bin_0 = b'\x01\xc3\x3e\x18' b'\x00\x00\x00\x00' \ - b'\x45\xa6\xab\xd6' b'\x72\x80\x6a\xb2' \ - b'\xdc\x5c\x63\xf8' b'\x65\x3c\xb5\xb7' \ - b'\x9a\xb2\x7c\xcf' b'\x00\x00\x00\x00' + 'draw_direction': 191, + 'font_ascent': -13287, + 'font_descent': -31466, + 'overall_ascent': -12473, + 'overall_descent': -30082, + 'overall_left': -735785526, + 'overall_right': -894056953, + 'overall_width': -1247205006, + 'sequence_number': 38196, + } + self.reply_bin_0 = b'\x01\xbf\x34\x95' b'\x00\x00\x00\x00' \ + b'\x19\xcc\x16\x85' b'\x47\xcf\x7e\x8a' \ + b'\x72\x29\xa9\xb5' b'\xca\xcd\x24\xd4' \ + b'\x07\xc6\xb5\xca' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.QueryTextExtents._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.QueryTextExtents._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.QueryTextExtents._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.QueryTextExtents._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestListFonts(unittest.TestCase): +class TestListFonts(EndianTest): def setUp(self): self.req_args_0 = { + 'max_names': 37298, 'pattern': 'bhazr', - 'max_names': 57427, } - self.req_bin_0 = b'\x31\x00\x04\x00' b'\x53\xe0\x05\x00' \ + self.req_bin_0 = b'\x31\x00\x04\x00' b'\xb2\x91\x05\x00' \ b'\x62\x68\x61\x7a' b'\x72\x00\x00\x00' self.reply_args_0 = { 'fonts': ['fie', 'fuzzy', 'foozooom'], - 'sequence_number': 39409, + 'sequence_number': 34517, } - self.reply_bin_0 = b'\x01\x00\xf1\x99' b'\x05\x00\x00\x00' \ + self.reply_bin_0 = b'\x01\x00\xd5\x86' b'\x05\x00\x00\x00' \ b'\x03\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ @@ -2485,117 +1721,81 @@ def setUp(self): def testPackRequest0(self): bin = request.ListFonts._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ListFonts._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.ListFonts._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.ListFonts._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestListFontsWithInfo(unittest.TestCase): +class TestListFontsWithInfo(EndianTest): def setUp(self): self.req_args_0 = { + 'max_names': 20989, 'pattern': 'bhazr2', - 'max_names': 52288, } - self.req_bin_0 = b'\x32\x00\x04\x00' b'\x40\xcc\x06\x00' \ + self.req_bin_0 = b'\x32\x00\x04\x00' b'\xfd\x51\x06\x00' \ b'\x62\x68\x61\x7a' b'\x72\x32\x00\x00' self.reply_args_0 = { - 'max_bounds': {'left_side_bearing': -9255, 'descent': -26305, 'right_side_bearing': -6756, 'attributes': 49084, 'character_width': -4462, 'ascent': -3529}, - 'all_chars_exist': 1, - 'font_ascent': -26930, + 'all_chars_exist': 0, + 'default_char': 61580, + 'draw_direction': 146, + 'font_ascent': -30368, + 'font_descent': -15151, + 'max_bounds': {'left_side_bearing': -28480, 'right_side_bearing': -10759, 'character_width': -11617, 'ascent': -22938, 'descent': -17786, 'attributes': 20976}, + 'max_byte1': 245, + 'max_char_or_byte2': 49530, + 'min_bounds': {'left_side_bearing': -10823, 'right_side_bearing': -9300, 'character_width': -22473, 'ascent': -24947, 'descent': -24065, 'attributes': 26194}, + 'min_byte1': 130, + 'min_char_or_byte2': 61140, 'name': 'fontfont', - 'replies_hint': 1755082535, - 'font_descent': -25033, - 'draw_direction': 229, - 'min_char_or_byte2': 65093, - 'default_char': 39019, - 'max_char_or_byte2': 45170, - 'min_bounds': {'left_side_bearing': -8350, 'descent': -16956, 'right_side_bearing': -19578, 'attributes': 27352, 'character_width': -20897, 'ascent': -9972}, - 'max_byte1': 221, - 'min_byte1': 158, - 'properties': [{'name': 213588122, 'value': 1789263183}], - 'sequence_number': 43812, - } - self.reply_bin_0 = b'\x01\x08\x24\xab' b'\x0b\x00\x00\x00' \ - b'\x62\xdf\x86\xb3' b'\x5f\xae\x0c\xd9' \ - b'\xc4\xbd\xd8\x6a' b'\x00\x00\x00\x00' \ - b'\xd9\xdb\x9c\xe5' b'\x92\xee\x37\xf2' \ - b'\x3f\x99\xbc\xbf' b'\x00\x00\x00\x00' \ - b'\x45\xfe\x72\xb0' b'\x6b\x98\x01\x00' \ - b'\xe5\x9e\xdd\x01' b'\xce\x96\x37\x9e' \ - b'\x27\x6f\x9c\x68' b'\x9a\x18\xbb\x0c' \ - b'\x4f\xfd\xa5\x6a' b'\x66\x6f\x6e\x74' \ + 'properties': [{'name': 2007331946, 'value': 560055601}], + 'replies_hint': 457810933, + 'sequence_number': 13642, + } + self.reply_bin_0 = b'\x01\x08\x4a\x35' b'\x0b\x00\x00\x00' \ + b'\xb9\xd5\xac\xdb' b'\x37\xa8\x8d\x9e' \ + b'\xff\xa1\x52\x66' b'\x00\x00\x00\x00' \ + b'\xc0\x90\xf9\xd5' b'\x9f\xd2\x66\xa6' \ + b'\x86\xba\xf0\x51' b'\x00\x00\x00\x00' \ + b'\xd4\xee\x7a\xc1' b'\x8c\xf0\x01\x00' \ + b'\x92\x82\xf5\x00' b'\x60\x89\xd1\xc4' \ + b'\xf5\xa3\x49\x1b' b'\x6a\x74\xa5\x77' \ + b'\x31\xc5\x61\x21' b'\x66\x6f\x6e\x74' \ b'\x66\x6f\x6e\x74' def testPackRequest0(self): bin = request.ListFontsWithInfo._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ListFontsWithInfo._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.ListFontsWithInfo._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.ListFontsWithInfo._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestSetFontPath(unittest.TestCase): +class TestSetFontPath(EndianTest): def setUp(self): self.req_args_0 = { 'path': ['foo', 'bar', 'gazonk'], @@ -2612,42 +1812,24 @@ def setUp(self): def testPackRequest0(self): bin = request.SetFontPath._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.SetFontPath._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackRequest1(self): bin = request.SetFontPath._request.to_binary(*(), **self.req_args_1) - try: - assert bin == self.req_bin_1 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_1) def testUnpackRequest1(self): args, remain = request.SetFontPath._request.parse_binary(self.req_bin_1, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_1 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_1) -class TestGetFontPath(unittest.TestCase): +class TestGetFontPath(EndianTest): def setUp(self): self.req_args_0 = { } @@ -2655,9 +1837,9 @@ def setUp(self): self.reply_args_0 = { 'paths': ['path1', 'path2232'], - 'sequence_number': 17086, + 'sequence_number': 33409, } - self.reply_bin_0 = b'\x01\x00\xbe\x42' b'\x04\x00\x00\x00' \ + self.reply_bin_0 = b'\x01\x00\x81\x82' b'\x04\x00\x00\x00' \ b'\x02\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ @@ -2666,9 +1848,9 @@ def setUp(self): self.reply_args_1 = { 'paths': [], - 'sequence_number': 8511, + 'sequence_number': 17636, } - self.reply_bin_1 = b'\x01\x00\x3f\x21' b'\x00\x00\x00\x00' \ + self.reply_bin_1 = b'\x01\x00\xe4\x44' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' @@ -2676,1320 +1858,951 @@ def setUp(self): def testPackRequest0(self): bin = request.GetFontPath._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetFontPath._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetFontPath._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetFontPath._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) def testPackReply1(self): bin = request.GetFontPath._reply.to_binary(*(), **self.reply_args_1) - try: - assert bin == self.reply_bin_1 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_1) def testUnpackReply1(self): args, remain = request.GetFontPath._reply.parse_binary(self.reply_bin_1, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_1 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_1) -class TestCreatePixmap(unittest.TestCase): +class TestCreatePixmap(EndianTest): def setUp(self): self.req_args_0 = { - 'width': 32332, - 'depth': 179, - 'pid': 847631690, - 'drawable': 1358709134, - 'height': 16464, + 'depth': 161, + 'drawable': 749556300, + 'height': 4764, + 'pid': 2004224799, + 'width': 57984, } - self.req_bin_0 = b'\x35\xb3\x04\x00' b'\x4a\xd5\x85\x32' \ - b'\x8e\x41\xfc\x50' b'\x4c\x7e\x50\x40' + self.req_bin_0 = b'\x35\xa1\x04\x00' b'\x1f\x0b\x76\x77' \ + b'\x4c\x52\xad\x2c' b'\x80\xe2\x9c\x12' def testPackRequest0(self): bin = request.CreatePixmap._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.CreatePixmap._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestFreePixmap(unittest.TestCase): +class TestFreePixmap(EndianTest): def setUp(self): self.req_args_0 = { - 'pixmap': 1323266674, + 'pixmap': 1888284001, } - self.req_bin_0 = b'\x36\x00\x02\x00' b'\x72\x72\xdf\x4e' + self.req_bin_0 = b'\x36\x00\x02\x00' b'\x61\xed\x8c\x70' def testPackRequest0(self): bin = request.FreePixmap._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.FreePixmap._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestCreateGC(unittest.TestCase): +class TestCreateGC(EndianTest): def setUp(self): self.req_args_0 = { - 'drawable': 830249906, - 'attrs': {'function': 14, 'foreground': 814230008, 'background': 2072616911, 'clip_x_origin': -6987, 'subwindow_mode': 0, 'cap_style': 1, 'fill_style': 3, 'tile_stipple_y_origin': -25870, 'font': 264499208, 'graphics_exposures': 0, 'join_style': 2, 'line_width': 36600, 'stipple': 870974399, 'dash_offset': 49599, 'clip_y_origin': -5712, 'tile_stipple_x_origin': -32365, 'arc_mode': 0, 'tile': 1597988019, 'line_style': 2, 'plane_mask': 1650697305, 'clip_mask': 402937862, 'fill_rule': 0, 'dashes': 136}, - 'cid': 779296774, - } - self.req_bin_0 = b'\x37\x00\x1b\x00' b'\x06\x20\x73\x2e' \ - b'\xb2\x9b\x7c\x31' b'\xff\xff\x7f\x00' \ - b'\x0e\x00\x00\x00' b'\x59\xa4\x63\x62' \ - b'\xf8\x29\x88\x30' b'\xcf\x9f\x89\x7b' \ - b'\xf8\x8e\x00\x00' b'\x02\x00\x00\x00' \ - b'\x01\x00\x00\x00' b'\x02\x00\x00\x00' \ - b'\x03\x00\x00\x00' b'\x00\x00\x00\x00' \ - b'\xb3\x5c\x3f\x5f' b'\xbf\x03\xea\x33' \ - b'\x93\x81\x00\x00' b'\xf2\x9a\x00\x00' \ - b'\x08\xf0\xc3\x0f' b'\x00\x00\x00\x00' \ - b'\x00\x00\x00\x00' b'\xb5\xe4\x00\x00' \ - b'\xb0\xe9\x00\x00' b'\x06\x58\x04\x18' \ - b'\xbf\xc1\x00\x00' b'\x88\x00\x00\x00' \ + 'attrs': {'function': 7, 'plane_mask': 793618921, 'foreground': 612071305, 'background': 338824284, 'line_width': 61484, 'line_style': 2, 'cap_style': 2, 'join_style': 2, 'fill_style': 0, 'fill_rule': 1, 'tile': 2000996399, 'stipple': 1424681955, 'tile_stipple_x_origin': -25980, 'tile_stipple_y_origin': -23968, 'font': 568001783, 'subwindow_mode': 0, 'graphics_exposures': 0, 'clip_x_origin': -22581, 'clip_y_origin': -14920, 'clip_mask': 605132525, 'dash_offset': 46571, 'dashes': 215, 'arc_mode': 0}, + 'cid': 1476454377, + 'drawable': 1362081172, + } + self.req_bin_0 = b'\x37\x00\x1b\x00' b'\xe9\xe7\x00\x58' \ + b'\x94\xb5\x2f\x51' b'\xff\xff\x7f\x00' \ + b'\x07\x00\x00\x00' b'\xe9\xa9\x4d\x2f' \ + b'\x89\x77\x7b\x24' b'\x5c\x0c\x32\x14' \ + b'\x2c\xf0\x00\x00' b'\x02\x00\x00\x00' \ + b'\x02\x00\x00\x00' b'\x02\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x01\x00\x00\x00' \ + b'\x2f\xc8\x44\x77' b'\xe3\xeb\xea\x54' \ + b'\x84\x9a\x00\x00' b'\x60\xa2\x00\x00' \ + b'\xf7\x04\xdb\x21' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\xcb\xa7\x00\x00' \ + b'\xb8\xc5\x00\x00' b'\xed\x96\x11\x24' \ + b'\xeb\xb5\x00\x00' b'\xd7\x00\x00\x00' \ b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.CreateGC._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.CreateGC._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestChangeGC(unittest.TestCase): +class TestChangeGC(EndianTest): def setUp(self): self.req_args_0 = { - 'gc': 1996372624, - 'attrs': {'function': 15, 'foreground': 1817174045, 'background': 840850119, 'clip_x_origin': -28415, 'subwindow_mode': 1, 'cap_style': 0, 'fill_style': 0, 'tile_stipple_y_origin': -24832, 'font': 240535139, 'graphics_exposures': 1, 'join_style': 2, 'line_width': 64290, 'stipple': 1739313208, 'dash_offset': 53189, 'clip_y_origin': -2802, 'tile_stipple_x_origin': -4548, 'arc_mode': 1, 'tile': 1091199324, 'line_style': 2, 'plane_mask': 1403123174, 'clip_mask': 1604118463, 'fill_rule': 1, 'dashes': 186}, + 'attrs': {'function': 8, 'plane_mask': 1085423224, 'foreground': 1049179696, 'background': 539344312, 'line_width': 36097, 'line_style': 0, 'cap_style': 3, 'join_style': 1, 'fill_style': 0, 'fill_rule': 0, 'tile': 716372747, 'stipple': 1656031462, 'tile_stipple_x_origin': -24195, 'tile_stipple_y_origin': -15601, 'font': 347060191, 'subwindow_mode': 1, 'graphics_exposures': 1, 'clip_x_origin': -32135, 'clip_y_origin': -25437, 'clip_mask': 161650480, 'dash_offset': 42536, 'dashes': 137, 'arc_mode': 1}, + 'gc': 1250995304, } - self.req_bin_0 = b'\x38\x00\x1a\x00' b'\x90\x3a\xfe\x76' \ - b'\xff\xff\x7f\x00' b'\x0f\x00\x00\x00' \ - b'\xe6\xf5\xa1\x53' b'\x1d\xe0\x4f\x6c' \ - b'\xc7\x5a\x1e\x32' b'\x22\xfb\x00\x00' \ - b'\x02\x00\x00\x00' b'\x00\x00\x00\x00' \ - b'\x02\x00\x00\x00' b'\x00\x00\x00\x00' \ - b'\x01\x00\x00\x00' b'\x5c\x61\x0a\x41' \ - b'\x38\xd0\xab\x67' b'\x3c\xee\x00\x00' \ - b'\x00\x9f\x00\x00' b'\x63\x46\x56\x0e' \ + self.req_bin_0 = b'\x38\x00\x1a\x00' b'\x68\xac\x90\x4a' \ + b'\xff\xff\x7f\x00' b'\x08\x00\x00\x00' \ + b'\x78\x3e\xb2\x40' b'\x30\x36\x89\x3e' \ + b'\xb8\xbd\x25\x20' b'\x01\x8d\x00\x00' \ + b'\x00\x00\x00\x00' b'\x03\x00\x00\x00' \ + b'\x01\x00\x00\x00' b'\x00\x00\x00\x00' \ + b'\x00\x00\x00\x00' b'\x0b\xfb\xb2\x2a' \ + b'\xe6\x08\xb5\x62' b'\x7d\xa1\x00\x00' \ + b'\x0f\xc3\x00\x00' b'\xdf\xb7\xaf\x14' \ b'\x01\x00\x00\x00' b'\x01\x00\x00\x00' \ - b'\x01\x91\x00\x00' b'\x0e\xf5\x00\x00' \ - b'\xbf\xe7\x9c\x5f' b'\xc5\xcf\x00\x00' \ - b'\xba\x00\x00\x00' b'\x01\x00\x00\x00' + b'\x79\x82\x00\x00' b'\xa3\x9c\x00\x00' \ + b'\x30\x97\xa2\x09' b'\x28\xa6\x00\x00' \ + b'\x89\x00\x00\x00' b'\x01\x00\x00\x00' def testPackRequest0(self): bin = request.ChangeGC._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ChangeGC._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestCopyGC(unittest.TestCase): +class TestCopyGC(EndianTest): def setUp(self): self.req_args_0 = { - 'src_gc': 1605257018, - 'dst_gc': 2046321491, - 'mask': 996538407, + 'dst_gc': 318094523, + 'mask': 923025483, + 'src_gc': 1186604145, } - self.req_bin_0 = b'\x39\x00\x04\x00' b'\x3a\x47\xae\x5f' \ - b'\x53\x63\xf8\x79' b'\x27\xf8\x65\x3b' + self.req_bin_0 = b'\x39\x00\x04\x00' b'\x71\x24\xba\x46' \ + b'\xbb\xbc\xf5\x12' b'\x4b\x40\x04\x37' def testPackRequest0(self): bin = request.CopyGC._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.CopyGC._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestSetDashes(unittest.TestCase): +class TestSetDashes(EndianTest): def setUp(self): self.req_args_0 = { - 'dash_offset': 34958, - 'gc': 2119954025, - 'dashes': [146, 217, 181, 229, 212, 175, 201, 251, 248], + 'dash_offset': 51381, + 'dashes': [160, 138, 206, 221, 138, 219, 181, 191, 154], + 'gc': 759584613, } - self.req_bin_0 = b'\x3a\x00\x06\x00' b'\x69\xee\x5b\x7e' \ - b'\x8e\x88\x09\x00' b'\x92\xd9\xb5\xe5' \ - b'\xd4\xaf\xc9\xfb' b'\xf8\x00\x00\x00' + self.req_bin_0 = b'\x3a\x00\x06\x00' b'\x65\x57\x46\x2d' \ + b'\xb5\xc8\x09\x00' b'\xa0\x8a\xce\xdd' \ + b'\x8a\xdb\xb5\xbf' b'\x9a\x00\x00\x00' def testPackRequest0(self): bin = request.SetDashes._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.SetDashes._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestSetClipRectangles(unittest.TestCase): +class TestSetClipRectangles(EndianTest): def setUp(self): self.req_args_0 = { - 'ordering': 3, - 'gc': 2028835270, - 'y_origin': -15522, - 'rectangles': [{'y': -27524, 'x': -27245, 'height': 31014, 'width': 52432}, {'y': -8991, 'x': -11302, 'height': 9053, 'width': 11072}], - 'x_origin': -26003, + 'gc': 1856792138, + 'ordering': 1, + 'rectangles': [{'x': -14422, 'y': -3797, 'width': 57581, 'height': 26888}, {'x': -858, 'y': -12431, 'width': 49373, 'height': 10384}], + 'x_origin': -27444, + 'y_origin': -780, } - self.req_bin_0 = b'\x3b\x03\x07\x00' b'\xc6\x91\xed\x78' \ - b'\x6d\x9a\x5e\xc3' b'\x93\x95\x7c\x94' \ - b'\xd0\xcc\x26\x79' b'\xda\xd3\xe1\xdc' \ - b'\x40\x2b\x5d\x23' + self.req_bin_0 = b'\x3b\x01\x07\x00' b'\x4a\x66\xac\x6e' \ + b'\xcc\x94\xf4\xfc' b'\xaa\xc7\x2b\xf1' \ + b'\xed\xe0\x08\x69' b'\xa6\xfc\x71\xcf' \ + b'\xdd\xc0\x90\x28' self.req_args_1 = { + 'gc': 1892892424, 'ordering': 1, - 'gc': 155607949, - 'y_origin': -32694, 'rectangles': [], - 'x_origin': -23382, + 'x_origin': -19258, + 'y_origin': -31956, } - self.req_bin_1 = b'\x3b\x01\x03\x00' b'\x8d\x63\x46\x09' \ - b'\xaa\xa4\x4a\x80' + self.req_bin_1 = b'\x3b\x01\x03\x00' b'\x08\x3f\xd3\x70' \ + b'\xc6\xb4\x2c\x83' def testPackRequest0(self): bin = request.SetClipRectangles._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.SetClipRectangles._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackRequest1(self): bin = request.SetClipRectangles._request.to_binary(*(), **self.req_args_1) - try: - assert bin == self.req_bin_1 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_1) def testUnpackRequest1(self): args, remain = request.SetClipRectangles._request.parse_binary(self.req_bin_1, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_1 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_1) -class TestFreeGC(unittest.TestCase): +class TestFreeGC(EndianTest): def setUp(self): self.req_args_0 = { - 'gc': 533809208, + 'gc': 385239625, } - self.req_bin_0 = b'\x3c\x00\x02\x00' b'\x38\x48\xd1\x1f' + self.req_bin_0 = b'\x3c\x00\x02\x00' b'\x49\x4a\xf6\x16' def testPackRequest0(self): bin = request.FreeGC._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.FreeGC._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestClearArea(unittest.TestCase): +class TestClearArea(EndianTest): def setUp(self): self.req_args_0 = { - 'width': 25049, - 'window': 451215820, - 'y': -6435, - 'x': -30623, - 'exposures': 0, - 'height': 27400, + 'exposures': 1, + 'height': 44159, + 'width': 52831, + 'window': 1680227732, + 'x': -2268, + 'y': -19277, } - self.req_bin_0 = b'\x3d\x00\x04\x00' b'\xcc\x01\xe5\x1a' \ - b'\x61\x88\xdd\xe6' b'\xd9\x61\x08\x6b' + self.req_bin_0 = b'\x3d\x01\x04\x00' b'\x94\x3d\x26\x64' \ + b'\x24\xf7\xb3\xb4' b'\x5f\xce\x7f\xac' def testPackRequest0(self): bin = request.ClearArea._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ClearArea._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestCopyArea(unittest.TestCase): +class TestCopyArea(EndianTest): def setUp(self): self.req_args_0 = { - 'dst_y': -10208, - 'dst_x': -3325, - 'gc': 544091206, - 'src_x': -14979, - 'src_y': -25188, - 'dst_drawable': 1518430886, - 'height': 46849, - 'width': 46860, - 'src_drawable': 197047820, - } - self.req_bin_0 = b'\x3e\x00\x07\x00' b'\x0c\xb6\xbe\x0b' \ - b'\xa6\x6a\x81\x5a' b'\x46\x2c\x6e\x20' \ - b'\x7d\xc5\x9c\x9d' b'\x03\xf3\x20\xd8' \ - b'\x0c\xb7\x01\xb7' + 'dst_drawable': 1578589574, + 'dst_x': -27552, + 'dst_y': -6968, + 'gc': 1741136437, + 'height': 7340, + 'src_drawable': 1855628899, + 'src_x': -24637, + 'src_y': -24026, + 'width': 46214, + } + self.req_bin_0 = b'\x3e\x00\x07\x00' b'\x63\xa6\x9a\x6e' \ + b'\x86\x5d\x17\x5e' b'\x35\xa2\xc7\x67' \ + b'\xc3\x9f\x26\xa2' b'\x60\x94\xc8\xe4' \ + b'\x86\xb4\xac\x1c' def testPackRequest0(self): bin = request.CopyArea._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.CopyArea._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestCopyPlane(unittest.TestCase): +class TestCopyPlane(EndianTest): def setUp(self): self.req_args_0 = { - 'dst_y': -24783, - 'dst_x': -17393, - 'bit_plane': 121248642, - 'gc': 2016534076, - 'src_x': -15677, - 'src_y': -24535, - 'dst_drawable': 626526507, - 'height': 9260, - 'width': 12445, - 'src_drawable': 1825271175, - } - self.req_bin_0 = b'\x3f\x00\x08\x00' b'\x87\x6d\xcb\x6c' \ - b'\x2b\x09\x58\x25' b'\x3c\xde\x31\x78' \ - b'\xc3\xc2\x29\xa0' b'\x0f\xbc\x31\x9f' \ - b'\x9d\x30\x2c\x24' b'\x82\x1b\x3a\x07' + 'bit_plane': 988559210, + 'dst_drawable': 1873029448, + 'dst_x': -25480, + 'dst_y': -26229, + 'gc': 83225989, + 'height': 60447, + 'src_drawable': 821567629, + 'src_x': -4634, + 'src_y': -17345, + 'width': 53771, + } + self.req_bin_0 = b'\x3f\x00\x08\x00' b'\x8d\x20\xf8\x30' \ + b'\x48\x29\xa4\x6f' b'\x85\xed\xf5\x04' \ + b'\xe6\xed\x3f\xbc' b'\x78\x9c\x8b\x99' \ + b'\x0b\xd2\x1f\xec' b'\x6a\x37\xec\x3a' def testPackRequest0(self): bin = request.CopyPlane._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.CopyPlane._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestPolyPoint(unittest.TestCase): +class TestPolyPoint(EndianTest): def setUp(self): self.req_args_0 = { 'coord_mode': 0, - 'drawable': 1127406891, - 'points': [{'y': -18047, 'x': -19763}, {'y': -5351, 'x': -20174}, {'y': -10573, 'x': -29362}], - 'gc': 1752128743, + 'drawable': 50884525, + 'gc': 1417476013, + 'points': [{'x': -21311, 'y': -22768}, {'x': -5881, 'y': -6707}, {'x': -4217, 'y': -25311}], } - self.req_bin_0 = b'\x40\x00\x06\x00' b'\x2b\xdd\x32\x43' \ - b'\xe7\x5c\x6f\x68' b'\xcd\xb2\x81\xb9' \ - b'\x32\xb1\x19\xeb' b'\x4e\x8d\xb3\xd6' + self.req_bin_0 = b'\x40\x00\x06\x00' b'\xad\x6f\x08\x03' \ + b'\xad\xf7\x7c\x54' b'\xc1\xac\x10\xa7' \ + b'\x07\xe9\xcd\xe5' b'\x87\xef\x21\x9d' def testPackRequest0(self): bin = request.PolyPoint._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.PolyPoint._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestPolyLine(unittest.TestCase): +class TestPolyLine(EndianTest): def setUp(self): self.req_args_0 = { 'coord_mode': 1, - 'drawable': 1354888255, - 'points': [{'y': -22360, 'x': -25237}, {'y': -21145, 'x': -28948}, {'y': -16928, 'x': -3515}, {'y': -25838, 'x': -12335}, {'y': -31134, 'x': -12944}], - 'gc': 1308624032, + 'drawable': 1459319574, + 'gc': 2107068434, + 'points': [{'x': -26440, 'y': -19712}, {'x': -22012, 'y': -23639}, {'x': -4445, 'y': -30494}, {'x': -1085, 'y': -7428}, {'x': -23622, 'y': -21262}], } - self.req_bin_0 = b'\x41\x01\x08\x00' b'\x3f\xf4\xc1\x50' \ - b'\xa0\x04\x00\x4e' b'\x6b\x9d\xa8\xa8' \ - b'\xec\x8e\x67\xad' b'\x45\xf2\xe0\xbd' \ - b'\xd1\xcf\x12\x9b' b'\x70\xcd\x62\x86' + self.req_bin_0 = b'\x41\x01\x08\x00' b'\x16\x73\xfb\x56' \ + b'\x12\x50\x97\x7d' b'\xb8\x98\x00\xb3' \ + b'\x04\xaa\xa9\xa3' b'\xa3\xee\xe2\x88' \ + b'\xc3\xfb\xfc\xe2' b'\xba\xa3\xf2\xac' def testPackRequest0(self): bin = request.PolyLine._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.PolyLine._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestPolySegment(unittest.TestCase): +class TestPolySegment(EndianTest): def setUp(self): self.req_args_0 = { - 'segments': [{'y1': -3160, 'x2': -5139, 'x1': -2249, 'y2': -26872}], - 'gc': 2022424938, - 'drawable': 158182613, + 'drawable': 59337240, + 'gc': 247760051, + 'segments': [{'x1': -5123, 'y1': -15198, 'x2': -21917, 'y2': -1992}], } - self.req_bin_0 = b'\x42\x00\x05\x00' b'\xd5\xac\x6d\x09' \ - b'\x6a\xc1\x8b\x78' b'\x37\xf7\xa8\xf3' \ - b'\xed\xeb\x08\x97' + self.req_bin_0 = b'\x42\x00\x05\x00' b'\x18\x6a\x89\x03' \ + b'\xb3\x84\xc4\x0e' b'\xfd\xeb\xa2\xc4' \ + b'\x63\xaa\x38\xf8' def testPackRequest0(self): bin = request.PolySegment._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.PolySegment._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestPolyRectangle(unittest.TestCase): +class TestPolyRectangle(EndianTest): def setUp(self): self.req_args_0 = { - 'gc': 1036376211, - 'drawable': 2136753875, - 'rectangles': [{'y': -29358, 'x': -6957, 'height': 19230, 'width': 32377}, {'y': -23694, 'x': -2777, 'height': 48827, 'width': 42548}, {'y': -22773, 'x': -12641, 'height': 9809, 'width': 30955}], + 'drawable': 742422946, + 'gc': 1564604140, + 'rectangles': [{'x': -4030, 'y': -970, 'width': 17374, 'height': 11958}, {'x': -13744, 'y': -1228, 'width': 64713, 'height': 17653}, {'x': -31515, 'y': -29216, 'width': 39352, 'height': 28735}], } - self.req_bin_0 = b'\x43\x00\x09\x00' b'\xd3\x46\x5c\x7f' \ - b'\x93\xd8\xc5\x3d' b'\xd3\xe4\x52\x8d' \ - b'\x79\x7e\x1e\x4b' b'\x27\xf5\x72\xa3' \ - b'\x34\xa6\xbb\xbe' b'\x9f\xce\x0b\xa7' \ - b'\xeb\x78\x51\x26' + self.req_bin_0 = b'\x43\x00\x09\x00' b'\xa2\x79\x40\x2c' \ + b'\xec\xf6\x41\x5d' b'\x42\xf0\x36\xfc' \ + b'\xde\x43\xb6\x2e' b'\x50\xca\x34\xfb' \ + b'\xc9\xfc\xf5\x44' b'\xe5\x84\xe0\x8d' \ + b'\xb8\x99\x3f\x70' def testPackRequest0(self): bin = request.PolyRectangle._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.PolyRectangle._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestPolyArc(unittest.TestCase): +class TestPolyArc(EndianTest): def setUp(self): self.req_args_0 = { - 'drawable': 2066514582, - 'gc': 956699423, - 'arcs': [{'width': 36714, 'angle1': -22260, 'angle2': -28493, 'y': -394, 'x': -6756, 'height': 63498}, {'width': 31212, 'angle1': -5166, 'angle2': -19039, 'y': -11179, 'x': -20569, 'height': 27113}, {'width': 62033, 'angle1': -18595, 'angle2': -26291, 'y': -8396, 'x': -7987, 'height': 11428}], + 'arcs': [{'x': -6999, 'y': -22490, 'width': 28855, 'height': 39984, 'angle1': -517, 'angle2': -16010}, {'x': -28979, 'y': -20146, 'width': 59205, 'height': 38043, 'angle1': -26540, 'angle2': -24422}, {'x': -31314, 'y': -9543, 'width': 28833, 'height': 366, 'angle1': -15732, 'angle2': -2439}], + 'drawable': 1732034432, + 'gc': 1156382390, } - self.req_bin_0 = b'\x44\x00\x0c\x00' b'\x96\x82\x2c\x7b' \ - b'\x1f\x13\x06\x39' b'\x9c\xe5\x76\xfe' \ - b'\x6a\x8f\x0a\xf8' b'\x0c\xa9\xb3\x90' \ - b'\xa7\xaf\x55\xd4' b'\xec\x79\xe9\x69' \ - b'\xd2\xeb\xa1\xb5' b'\xcd\xe0\x34\xdf' \ - b'\x51\xf2\xa4\x2c' b'\x5d\xb7\x4d\x99' + self.req_bin_0 = b'\x44\x00\x0c\x00' b'\x80\xbf\x3c\x67' \ + b'\xb6\xfe\xec\x44' b'\xa9\xe4\x26\xa8' \ + b'\xb7\x70\x30\x9c' b'\xfb\xfd\x76\xc1' \ + b'\xcd\x8e\x4e\xb1' b'\x45\xe7\x9b\x94' \ + b'\x54\x98\x9a\xa0' b'\xae\x85\xb9\xda' \ + b'\xa1\x70\x6e\x01' b'\x8c\xc2\x79\xf6' def testPackRequest0(self): bin = request.PolyArc._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.PolyArc._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestFillPoly(unittest.TestCase): +class TestFillPoly(EndianTest): def setUp(self): self.req_args_0 = { - 'coord_mode': 1, - 'drawable': 526750870, - 'points': [{'y': -765, 'x': -11821}, {'y': -10853, 'x': -1907}, {'y': -29710, 'x': -468}], - 'gc': 112110920, - 'shape': 0, + 'coord_mode': 0, + 'drawable': 423195261, + 'gc': 782225195, + 'points': [{'x': -10262, 'y': -9194}, {'x': -1958, 'y': -8456}, {'x': -8617, 'y': -10793}], + 'shape': 1, } - self.req_bin_0 = b'\x45\x00\x07\x00' b'\x96\x94\x65\x1f' \ - b'\x48\xad\xae\x06' b'\x00\x01\x00\x00' \ - b'\xd3\xd1\x03\xfd' b'\x8d\xf8\x9b\xd5' \ - b'\x2c\xfe\xf2\x8b' + self.req_bin_0 = b'\x45\x00\x07\x00' b'\x7d\x72\x39\x19' \ + b'\x2b\xcf\x9f\x2e' b'\x01\x00\x00\x00' \ + b'\xea\xd7\x16\xdc' b'\x5a\xf8\xf8\xde' \ + b'\x57\xde\xd7\xd5' def testPackRequest0(self): bin = request.FillPoly._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.FillPoly._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestPolyFillRectangle(unittest.TestCase): +class TestPolyFillRectangle(EndianTest): def setUp(self): self.req_args_0 = { - 'gc': 468793444, - 'drawable': 878946804, - 'rectangles': [{'y': -29169, 'x': -18095, 'height': 15301, 'width': 12078}, {'y': -7148, 'x': -18997, 'height': 7501, 'width': 17120}], + 'drawable': 267696363, + 'gc': 1545726032, + 'rectangles': [{'x': -1676, 'y': -11003, 'width': 60599, 'height': 21895}, {'x': -12349, 'y': -22482, 'width': 43731, 'height': 55831}], } - self.req_bin_0 = b'\x46\x00\x07\x00' b'\xf4\xa9\x63\x34' \ - b'\x64\x38\xf1\x1b' b'\x51\xb9\x0f\x8e' \ - b'\x2e\x2f\xc5\x3b' b'\xcb\xb5\x14\xe4' \ - b'\xe0\x42\x4d\x1d' + self.req_bin_0 = b'\x46\x00\x07\x00' b'\xeb\xb8\xf4\x0f' \ + b'\x50\xe8\x21\x5c' b'\x74\xf9\x05\xd5' \ + b'\xb7\xec\x87\x55' b'\xc3\xcf\x2e\xa8' \ + b'\xd3\xaa\x17\xda' def testPackRequest0(self): bin = request.PolyFillRectangle._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.PolyFillRectangle._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestPolyFillArc(unittest.TestCase): +class TestPolyFillArc(EndianTest): def setUp(self): self.req_args_0 = { - 'drawable': 1286339124, - 'gc': 1256983120, - 'arcs': [{'width': 62526, 'angle1': -17496, 'angle2': -20949, 'y': -21843, 'x': -31746, 'height': 59073}], + 'arcs': [{'x': -3276, 'y': -22928, 'width': 33490, 'height': 20525, 'angle1': -10916, 'angle2': -19386}], + 'drawable': 700537986, + 'gc': 864213787, } - self.req_bin_0 = b'\x47\x00\x06\x00' b'\x34\xfa\xab\x4c' \ - b'\x50\x0a\xec\x4a' b'\xfe\x83\xad\xaa' \ - b'\x3e\xf4\xc1\xe6' b'\xa8\xbb\x2b\xae' + self.req_bin_0 = b'\x47\x00\x06\x00' b'\x82\x5c\xc1\x29' \ + b'\x1b\xdb\x82\x33' b'\x34\xf3\x70\xa6' \ + b'\xd2\x82\x2d\x50' b'\x5c\xd5\x46\xb4' def testPackRequest0(self): bin = request.PolyFillArc._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.PolyFillArc._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestPutImage(unittest.TestCase): +class TestPutImage(EndianTest): def setUp(self): self.req_args_0 = { - 'dst_y': -18744, - 'width': 39512, - 'left_pad': 222, - 'gc': 1858057277, - 'dst_x': -9189, + 'data': b'\xe9\x10\xf2o\x7f{\xae-\xe6\x18\xce\x83', + 'depth': 172, + 'drawable': 634980240, + 'dst_x': -18991, + 'dst_y': -10980, 'format': 2, - 'drawable': 935710750, - 'data': 'bit map data', - 'depth': 218, - 'height': 16464, + 'gc': 1190657277, + 'height': 12828, + 'left_pad': 225, + 'width': 8597, } - self.req_bin_0 = b'\x48\x02\x09\x00' b'\x1e\xd0\xc5\x37' \ - b'\x3d\xb4\xbf\x6e' b'\x58\x9a\x50\x40' \ - b'\x1b\xdc\xc8\xb6' b'\xde\xda\x00\x00' \ - b'\x62\x69\x74\x20' b'\x6d\x61\x70\x20' \ - b'\x64\x61\x74\x61' + self.req_bin_0 = b'\x48\x02\x09\x00' b'\x90\x07\xd9\x25' \ + b'\xfd\xfc\xf7\x46' b'\x95\x21\x1c\x32' \ + b'\xd1\xb5\x1c\xd5' b'\xe1\xac\x00\x00' \ + b'\xe9\x10\xf2\x6f' b'\x7f\x7b\xae\x2d' \ + b'\xe6\x18\xce\x83' def testPackRequest0(self): bin = request.PutImage._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.PutImage._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGetImage(unittest.TestCase): +class TestGetImage(EndianTest): def setUp(self): self.req_args_0 = { - 'width': 47689, - 'format': 1, - 'y': -2692, - 'x': -32705, - 'drawable': 377616775, - 'plane_mask': 849117586, - 'height': 24480, - } - self.req_bin_0 = b'\x49\x01\x05\x00' b'\x87\xf9\x81\x16' \ - b'\x3f\x80\x7c\xf5' b'\x49\xba\xa0\x5f' \ - b'\x92\x81\x9c\x32' + 'drawable': 872105322, + 'format': 2, + 'height': 20170, + 'plane_mask': 616208054, + 'width': 282, + 'x': -14814, + 'y': -5449, + } + self.req_bin_0 = b'\x49\x02\x05\x00' b'\x6a\x45\xfb\x33' \ + b'\x22\xc6\xb7\xea' b'\x1a\x01\xca\x4e' \ + b'\xb6\x96\xba\x24' self.reply_args_0 = { - 'depth': 249, - 'data': 'this is real ly imag e b-map', - 'visual': 141686402, - 'sequence_number': 47197, + 'data': b'\xeb?:\xa7\xc6\x8b\xc2\x96o-S\xe6\xd6z6\x94\xd7v\xd2R.\xa2\xeaw\t\x13\x95\x85', + 'depth': 181, + 'sequence_number': 28429, + 'visual': 1687469773, } - self.reply_bin_0 = b'\x01\xf9\x5d\xb8' b'\x07\x00\x00\x00' \ - b'\x82\xf6\x71\x08' b'\x00\x00\x00\x00' \ + self.reply_bin_0 = b'\x01\xb5\x0d\x6f' b'\x07\x00\x00\x00' \ + b'\xcd\xbe\x94\x64' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ - b'\x74\x68\x69\x73' b'\x20\x69\x73\x20' \ - b'\x72\x65\x61\x6c' b'\x20\x6c\x79\x20' \ - b'\x69\x6d\x61\x67' b'\x20\x65\x20\x62' \ - b'\x2d\x6d\x61\x70' + b'\xeb\x3f\x3a\xa7' b'\xc6\x8b\xc2\x96' \ + b'\x6f\x2d\x53\xe6' b'\xd6\x7a\x36\x94' \ + b'\xd7\x76\xd2\x52' b'\x2e\xa2\xea\x77' \ + b'\x09\x13\x95\x85' def testPackRequest0(self): bin = request.GetImage._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetImage._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetImage._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetImage._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestPolyText8(unittest.TestCase): +class TestPolyText8(EndianTest): def setUp(self): self.req_args_0 = { - 'y': -7036, - 'items': [{'string': 'zoo', 'delta': 2}, 16909060, {'string': 'ie', 'delta': 0}], - 'drawable': 1736403224, - 'gc': 1348241590, - 'x': -27139, - } - self.req_bin_0 = b'\x4a\x00\x08\x00' b'\x18\x69\x7f\x67' \ - b'\xb6\x88\x5c\x50' b'\xfd\x95\x84\xe4' \ + 'drawable': 1245573363, + 'gc': 1302861330, + 'items': [{'delta': 2, 'string': 'zoo'}, 16909060, {'delta': 0, 'string': 'ie'}], + 'x': -11315, + 'y': -22209, + } + self.req_bin_0 = b'\x4a\x00\x08\x00' b'\xf3\xf0\x3d\x4a' \ + b'\x12\x16\xa8\x4d' b'\xcd\xd3\x3f\xa9' \ b'\x03\x02\x7a\x6f' b'\x6f\xff\x01\x02' \ b'\x03\x04\x02\x00' b'\x69\x65\x00\x00' def testPackRequest0(self): bin = request.PolyText8._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.PolyText8._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestPolyText16(unittest.TestCase): +class TestPolyText16(EndianTest): def setUp(self): self.req_args_0 = { - 'y': -10535, - 'items': [{'string': (4131, 18), 'delta': 2}, 16909060], - 'drawable': 1669371472, - 'gc': 327278878, - 'x': -31319, - } - self.req_bin_0 = b'\x4b\x00\x07\x00' b'\x50\x96\x80\x63' \ - b'\x1e\xe1\x81\x13' b'\xa9\x85\xd9\xd6' \ + 'drawable': 998620068, + 'gc': 948793778, + 'items': [{'delta': 2, 'string': (4131, 18)}, 16909060], + 'x': -18280, + 'y': -10630, + } + self.req_bin_0 = b'\x4b\x00\x07\x00' b'\xa4\xbb\x85\x3b' \ + b'\xb2\x71\x8d\x38' b'\x98\xb8\x7a\xd6' \ b'\x02\x02\x10\x23' b'\x00\x12\xff\x01' \ b'\x02\x03\x04\x00' def testPackRequest0(self): bin = request.PolyText16._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.PolyText16._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestImageText8(unittest.TestCase): +class TestImageText8(EndianTest): def setUp(self): self.req_args_0 = { - 'y': -3727, - 'x': -15149, - 'drawable': 2131605072, - 'gc': 581816261, + 'drawable': 458985805, + 'gc': 1097803335, 'string': 'showme', + 'x': -17263, + 'y': -6759, } - self.req_bin_0 = b'\x4c\x06\x06\x00' b'\x50\xb6\x0d\x7f' \ - b'\xc5\xcf\xad\x22' b'\xd3\xc4\x71\xf1' \ + self.req_bin_0 = b'\x4c\x06\x06\x00' b'\x4d\x91\x5b\x1b' \ + b'\x47\x26\x6f\x41' b'\x91\xbc\x99\xe5' \ b'\x73\x68\x6f\x77' b'\x6d\x65\x00\x00' def testPackRequest0(self): bin = request.ImageText8._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ImageText8._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestImageText16(unittest.TestCase): +class TestImageText16(EndianTest): def setUp(self): self.req_args_0 = { - 'y': -1074, - 'x': -2847, - 'drawable': 1442818198, - 'gc': 145495998, + 'drawable': 1935336610, + 'gc': 2061289059, 'string': (115, 104, 111, 119, 109, 111, 114, 101), + 'x': -6684, + 'y': -8653, } - self.req_bin_0 = b'\x4d\x08\x08\x00' b'\x96\xa8\xff\x55' \ - b'\xbe\x17\xac\x08' b'\xe1\xf4\xce\xfb' \ + self.req_bin_0 = b'\x4d\x08\x08\x00' b'\xa2\xe4\x5a\x73' \ + b'\x63\xc6\xdc\x7a' b'\xe4\xe5\x33\xde' \ b'\x00\x73\x00\x68' b'\x00\x6f\x00\x77' \ b'\x00\x6d\x00\x6f' b'\x00\x72\x00\x65' def testPackRequest0(self): bin = request.ImageText16._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ImageText16._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestCreateColormap(unittest.TestCase): +class TestCreateColormap(EndianTest): def setUp(self): self.req_args_0 = { 'alloc': 0, - 'window': 1386427589, - 'visual': 1165319270, - 'mid': 1982619692, + 'mid': 1414936748, + 'visual': 609492200, + 'window': 182162564, } - self.req_bin_0 = b'\x4e\x00\x04\x00' b'\x2c\x60\x2c\x76' \ - b'\xc5\x34\xa3\x52' b'\x66\x5c\x75\x45' + self.req_bin_0 = b'\x4e\x00\x04\x00' b'\xac\x38\x56\x54' \ + b'\x84\x94\xdb\x0a' b'\xe8\x1c\x54\x24' def testPackRequest0(self): bin = request.CreateColormap._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.CreateColormap._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestFreeColormap(unittest.TestCase): +class TestFreeColormap(EndianTest): def setUp(self): self.req_args_0 = { - 'cmap': 1948229362, + 'cmap': 1106990292, } - self.req_bin_0 = b'\x4f\x00\x02\x00' b'\xf2\x9e\x1f\x74' + self.req_bin_0 = b'\x4f\x00\x02\x00' b'\xd4\x54\xfb\x41' def testPackRequest0(self): bin = request.FreeColormap._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.FreeColormap._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestCopyColormapAndFree(unittest.TestCase): +class TestCopyColormapAndFree(EndianTest): def setUp(self): self.req_args_0 = { - 'src_cmap': 836376231, - 'mid': 1781544437, + 'mid': 1425680795, + 'src_cmap': 1359295675, } - self.req_bin_0 = b'\x50\x00\x03\x00' b'\xf5\x35\x30\x6a' \ - b'\xa7\x16\xda\x31' + self.req_bin_0 = b'\x50\x00\x03\x00' b'\x9b\x29\xfa\x54' \ + b'\xbb\x34\x05\x51' def testPackRequest0(self): bin = request.CopyColormapAndFree._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.CopyColormapAndFree._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestInstallColormap(unittest.TestCase): +class TestInstallColormap(EndianTest): def setUp(self): self.req_args_0 = { - 'cmap': 1065317214, + 'cmap': 1329917990, } - self.req_bin_0 = b'\x51\x00\x02\x00' b'\x5e\x73\x7f\x3f' + self.req_bin_0 = b'\x51\x00\x02\x00' b'\x26\xf0\x44\x4f' def testPackRequest0(self): bin = request.InstallColormap._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.InstallColormap._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestUninstallColormap(unittest.TestCase): +class TestUninstallColormap(EndianTest): def setUp(self): self.req_args_0 = { - 'cmap': 1636916558, + 'cmap': 719876845, } - self.req_bin_0 = b'\x52\x00\x02\x00' b'\x4e\x5d\x91\x61' + self.req_bin_0 = b'\x52\x00\x02\x00' b'\xed\x72\xe8\x2a' def testPackRequest0(self): bin = request.UninstallColormap._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.UninstallColormap._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestListInstalledColormaps(unittest.TestCase): +class TestListInstalledColormaps(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 198767900, + 'window': 200613013, } - self.req_bin_0 = b'\x53\x00\x02\x00' b'\x1c\xf5\xd8\x0b' + self.req_bin_0 = b'\x53\x00\x02\x00' b'\x95\x1c\xf5\x0b' self.reply_args_0 = { - 'cmaps': [6854304, 441133660], - 'sequence_number': 56438, + 'cmaps': [1757616530, 2044469232], + 'sequence_number': 49482, } - self.reply_bin_0 = b'\x01\x00\x76\xdc' b'\x02\x00\x00\x00' \ + self.reply_bin_0 = b'\x01\x00\x4a\xc1' b'\x02\x00\x00\x00' \ b'\x02\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ - b'\xa0\x96\x68\x00' b'\x5c\x2a\x4b\x1a' + b'\x92\x19\xc3\x68' b'\xf0\x1f\xdc\x79' def testPackRequest0(self): bin = request.ListInstalledColormaps._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ListInstalledColormaps._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.ListInstalledColormaps._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.ListInstalledColormaps._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestAllocColor(unittest.TestCase): +class TestAllocColor(EndianTest): def setUp(self): self.req_args_0 = { - 'blue': 57892, - 'cmap': 1775908575, - 'green': 61383, - 'red': 8870, + 'blue': 14978, + 'cmap': 504442007, + 'green': 20599, + 'red': 44348, } - self.req_bin_0 = b'\x54\x00\x04\x00' b'\xdf\x36\xda\x69' \ - b'\xa6\x22\xc7\xef' b'\x24\xe2\x00\x00' + self.req_bin_0 = b'\x54\x00\x04\x00' b'\x97\x2c\x11\x1e' \ + b'\x3c\xad\x77\x50' b'\x82\x3a\x00\x00' self.reply_args_0 = { - 'blue': 22111, - 'green': 27536, - 'red': 54369, - 'sequence_number': 52666, - 'pixel': 1186287049, - } - self.reply_bin_0 = b'\x01\x00\xba\xcd' b'\x00\x00\x00\x00' \ - b'\x61\xd4\x90\x6b' b'\x5f\x56\x00\x00' \ - b'\xc9\x4d\xb5\x46' b'\x00\x00\x00\x00' \ + 'blue': 1856, + 'green': 9912, + 'pixel': 99308744, + 'red': 13306, + 'sequence_number': 53114, + } + self.reply_bin_0 = b'\x01\x00\x7a\xcf' b'\x00\x00\x00\x00' \ + b'\xfa\x33\xb8\x26' b'\x40\x07\x00\x00' \ + b'\xc8\x54\xeb\x05' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.AllocColor._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.AllocColor._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.AllocColor._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.AllocColor._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestAllocNamedColor(unittest.TestCase): +class TestAllocNamedColor(EndianTest): def setUp(self): self.req_args_0 = { - 'cmap': 695059054, + 'cmap': 525860889, 'name': 'octarin', } - self.req_bin_0 = b'\x55\x00\x05\x00' b'\x6e\xc2\x6d\x29' \ + self.req_bin_0 = b'\x55\x00\x05\x00' b'\x19\x00\x58\x1f' \ b'\x07\x00\x00\x00' b'\x6f\x63\x74\x61' \ b'\x72\x69\x6e\x00' self.reply_args_0 = { - 'exact_red': 45174, - 'screen_blue': 21718, - 'exact_green': 45002, - 'exact_blue': 55971, - 'screen_green': 47979, - 'screen_red': 60497, - 'sequence_number': 38835, - 'pixel': 580415589, - } - self.reply_bin_0 = b'\x01\x00\xb3\x97' b'\x00\x00\x00\x00' \ - b'\x65\x70\x98\x22' b'\x76\xb0\xca\xaf' \ - b'\xa3\xda\x51\xec' b'\x6b\xbb\xd6\x54' \ + 'exact_blue': 50619, + 'exact_green': 55944, + 'exact_red': 40316, + 'pixel': 1020413057, + 'screen_blue': 27416, + 'screen_green': 30102, + 'screen_red': 5028, + 'sequence_number': 64739, + } + self.reply_bin_0 = b'\x01\x00\xe3\xfc' b'\x00\x00\x00\x00' \ + b'\x81\x44\xd2\x3c' b'\x7c\x9d\x88\xda' \ + b'\xbb\xc5\xa4\x13' b'\x96\x75\x18\x6b' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.AllocNamedColor._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.AllocNamedColor._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.AllocNamedColor._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.AllocNamedColor._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestAllocColorCells(unittest.TestCase): +class TestAllocColorCells(EndianTest): def setUp(self): self.req_args_0 = { - 'contiguous': 1, - 'cmap': 2071194037, - 'colors': 16292, - 'planes': 14978, + 'cmap': 1542701632, + 'colors': 45892, + 'contiguous': 0, + 'planes': 25420, } - self.req_bin_0 = b'\x56\x01\x03\x00' b'\xb5\xe9\x73\x7b' \ - b'\xa4\x3f\x82\x3a' + self.req_bin_0 = b'\x56\x00\x03\x00' b'\x40\xc2\xf3\x5b' \ + b'\x44\xb3\x4c\x63' self.reply_args_0 = { - 'pixels': [1664874569, 198876857, 135035151, 1499807858, 600240169, 1403510863, 757170725, 929995606, 155550883, 642439566, 971734621, 1359474267, 609593319, 669993327, 1837906914, 1355959290, 835285748], - 'masks': [50898278, 362272940, 1106373487], - 'sequence_number': 57786, + 'masks': [1726878301, 2057281944, 1494524694], + 'pixels': [1061732426, 858313521, 524018138, 316972578, 1408939380, 1476723430, 11972931, 1917037904, 1612749468, 1847847580, 1653727126, 1901587588, 228960010, 1671710636, 913060041, 470023299, 377779303], + 'sequence_number': 34200, } - self.reply_bin_0 = b'\x01\x00\xba\xe1' b'\x14\x00\x00\x00' \ + self.reply_bin_0 = b'\x01\x00\x98\x85' b'\x14\x00\x00\x00' \ b'\x11\x00\x03\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ - b'\x49\xf8\x3b\x63' b'\xb9\x9e\xda\x0b' \ - b'\x0f\x79\x0c\x08' b'\x72\x40\x65\x59' \ - b'\x29\xf0\xc6\x23' b'\x4f\xe0\xa7\x53' \ - b'\x25\x82\x21\x2d' b'\x56\x9b\x6e\x37' \ - b'\xa3\x84\x45\x09' b'\x8e\xd9\x4a\x26' \ - b'\x5d\x7e\xeb\x39' b'\x5b\xee\x07\x51' \ - b'\xe7\xa7\x55\x24' b'\x6f\x49\xef\x27' \ - b'\xe2\x3b\x8c\x6d' b'\xfa\x4b\xd2\x50' \ - b'\xf4\x72\xc9\x31' b'\x66\xa5\x08\x03' \ - b'\xac\xd8\x97\x15' b'\x6f\xeb\xf1\x41' + b'\x4a\xc0\x48\x3f' b'\x31\xd3\x28\x33' \ + b'\xda\xe1\x3b\x1f' b'\x22\x9e\xe4\x12' \ + b'\x74\xb5\xfa\x53' b'\xe6\x02\x05\x58' \ + b'\x43\xb1\xb6\x00' b'\x50\xad\x43\x72' \ + b'\x9c\x9a\x20\x60' b'\x9c\xea\x23\x6e' \ + b'\x96\xdf\x91\x62' b'\x84\xec\x57\x71' \ + b'\x0a\xa7\xa5\x0d' b'\xac\x47\xa4\x63' \ + b'\xc9\x30\x6c\x36' b'\x83\xfc\x03\x1c' \ + b'\x67\x74\x84\x16' b'\x5d\x12\xee\x66' \ + b'\x98\xa1\x9f\x7a' b'\x16\xa3\x14\x59' self.reply_args_1 = { - 'pixels': [], 'masks': [], - 'sequence_number': 49324, + 'pixels': [], + 'sequence_number': 30700, } - self.reply_bin_1 = b'\x01\x00\xac\xc0' b'\x00\x00\x00\x00' \ + self.reply_bin_1 = b'\x01\x00\xec\x77' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' @@ -3997,580 +2810,409 @@ def setUp(self): def testPackRequest0(self): bin = request.AllocColorCells._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.AllocColorCells._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.AllocColorCells._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.AllocColorCells._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) def testPackReply1(self): bin = request.AllocColorCells._reply.to_binary(*(), **self.reply_args_1) - try: - assert bin == self.reply_bin_1 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_1) def testUnpackReply1(self): args, remain = request.AllocColorCells._reply.parse_binary(self.reply_bin_1, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_1 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_1) -class TestAllocColorPlanes(unittest.TestCase): +class TestAllocColorPlanes(EndianTest): def setUp(self): self.req_args_0 = { - 'blue': 34241, - 'colors': 11903, - 'cmap': 2107895767, - 'green': 33790, - 'contiguous': 1, - 'red': 37700, + 'blue': 8209, + 'cmap': 1197085372, + 'colors': 16587, + 'contiguous': 0, + 'green': 55852, + 'red': 60383, } - self.req_bin_0 = b'\x57\x01\x04\x00' b'\xd7\xef\xa3\x7d' \ - b'\x7f\x2e\x44\x93' b'\xfe\x83\xc1\x85' + self.req_bin_0 = b'\x57\x00\x04\x00' b'\xbc\x12\x5a\x47' \ + b'\xcb\x40\xdf\xeb' b'\x2c\xda\x11\x20' self.reply_args_0 = { - 'red_mask': 931105404, - 'blue_mask': 874671906, - 'pixels': [1675913921, 1252164172, 37816631, 1472651082], - 'sequence_number': 17565, - 'green_mask': 1072565720, - } - self.reply_bin_0 = b'\x01\x00\x9d\x44' b'\x04\x00\x00\x00' \ - b'\x04\x00\x00\x00' b'\x7c\x8a\x7f\x37' \ - b'\xd8\x0d\xee\x3f' b'\x22\x6f\x22\x34' \ + 'blue_mask': 1200348460, + 'green_mask': 2121548418, + 'pixels': [980309855, 286409072, 1721094583, 997879295], + 'red_mask': 1140662566, + 'sequence_number': 44006, + } + self.reply_bin_0 = b'\x01\x00\xe6\xab' b'\x04\x00\x00\x00' \ + b'\x04\x00\x00\x00' b'\x26\x21\xfd\x43' \ + b'\x82\x42\x74\x7e' b'\x2c\xdd\x8b\x47' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ - b'\xc1\x6a\xe4\x63' b'\x4c\x82\xa2\x4a' \ - b'\x37\x09\x41\x02' b'\x4a\xdf\xc6\x57' + b'\x5f\x57\x6e\x3a' b'\x70\x41\x12\x11' \ + b'\xb7\xd1\x95\x66' b'\xff\x6d\x7a\x3b' def testPackRequest0(self): bin = request.AllocColorPlanes._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.AllocColorPlanes._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.AllocColorPlanes._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.AllocColorPlanes._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestFreeColors(unittest.TestCase): +class TestFreeColors(EndianTest): def setUp(self): self.req_args_0 = { - 'cmap': 32694046, - 'plane_mask': 1074378407, - 'pixels': [2014216051, 1664038241, 1220941033, 1378294408, 197757808, 793595544, 1289781247, 713684847, 1724469541, 1432124373, 1426727603, 1787792301, 406458839, 1918513211, 441394489, 988895943, 146997744], - } - self.req_bin_0 = b'\x58\x00\x14\x00' b'\x1e\xdf\xf2\x01' \ - b'\xa7\xb6\x09\x40' b'\x73\x7f\x0e\x78' \ - b'\x61\x35\x2f\x63' b'\xe9\x14\xc6\x48' \ - b'\x88\x1a\x27\x52' b'\x70\x8b\xc9\x0b' \ - b'\x98\x4e\x4d\x2f' b'\xff\x7f\xe0\x4c' \ - b'\x6f\xf7\x89\x2a' b'\x25\x51\xc9\x66' \ - b'\xd5\x7b\x5c\x55' b'\xb3\x22\x0a\x55' \ - b'\xad\x8b\x8f\x6a' b'\xd7\x11\x3a\x18' \ - b'\x3b\x30\x5a\x72' b'\x39\x25\x4f\x1a' \ - b'\xc7\x5a\xf1\x3a' b'\xf0\x01\xc3\x08' + 'cmap': 341854532, + 'pixels': [1278789650, 681457705, 2040260049, 1621952585, 1914388136, 950484730, 1315726377, 1750278681, 1544694596, 1915664535, 1084068385, 916484334, 1783699241, 1947521244, 1176611597, 957657715, 1926805276], + 'plane_mask': 1597053435, + } + self.req_bin_0 = b'\x58\x00\x14\x00' b'\x44\x49\x60\x14' \ + b'\xfb\x19\x31\x5f' b'\x12\xc8\x38\x4c' \ + b'\x29\x38\x9e\x28' b'\xd1\xe5\x9b\x79' \ + b'\x49\x08\xad\x60' b'\xa8\x3e\x1b\x72' \ + b'\xfa\x3e\xa7\x38' b'\x29\x64\x6c\x4e' \ + b'\x19\x22\x53\x68' b'\x44\x2b\x12\x5c' \ + b'\x97\xb8\x2e\x72' b'\x21\x92\x9d\x40' \ + b'\xee\x70\xa0\x36' b'\x29\x17\x51\x6a' \ + b'\xdc\xd0\x14\x74' b'\x0d\xab\x21\x46' \ + b'\x73\xb2\x14\x39' b'\x1c\xb7\xd8\x72' def testPackRequest0(self): bin = request.FreeColors._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.FreeColors._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestStoreColors(unittest.TestCase): +class TestStoreColors(EndianTest): def setUp(self): self.req_args_0 = { - 'items': [{'blue': 3577, 'flags': 221, 'green': 15650, 'pixel': 330879354, 'red': 30294}, {'blue': 18226, 'flags': 219, 'green': 45614, 'pixel': 302874221, 'red': 54265}, {'blue': 32215, 'flags': 160, 'green': 48737, 'pixel': 1699694808, 'red': 60115}, {'blue': 28524, 'flags': 209, 'green': 37615, 'pixel': 710550693, 'red': 50488}], - 'cmap': 1791140577, + 'cmap': 686636594, + 'items': [{'pixel': 1850111768, 'red': 31364, 'green': 29751, 'blue': 17242, 'flags': 191}, {'pixel': 1803657350, 'red': 42045, 'green': 18429, 'blue': 50444, 'flags': 252}, {'pixel': 1345997556, 'red': 15935, 'green': 18252, 'blue': 29083, 'flags': 147}, {'pixel': 1532391469, 'red': 18981, 'green': 15623, 'blue': 18063, 'flags': 213}], } - self.req_bin_0 = b'\x59\x00\x0e\x00' b'\xe1\xa2\xc2\x6a' \ - b'\x7a\xd1\xb8\x13' b'\x56\x76\x22\x3d' \ - b'\xf9\x0d\xdd\x00' b'\x6d\x7e\x0d\x12' \ - b'\xf9\xd3\x2e\xb2' b'\x32\x47\xdb\x00' \ - b'\xd8\x48\x4f\x65' b'\xd3\xea\x61\xbe' \ - b'\xd7\x7d\xa0\x00' b'\xa5\x24\x5a\x2a' \ - b'\x38\xc5\xef\x92' b'\x6c\x6f\xd1\x00' + self.req_bin_0 = b'\x59\x00\x0e\x00' b'\x32\x3e\xed\x28' \ + b'\x18\x77\x46\x6e' b'\x84\x7a\x37\x74' \ + b'\x5a\x43\xbf\x00' b'\x86\xa0\x81\x6b' \ + b'\x3d\xa4\xfd\x47' b'\x0c\xc5\xfc\x00' \ + b'\xf4\x4a\x3a\x50' b'\x3f\x3e\x4c\x47' \ + b'\x9b\x71\x93\x00' b'\x2d\x70\x56\x5b' \ + b'\x25\x4a\x07\x3d' b'\x8f\x46\xd5\x00' def testPackRequest0(self): bin = request.StoreColors._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.StoreColors._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestStoreNamedColor(unittest.TestCase): +class TestStoreNamedColor(EndianTest): def setUp(self): self.req_args_0 = { - 'cmap': 869324276, - 'flags': 169, + 'cmap': 297221571, + 'flags': 148, 'name': 'blue', - 'pixel': 413175613, + 'pixel': 323971915, } - self.req_bin_0 = b'\x5a\xa9\x05\x00' b'\xf4\xd5\xd0\x33' \ - b'\x3d\x8f\xa0\x18' b'\x04\x00\x00\x00' \ + self.req_bin_0 = b'\x5a\x94\x05\x00' b'\xc3\x3d\xb7\x11' \ + b'\x4b\x6b\x4f\x13' b'\x04\x00\x00\x00' \ b'\x62\x6c\x75\x65' def testPackRequest0(self): bin = request.StoreNamedColor._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.StoreNamedColor._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestQueryColors(unittest.TestCase): +class TestQueryColors(EndianTest): def setUp(self): self.req_args_0 = { - 'cmap': 1750052450, - 'pixels': [1673396539, 1897675292, 1453845591, 816818886, 897340342, 1782049962, 796231465, 722380604], + 'cmap': 875378525, + 'pixels': [496695788, 822627561, 1490311416, 328212337, 1517089095, 459525846, 137995944, 890987562], } - self.req_bin_0 = b'\x5b\x00\x0a\x00' b'\x62\xae\x4f\x68' \ - b'\x3b\x01\xbe\x63' b'\x1c\x3a\x1c\x71' \ - b'\x57\xec\xa7\x56' b'\xc6\xaa\xaf\x30' \ - b'\xb6\x53\x7c\x35' b'\xaa\xec\x37\x6a' \ - b'\x29\x87\x75\x2f' b'\x3c\xa7\x0e\x2b' + self.req_bin_0 = b'\x5b\x00\x0a\x00' b'\x5d\x37\x2d\x34' \ + b'\xec\xf9\x9a\x1d' b'\xe9\x4c\x08\x31' \ + b'\xf8\x58\xd4\x58' b'\x71\x1f\x90\x13' \ + b'\x47\xf1\x6c\x5a' b'\xd6\xce\x63\x1b' \ + b'\xa8\xa6\x39\x08' b'\x2a\x64\x1b\x35' self.reply_args_0 = { - 'colors': [{'blue': 63820, 'green': 60107, 'red': 62261}, {'blue': 54480, 'green': 48839, 'red': 10033}, {'blue': 31765, 'green': 31737, 'red': 43117}, {'blue': 50953, 'green': 52009, 'red': 14234}, {'blue': 55150, 'green': 30330, 'red': 55956}], - 'sequence_number': 10895, + 'colors': [{'red': 35816, 'green': 30790, 'blue': 27504}, {'red': 4336, 'green': 13811, 'blue': 54840}, {'red': 27790, 'green': 25780, 'blue': 59555}, {'red': 50705, 'green': 38534, 'blue': 62257}, {'red': 45837, 'green': 1536, 'blue': 56402}], + 'sequence_number': 57970, } - self.reply_bin_0 = b'\x01\x00\x8f\x2a' b'\x0a\x00\x00\x00' \ + self.reply_bin_0 = b'\x01\x00\x72\xe2' b'\x0a\x00\x00\x00' \ b'\x05\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ - b'\x35\xf3\xcb\xea' b'\x4c\xf9\x00\x00' \ - b'\x31\x27\xc7\xbe' b'\xd0\xd4\x00\x00' \ - b'\x6d\xa8\xf9\x7b' b'\x15\x7c\x00\x00' \ - b'\x9a\x37\x29\xcb' b'\x09\xc7\x00\x00' \ - b'\x94\xda\x7a\x76' b'\x6e\xd7\x00\x00' + b'\xe8\x8b\x46\x78' b'\x70\x6b\x00\x00' \ + b'\xf0\x10\xf3\x35' b'\x38\xd6\x00\x00' \ + b'\x8e\x6c\xb4\x64' b'\xa3\xe8\x00\x00' \ + b'\x11\xc6\x86\x96' b'\x31\xf3\x00\x00' \ + b'\x0d\xb3\x00\x06' b'\x52\xdc\x00\x00' self.req_args_1 = { - 'cmap': 340337174, + 'cmap': 710627905, 'pixels': [], } - self.req_bin_1 = b'\x5b\x00\x02\x00' b'\x16\x22\x49\x14' + self.req_bin_1 = b'\x5b\x00\x02\x00' b'\x41\x52\x5b\x2a' def testPackRequest0(self): bin = request.QueryColors._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.QueryColors._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackRequest1(self): bin = request.QueryColors._request.to_binary(*(), **self.req_args_1) - try: - assert bin == self.req_bin_1 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_1) def testUnpackRequest1(self): args, remain = request.QueryColors._request.parse_binary(self.req_bin_1, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_1 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_1) def testPackReply0(self): bin = request.QueryColors._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.QueryColors._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestLookupColor(unittest.TestCase): +class TestLookupColor(EndianTest): def setUp(self): self.req_args_0 = { - 'cmap': 2120409969, + 'cmap': 1644167361, 'name': 'octarin', } - self.req_bin_0 = b'\x5c\x00\x05\x00' b'\x71\xe3\x62\x7e' \ + self.req_bin_0 = b'\x5c\x00\x05\x00' b'\xc1\x00\x00\x62' \ b'\x07\x00\x00\x00' b'\x6f\x63\x74\x61' \ b'\x72\x69\x6e\x00' self.reply_args_0 = { - 'exact_red': 63730, - 'screen_blue': 9467, - 'exact_green': 24400, - 'exact_blue': 27493, - 'screen_green': 15878, - 'screen_red': 26587, - 'sequence_number': 2933, - } - self.reply_bin_0 = b'\x01\x00\x75\x0b' b'\x00\x00\x00\x00' \ - b'\xf2\xf8\x50\x5f' b'\x65\x6b\xdb\x67' \ - b'\x06\x3e\xfb\x24' b'\x00\x00\x00\x00' \ + 'exact_blue': 642, + 'exact_green': 31515, + 'exact_red': 25184, + 'screen_blue': 19825, + 'screen_green': 23308, + 'screen_red': 62039, + 'sequence_number': 37984, + } + self.reply_bin_0 = b'\x01\x00\x60\x94' b'\x00\x00\x00\x00' \ + b'\x60\x62\x1b\x7b' b'\x82\x02\x57\xf2' \ + b'\x0c\x5b\x71\x4d' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.LookupColor._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.LookupColor._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.LookupColor._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.LookupColor._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestCreateCursor(unittest.TestCase): +class TestCreateCursor(EndianTest): def setUp(self): self.req_args_0 = { - 'fore_blue': 45533, - 'cid': 1389570470, - 'fore_green': 32059, - 'mask': 1475520754, - 'back_blue': 7481, - 'fore_red': 42911, - 'source': 2060548957, - 'back_green': 9237, - 'y': 31911, - 'x': 731, - 'back_red': 30886, - } - self.req_bin_0 = b'\x5d\x00\x08\x00' b'\xa6\x29\xd3\x52' \ - b'\x5d\x7b\xd1\x7a' b'\xf2\xa8\xf2\x57' \ - b'\x9f\xa7\x3b\x7d' b'\xdd\xb1\xa6\x78' \ - b'\x15\x24\x39\x1d' b'\xdb\x02\xa7\x7c' + 'back_blue': 49245, + 'back_green': 35528, + 'back_red': 27716, + 'cid': 1618141054, + 'fore_blue': 55026, + 'fore_green': 62740, + 'fore_red': 58690, + 'mask': 1832831050, + 'source': 837555484, + 'x': 48400, + 'y': 36047, + } + self.req_bin_0 = b'\x5d\x00\x08\x00' b'\x7e\xdf\x72\x60' \ + b'\x1c\x15\xec\x31' b'\x4a\xc8\x3e\x6d' \ + b'\x42\xe5\x14\xf5' b'\xf2\xd6\x44\x6c' \ + b'\xc8\x8a\x5d\xc0' b'\x10\xbd\xcf\x8c' def testPackRequest0(self): bin = request.CreateCursor._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.CreateCursor._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestCreateGlyphCursor(unittest.TestCase): +class TestCreateGlyphCursor(EndianTest): def setUp(self): self.req_args_0 = { - 'fore_blue': 25271, - 'mask_char': 19164, - 'cid': 1841424177, - 'mask': 277453392, - 'fore_green': 51196, - 'fore_red': 9195, - 'source': 21529898, - 'back_green': 55277, - 'back_blue': 7419, - 'source_char': 50271, - 'back_red': 13590, - } - self.req_bin_0 = b'\x5e\x00\x08\x00' b'\x31\xe7\xc1\x6d' \ - b'\x2a\x85\x48\x01' b'\x50\x9a\x89\x10' \ - b'\x5f\xc4\xdc\x4a' b'\xeb\x23\xfc\xc7' \ - b'\xb7\x62\x16\x35' b'\xed\xd7\xfb\x1c' + 'back_blue': 25740, + 'back_green': 2158, + 'back_red': 32083, + 'cid': 1717769345, + 'fore_blue': 28818, + 'fore_green': 18143, + 'fore_red': 14636, + 'mask': 1928100723, + 'mask_char': 32252, + 'source': 1295540602, + 'source_char': 14709, + } + self.req_bin_0 = b'\x5e\x00\x08\x00' b'\x81\x14\x63\x66' \ + b'\x7a\x61\x38\x4d' b'\x73\x7b\xec\x72' \ + b'\x75\x39\xfc\x7d' b'\x2c\x39\xdf\x46' \ + b'\x92\x70\x53\x7d' b'\x6e\x08\x8c\x64' def testPackRequest0(self): bin = request.CreateGlyphCursor._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.CreateGlyphCursor._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestFreeCursor(unittest.TestCase): +class TestFreeCursor(EndianTest): def setUp(self): self.req_args_0 = { - 'cursor': 830435200, + 'cursor': 721898231, } - self.req_bin_0 = b'\x5f\x00\x02\x00' b'\x80\x6f\x7f\x31' + self.req_bin_0 = b'\x5f\x00\x02\x00' b'\xf7\x4a\x07\x2b' def testPackRequest0(self): bin = request.FreeCursor._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.FreeCursor._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestRecolorCursor(unittest.TestCase): +class TestRecolorCursor(EndianTest): def setUp(self): self.req_args_0 = { - 'cursor': 602252227, - 'back_red': 6018, - 'fore_blue': 64036, - 'back_green': 49024, - 'back_blue': 15439, - 'fore_green': 39148, - 'fore_red': 48154, + 'back_blue': 55339, + 'back_green': 11072, + 'back_red': 47715, + 'cursor': 1436460699, + 'fore_blue': 26753, + 'fore_green': 52563, + 'fore_red': 44764, } - self.req_bin_0 = b'\x60\x00\x05\x00' b'\xc3\xa3\xe5\x23' \ - b'\x1a\xbc\xec\x98' b'\x24\xfa\x82\x17' \ - b'\x80\xbf\x4f\x3c' + self.req_bin_0 = b'\x60\x00\x05\x00' b'\x9b\xa6\x9e\x55' \ + b'\xdc\xae\x53\xcd' b'\x81\x68\x63\xba' \ + b'\x40\x2b\x2b\xd8' def testPackRequest0(self): bin = request.RecolorCursor._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.RecolorCursor._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestQueryBestSize(unittest.TestCase): +class TestQueryBestSize(EndianTest): def setUp(self): self.req_args_0 = { - 'width': 52832, + 'drawable': 1974766133, + 'height': 64528, 'item_class': 1, - 'drawable': 1606665099, - 'height': 4701, + 'width': 8620, } - self.req_bin_0 = b'\x61\x01\x03\x00' b'\x8b\xc3\xc3\x5f' \ - b'\x60\xce\x5d\x12' + self.req_bin_0 = b'\x61\x01\x03\x00' b'\x35\x8a\xb4\x75' \ + b'\xac\x21\x10\xfc' self.reply_args_0 = { - 'width': 33709, - 'sequence_number': 43788, - 'height': 12826, + 'height': 2023, + 'sequence_number': 41036, + 'width': 35260, } - self.reply_bin_0 = b'\x01\x00\x0c\xab' b'\x00\x00\x00\x00' \ - b'\xad\x83\x1a\x32' b'\x00\x00\x00\x00' \ + self.reply_bin_0 = b'\x01\x00\x4c\xa0' b'\x00\x00\x00\x00' \ + b'\xbc\x89\xe7\x07' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.QueryBestSize._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.QueryBestSize._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.QueryBestSize._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.QueryBestSize._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestQueryExtension(unittest.TestCase): +class TestQueryExtension(EndianTest): def setUp(self): self.req_args_0 = { 'name': 'XTRA', @@ -4579,56 +3221,38 @@ def setUp(self): b'\x58\x54\x52\x41' self.reply_args_0 = { - 'first_event': 163, - 'first_error': 166, - 'major_opcode': 215, + 'first_error': 237, + 'first_event': 149, + 'major_opcode': 134, 'present': 1, - 'sequence_number': 3124, + 'sequence_number': 59692, } - self.reply_bin_0 = b'\x01\x00\x34\x0c' b'\x00\x00\x00\x00' \ - b'\x01\xd7\xa3\xa6' b'\x00\x00\x00\x00' \ + self.reply_bin_0 = b'\x01\x00\x2c\xe9' b'\x00\x00\x00\x00' \ + b'\x01\x86\x95\xed' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.QueryExtension._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.QueryExtension._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.QueryExtension._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.QueryExtension._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestListExtensions(unittest.TestCase): +class TestListExtensions(EndianTest): def setUp(self): self.req_args_0 = { } @@ -4636,9 +3260,9 @@ def setUp(self): self.reply_args_0 = { 'names': ['XTRA', 'XTRA-II'], - 'sequence_number': 21122, + 'sequence_number': 9149, } - self.reply_bin_0 = b'\x01\x02\x82\x52' b'\x04\x00\x00\x00' \ + self.reply_bin_0 = b'\x01\x02\xbd\x23' b'\x04\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ @@ -4648,520 +3272,376 @@ def setUp(self): def testPackRequest0(self): bin = request.ListExtensions._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ListExtensions._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.ListExtensions._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.ListExtensions._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) - - -class TestChangeKeyboardMapping(unittest.TestCase): - def setUp(self): - self.req_args_0 = { - 'first_keycode': 131, - 'keysyms': [[1479273593, 495399194, 1752874714], [183124138, 826800766, 542058728], [519501686, 1358630902, 1051542205], [1363902850, 52079613, 1721268402], [2124568309, 323328202, 1426344655], [1775218167, 1821828429, 1704892958], [1784543283, 783698836, 1882907069], [1165130550, 1276086917, 957090966], [1623553701, 77158667, 420399405], [790514637, 1104383431, 1645303152], [879499287, 349457843, 1313813953], [367336866, 1207824094, 514125338], [767413913, 135340640, 756292967], [475442692, 2076098223, 1252936842], [964050497, 2006979633, 948353974], [1923834215, 1061136894, 1319606154], [1186538913, 1770176901, 715354628], [1470481551, 403222608, 252019996], [260033548, 1553379907, 1096456683], [2027881549, 1992616114, 382810564]], - } - self.req_bin_0 = b'\x64\x14\x3e\x00' b'\x83\x03\x00\x00' \ - b'\x79\xec\x2b\x58' b'\x1a\x31\x87\x1d' \ - b'\xda\xbe\x7a\x68' b'\xaa\x40\xea\x0a' \ - b'\x7e\xfa\x47\x31' b'\xe8\x28\x4f\x20' \ - b'\x76\xf7\xf6\x1e' b'\xf6\x0f\xfb\x50' \ - b'\xbd\x42\xad\x3e' b'\x82\x81\x4b\x51' \ - b'\xfd\xab\x1a\x03' b'\xb2\x78\x98\x66' \ - b'\xf5\x56\xa2\x7e' b'\xca\x98\x45\x13' \ - b'\xcf\x4a\x04\x55' b'\xf7\xad\xcf\x69' \ - b'\x4d\xe5\x96\x6c' b'\x1e\x9a\x9e\x65' \ - b'\x33\xf8\x5d\x6a' b'\x94\x4b\xb6\x2e' \ - b'\xbd\xe1\x3a\x70' b'\x36\x7b\x72\x45' \ - b'\x85\x8a\x0f\x4c' b'\x96\x0c\x0c\x39' \ - b'\xa5\x76\xc5\x60' b'\x0b\x59\x99\x04' \ - b'\x2d\xc9\x0e\x19' b'\xcd\x4b\x1e\x2f' \ - b'\xc7\x8d\xd3\x41' b'\x70\x55\x11\x62' \ - b'\x17\x18\x6c\x34' b'\xb3\x4d\xd4\x14' \ - b'\xc1\x35\x4f\x4e' b'\xa2\x1d\xe5\x15' \ - b'\xde\xee\xfd\x47' b'\x1a\xee\xa4\x1e' \ - b'\x99\xce\xbd\x2d' b'\x60\x22\x11\x08' \ - b'\x67\x1d\x14\x2d' b'\x04\xae\x56\x1c' \ - b'\xaf\xbe\xbe\x7b' b'\x8a\x4c\xae\x4a' \ - b'\x41\x3e\x76\x39' b'\x31\x14\xa0\x77' \ - b'\xb6\xbb\x86\x38' b'\x67\x61\xab\x72' \ - b'\xfe\xa9\x3f\x3f' b'\x8a\x97\xa7\x4e' \ - b'\xa1\x25\xb9\x46' b'\x85\xc1\x82\x69' \ - b'\x04\x72\xa3\x2a' b'\x8f\xc4\xa5\x57' \ - b'\x50\xb0\x08\x18' b'\x1c\x85\x05\x0f' \ - b'\x0c\xcc\x7f\x0f' b'\x43\xb2\x96\x5c' \ - b'\xeb\x99\x5a\x41' b'\x4d\x04\xdf\x78' \ - b'\xb2\xe8\xc4\x76' b'\xc4\x39\xd1\x16' + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) + + +class TestChangeKeyboardMapping(EndianTest): + def setUp(self): + self.req_args_0 = { + 'first_keycode': 157, + 'keysyms': [[1861549105, 991489870, 390260112], [107985429, 558681426, 814119353], [702984500, 454537006, 976459372], [701896028, 724776911, 1634728346], [1889012491, 814167346, 597551532], [1614928797, 2042695294, 1786543801], [905303576, 541748982, 1792957544], [175892294, 1009976242, 41625283], [1608517348, 1158393599, 111852976], [2147285698, 2044231981, 751534113], [481513427, 1396173819, 147356828], [1677685199, 2055755177, 1399632465], [86453688, 1619703478, 66636412], [2039275666, 531036848, 428123802], [1802230236, 43765755, 1334308166], [327238597, 512271361, 271057482], [1016964633, 1437651928, 245649464], [1211115441, 2035292716, 468075293], [998652876, 1502089592, 550279151], [1646901134, 792196355, 360324443]], + } + self.req_bin_0 = b'\x64\x14\x3e\x00' b'\x9d\x03\x00\x00' \ + b'\x31\xfc\xf4\x6e' b'\x4e\xef\x18\x3b' \ + b'\x90\xe5\x42\x17' b'\x15\xba\x6f\x06' \ + b'\x52\xcd\x4c\x21' b'\xb9\x79\x86\x30' \ + b'\x34\xb1\xe6\x29' b'\x2e\xaf\x17\x1b' \ + b'\x6c\x96\x33\x3a' b'\x5c\x15\xd6\x29' \ + b'\xcf\x37\x33\x2b' b'\x9a\xf9\x6f\x61' \ + b'\x0b\x0b\x98\x70' b'\x32\x35\x87\x30' \ + b'\xac\xe9\x9d\x23' b'\x9d\xdb\x41\x60' \ + b'\x7e\x0e\xc1\x79' b'\xb9\x7e\x7c\x6a' \ + b'\x18\xd6\xf5\x35' b'\xf6\x6e\x4a\x20' \ + b'\x68\x5c\xde\x6a' b'\x46\xe7\x7b\x0a' \ + b'\xb2\x03\x33\x3c' b'\xc3\x26\x7b\x02' \ + b'\xe4\x06\xe0\x5f' b'\xff\xae\x0b\x45' \ + b'\xb0\xbd\xaa\x06' b'\xc2\xfa\xfc\x7f' \ + b'\x2d\x81\xd8\x79' b'\x21\x80\xcb\x2c' \ + b'\xd3\x4f\xb3\x1c' b'\xfb\xeb\x37\x53' \ + b'\x9c\x7c\xc8\x08' b'\xcf\x71\xff\x63' \ + b'\xa9\x55\x88\x7a' b'\x51\xb2\x6c\x53' \ + b'\xb8\x2d\x27\x05' b'\xb6\xb6\x8a\x60' \ + b'\x7c\xca\xf8\x03' b'\x92\xe0\x8c\x79' \ + b'\xb0\xfa\xa6\x1f' b'\x9a\xa6\x84\x19' \ + b'\xdc\xd9\x6b\x6b' b'\xfb\xcf\x9b\x02' \ + b'\x46\xed\x87\x4f' b'\xc5\x43\x81\x13' \ + b'\x01\xa4\x88\x1e' b'\x4a\x02\x28\x10' \ + b'\x19\xa6\x9d\x3c' b'\xd8\xd3\xb0\x55' \ + b'\x38\x50\xa4\x0e' b'\xb1\x27\x30\x48' \ + b'\x2c\x1a\x50\x79' b'\x1d\x43\xe6\x1b' \ + b'\xcc\x3b\x86\x3b' b'\x78\x11\x88\x59' \ + b'\xef\x97\xcc\x20' b'\x8e\xb7\x29\x62' \ + b'\x03\xf5\x37\x2f' b'\x5b\x1d\x7a\x15' def testPackRequest0(self): bin = request.ChangeKeyboardMapping._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ChangeKeyboardMapping._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGetKeyboardMapping(unittest.TestCase): +class TestGetKeyboardMapping(EndianTest): def setUp(self): self.req_args_0 = { - 'first_keycode': 174, - 'count': 233, + 'count': 207, + 'first_keycode': 169, } - self.req_bin_0 = b'\x65\x00\x02\x00' b'\xae\xe9\x00\x00' + self.req_bin_0 = b'\x65\x00\x02\x00' b'\xa9\xcf\x00\x00' self.reply_args_0 = { - 'keysyms': [[536700486, 90972970, 1834434734], [604690854, 1612992766, 1785113276], [1258017014, 814047417, 79874791], [1752913778, 2069894554, 1342993084], [691283205, 2002270597, 1552550365], [1427239047, 80222814, 380890249], [932130695, 1233544402, 1343201446], [850296480, 830996690, 1219102856], [1427529259, 1334110395, 1423305447], [925543758, 1154246092, 389857513], [782217983, 1673349321, 296773941], [904384636, 788791004, 1427343811], [578056967, 1628142600, 882651915], [1727003528, 1202959768, 59536638], [932784259, 453243643, 1846802632], [1527858524, 2055184942, 1534128611], [134086768, 909769847, 323736641], [2080620639, 1573387975, 566724688], [1393924270, 1408645244, 1610610798], [391612329, 341605408, 484634403]], - 'sequence_number': 27901, + 'keysyms': [[232140298, 1242716010, 55143985], [1994770011, 669923085, 1236514049], [1454592222, 1949971307, 2057660497], [805965556, 851808913, 2021792706], [1535482384, 425909956, 163201187], [1271520474, 1483083165, 1783638995], [1346992789, 521515080, 218831382], [1497210568, 1658890074, 647643874], [1825990828, 1469435098, 1289374120], [1729858135, 259963764, 1709884923], [2112789657, 1215330896, 1680696611], [88195295, 745614404, 1144061708], [919934772, 1420606257, 795794911], [148083460, 1086542523, 1390588550], [732788374, 27170279, 1824449766], [902069278, 1765942198, 1052700150], [226642993, 930984408, 2063275595], [777792886, 1364908620, 1914642756], [1779635393, 987282730, 1518933756], [328545991, 935201525, 378251236]], + 'sequence_number': 48346, } - self.reply_bin_0 = b'\x01\x03\xfd\x6c' b'\x3c\x00\x00\x00' \ + self.reply_bin_0 = b'\x01\x03\xda\xbc' b'\x3c\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ - b'\x46\x66\xfd\x1f' b'\x2a\x23\x6c\x05' \ - b'\xae\x40\x57\x6d' b'\xa6\xd9\x0a\x24' \ - b'\xfe\x50\x24\x60' b'\xbc\xaa\x66\x6a' \ - b'\xf6\xd0\xfb\x4a' b'\xb9\x60\x85\x30' \ - b'\xe7\xca\xc2\x04' b'\x72\x57\x7b\x68' \ - b'\x9a\x15\x60\x7b' b'\xbc\x72\x0c\x50' \ - b'\x05\x25\x34\x29' b'\x85\x39\x58\x77' \ - b'\xdd\x09\x8a\x5c' b'\x87\xf0\x11\x55' \ - b'\x5e\x1a\xc8\x04' b'\x89\xec\xb3\x16' \ - b'\x87\x2f\x8f\x37' b'\xd2\x64\x86\x49' \ - b'\xa6\xa0\x0f\x50' b'\xa0\x7e\xae\x32' \ - b'\xd2\x00\x88\x31' b'\x88\x08\xaa\x48' \ - b'\x2b\x5e\x16\x55' b'\xbb\xe8\x84\x4f' \ - b'\xe7\xea\xd5\x54' b'\x4e\xad\x2a\x37' \ - b'\xcc\x65\xcc\x44' b'\xe9\xc0\x3c\x17' \ - b'\xff\xb2\x9f\x2e' b'\xc9\x48\xbd\x63' \ - b'\x35\x69\xb0\x11' b'\x7c\xd0\xe7\x35' \ - b'\xdc\xfe\x03\x2f' b'\xc3\x89\x13\x55' \ - b'\x07\x73\x74\x22' b'\x08\x7c\x0b\x61' \ - b'\x0b\x33\x9c\x34' b'\x88\xfb\xef\x66' \ - b'\x98\xb5\xb3\x47' b'\xfe\x74\x8c\x03' \ - b'\x83\x28\x99\x37' b'\xfb\xf2\x03\x1b' \ - b'\xc8\xf8\x13\x6e' b'\x5c\x45\x11\x5b' \ - b'\x2e\xa2\x7f\x7a' b'\xe3\xf1\x70\x5b' \ - b'\x70\x00\xfe\x07' b'\x77\xfc\x39\x36' \ - b'\x41\xd4\x4b\x13' b'\x5f\xc0\x03\x7c' \ - b'\xc7\xfe\xc7\x5d' b'\x50\x88\xc7\x21' \ - b'\xae\x98\x15\x53' b'\x7c\x38\xf6\x53' \ - b'\x6e\xf8\xff\x5f' b'\xa9\x87\x57\x17' \ - b'\x20\x7c\x5c\x14' b'\x23\xef\xe2\x1c' + b'\x0a\x2e\xd6\x0d' b'\x6a\x57\x12\x4a' \ + b'\x31\x6e\x49\x03' b'\x5b\xc6\xe5\x76' \ + b'\x0d\x37\xee\x27' b'\x01\xb5\xb3\x49' \ + b'\xde\x50\xb3\x56' b'\x6b\x33\x3a\x74' \ + b'\x51\x68\xa5\x7a' b'\xf4\x0e\x0a\x30' \ + b'\x91\x92\xc5\x32' b'\xc2\x1b\x82\x78' \ + b'\x10\x9a\x85\x5b' b'\xc4\xde\x62\x19' \ + b'\xa3\x40\xba\x09' b'\xda\xdc\xc9\x4b' \ + b'\x9d\x0d\x66\x58' b'\xd3\x2b\x50\x6a' \ + b'\x95\x7a\x49\x50' b'\x48\xb0\x15\x1f' \ + b'\x16\x1a\x0b\x0d' b'\xc8\x9e\x3d\x59' \ + b'\x5a\xa7\xe0\x62' b'\xe2\x42\x9a\x26' \ + b'\xac\x68\xd6\x6c' b'\xda\xcc\x95\x57' \ + b'\xa8\x49\xda\x4c' b'\x57\x8a\x1b\x67' \ + b'\x74\xbb\x7e\x0f' b'\xfb\xc5\xea\x65' \ + b'\x99\x9c\xee\x7d' b'\x50\x7a\x70\x48' \ + b'\x23\x65\x2d\x64' b'\xdf\xc0\x41\x05' \ + b'\x44\x2c\x71\x2c' b'\x0c\xff\x30\x44' \ + b'\x34\x17\xd5\x36' b'\x31\xbb\xac\x54' \ + b'\xdf\xdd\x6e\x2f' b'\x04\x93\xd3\x08' \ + b'\xbb\x52\xc3\x40' b'\x86\xb2\xe2\x52' \ + b'\x96\x76\xad\x2b' b'\xe7\x95\x9e\x01' \ + b'\xe6\xe4\xbe\x6c' b'\x1e\x7c\xc4\x35' \ + b'\xb6\x23\x42\x69' b'\xf6\xed\xbe\x3e' \ + b'\x31\x4c\x82\x0d' b'\xd8\xb1\x7d\x37' \ + b'\x4b\x16\xfb\x7a' b'\x76\x2d\x5c\x2e' \ + b'\x4c\xda\x5a\x51' b'\x44\x21\x1f\x72' \ + b'\xc1\x14\x13\x6a' b'\x2a\xbd\xd8\x3a' \ + b'\xfc\x16\x89\x5a' b'\xc7\x36\x95\x13' \ + b'\xf5\x0a\xbe\x37' b'\xe4\xa7\x8b\x16' def testPackRequest0(self): bin = request.GetKeyboardMapping._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetKeyboardMapping._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetKeyboardMapping._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetKeyboardMapping._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestChangeKeyboardControl(unittest.TestCase): +class TestChangeKeyboardControl(EndianTest): def setUp(self): self.req_args_0 = { - 'attrs': {'led': 241, 'key': 193, 'bell_duration': -19485, 'auto_repeat_mode': 0, 'bell_pitch': -13220, 'key_click_percent': -3, 'bell_percent': -74, 'led_mode': 1}, + 'attrs': {'key_click_percent': -59, 'bell_percent': -5, 'bell_pitch': -2303, 'bell_duration': -4223, 'led': 196, 'led_mode': 1, 'key': 190, 'auto_repeat_mode': 0}, } self.req_bin_0 = b'\x66\x00\x0a\x00' b'\xff\x00\x00\x00' \ - b'\xfd\x00\x00\x00' b'\xb6\x00\x00\x00' \ - b'\x5c\xcc\x00\x00' b'\xe3\xb3\x00\x00' \ - b'\xf1\x00\x00\x00' b'\x01\x00\x00\x00' \ - b'\xc1\x00\x00\x00' b'\x00\x00\x00\x00' + b'\xc5\x00\x00\x00' b'\xfb\x00\x00\x00' \ + b'\x01\xf7\x00\x00' b'\x81\xef\x00\x00' \ + b'\xc4\x00\x00\x00' b'\x01\x00\x00\x00' \ + b'\xbe\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.ChangeKeyboardControl._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ChangeKeyboardControl._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGetKeyboardControl(unittest.TestCase): +class TestGetKeyboardControl(EndianTest): def setUp(self): self.req_args_0 = { } self.req_bin_0 = b'\x67\x00\x01\x00' self.reply_args_0 = { - 'led_mask': 1389423883, - 'global_auto_repeat': 1, - 'auto_repeats': [129, 211, 180, 202, 218, 145, 129, 136, 137, 165, 210, 160, 229, 223, 226, 130, 197, 233, 187, 166, 211, 241, 173, 183, 184, 216, 216, 218, 182, 224, 175, 210], - 'bell_pitch': 27576, - 'bell_duration': 26314, - 'bell_percent': 130, - 'sequence_number': 62321, - 'key_click_percent': 140, - } - self.reply_bin_0 = b'\x01\x01\x71\xf3' b'\x05\x00\x00\x00' \ - b'\x0b\xed\xd0\x52' b'\x8c\x82\xb8\x6b' \ - b'\xca\x66\x00\x00' b'\x81\xd3\xb4\xca' \ - b'\xda\x91\x81\x88' b'\x89\xa5\xd2\xa0' \ - b'\xe5\xdf\xe2\x82' b'\xc5\xe9\xbb\xa6' \ - b'\xd3\xf1\xad\xb7' b'\xb8\xd8\xd8\xda' \ - b'\xb6\xe0\xaf\xd2' + 'auto_repeats': [199, 243, 190, 246, 225, 214, 135, 254, 211, 174, 252, 182, 218, 194, 215, 199, 198, 130, 176, 149, 189, 232, 253, 189, 249, 253, 242, 132, 151, 203, 184, 231], + 'bell_duration': 35050, + 'bell_percent': 249, + 'bell_pitch': 36528, + 'global_auto_repeat': 0, + 'key_click_percent': 222, + 'led_mask': 1425908825, + 'sequence_number': 20323, + } + self.reply_bin_0 = b'\x01\x00\x63\x4f' b'\x05\x00\x00\x00' \ + b'\x59\xa4\xfd\x54' b'\xde\xf9\xb0\x8e' \ + b'\xea\x88\x00\x00' b'\xc7\xf3\xbe\xf6' \ + b'\xe1\xd6\x87\xfe' b'\xd3\xae\xfc\xb6' \ + b'\xda\xc2\xd7\xc7' b'\xc6\x82\xb0\x95' \ + b'\xbd\xe8\xfd\xbd' b'\xf9\xfd\xf2\x84' \ + b'\x97\xcb\xb8\xe7' def testPackRequest0(self): bin = request.GetKeyboardControl._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetKeyboardControl._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetKeyboardControl._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetKeyboardControl._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestBell(unittest.TestCase): +class TestBell(EndianTest): def setUp(self): self.req_args_0 = { - 'percent': -14, + 'percent': -40, } - self.req_bin_0 = b'\x68\xf2\x01\x00' + self.req_bin_0 = b'\x68\xd8\x01\x00' def testPackRequest0(self): bin = request.Bell._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.Bell._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestChangePointerControl(unittest.TestCase): +class TestChangePointerControl(EndianTest): def setUp(self): self.req_args_0 = { - 'accel_num': -5554, - 'threshold': -10566, + 'accel_denum': -8326, + 'accel_num': -18826, 'do_accel': 1, - 'accel_denum': -24572, 'do_thresh': 1, + 'threshold': -14733, } - self.req_bin_0 = b'\x69\x00\x03\x00' b'\x4e\xea\x04\xa0' \ - b'\xba\xd6\x01\x01' + self.req_bin_0 = b'\x69\x00\x03\x00' b'\x76\xb6\x7a\xdf' \ + b'\x73\xc6\x01\x01' def testPackRequest0(self): bin = request.ChangePointerControl._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ChangePointerControl._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGetPointerControl(unittest.TestCase): +class TestGetPointerControl(EndianTest): def setUp(self): self.req_args_0 = { } self.req_bin_0 = b'\x6a\x00\x01\x00' self.reply_args_0 = { - 'accel_num': 11888, - 'threshold': 36822, - 'sequence_number': 62480, - 'accel_denom': 46073, + 'accel_denom': 18010, + 'accel_num': 29992, + 'sequence_number': 46318, + 'threshold': 20350, } - self.reply_bin_0 = b'\x01\x00\x10\xf4' b'\x00\x00\x00\x00' \ - b'\x70\x2e\xf9\xb3' b'\xd6\x8f\x00\x00' \ + self.reply_bin_0 = b'\x01\x00\xee\xb4' b'\x00\x00\x00\x00' \ + b'\x28\x75\x5a\x46' b'\x7e\x4f\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.GetPointerControl._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetPointerControl._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetPointerControl._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetPointerControl._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestSetScreenSaver(unittest.TestCase): +class TestSetScreenSaver(EndianTest): def setUp(self): self.req_args_0 = { - 'prefer_blank': 1, - 'interval': -19218, - 'timeout': -2423, 'allow_exposures': 2, + 'interval': -25214, + 'prefer_blank': 0, + 'timeout': -24531, } - self.req_bin_0 = b'\x6b\x00\x03\x00' b'\x89\xf6\xee\xb4' \ - b'\x01\x02\x00\x00' + self.req_bin_0 = b'\x6b\x00\x03\x00' b'\x2d\xa0\x82\x9d' \ + b'\x00\x02\x00\x00' def testPackRequest0(self): bin = request.SetScreenSaver._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.SetScreenSaver._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestGetScreenSaver(unittest.TestCase): +class TestGetScreenSaver(EndianTest): def setUp(self): self.req_args_0 = { } self.req_bin_0 = b'\x6c\x00\x01\x00' self.reply_args_0 = { - 'interval': 51464, - 'prefer_blanking': 1, - 'timeout': 5207, - 'sequence_number': 45153, - 'allow_exposures': 1, - } - self.reply_bin_0 = b'\x01\x00\x61\xb0' b'\x00\x00\x00\x00' \ - b'\x57\x14\x08\xc9' b'\x01\x01\x00\x00' \ + 'allow_exposures': 0, + 'interval': 8091, + 'prefer_blanking': 0, + 'sequence_number': 12877, + 'timeout': 20935, + } + self.reply_bin_0 = b'\x01\x00\x4d\x32' b'\x00\x00\x00\x00' \ + b'\xc7\x51\x9b\x1f' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' def testPackRequest0(self): bin = request.GetScreenSaver._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetScreenSaver._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetScreenSaver._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetScreenSaver._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestChangeHosts(unittest.TestCase): +class TestChangeHosts(EndianTest): def setUp(self): self.req_args_0 = { - 'host': [150, 200, 205, 182], - 'mode': 0, + 'host': [183, 251, 198, 200], 'host_family': 0, + 'mode': 0, } self.req_bin_0 = b'\x6d\x00\x03\x00' b'\x00\x00\x04\x00' \ - b'\x96\xc8\xcd\xb6' + b'\xb7\xfb\xc6\xc8' def testPackRequest0(self): bin = request.ChangeHosts._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ChangeHosts._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestListHosts(unittest.TestCase): +class TestListHosts(EndianTest): def setUp(self): self.req_args_0 = { } self.req_bin_0 = b'\x6e\x00\x01\x00' self.reply_args_0 = { - 'hosts': [{'name': [34, 23, 178, 12], 'family': 0}, {'name': [130, 236, 254, 15], 'family': 0}], + 'hosts': [{'family': 0, 'name': [34, 23, 178, 12]}, {'family': 0, 'name': [130, 236, 254, 15]}], 'mode': 1, - 'sequence_number': 33455, + 'sequence_number': 15164, } - self.reply_bin_0 = b'\x01\x01\xaf\x82' b'\x04\x00\x00\x00' \ + self.reply_bin_0 = b'\x01\x01\x3c\x3b' b'\x04\x00\x00\x00' \ b'\x02\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ @@ -5171,42 +3651,24 @@ def setUp(self): def testPackRequest0(self): bin = request.ListHosts._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ListHosts._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.ListHosts._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.ListHosts._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestSetAccessControl(unittest.TestCase): +class TestSetAccessControl(EndianTest): def setUp(self): self.req_args_0 = { 'mode': 1, @@ -5216,114 +3678,78 @@ def setUp(self): def testPackRequest0(self): bin = request.SetAccessControl._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.SetAccessControl._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestSetCloseDownMode(unittest.TestCase): +class TestSetCloseDownMode(EndianTest): def setUp(self): self.req_args_0 = { - 'mode': 1, + 'mode': 0, } - self.req_bin_0 = b'\x70\x01\x01\x00' + self.req_bin_0 = b'\x70\x00\x01\x00' def testPackRequest0(self): bin = request.SetCloseDownMode._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.SetCloseDownMode._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestKillClient(unittest.TestCase): +class TestKillClient(EndianTest): def setUp(self): self.req_args_0 = { - 'resource': 1900634441, + 'resource': 649180254, } - self.req_bin_0 = b'\x71\x00\x02\x00' b'\x49\x61\x49\x71' + self.req_bin_0 = b'\x71\x00\x02\x00' b'\x5e\xb4\xb1\x26' def testPackRequest0(self): bin = request.KillClient._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.KillClient._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestRotateProperties(unittest.TestCase): +class TestRotateProperties(EndianTest): def setUp(self): self.req_args_0 = { - 'window': 1149115389, - 'properties': [194806244, 1444715269, 486779871, 1850032482, 1083061497, 786546027, 807635511, 1716883082, 80335197, 1654299, 1459844212, 850673646], - 'delta': -27029, + 'delta': -11867, + 'properties': [30448914, 1520523655, 1147111912, 271900374, 589144637, 97809756, 2092347973, 117159267, 1188394866, 627424198, 1497757970, 2027482546], + 'window': 271248673, } - self.req_bin_0 = b'\x72\x00\x0f\x00' b'\xfd\x1b\x7e\x44' \ - b'\x0c\x00\x6b\x96' b'\xe4\x81\x9c\x0b' \ - b'\x05\x9b\x1c\x56' b'\xdf\xab\x03\x1d' \ - b'\x62\x41\x45\x6e' b'\xf9\x34\x8e\x40' \ - b'\x6b\xbd\xe1\x2e' b'\x37\x8a\x23\x30' \ - b'\x8a\x8e\x55\x66' b'\x5d\xd1\xc9\x04' \ - b'\x1b\x3e\x19\x00' b'\x74\x74\x03\x57' \ - b'\xee\x3f\xb4\x32' + self.req_bin_0 = b'\x72\x00\x0f\x00' b'\x21\xed\x2a\x10' \ + b'\x0c\x00\xa5\xd1' b'\x12\x9d\xd0\x01' \ + b'\x87\x59\xa1\x5a' b'\xe8\x89\x5f\x44' \ + b'\xd6\xde\x34\x10' b'\x3d\xa2\x1d\x23' \ + b'\x5c\x75\xd4\x05' b'\x45\xb2\xb6\x7c' \ + b'\x63\xb5\xfb\x06' b'\x72\x77\xd5\x46' \ + b'\xc6\xbb\x65\x25' b'\x12\xf9\x45\x59' \ + b'\xb2\xed\xd8\x78' def testPackRequest0(self): bin = request.RotateProperties._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.RotateProperties._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestForceScreenSaver(unittest.TestCase): +class TestForceScreenSaver(EndianTest): def setUp(self): self.req_args_0 = { 'mode': 1, @@ -5333,36 +3759,27 @@ def setUp(self): def testPackRequest0(self): bin = request.ForceScreenSaver._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.ForceScreenSaver._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) -class TestSetPointerMapping(unittest.TestCase): +class TestSetPointerMapping(EndianTest): def setUp(self): self.req_args_0 = { - 'map': [130, 178, 229, 218, 178], + 'map': [154, 131, 200, 248, 250], } - self.req_bin_0 = b'\x74\x05\x03\x00' b'\x82\xb2\xe5\xda' \ - b'\xb2\x00\x00\x00' + self.req_bin_0 = b'\x74\x05\x03\x00' b'\x9a\x83\xc8\xf8' \ + b'\xfa\x00\x00\x00' self.reply_args_0 = { - 'status': 145, - 'sequence_number': 57045, + 'sequence_number': 22584, + 'status': 240, } - self.reply_bin_0 = b'\x01\x91\xd5\xde' b'\x00\x00\x00\x00' \ + self.reply_bin_0 = b'\x01\xf0\x38\x58' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' @@ -5370,109 +3787,73 @@ def setUp(self): def testPackRequest0(self): bin = request.SetPointerMapping._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.SetPointerMapping._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.SetPointerMapping._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.SetPointerMapping._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestGetPointerMapping(unittest.TestCase): +class TestGetPointerMapping(EndianTest): def setUp(self): self.req_args_0 = { } self.req_bin_0 = b'\x75\x00\x01\x00' self.reply_args_0 = { - 'map': [248, 185, 227, 157, 133], - 'sequence_number': 20072, + 'map': [175, 141, 192, 250, 157], + 'sequence_number': 54134, } - self.reply_bin_0 = b'\x01\x05\x68\x4e' b'\x02\x00\x00\x00' \ + self.reply_bin_0 = b'\x01\x05\x76\xd3' b'\x02\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ - b'\xf8\xb9\xe3\x9d' b'\x85\x00\x00\x00' + b'\xaf\x8d\xc0\xfa' b'\x9d\x00\x00\x00' def testPackRequest0(self): bin = request.GetPointerMapping._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetPointerMapping._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetPointerMapping._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetPointerMapping._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestSetModifierMapping(unittest.TestCase): +class TestSetModifierMapping(EndianTest): def setUp(self): self.req_args_0 = { - 'keycodes': [[6, 191], [94, 123], [46, 94], [104, 116], [132, 158], [35, 75], [128, 63], [135, 221]], + 'keycodes': [[33, 205], [251, 37], [27, 77], [76, 155], [43, 127], [60, 213], [115, 194], [230, 226]], } - self.req_bin_0 = b'\x76\x02\x05\x00' b'\x06\xbf\x5e\x7b' \ - b'\x2e\x5e\x68\x74' b'\x84\x9e\x23\x4b' \ - b'\x80\x3f\x87\xdd' + self.req_bin_0 = b'\x76\x02\x05\x00' b'\x21\xcd\xfb\x25' \ + b'\x1b\x4d\x4c\x9b' b'\x2b\x7f\x3c\xd5' \ + b'\x73\xc2\xe6\xe2' self.reply_args_0 = { - 'status': 149, - 'sequence_number': 26757, + 'sequence_number': 56627, + 'status': 204, } - self.reply_bin_0 = b'\x01\x95\x85\x68' b'\x00\x00\x00\x00' \ + self.reply_bin_0 = b'\x01\xcc\x33\xdd' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' @@ -5480,97 +3861,61 @@ def setUp(self): def testPackRequest0(self): bin = request.SetModifierMapping._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.SetModifierMapping._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.SetModifierMapping._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.SetModifierMapping._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestGetModifierMapping(unittest.TestCase): +class TestGetModifierMapping(EndianTest): def setUp(self): self.req_args_0 = { } self.req_bin_0 = b'\x77\x00\x01\x00' self.reply_args_0 = { - 'keycodes': [[85, 162], [139, 194], [12, 107], [120, 193], [26, 40], [125, 221], [27, 0], [220, 78]], - 'sequence_number': 17677, + 'keycodes': [[219, 156], [30, 50], [106, 108], [135, 41], [80, 122], [88, 38], [80, 1], [209, 230]], + 'sequence_number': 45434, } - self.reply_bin_0 = b'\x01\x02\x0d\x45' b'\x04\x00\x00\x00' \ + self.reply_bin_0 = b'\x01\x02\x7a\xb1' b'\x04\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ b'\x00\x00\x00\x00' b'\x00\x00\x00\x00' \ - b'\x55\xa2\x8b\xc2' b'\x0c\x6b\x78\xc1' \ - b'\x1a\x28\x7d\xdd' b'\x1b\x00\xdc\x4e' + b'\xdb\x9c\x1e\x32' b'\x6a\x6c\x87\x29' \ + b'\x50\x7a\x58\x26' b'\x50\x01\xd1\xe6' def testPackRequest0(self): bin = request.GetModifierMapping._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.GetModifierMapping._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) def testPackReply0(self): bin = request.GetModifierMapping._reply.to_binary(*(), **self.reply_args_0) - try: - assert bin == self.reply_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.reply_bin_0) def testUnpackReply0(self): args, remain = request.GetModifierMapping._reply.parse_binary(self.reply_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.reply_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.reply_args_0) -class TestNoOperation(unittest.TestCase): +class TestNoOperation(EndianTest): def setUp(self): self.req_args_0 = { } @@ -5579,23 +3924,13 @@ def setUp(self): def testPackRequest0(self): bin = request.NoOperation._request.to_binary(*(), **self.req_args_0) - try: - assert bin == self.req_bin_0 - except AssertionError: - raise AssertionError(tohex(bin)) + self.assertBinaryEqual(bin, self.req_bin_0) def testUnpackRequest0(self): args, remain = request.NoOperation._request.parse_binary(self.req_bin_0, dummy_display, 1) - try: - assert len(remain) == 0 - except AssertionError: - raise AssertionError(tohex(remain)) - try: - assert args == self.req_args_0 - except AssertionError: - raise AssertionError(args) + self.assertBinaryEmpty(remain) + self.assertEqual(args, self.req_args_0) if __name__ == "__main__": - check_endian() unittest.main() diff --git a/test/test_struct.py b/test/test_struct.py new file mode 100644 index 00000000..47da4e5d --- /dev/null +++ b/test/test_struct.py @@ -0,0 +1,197 @@ + +from collections import OrderedDict +from functools import partial +import struct +import types +import re + +from six import binary_type, iterbytes + +from Xlib.protocol import rq +from . import DummyDisplay, TestCase + + +dummy_display = DummyDisplay() + +def pack(format, *args): + return struct.pack('=' + format, *args) + +def packstr(s, padding=0): + return s.encode() + (b'\0' * padding) + + +class StructTest(object): + """ Test class helper for rq.Struct packing/unpacking support. """ + + struct = None + values_in = None + binary = None + values_out = None + + def test_pack_value_dict(self): + self.assertBinaryEqual(self.struct.pack_value(dict(self.values_in)), self.binary) + + def test_pack_value_tuple(self): + self.assertBinaryEqual(self.struct.pack_value(tuple(self.values_in.values())), self.binary) + + def test_to_binary_args(self): + self.assertBinaryEqual(self.struct.to_binary(*self.values_in.values()), self.binary) + + def test_to_binary_kwargs(self): + self.assertBinaryEqual(self.struct.to_binary(**dict(self.values_in)), self.binary) + + def test_parse_binary(self): + values, remain = self.struct.parse_binary(self.binary, dummy_display) + self.assertEqual(values, rq.DictWrapper(dict(self.values_out))) + self.assertBinaryEmpty(remain) + + +def _struct_test(name, fields): + """ Generate a new Struct packing/unpacking test. + + is a list of (field_name, field_type, field_value, field_binary): + - field_name: + name of the field, None if it's not a named field (e.g. LengthOf) + - field_type: + factory for the field type, taking one parameter only, the name of + the field and returning a rq.Field subclass instance + - field_value_in: + the raw value passed in when packing and expected output on unpacking + - field_binary: + the binary representation of the field value or a function to + convert it to binary for creating the expected result of packing + the struct + - field_value_out: + the raw value passed expected on output on unpacking + (optional, is used if not specified) + """ + + class_name = ''.join([part.capitalize() for part in re.sub(r'[^\w]+', ' ', name).split()]) + class_name += 'StructTest' + struct_layout = [] + values_in = OrderedDict() + binary = b'' + values_out = OrderedDict() + for field_params in fields: + assert 4 <= len(field_params) <= 5 + field_name, field_type, field_value_in, field_binary = field_params[0:4] + if len(field_params) == 5: + field_value_out = field_params[4] + else: + field_value_out = field_value_in + struct_layout.append(field_type(field_name)) + if field_name is not None: + if field_value_in is not None: + 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): + binary += field_binary + elif isinstance(field_binary, (types.FunctionType, types.LambdaType, partial)): + binary += field_binary(field_value_in) + else: + raise ValueError('unsupported type for binary: {data} [{type}]'.format( + data=str(field_binary), type=type(field_binary)) + ) + class_dict = { + 'struct': rq.Struct(*struct_layout), + 'values_in': values_in, + 'binary': binary, + 'values_out': values_out, + } + globals()[class_name] = type(class_name, (StructTest, TestCase), class_dict) + + +_struct_test('card', ( + ('c8' , rq.Card8 , 0x42 , partial(pack, 'B')), + ('c16', rq.Card16, 0x666 , partial(pack, 'H')), + ('c32', rq.Card32, 0xdeadbeef, partial(pack, 'L')), +)) + +_struct_test('int', ( + ('i8' , rq.Int8 , -42 , partial(pack, 'b')), + ('i16', rq.Int16, -666 , partial(pack, 'h')), + ('i32', rq.Int32, -2147483648, partial(pack, 'l')), +)) + +_struct_test('list', ( + (None , lambda name: rq.LengthOf('lc8', 1) , None , pack('B', 2) ), + (None , lambda name: rq.LengthOf('lc16', 2) , None , pack('H', 3) ), + (None , lambda name: rq.LengthOf('lc32', 4) , None , pack('L', 5) ), + ('lc8' , lambda name: rq.List(name, rq.Card8 , pad=0), [0x42, 0xc3] , lambda v: pack('2B' , *v)), + ('lc16' , lambda name: rq.List(name, rq.Card16, pad=0), [666, 1, 60143] , lambda v: pack('3H' , *v)), + ('lc32' , lambda name: rq.List(name, rq.Card32, pad=0), [0xf02facb, 666, 1, 0x1043, 0xdeadbeef], lambda v: pack('5L' , *v)), +)) + +_struct_test('list pad', ( + (None , lambda name: rq.LengthOf('lc8', 1) , None , pack('B', 2) ), + (None , lambda name: rq.LengthOf('lc16', 2) , None , pack('H', 3) ), + (None , lambda name: rq.LengthOf('lc32', 4) , None , pack('L', 5) ), + ('lc8' , lambda name: rq.List(name, rq.Card8 , pad=1), [0x42, 0xc3] , lambda v: pack('2B2x', *v)), + ('lc16' , lambda name: rq.List(name, rq.Card16, pad=1), [666, 1, 60143] , lambda v: pack('3H2x', *v)), + ('lc32' , lambda name: rq.List(name, rq.Card32, pad=1), [0xf02facb, 666, 1, 0x1043, 0xdeadbeef], lambda v: pack('5L' , *v)), +)) + +_struct_test('fixed list', ( + ('lc8' , lambda name: rq.FixedList(name, 2, rq.Card8 , pad=0), [0x42, 0xc3] , lambda v: pack('2B' , *v)), + ('lc16' , lambda name: rq.FixedList(name, 3, rq.Card16, pad=0), [666, 1, 60143] , lambda v: pack('3H' , *v)), + ('lc32' , lambda name: rq.FixedList(name, 5, rq.Card32, pad=0), [0xf02facb, 666, 1, 0x1043, 0xdeadbeef], lambda v: pack('5L' , *v)), +)) + +_struct_test('fixed list pad', ( + ('lc8p' , lambda name: rq.FixedList(name, 2, rq.Card8 , pad=1), [0x42, 0xc3] , lambda v: pack('2B2x', *v)), + ('lc16p', lambda name: rq.FixedList(name, 3, rq.Card16, pad=1), [666, 1, 60143] , lambda v: pack('3H2x', *v)), + ('lc32p', lambda name: rq.FixedList(name, 5, rq.Card32, pad=1), [0xf02facb, 666, 1, 0x1043, 0xdeadbeef], lambda v: pack('5L' , *v)), +)) + +_struct_test('string8', ( + (None, lambda name: rq.LengthOf('s1', 1) , None , pack('B', 7) ), + (None, lambda name: rq.LengthOf('s2', 2) , None , pack('H', 13)), + (None, lambda name: rq.LengthOf('s3', 4) , None , pack('L', 34)), + ('s1', lambda name: rq.String8(name, pad=0), "testing" , packstr ), + ('s2', lambda name: rq.String8(name, pad=0), "one two three" , packstr ), + ('s3', lambda name: rq.String8(name, pad=0), "supercalifragilisticexpialidocious", packstr ), +)) + +_struct_test('string8 pad', ( + (None, lambda name: rq.LengthOf('s1', 1) , None , pack('B', 7) ), + (None, lambda name: rq.LengthOf('s2', 2) , None , pack('H', 13) ), + (None, lambda name: rq.LengthOf('s3', 4) , None , pack('L', 34) ), + ('s1', lambda name: rq.String8(name, pad=1), "testing" , partial(packstr, padding=1)), + ('s2', lambda name: rq.String8(name, pad=1), "one two three" , partial(packstr, padding=3)), + ('s3', lambda name: rq.String8(name, pad=1), "supercalifragilisticexpialidocious", partial(packstr, padding=2)), +)) + +_struct_test('simple string16', ( + (None, lambda name: rq.LengthOf('s1', 1) , None , pack('B', 3) ), + (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)), +)) + +_struct_test('binary', ( + (None, lambda name: rq.LengthOf('s1', 1) , None , pack('B', 7) ), + (None, lambda name: rq.LengthOf('s2', 2) , None , pack('H', 13)), + (None, lambda name: rq.LengthOf('s3', 4) , None , pack('L', 34)), + ('s1', lambda name: rq.Binary(name, pad=0), b"testing" , lambda v: v), + ('s2', lambda name: rq.Binary(name, pad=0), b"one two three" , lambda v: v), + ('s3', lambda name: rq.Binary(name, pad=0), b"supercalifragilisticexpialidocious", lambda v: v), +)) + +_struct_test('binary pad', ( + (None, lambda name: rq.LengthOf('s1', 1) , None , pack('B', 7) ), + (None, lambda name: rq.LengthOf('s2', 2) , None , pack('H', 13)), + (None, lambda name: rq.LengthOf('s3', 4) , None , pack('L', 34)), + ('s1', lambda name: rq.Binary(name, pad=1), b"testing" , lambda v: v + b'\0' * 1), + ('s2', lambda name: rq.Binary(name, pad=1), b"one two three" , lambda v: v + b'\0' * 3), + ('s3', lambda name: rq.Binary(name, pad=1), b"supercalifragilisticexpialidocious", lambda v: v + b'\0' * 2), +)) + +_struct_test('fixed binary', ( + ('s1', lambda name: rq.FixedBinary(name, 7 ), b"testing" , lambda v: v), + ('s2', lambda name: rq.FixedBinary(name, 13), b"one two three" , lambda v: v), + ('s3', lambda name: rq.FixedBinary(name, 34), b"supercalifragilisticexpialidocious", lambda v: v), + # Make sure fixed binary fields are handled as static fields. + ('c8', rq.Card8, 0x42, partial(pack, 'B')), +)) diff --git a/test/test_unix_connect.py b/test/test_unix_connect.py new file mode 100644 index 00000000..3199fa5f --- /dev/null +++ b/test/test_unix_connect.py @@ -0,0 +1,157 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -* + +from functools import partial +import socket +import sys +import unittest + +from mock import patch + +from Xlib.support import unix_connect +from Xlib.error import DisplayConnectionError, DisplayNameError + + +@unittest.skipUnless(sys.platform.startswith('linux'), 'Linux specific tests') +class TestUnixConnect(unittest.TestCase): + + def test_get_display(self): + # Valid cases. + for display, expected in ( + # Implicit Unix socket connections. + (':0.1', (None, '', 0, 1)), + (':4', (None, '', 4, 0)), + # Implicit TCP connections. + ('foo:1.2', (None, 'foo', 1, 2)), + ('bar:5', (None, 'bar', 5, 0)), + # Explicit Unix socket connections. + ('unix/foo:4.3', ('unix', 'foo', 4, 3)), + ('unix/:66', ('unix', '', 66, 0)), + # Explicit TCP connections. + ('tcp/foo:11.1', ('tcp', 'foo', 11, 1)), + ('tcp/bar:66.6', ('tcp', 'bar', 66, 6)), + ('tcp/unix:54.3', ('tcp', 'unix', 54, 3)), + # Special case: `unix:0.0` is equivalent to `:0.0`. + ('unix:99.5', (None, 'unix', 99, 5)), + ('unix:42', (None, 'unix', 42, 0)), + ): + result = unix_connect.get_display(display) + self.assertEqual(result, (display,) + expected) + # Invalid cases. + for display in ( + # No display number. + '', + ':', + 'foo', + 'bar:', + # Bad screen number. + ':48.', + ':47.f', + # Bad hostname. + u'fòó:0', + u'tcp/bàr:1', + u'unix/fòóbàr:2', + # Bad protocol. + 'udp/foo:0' + # With explicit TCP connections, hostname must be set. + 'tcp/:0', + ): + with self.assertRaises(DisplayNameError): + unix_connect.get_display(display) + + def test_get_socket(self): + class FakeSocket(object): + def fileno(self): + return 42 + calls = [] + def _get_socket(socket_type, raises, *params): + calls.append(('_get_%s_socket' % socket_type,) + params) + if raises: + raise socket.error() + return FakeSocket() + def path_exists(returns, path): + calls.append(('os.path.exists', path)) + return returns + def ensure_not_inheritable(*args): + calls.append(('ensure_not_inheritable',) + args) + for params, allow_unix, unix_addr_exists, allow_tcp, expect_connection_error, expected_calls in ( + # Successful explicit TCP socket connection. + (('tcp/host:6', None, 'host', 6), False, False, True, False, [ + ('_get_tcp_socket', 'host', 6), + ]), + # Failed explicit TCP socket connection. + (('tcp/host:6', None, 'host', 6), False, False, False, True, [ + ('_get_tcp_socket', 'host', 6), + ]), + # Successful implicit TCP socket connection. + (('host:5', None, 'host', 5), False, False, True, False, [ + ('_get_tcp_socket', 'host', 5), + ]), + # Failed implicit TCP socket connection. + (('host:5', None, 'host', 5), False, False, False, True, [ + ('_get_tcp_socket', 'host', 5), + ]), + # Successful explicit Unix socket connection. + (('unix/name:0', 'unix', 'name', 0), True, True, False, False, [ + ('os.path.exists', '/tmp/.X11-unix/X0'), + ('_get_unix_socket', '/tmp/.X11-unix/X0'), + ]), + # Failed explicit Unix socket connection. + (('unix/name:0', 'unix', 'name', 0), False, True, False, True, [ + ('os.path.exists', '/tmp/.X11-unix/X0'), + ('_get_unix_socket', '/tmp/.X11-unix/X0'), + ]), + # Successful explicit Unix socket connection, variant. + (('unix:0', None, 'unix', 0), True, True, False, False, [ + ('os.path.exists', '/tmp/.X11-unix/X0'), + ('_get_unix_socket', '/tmp/.X11-unix/X0'), + ]), + # Failed explicit Unix socket connection, variant. + (('unix:0', None, 'unix', 0), False, True, False, True, [ + ('os.path.exists', '/tmp/.X11-unix/X0'), + ('_get_unix_socket', '/tmp/.X11-unix/X0'), + ]), + # Successful implicit Unix socket connection. + ((':4', None, '', 4), True, True, False, False, [ + ('os.path.exists', '/tmp/.X11-unix/X4'), + ('_get_unix_socket', '/tmp/.X11-unix/X4'), + ]), + # Successful implicit Unix socket connection, abstract address. + ((':3', None, '', 3), True, False, False, False, [ + ('os.path.exists', '/tmp/.X11-unix/X3'), + ('_get_unix_socket', '\0/tmp/.X11-unix/X3'), + ]), + # Failed implicit Unix socket connection, successful fallback on TCP. + ((':2', None, '', 2), False, False, True, False, [ + ('os.path.exists', '/tmp/.X11-unix/X2'), + ('_get_unix_socket', '\0/tmp/.X11-unix/X2'), + ('_get_tcp_socket', '', 2), + ]), + # Failed implicit Unix socket connection, failed fallback on TCP. + ((':1', None, '', 1), False, False, False, True, [ + ('os.path.exists', '/tmp/.X11-unix/X1'), + ('_get_unix_socket', '\0/tmp/.X11-unix/X1'), + ('_get_tcp_socket', '', 1), + ]), + ): + with \ + patch('Xlib.support.unix_connect._get_unix_socket', + partial(_get_socket, 'unix', not allow_unix)), \ + patch('Xlib.support.unix_connect._get_tcp_socket', + partial(_get_socket, 'tcp', not allow_tcp)), \ + patch('os.path.exists', + partial(path_exists, unix_addr_exists)), \ + patch('Xlib.support.unix_connect._ensure_not_inheritable', ensure_not_inheritable): + del calls[:] + if expect_connection_error: + with self.assertRaises(DisplayConnectionError): + unix_connect.get_socket(*params) + else: + s = unix_connect.get_socket(*params) + self.assertIsInstance(s, FakeSocket) + expected_calls.append(('ensure_not_inheritable', s)) + self.assertEqual(calls, expected_calls) + + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_xlib_display.py b/test/test_xlib_display.py new file mode 100644 index 00000000..61994617 --- /dev/null +++ b/test/test_xlib_display.py @@ -0,0 +1,172 @@ +#!/usr/bin/env python + +import sys +import os +import unittest + +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) + +import Xlib.display +import Xlib.error +import Xlib.protocol.display +import Xlib.protocol.event +import Xlib.protocol.rq +import Xlib.xobject.fontable +import Xlib.X + + +class TestXlibDisplay(unittest.TestCase): + def setUp(self): + # Create authority file. + self.display_num = os.getenv("DISPLAY") + self.display = Xlib.display.Display(self.display_num) + self.dummy_str = "qqq" + self.keysym = 65535 + + def test_display_instance(self): + self.assertTrue(isinstance(self.display, Xlib.display.Display)) + + def test_default_display_name(self): + self.assertEqual(self.display.get_display_name(), self.display_num) + + def test_default_screen_number(self): + self.assertEqual(self.display.get_default_screen(), 0) + + def test_returns_no_events(self): + self.assertEqual(self.display.pending_events(), 0) + + def test_pointer_mapping_is_list(self): + self.assertTrue(isinstance(self.display.get_pointer_mapping(), list)) + + def test_set_get_pointer_mapping(self): + orig_mapping = self.display.get_pointer_mapping() + length = len(orig_mapping) + try: + self.display.set_pointer_mapping([0] * length) + self.assertEqual(self.display.get_pointer_mapping(), [0] * length) + finally: + self.display.set_pointer_mapping(orig_mapping) + + def test_can_close_display(self): + self.display.close() + self.assertEqual(str(self.display.display.socket_error), "Display connection closed by client") + + def test_can_close_display_and_check_for_error(self): + self.display.close() + self.assertRaises(Xlib.error.ConnectionClosedError, self.display.flush) + + def test_return_fileno(self): + self.assertTrue(isinstance(self.display.fileno(), int)) + + def test_has_no_invalid_extension(self): + self.assertTrue(~self.display.has_extension(self.dummy_str)) + + def test_has_valid_extension(self): + extensions = self.display.list_extensions() + if extensions: + self.assertTrue(~self.display.has_extension(extensions[0])) + + def test_can_create_resource_object(self): + self.assertTrue( + isinstance(self.display.create_resource_object("font", 0), Xlib.xobject.fontable.Font)) + + def test_get_default_screen_instance(self): + self.assertTrue(isinstance(self.display.screen(), Xlib.protocol.rq.DictWrapper)) + + def test_get_zero_screen_instance(self): + self.assertTrue(isinstance(self.display.screen(0), Xlib.protocol.rq.DictWrapper)) + + def test_default_screen_count(self): + self.assertEqual(self.display.screen_count(), 1) + + def test_cannot_add_existing_display_method(self): + self.assertRaises(AssertionError, self.display.extension_add_method, + "display", "extension_add_method", lambda x: x) + + def test_cannot_add_existing_font_method(self): + self.assertRaises(AssertionError, self.display.extension_add_method, "font", "__init__", lambda x: x) + + def test_can_add_extension_error(self): + self.display.extension_add_error(1, Xlib.error.XError) + self.assertEqual(self.display.display.error_classes[1], Xlib.error.XError) + + def test_keycode_to_keysym_for_invalid_index(self): + self.assertEqual(self.display.keycode_to_keysym(0, 0), Xlib.X.NoSymbol) + + def test_keysym_to_keycode_for_nosymbol(self): + self.assertEqual(self.display.keysym_to_keycode(Xlib.X.NoSymbol), 0) + + def test_keysym_to_keycode_for_valid_symbol(self): + self.assertEqual(self.display.keysym_to_keycode(self.keysym), 119) + + def test_keysym_to_keycodes_for_nosymbol(self): + self.assertEqual(self.display.keysym_to_keycodes(Xlib.X.NoSymbol), []) + + def test_refresh_keyboard_mapping_invalid_event(self): + self.assertRaises(TypeError, self.display.refresh_keyboard_mapping, Xlib.protocol.event.AnyEvent) + + def test_get_modifier_mapping(self): + self.assertEqual(len(self.display.get_modifier_mapping()), 8) + + def test_set_modifier_mapping(self): + mapping = self.display.get_modifier_mapping() + self.assertEqual(self.display.set_modifier_mapping(mapping), Xlib.X.MappingSuccess) + + def test_get_screensaver(self): + self.assertTrue(isinstance(self.display.get_screen_saver(), Xlib.protocol.request.GetScreenSaver)) + + def test_list_hosts(self): + self.assertTrue(isinstance(self.display.list_hosts(), Xlib.protocol.request.ListHosts)) + + def test_get_keyboard_control(self): + self.assertTrue( + isinstance(self.display.get_keyboard_control(), Xlib.protocol.request.GetKeyboardControl)) + + def test_change_keyboard_mapping(self): + kpt_mapping = self.display.get_keyboard_mapping(254, 1) + self.display.change_keyboard_mapping(254, kpt_mapping) + self.assertEqual(self.display.get_keyboard_mapping(254, 1), kpt_mapping) + + def test_get_font_path(self): + self.assertNotEqual(self.display.get_font_path(), []) + + def test_get_atom_name(self): + atom = self.display.get_atom(self.display_num) + val = self.display.get_atom_name(atom) + self.assertEqual(val, self.display_num) + + def test_intern_atom(self): + atom = self.display.intern_atom(self.display_num) + val = self.display.get_atom_name(atom) + self.assertEqual(val, self.display_num) + + def test_get_input_focus(self): + self.assertTrue(isinstance(self.display.get_input_focus(), Xlib.protocol.request.GetInputFocus)) + + def test_query_keymap(self): + self.assertTrue(isinstance(self.display.query_keymap(), list)) + + def test_open_invalid_font(self): + self.assertEqual(self.display.open_font(self.dummy_str), None) + + def test_list_fonts(self): + fonts = self.display.list_fonts("*", 1) + self.assertNotEqual(fonts, []) + + def test_lookup_valid_keysym(self): + self.assertNotEqual(self.display.lookup_string(self.keysym), None) + + def test_lookup_invalid_keysym(self): + self.assertEqual(self.display.lookup_string(-1), None) + + def test_rebind_string(self): + self.display.rebind_string(self.keysym, self.dummy_str) + self.assertEqual(self.display.lookup_string(self.keysym), self.dummy_str) + + def test_get_selection_owner(self): + atom = self.display.get_atom(self.display_num) + self.assertEqual(self.display.get_selection_owner(atom), 0) + + +if __name__ == '__main__': + unittest.main() diff --git a/test/testall.py b/test/testall.py deleted file mode 100644 index c3cbffad..00000000 --- a/test/testall.py +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env python - -from __future__ import print_function -import sys -import os -import unittest -import struct - -testfolder = os.path.abspath(os.path.dirname(__file__)) -package_root = os.path.abspath(os.path.join(testfolder, "..")) -sys.path.append(package_root) - -from Xlib.protocol import request, rq, event -import Xlib.protocol.event - -def is_big_endian(): - "Check endianess (return True on big-endian system)" - return struct.unpack('BB', struct.pack('H', 0x0100))[0] != 0 - - -def run_tests(): - "Run all suitable tests" - - if is_big_endian(): - excludes = ['test_events_le', 'test_requests_le', ] - else: - excludes = ['test_events_be', 'test_requests_be', ] - - suite = unittest.TestSuite() - - sys.path.append(testfolder) - - for root, dirs, files in os.walk(testfolder): - test_modules = [ - file.replace('.py', '') for file in files if - file.startswith('test_') and - file.endswith('.py')] - - test_modules = [mod for mod in test_modules if mod.lower() not in excludes] - print('test_modules:') - print(test_modules) - for mod in test_modules: - - imported_mod = __import__(mod, globals(), locals()) - - suite.addTests( - unittest.defaultTestLoader.loadTestsFromModule(imported_mod)) - - unittest.TextTestRunner(verbosity=3).run(suite) - - -if __name__ == '__main__': - run_tests() \ No newline at end of file diff --git a/tox.ini b/tox.ini new file mode 100644 index 00000000..360451f1 --- /dev/null +++ b/tox.ini @@ -0,0 +1,9 @@ +[tox] +envlist = py27,py33,py34,py35,py36 +skip_missing_interpreters = true + +[testenv] +deps= + -rdev-requirements.txt + -rrequirements.txt +commands={envpython} -W all runtests.py {posargs} diff --git a/utils/parsexbug.py b/utils/parsexbug.py index 632d6666..92f38361 100644 --- a/utils/parsexbug.py +++ b/utils/parsexbug.py @@ -20,7 +20,7 @@ def dummy_buffer(str, x, y = sys.maxint): # We don't want any fancy dictwrapper, just plain mappings rq.DictWrapper = lambda x: x -class BugFile: +class BugFile(object): def __init__(self, file): self.file = file self.cbuf = self.sbuf = '' @@ -60,7 +60,7 @@ def read_next(self): raise ValueError('Bad control line: %s' % line) -class ParseString: +class ParseString(object): def __init__(self, datafunc): self.get_data = datafunc self.data = '' @@ -102,11 +102,11 @@ def __getitem__(self, key): return self.data[i:j] -class DummyDisplay: +class DummyDisplay(object): def get_resource_class(self, name): return None -class ParseXbug: +class ParseXbug(object): def __init__(self, infile = sys.stdin, outfile = sys.stdout): bf = BugFile(infile) self.cdata = ParseString(bf.read_client)