Skip to content

Commit

Permalink
Remove Python 2 Specific Code
Browse files Browse the repository at this point in the history
This patch removes some more Python 2 specific code which is now
unnecessary since we dropped Python 2 support.
  • Loading branch information
lkiesow authored and shaardie committed Jun 19, 2020
1 parent ce399dc commit 1927c35
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 22 deletions.
4 changes: 2 additions & 2 deletions pyca/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
:license: LGPL – see license.lgpl for more details.
'''

from pyca.utils import http_request, configure_service, unix_ts, timestamp, \
from pyca.utils import http_request, configure_service, timestamp, \
set_service_status_immediate, terminate
from pyca.config import config
from pyca.db import get_session, UpcomingEvent, Service, ServiceStatus, \
Expand Down Expand Up @@ -41,7 +41,7 @@ def parse_ical(vcal):
if len(line) <= 1 or key == 'end':
continue
if key.startswith('dt'):
event[key] = unix_ts(dateutil.parser.parse(line[1]))
event[key] = int(dateutil.parser.parse(line[1]).timestamp())
continue
if not key.startswith('attach'):
event[key] = line[1]
Expand Down
13 changes: 1 addition & 12 deletions pyca/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,10 @@ def get_service(service_type):
return endpoints


def unix_ts(dtval):
'''Convert datetime into a unix timestamp.
This is the equivalent to Python 3's int(datetime.timestamp()).
:param dt: datetime to convert
'''
epoch = datetime(1970, 1, 1, 0, 0, tzinfo=tzutc())
delta = (dtval - epoch)
return delta.days * 24 * 3600 + delta.seconds


def timestamp():
'''Get current unix timestamp
'''
return unix_ts(datetime.now(tzutc()))
return int(datetime.now(tzutc()).timestamp())


def try_mkdir(directory):
Expand Down
5 changes: 1 addition & 4 deletions tests/test_ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
import tempfile
import unittest

try:
from unittest.mock import patch
except ImportError:
from mock import patch
from unittest.mock import patch

from pyca import ingest, config, db, utils
from tests.tools import should_fail, terminate_fn
Expand Down
5 changes: 1 addition & 4 deletions tests/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
import logging
import pycurl

try:
from importlib import reload # noqa
except ImportError:
from imp import reload # noqa
from importlib import reload # noqa


# Raise log level above maximum to silence logging in tests.
Expand Down

0 comments on commit 1927c35

Please sign in to comment.