[blinkpy] Switch to run WPT subcommands using Python3

Upstream WPT is now Python 3-first. To minimize the likelihood of
Chromium engineers writing incompatible tests*, we should run the WPT
parts of blinkpy under Python 3.

* Or, more likely, incompatible Python file handlers
(https://web-platform-tests.org/writing-tests/python-handlers/index.html)

Bug: 1135554
Change-Id: I9813a81543219ede80bb58de971d2e4509ef4b53
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2558741
Commit-Queue: Stephen McGruer <smcgruer@chromium.org>
Reviewed-by: Robert Ma <robertma@chromium.org>
Reviewed-by: Adam Rice <ricea@chromium.org>
Cr-Commit-Position: refs/heads/master@{#835668}
diff --git a/.well-known/origin-policy b/.well-known/origin-policy
index d0de31e..2f0e9d0 100644
--- a/.well-known/origin-policy
+++ b/.well-known/origin-policy
@@ -35,6 +35,6 @@
     if len(matches) != 1:
         return 404, [], '{} origin policies found at a path matching "{}"'.format(len(matches), filepath_pattern)
 
-    with open(matches[0]) as f:
+    with open(matches[0], 'rb') as f:
         data = f.read()
         return return_code, [('Content-Type', content_type)], data
diff --git a/cookies/resources/cookie.py b/cookies/resources/cookie.py
index 9710b51..63eedf0 100644
--- a/cookies/resources/cookie.py
+++ b/cookies/resources/cookie.py
@@ -21,7 +21,7 @@
     try:
         if b'drop' in request.GET:
             cookie = request.GET[b'drop']
-            cookie += "; max-age=0"
+            cookie += b'; max-age=0'
 
         if b'set' in request.GET:
             cookie = request.GET[b'set']
diff --git a/fetch/metadata/resources/post-to-owner.py b/fetch/metadata/resources/post-to-owner.py
index 4890c49..256dd6e 100644
--- a/fetch/metadata/resources/post-to-owner.py
+++ b/fetch/metadata/resources/post-to-owner.py
@@ -9,6 +9,10 @@
     ]
     key = request.GET.first(b"key", None)
 
+    # We serialize the key into JSON, so have to decode it first.
+    if key is not None:
+      key = key.decode('utf-8')
+
     body = u"""
         <!DOCTYPE html>
         <script src="/portals/resources/stash-utils.sub.js"></script>
diff --git a/xhr/resources/auth5/auth.py b/xhr/resources/auth5/auth.py
index e18319e..43b376e 100644
--- a/xhr/resources/auth5/auth.py
+++ b/xhr/resources/auth5/auth.py
@@ -10,6 +10,6 @@
         response.headers.set(b'WWW-Authenticate', b'Basic realm="test"')
         content = b'User name/password wrong or not given: '
 
-    content += b"%s\n%s" % (request.auth.username,
-                            request.auth.password)
+    content += b"%s\n%s" % (request.auth.username or b'',
+                            request.auth.password or b'')
     return content