Skip to content

Commit

Permalink
Remove use of utcnow and timezone.utc
Browse files Browse the repository at this point in the history
  • Loading branch information
rkhwaja committed May 28, 2024
1 parent 06d5f72 commit 04b61e9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions fs/googledrivefs/googledrivefs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timezone
from datetime import datetime, UTC
from io import BytesIO, SEEK_END
from logging import getLogger
from os import close, remove
Expand Down Expand Up @@ -102,7 +102,7 @@ def close(self):
super().close() # close the file so that it's readable for upload
if self.parsedMode.writing:
# google doesn't accept the fractional second part
now = datetime.utcnow().replace(microsecond=0).isoformat() + 'Z'
now = datetime.now(tz=UTC).replace(microsecond=0, tzinfo=None).isoformat() + 'Z'
uploadMetadata = {'modifiedTime': now}
if self.thisMetadata is None:
uploadMetadata.update(
Expand Down Expand Up @@ -338,7 +338,7 @@ def setinfo(self, path, info):
if namespace == 'details':
if name == 'modified':
# incoming datetimes should be utc timestamps, Google Drive expects RFC 3339
updatedData['modifiedTime'] = epoch_to_datetime(value).replace(tzinfo=timezone.utc).isoformat()
updatedData['modifiedTime'] = epoch_to_datetime(value).replace(tzinfo=UTC).isoformat()
elif namespace == 'google':
if name == 'indexableText':
updatedData['contentHints'] = {'indexableText': value}
Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ pyngrok = ">=7"
pytest-localserver = ">=0.5.0"
pytest-xdist = ">=3.2.1"
ruff = ">=0.4.4"
pytest-rerunfailures = ">=14.0"

[tool.poe.tasks]
lint = "ruff check fs/googledrivefs/ tests/"

[tool.poe.tasks.test]
shell = """
pytest -n 4 --cov=fs/googledrivefs --timeout=2700 || exit 1
pytest -n 4 --reruns 2 --only-rerun TimeoutError --cov=fs/googledrivefs --timeout=2700 || exit 1
coverage xml
"""

Expand All @@ -57,7 +58,7 @@ coverage xml
line-length = 200
lint.ignore = ["ANN", "D", "DTZ", "EM102", "ERA001", "FBT002", "FIX", "G004", "I", "N", "PT009", "PT027", "PT013", "PTH", "S101", "TCH003", "TD", "TRY003", "W191"]
lint.select = ["ALL"]
target-version = "py37"
target-version = "py38"

[tool.ruff.lint.extend-per-file-ignores]
"__init__.py" = ["F401"]
Expand Down
4 changes: 2 additions & 2 deletions tests/test_googledrivefs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timedelta, timezone
from datetime import datetime, timedelta, UTC
from hashlib import md5
from io import BytesIO
from json import load, loads
Expand Down Expand Up @@ -107,7 +107,7 @@ def test_webhooks(self):

self.fs.touch('touched-file.txt')

expirationDateTime = datetime.now(timezone.utc) + timedelta(minutes=5)
expirationDateTime = datetime.now(UTC) + timedelta(minutes=5)
subscriptionId = str(uuid4())
self.fs.watch('touched-file.txt', tunnel.public_url.replace('http://', 'https://'), subscriptionId, expirationDateTime)
info(f'Watching {subscriptionId}')
Expand Down

0 comments on commit 04b61e9

Please sign in to comment.