Skip to content

Upgraded to pylint 2.x #384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ python:
jobs:
include:
- name: "Lint"
python: "2.7"
python: "3.7"
script: ./lint.sh all

before_install:
Expand Down
36 changes: 18 additions & 18 deletions firebase_admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ def initialize_app(credential=None, options=None, name=_DEFAULT_APP_NAME):
'initialize_app() once. But if you do want to initialize multiple '
'apps, pass a second argument to initialize_app() to give each app '
'a unique name.'))
else:
raise ValueError((
'Firebase app named "{0}" already exists. This means you called '
'initialize_app() more than once with the same app name as the '
'second argument. Make sure you provide a unique name every time '
'you call initialize_app().').format(name))

raise ValueError((
'Firebase app named "{0}" already exists. This means you called '
'initialize_app() more than once with the same app name as the '
'second argument. Make sure you provide a unique name every time '
'you call initialize_app().').format(name))


def delete_app(app):
Expand All @@ -106,11 +106,11 @@ def delete_app(app):
raise ValueError(
'The default Firebase app is not initialized. Make sure to initialize '
'the default app by calling initialize_app().')
else:
raise ValueError(
('Firebase app named "{0}" is not initialized. Make sure to initialize '
'the app by calling initialize_app() with your app name as the '
'second argument.').format(app.name))

raise ValueError(
('Firebase app named "{0}" is not initialized. Make sure to initialize '
'the app by calling initialize_app() with your app name as the '
'second argument.').format(app.name))


def get_app(name=_DEFAULT_APP_NAME):
Expand All @@ -137,14 +137,14 @@ def get_app(name=_DEFAULT_APP_NAME):
raise ValueError(
'The default Firebase app does not exist. Make sure to initialize '
'the SDK by calling initialize_app().')
else:
raise ValueError(
('Firebase app named "{0}" does not exist. Make sure to initialize '
'the SDK by calling initialize_app() with your app name as the '
'second argument.').format(name))

raise ValueError(
('Firebase app named "{0}" does not exist. Make sure to initialize '
'the SDK by calling initialize_app() with your app name as the '
'second argument.').format(name))


class _AppOptions(object):
class _AppOptions:
"""A collection of configuration options for an App."""

def __init__(self, options):
Expand Down Expand Up @@ -185,7 +185,7 @@ def _load_from_environment(self):
return {k: v for k, v in json_data.items() if k in _CONFIG_VALID_KEYS}


class App(object):
class App:
"""The entry point for Firebase Python SDK.

Represents a Firebase app, while holding the configuration and state
Expand Down
4 changes: 3 additions & 1 deletion firebase_admin/_auth_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def validate_provider_id(provider_id, required=True):
return provider_id

def validate_photo_url(photo_url, required=False):
"""Parses and validates the given URL string."""
if photo_url is None and not required:
return None
if not isinstance(photo_url, six.string_types) or not photo_url:
Expand All @@ -118,6 +119,7 @@ def validate_photo_url(photo_url, required=False):
raise ValueError('Malformed photo URL: "{0}".'.format(photo_url))

def validate_timestamp(timestamp, label, required=False):
"""Validates the given timestamp value. Timestamps must be positive integers."""
if timestamp is None and not required:
return None
if isinstance(timestamp, bool):
Expand Down Expand Up @@ -181,7 +183,7 @@ def validate_custom_claims(custom_claims, required=False):
if len(invalid_claims) > 1:
joined = ', '.join(sorted(invalid_claims))
raise ValueError('Claims "{0}" are reserved, and must not be set.'.format(joined))
elif len(invalid_claims) == 1:
if len(invalid_claims) == 1:
raise ValueError(
'Claim "{0}" is reserved, and must not be set.'.format(invalid_claims.pop()))
return claims_str
Expand Down
2 changes: 1 addition & 1 deletion firebase_admin/_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
raise_on_status=False, backoff_factor=0.5)


class HttpClient(object):
class HttpClient:
"""Base HTTP client used to make HTTP calls.

HttpClient maintains an HTTP session, and handles request authentication and retries if
Expand Down
34 changes: 17 additions & 17 deletions firebase_admin/_messaging_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import firebase_admin._messaging_utils as _messaging_utils


