From c5a3395b8781e14c4566cf0e476b234d6a1c1224 Mon Sep 17 00:00:00 2001 From: Jay Lee Date: Fri, 17 Jan 2020 11:18:47 -0800 Subject: [PATCH] fix: make collections import compatible across Python versions (#419) * Use collections.abc, fixes #418 * Python 2.7 compat fix * Fix check --- google/auth/jwt.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/google/auth/jwt.py b/google/auth/jwt.py index a30c575b2..361c4567a 100644 --- a/google/auth/jwt.py +++ b/google/auth/jwt.py @@ -40,7 +40,10 @@ """ -import collections +try: + from collections.abc import Mapping +except ImportError: # Python 2.7 compatibility + from collections import Mapping import copy import datetime import json @@ -215,7 +218,7 @@ def decode(token, certs=None, verify=True, audience=None): # If certs is specified as a dictionary of key IDs to certificates, then # use the certificate identified by the key ID in the token header. - if isinstance(certs, collections.Mapping): + if isinstance(certs, Mapping): key_id = header.get("kid") if key_id: if key_id not in certs: