mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-31 20:26:40 +00:00
replace "datetime.utcfromtimestamp" with custom helper to avoid deprecation warnings when using Python 3.12
This commit is contained in:
parent
f72adc9e61
commit
90de901ff4
2 changed files with 14 additions and 11 deletions
|
@ -6,7 +6,7 @@
|
||||||
import sys
|
import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from datetime import datetime
|
from datetime import datetime, timezone
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from setuptools import Command
|
from setuptools import Command
|
||||||
|
@ -460,10 +460,8 @@ def write_man_header(self, write, title, description):
|
||||||
self.write_heading(write, description, double_sided=True)
|
self.write_heading(write, description, double_sided=True)
|
||||||
# man page metadata
|
# man page metadata
|
||||||
write(':Author: The Borg Collective')
|
write(':Author: The Borg Collective')
|
||||||
write(
|
source_date_epoch = int(os.environ.get("SOURCE_DATE_EPOCH", time.time()))
|
||||||
':Date:',
|
write(':Date:', datetime.fromtimestamp(source_date_epoch, timezone.utc).date().isoformat())
|
||||||
datetime.utcfromtimestamp(int(os.environ.get('SOURCE_DATE_EPOCH', time.time()))).date().isoformat(),
|
|
||||||
)
|
|
||||||
write(':Manual section: 1')
|
write(':Manual section: 1')
|
||||||
write(':Manual group: borg backup tool')
|
write(':Manual group: borg backup tool')
|
||||||
write()
|
write()
|
||||||
|
|
|
@ -1084,6 +1084,11 @@ def test_swidth_slice_mixed_characters():
|
||||||
assert swidth_slice(string, 6) == '나윤a'
|
assert swidth_slice(string, 6) == '나윤a'
|
||||||
|
|
||||||
|
|
||||||
|
def utcfromtimestamp(timestamp):
|
||||||
|
"""Returns a naive datetime instance representing the timestamp in the UTC timezone"""
|
||||||
|
return datetime.fromtimestamp(timestamp, timezone.utc).replace(tzinfo=None)
|
||||||
|
|
||||||
|
|
||||||
def test_safe_timestamps():
|
def test_safe_timestamps():
|
||||||
if SUPPORT_32BIT_PLATFORMS:
|
if SUPPORT_32BIT_PLATFORMS:
|
||||||
# ns fit into int64
|
# ns fit into int64
|
||||||
|
@ -1095,9 +1100,9 @@ def test_safe_timestamps():
|
||||||
# datetime won't fall over its y10k problem
|
# datetime won't fall over its y10k problem
|
||||||
beyond_y10k = 2 ** 100
|
beyond_y10k = 2 ** 100
|
||||||
with pytest.raises(OverflowError):
|
with pytest.raises(OverflowError):
|
||||||
datetime.utcfromtimestamp(beyond_y10k)
|
utcfromtimestamp(beyond_y10k)
|
||||||
assert datetime.utcfromtimestamp(safe_s(beyond_y10k)) > datetime(2038, 1, 1)
|
assert utcfromtimestamp(safe_s(beyond_y10k)) > datetime(2038, 1, 1)
|
||||||
assert datetime.utcfromtimestamp(safe_ns(beyond_y10k) / 1000000000) > datetime(2038, 1, 1)
|
assert utcfromtimestamp(safe_ns(beyond_y10k) / 1000000000) > datetime(2038, 1, 1)
|
||||||
else:
|
else:
|
||||||
# ns fit into int64
|
# ns fit into int64
|
||||||
assert safe_ns(2 ** 64) <= 2 ** 63 - 1
|
assert safe_ns(2 ** 64) <= 2 ** 63 - 1
|
||||||
|
@ -1108,9 +1113,9 @@ def test_safe_timestamps():
|
||||||
# datetime won't fall over its y10k problem
|
# datetime won't fall over its y10k problem
|
||||||
beyond_y10k = 2 ** 100
|
beyond_y10k = 2 ** 100
|
||||||
with pytest.raises(OverflowError):
|
with pytest.raises(OverflowError):
|
||||||
datetime.utcfromtimestamp(beyond_y10k)
|
utcfromtimestamp(beyond_y10k)
|
||||||
assert datetime.utcfromtimestamp(safe_s(beyond_y10k)) > datetime(2262, 1, 1)
|
assert utcfromtimestamp(safe_s(beyond_y10k)) > datetime(2262, 1, 1)
|
||||||
assert datetime.utcfromtimestamp(safe_ns(beyond_y10k) / 1000000000) > datetime(2262, 1, 1)
|
assert utcfromtimestamp(safe_ns(beyond_y10k) / 1000000000) > datetime(2262, 1, 1)
|
||||||
|
|
||||||
|
|
||||||
class TestPopenWithErrorHandling:
|
class TestPopenWithErrorHandling:
|
||||||
|
|
Loading…
Reference in a new issue