Skip to content

Commit 7078e96

Browse files
authored
chore: Dropped the dependency on six (#385)
* Removing Python 2 support * Upgraded to Pylint 2.x and fixed all linter errors for Python 3 * Removed the dependency on the six library
1 parent 0e4f3bf commit 7078e96

22 files changed

+84
-104
lines changed

firebase_admin/__init__.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
import os
1919
import threading
2020

21-
import six
22-
2321
from firebase_admin import credentials
2422
from firebase_admin.__about__ import __version__
2523

@@ -126,7 +124,7 @@ def get_app(name=_DEFAULT_APP_NAME):
126124
ValueError: If the specified name is not a string, or if the specified
127125
app does not exist.
128126
"""
129-
if not isinstance(name, six.string_types):
127+
if not isinstance(name, str):
130128
raise ValueError('Illegal app name argument type: "{}". App name '
131129
'must be a string.'.format(type(name)))
132130
with _apps_lock:
@@ -203,7 +201,7 @@ def __init__(self, name, credential, options):
203201
Raises:
204202
ValueError: If an argument is None or invalid.
205203
"""
206-
if not name or not isinstance(name, six.string_types):
204+
if not name or not isinstance(name, str):
207205
raise ValueError('Illegal Firebase app name "{0}" provided. App name must be a '
208206
'non-empty string.'.format(name))
209207
self._name = name
@@ -221,7 +219,7 @@ def __init__(self, name, credential, options):
221219

222220
@classmethod
223221
def _validate_project_id(cls, project_id):
224-
if project_id is not None and not isinstance(project_id, six.string_types):
222+
if project_id is not None and not isinstance(project_id, str):
225223
raise ValueError(
226224
'Invalid project ID: "{0}". project ID must be a string.'.format(project_id))
227225

@@ -286,7 +284,7 @@ def _get_service(self, name, initializer):
286284
Raises:
287285
ValueError: If the provided name is invalid, or if the App is already deleted.
288286
"""
289-
if not name or not isinstance(name, six.string_types):
287+
if not name or not isinstance(name, str):
290288
raise ValueError(
291289
'Illegal name argument: "{0}". Name must be a non-empty string.'.format(name))
292290
with self._lock:

firebase_admin/_auth_utils.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616

1717
import json
1818
import re
19-
20-
import six
21-
from six.moves import urllib
19+
from urllib import parse
2220

2321
from firebase_admin import exceptions
2422
from firebase_admin import _utils
@@ -35,7 +33,7 @@
3533
def validate_uid(uid, required=False):
3634
if uid is None and not required:
3735
return None
38-
if not isinstance(uid, six.string_types) or not uid or len(uid) > 128:
36+
if not isinstance(uid, str) or not uid or len(uid) > 128:
3937
raise ValueError(
4038
'Invalid uid: "{0}". The uid must be a non-empty string with no more than 128 '
4139
'characters.'.format(uid))
@@ -44,7 +42,7 @@ def validate_uid(uid, required=False):
4442
def validate_email(email, required=False):
4543
if email is None and not required:
4644
return None
47-
if not isinstance(email, six.string_types) or not email:
45+
if not isinstance(email, str) or not email:
4846
raise ValueError(
4947
'Invalid email: "{0}". Email must be a non-empty string.'.format(email))
5048
parts = email.split('@')
@@ -61,7 +59,7 @@ def validate_phone(phone, required=False):
6159
"""
6260
if phone is None and not required:
6361
return None
64-
if not isinstance(phone, six.string_types) or not phone:
62+
if not isinstance(phone, str) or not phone:
6563
raise ValueError('Invalid phone number: "{0}". Phone number must be a non-empty '
6664
'string.'.format(phone))
6765
if not phone.startswith('+') or not re.search('[a-zA-Z0-9]', phone):
@@ -72,22 +70,22 @@ def validate_phone(phone, required=False):
7270
def validate_password(password, required=False):
7371
if password is None and not required:
7472
return None
75-
if not isinstance(password, six.string_types) or len(password) < 6:
73+
if not isinstance(password, str) or len(password) < 6:
7674
raise ValueError(
7775
'Invalid password string. Password must be a string at least 6 characters long.')
7876
return password
7977

8078
def validate_bytes(value, label, required=False):
8179
if value is None and not required:
8280
return None
83-
if not isinstance(value, six.binary_type) or not value:
81+
if not isinstance(value, bytes) or not value:
8482
raise ValueError('{0} must be a non-empty byte sequence.'.format(label))
8583
return value
8684

8785
def validate_display_name(display_name, required=False):
8886
if display_name is None and not required:
8987
return None
90-
if not isinstance(display_name, six.string_types) or not display_name:
88+
if not isinstance(display_name, str) or not display_name:
9189
raise ValueError(
9290
'Invalid display name: "{0}". Display name must be a non-empty '
9391
'string.'.format(display_name))
@@ -96,7 +94,7 @@ def validate_display_name(display_name, required=False):
9694
def validate_provider_id(provider_id, required=True):
9795
if provider_id is None and not required:
9896
return None
99-
if not isinstance(provider_id, six.string_types) or not provider_id:
97+
if not isinstance(provider_id, str) or not provider_id:
10098
raise ValueError(
10199
'Invalid provider ID: "{0}". Provider ID must be a non-empty '
102100
'string.'.format(provider_id))
@@ -106,12 +104,12 @@ def validate_photo_url(photo_url, required=False):
106104
"""Parses and validates the given URL string."""
107105
if photo_url is None and not required:
108106
return None
109-
if not isinstance(photo_url, six.string_types) or not photo_url:
107+
if not isinstance(photo_url, str) or not photo_url:
110108
raise ValueError(
111109
'Invalid photo URL: "{0}". Photo URL must be a non-empty '
112110
'string.'.format(photo_url))
113111
try:
114-
parsed = urllib.parse.urlparse(photo_url)
112+
parsed = parse.urlparse(photo_url)
115113
if not parsed.netloc:
116114
raise ValueError('Malformed photo URL: "{0}".'.format(photo_url))
117115
return photo_url

firebase_admin/_messaging_encoder.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import numbers
2121
import re
2222

23-
import six
24-
2523
import firebase_admin._messaging_utils as _messaging_utils
2624

2725

@@ -99,7 +97,7 @@ def check_string(cls, label, value, non_empty=False):
9997
"""Checks if the given value is a string."""
10098
if value is None:
10199
return None
102-
if not isinstance(value, six.string_types):
100+
if not isinstance(value, str):
103101
if non_empty:
104102
raise ValueError('{0} must be a non-empty string.'.format(label))
105103
raise ValueError('{0} must be a string.'.format(label))
@@ -122,10 +120,10 @@ def check_string_dict(cls, label, value):
122120
return None
123121
if not isinstance(value, dict):
124122
raise ValueError('{0} must be a dictionary.'.format(label))
125-
non_str = [k for k in value if not isinstance(k, six.string_types)]
123+
non_str = [k for k in value if not isinstance(k, str)]
126124
if non_str:
127125
raise ValueError('{0} must not contain non-string keys.'.format(label))
128-
non_str = [v for v in value.values() if not isinstance(v, six.string_types)]
126+
non_str = [v for v in value.values() if not isinstance(v, str)]
129127
if non_str:
130128
raise ValueError('{0} must not contain non-string values.'.format(label))
131129
return value
@@ -137,7 +135,7 @@ def check_string_list(cls, label, value):
137135
return None
138136
if not isinstance(value, list):
139137
raise ValueError('{0} must be a list of strings.'.format(label))
140-
non_str = [k for k in value if not isinstance(k, six.string_types)]
138+
non_str = [k for k in value if not isinstance(k, str)]
141139
if non_str:
142140
raise ValueError('{0} must not contain non-string values.'.format(label))
143141
return value
@@ -570,7 +568,7 @@ def encode_aps_sound(cls, sound):
570568
"""Encodes an APNs sound configuration into JSON."""
571569
if sound is None:
572570
return None
573-
if sound and isinstance(sound, six.string_types):
571+
if sound and isinstance(sound, str):
574572
return sound
575573
if not isinstance(sound, _messaging_utils.CriticalSound):
576574
raise ValueError(
@@ -593,7 +591,7 @@ def encode_aps_alert(cls, alert):
593591
"""Encodes an ``ApsAlert`` instance into JSON."""
594592
if alert is None:
595593
return None
596-
if isinstance(alert, six.string_types):
594+
if isinstance(alert, str):
597595
return alert
598596
if not isinstance(alert, _messaging_utils.ApsAlert):
599597
raise ValueError('Aps.alert must be a string or an instance of ApsAlert class.')

firebase_admin/_token_gen.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import cachecontrol
2121
import requests
22-
import six
2322
from google.auth import credentials
2423
from google.auth import iam
2524
from google.auth import jwt
@@ -149,7 +148,7 @@ def create_custom_token(self, uid, developer_claims=None):
149148
', '.join(disallowed_keys)))
150149
raise ValueError(error_message)
151150

