Skip to content

Commit 1ae604f

Browse files
committed
pylint
1 parent 53c3868 commit 1ae604f

File tree

1 file changed

+37
-84
lines changed

1 file changed

+37
-84
lines changed

tests/software.py

+37-84
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def get_rating_from_sitespeed(url, local_translation, global_translation):
126126
result = convert_item_to_domain_data(data)
127127

128128
texts = ''
129-
texts = sum_overall_software_used(local_translation, global_translation, result)
129+
texts = sum_overall_software_used(local_translation, result)
130130

131131
rating += rate_software_security_result(local_translation, global_translation, result)
132132

@@ -441,7 +441,7 @@ def rate_software_cve(issue_type, result, local_translation, global_translation)
441441
rating += cve_ratings
442442
return rating
443443

444-
def sum_overall_software_used(local_translation, global_translation, result):
444+
def sum_overall_software_used(local_translation, result):
445445
texts = []
446446

447447
categories = ['cms', 'webserver', 'os',
@@ -574,10 +574,8 @@ def enrich_data(data, orginal_domain, result_folder_name, rules):
574574
for item in data:
575575
enrich_versions(softwares, item)
576576

577-
enrich_data_from_javascript(tmp_list, item, rules)
578-
enrich_data_from_videos(tmp_list, item, result_folder_name)
577+
enrich_data_from_javascript(item, rules)
579578
enrich_data_from_images(tmp_list, item, result_folder_name)
580-
enrich_data_from_documents(tmp_list, item, result_folder_name)
581579

582580
if len(testing) > 0:
583581
raw_data['test'][orginal_domain] = {
@@ -663,36 +661,6 @@ def add_known_software_source(name, source_type, match, url):
663661
with open(file_path, 'w', encoding='utf-8', newline='') as file:
664662
file.write(data)
665663

666-
def add_wordpressplugin_software_source(name, version, url):
667-
base_directory = Path(os.path.dirname(
668-
os.path.realpath(__file__)) + os.path.sep).parent
669-
670-
file_path = (
671-
f'{base_directory}{os.path.sep}data{os.path.sep}'
672-
'software-wordpressplugin-sources.json')
673-
if not os.path.isfile(file_path):
674-
file_path = f'{base_directory}{os.path.sep}software-wordpressplugin-sources.json'
675-
if not os.path.isfile(file_path):
676-
print("Info: No software-wordpressplugin-sources.json file found!")
677-
678-
collection = {}
679-
try:
680-
with open(file_path, encoding='utf-8') as json_file:
681-
collection = json.load(json_file)
682-
except:
683-
print('INFO: There was no ', file_path, 'file.')
684-
685-
if 'softwares' not in collection:
686-
collection['softwares'] = {}
687-
688-
if name not in collection['softwares']:
689-
collection['softwares'][name] = {}
690-
691-
data = json.dumps(collection, indent=4)
692-
with open(file_path, 'w', encoding='utf-8', newline='') as file:
693-
file.write(data)
694-
695-
696664
def add_unknown_software_source(name, version, url):
697665
base_directory = Path(os.path.dirname(
698666
os.path.realpath(__file__)) + os.path.sep).parent
@@ -715,7 +683,7 @@ def add_unknown_software_source(name, version, url):
715683
'versions': {},
716684
}
717685

718-
if version == None or version == '':
686+
if version in (None, ''):
719687
version = 'unknown'
720688

721689
if version not in collection[name]['versions']:
@@ -789,13 +757,13 @@ def enrich_versions(collection, item):
789757
current_year = datetime.now().year
790758
for year in range(10, 2, -1):
791759
if last_pushed_year < (current_year - year):
792-
match['issues'].append('UNMAINTAINED_SOURCE_{0}_YEARS'.format(year))
760+
match['issues'].append(f'UNMAINTAINED_SOURCE_{year}_YEARS')
793761
break
794762

795763
if 'tech' in software_info:
796764
match['tech'] = software_info['tech']
797765

798-
if match['version'] == None:
766+
if match['version'] is None:
799767
continue
800768

801769
version = None
@@ -827,7 +795,7 @@ def enrich_versions(collection, item):
827795
if tmp_version == version:
828796
match['issues'].extend(software_info['versions'][current_version])
829797
break
830-
elif tmp_version > version:
798+
if tmp_version > version:
831799
# NOTE: handle versions that doesn't match but we know is less or
832800
# greater then versions we know.
833801
# For example if: software_info['versions'] = [4.0, 3.0, 2.0, 1.0].
@@ -858,7 +826,7 @@ def enrich_versions(collection, item):
858826
else:
859827
match['issues'].append('BEHIND001')
860828

861-
def enrich_data_from_javascript(tmp_list, item, rules):
829+
def enrich_data_from_javascript(item, rules):
862830
if USE_STEALTH:
863831
return
864832
for match in item['matches']:
@@ -872,21 +840,7 @@ def enrich_data_from_javascript(tmp_list, item, rules):
872840
if match['version'] is None:
873841
return
874842

875-
def enrich_data_from_videos(tmp_list, item, result_folder_name, nof_tries=0):
876-
if USE_STEALTH:
877-
return
878-
for match in item['matches']:
879-
if match['category'] != 'video':
880-
return
881-
882-
if match['name'] != 'mp4':
883-
return
884-
885-
def enrich_data_from_documents(tmp_list, item, result_folder_name, nof_tries=0):
886-
if USE_STEALTH:
887-
return
888-
889-
def enrich_data_from_images(tmp_list, item, result_folder_name, nof_tries=0):
843+
def enrich_data_from_images(tmp_list, item, result_folder_name):
890844
if USE_STEALTH:
891845
return
892846
for match in item['matches']:
@@ -905,7 +859,7 @@ def enrich_data_from_images(tmp_list, item, result_folder_name, nof_tries=0):
905859

906860
tech_name = ''
907861
tech_version = ''
908-
for matchNum, match in enumerate(matches, start=1):
862+
for _, match in enumerate(matches, start=1):
909863
tech_name = match.group('name')
910864
tech_version = match.group('version')
911865

@@ -918,7 +872,7 @@ def enrich_data_from_images(tmp_list, item, result_folder_name, nof_tries=0):
918872
'enrich',
919873
match['precision'],
920874
'security',
921-
'whisper.{0}.app'.format(match['category']), None))
875+
f"whisper.{match['category']}.app", None))
922876

