Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ skip_glob = **/STIXPattern*.py
known_third_party =
antlr4,
pytest,
six,
typing,
known_first_party = stix2patterns
force_sort_within_sections = 1
Expand Down
4 changes: 2 additions & 2 deletions docs/developers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ repository. If the grammar changes, the code in this repository should be
updated to match. To do so, use the Java ANTLR package to generate new Python
source files. (The .jar file is not needed for normal use of the validator).

1. Download antlr-4.7.1-complete.jar from http://www.antlr.org/download/
1. Download antlr-4.7.1-complete.jar from http://www.antlr.org/
2. Clone the stix2-json-schemas repository or download the STIXPattern.g4 file.
3. Change to the directory containing the STIXPattern.g4 file.
4. Run the following command (for STIX v2.1)

.. prompt:: bash

java -jar "/path/to/antlr-4.7.1-complete.jar" -Dlanguage=Python2 STIXPattern.g4 -visitor -o /path/to/cti-pattern-validator/stix2patterns/v21/grammars
java -jar "/path/to/antlr-4.13.1-complete.jar" -Dlanguage=Python4 STIXPattern.g4 -visitor -o /path/to/cti-pattern-validator/stix2patterns/v21/grammars

5. Commit the resulting files to git.

Expand Down
7 changes: 1 addition & 6 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@ Installation
Requirements
------------

- `Python <https://www.python.org>`__ 2.7 or 3.4+
- `Python <https://www.python.org>`__ 3.7+
- ANTLR grammar runtime (4.7 or newer):

- `antlr4-python2-runtime <https://pypi.org/project/antlr4-python2-runtime>`__
(Python 2.7)
- `antlr4-python3-runtime <https://pypi.org/project/antlr4-python3-runtime>`__
(Python 3)

- `six <https://pypi.org/project/six>`__
- `typing <https://pypi.org/project/typing>`__ (Python 3.4)

Install Package
---------------

Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
python_requires=">=3.8",
packages=find_packages(),
install_requires=[
'antlr4-python3-runtime~=4.9.0',
'six',
'antlr4-python3-runtime~=4.13.0',
],
package_data={
'stix2patterns.test.v20': ['spec_examples.txt'],
Expand Down
5 changes: 1 addition & 4 deletions stix2patterns/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import six


def brackets_check(pattern):
"""
Check whether the pattern is missing square brackets, in a way which does
Expand All @@ -10,7 +7,7 @@ def brackets_check(pattern):
:param pattern: A STIX pattern string
:return: True if the pattern had its brackets; False if not
"""
if isinstance(pattern, six.string_types):
if isinstance(pattern, str):

# There can be an arbitrary number of open parens first... skip over
# those
Expand Down
417 changes: 184 additions & 233 deletions stix2patterns/v20/grammars/STIXPatternLexer.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions stix2patterns/v20/grammars/STIXPatternListener.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated from STIXPattern.g4 by ANTLR 4.9.2
# Generated from STIXPattern.g4 by ANTLR 4.13.1
from antlr4 import *
if __name__ is not None and "." in __name__:
if "." in __name__:
from .STIXPatternParser import STIXPatternParser
else:
from STIXPatternParser import STIXPatternParser
Expand Down
231 changes: 106 additions & 125 deletions stix2patterns/v20/grammars/STIXPatternParser.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions stix2patterns/v20/grammars/STIXPatternVisitor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated from STIXPattern.g4 by ANTLR 4.9.2
# Generated from STIXPattern.g4 by ANTLR 4.13.1
from antlr4 import *
if __name__ is not None and "." in __name__:
if "." in __name__:
from .STIXPatternParser import STIXPatternParser
else:
from STIXPatternParser import STIXPatternParser
Expand Down
7 changes: 1 addition & 6 deletions stix2patterns/v20/pattern.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import antlr4
import six

from ..exceptions import ParseException, ParserErrorListener
from .grammars.STIXPatternLexer import STIXPatternLexer
Expand Down Expand Up @@ -106,8 +105,4 @@ def __do_parse(self, pattern_str):
# invocation. Wish this could be cleaner...
parser._errHandler.reportError(parser, real_exc)

# should probably chain exceptions if we can...
# Should I report the cancellation or recognition exception as the
# cause...?
six.raise_from(ParseException(error_listener.error_message),
real_exc)
raise ParseException(error_listener.error_message) from real_exc
423 changes: 187 additions & 236 deletions stix2patterns/v21/grammars/STIXPatternLexer.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions stix2patterns/v21/grammars/STIXPatternListener.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated from STIXPattern.g4 by ANTLR 4.9.2
# Generated from STIXPattern.g4 by ANTLR 4.13.1
from antlr4 import *
if __name__ is not None and "." in __name__:
if "." in __name__:
from .STIXPatternParser import STIXPatternParser
else:
from STIXPatternParser import STIXPatternParser
Expand Down
231 changes: 106 additions & 125 deletions stix2patterns/v21/grammars/STIXPatternParser.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions stix2patterns/v21/grammars/STIXPatternVisitor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated from STIXPattern.g4 by ANTLR 4.9.2
# Generated from STIXPattern.g4 by ANTLR 4.13.1
from antlr4 import *
if __name__ is not None and "." in __name__:
if "." in __name__:
from .STIXPatternParser import STIXPatternParser
else:
from STIXPatternParser import STIXPatternParser
Expand Down
7 changes: 1 addition & 6 deletions stix2patterns/v21/pattern.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import antlr4
import six

from ..exceptions import ParseException, ParserErrorListener
from .grammars.STIXPatternLexer import STIXPatternLexer
Expand Down Expand Up @@ -106,8 +105,4 @@ def __do_parse(self, pattern_str):
# invocation. Wish this could be cleaner...
parser._errHandler.reportError(parser, real_exc)

# should probably chain exceptions if we can...
# Should I report the cancellation or recognition exception as the
# cause...?
six.raise_from(ParseException(error_listener.error_message),
real_exc)
raise ParseException(error_listener.error_message) from real_exc
5 changes: 2 additions & 3 deletions stix2patterns/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import argparse

from antlr4 import InputStream
import six

from . import DEFAULT_VERSION
from .exceptions import STIXPatternErrorListener # noqa: F401
Expand All @@ -21,7 +20,7 @@ def run_validator(pattern, stix_version=DEFAULT_VERSION):
Validates a pattern against the STIX Pattern grammar. Error messages are
returned in a list. The test passed if the returned list is empty.
"""
if isinstance(pattern, six.string_types):
if isinstance(pattern, str):
pattern_str = pattern
pattern = InputStream(pattern)

Expand Down Expand Up @@ -88,7 +87,7 @@ def main():
if args.file:
nextpattern = args.file.readline
else:
nextpattern = functools.partial(six.moves.input, "Enter a pattern to validate: ")
nextpattern = functools.partial(input, "Enter a pattern to validate: ")

try:
while True:
Expand Down