Skip to content

Commit

Permalink
refactor: major code restructuring to make it compliant with black
Browse files Browse the repository at this point in the history
Also removed many unused statements.
  • Loading branch information
joamag committed Apr 23, 2024
1 parent 7dbde4d commit 3b333ee
Show file tree
Hide file tree
Showing 13 changed files with 239 additions and 298 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ jobs:
runs-on: ubuntu-latest
container: python:${{ matrix.python-version }}
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- run: python --version
- run: pip install -r requirements.txt
- run: |
pip install black
black . --check
if: matrix.python-version == '3.12'
- run: python setup.py test
- run: pip install twine wheel
- run: python setup.py sdist bdist_wheel
Expand Down
36 changes: 34 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,43 @@ jobs:
name: Build
strategy:
matrix:
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, rc]
python-version: [
2.7,
3.5,
3.6,
3.7,
3.8,
3.9,
"3.10",
"3.11",
"3.12",
latest,
rc
]
runs-on: ubuntu-latest
container: python:${{ matrix.python-version }}
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
- run: python --version
- run: pip install -r requirements.txt
- run: |
pip install black
black . --check
if: matrix.python-version == '3.12'
- run: python setup.py test
build-pypy:
name: Build PyPy
strategy:
matrix:
python-version: [2.7, 3.6, 3.9, "3.10"]
runs-on: ubuntu-latest
container: pypy:${{ matrix.python-version }}
steps:
- uses: actions/checkout@v4
- run: pypy --version
- run: pip install -r requirements.txt
- run: |
pip install black
black . --check
if: matrix.python-version == '3.12'
- run: pypy setup.py test
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

session.shelve*

.DS_Store

/.vscode/settings.json

/.env
/.venv

/dist
/build
/src/dropbox_api.egg-info
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

*
* Major code restructuring to make it compliant with `black`

### Fixed

Expand Down
53 changes: 20 additions & 33 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

# Hive Dropbox API
# Copyright (c) 2008-2020 Hive Solutions Lda.
# Copyright (c) 2008-2024 Hive Solutions Lda.
#
# This file is part of Hive Dropbox API.
#
Expand All @@ -22,16 +22,7 @@
__author__ = "João Magalhães <joamag@hive.pt>"
""" The author(s) of the module """

__version__ = "1.0.0"
""" The version of the module """

__revision__ = "$LastChangedRevision$"
""" The revision number of the module """

__date__ = "$LastChangedDate$"
""" The last change date of the module """

__copyright__ = "Copyright (c) 2008-2020 Hive Solutions Lda."
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
""" The copyright for the module """

__license__ = "Apache License, Version 2.0"
Expand All @@ -41,25 +32,19 @@
import setuptools