923877
if tech_version is not None:
924878
tech_version = tech_version.lower()
@@ -929,10 +883,9 @@ def enrich_data_from_images(tmp_list, item, result_folder_name, nof_tries=0):
929883
'enrich',
930884
0.8,
931885
'security',
932-
'whisper.{0}.app'.format(match['category']), None))
886+
f"whisper.{match['category']}.app", None))
933887
else:
934-
cache_key = '{0}.cache.{1}'.format(
935-
hashlib.sha512(item['url'].encode()).hexdigest(), match['name'])
888+
cache_key = f"{hashlib.sha512(item['url'].encode()).hexdigest()}.cache.{match['name']}"
936889
cache_path = os.path.join(result_folder_name, cache_key)
937890

938891
image_data = None
@@ -961,8 +914,8 @@ def enrich_data_from_images(tmp_list, item, result_folder_name, nof_tries=0):
961914
for tag_id in exifdata:
962915
# get the tag name, instead of human unreadable tag id
963916
tag = TAGS.get(tag_id, None)
964-
if tag == None:
965-
tag = 'unknown_{0}'.format(tag_id)
917+
if tag is None:
918+
tag = f'unknown_{tag_id}'
966919

967920
tag_name = tag.lower()
968921
tag_data = exifdata.get(tag_id)
@@ -979,11 +932,11 @@ def enrich_data_from_images(tmp_list, item, result_folder_name, nof_tries=0):
979932
r"(?P<version>[0-9.]+){0,1}[ (]{0,2}(?P<osname>[a-zA-Z]+){0,1})[)]{0,1}")
980933
matches = re.finditer(
981934
regex, tag_data, re.MULTILINE)
982-
for matchNum, match in enumerate(matches, start=1):
935+
for _, match in enumerate(matches, start=1):
983936
tech_name = match.group('name')
984937
tech_version = match.group('version')
985938
os_name = match.group('osname')
986-
if tech_name != None and tech_version == None:
939+
if tech_name is not None and tech_version is None:
987940
tech_name = tech_name.lower().strip().replace(' ', '-')
988941
tmp_list.append(get_default_info(
989942
item['url'], 'enrich', 0.5, 'img.software', tech_name, None))
@@ -992,9 +945,9 @@ def enrich_data_from_images(tmp_list, item, result_folder_name, nof_tries=0):
992945
'enrich',
993946
match['precision'],
994947
'security',
995-
'whisper.{0}.app'.format(match['category']), None))
948+
f"whisper.{match['category']}.app", None))
996949

