aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Bond <will@wbond.net>2019-12-25 06:28:32 -0500
committerGitHub <noreply@github.com>2019-12-25 06:28:32 -0500
commit53f60e059d5cecc8328cfcccc734ee534ddfb17b (patch)
tree2c3be790cf59ef9622f785f94ed43e9100ee011f
parent70fc737af5a8f7b8a52802c58b26835d07f5e440 (diff)
parent20e2b4ed3ee3a4cab080ba8b4f98aee94316e01c (diff)
downloadasn1crypto-53f60e059d5cecc8328cfcccc734ee534ddfb17b.tar.gz
Merge pull request #169 from joernheissler/i167
Add __getinitargs__ method to util.timezone
-rw-r--r--asn1crypto/util.py10
-rw-r--r--tests/test_core.py9
2 files changed, 19 insertions, 0 deletions
diff --git a/asn1crypto/util.py b/asn1crypto/util.py
index 4d743df..7196897 100644
--- a/asn1crypto/util.py
+++ b/asn1crypto/util.py
@@ -161,6 +161,16 @@ if sys.version_info <= (3,):
return False
return self._offset == other._offset
+ def __getinitargs__(self):
+ """
+ Called by tzinfo.__reduce__ to support pickle and copy.
+
+ :return:
+ offset and name, to be used for __init__
+ """
+
+ return self._offset, self._name
+
def tzname(self, dt):
"""
:param dt:
diff --git a/tests/test_core.py b/tests/test_core.py
index aaff9f5..41ea71d 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -409,6 +409,15 @@ class CoreTests(unittest.TestCase):
# Is past 2050
core.UTCTime(datetime(2106, 2, 7, 6, 28, 16, tzinfo=util.timezone.utc))
+ def test_utctime_copy(self):
+ a = core.UTCTime(datetime(2019, 11, 11, 17, 45, 18, tzinfo=util.timezone.utc))
+ # Ensure _native is set because we want to test copy on the nested timezone object.
+ a.native
+ b = a.copy()
+ self.assertEqual(a.native, b.native)
+ self.assertEqual(a.contents, b.contents)
+ self.assertEqual(a.dump(), b.dump())
+
@staticmethod
def generalized_time_info():
def tz(hours, minutes=0):