Skip to content

Commit

Permalink
fix: Fix broken example in Python 3.10 (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgmacias95 authored Sep 22, 2022
1 parent 937cd32 commit c3282d2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
14 changes: 6 additions & 8 deletions examples/download_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def download_files(queue, args):
queue.task_done()


def main():
async def main():

parser = argparse.ArgumentParser(
description=program_description)
Expand Down Expand Up @@ -77,21 +77,19 @@ def main():
else:
input_file = sys.stdin

loop = asyncio.get_event_loop()
queue = asyncio.Queue(loop=loop)
loop.create_task(read_hashes(queue, input_file))
queue = asyncio.Queue()
asyncio.create_task(read_hashes(queue, input_file))

worker_tasks = []
for _ in range(args.workers):
worker_tasks.append(
loop.create_task(download_files(queue, args)))
asyncio.create_task(download_files(queue, args)))

# Wait until all worker tasks has completed.
loop.run_until_complete(asyncio.gather(*worker_tasks))
loop.close()
await asyncio.gather(*worker_tasks)
if input_file != sys.stdin:
input_file.close()


if __name__ == '__main__':
main()
asyncio.run(main())
11 changes: 10 additions & 1 deletion vt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ def _get_session(self):
headers = {
'X-Apikey': self._apikey,
'Accept-Encoding': 'gzip',
'Content-Type': 'application/json',
'User-Agent': _USER_AGENT_FMT.format_map({
'agent': self._agent, 'version': __version__})
}
Expand Down Expand Up @@ -577,6 +576,11 @@ def patch_object(self, path, *path_args, obj):
async def patch_object_async(self, path, *path_args, obj):
"""Like :func:`patch_object` but returns a coroutine."""
data = json.dumps({'data': obj.to_dict(modified_attributes_only=True)})

if self._user_headers is None:
self._user_headers = {}
self._user_headers['Content-Type'] = 'application/json'

response = await self.patch_async(path, *path_args, data=data)
return await self._response_to_object(response)

Expand Down Expand Up @@ -624,6 +628,11 @@ def post_object(self, path, *path_args, obj):
async def post_object_async(self, path, *path_args, obj):
"""Like :func:`post_object` but returns a coroutine."""
data = json.dumps({'data': obj.to_dict()})

if self._user_headers is None:
self._user_headers = {}
self._user_headers['Content-Type'] = 'application/json'

response = await self.post_async(path, *path_args, data=data)
return await self._response_to_object(response)

Expand Down

0 comments on commit c3282d2

Please sign in to comment.