997-
if tech_version != None:
950+
if tech_version is not None:
998951
tech_version = tech_version.lower()
999952
tmp_list.append(get_default_info(
1000953
item['url'],
@@ -1008,7 +961,7 @@ def enrich_data_from_images(tmp_list, item, result_folder_name, nof_tries=0):
1008961
'enrich',
1009962
0.8,
1010963
'security',
1011-
'whisper.{0}.app'.format(match['category']), None))
964+
f"whisper.{match['category']}.app", None))
1012965

1013966
if os_name is not None:
1014967
os_name = os_name.lower()
@@ -1019,14 +972,14 @@ def enrich_data_from_images(tmp_list, item, result_folder_name, nof_tries=0):
1019972
'enrich',
1020973
0.8,
1021974
'security',
1022-
'whisper.{0}.os'.format(match['category']), None))
975+
f"whisper.{match['category']}.os", None))
1023976
elif 'artist' == tag_name or 'xpauthor' == tag_name:
1024977
tmp_list.append(get_default_info(
1025978
item['url'],
1026979
'enrich',
1027980
0.8,
1028981
'security',
1029-
'info.{0}.person'.format(match['category']), None))
982+
f"info.{match['category']}.person", None))
1030983
elif 'make' == tag_name:
1031984
device_name = tag_data.lower().strip()
1032985
if 'nikon corporation' in device_name:
@@ -1038,31 +991,31 @@ def enrich_data_from_images(tmp_list, item, result_folder_name, nof_tries=0):
1038991
r"(?P<version>[0-9.]+){0,1}[ (]{0,2}(?P<osname>[a-zA-Z]+){0,1})[)]{0,1}")
1039992
matches = re.finditer(
1040993
regex, tag_data, re.MULTILINE)
1041-
for matchNum, match in enumerate(matches, start=1):
994+
for _, match in enumerate(matches, start=1):
1042995
tech_name = match.group('name')
1043996
tech_version = match.group('version')
1044997
os_name = match.group('osname')
1045-
if tech_name != None and tech_version == None:
998+
if tech_name is not None and tech_version is None:
1046999
tech_name = tech_name.lower().strip().replace(' ', '-')
10471000
device_name = tech_name
10481001
tmp_list.append(get_default_info(
10491002
item['url'],
10501003
'enrich',
10511004
match['precision'],
10521005
'security',
1053-
'whisper.{0}.device'.format(match['category']), None))
1006+
f"whisper.{match['category']}.device", None))
10541007

1055-
if tech_version != None:
1008+
if tech_version is not None:
10561009
tech_version = tech_version.lower()
10571010
device_version = tech_version
10581011
tmp_list.append(get_default_info(
10591012
item['url'],
10601013
'enrich',
10611014
0.8,
10621015
'security',
1063-
'whisper.{0}.device'.format(match['category']), None))
1016+
f"whisper.{match['category']}.device", None))
10641017

