From 59da8450fdfc4c794307299c378cd7c38efaab9d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juan=20Luis=20Boya=20Garc=C3=ADa?= <ntrrgc@gmail.com>
Date: Sun, 23 Feb 2014 17:21:09 +0100
Subject: [PATCH] Fix get_best_auth for Python 3

All self.entries items are byte strings, but get_best_auth receives
Unicode strings. Convert them to bytes before comparing.

This fixes a bug that prevented python3-xlib to find X11 cookies in
Xauthority, thus not allowing to use it without `xhost +`.
---
 Xlib/xauth.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/Xlib/xauth.py b/Xlib/xauth.py
index d10338b..bf841dc 100644
--- a/Xlib/xauth.py
+++ b/Xlib/xauth.py
@@ -97,7 +97,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,7 +110,8 @@ def get_best_auth(self, family, address, dispno,
         otherwise XNoAuthError is raised.
         """
 
-        num = str(dispno)
+        num = str(dispno).encode()
+        address = address.encode()
 
         matches = {}
 
