|
37 | 37 |
|
38 | 38 | from license_expression import Licensing
|
39 | 39 | from packageurl import PackageURL
|
40 |
| - |
41 |
| -from attributecode import __version__ |
42 |
| -from attributecode import CRITICAL |
43 |
| -from attributecode import ERROR |
44 |
| -from attributecode import INFO |
45 |
| -from attributecode import WARNING |
46 |
| -from attributecode import api |
47 |
| -from attributecode import Error |
48 |
| -from attributecode import saneyaml |
49 |
| -from attributecode import gen |
50 |
| -from attributecode import util |
51 |
| -from attributecode.transform import write_excel |
52 |
| -from attributecode.util import add_unc |
53 |
| -from attributecode.util import boolean_fields |
54 |
| -from attributecode.util import copy_license_notice_files |
55 |
| -from attributecode.util import copy_file |
56 |
| -from attributecode.util import csv |
57 |
| -from attributecode.util import file_fields |
58 |
| -from attributecode.util import filter_errors |
59 |
| -from attributecode.util import get_spdx_key_and_lic_key_from_licdb |
60 |
| -from attributecode.util import is_valid_name |
61 |
| -from attributecode.util import on_windows |
62 |
| -from attributecode.util import norm |
63 |
| -from attributecode.util import replace_tab_with_spaces |
64 |
| -from attributecode.util import wrap_boolean_value |
65 |
| -from attributecode.util import UNC_PREFIX |
66 |
| -from attributecode.util import ungroup_licenses |
67 |
| -from attributecode.util import ungroup_licenses_from_sctk |
| 40 | +from attributecode.util import ( |
| 41 | + add_unc, |
| 42 | + boolean_fields, |
| 43 | + copy_license_notice_files, |
| 44 | + copy_file, |
| 45 | + csv, |
| 46 | + file_fields, |
| 47 | + filter_errors, |
| 48 | + get_spdx_key_and_lic_key_from_licdb, |
| 49 | + is_valid_name, |
| 50 | + on_windows, |
| 51 | + norm, |
| 52 | + replace_tab_with_spaces, |
| 53 | + wrap_boolean_value, |
| 54 | + UNC_PREFIX, |
| 55 | + ungroup_licenses, |
| 56 | + ungroup_licenses_from_sctk, |
| 57 | + parse_license_expression, |
| 58 | + detect_special_char, |
| 59 | +) |
68 | 60 |
|
69 | 61 | genereated_tk_version = "# Generated with AboutCode Toolkit Version %s \n\n" % __version__
|
70 | 62 |
|
@@ -234,9 +226,10 @@ class StringField(Field):
|
234 | 226 | """
|
235 | 227 |
|
236 | 228 | def _validate(self, *args, **kwargs):
|
237 |
| - errors = super(StringField, self)._validate(*args, ** kwargs) |
| 229 | + errors = super(StringField, self)._validate(*args, **kwargs) |
| 230 | + |
238 | 231 | no_special_char_field = [
|
239 |
| - 'license_expression', 'license_key', 'license_name', 'declared_license_expression', 'other_license_expression '] |
| 232 | + 'license_expression', 'license_key', 'license_name', 'declared_license_expression', 'other_license_expression'] |
240 | 233 | name = self.name
|
241 | 234 | if name in no_special_char_field:
|
242 | 235 | val = self.value
|
@@ -2145,40 +2138,3 @@ def convert_spdx_expression_to_lic_expression(spdx_key, spdx_lic_dict):
|
2145 | 2138 | return value
|
2146 | 2139 |
|
2147 | 2140 |
|
2148 |
| -def parse_license_expression(lic_expression): |
2149 |
| - licensing = Licensing() |
2150 |
| - lic_list = [] |
2151 |
| - invalid_lic_exp = '' |
2152 |
| - special_char = detect_special_char(lic_expression) |
2153 |
| - if not special_char: |
2154 |
| - # Parse the license expression and save it into a list |
2155 |
| - try: |
2156 |
| - lic_list = licensing.license_keys(lic_expression) |
2157 |
| - except: |
2158 |
| - invalid_lic_exp = lic_expression |
2159 |
| - return special_char, lic_list, invalid_lic_exp |
2160 |
| - |
2161 |
| - |
2162 |
| -def detect_special_char(expression): |
2163 |
| - not_support_char = [ |
2164 |
| - '!', '@', '#', '$', '^', '&', '*', '=', '{', '}', |
2165 |
| - '|', '[', ']', '\\', ':', ';', '<', '>', '?', ',', '/'] |
2166 |
| - special_character = [] |
2167 |
| - for char in not_support_char: |
2168 |
| - if char in expression: |
2169 |
| - special_character.append(char) |
2170 |
| - return special_character |
2171 |
| - |
2172 |
| - |
2173 |
| -def valid_api_url(api_url): |
2174 |
| - try: |
2175 |
| - response = get(api_url) |
2176 |
| - # The 403 error code is expected if the api_url is pointing to DJE as no |
2177 |
| - # API key is provided. The 200 status code represent connection success |
2178 |
| - # to scancode's LicenseDB. All other exception yield to invalid api_url |
2179 |
| - if response.status_code == 403 or response.status_code == 200: |
2180 |
| - return True |
2181 |
| - else: |
2182 |
| - return False |
2183 |
| - except: |
2184 |
| - return False |
0 commit comments