152-
if not uid or not isinstance(uid, six.string_types) or len(uid) > 128:
151+
if not uid or not isinstance(uid, str) or len(uid) > 128:
153152
raise ValueError('uid must be a string between 1 and 128 characters.')
154153

155154
signing_provider = self.signing_provider
@@ -174,8 +173,8 @@ def create_custom_token(self, uid, developer_claims=None):
174173

175174
def create_session_cookie(self, id_token, expires_in):
176175
"""Creates a session cookie from the provided ID token."""
177-
id_token = id_token.decode('utf-8') if isinstance(id_token, six.binary_type) else id_token
178-
if not isinstance(id_token, six.text_type) or not id_token:
176+
id_token = id_token.decode('utf-8') if isinstance(id_token, bytes) else id_token
177+
if not isinstance(id_token, str) or not id_token:
179178
raise ValueError(
180179
'Illegal ID token provided: {0}. ID token must be a non-empty '
181180
'string.'.format(id_token))
@@ -256,8 +255,8 @@ def __init__(self, **kwargs):
256255

257256
def verify(self, token, request):
258257
"""Verifies the signature and data for the provided JWT."""
259-
token = token.encode('utf-8') if isinstance(token, six.text_type) else token
260-
if not isinstance(token, six.binary_type) or not token:
258+
token = token.encode('utf-8') if isinstance(token, str) else token
259+
if not isinstance(token, bytes) or not token:
261260
raise ValueError(
262261
'Illegal {0} provided: {1}. {0} must be a non-empty '
263262
'string.'.format(self.short_name, token))
@@ -308,7 +307,7 @@ def verify(self, token, request):
308307
'Firebase {0} has incorrect "iss" (issuer) claim. Expected "{1}" but '
309308
'got "{2}". {3} {4}'.format(self.short_name, expected_issuer, issuer,
310309
project_id_match_msg, verify_id_token_msg))
311-
elif subject is None or not isinstance(subject, six.string_types):
310+
elif subject is None or not isinstance(subject, str):
312311
error_message = (
313312
'Firebase {0} has no "sub" (subject) claim. '
314313
'{1}'.format(self.short_name, verify_id_token_msg))