1065-
if os_name != None:
1018+
if os_name is not None:
10661019
os_name = os_name.lower().strip()
10671020
tmp_list.append(get_default_info(
10681021
item['url'], 'content', 0.6, 'img.os', os_name, None))
@@ -1071,22 +1024,22 @@ def enrich_data_from_images(tmp_list, item, result_folder_name, nof_tries=0):
10711024
'enrich',
10721025
0.8,
10731026
'security',
1074-
'whisper.{0}.os'.format(match['category']), None))
1027+
f"whisper.{match['category']}.os", None))
10751028
elif 'model' == tag_name:
10761029
tmp_list.append(get_default_info(
10771030
item['url'],
10781031
'enrich',
10791032
0.8,
10801033
'security',
1081-
'info.{0}.model'.format(match['category']), None))
1034+
f"info.{match['category']}.model", None))
10821035
device_version = tag_data.lower().strip()
10831036
elif 'gpsinfo' == tag_name:
10841037
tmp_list.append(get_default_info(
10851038
item['url'],
10861039
'enrich',
10871040
0.8,
10881041
'security',
1089-
'info.{0}.location'.format(match['category']), None))
1042+
f"info.{match['category']}.location", None))
10901043

10911044
if device_name is not None or device_version is not None:
10921045
if device_name is not None:
@@ -1099,7 +1052,7 @@ def enrich_data_from_images(tmp_list, item, result_folder_name, nof_tries=0):
10991052
'enrich',
11001053
match['precision'],
11011054
'security',
1102-
'whisper.{0}.device'.format(match['category']), None))
1055+
f"whisper.{match['category']}.device", None))
11031056

11041057
if device_name is not None and device_version is not None:
11051058
device_version = device_version.lower()
@@ -1112,7 +1065,7 @@ def enrich_data_from_images(tmp_list, item, result_folder_name, nof_tries=0):
11121065
'enrich',
11131066
0.8,
11141067
'security',
1115-
'whisper.{0}.device'.format(match['category']), None))
1068+
f"whisper.{match['category']}.device", None))
11161069

11171070

11181071
def identify_software(filename, origin_domain, rules):
@@ -1265,7 +1218,7 @@ def lookup_response_content(item, response_mimetype, response_content, rules):
12651218

12661219
regex = r"{0}".format(rule['match'])
12671220
matches = re.finditer(regex, response_content, re.IGNORECASE)
1268-
for matchNum, match in enumerate(matches, start=1):
1221+
for _, match in enumerate(matches, start=1):
12691222
match_name = None
12701223
match_version = None
12711224
match_github_owner = None
@@ -1379,7 +1332,7 @@ def lookup_request_url(item, rules, origin_domain):
13791332

13801333
regex = r"{0}".format(rule['match'])
13811334
matches = re.finditer(regex, req_url, re.MULTILINE)
1382-
for matchNum, match in enumerate(matches, start=1):
1335+
for _, match in enumerate(matches, start=1):
13831336
match_name = None
13841337
match_version = None
13851338

@@ -1466,7 +1419,7 @@ def lookup_cookie(item, cookie_name, cookie_value, rules, origin_domain):
14661419

14671420
regex = r"{0}".format(rule['match'])
14681421
matches = re.finditer(regex, value, re.MULTILINE)
1469-
for matchNum, match in enumerate(matches, start=1):
1422+
for _, match in enumerate(matches, start=1):
14701423
match_name = None
14711424
match_version = None
14721425

@@ -1552,7 +1505,7 @@ def lookup_response_header(item, header_name, header_value, rules, origin_domain
15521505

15531506
regex = r"{0}".format(rule['match'])
15541507
matches = re.finditer(regex, header_value, re.MULTILINE)
1555-
for matchNum, match in enumerate(matches, start=1):
1508+
for _, match in enumerate(matches, start=1):
15561509
match_name = None
15571510
match_version = None
15581511

0 commit comments

Comments
 (0)