setuptools.setup(
name = "dropbox-api",
version = "0.2.4",
author = "Hive Solutions Lda.",
author_email = "development@hive.pt",
description = "Dropbox API Client",
license = "Apache License, Version 2.0",
keywords = "dropbox api",
url = "http://dropbox-api.hive.pt",
zip_safe = False,
packages = [
"dropbox"
],
package_dir = {
"" : os.path.normpath("src")
},
install_requires = [
"appier"
],
classifiers = [
name="dropbox-api",
version="0.2.4",
author="Hive Solutions Lda.",
author_email="development@hive.pt",
description="Dropbox API Client",
license="Apache License, Version 2.0",
keywords="dropbox api",
url="http://dropbox-api.hive.pt",
zip_safe=False,
packages=["dropbox"],
package_dir={"": os.path.normpath("src")},
install_requires=["appier"],
classifiers=[
"Development Status :: 3 - Alpha",
"Topic :: Utilities",
"License :: OSI Approved :: Apache Software License",
Expand All @@ -74,8 +59,10 @@
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7"
"Programming Language :: Python :: 3.7",
],
long_description = open(os.path.join(os.path.dirname(__file__), "README.md"), "rb").read().decode("utf-8"),
long_description_content_type = "text/markdown"
long_description=open(os.path.join(os.path.dirname(__file__), "README.md"), "rb")
.read()
.decode("utf-8"),
long_description_content_type="text/markdown",
)
13 changes: 2 additions & 11 deletions src/dropbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

# Hive Dropbox API
# Copyright (c) 2008-2020 Hive Solutions Lda.
# Copyright (c) 2008-2024 Hive Solutions Lda.
#
# This file is part of Hive Dropbox API.
#
Expand All @@ -19,16 +19,7 @@
# You should have received a copy of the Apache License along with
# Hive Dropbox API. If not, see <http://www.apache.org/licenses/>.

__version__ = "1.0.0"
""" The version of the module """

__revision__ = "$LastChangedRevision$"
""" The revision number of the module """

__date__ = "$LastChangedDate$"
""" The last change date of the module """

__copyright__ = "Copyright (c) 2008-2020 Hive Solutions Lda."
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
""" The copyright for the module """

__license__ = "Apache License, Version 2.0"
Expand Down
98 changes: 45 additions & 53 deletions src/dropbox/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

# Hive Dropbox API
# Copyright (c) 2008-2020 Hive Solutions Lda.
# Copyright (c) 2008-2024 Hive Solutions Lda.
#
# This file is part of Hive Dropbox API.
#
Expand All @@ -22,16 +22,7 @@
__author__ = "João Magalhães <joamag@hive.pt>"
""" The author(s) of the module """

__version__ = "1.0.0"
""" The version of the module """

__revision__ = "$LastChangedRevision$"
""" The revision number of the module """

__date__ = "$LastChangedDate$"
""" The last change date of the module """

__copyright__ = "Copyright (c) 2008-2020 Hive Solutions Lda."
__copyright__ = "Copyright (c) 2008-2024 Hive Solutions Lda."
""" The copyright for the module """

__license__ = "Apache License, Version 2.0"
Expand Down Expand Up @@ -83,12 +74,8 @@
""" The default refresh token to be applied to the
client when no other is provided """

class API(
appier.OAuth2API,
file.FileAPI,
user.UserAPI,
shared_link.SharedLinkAPI
):

class API(appier.OAuth2API, file.FileAPI, user.UserAPI, shared_link.SharedLinkAPI):

def __init__(self, *args, **kwargs):
appier.OAuth2API.__init__(self, *args, **kwargs)
Expand All @@ -113,46 +100,51 @@ def build(
self,
method,
url,
data = None,
data_j = None,
data_m = None,
headers = None,
params = None,
mime = None,
kwargs = None
data=None,
data_j=None,
data_m=None,
headers=None,
params=None,
mime=None,
kwargs=None,
):
appier.OAuth2API.build(
self,
method,
url,
data = data,
data_j = data_j,
data_m = data_m,
headers = headers,
params = params,
mime = mime,
kwargs = kwargs
data=data,
data_j=data_j,
data_m=data_m,
headers=headers,
params=params,
mime=mime,
kwargs=kwargs,
)
if not self.is_oauth(): return
if not self.is_oauth():
return
kwargs.pop("access_token", True)

def auth_callback(self, params, headers):
if not self.refresh_token: return
if not self.refresh_token:
return
self.oauth_refresh()
params["access_token"] = self.get_access_token()
headers["Authorization"] = "Bearer %s" % self.get_access_token()

def oauth_authorize(self, state = None, token_access_type = "offline", prompt = True):
def oauth_authorize(self, state=None, token_access_type="offline", prompt=True):
url = self.web_url + "oauth2/authorize"
values = dict(
client_id = self.client_id,
redirect_uri = self.redirect_url,
response_type = "code",
scope = " ".join(self.scope)
client_id=self.client_id,
redirect_uri=self.redirect_url,
response_type="code",
scope=" ".join(self.scope),
)
if state: values["state"] = state
if token_access_type: values["token_access_type"] = token_access_type
if not prompt: values["prompt"] = "none"
if state:
values["state"] = state
if token_access_type:
values["token_access_type"] = token_access_type
if not prompt:
values["prompt"] = "none"
data = appier.legacy.urlencode(values)
url = url + "?" + data
return url
Expand All @@ -161,12 +153,12 @@ def oauth_access(self, code):
url = self.api_url + "oauth2/token"
contents = self.post(
url,
token = False,
client_id = self.client_id,
client_secret = self.client_secret,
grant_type = "authorization_code",
redirect_uri = self.redirect_url,
code = code
token=False,
client_id=self.client_id,
client_secret=self.client_secret,
grant_type="authorization_code",
redirect_uri=self.redirect_url,
code=code,
)
self.access_token = contents["access_token"]
self.refresh_token = contents.get("refresh_token", None)
Expand All @@ -178,12 +170,12 @@ def oauth_refresh(self):
url = self.api_url + "oauth2/token"
contents = self.post(
url,
callback = False,
token = False,
client_id = self.client_id,
client_secret = self.client_secret,
grant_type = "refresh_token",
refresh_token = self.refresh_token
callback=False,
token=False,
client_id=self.client_id,
client_secret=self.client_secret,
grant_type="refresh_token",
refresh_token=self.refresh_token,
)
self.access_token = contents["access_token"]
self.trigger("access_token", self.access_token)
Expand Down
Loading

0 comments on commit 3b333ee

Please sign in to comment.