Skip to content

Commit a6235aa

Browse files
committed
Drop Python 2. Modernize notices. Format code
Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent b3b3845 commit a6235aa

File tree

6 files changed

+41
-53
lines changed

6 files changed

+41
-53
lines changed

NOTICE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# Copyright (c) nexB Inc. and others.
33
# SPDX-License-Identifier: Apache-2.0
44
#
5-
# Visit https://aboutcode.org and https://github.com/nexB/license-expression for support and download.
5+
# Visit https://aboutcode.org and https://github.com/nexB/license-expression
6+
# for support and download.
67
#
78
# Licensed under the Apache License, Version 2.0 (the "License");
89
# you may not use this file except in compliance with the License.

README.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
license-expression
33
==================
44

5-
license-expression is a small utility library to parse, compare, simplify and normalize
6-
license expressions (e.g. SPDX license expressions) using boolean logic such as:
7-
`GPL-2.0 or later WITH Classpath Exception AND MIT`.
5+
license-expression is a comprehensive utility library to parse, compare,
6+
simplify and normalize license expressions (such as SPDX license expressions)
7+
using boolean logic like in: `GPL-2.0 or later WITH Classpath Exception AND MIT`.
88

99
See also for details:
1010
https://spdx.org/sites/cpstandard/files/pages/files/spdxversion2.1.pdf#page=95&zoom=auto
@@ -135,6 +135,7 @@ Development
135135
===========
136136

137137
* Checkout a clone from https://github.com/nexB/license-expression.git
138-
* Then run ``./configure`` (or ``configure.bat``) and then ``source bin/activate``. This will
139-
install all vendored dependencies in a local virtualenv, including development deps.
138+
* Then run ``./configure`` (or ``configure.bat``) and then ``source bin/activate``.
139+
This will install all vendored dependencies in a local virtualenv, including
140+
development deps.
140141
* To run the tests, run ``py.test -vvs``

src/license_expression/__init__.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
11
#
2-
# license-expression is a free software tool from nexB Inc. and others.
3-
# Visit https://github.com/nexB/license-expression for support and download.
4-
#
52
# Copyright (c) nexB Inc. and others. All rights reserved.
6-
# http://nexb.com and http://aboutcode.org
7-
#
8-
# This software is licensed under the Apache License version 2.0.
3+
# SPDX-License-Identifier: Apache-2.0
4+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
5+
# See https://github.com/nexB/license-expression for support or download.
6+
# See https://aboutcode.org for more information about nexB OSS projects.
97
#
10-
# You may not use this software except in compliance with the License.
11-
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
12-
# Unless required by applicable law or agreed to in writing, software distributed
13-
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14-
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
15-
# specific language governing permissions and limitations under the License.
16-
178
"""
189
This module defines a mini language to parse, validate, simplify, normalize and
1910
compare license expressions using a boolean logic engine.
@@ -27,15 +18,15 @@
2718
The main entry point is the Licensing object.
2819
"""
2920

21+
import itertools
22+
import re
23+
import string
3024
from collections import defaultdict
3125
from collections import deque
3226
from collections import namedtuple
3327
from copy import copy
3428
from copy import deepcopy
3529
from functools import total_ordering
36-
import itertools
37-
import re
38-
import string
3930

4031
import boolean
4132
from boolean import Expression as LicenseExpression

src/license_expression/_pyahocorasick.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,29 @@
11
# -*- coding: utf-8 -*-
2+
#
3+
# SPDX-License-Identifier: LicenseRef-scancode-public-domain
4+
# See https://github.com/nexB/license-expression for support or download.
5+
# See https://aboutcode.org for more information about nexB OSS projects.
6+
#
27
"""
3-
Aho-Corasick string search algorithm.
8+
Aho-Corasick string search algorithm in pure Python
49
510
Original Author: Wojciech Muła, [email protected]
611
WWW : http://0x80.pl
712
License : public domain
813
9-
Modified for use in the license_expression library:
14+
This is the pure Python Aho-Corasick automaton from pyahocorasick modified for
15+
use in the license_expression library for advanced tokenization:
16+
1017
- add support for unicode strings.
1118
- case insensitive search using sequence of words and not characters
1219
- improve returned results with the actual start,end and matched string.
1320
- support returning non-matched parts of a string
1421
"""
15-
16-
from __future__ import absolute_import
17-
from __future__ import print_function
18-
from __future__ import unicode_literals
19-
2022
from collections import deque
2123
from collections import OrderedDict
2224
import logging
2325
import re
2426

25-
# Python 2 and 3 support
26-
try:
27-
# Python 2
28-
unicode
29-
str = unicode # NOQA
30-
except NameError:
31-
# Python 3
32-
unicode = str # NOQA
33-
3427
TRACE = False
3528

3629
logger = logging.getLogger(__name__)
@@ -109,7 +102,7 @@ def add(self, tokens_string, value=None):
109102
provided value, typically a Token object. If a value is not provided,
110103
the tokens_string is used as value.
111104
112-
A tokens_string is any unicode string. It will be tokenized when added
105+
A tokens_string is any string. It will be tokenized when added
113106
to the Trie.
114107
"""
115108
if self._converted:
@@ -326,7 +319,12 @@ def iter(self, tokens_string, include_unmatched=False, include_space=False):
326319
if include_unmatched:
327320
n = len(token_string)
328321
start_pos = end_pos - n + 1
329-
tok = Token(start_pos, end_pos, tokens_string[start_pos: end_pos + 1], None)
322+
tok = Token(
323+
start=start_pos,
324+
end=end_pos,
325+
string=tokens_string[start_pos: end_pos + 1],
326+
value=None
327+
)
330328
if TRACE:
331329
logger_debug(' unmatched tok:', tok)
332330
yield tok

tests/test__pyahocorasick.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# -*- coding: utf-8 -*-
2+
#
3+
# SPDX-License-Identifier: LicenseRef-scancode-public-domain
4+
# See https://github.com/nexB/license-expression for support or download.
5+
# See https://aboutcode.org for more information about nexB OSS projects.
26

37
"""
48
Tests for Aho-Corasick string search algorithm.

tests/test_license_expression.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
1-
# license-expression is a free software tool from nexB Inc. and others.
2-
# Visit https://github.com/nexB/license-expression for support and download.
31
#
4-
# Copyright (c) nexB Inc. and others. All rights reserved.
5-
# http://nexb.com and http://aboutcode.org
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# SPDX-License-Identifier: Apache-2.0
4+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
5+
# See https://github.com/nexB/license-expression for support or download.
6+
# See https://aboutcode.org for more information about nexB OSS projects.
67
#
7-
# This software is licensed under the Apache License version 2.0.
8-
#
9-
# You may not use this software except in compliance with the License.
10-
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
11-
# Unless required by applicable law or agreed to in writing, software distributed
12-
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
13-
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
14-
# specific language governing permissions and limitations under the License.
158

9+
import sys
1610
from collections import namedtuple
1711
from unittest import TestCase
1812
from unittest.case import expectedFailure
19-
import sys
2013

2114
from boolean.boolean import PARSE_UNBALANCED_CLOSING_PARENS
2215
from boolean.boolean import PARSE_INVALID_SYMBOL_SEQUENCE

0 commit comments

Comments
 (0)