diff options
author | Ilya Etingof <etingof@gmail.com> | 2019-11-23 09:57:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-23 09:57:24 +0100 |
commit | 2b646e07d5d83f0892fa2a809ae4c981430cb12c (patch) | |
tree | 20b10450bced84c425ca0735b4ee7202e68ee1ec | |
parent | 788af3c44edc2ebd079eda3f7a4ae2f9931446fd (diff) | |
parent | f10434e31f9293c4e739ac6c5d1519f407bd1540 (diff) | |
download | pyasn1-git-2b646e07d5d83f0892fa2a809ae4c981430cb12c.tar.gz |
Merge branch 'master' into streamoptimum37
46 files changed, 128 insertions, 515 deletions
diff --git a/.travis.yml b/.travis.yml index cb495de..6d7d566 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,53 +2,25 @@ language: python cache: pip 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 - python: '3.5' - - os: linux - dist: trusty - python: '3.6' - - os: linux - dist: xenial - sudo: true - python: '3.7' - - os: linux - dist: trusty - python: 'nightly' - - os: linux - dist: trusty - python: 'pypy' - - os: linux - dist: trusty - python: 'pypy3' + - python: '2.7' + - python: '3.5' + - python: '3.6' + - python: '3.7' + - python: '3.8' + - python: 'nightly' + - python: 'pypy' + - python: 'pypy3' install: - pip install codecov - pip install -r requirements.txt -r devel-requirements.txt - pip install -e . script: - PYTHONPATH=.:$PYTHONPATH python tests/__main__.py - - if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then (make -C docs html); fi - if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then (make -C docs html); fi - - if [[ $TRAVIS_PYTHON_VERSION == '3.3' ]]; then (make -C docs html); fi - - if [[ $TRAVIS_PYTHON_VERSION == '3.4' ]]; then (make -C docs html); fi - if [[ $TRAVIS_PYTHON_VERSION == '3.5' ]]; then (make -C docs html); fi - if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then (make -C docs html); fi - if [[ $TRAVIS_PYTHON_VERSION == '3.7' ]]; then (make -C docs html); fi + - if [[ $TRAVIS_PYTHON_VERSION == '3.8' ]]; then (make -C docs html); fi - if [[ $TRAVIS_PYTHON_VERSION == 'nightly' ]]; then (make -C docs html); fi after_success: - PYTHONPATH=.:$PYTHONPATH coverage run --omit=*test* tests/__main__.py diff --git a/CHANGES.rst b/CHANGES.rst index a4f91b8..f992889 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,7 @@ Revision 0.5.0, released XX-09-2019 - Refactor BER/CER/DER decoder into a coroutine. - The goal of this change is to make the decoder stopping on input + The goal of this change is to make the decoder yielding on input data starvation and resuming from where it stopped whenever the caller decides to try again (hopefully making sure that some more input becomes available). @@ -22,7 +22,13 @@ Revision 0.5.0, released XX-09-2019 `StreamingDecoder` class. Previously published API is implemented as a thin wrapper on top of that ensuring backward compatibility. -Revision 0.4.8, released XX-09-2019 +Revision 0.4.9, released XX-11-2019 +----------------------------------- + +- Added support for Python 3.8. +- Removed support for EOL Pythons 2.4, 2.5, 2.6, 3.2, 3.3 and 3.4. + +Revision 0.4.8, released 16-11-2019 ----------------------------------- - Added ability of combining `SingleValueConstraint` and @@ -20,7 +20,7 @@ Features * Standards compliant BER/CER/DER codecs * Can operate on streams of serialized data * 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.5+ * 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 5a56a70..c67f662 100644 --- a/pyasn1/__init__.py +++ b/pyasn1/__init__.py @@ -1,7 +1,7 @@ import sys # https://www.python.org/dev/peps/pep-0396/ -__version__ = '0.4.8' +__version__ = '0.4.9' -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 7c5edc9..6b8ca6d 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 @@ -242,8 +238,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..968d04f 100644 --- a/pyasn1/compat/integer.py +++ b/pyasn1/compat/integer.py @@ -5,23 +5,16 @@ # 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': +if sys.version_info[0] < 3 or implementation != 'CPython': from binascii import a2b_hex, b2a_hex - if sys.version_info[0] > 2: - long = int - def from_bytes(octets, signed=False): if not octets: return 0 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) @@ -7,6 +7,7 @@ # import os import sys +import unittest classifiers = """\ Development Status :: 5 - Production/Stable @@ -20,17 +21,12 @@ 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 Programming Language :: Python :: 3.7 +Programming Language :: Python :: 3.8 Topic :: Communications Topic :: Software Development :: Libraries :: Python Modules """ @@ -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.*, !=3.4.*'}) 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 9c2fc94..ec81462 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.test_streaming.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 17483db..4e2a984 100644 --- a/tests/codec/ber/test_decoder.py +++ b/tests/codec/ber/test_decoder.py @@ -9,12 +9,8 @@ import io import os import sys import tempfile +import unittest import zipfile -try: - import unittest2 as unittest - -except ImportError: - import unittest from tests.base import BaseTestCase @@ -488,10 +484,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 b880285..49eb91d 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 d628061..ea435e1 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 ce26387..4535927 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..04923bb 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 @@ -148,21 +143,11 @@ class NoValueTestCase(BaseTestCase): def testSizeOf(self): try: - if hasattr(sys, 'getsizeof'): - sys.getsizeof(univ.noValue) - - # TODO: remove when Py2.5 support is gone - elif sys.version_info > (2, 6): - raise unittest.SkipTest("no sys.getsizeof() method") + sys.getsizeof(univ.noValue) except PyAsn1Error: assert False, 'sizeof failed for NoValue object' - except TypeError: - # TODO: remove when Py2.5 support is gone - if sys.version_info > (2, 6): - raise unittest.SkipTest("sys.getsizeof() raises TypeError") - class IntegerTestCase(BaseTestCase): def testStr(self): @@ -278,9 +263,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 +421,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 +522,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): @@ -565,11 +547,6 @@ class OctetStringUnicodeErrorTestCase(BaseTestCase): except PyAsn1UnicodeEncodeError: pass - # TODO: remove when Py2.5 support is gone - else: - if sys.version_info > (2, 6): - assert False, 'Unicode encoding error not caught' - def testDecodeError(self): serialized = ints2octs((0xff, 0xfe)) @@ -585,11 +562,6 @@ class OctetStringUnicodeErrorTestCase(BaseTestCase): except PyAsn1UnicodeDecodeError: pass - # TODO: remove when Py2.5 support is gone - else: - if sys.version_info > (2, 6): - assert False, 'Unicode decoding error not caught' - class OctetStringWithUtf8TestCase(OctetStringWithUnicodeMixIn, BaseTestCase): initializer = (208, 176, 208, 177, 208, 178) @@ -860,9 +832,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 |