firebase_admin/_user_mgt.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
import base64
1818
import json
19+
from urllib import parse
20+
1921
import requests
20-
import six
21-
from six.moves import urllib
2222

2323
from firebase_admin import _auth_utils
2424
from firebase_admin import _user_import
@@ -397,7 +397,7 @@ def encode_action_code_settings(settings):
397397
raise ValueError("Dynamic action links url is mandatory")
398398

399399
try:
400-
parsed = urllib.parse.urlparse(settings.url)
400+
parsed = parse.urlparse(settings.url)
401401
if not parsed.netloc:
402402
raise ValueError('Malformed dynamic action links url: "{0}".'.format(settings.url))
403403
parameters['continueUrl'] = settings.url
@@ -413,14 +413,14 @@ def encode_action_code_settings(settings):
413413

414414
# dynamic_link_domain
415415
if settings.dynamic_link_domain is not None:
416-
if not isinstance(settings.dynamic_link_domain, six.string_types):
416+
if not isinstance(settings.dynamic_link_domain, str):
417417
raise ValueError('Invalid value provided for dynamic_link_domain: {0}'
418418
.format(settings.dynamic_link_domain))
419419
parameters['dynamicLinkDomain'] = settings.dynamic_link_domain
420420

421421
# ios_bundle_id
422422
if settings.ios_bundle_id is not None:
423-
if not isinstance(settings.ios_bundle_id, six.string_types):
423+
if not isinstance(settings.ios_bundle_id, str):
424424
raise ValueError('Invalid value provided for ios_bundle_id: {0}'
425425
.format(settings.ios_bundle_id))
426426
parameters['iosBundleId'] = settings.ios_bundle_id
@@ -431,13 +431,13 @@ def encode_action_code_settings(settings):
431431
raise ValueError("Android package name is required when specifying other Android settings")
432432

