Skip to content

Commit

Permalink
Format with black
Browse files Browse the repository at this point in the history
  • Loading branch information
aaront committed Mar 16, 2021
1 parent 27879f5 commit b6d07a7
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 32 deletions.
33 changes: 23 additions & 10 deletions mygeotab/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@


class API(object):
"""A simple and Pythonic wrapper for the MyGeotab API.
"""
"""A simple and Pythonic wrapper for the MyGeotab API."""

def __init__(
self, username, password=None, database=None, session_id=None, server="my.geotab.com", timeout=DEFAULT_TIMEOUT, proxies=None
self,
username,
password=None,
database=None,
session_id=None,
server="my.geotab.com",
timeout=DEFAULT_TIMEOUT,
proxies=None,
):
"""Initialize the MyGeotab API object with credentials.
Expand Down Expand Up @@ -98,7 +104,9 @@ def call(self, method, **parameters):
params["credentials"] = self.credentials.get_param()

try:
result = _query(self._server, method, params, self.timeout, verify_ssl=self._is_verify_ssl, proxies=self._proxies)
result = _query(
self._server, method, params, self.timeout, verify_ssl=self._is_verify_ssl, proxies=self._proxies
)
if result is not None:
self.__reauthorize_count = 0
return result
Expand Down Expand Up @@ -204,7 +212,14 @@ def authenticate(self):
auth_data = dict(credentials=dict(auth_data, **{"sessionId": self.credentials.session_id}))

try:
result = _query(self._server, "Authenticate", auth_data, self.timeout, verify_ssl=self._is_verify_ssl, proxies=self._proxies)
result = _query(
self._server,
"Authenticate",
auth_data,
self.timeout,
verify_ssl=self._is_verify_ssl,
proxies=self._proxies,
)
if result:
if "path" not in result and self.credentials.session_id:
# Session was extended
Expand Down Expand Up @@ -244,8 +259,7 @@ def from_credentials(credentials):


class Credentials(object):
"""The MyGeotab Credentials object.
"""
"""The MyGeotab Credentials object."""

def __init__(self, username, session_id, database, server, password=None):
"""Initialize the Credentials object.
Expand Down Expand Up @@ -285,8 +299,7 @@ def get_param(self):


class GeotabHTTPAdapter(HTTPAdapter):
"""HTTP adapter to force use of TLS 1.2 for HTTPS connections.
"""
"""HTTP adapter to force use of TLS 1.2 for HTTPS connections."""

def init_poolmanager(self, connections, maxsize, block=False, **pool_kwargs):
self.poolmanager = urllib3.poolmanager.PoolManager(
Expand Down Expand Up @@ -327,7 +340,7 @@ def _query(server, method, parameters, timeout=DEFAULT_TIMEOUT, verify_ssl=True,
allow_redirects=True,
timeout=timeout,
verify=verify_ssl,
proxies=proxies
proxies=proxies,
)
except Timeout:
raise TimeoutException(server)
Expand Down
6 changes: 2 additions & 4 deletions mygeotab/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@


class Session(object):
"""The console session object.
"""
"""The console session object."""

def __init__(self):
"""Initialize the console session object.
"""
"""Initialize the console session object."""
self.credentials = None

@staticmethod
Expand Down
15 changes: 5 additions & 10 deletions mygeotab/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@


class MyGeotabException(IOError):
"""There was an exception while handling your call.
"""
"""There was an exception while handling your call."""

def __init__(self, full_error, *args, **kwargs):
"""Initialize MyGeotabException with the full error from the server.
Expand All @@ -33,8 +32,7 @@ def __str__(self):


class AuthenticationException(IOError):
"""Unsuccessful authentication with the server.
"""
"""Unsuccessful authentication with the server."""

def __init__(self, username, database, server, *args, **kwargs):
"""Initialize AuthenticationException with username, database, and server.
Expand All @@ -53,14 +51,12 @@ def __str__(self):

@property
def message(self):
"""The exception message.
"""
"""The exception message."""
return "Cannot authenticate '{0} @ {1}/{2}'".format(self.username, self.server, self.database)


class TimeoutException(IOError):
"""The request timed out while handling your request.
"""
"""The request timed out while handling your request."""

def __init__(self, server, *args, **kwargs):
"""Initialize TimeoutException with the server name.
Expand All @@ -75,6 +71,5 @@ def __str__(self):

@property
def message(self):
"""The excepton message.
"""
"""The excepton message."""
return "Request timed out @ {0}".format(self.server)
6 changes: 2 additions & 4 deletions mygeotab/ext/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@


class DataFeedListener(object):
"""The abstract DataFeedListener to override
"""
"""The abstract DataFeedListener to override"""

__metaclass__ = abc.ABCMeta

Expand Down Expand Up @@ -66,8 +65,7 @@ def __init__(self, client_api, listener, type_name, interval, search=None, resul
self._thread = None

def _run(self):
"""Runner for the Data Feed.
"""
"""Runner for the Data Feed."""
while self.running:
try:
result = self.client_api.call(
Expand Down
13 changes: 9 additions & 4 deletions mygeotab/py3/api_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"""

import asyncio
from copy import Error
import sys

if sys.version_info < (3, 5):
Expand All @@ -25,11 +24,17 @@


class API(api.API):
"""A simple, asynchronous, and Pythonic wrapper for the MyGeotab API.
"""
"""A simple, asynchronous, and Pythonic wrapper for the MyGeotab API."""

def __init__(
self, username, password=None, database=None, session_id=None, server="my.geotab.com", timeout=DEFAULT_TIMEOUT, proxies=None
self,
username,
password=None,
database=None,
session_id=None,
server="my.geotab.com",
timeout=DEFAULT_TIMEOUT,
proxies=None,
):
"""
Initialize the asynchronous MyGeotab API object with credentials.
Expand Down

0 comments on commit b6d07a7

Please sign in to comment.