Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Make onedrivesdk compatible with Python 3.11 #206

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,10 @@ implements `asyncio.ascompleted`, and execute it with
```python
import asyncio

@asyncio.coroutine
def run_gets(client):
async def run_gets(client):
coroutines = [client.drive('me').request().get_async() for i in range(3)]
for future in asyncio.as_completed(coroutines):
drive = yield from future
drive = await future
print(drive.id)

loop = asyncio.get_event_loop()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
from ..async_operation_monitor import AsyncOperationMonitor


@asyncio.coroutine
def poll_until_done_async(self):
async def poll_until_done_async(self):
"""Yielding this method blocks until done polling for
the result of the async operation is returned

Expand All @@ -35,7 +34,7 @@ def poll_until_done_async(self):
"""
future = self._client._loop.run_in_executor(None,
self.poll_until_done)
item = yield from future
item = await future
return item

AsyncOperationMonitor.poll_until_done_async = poll_until_done_async
15 changes: 6 additions & 9 deletions src/onedrivesdk/version_bridge/auth_provider_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
from ..auth_provider import AuthProvider


@asyncio.coroutine
def authenticate_async(self, code, redirect_uri, client_secret=None):
async def authenticate_async(self, code, redirect_uri, client_secret=None):
"""Takes in a code string, gets the access token,
and creates session property bag in async

Expand All @@ -43,11 +42,10 @@ def authenticate_async(self, code, redirect_uri, client_secret=None):
code,
redirect_uri,
client_secret)
yield from future
await future


@asyncio.coroutine
def authenticate_request_async(self, request):
async def authenticate_request_async(self, request):
"""Authenticate and append the required
headers to the request in async

Expand All @@ -58,15 +56,14 @@ def authenticate_request_async(self, request):
future = self._loop.run_in_executor(None,
self.authenticate_request,
request)
yield from future
await future


@asyncio.coroutine
def refresh_token_async(self):
async def refresh_token_async(self):
"""Refresh the token currently used by the session"""
future = self._loop.run_in_executor(None,
self.refresh_token)
yield from future
await future

AuthProvider.authenticate_async = authenticate_async
AuthProvider.authenticate_request_async = authenticate_async
Expand Down
10 changes: 4 additions & 6 deletions src/onedrivesdk/version_bridge/fragment_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ def post(self):
entity = UploadSession(json.loads(self.send(data=self._file_handle).content))
return entity

@asyncio.coroutine
def post_async(self):
async def post_async(self):
"""Sends the POST request using an asyncio coroutine

Yields:
Expand All @@ -67,7 +66,7 @@ def post_async(self):
"""
future = self._client._loop.run_in_executor(None,
self.post)
entity = yield from future
entity = await future
return entity


Expand Down Expand Up @@ -120,15 +119,14 @@ def post(self, begin, length, options=None):
"""
return self.request(begin, length, options).post()

@asyncio.coroutine
def post_async(self, begin, length, options=None):
async def post_async(self, begin, length, options=None):
"""Sends the POST request using an asyncio coroutine

Yields:
:class:`UploadedFragment<onedrivesdk.model.uploaded_fragment.UploadedFragment>`:
The resulting UploadSession from the operation
"""
entity = yield from self.request(begin, length, options).post_async()
entity = await self.request(begin, length, options).post_async()
return entity


Expand Down
20 changes: 8 additions & 12 deletions src/python3/request/children_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ def add(self, entity):
entity = Item(json.loads(self.send(entity).content))
return entity

@asyncio.coroutine
def add_async(self, entity):
async def add_async(self, entity):
"""Add a Item to the collection in async

Args:
Expand All @@ -59,7 +58,7 @@ def add_async(self, entity):
future = self._client._loop.run_in_executor(None,
self.add,
entity)
entity = yield from future
entity = await future
return entity

def get(self):
Expand All @@ -73,8 +72,7 @@ def get(self):
collection_response = ChildrenCollectionResponse(json.loads(self.send().content))
return self._page_from_response(collection_response)

@asyncio.coroutine
def get_async(self):
async def get_async(self):
"""Gets the ChildrenCollectionPage in async

Yields:
Expand All @@ -83,7 +81,7 @@ def get_async(self):
"""
future = self._client._loop.run_in_executor(None,
self.get)
collection_page = yield from future
collection_page = await future
return collection_page

@staticmethod
Expand Down Expand Up @@ -156,8 +154,7 @@ def add(self, entity):
"""
return self.request().add(entity)

@asyncio.coroutine
def add_async(self, entity):
async def add_async(self, entity):
"""Add a Item to the collection in async

Args:
Expand All @@ -168,7 +165,7 @@ def add_async(self, entity):
:class:`Item<onedrivesdk.model.item.Item>`:
The Item that you added, with additional data from OneDrive
"""
entity = yield from self.request().add_async(entity)
entity = await self.request().add_async(entity)
return entity

def get(self):
Expand All @@ -180,15 +177,14 @@ def get(self):
"""
return self.request().get()

@asyncio.coroutine
def get_async(self):
async def get_async(self):
"""Gets the ChildrenCollectionPage in async

Yields:
:class:`ChildrenCollectionPage<onedrivesdk.model.children_collection_page.ChildrenCollectionPage>`:
The ChildrenCollectionPage
"""
collection_page = yield from self.request().get_async()
collection_page = await self.request().get_async()
return collection_page


Expand Down
10 changes: 4 additions & 6 deletions src/python3/request/drive_recent.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ def get(self):
collection_response = ItemsCollectionResponse(json.loads(self.send().content))
return self._page_from_response(collection_response)

@asyncio.coroutine
def get_async(self):
async def get_async(self):
"""Sends the GET request using an asyncio coroutine

Yields:
Expand All @@ -39,7 +38,7 @@ def get_async(self):
"""
future = self._client._loop.run_in_executor(None,
self.get)
collection_response = yield from future
collection_response = await future
return collection_response

@staticmethod
Expand Down Expand Up @@ -92,15 +91,14 @@ def get(self):
"""
return self.request().get()

@asyncio.coroutine
def get_async(self):
async def get_async(self):
"""Sends the GET request using an asyncio coroutine

Yields:
:class:`ItemsCollectionResponse<onedrivesdk.request.items_collection.ItemsCollectionResponse>`:
The resulting ItemsCollectionResponse from the operation
"""
collection_page = yield from self.request().get_async()
collection_page = await self.request().get_async()
return collection_page

from ..request.items_collection import ItemsCollectionResponse
15 changes: 6 additions & 9 deletions src/python3/request/drive_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ def delete(self):
self.method = "DELETE"
self.send()

@asyncio.coroutine
def delete_async(self):
async def delete_async(self):
"""Deletes the specified Drive."""
future = self._client._loop.run_in_executor(None,
self.delete)
yield from future
await future

def get(self):
"""Gets the specified Drive.
Expand All @@ -50,8 +49,7 @@ def get(self):
self._initialize_collection_properties(entity)
return entity

@asyncio.coroutine
def get_async(self):
async def get_async(self):
"""Gets the specified Drive in async.

Yields:
Expand All @@ -60,7 +58,7 @@ def get_async(self):
"""
future = self._client._loop.run_in_executor(None,
self.get)
entity = yield from future
entity = await future
return entity

def update(self, drive):
Expand All @@ -80,8 +78,7 @@ def update(self, drive):
self._initialize_collection_properties(entity)
return entity

@asyncio.coroutine
def update_async(self, drive):
async def update_async(self, drive):
"""Updates the specified Drive in async

Args:
Expand All @@ -95,7 +92,7 @@ def update_async(self, drive):
future = self._client._loop.run_in_executor(None,
self.update,
drive)
entity = yield from future
entity = await future
return entity

def _initialize_collection_properties(self, value):
Expand Down
15 changes: 6 additions & 9 deletions src/python3/request/drive_request_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,9 @@ def delete(self):
"""Deletes the specified Drive."""
self.request().delete()

@asyncio.coroutine
def delete_async(self):
async def delete_async(self):
"""Deletes the specified Drive."""
yield from self.request().delete_async()
await self.request().delete_async()
def get(self):
"""Gets the specified Drive.

Expand All @@ -61,15 +60,14 @@ def get(self):
"""
return self.request().get()

@asyncio.coroutine
def get_async(self):
async def get_async(self):
"""Gets the specified Drive in async.

Returns:
:class:`Drive<onedrivesdk.model.drive.Drive>`:
The Drive.
"""
entity = yield from self.request().get_async()
entity = await self.request().get_async()
return entity
def update(self, drive):
"""Updates the specified Drive.
Expand All @@ -84,8 +82,7 @@ def update(self, drive):
"""
return self.request().update(drive)

@asyncio.coroutine
def update_async(self, drive):
async def update_async(self, drive):
"""Updates the specified Drive in async

Args:
Expand All @@ -96,7 +93,7 @@ def update_async(self, drive):
:class:`Drive<onedrivesdk.model.drive.Drive>`:
The updated Drive.
"""
entity = yield from self.request().update_async(drive)
entity = await self.request().update_async(drive)
return entity

@property
Expand Down
10 changes: 4 additions & 6 deletions src/python3/request/drives_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ def get(self):
collection_response = DrivesCollectionResponse(json.loads(self.send().content))
return self._page_from_response(collection_response)

@asyncio.coroutine
def get_async(self):
async def get_async(self):
"""Gets the DrivesCollectionPage in async

Yields:
Expand All @@ -48,7 +47,7 @@ def get_async(self):
"""
future = self._client._loop.run_in_executor(None,
self.get)
collection_page = yield from future
collection_page = await future
return collection_page

@staticmethod
Expand Down Expand Up @@ -117,15 +116,14 @@ def get(self):
"""
return self.request().get()

@asyncio.coroutine
def get_async(self):
async def get_async(self):
"""Gets the DrivesCollectionPage in async

Yields:
:class:`DrivesCollectionPage<onedrivesdk.model.drives_collection_page.DrivesCollectionPage>`:
The DrivesCollectionPage
"""
collection_page = yield from self.request().get_async()
collection_page = await self.request().get_async()
return collection_page


Expand Down
Loading