433433
if settings.android_package_name is not None:
434-
if not isinstance(settings.android_package_name, six.string_types):
434+
if not isinstance(settings.android_package_name, str):
435435
raise ValueError('Invalid value provided for android_package_name: {0}'
436436
.format(settings.android_package_name))
437437
parameters['androidPackageName'] = settings.android_package_name
438438

439439
if settings.android_minimum_version is not None:
440-
if not isinstance(settings.android_minimum_version, six.string_types):
440+
if not isinstance(settings.android_minimum_version, str):
441441
raise ValueError('Invalid value provided for android_minimum_version: {0}'
442442
.format(settings.android_minimum_version))
443443
parameters['androidMinimumVersion'] = settings.android_minimum_version
@@ -486,7 +486,7 @@ def get_user(self, **kwargs):
486486
def list_users(self, page_token=None, max_results=MAX_LIST_USERS_RESULTS):
487487
"""Retrieves a batch of users."""
488488
if page_token is not None:
489-
if not isinstance(page_token, six.string_types) or not page_token:
489+
if not isinstance(page_token, str) or not page_token:
490490
raise ValueError('Page token must be a non-empty string.')
491491
if not isinstance(max_results, int):
492492
raise ValueError('Max results must be an integer.')

firebase_admin/_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414

1515
"""Internal utilities common to all modules."""
1616

17+
import io
1718
import json
1819
import socket
1920

2021
import googleapiclient
2122
import httplib2
2223
import requests
23-
import six
2424

2525
import firebase_admin
2626
from firebase_admin import exceptions
@@ -255,7 +255,7 @@ def handle_googleapiclient_error(error, message=None, code=None, http_response=N
255255
def _http_response_from_googleapiclient_error(error):
256256
"""Creates a requests HTTP Response object from the given googleapiclient error."""
257257
resp = requests.models.Response()
258-
resp.raw = six.BytesIO(error.content)
258+
resp.raw = io.BytesIO(error.content)
259259
resp.status_code = error.resp.status
260260
return resp
261261

firebase_admin/credentials.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"""Firebase credentials module."""
1616
import collections
1717
import json
18-
import six
1918

2019
import google.auth
2120
from google.auth.transport import requests
@@ -79,7 +78,7 @@ def __init__(self, cert):
7978
ValueError: If the specified certificate is invalid.
8079
"""
8180
super(Certificate, self).__init__()
82-
if isinstance(cert, six.string_types):
81+
if isinstance(cert, str):
8382
with open(cert) as json_file:
8483
json_data = json.load(json_file)
8584
elif isinstance(cert, dict):
@@ -180,7 +179,7 @@ def __init__(self, refresh_token):
180179
ValueError: If the refresh token configuration is invalid.
181180
"""
182181
super(RefreshToken, self).__init__()
183-
if isinstance(refresh_token, six.string_types):
182+
if isinstance(refresh_token, str):
184183
with open(refresh_token) as json_file:
185184
json_data = json.load(json_file)
186185
elif isinstance(refresh_token, dict):

0 commit comments

Comments
 (0)