class Message(object):
class Message:
"""A message that can be sent via Firebase Cloud Messaging.

Contains payload information as well as recipient information. In particular, the message must
Expand Down Expand Up @@ -61,7 +61,7 @@ def __str__(self):
return json.dumps(self, cls=MessageEncoder, sort_keys=True)


class MulticastMessage(object):
class MulticastMessage:
"""A message that can be sent to multiple tokens via Firebase Cloud Messaging.

Args:
Expand All @@ -88,7 +88,7 @@ def __init__(self, tokens, data=None, notification=None, android=None, webpush=N
self.fcm_options = fcm_options


class _Validators(object):
class _Validators:
"""A collection of data validation utilities.

Methods provided in this class raise ``ValueErrors`` if any validations fail.
Expand All @@ -102,8 +102,7 @@ def check_string(cls, label, value, non_empty=False):
if not isinstance(value, six.string_types):
if non_empty:
raise ValueError('{0} must be a non-empty string.'.format(label))
else:
raise ValueError('{0} must be a string.'.format(label))
raise ValueError('{0} must be a string.'.format(label))
if non_empty and not value:
raise ValueError('{0} must be a non-empty string.'.format(label))
return value
Expand Down Expand Up @@ -647,6 +646,7 @@ def encode_notification(cls, notification):

@classmethod
def sanitize_topic_name(cls, topic):
"""Removes the /topics/ prefix from the topic name, if present."""
if not topic:
return None
prefix = '/topics/'
Expand All @@ -657,20 +657,20 @@ def sanitize_topic_name(cls, topic):
raise ValueError('Malformed topic name.')
return topic

def default(self, obj): # pylint: disable=method-hidden
if not isinstance(obj, Message):
return json.JSONEncoder.default(self, obj)
def default(self, o): # pylint: disable=method-hidden
if not isinstance(o, Message):
return json.JSONEncoder.default(self, o)
result = {
'android': MessageEncoder.encode_android(obj.android),
'apns': MessageEncoder.encode_apns(obj.apns),
'android': MessageEncoder.encode_android(o.android),
'apns': MessageEncoder.encode_apns(o.apns),
'condition': _Validators.check_string(
'Message.condition', obj.condition, non_empty=True),
'data': _Validators.check_string_dict('Message.data', obj.data),
'notification': MessageEncoder.encode_notification(obj.notification),
'token': _Validators.check_string('Message.token', obj.token, non_empty=True),
'topic': _Validators.check_string('Message.topic', obj.topic, non_empty=True),
'webpush': MessageEncoder.encode_webpush(obj.webpush),
'fcm_options': MessageEncoder.encode_fcm_options(obj.fcm_options),
'Message.condition', o.condition, non_empty=True),
'data': _Validators.check_string_dict('Message.data', o.data),
'notification': MessageEncoder.encode_notification(o.notification),
'token': _Validators.check_string('Message.token', o.token, non_empty=True),
'topic': _Validators.check_string('Message.topic', o.topic, non_empty=True),
'webpush': MessageEncoder.encode_webpush(o.webpush),
'fcm_options': MessageEncoder.encode_fcm_options(o.fcm_options),
}
result['topic'] = MessageEncoder.sanitize_topic_name(result.get('topic'))
result = MessageEncoder.remove_null_values(result)
Expand Down
32 changes: 16 additions & 16 deletions firebase_admin/_messaging_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from firebase_admin import exceptions


class Notification(object):
class Notification:
"""A notification that can be included in a message.

Args:
Expand All @@ -32,7 +32,7 @@ def __init__(self, title=None, body=None, image=None):
self.image = image


class AndroidConfig(object):
class AndroidConfig:
"""Android-specific options that can be included in a message.

Args:
Expand Down Expand Up @@ -62,7 +62,7 @@ def __init__(self, collapse_key=None, priority=None, ttl=None, restricted_packag
self.fcm_options = fcm_options


class AndroidNotification(object):
class AndroidNotification:
"""Android-specific notification parameters.

Args:
Expand Down Expand Up @@ -178,7 +178,7 @@ def __init__(self, title=None, body=None, icon=None, color=None, sound=None, tag
self.notification_count = notification_count


class LightSettings(object):
class LightSettings:
"""Represents settings to control notification LED that can be included in a
``messaging.AndroidNotification``.

Expand All @@ -196,7 +196,7 @@ def __init__(self, color, light_on_duration_millis,
self.light_off_duration_millis = light_off_duration_millis


class AndroidFCMOptions(object):
class AndroidFCMOptions:
"""Options for features provided by the FCM SDK for Android.

Args:
Expand All @@ -208,7 +208,7 @@ def __init__(self, analytics_label=None):
self.analytics_label = analytics_label


class WebpushConfig(object):
class WebpushConfig:
"""Webpush-specific options that can be included in a message.

Args:
Expand All @@ -230,7 +230,7 @@ def __init__(self, headers=None, data=None, notification=None, fcm_options=None)
self.fcm_options = fcm_options


class WebpushNotificationAction(object):
class WebpushNotificationAction:
"""An action available to the users when the notification is presented.

Args:
Expand All @@ -245,7 +245,7 @@ def __init__(self, action, title, icon=None):
self.icon = icon


class WebpushNotification(object):
class WebpushNotification:
"""Webpush-specific notification parameters.

Refer to the `Notification Reference`_ for more information.
Expand Down Expand Up @@ -302,7 +302,7 @@ def __init__(self, title=None, body=None, icon=None, actions=None, badge=None, d
self.custom_data = custom_data


class WebpushFCMOptions(object):
class WebpushFCMOptions:
"""Options for features provided by the FCM SDK for Web.

Args:
Expand All @@ -314,7 +314,7 @@ def __init__(self, link=None):
self.link = link


class APNSConfig(object):
class APNSConfig:
"""APNS-specific options that can be included in a message.

Refer to `APNS Documentation`_ for more information.
Expand All @@ -335,7 +335,7 @@ def __init__(self, headers=None, payload=None, fcm_options=None):
self.fcm_options = fcm_options


class APNSPayload(object):
class APNSPayload:
"""Payload of an APNS message.

Args:
Expand All @@ -349,7 +349,7 @@ def __init__(self, aps, **kwargs):
self.custom_data = kwargs


class Aps(object):
class Aps:
"""Aps dictionary to be included in an APNS payload.

Args:
Expand Down Expand Up @@ -379,7 +379,7 @@ def __init__(self, alert=None, badge=None, sound=None, content_available=None, c
self.custom_data = custom_data


class CriticalSound(object):
class CriticalSound:
"""Critical alert sound configuration that can be included in ``messaging.Aps``.

Args:
Expand All @@ -398,7 +398,7 @@ def __init__(self, name, critical=None, volume=None):
self.volume = volume


class ApsAlert(object):
class ApsAlert:
"""An alert that can be included in ``messaging.Aps``.

Args:
Expand Down Expand Up @@ -437,7 +437,7 @@ def __init__(self, title=None, subtitle=None, body=None, loc_key=None, loc_args=
self.custom_data = custom_data


class APNSFCMOptions(object):
class APNSFCMOptions:
"""Options for features provided by the FCM SDK for iOS.

Args:
Expand All @@ -452,7 +452,7 @@ def __init__(self, analytics_label=None, image=None):
self.image = image


class FCMOptions(object):
class FCMOptions:
"""Options for features provided by SDK.

Args:
Expand Down
10 changes: 5 additions & 5 deletions firebase_admin/_sseclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def rebuild_auth(self, prepared_request, response):
pass


class _EventBuffer(object):
class _EventBuffer:
"""A helper class for buffering and parsing raw SSE data."""

def __init__(self):
Expand Down Expand Up @@ -68,7 +68,7 @@ def buffer_string(self):
return ''.join(self._buffer)


class SSEClient(object):
class SSEClient:
"""SSE client implementation."""

def __init__(self, url, session, retry=3000, **kwargs):
Expand Down Expand Up @@ -140,7 +140,7 @@ def __next__(self):
if event.data == 'credential is no longer valid':
self._connect()
return None
elif event.data == 'null':
if event.data == 'null':
return None

# If the server requests a specific retry delay, we need to honor it.
Expand All @@ -157,7 +157,7 @@ def next(self):
return self.__next__()


class Event(object):
class Event:
"""Event represents the events fired by SSE."""

sse_line_pattern = re.compile('(?P<name>[^:]*):?( ?(?P<value>.*))?')
Expand Down Expand Up @@ -192,7 +192,7 @@ def parse(cls, raw):
if name == '':
# line began with a ":", so is a comment. Ignore
continue
elif name == 'data':
if name == 'data':
# If we already have some data, then join to it with a newline.
# Else this is it.
if event.data:
Expand Down
Loading