summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2019-11-16 10:19:07 -0800
committerIlya Etingof <etingof@gmail.com>2019-11-16 19:19:07 +0100
commita7d2ac036866e5f437bd6f9a9f01723f601b4073 (patch)
tree543d918472952d4d7b41ff9ea3ff56fc21b38448
parente51d6f520bdd57748f70b8defc2bda1ddea9856b (diff)
downloadpyasn1-git-a7d2ac036866e5f437bd6f9a9f01723f601b4073.tar.gz
Drop support for EOL Pythons (#131)
Python 2.4, 2.5, 2.6, 3.2 and 3.3 are end of life. They are no longer receiving bug fixes, including for security issues. These Pythons went EOL on: Python 2.6: 2013-10-29 Python 3.2: 2016-02-20 Python 3.3: 2017-09-29 For additional details on supported Python versions, see: https://devguide.python.org/#status-of-python-branches Removing support for EOL Pythons will reduce testing and maintenance resources. Using pypinfo, here are the download statistics of the project for the last 30 days, showing limited downloads from EOL Pythons: | python_version | percent | download_count | | -------------- | ------: | -------------: | | 2.7 | 90.33% | 7,975,885 | | 3.6 | 4.95% | 437,261 | | 3.5 | 2.99% | 263,637 | | 3.4 | 1.02% | 89,723 | | 2.6 | 0.69% | 60,511 | | 3.7 | 0.02% | 2,024 | | 3.3 | 0.00% | 441 | | 3.2 | 0.00% | 38 | | 3.8 | 0.00% | 9 | | None | 0.00% | 2 | By removing support for older Pythons, can remove or update the following workarounds and code: * Built-in function bin() is always available. * Built-in function callable() is always available. * Built-in function all() is always available. * The collections.OrderedDict class is always available. * The datetime.strptime() method is always available. * The platform module is always available. * The string.partition() method is always available. * The NullHandler class is always available. * The method .__trunc__() is always available. * Can use set literals. * Updated unittest is always available. The unittest2 module is unnecessary. Users on older versions of Python can continue to download, install, and use older versions of the library that continue to have support for older Pythons.
-rw-r--r--.travis.yml10
-rw-r--r--CHANGES.rst2
-rw-r--r--README.md2
-rw-r--r--docs/source/download.rst5
-rw-r--r--docs/source/pyasn1/contents.rst2
-rw-r--r--pyasn1/__init__.py4
-rw-r--r--pyasn1/codec/native/encoder.py9
-rw-r--r--pyasn1/compat/binary.py33
-rw-r--r--pyasn1/compat/calling.py20
-rw-r--r--pyasn1/compat/dateandtime.py22
-rw-r--r--pyasn1/compat/integer.py10
-rw-r--r--pyasn1/compat/string.py26
-rw-r--r--pyasn1/debug.py12
-rw-r--r--pyasn1/type/base.py53
-rw-r--r--pyasn1/type/univ.py26
-rw-r--r--pyasn1/type/useful.py12
-rw-r--r--setup.py19
-rw-r--r--tests/__main__.py6
-rw-r--r--tests/base.py7
-rw-r--r--tests/codec/__main__.py6
-rw-r--r--tests/codec/ber/__main__.py6
-rw-r--r--tests/codec/ber/test_decoder.py14
-rw-r--r--tests/codec/ber/test_encoder.py26
-rw-r--r--tests/codec/cer/__main__.py6
-rw-r--r--tests/codec/cer/test_decoder.py6
-rw-r--r--tests/codec/cer/test_encoder.py6
-rw-r--r--tests/codec/der/__main__.py6
-rw-r--r--tests/codec/der/test_decoder.py7
-rw-r--r--tests/codec/der/test_encoder.py7
-rw-r--r--tests/codec/native/__main__.py6
-rw-r--r--tests/codec/native/test_decoder.py7
-rw-r--r--tests/codec/native/test_encoder.py7
-rw-r--r--tests/compat/__main__.py9
-rw-r--r--tests/compat/test_binary.py56
-rw-r--r--tests/compat/test_integer.py6
-rw-r--r--tests/compat/test_octets.py6
-rw-r--r--tests/test_debug.py7
-rw-r--r--tests/type/__main__.py6
-rw-r--r--tests/type/test_char.py12
-rw-r--r--tests/type/test_constraint.py7
-rw-r--r--tests/type/test_namedtype.py7
-rw-r--r--tests/type/test_namedval.py15
-rw-r--r--tests/type/test_opentype.py7
-rw-r--r--tests/type/test_tag.py7
-rw-r--r--tests/type/test_univ.py27
-rw-r--r--tests/type/test_useful.py7
46 files changed, 108 insertions, 461 deletions
diff --git a/.travis.yml b/.travis.yml
index cb495de..98314f4 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -4,18 +4,9 @@ matrix:
include:
- os: linux
dist: trusty
- python: '2.6'
- - os: linux
- dist: trusty
python: '2.7'
- os: linux
dist: trusty
- python: '3.2'
- - os: linux
- dist: trusty
- python: '3.3'
- - os: linux
- dist: trusty
python: '3.4'
- os: linux
dist: trusty
@@ -25,7 +16,6 @@ matrix:
python: '3.6'
- os: linux
dist: xenial
- sudo: true
python: '3.7'
- os: linux
dist: trusty
diff --git a/CHANGES.rst b/CHANGES.rst
index 645f4f7..4ca71b5 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -2,7 +2,7 @@
Revision 0.5.0, released XX-11-2019
-----------------------------------
-No changes yet
+- Removed support for EOL Pythons 2.4, 2.5, 2.6, 3.2 and 3.3.
Revision 0.4.8, released 16-11-2019
-----------------------------------
diff --git a/README.md b/README.md
index e36324b..a73bf54 100644
--- a/README.md
+++ b/README.md
@@ -19,7 +19,7 @@ Features
* Generic implementation of ASN.1 types (X.208)
* Standards compliant BER/CER/DER codecs
* Dumps/loads ASN.1 structures from Python types
-* 100% Python, works with Python 2.4 up to Python 3.7
+* 100% Python, works with Python 2.7 and 3.4+
* MT-safe
* Contributed ASN.1 compiler [Asn1ate](https://github.com/kimgr/asn1ate)
diff --git a/docs/source/download.rst b/docs/source/download.rst
index bbbd66c..2869411 100644
--- a/docs/source/download.rst
+++ b/docs/source/download.rst
@@ -3,10 +3,7 @@ Download & Install
==================
The *pyasn1* library is a pure-Python package with no external
-dependencies. Considering how much industrial or finance software
-can be stuck with an old platform (think RHEL 5), we struggle to
-maintain its compatibility back to the very pre-historic Python
-(which is 2.4!).
+dependencies. It works with Python 2.7 and 3.4+.
The best way to obtain PyASN1 is by running `pip`:
diff --git a/docs/source/pyasn1/contents.rst b/docs/source/pyasn1/contents.rst
index eaa7835..bba0d35 100644
--- a/docs/source/pyasn1/contents.rst
+++ b/docs/source/pyasn1/contents.rst
@@ -20,7 +20,7 @@ implementation of pyasn1 classes from ASN.1 specification.
Both `pyasn1 <https://github.com/etingof/pyasn1>`_ and
`pyasn1-modules <https://github.com/etingof/pyasn1-modules>`_ libraries
-can be used out-of-the-box with Python versions 2.4 through 3.7.
+can be used out-of-the-box with Python versions 2.7 and 3.4+.
No external dependencies required.
.. _pyasn1-types:
diff --git a/pyasn1/__init__.py b/pyasn1/__init__.py
index 39d6857..42c7422 100644
--- a/pyasn1/__init__.py
+++ b/pyasn1/__init__.py
@@ -3,5 +3,5 @@ import sys
# https://www.python.org/dev/peps/pep-0396/
__version__ = '0.5.0'
-if sys.version_info[:2] < (2, 4):
- raise RuntimeError('PyASN1 requires Python 2.4 or later')
+if sys.version_info[:2] < (2, 7):
+ raise RuntimeError('PyASN1 requires Python 2.7 or later')
diff --git a/pyasn1/codec/native/encoder.py b/pyasn1/codec/native/encoder.py
index 4318abd..a83d00a 100644
--- a/pyasn1/codec/native/encoder.py
+++ b/pyasn1/codec/native/encoder.py
@@ -4,11 +4,7 @@
# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
# License: http://snmplabs.com/pyasn1/license.html
#
-try:
- from collections import OrderedDict
-
-except ImportError:
- OrderedDict = dict
+from collections import OrderedDict
from pyasn1 import debug
from pyasn1 import error
@@ -224,8 +220,7 @@ class Encoder(object):
#: of those.
#:
#: One exception is that instead of :py:class:`dict`, the :py:class:`OrderedDict`
-#: can be produced (whenever available) to preserve ordering of the components
-#: in ASN.1 SEQUENCE.
+#: is used to preserve ordering of the components in ASN.1 SEQUENCE.
#:
#: Parameters
#: ----------
diff --git a/pyasn1/compat/binary.py b/pyasn1/compat/binary.py
deleted file mode 100644
index addbdc9..0000000
--- a/pyasn1/compat/binary.py
+++ /dev/null
@@ -1,33 +0,0 @@
-#
-# This file is part of pyasn1 software.
-#
-# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
-# License: http://snmplabs.com/pyasn1/license.html
-#
-from sys import version_info
-
-if version_info[0:2] < (2, 6):
- def bin(value):
- bitstring = []
-
- if value > 0:
- prefix = '0b'
- elif value < 0:
- prefix = '-0b'
- value = abs(value)
- else:
- prefix = '0b0'
-
- while value:
- if value & 1 == 1:
- bitstring.append('1')
- else:
- bitstring.append('0')
-
- value >>= 1
-
- bitstring.reverse()
-
- return prefix + ''.join(bitstring)
-else:
- bin = bin
diff --git a/pyasn1/compat/calling.py b/pyasn1/compat/calling.py
deleted file mode 100644
index 778a3d1..0000000
--- a/pyasn1/compat/calling.py
+++ /dev/null
@@ -1,20 +0,0 @@
-#
-# This file is part of pyasn1 software.
-#
-# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
-# License: http://snmplabs.com/pyasn1/license.html
-#
-from sys import version_info
-
-__all__ = ['callable']
-
-
-if (2, 7) < version_info[:2] < (3, 2):
- import collections
-
- def callable(x):
- return isinstance(x, collections.Callable)
-
-else:
-
- callable = callable
diff --git a/pyasn1/compat/dateandtime.py b/pyasn1/compat/dateandtime.py
deleted file mode 100644
index 5e471bf..0000000
--- a/pyasn1/compat/dateandtime.py
+++ /dev/null
@@ -1,22 +0,0 @@
-#
-# This file is part of pyasn1 software.
-#
-# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
-# License: http://snmplabs.com/pyasn1/license.html
-#
-import time
-from datetime import datetime
-from sys import version_info
-
-__all__ = ['strptime']
-
-
-if version_info[:2] <= (2, 4):
-
- def strptime(text, dateFormat):
- return datetime(*(time.strptime(text, dateFormat)[0:6]))
-
-else:
-
- def strptime(text, dateFormat):
- return datetime.strptime(text, dateFormat)
diff --git a/pyasn1/compat/integer.py b/pyasn1/compat/integer.py
index 4b31791..df6bed4 100644
--- a/pyasn1/compat/integer.py
+++ b/pyasn1/compat/integer.py
@@ -5,16 +5,12 @@
# License: http://snmplabs.com/pyasn1/license.html
#
import sys
+import platform
-try:
- import platform
-
- implementation = platform.python_implementation()
+from pyasn1.compat.octets import oct2int, null, ensureString
-except (ImportError, AttributeError):
- implementation = 'CPython'
-from pyasn1.compat.octets import oct2int, null, ensureString
+implementation = platform.python_implementation()
if sys.version_info[0:2] < (3, 2) or implementation != 'CPython':
from binascii import a2b_hex, b2a_hex
diff --git a/pyasn1/compat/string.py b/pyasn1/compat/string.py
deleted file mode 100644
index b9bc8c3..0000000
--- a/pyasn1/compat/string.py
+++ /dev/null
@@ -1,26 +0,0 @@
-#
-# This file is part of pyasn1 software.
-#
-# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
-# License: http://snmplabs.com/pyasn1/license.html
-#
-from sys import version_info
-
-if version_info[:2] <= (2, 5):
-
- def partition(string, sep):
- try:
- a, c = string.split(sep, 1)
-
- except ValueError:
- a, b, c = string, '', ''
-
- else:
- b = sep
-
- return a, b, c
-
-else:
-
- def partition(string, sep):
- return string.partition(sep)
diff --git a/pyasn1/debug.py b/pyasn1/debug.py
index 8707aa8..c70b1db 100644
--- a/pyasn1/debug.py
+++ b/pyasn1/debug.py
@@ -55,16 +55,6 @@ class Printer(object):
return '<python logging>'
-if hasattr(logging, 'NullHandler'):
- NullHandler = logging.NullHandler
-
-else:
- # Python 2.6 and older
- class NullHandler(logging.Handler):
- def emit(self, record):
- pass
-
-
class Debug(object):
defaultPrinter = Printer()
@@ -75,7 +65,7 @@ class Debug(object):
# route our logs to parent logger
self._printer = Printer(
logger=logging.getLogger(options['loggerName']),
- handler=NullHandler()
+ handler=logging.NullHandler()
)
elif 'printer' in options:
diff --git a/pyasn1/type/base.py b/pyasn1/type/base.py
index 994f1c9..f0ef270 100644
--- a/pyasn1/type/base.py
+++ b/pyasn1/type/base.py
@@ -7,7 +7,6 @@
import sys
from pyasn1 import error
-from pyasn1.compat import calling
from pyasn1.type import constraint
from pyasn1.type import tag
from pyasn1.type import tagmap
@@ -179,31 +178,31 @@ class NoValue(object):
Any operation attempted on the *noValue* object will raise the
*PyAsn1Error* exception.
"""
- skipMethods = set(
- ('__slots__',
- # attributes
- '__getattribute__',
- '__getattr__',
- '__setattr__',
- '__delattr__',
- # class instance
- '__class__',
- '__init__',
- '__del__',
- '__new__',
- '__repr__',
- '__qualname__',
- '__objclass__',
- 'im_class',
- '__sizeof__',
- # pickle protocol
- '__reduce__',
- '__reduce_ex__',
- '__getnewargs__',
- '__getinitargs__',
- '__getstate__',
- '__setstate__')
- )
+ skipMethods = {
+ '__slots__',
+ # attributes
+ '__getattribute__',
+ '__getattr__',
+ '__setattr__',
+ '__delattr__',
+ # class instance
+ '__class__',
+ '__init__',
+ '__del__',
+ '__new__',
+ '__repr__',
+ '__qualname__',
+ '__objclass__',
+ 'im_class',
+ '__sizeof__',
+ # pickle protocol
+ '__reduce__',
+ '__reduce_ex__',
+ '__getnewargs__',
+ '__getinitargs__',
+ '__getstate__',
+ '__setstate__',
+ }
_instance = None
@@ -220,7 +219,7 @@ class NoValue(object):
if (name not in cls.skipMethods and
name.startswith('__') and
name.endswith('__') and
- calling.callable(getattr(typ, name)))]
+ callable(getattr(typ, name)))]
for name in set(op_names):
setattr(cls, name, getPlug(name))
diff --git a/pyasn1/type/univ.py b/pyasn1/type/univ.py
index aa688b2..05fa677 100644
--- a/pyasn1/type/univ.py
+++ b/pyasn1/type/univ.py
@@ -9,7 +9,6 @@ import sys
from pyasn1 import error
from pyasn1.codec.ber import eoo
-from pyasn1.compat import binary
from pyasn1.compat import integer
from pyasn1.compat import octets
from pyasn1.type import base
@@ -231,9 +230,8 @@ class Integer(base.SimpleAsn1Type):
def __ceil__(self):
return math.ceil(self._value)
- if sys.version_info[0:2] > (2, 5):
- def __trunc__(self):
- return self.clone(math.trunc(self._value))
+ def __trunc__(self):
+ return self.clone(math.trunc(self._value))
def __lt__(self, value):
return self._value < value
@@ -586,7 +584,7 @@ class BitString(base.SimpleAsn1Type):
def asBinary(self):
"""Get |ASN.1| value as a text string of bits.
"""
- binString = binary.bin(self._value)[2:]
+ binString = bin(self._value)[2:]
return '0' * (len(self._value) - len(binString)) + binString
@classmethod
@@ -719,19 +717,6 @@ class BitString(base.SimpleAsn1Type):
)
-try:
- # noinspection PyStatementEffect
- all
-
-except NameError: # Python 2.4
- # noinspection PyShadowingBuiltins
- def all(iterable):
- for element in iterable:
- if not element:
- return False
- return True
-
-
class OctetString(base.SimpleAsn1Type):
"""Create |ASN.1| schema or value object.
@@ -1499,9 +1484,8 @@ class Real(base.SimpleAsn1Type):
def __ceil__(self):
return self.clone(math.ceil(float(self)))
- if sys.version_info[0:2] > (2, 5):
- def __trunc__(self):
- return self.clone(math.trunc(float(self)))
+ def __trunc__(self):
+ return self.clone(math.trunc(float(self)))
def __lt__(self, value):
return float(self) < value
diff --git a/pyasn1/type/useful.py b/pyasn1/type/useful.py
index 7536b95..a9a0287 100644
--- a/pyasn1/type/useful.py
+++ b/pyasn1/type/useful.py
@@ -7,8 +7,6 @@
import datetime
from pyasn1 import error
-from pyasn1.compat import dateandtime
-from pyasn1.compat import string
from pyasn1.type import char
from pyasn1.type import tag
from pyasn1.type import univ
@@ -74,9 +72,9 @@ class TimeMixIn(object):
elif '-' in text or '+' in text:
if '+' in text:
- text, plusminus, tz = string.partition(text, '+')
+ text, plusminus, tz = text.partition('+')
else:
- text, plusminus, tz = string.partition(text, '-')
+ text, plusminus, tz = text.partition('-')
if self._shortTZ and len(tz) == 2:
tz += '00'
@@ -99,9 +97,9 @@ class TimeMixIn(object):
if '.' in text or ',' in text:
if '.' in text:
- text, _, ms = string.partition(text, '.')
+ text, _, ms = text.partition('.')
else:
- text, _, ms = string.partition(text, ',')
+ text, _, ms = text.partition(',')
try:
ms = int(ms) * 1000
@@ -118,7 +116,7 @@ class TimeMixIn(object):
text += '00'
try:
- dt = dateandtime.strptime(text, self._yearsDigits == 4 and '%Y%m%d%H%M%S' or '%y%m%d%H%M%S')
+ dt = datetime.datetime.strptime(text, self._yearsDigits == 4 and '%Y%m%d%H%M%S' or '%y%m%d%H%M%S')
except ValueError:
raise error.PyAsn1Error('malformed datetime format %s' % self)
diff --git a/setup.py b/setup.py
index fa0a876..1992835 100644
--- a/setup.py
+++ b/setup.py
@@ -7,6 +7,7 @@
#
import os
import sys
+import unittest
classifiers = """\
Development Status :: 5 - Production/Stable
@@ -20,13 +21,8 @@ License :: OSI Approved :: BSD License
Natural Language :: English
Operating System :: OS Independent
Programming Language :: Python :: 2
-Programming Language :: Python :: 2.4
-Programming Language :: Python :: 2.5
-Programming Language :: Python :: 2.6
Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
-Programming Language :: Python :: 3.2
-Programming Language :: Python :: 3.3
Programming Language :: Python :: 3.4
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6
@@ -49,8 +45,8 @@ def howto_install_setuptools():
""")
-if sys.version_info[:2] < (2, 4):
- print("ERROR: this package requires Python 2.4 or later!")
+if sys.version_info[:2] < (2, 7):
+ print("ERROR: this package requires Python 2.7 or later!")
sys.exit(1)
try:
@@ -88,13 +84,8 @@ params.update({
'pyasn1.codec.ber',
'pyasn1.codec.cer',
'pyasn1.codec.der',
- 'pyasn1.codec.native']})
-
-# handle unittest discovery feature
-try:
- import unittest2 as unittest
-except ImportError:
- import unittest
+ 'pyasn1.codec.native'],
+ 'python_requires': '>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*'})
class PyTest(Command):
diff --git a/tests/__main__.py b/tests/__main__.py
index 14ef28a..5340b83 100644
--- a/tests/__main__.py
+++ b/tests/__main__.py
@@ -4,11 +4,7 @@
# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
# License: http://snmplabs.com/pyasn1/license.html
#
-try:
- import unittest2 as unittest
-
-except ImportError:
- import unittest
+import unittest
suite = unittest.TestLoader().loadTestsFromNames(
['tests.test_debug.suite',
diff --git a/tests/base.py b/tests/base.py
index 07f06dc..1274049 100644
--- a/tests/base.py
+++ b/tests/base.py
@@ -4,12 +4,7 @@
# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
# License: http://snmplabs.com/pyasn1/license.html
#
-
-try:
- import unittest2 as unittest
-
-except ImportError:
- import unittest
+import unittest
from pyasn1 import debug
diff --git a/tests/codec/__main__.py b/tests/codec/__main__.py
index 7a4cf20..8f2aaff 100644
--- a/tests/codec/__main__.py
+++ b/tests/codec/__main__.py
@@ -4,11 +4,7 @@
# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
# License: http://snmplabs.com/pyasn1/license.html
#
-try:
- import unittest2 as unittest
-
-except ImportError:
- import unittest
+import unittest
suite = unittest.TestLoader().loadTestsFromNames(
['tests.codec.ber.__main__.suite',
diff --git a/tests/codec/ber/__main__.py b/tests/codec/ber/__main__.py
index 59c0c2b..a1e1b16 100644
--- a/tests/codec/ber/__main__.py
+++ b/tests/codec/ber/__main__.py
@@ -4,11 +4,7 @@
# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
# License: http://snmplabs.com/pyasn1/license.html
#
-try:
- import unittest2 as unittest
-
-except ImportError:
- import unittest
+import unittest
suite = unittest.TestLoader().loadTestsFromNames(
['tests.codec.ber.test_encoder.suite',
diff --git a/tests/codec/ber/test_decoder.py b/tests/codec/ber/test_decoder.py
index e3b74df..2921a4f 100644
--- a/tests/codec/ber/test_decoder.py
+++ b/tests/codec/ber/test_decoder.py
@@ -5,12 +5,7 @@
# License: http://snmplabs.com/pyasn1/license.html
#
import sys
-
-try:
- import unittest2 as unittest
-
-except ImportError:
- import unittest
+import unittest
from tests.base import BaseTestCase
@@ -483,10 +478,9 @@ class RealDecoderTestCase(BaseTestCase):
assert 0, 'accepted too-short real'
-if sys.version_info[0:2] > (2, 5):
- class UniversalStringDecoderTestCase(BaseTestCase):
- def testDecoder(self):
- assert decoder.decode(ints2octs((28, 12, 0, 0, 0, 97, 0, 0, 0, 98, 0, 0, 0, 99))) == (char.UniversalString(sys.version_info[0] >= 3 and 'abc' or unicode('abc')), null)
+class UniversalStringDecoderTestCase(BaseTestCase):
+ def testDecoder(self):
+ assert decoder.decode(ints2octs((28, 12, 0, 0, 0, 97, 0, 0, 0, 98, 0, 0, 0, 99))) == (char.UniversalString(sys.version_info[0] == 3 and 'abc' or unicode('abc')), null)
class BMPStringDecoderTestCase(BaseTestCase):
diff --git a/tests/codec/ber/test_encoder.py b/tests/codec/ber/test_encoder.py
index df82e7b..3ba658a 100644
--- a/tests/codec/ber/test_encoder.py
+++ b/tests/codec/ber/test_encoder.py
@@ -5,12 +5,7 @@
# License: http://snmplabs.com/pyasn1/license.html
#
import sys
-
-try:
- import unittest2 as unittest
-
-except ImportError:
- import unittest
+import unittest
from tests.base import BaseTestCase
@@ -433,18 +428,17 @@ class RealEncoderWithSchemaTestCase(BaseTestCase):
) == ints2octs((9, 7, 3, 49, 50, 51, 69, 49, 49))
-if sys.version_info[0:2] > (2, 5):
- class UniversalStringEncoderTestCase(BaseTestCase):
- def testEncoding(self):
- assert encoder.encode(char.UniversalString(sys.version_info[0] >= 3 and 'abc' or unicode('abc'))) == ints2octs(
- (28, 12, 0, 0, 0, 97, 0, 0, 0, 98, 0, 0, 0, 99)), 'Incorrect encoding'
+class UniversalStringEncoderTestCase(BaseTestCase):
+ def testEncoding(self):
+ assert encoder.encode(char.UniversalString(sys.version_info[0] >= 3 and 'abc' or unicode('abc'))) == ints2octs(
+ (28, 12, 0, 0, 0, 97, 0, 0, 0, 98, 0, 0, 0, 99)), 'Incorrect encoding'
- class UniversalStringEncoderWithSchemaTestCase(BaseTestCase):
- def testEncoding(self):
- assert encoder.encode(
- sys.version_info[0] >= 3 and 'abc' or unicode('abc'), asn1Spec=char.UniversalString()
- ) == ints2octs((28, 12, 0, 0, 0, 97, 0, 0, 0, 98, 0, 0, 0, 99)), 'Incorrect encoding'
+class UniversalStringEncoderWithSchemaTestCase(BaseTestCase):
+ def testEncoding(self):
+ assert encoder.encode(
+ sys.version_info[0] >= 3 and 'abc' or unicode('abc'), asn1Spec=char.UniversalString()
+ ) == ints2octs((28, 12, 0, 0, 0, 97, 0, 0, 0, 98, 0, 0, 0, 99)), 'Incorrect encoding'
class BMPStringEncoderTestCase(BaseTestCase):
diff --git a/tests/codec/cer/__main__.py b/tests/codec/cer/__main__.py
index e3643a1..787d9d6 100644
--- a/tests/codec/cer/__main__.py
+++ b/tests/codec/cer/__main__.py
@@ -4,11 +4,7 @@
# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
# License: http://snmplabs.com/pyasn1/license.html
#
-try:
- import unittest2 as unittest
-
-except ImportError:
- import unittest
+import unittest
suite = unittest.TestLoader().loadTestsFromNames(
['tests.codec.cer.test_encoder.suite',
diff --git a/tests/codec/cer/test_decoder.py b/tests/codec/cer/test_decoder.py
index bb5ce93..47a13eb 100644
--- a/tests/codec/cer/test_decoder.py
+++ b/tests/codec/cer/test_decoder.py
@@ -5,11 +5,7 @@
# License: http://snmplabs.com/pyasn1/license.html
#
import sys
-
-try:
- import unittest2 as unittest
-except ImportError:
- import unittest
+import unittest
from tests.base import BaseTestCase
diff --git a/tests/codec/cer/test_encoder.py b/tests/codec/cer/test_encoder.py
index e155571..9e003a7 100644
--- a/tests/codec/cer/test_encoder.py
+++ b/tests/codec/cer/test_encoder.py
@@ -5,11 +5,7 @@
# License: http://snmplabs.com/pyasn1/license.html
#
import sys
-
-try:
- import unittest2 as unittest
-except ImportError:
- import unittest
+import unittest
from tests.base import BaseTestCase
diff --git a/tests/codec/der/__main__.py b/tests/codec/der/__main__.py
index bfa4ee0..8099af2 100644
--- a/tests/codec/der/__main__.py
+++ b/tests/codec/der/__main__.py
@@ -4,11 +4,7 @@
# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
# License: http://snmplabs.com/pyasn1/license.html
#
-try:
- import unittest2 as unittest
-
-except ImportError:
- import unittest
+import unittest
suite = unittest.TestLoader().loadTestsFromNames(
['tests.codec.der.test_encoder.suite',
diff --git a/tests/codec/der/test_decoder.py b/tests/codec/der/test_decoder.py
index 51ce296..e5b2663 100644
--- a/tests/codec/der/test_decoder.py
+++ b/tests/codec/der/test_decoder.py
@@ -5,12 +5,7 @@
# License: http://snmplabs.com/pyasn1/license.html
#
import sys
-
-try:
- import unittest2 as unittest
-
-except ImportError:
- import unittest
+import unittest
from tests.base import BaseTestCase
diff --git a/tests/codec/der/test_encoder.py b/tests/codec/der/test_encoder.py
index 912e32c..6b8417b 100644
--- a/tests/codec/der/test_encoder.py
+++ b/tests/codec/der/test_encoder.py
@@ -5,12 +5,7 @@
# License: http://snmplabs.com/pyasn1/license.html
#
import sys
-
-try:
- import unittest2 as unittest
-
-except ImportError:
- import unittest
+import unittest
from tests.base import BaseTestCase
diff --git a/tests/codec/native/__main__.py b/tests/codec/native/__main__.py
index 640f586..01308d8 100644
--- a/tests/codec/native/__main__.py
+++ b/tests/codec/native/__main__.py
@@ -4,11 +4,7 @@
# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
# License: http://snmplabs.com/pyasn1/license.html
#
-try:
- import unittest2 as unittest
-
-except ImportError:
- import unittest
+import unittest
suite = unittest.TestLoader().loadTestsFromNames(
['tests.codec.native.test_encoder.suite',
diff --git a/tests/codec/native/test_decoder.py b/tests/codec/native/test_decoder.py
index 654e2cc..948e7e8 100644
--- a/tests/codec/native/test_decoder.py
+++ b/tests/codec/native/test_decoder.py
@@ -5,12 +5,7 @@
# License: http://snmplabs.com/pyasn1/license.html
#
import sys
-
-try:
- import unittest2 as unittest
-
-except ImportError:
- import unittest
+import unittest
from tests.base import BaseTestCase
diff --git a/tests/codec/native/test_encoder.py b/tests/codec/native/test_encoder.py
index 25c9979..d0f6587 100644
--- a/tests/codec/native/test_encoder.py
+++ b/tests/codec/native/test_encoder.py
@@ -5,12 +5,7 @@
# License: http://snmplabs.com/pyasn1/license.html
#
import sys
-
-try:
- import unittest2 as unittest
-
-except ImportError:
- import unittest
+import unittest
from tests.base import BaseTestCase
diff --git a/tests/compat/__main__.py b/tests/compat/__main__.py
index 296d70c..53a3579 100644
--- a/tests/compat/__main__.py
+++ b/tests/compat/__main__.py
@@ -4,15 +4,10 @@
# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
# License: http://snmplabs.com/pyasn1/license.html
#
-try:
- import unittest2 as unittest
-
-except ImportError:
- import unittest
+import unittest
suite = unittest.TestLoader().loadTestsFromNames(
- ['tests.compat.test_binary.suite',
- 'tests.compat.test_integer.suite',
+ ['tests.compat.test_integer.suite',
'tests.compat.test_octets.suite']
)
diff --git a/tests/compat/test_binary.py b/tests/compat/test_binary.py
deleted file mode 100644
index 3e0949f..0000000
--- a/tests/compat/test_binary.py
+++ /dev/null
@@ -1,56 +0,0 @@
-#
-# This file is part of pyasn1 software.
-#
-# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
-# License: http://snmplabs.com/pyasn1/license.html
-#
-import sys
-
-try:
- import unittest2 as unittest
-except ImportError:
- import unittest
-
-from tests.base import BaseTestCase
-
-from pyasn1.compat import binary
-
-
-class BinaryTestCase(BaseTestCase):
-
- def test_bin_zero(self):
- assert '0b0' == binary.bin(0)
-
-
- def test_bin_noarg(self):
- try:
- binary.bin()
-
- except TypeError:
- pass
-
- except:
- assert 0, 'bin() tolerates no arguments'
-
-
- def test_bin_allones(self):
- assert '0b1111111111111111111111111111111111111111111111111111111111111111' == binary.bin(0xffffffffffffffff)
-
-
- def test_bin_allzeros(self):
- assert '0b0' == binary.bin(0x0000000)
-
-
-
- def test_bin_pos(self):
- assert '0b1000000010000000100000001' == binary.bin(0x01010101)
-
-
- def test_bin_neg(self):
- assert '-0b1000000010000000100000001' == binary.bin(-0x01010101)
-
-
-suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
-
-if __name__ == '__main__':
- unittest.TextTestRunner(verbosity=2).run(suite)
diff --git a/tests/compat/test_integer.py b/tests/compat/test_integer.py
index 04fd86a..716256c 100644
--- a/tests/compat/test_integer.py
+++ b/tests/compat/test_integer.py
@@ -5,11 +5,7 @@
# License: http://snmplabs.com/pyasn1/license.html
#
import sys
-
-try:
- import unittest2 as unittest
-except ImportError:
- import unittest
+import unittest
from tests.base import BaseTestCase
diff --git a/tests/compat/test_octets.py b/tests/compat/test_octets.py
index 5a9bc7c..d2b8021 100644
--- a/tests/compat/test_octets.py
+++ b/tests/compat/test_octets.py
@@ -5,11 +5,7 @@
# License: http://snmplabs.com/pyasn1/license.html
#
import sys
-
-try:
- import unittest2 as unittest
-except ImportError:
- import unittest
+import unittest
from tests.base import BaseTestCase
diff --git a/tests/test_debug.py b/tests/test_debug.py
index 9e33f93..1cd4c05 100644
--- a/tests/test_debug.py
+++ b/tests/test_debug.py
@@ -5,12 +5,7 @@
# License: http://snmplabs.com/pyasn1/license.html
#
import sys
-
-try:
- import unittest2 as unittest
-
-except ImportError:
- import unittest
+import unittest
from tests.base import BaseTestCase
diff --git a/tests/type/__main__.py b/tests/type/__main__.py
index fcc66e7..d6f44e6 100644
--- a/tests/type/__main__.py
+++ b/tests/type/__main__.py
@@ -4,11 +4,7 @@
# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
# License: http://snmplabs.com/pyasn1/license.html
#
-try:
- import unittest2 as unittest
-
-except ImportError:
- import unittest
+import unittest
suite = unittest.TestLoader().loadTestsFromNames(
['tests.type.test_constraint.suite',
diff --git a/tests/type/test_char.py b/tests/type/test_char.py
index 8540a3e..e2fac73 100644
--- a/tests/type/test_char.py
+++ b/tests/type/test_char.py
@@ -6,12 +6,7 @@
#
import pickle
import sys
-
-try:
- import unittest2 as unittest
-
-except ImportError:
- import unittest
+import unittest
from tests.base import BaseTestCase
@@ -111,9 +106,8 @@ class AbstractStringTestCase(object):
assert self.pythonString in self.asn1String
assert self.pythonString + self.pythonString not in self.asn1String
- if sys.version_info[:2] > (2, 4):
- def testReverse(self):
- assert list(reversed(self.asn1String)) == list(reversed(self.pythonString))
+ def testReverse(self):
+ assert list(reversed(self.asn1String)) == list(reversed(self.pythonString))
def testSchemaPickling(self):
old_asn1 = self.asn1Type()
diff --git a/tests/type/test_constraint.py b/tests/type/test_constraint.py
index 7ef6293..8a88731 100644
--- a/tests/type/test_constraint.py
+++ b/tests/type/test_constraint.py
@@ -5,12 +5,7 @@
# License: http://snmplabs.com/pyasn1/license.html
#
import sys
-
-try:
- import unittest2 as unittest
-
-except ImportError:
- import unittest
+import unittest
from tests.base import BaseTestCase
diff --git a/tests/type/test_namedtype.py b/tests/type/test_namedtype.py
index 7cff45e..e2ab60b 100644
--- a/tests/type/test_namedtype.py
+++ b/tests/type/test_namedtype.py
@@ -5,12 +5,7 @@
# License: http://snmplabs.com/pyasn1/license.html
#
import sys
-
-try:
- import unittest2 as unittest
-
-except ImportError:
- import unittest
+import unittest
from tests.base import BaseTestCase
diff --git a/tests/type/test_namedval.py b/tests/type/test_namedval.py
index 4ac08cf..eae6b4d 100644
--- a/tests/type/test_namedval.py
+++ b/tests/type/test_namedval.py
@@ -5,12 +5,7 @@
# License: http://snmplabs.com/pyasn1/license.html
#
import sys
-
-try:
- import unittest2 as unittest
-
-except ImportError:
- import unittest
+import unittest
from tests.base import BaseTestCase
@@ -23,10 +18,10 @@ class NamedValuesCaseBase(BaseTestCase):
self.e = namedval.NamedValues(('off', 0), ('on', 1))
def testDict(self):
- assert set(self.e.items()) == set([('off', 0), ('on', 1)])
- assert set(self.e.keys()) == set(['off', 'on'])
- assert set(self.e) == set(['off', 'on'])
- assert set(self.e.values()) == set([0, 1])
+ assert set(self.e.items()) == {('off', 0), ('on', 1)}
+ assert set(self.e.keys()) == {'off', 'on'}
+ assert set(self.e) == {'off', 'on'}
+ assert set(self.e.values()) == {0, 1}
assert 'on' in self.e and 'off' in self.e and 'xxx' not in self.e
assert 0 in self.e and 1 in self.e and 2 not in self.e
diff --git a/tests/type/test_opentype.py b/tests/type/test_opentype.py
index ff6788f..a3efbf0 100644
--- a/tests/type/test_opentype.py
+++ b/tests/type/test_opentype.py
@@ -5,12 +5,7 @@
# License: http://snmplabs.com/pyasn1/license.html
#
import sys
-
-try:
- import unittest2 as unittest
-
-except ImportError:
- import unittest
+import unittest
from tests.base import BaseTestCase
diff --git a/tests/type/test_tag.py b/tests/type/test_tag.py
index e8dd7a3..7e8f694 100644
--- a/tests/type/test_tag.py
+++ b/tests/type/test_tag.py
@@ -5,12 +5,7 @@
# License: http://snmplabs.com/pyasn1/license.html
#
import sys
-
-try:
- import unittest2 as unittest
-
-except ImportError:
- import unittest
+import unittest
from tests.base import BaseTestCase
diff --git a/tests/type/test_univ.py b/tests/type/test_univ.py
index 124e5e9..7d2b098 100644
--- a/tests/type/test_univ.py
+++ b/tests/type/test_univ.py
@@ -7,12 +7,7 @@
import math
import pickle
import sys
-
-try:
- import unittest2 as unittest
-
-except ImportError:
- import unittest
+import unittest
from tests.base import BaseTestCase
@@ -278,9 +273,8 @@ class IntegerTestCase(BaseTestCase):
def testCeil(self):
assert math.ceil(univ.Integer(1)) == 1, '__ceil__() fails'
- if sys.version_info[0:2] > (2, 5):
- def testTrunc(self):
- assert math.trunc(univ.Integer(1)) == 1, '__trunc__() fails'
+ def testTrunc(self):
+ assert math.trunc(univ.Integer(1)) == 1, '__trunc__() fails'
def testPrettyIn(self):
assert univ.Integer('3') == 3, 'prettyIn() fails'
@@ -437,9 +431,8 @@ class BitStringTestCase(BaseTestCase):
assert self.b.clone("'A98A'H")[1] == 0
assert self.b.clone("'A98A'H")[2] == 1
- if sys.version_info[:2] > (2, 4):
- def testReverse(self):
- assert list(reversed(univ.BitString([0, 0, 1]))) == list(univ.BitString([1, 0, 0]))
+ def testReverse(self):
+ assert list(reversed(univ.BitString([0, 0, 1]))) == list(univ.BitString([1, 0, 0]))
def testAsOctets(self):
assert self.b.clone(hexValue='A98A').asOctets() == ints2octs((0xa9, 0x8a)), 'testAsOctets() fails'
@@ -539,9 +532,8 @@ class OctetStringWithUnicodeMixIn(object):
assert self.encodedPythonString in s
assert self.encodedPythonString * 2 not in s
- if sys.version_info[:2] > (2, 4):
- def testReverse(self):
- assert list(reversed(univ.OctetString(self.encodedPythonString))) == list(reversed(self.encodedPythonString))
+ def testReverse(self):
+ assert list(reversed(univ.OctetString(self.encodedPythonString))) == list(reversed(self.encodedPythonString))
class OctetStringWithAsciiTestCase(OctetStringWithUnicodeMixIn, BaseTestCase):
@@ -860,9 +852,8 @@ class RealTestCase(BaseTestCase):
def testCeil(self):
assert math.ceil(univ.Real(1.2)) == 2.0, '__ceil__() fails'
- if sys.version_info[0:2] > (2, 5):
- def testTrunc(self):
- assert math.trunc(univ.Real(1.1)) == 1.0, '__trunc__() fails'
+ def testTrunc(self):
+ assert math.trunc(univ.Real(1.1)) == 1.0, '__trunc__() fails'
def testTag(self):
assert univ.Real().tagSet == tag.TagSet(
diff --git a/tests/type/test_useful.py b/tests/type/test_useful.py
index 8a5ab30..5078232 100644
--- a/tests/type/test_useful.py
+++ b/tests/type/test_useful.py
@@ -8,12 +8,7 @@ import datetime
import pickle
import sys
from copy import deepcopy
-
-try:
- import unittest2 as unittest
-
-except ImportError:
- import unittest
+import unittest
from tests.base import BaseTestCase