Add Python3.8 support, fix import

Uses try/catch to still support 2.7 too
master
Chris Lenk 2020-01-04 13:50:06 -05:00
parent 2d3afb2a27
commit 6c0fba0e67
5 changed files with 22 additions and 9 deletions

View File

@ -8,6 +8,7 @@ python:
- "3.5" - "3.5"
- "3.6" - "3.6"
- "3.7" - "3.7"
- "3.8"
install: install:
- pip install -U pip setuptools - pip install -U pip setuptools
- pip install tox-travis pre-commit - pip install tox-travis pre-commit

View File

@ -46,6 +46,7 @@ setup(
'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
], ],
keywords='stix stix2 json cti cyber threat intelligence', keywords='stix stix2 json cti cyber threat intelligence',
packages=find_packages(exclude=['*.test', '*.test.*']), packages=find_packages(exclude=['*.test', '*.test.*']),

View File

@ -1,6 +1,5 @@
"""Base classes for type definitions in the STIX2 library.""" """Base classes for type definitions in the STIX2 library."""
import collections
import copy import copy
import datetime as dt import datetime as dt
import uuid import uuid
@ -20,6 +19,12 @@ from .utils import NOW, find_property_index, format_datetime, get_timestamp
from .utils import new_version as _new_version from .utils import new_version as _new_version
from .utils import revoke as _revoke from .utils import revoke as _revoke
try:
from collections.abc import Mapping
except ImportError:
from collections import Mapping
__all__ = ['STIXJSONEncoder', '_STIXBase'] __all__ = ['STIXJSONEncoder', '_STIXBase']
DEFAULT_ERROR = "{type} must have {property}='{expected}'." DEFAULT_ERROR = "{type} must have {property}='{expected}'."
@ -68,7 +73,7 @@ def get_required_properties(properties):
return (k for k, v in properties.items() if v.required) return (k for k, v in properties.items() if v.required)
class _STIXBase(collections.Mapping): class _STIXBase(Mapping):
"""Base class for STIX object types""" """Base class for STIX object types"""
def object_properties(self): def object_properties(self):

View File

@ -2,7 +2,6 @@
import base64 import base64
import binascii import binascii
import collections
import copy import copy
import inspect import inspect
import re import re
@ -20,6 +19,11 @@ from .exceptions import (
) )
from .utils import _get_dict, get_class_hierarchy_names, parse_into_datetime from .utils import _get_dict, get_class_hierarchy_names, parse_into_datetime
try:
from collections.abc import Mapping
except ImportError:
from collections import Mapping
ERROR_INVALID_ID = ( ERROR_INVALID_ID = (
"not a valid STIX identifier, must match <object-type>--<UUID>: {}" "not a valid STIX identifier, must match <object-type>--<UUID>: {}"
) )
@ -198,7 +202,7 @@ class ListProperty(Property):
else: else:
obj_type = self.contained obj_type = self.contained
if isinstance(valid, collections.Mapping): if isinstance(valid, Mapping):
try: try:
valid._allow_custom valid._allow_custom
except AttributeError: except AttributeError:

12
tox.ini
View File

@ -1,5 +1,5 @@
[tox] [tox]
envlist = py27,py34,py35,py36,py37,style,isort-check,packaging envlist = py27,py34,py35,py36,py37,py38,style,isort-check,packaging
[testenv] [testenv]
deps = deps =
@ -11,6 +11,7 @@ deps =
taxii2-client taxii2-client
fuzzywuzzy fuzzywuzzy
haversine haversine
python-Levenshtein
medallion medallion
commands = commands =
python -m pytest --cov=stix2 stix2/test/ --cov-report term-missing -W ignore::stix2.exceptions.STIXDeprecationWarning python -m pytest --cov=stix2 stix2/test/ --cov-report term-missing -W ignore::stix2.exceptions.STIXDeprecationWarning
@ -42,7 +43,8 @@ commands =
[travis] [travis]
python = python =
2.7: py27, style 2.7: py27, style
3.4: py34, style 3.4: py34
3.5: py35, style 3.5: py35
3.6: py36, style, packaging 3.6: py36
3.7: py37, style 3.7: py37
3.7: py38, style, packaging