forked from platypush/platypush
Replaced deprecated usages of datetime.utcnow()
with datetime.now(UTC)
.
This commit is contained in:
parent
d6185ddb1e
commit
fa318882a5
9 changed files with 46 additions and 30 deletions
|
@ -17,7 +17,7 @@ __routes__ = [
|
||||||
|
|
||||||
@login.route('/login', methods=['GET', 'POST'])
|
@login.route('/login', methods=['GET', 'POST'])
|
||||||
def login():
|
def login():
|
||||||
""" Login page """
|
"""Login page"""
|
||||||
user_manager = UserManager()
|
user_manager = UserManager()
|
||||||
session_token = request.cookies.get('session_token')
|
session_token = request.cookies.get('session_token')
|
||||||
|
|
||||||
|
@ -37,11 +37,15 @@ def login():
|
||||||
username = request.form.get('username')
|
username = request.form.get('username')
|
||||||
password = request.form.get('password')
|
password = request.form.get('password')
|
||||||
remember = request.form.get('remember')
|
remember = request.form.get('remember')
|
||||||
expires = datetime.datetime.utcnow() + datetime.timedelta(days=365) \
|
expires = (
|
||||||
if remember else None
|
datetime.datetime.now(datetime.UTC) + datetime.timedelta(days=365)
|
||||||
|
if remember
|
||||||
|
else None
|
||||||
|
)
|
||||||
|
|
||||||
session = user_manager.create_user_session(username=username, password=password,
|
session = user_manager.create_user_session(
|
||||||
expires_at=expires)
|
username=username, password=password, expires_at=expires
|
||||||
|
)
|
||||||
|
|
||||||
if session:
|
if session:
|
||||||
redirect_target = redirect(redirect_page, 302) # lgtm [py/url-redirection]
|
redirect_target = redirect(redirect_page, 302) # lgtm [py/url-redirection]
|
||||||
|
|
|
@ -17,7 +17,7 @@ __routes__ = [
|
||||||
|
|
||||||
@register.route('/register', methods=['GET', 'POST'])
|
@register.route('/register', methods=['GET', 'POST'])
|
||||||
def register():
|
def register():
|
||||||
""" Registration page """
|
"""Registration page"""
|
||||||
user_manager = UserManager()
|
user_manager = UserManager()
|
||||||
redirect_page = request.args.get('redirect')
|
redirect_page = request.args.get('redirect')
|
||||||
if not redirect_page:
|
if not redirect_page:
|
||||||
|
@ -34,7 +34,9 @@ def register():
|
||||||
return redirect(redirect_page, 302) # lgtm [py/url-redirection]
|
return redirect(redirect_page, 302) # lgtm [py/url-redirection]
|
||||||
|
|
||||||
if user_manager.get_user_count() > 0:
|
if user_manager.get_user_count() > 0:
|
||||||
return redirect('/login?redirect=' + redirect_page, 302) # lgtm [py/url-redirection]
|
return redirect(
|
||||||
|
'/login?redirect=' + redirect_page, 302
|
||||||
|
) # lgtm [py/url-redirection]
|
||||||
|
|
||||||
if request.form:
|
if request.form:
|
||||||
username = request.form.get('username')
|
username = request.form.get('username')
|
||||||
|
@ -44,12 +46,20 @@ def register():
|
||||||
|
|
||||||
if password == confirm_password:
|
if password == confirm_password:
|
||||||
user_manager.create_user(username=username, password=password)
|
user_manager.create_user(username=username, password=password)
|
||||||
session = user_manager.create_user_session(username=username, password=password,
|
session = user_manager.create_user_session(
|
||||||
expires_at=datetime.datetime.utcnow() + datetime.timedelta(days=1)
|
username=username,
|
||||||
if not remember else None)
|
password=password,
|
||||||
|
expires_at=(
|
||||||
|
datetime.datetime.now(datetime.UTC) + datetime.timedelta(days=1)
|
||||||
|
if not remember
|
||||||
|
else None
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
if session:
|
if session:
|
||||||
redirect_target = redirect(redirect_page, 302) # lgtm [py/url-redirection]
|
redirect_target = redirect(
|
||||||
|
redirect_page, 302
|
||||||
|
) # lgtm [py/url-redirection]
|
||||||
response = make_response(redirect_target)
|
response = make_response(redirect_target)
|
||||||
response.set_cookie('session_token', session.session_token)
|
response.set_cookie('session_token', session.session_token)
|
||||||
return response
|
return response
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta, UTC
|
||||||
import logging
|
import logging
|
||||||
from threading import Event
|
from threading import Event
|
||||||
from typing import Collection, Optional
|
from typing import Collection, Optional
|
||||||
|
@ -45,8 +45,8 @@ def get_entities_engine(timeout: Optional[float] = None) -> EntitiesEngine:
|
||||||
|
|
||||||
:param timeout: Timeout in seconds (default: None).
|
:param timeout: Timeout in seconds (default: None).
|
||||||
"""
|
"""
|
||||||
time_start = datetime.utcnow()
|
time_start = datetime.now(UTC)
|
||||||
while not timeout or (datetime.utcnow() - time_start < timedelta(seconds=timeout)):
|
while not timeout or (datetime.now(UTC) - time_start < timedelta(seconds=timeout)):
|
||||||
if _engine:
|
if _engine:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import pathlib
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import types
|
import types
|
||||||
from datetime import datetime
|
from datetime import datetime, UTC
|
||||||
from typing import Callable, Dict, List, Optional, Set, Type, Tuple, Any
|
from typing import Callable, Dict, List, Optional, Set, Type, Tuple, Any
|
||||||
|
|
||||||
import pkgutil
|
import pkgutil
|
||||||
|
@ -83,12 +83,12 @@ if not is_defined('entity'):
|
||||||
image_url = Column(String)
|
image_url = Column(String)
|
||||||
|
|
||||||
created_at = Column(
|
created_at = Column(
|
||||||
DateTime(timezone=False), default=datetime.utcnow(), nullable=False
|
DateTime(timezone=False), default=datetime.now(UTC), nullable=False
|
||||||
)
|
)
|
||||||
updated_at = Column(
|
updated_at = Column(
|
||||||
DateTime(timezone=False),
|
DateTime(timezone=False),
|
||||||
default=datetime.utcnow(),
|
default=datetime.now(UTC),
|
||||||
onupdate=datetime.utcnow(),
|
onupdate=datetime.now(UTC),
|
||||||
)
|
)
|
||||||
|
|
||||||
parent = relationship(
|
parent = relationship(
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import inspect
|
import inspect
|
||||||
import json
|
import json
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from datetime import datetime
|
from datetime import datetime, UTC
|
||||||
from typing import Any, Optional, Dict, Collection, Type
|
from typing import Any, Optional, Dict, Collection, Type
|
||||||
|
|
||||||
from platypush.config import Config
|
from platypush.config import Config
|
||||||
|
@ -77,7 +77,7 @@ class EntityManager(ABC):
|
||||||
entity.id = None # type: ignore
|
entity.id = None # type: ignore
|
||||||
|
|
||||||
entity.plugin = get_plugin_name_by_class(self.__class__) # type: ignore
|
entity.plugin = get_plugin_name_by_class(self.__class__) # type: ignore
|
||||||
entity.updated_at = datetime.utcnow() # type: ignore
|
entity.updated_at = datetime.now(UTC) # type: ignore
|
||||||
entity.children = self._normalize_entities(entity.children)
|
entity.children = self._normalize_entities(entity.children)
|
||||||
|
|
||||||
return entities
|
return entities
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta, UTC
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
from typing import Callable, Collection, Dict, Final, List, Optional, Type
|
from typing import Callable, Collection, Dict, Final, List, Optional, Type
|
||||||
|
@ -98,7 +98,7 @@ event_matchers: Dict[
|
||||||
)
|
)
|
||||||
and (
|
and (
|
||||||
not (old and old.updated_at)
|
not (old and old.updated_at)
|
||||||
or datetime.utcnow() - old.updated_at
|
or datetime.now(UTC) - old.updated_at
|
||||||
>= timedelta(seconds=_rssi_update_interval)
|
>= timedelta(seconds=_rssi_update_interval)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
@ -227,9 +227,11 @@ class EventHandler:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
mapped_uuids = [
|
mapped_uuids = [
|
||||||
|
(
|
||||||
int(str(srv.uuid).split('-', maxsplit=1)[0], 16) & 0xFFFF
|
int(str(srv.uuid).split('-', maxsplit=1)[0], 16) & 0xFFFF
|
||||||
if isinstance(srv.uuid, UUID)
|
if isinstance(srv.uuid, UUID)
|
||||||
else srv.uuid
|
else srv.uuid
|
||||||
|
)
|
||||||
for srv in device.services
|
for srv in device.services
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ class GoogleCalendarPlugin(GooglePlugin, CalendarInterface):
|
||||||
:meth:`platypush.plugins.calendar.CalendarPlugin.get_upcoming_events`.
|
:meth:`platypush.plugins.calendar.CalendarPlugin.get_upcoming_events`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
now = datetime.datetime.utcnow().isoformat() + 'Z'
|
now = datetime.datetime.now(datetime.UTC).isoformat() + 'Z'
|
||||||
service = self.get_service('calendar', 'v3')
|
service = self.get_service('calendar', 'v3')
|
||||||
result = (
|
result = (
|
||||||
service.events()
|
service.events()
|
||||||
|
|
|
@ -289,7 +289,7 @@ class RssPlugin(RunnablePlugin):
|
||||||
title = ElementTree.Element('title')
|
title = ElementTree.Element('title')
|
||||||
title.text = 'Platypush feed subscriptions'
|
title.text = 'Platypush feed subscriptions'
|
||||||
created = ElementTree.Element('dateCreated')
|
created = ElementTree.Element('dateCreated')
|
||||||
created.text = self._datetime_to_string(datetime.datetime.utcnow())
|
created.text = self._datetime_to_string(datetime.datetime.now(datetime.UTC))
|
||||||
head.append(title)
|
head.append(title)
|
||||||
head.append(created)
|
head.append(created)
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ class UserManager:
|
||||||
),
|
),
|
||||||
password_salt=password_salt.hex(),
|
password_salt=password_salt.hex(),
|
||||||
hmac_iterations=hmac_iterations,
|
hmac_iterations=hmac_iterations,
|
||||||
created_at=datetime.datetime.utcnow(),
|
created_at=datetime.datetime.now(datetime.UTC),
|
||||||
**kwargs,
|
**kwargs,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ class UserManager:
|
||||||
|
|
||||||
if not user_session or (
|
if not user_session or (
|
||||||
user_session.expires_at
|
user_session.expires_at
|
||||||
and user_session.expires_at < datetime.datetime.utcnow()
|
and user_session.expires_at < datetime.datetime.now(datetime.UTC)
|
||||||
):
|
):
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ class UserManager:
|
||||||
user_id=user.user_id,
|
user_id=user.user_id,
|
||||||
session_token=self.generate_session_token(),
|
session_token=self.generate_session_token(),
|
||||||
csrf_token=self.generate_session_token(),
|
csrf_token=self.generate_session_token(),
|
||||||
created_at=datetime.datetime.utcnow(),
|
created_at=datetime.datetime.now(datetime.UTC),
|
||||||
expires_at=expires_at,
|
expires_at=expires_at,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue